From patchwork Fri Oct 6 13:31:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 9989297 X-Patchwork-Delegate: bhelgaas@google.com 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 25E5F6029B for ; Fri, 6 Oct 2017 13:28:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 23BF828DA6 for ; Fri, 6 Oct 2017 13:28:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1853F28DAB; Fri, 6 Oct 2017 13:28:11 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 83A5728DA6 for ; Fri, 6 Oct 2017 13:28:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751989AbdJFN2J (ORCPT ); Fri, 6 Oct 2017 09:28:09 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:60154 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751901AbdJFN2I (ORCPT ); Fri, 6 Oct 2017 09:28:08 -0400 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 DF61715BF; Fri, 6 Oct 2017 06:28:07 -0700 (PDT) Received: from e106794-lin.cambridge.arm.com (e106794-lin.cambridge.arm.com [10.1.211.72]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 123D03F578; Fri, 6 Oct 2017 06:28:02 -0700 (PDT) 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 Cc: joro@8bytes.org, robh+dt@kernel.org, mark.rutland@arm.com, catalin.marinas@arm.com, will.deacon@arm.com, lorenzo.pieralisi@arm.com, hanjun.guo@linaro.org, sudeep.holla@arm.com, rjw@rjwysocki.net, lenb@kernel.org, robin.murphy@arm.com, bhelgaas@google.com, alex.williamson@redhat.com, tn@semihalf.com, liubo95@huawei.com, thunder.leizhen@huawei.com, xieyisheng1@huawei.com, gabriele.paoloni@huawei.com, nwatters@codeaurora.org, okaya@codeaurora.org, rfranz@cavium.com, dwmw2@infradead.org, jacob.jun.pan@linux.intel.com, yi.l.liu@intel.com, ashok.raj@intel.com, robdclark@gmail.com Subject: [RFCv2 PATCH 03/36] iommu/process: Add public function to search for a process Date: Fri, 6 Oct 2017 14:31:30 +0100 Message-Id: <20171006133203.22803-4-jean-philippe.brucker@arm.com> X-Mailer: git-send-email 2.13.3 In-Reply-To: <20171006133203.22803-1-jean-philippe.brucker@arm.com> References: <20171006133203.22803-1-jean-philippe.brucker@arm.com> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The fault handler will need to find a process given its PASID. This is the reason we have an IDR for storing processes, so hook it up. Signed-off-by: Jean-Philippe Brucker --- drivers/iommu/iommu-process.c | 35 +++++++++++++++++++++++++++++++++++ include/linux/iommu.h | 12 ++++++++++++ 2 files changed, 47 insertions(+) diff --git a/drivers/iommu/iommu-process.c b/drivers/iommu/iommu-process.c index 61ca0bd707c0..8f4c98632d58 100644 --- a/drivers/iommu/iommu-process.c +++ b/drivers/iommu/iommu-process.c @@ -145,6 +145,41 @@ static void iommu_process_put_locked(struct iommu_process *process) kref_put(&process->kref, iommu_process_release); } +/** + * iommu_process_put - Put reference to process, freeing it if necessary. + */ +void iommu_process_put(struct iommu_process *process) +{ + spin_lock(&iommu_process_lock); + iommu_process_put_locked(process); + spin_unlock(&iommu_process_lock); +} +EXPORT_SYMBOL_GPL(iommu_process_put); + +/** + * iommu_process_find - Find process associated to the given PASID + * + * Returns the IOMMU process corresponding to this PASID, or NULL if not found. + * A reference to the iommu_process is kept, and must be released with + * iommu_process_put. + */ +struct iommu_process *iommu_process_find(int pasid) +{ + struct iommu_process *process; + + spin_lock(&iommu_process_lock); + process = idr_find(&iommu_process_idr, pasid); + if (process) { + if (!iommu_process_get_locked(process)) + /* kref is 0, process is defunct */ + process = NULL; + } + spin_unlock(&iommu_process_lock); + + return process; +} +EXPORT_SYMBOL_GPL(iommu_process_find); + static int iommu_process_attach(struct iommu_domain *domain, struct device *dev, struct iommu_process *process) { diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 8d74f9058f30..e9528fcacab1 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -733,12 +733,24 @@ const struct iommu_ops *iommu_ops_from_fwnode(struct fwnode_handle *fwnode) extern void iommu_set_process_exit_handler(struct device *dev, iommu_process_exit_handler_t cb, void *token); +extern struct iommu_process *iommu_process_find(int pasid); +extern void iommu_process_put(struct iommu_process *process); + #else /* CONFIG_IOMMU_PROCESS */ static inline void iommu_set_process_exit_handler(struct device *dev, iommu_process_exit_handler_t cb, void *token) { } + +static inline struct iommu_process *iommu_process_find(int pasid) +{ + return NULL; +} + +static inline void iommu_process_put(struct iommu_process *process) +{ +} #endif /* CONFIG_IOMMU_PROCESS */ #endif /* __LINUX_IOMMU_H */