From patchwork Fri May 11 19:06:07 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: 10394869 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 850DB6053A for ; Fri, 11 May 2018 19:08:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6DF1528581 for ; Fri, 11 May 2018 19:08:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6256428674; Fri, 11 May 2018 19:08:08 +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=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E676F28581 for ; Fri, 11 May 2018 19:08:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 563C16B0685; Fri, 11 May 2018 15:08:06 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 4E4506B0686; Fri, 11 May 2018 15:08:06 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3FB2A6B0687; Fri, 11 May 2018 15:08:06 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-oi0-f70.google.com (mail-oi0-f70.google.com [209.85.218.70]) by kanga.kvack.org (Postfix) with ESMTP id 1A1806B0685 for ; Fri, 11 May 2018 15:08:06 -0400 (EDT) Received: by mail-oi0-f70.google.com with SMTP id c23-v6so3488207oic.2 for ; Fri, 11 May 2018 12:08:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=sAO1Y8ghGH9xYCMM8fRpLJtMQijTWmLiyXbarZhwnFk=; b=RqH56Ne7uwOWYvmiCmJalQXZNArM6SOMln+xNABrxtpWQLqvLI5TBeXbWBAvAbQAwj SXr2wj59hMCCn0C9fVRbCRO9pnLSlhcPYmxGla3UMsXE64bW2sD0TcNt8nDB356euVjq SOaSNGugWVsh0STPbh5GjJDvB5yXD2fTCmFfrqPcl0Xce5r169cp7ACUNbrdv/7p/NiW CsczhuE4KY6dhI5hP0kvDyn6SWvbbh/mvHu1rK9R+jBHhe4z+vux6cJ79E+Hj77+3h0P 6cc0UcofYbAYiBAGb7YcaZ7J525GckA4rkB3SoknCpnLWglqH3yOoe5m+P3ydpTlG0tN vKXQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of jean-philippe.brucker@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=jean-philippe.brucker@arm.com X-Gm-Message-State: ALKqPwcyOiTj+pFe0yxkFZdAudL8XjCYIL7KCiCnJXG84KTUjt/jMNcc SmKnmCZ0mAmad6o+mEMdAeUIYk00ts2kCjTyGoSFg38+jM+NHGCNyjAdd4Va4KJkD3Jjmh/AhRG blKBPh6ivkWMXGoY+50CYT218hip5dEB5qCvtSXXiPQrb/tmjDC47yp6+HxNyOO9B3g== X-Received: by 2002:aca:4444:: with SMTP id r65-v6mr27055oia.270.1526065685881; Fri, 11 May 2018 12:08:05 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqa0EwcC/FMpS2e9AxMF3LjJu7+h+3KltpLtBwJEXNHR8ZbbLK/vre8LK7WKhwfqdcPsUOc X-Received: by 2002:aca:4444:: with SMTP id r65-v6mr27025oia.270.1526065685217; Fri, 11 May 2018 12:08:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526065685; cv=none; d=google.com; s=arc-20160816; b=JVH/JnhdEWB/ICZVjHmI46ZjmxYUwxOEXUrDtFjqkyHUTG8hSolaks4qZcCAYacO9e RYxmaUPXUbWluG3x1e1NOV810bdOgK6S10MyS+NGcsa9Kh9lR2VGI/XsLu9Um2KwFo8V dGSc37/I1jfgCFhz36vtzqgfo70VKeqC6i1SlJoaRWlNvi1GZ++5uH1ceL4FDfHFZbrP 9TjS9fqElkOqzHf9iKsYgBDNv/4f+cHdMM6nXPLMGJHQshfepAzLrwO9BdybQArsPcJc M2wVOnJKtGVMhMbwCB0DTD7Xt1pEQkMKebTl7tyeE30KooCVAl7Anb5io+zwsigdurS8 moMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=sAO1Y8ghGH9xYCMM8fRpLJtMQijTWmLiyXbarZhwnFk=; b=htaxLN0BR/tWQEVfwruPUf8HwtbYoU2GOM8TKUCA6UnTadOs8gTt064WlQRB1nEOz0 MrJYHi9IpKrs0xGZ0V+5OQBBZwNDLgmBdoD4iqIakN2LvWo66J5Ziu13dm48N54pWyl0 NS7nj48nwS/x7lVNmqjYe5d6i7zCGFmIImBOzThJhTHzdPrM+ax9Cq/ap64QinEoyedd UvhF9LQo+ySAEWOP1xvigg/hKWXF5a6r5psD5XcU2wyuKXrbLxmVK5hWZiQDI8QRekga kJgjTOjVbOMOsSjO8SEkTD37tV2ZzLj12sJjkzPaVp2c949aHUW3eweVzYz52JLn+3AO Rn2Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of jean-philippe.brucker@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=jean-philippe.brucker@arm.com Received: from foss.arm.com (foss.arm.com. [217.140.101.70]) by mx.google.com with ESMTP id 188-v6si1199342oia.429.2018.05.11.12.08.05 for ; Fri, 11 May 2018 12:08:05 -0700 (PDT) Received-SPF: pass (google.com: domain of jean-philippe.brucker@arm.com designates 217.140.101.70 as permitted sender) client-ip=217.140.101.70; Authentication-Results: mx.google.com; spf=pass (google.com: domain of jean-philippe.brucker@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=jean-philippe.brucker@arm.com 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 D8EC71993; Fri, 11 May 2018 12:08:04 -0700 (PDT) Received: from ostrya.cambridge.arm.com (ostrya.cambridge.arm.com [10.1.210.33]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 9A2503F23C; Fri, 11 May 2018 12:07:59 -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, kvm@vger.kernel.org, linux-mm@kvack.org Cc: joro@8bytes.org, will.deacon@arm.com, robin.murphy@arm.com, alex.williamson@redhat.com, tn@semihalf.com, liubo95@huawei.com, thunder.leizhen@huawei.com, xieyisheng1@huawei.com, xuzaibo@huawei.com, ilias.apalodimas@linaro.org, jonathan.cameron@huawei.com, liudongdong3@huawei.com, shunyong.yang@hxt-semitech.com, nwatters@codeaurora.org, okaya@codeaurora.org, jcrouse@codeaurora.org, rfranz@cavium.com, dwmw2@infradead.org, jacob.jun.pan@linux.intel.com, yi.l.liu@intel.com, ashok.raj@intel.com, kevin.tian@intel.com, baolu.lu@linux.intel.com, robdclark@gmail.com, christian.koenig@amd.com, bharatku@xilinx.com, rgummal@xilinx.com Subject: [PATCH v2 06/40] iommu/sva: Search mm by PASID Date: Fri, 11 May 2018 20:06:07 +0100 Message-Id: <20180511190641.23008-7-jean-philippe.brucker@arm.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180511190641.23008-1-jean-philippe.brucker@arm.com> References: <20180511190641.23008-1-jean-philippe.brucker@arm.com> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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. 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 e9afae2537a2..5abe0f0b445c 100644 --- a/drivers/iommu/iommu-sva.c +++ b/drivers/iommu/iommu-sva.c @@ -736,3 +736,29 @@ void __iommu_sva_unbind_dev_all(struct device *dev) } } EXPORT_SYMBOL_GPL(__iommu_sva_unbind_dev_all); + +/** + * iommu_sva_find() - Find mm associated to the given PASID + * @pasid: Process Address Space ID assigned to the mm + * + * 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 caa6f79785b9..faf3390ce89d 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -1001,6 +1001,7 @@ extern int __iommu_sva_bind_device(struct device *dev, struct mm_struct *mm, extern int __iommu_sva_unbind_device(struct device *dev, int pasid); extern void __iommu_sva_unbind_dev_all(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, @@ -1030,6 +1031,11 @@ static inline int __iommu_sva_unbind_device(struct device *dev, int pasid) static inline void __iommu_sva_unbind_dev_all(struct device *dev) { } + +static inline struct mm_struct *iommu_sva_find(int pasid) +{ + return NULL; +} #endif /* CONFIG_IOMMU_SVA */ #endif /* __LINUX_IOMMU_H */