From patchwork Mon Feb 12 18:33:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 10214095 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8D27F6055C for ; Mon, 12 Feb 2018 18:35:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 818B328894 for ; Mon, 12 Feb 2018 18:35:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7379028CF6; Mon, 12 Feb 2018 18:35:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C1A7528AB7 for ; Mon, 12 Feb 2018 18:35:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:References:In-Reply-To:Message-Id:Date:Subject:To: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Bk7at3a1lewOmVGrlWNUmbKbv9Wo5kQqOWPzW8FYd3c=; b=gZng48hk5K2/z+pDk29uI0g4c0 hkeEMI61YmuXOt/9N+6nuY5dyE5NeTqA8mxdC8upSROIzeWpsTZ6vIYu/Ptk/SfAuGXy2/z4hf/yN e8IS7VjmysICrhWwJTERASGmx9E7/h6gpwBngebYMOqonf4gJ4g5ZUx1k7gwWK+aITHr3XvwINyWw XVDzMAv7uM7JJ93jA9PekL2xcE6xCoVOOjVff88DDzUjf2rfOmUAYrYQYtfADxTtTfC/bFfw4SluY a1/pKxHX/cYKgaumXE8zxJTVTJiTBNlEMVggz1Ai/OcqsB8My1pmCRmcaxsuUZsJdIy/XsYcWHLRY anM+/ysA==; Received: from [198.137.202.133] (helo=bombadil.infradead.org) by casper.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1elIwu-00071M-1b for patchwork-linux-arm@patchwork.kernel.org; Mon, 12 Feb 2018 18:35:32 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=Bk7at3a1lewOmVGrlWNUmbKbv9Wo5kQqOWPzW8FYd3c=; b=NSbaIKcRbTY+p0v5O0xl88Li58 SGJqWJEQRhx6wt0PWQgRmyUyw1blImoyLdB7gC35p9OQcTS4AFDE3gpQ62pONqFXuhLgAsbP1guxS 1l6TTh2znKm0Vof0NDxy/Fs1d6E/PVhsTWsvK42Dt5M6+dZrKbc67x4X2JKUvj5k3fLS/zpAqrXQQ i/B6UPAhP+Wh0Z3vQmphlv5aJ9IPZXgIDO7b7F73Z5F3D1jTvU9kMwPNV6Rt7kPVvGyYY4gtcWkek KF/OtL4f9y9X8blav5/JphSovs5+viQKz6KSDcxoSxSnT8fo8SLtQ31vPnpWCdcl0Znj51u0NlYc2 umOQhI+g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1elIwh-0000pC-5S; Mon, 12 Feb 2018 18:35:19 +0000 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70] helo=foss.arm.com) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1elIt8-0002pq-Qq for linux-arm-kernel@lists.infradead.org; Mon, 12 Feb 2018 18:31:42 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8066C164F; Mon, 12 Feb 2018 10:31:28 -0800 (PST) Received: from e106794-lin.cambridge.arm.com (e106794-lin.cambridge.arm.com [10.1.210.24]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id A37203F24D; Mon, 12 Feb 2018 10:31:22 -0800 (PST) From: Jean-Philippe Brucker To: linux-arm-kernel@lists.infradead.org, linux-pci@vger.kernel.org, linux-acpi@vger.kernel.org, devicetree@vger.kernel.org, iommu@lists.linux-foundation.org, kvm@vger.kernel.org Subject: [PATCH 06/37] iommu/sva: Search mm by PASID Date: Mon, 12 Feb 2018 18:33:21 +0000 Message-Id: <20180212183352.22730-7-jean-philippe.brucker@arm.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180212183352.22730-1-jean-philippe.brucker@arm.com> References: <20180212183352.22730-1-jean-philippe.brucker@arm.com> X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, xieyisheng1@huawei.com, ilias.apalodimas@linaro.org, catalin.marinas@arm.com, xuzaibo@huawei.com, jonathan.cameron@huawei.com, will.deacon@arm.com, okaya@codeaurora.org, yi.l.liu@intel.com, lorenzo.pieralisi@arm.com, ashok.raj@intel.com, tn@semihalf.com, joro@8bytes.org, bharatku@xilinx.com, rfranz@cavium.com, lenb@kernel.org, jacob.jun.pan@linux.intel.com, alex.williamson@redhat.com, robh+dt@kernel.org, thunder.leizhen@huawei.com, bhelgaas@google.com, shunyong.yang@hxt-semitech.com, dwmw2@infradead.org, liubo95@huawei.com, rjw@rjwysocki.net, jcrouse@codeaurora.org, robdclark@gmail.com, hanjun.guo@linaro.org, sudeep.holla@arm.com, robin.murphy@arm.com, christian.koenig@amd.com, nwatters@codeaurora.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The fault handler will need to find an mm given its PASID. This is the reason we have an IDR for storing address spaces, so hook it up. A future optimization could find the io_mm from the struct device passed to the fault handler, since it's readily accessible. Signed-off-by: Jean-Philippe Brucker --- drivers/iommu/iommu-sva.c | 26 ++++++++++++++++++++++++++ include/linux/iommu.h | 6 ++++++ 2 files changed, 32 insertions(+) diff --git a/drivers/iommu/iommu-sva.c b/drivers/iommu/iommu-sva.c index 9108adb54ec7..4bc2a8c12465 100644 --- a/drivers/iommu/iommu-sva.c +++ b/drivers/iommu/iommu-sva.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -770,3 +771,28 @@ int iommu_unregister_mm_exit_handler(struct device *dev) return 0; } EXPORT_SYMBOL_GPL(iommu_unregister_mm_exit_handler); + +/* + * iommu_sva_find() - Find mm associated to the given PASID + * + * Returns the mm corresponding to this PASID, or NULL if not found. A reference + * to the mm is taken, and must be released with mmput(). + */ +struct mm_struct *iommu_sva_find(int pasid) +{ + struct io_mm *io_mm; + struct mm_struct *mm = NULL; + + spin_lock(&iommu_sva_lock); + io_mm = idr_find(&iommu_pasid_idr, pasid); + if (io_mm && io_mm_get_locked(io_mm)) { + if (mmget_not_zero(io_mm->mm)) + mm = io_mm->mm; + + io_mm_put_locked(io_mm); + } + spin_unlock(&iommu_sva_lock); + + return mm; +} +EXPORT_SYMBOL_GPL(iommu_sva_find); diff --git a/include/linux/iommu.h b/include/linux/iommu.h index afec7b1d3301..226ab4f3ae0e 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -958,6 +958,7 @@ extern int iommu_register_mm_exit_handler(struct device *dev, iommu_mm_exit_handler_t handler); extern int iommu_unregister_mm_exit_handler(struct device *dev); +extern struct mm_struct *iommu_sva_find(int pasid); #else /* CONFIG_IOMMU_SVA */ static inline int iommu_sva_device_init(struct device *dev, unsigned long features, @@ -997,6 +998,11 @@ static inline int iommu_unregister_mm_exit_handler(struct device *dev) { return -ENODEV; } + +static inline struct mm_struct *iommu_sva_find(int pasid) +{ + return NULL; +} #endif /* CONFIG_IOMMU_SVA */ #endif /* __LINUX_IOMMU_H */