From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BBE35C38A30 for ; Tue, 14 Apr 2020 17:04:33 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7BDE12075E for ; Tue, 14 Apr 2020 17:04:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="s8kwev4q" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7BDE12075E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 781258E0016; Tue, 14 Apr 2020 13:04:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 70DDB8E0001; Tue, 14 Apr 2020 13:04:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5D1E18E0016; Tue, 14 Apr 2020 13:04:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0202.hostedemail.com [216.40.44.202]) by kanga.kvack.org (Postfix) with ESMTP id 3E5028E0001 for ; Tue, 14 Apr 2020 13:04:25 -0400 (EDT) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id F422B824556B for ; Tue, 14 Apr 2020 17:04:24 +0000 (UTC) X-FDA: 76707084090.02.women94_7dce8034fc229 X-HE-Tag: women94_7dce8034fc229 X-Filterd-Recvd-Size: 5205 Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by imf01.hostedemail.com (Postfix) with ESMTP for ; Tue, 14 Apr 2020 17:04:24 +0000 (UTC) Received: by mail-wm1-f65.google.com with SMTP id r26so14957715wmh.0 for ; Tue, 14 Apr 2020 10:04:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VGMc5wLgmgx1eLWq9RQ7RG7NMxWRw2tpIDY5WHUtd3w=; b=s8kwev4qB+FwMlvJnZIEgUlpsfPv5PqQmyfezwvPiaaBckIACLW3XMkbvKRq6DnKDi t2UKqeUTPQYcigtkMp+zlJsyJsWC29+hzyF/YILdw1kem5LX+rUdahvgddngTIewGKPI Ls9qOOWbX1+GZLw2eHVDQ0C+3Q+XuIo7i0CpC5yzUkrPvbUvTws6yMxrz4kHGk4gH7S2 lLF7B3VkEZoHfACdrS90vN31rEj3/80zND2C7VWgfzHYgNywd5gdWfI831crvwFJA6Fr T0J9K0/WC/Dm3PeoZXFwuI8vTy1x6RYRQz3w1oY7B7IC5RAT8PsArjVC3oEpvuMEqYG7 NofQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VGMc5wLgmgx1eLWq9RQ7RG7NMxWRw2tpIDY5WHUtd3w=; b=BTUIYnj227I3jQYFK1K5wk0JUtowiDNxS5M7vjPMCXZx6R5KTunP32Ll8EvQuMiJMB M3s4+P94Ci2uzC86aZKT6a4rOlkKySY/l4aVMzv6ZwB+Q0BL2leTrzVI0HmsiY5zoxrX I4NozzPjYrB7unGa+RKU89r6dC+o9rGY4v2xTj0ES1TP/7RSDEtHS9WTejXKPG0eZpYa hhsccB7v4gEHVFRbzTaPpHI/b34O0SN5wFRxO7ST6ZDxTm8S4KG4VfgKcUnRc1Md5s8j fyC6FTCgfJBODIaEspUrfCNTU+eyODBwcia+Aet7ZFP8KFCivBS/bUh3OUHbd3K6k9Ae VxNw== X-Gm-Message-State: AGi0PuZ9RihFLxtlPoqGf+ox0yPGvxtBTOz7/QbSmvXy3ykx3T/XujES Mnm8YvW4aa1NVRw9JdirnN2exA== X-Google-Smtp-Source: APiQypL42n0W5SIMAbcNDaJARHcsQO61MSaD9RMrsbqmlsVv6uHGjdhQFjv16aEzCb2QZXgo0ox3nw== X-Received: by 2002:a1c:e906:: with SMTP id q6mr775518wmc.62.1586883863302; Tue, 14 Apr 2020 10:04:23 -0700 (PDT) Received: from localhost.localdomain ([2001:171b:226b:54a0:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id x18sm19549147wrs.11.2020.04.14.10.04.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Apr 2020 10:04:22 -0700 (PDT) From: Jean-Philippe Brucker To: iommu@lists.linux-foundation.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pci@vger.kernel.org, linux-mm@kvack.org Cc: joro@8bytes.org, catalin.marinas@arm.com, will@kernel.org, robin.murphy@arm.com, kevin.tian@intel.com, baolu.lu@linux.intel.com, Jonathan.Cameron@huawei.com, jacob.jun.pan@linux.intel.com, christian.koenig@amd.com, zhangfei.gao@linaro.org, jgg@ziepe.ca, xuzaibo@huawei.com, Jean-Philippe Brucker Subject: [PATCH v5 04/25] iommu/sva: Search mm by PASID Date: Tue, 14 Apr 2020 19:02:32 +0200 Message-Id: <20200414170252.714402-5-jean-philippe@linaro.org> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200414170252.714402-1-jean-philippe@linaro.org> References: <20200414170252.714402-1-jean-philippe@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: 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 --- include/linux/iommu.h | 9 +++++++++ drivers/iommu/iommu-sva.c | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 5a3d092c2568a..4b9c25d7246d5 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -1081,6 +1081,15 @@ void iommu_debugfs_setup(void); static inline void iommu_debugfs_setup(void) {} #endif =20 +#ifdef CONFIG_IOMMU_SVA +extern struct mm_struct *iommu_sva_find(int pasid); +#else /* !CONFIG_IOMMU_SVA */ +static inline struct mm_struct *iommu_sva_find(int pasid) +{ + return NULL; +} +#endif /* !CONFIG_IOMMU_SVA */ + #ifdef CONFIG_IOMMU_PAGE_FAULT extern int iommu_queue_iopf(struct iommu_fault *fault, void *cookie); =20 diff --git a/drivers/iommu/iommu-sva.c b/drivers/iommu/iommu-sva.c index 7fecc74a9f7d6..b177d6cbf4fff 100644 --- a/drivers/iommu/iommu-sva.c +++ b/drivers/iommu/iommu-sva.c @@ -525,3 +525,22 @@ int iommu_sva_get_pasid_generic(struct iommu_sva *ha= ndle) return bond->io_mm->pasid; } EXPORT_SYMBOL_GPL(iommu_sva_get_pasid_generic); + +/* ioasid wants a void * argument */ +static bool __mmget_not_zero(void *mm) +{ + return mmget_not_zero(mm); +} + +/** + * 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 an error if not found.= A + * reference to the mm is taken, and must be released with mmput(). + */ +struct mm_struct *iommu_sva_find(int pasid) +{ + return ioasid_find(&shared_pasid, pasid, __mmget_not_zero); +} +EXPORT_SYMBOL_GPL(iommu_sva_find); --=20 2.26.0