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: 9989341 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 856906029B for ; Fri, 6 Oct 2017 13:29:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 803C728BCF for ; Fri, 6 Oct 2017 13:29:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 74B1228D7B; Fri, 6 Oct 2017 13:29:09 +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 bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E827828BCF for ; Fri, 6 Oct 2017 13:29:08 +0000 (UTC) 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=Xh13hpB+qWd14SztoI6BT3nAuYt5H0ItlOuDjAP+BYI=; b=VB18TscT5koSdewsm4U12hX95x Nnv3GK0/MuvLbSPp9MPvy0EB/47Q338FsAvH3VDf8r8VgAkoV9o79mAFQLNBUHmVIWAk+5zZQ6sq5 MNjYkELQ6B+igpIe3UXshwS/FUO/9NyT78c5V1GxaMMjoh8BqsqYYaZ5CDebl3KK36GhJrNHtLroN hueSMjHnuSvFchH2JRXssj0RJ4qamKjgHEtu/sCtjc7hJMzjAicK1Jx3Ab+GuqLYNd4W2kmY5quMV M3SwBaNlSxXs7jiR7fJbl5aYvxva02zRZvyXYr4O3xa0Jg8nx46IVns0puzD+ytFy7L/NBYXlV7Dj eiH0JD3g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1e0Sga-0002hu-7h; Fri, 06 Oct 2017 13:29:04 +0000 Received: from foss.arm.com ([217.140.101.70]) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1e0Sfz-0001zz-Vm for linux-arm-kernel@lists.infradead.org; Fri, 06 Oct 2017 13:28:31 +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 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171006_062828_293209_4C78254C X-CRM114-Status: GOOD ( 10.40 ) 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, gabriele.paoloni@huawei.com, catalin.marinas@arm.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, 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, dwmw2@infradead.org, liubo95@huawei.com, rjw@rjwysocki.net, robdclark@gmail.com, hanjun.guo@linaro.org, sudeep.holla@arm.com, robin.murphy@arm.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 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 */