From patchwork Sun Mar 12 11:26:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A. Shutemov" X-Patchwork-Id: 13171302 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CE5F1C74A5B for ; Sun, 12 Mar 2023 11:26:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E48CB8E000A; Sun, 12 Mar 2023 07:26:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E1F608E0008; Sun, 12 Mar 2023 07:26:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CC13B8E000A; Sun, 12 Mar 2023 07:26:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id B916A8E0008 for ; Sun, 12 Mar 2023 07:26:40 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 8B00112086E for ; Sun, 12 Mar 2023 11:26:40 +0000 (UTC) X-FDA: 80560018560.17.4EEE80C Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by imf14.hostedemail.com (Postfix) with ESMTP id 6C603100004 for ; Sun, 12 Mar 2023 11:26:38 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=DL+rX3xj; spf=none (imf14.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 134.134.136.65) smtp.mailfrom=kirill.shutemov@linux.intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678620398; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=E+vgO6hMBee1lhY3UlBSn+wO/aeilTZUQ4GQAb4cApQ=; b=uRhpnT0XJSJdlJfukSEDV/DP6SKfJQXNmVpVeaj0m9kPvuTUbnfcVluimIhBDPtJuEUi3w wDSjRG4b3Ak5xG5i2RXPWEW5HM825OLoATfQ/cih1/DLROvy8NiUWaSWM4nMo/7m4N4thZ oYi+02eN4Qto7bbTnhlUyN0g7hzegbw= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=DL+rX3xj; spf=none (imf14.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 134.134.136.65) smtp.mailfrom=kirill.shutemov@linux.intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678620398; a=rsa-sha256; cv=none; b=4kdN110uPp1UvoR53+EoxgmaukVX0msl3tiHsV1FHIlB+1ELFHLxisk0wZ+LxQ3sCo7+NV ZeeFEscQU1i6v5/gBeAfzwAOFq7m9kO4ZORUQm8mQDgiwWSXz4ASfL2bdmVYu8zXTseSPa EaSIHVTWiVESrAaVBJtd416F+poZL1k= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1678620398; x=1710156398; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+iKOETahP1WXZi4zcV24NixONYfrth/yIw9MG3r4KgU=; b=DL+rX3xjk6tEfmSRwiunsyVURZjWenxeK7sMdQo4J1oORiDy+4U2ddOh HOOtQ0gnEylf18KGXU6z6CeCRoKfVjOiVNKAE6wYBXqlLcy3P2akh1FUM pIUqc32EJnABdymrusQMjpaCGaBVXrKPUxE2E9WiaIGKHiZv0pWkb24o9 MRuD2ObWP9x6oaUKUM40k5l3rWDjEBVyDdo5MptUdQAZ3eA4XVqM6Sg/E lA8xdCJGrSprFeCUzMOhAKH2zOZbxnYSRsjye8MFRbOe90yS6+ODnsSe7 rczCTgMeZWm8cNxE00Fnw/HeD7NQisTbGlxMX9vQradhbTuf/f+4A7gLF w==; X-IronPort-AV: E=McAfee;i="6500,9779,10646"; a="339349975" X-IronPort-AV: E=Sophos;i="5.98,254,1673942400"; d="scan'208";a="339349975" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Mar 2023 04:26:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10646"; a="852438035" X-IronPort-AV: E=Sophos;i="5.98,254,1673942400"; d="scan'208";a="852438035" Received: from nmoazzen-mobl1.amr.corp.intel.com (HELO box.shutemov.name) ([10.251.219.215]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Mar 2023 04:26:30 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id B979A10D7B8; Sun, 12 Mar 2023 14:26:19 +0300 (+03) From: "Kirill A. Shutemov" To: Dave Hansen , Andy Lutomirski , Peter Zijlstra Cc: x86@kernel.org, Kostya Serebryany , Andrey Ryabinin , Andrey Konovalov , Alexander Potapenko , Taras Madan , Dmitry Vyukov , "H . J . Lu" , Andi Kleen , Rick Edgecombe , Bharata B Rao , Jacob Pan , Ashok Raj , Linus Torvalds , linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: [PATCHv16 10/17] iommu/sva: Replace pasid_valid() helper with mm_valid_pasid() Date: Sun, 12 Mar 2023 14:26:05 +0300 Message-Id: <20230312112612.31869-11-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230312112612.31869-1-kirill.shutemov@linux.intel.com> References: <20230312112612.31869-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 6C603100004 X-Rspam-User: X-Stat-Signature: sy6eaq4tuusnng74qmbkuw5u5wjp7687 X-HE-Tag: 1678620398-353804 X-HE-Meta: U2FsdGVkX19joFn2vVk5LhAvxr/Y8iUlCJSmGgbxF+BwSnuvAR8WH0JW1S0I4RsU24j8QajrNXt6St4I4CNCebupnT7Fm8qVIkrgS/YbaqswtkkxyTS1b6Cmhi30FmApv4eyRAB+QdEnxXC30pSIfVdZ6NBctXFY1eu2mzY5GKRGBkcmxVjWpYPXfEEUXZC+IztbSdfSMJG/ZQ/fDqweVtxMW+ljqVeDXOBttA9FDMqjyIfQN0/k6Ol++SDefmQHeUO4OnUKkw9sU1neP3uWlcNayyTCLRBhgDhJbgRGa4eycBRjF4g8qKwmQBV6M5xQqtwvxiXBk19Ov02D2AQTKmA2Tz+RttguOiIzo28ozF3mH0L50ZAy9C9v8lVIAIxA9BATV4cqLhqhoAaOLS9WwuhnT7CNZCtupGLSV06OWE61+wd38tDAayCaNhA8CpeAwHnUPDd+0neHN/WCf5V4xGZqSc494srUxyOR1l7W8hEdOQRyFHREdBNjD3yNfWOAl11e1rQRcC9mgwXmyywgKXJN4bv3rGcQo7F9kWUSIrjnacyCJmiIuj1w+mmDtzxywTNDO0Ntmunylw5HJ+nx+z1q5jpIc5AXr8q9/dQs9d96voVrV5pVbAI8jy4xPedORWMtnO/RUE1SjuEVKyPQ7Y/wNGQTX9KYU9azYufXNdSdQRbQVmWaM/10yXaYvI00xf/PQSmTaLy0Unf/GjLW9P1nYHx25fTRefhACaw0Sgtq+9aNCoFljy8f3Wyzt2N0mKwrlLfJIm5sT8sa/VUwdi3Vtf75nbsYMzbEneVUyf7ZHcEMVOdbEgNz3+2IL2t/+6b4lTNEVMmTPa0dAHbGD8Z07psJ6QLiKid7DabzXxUPCCH4g4KicC4cvRGSVQo8/vapD8oCWHueK1DgMW/+eWCZf+8Uvtb537J9YNulYA1WWq6kCWKz5P3SP1RXy9oI0B4OaWxYIckPZyKbUGl 1Xa2dgNl YDO/VtuV8um8biTfHpLGwqjsPOalGD5DegHjmmeTU8RWt+OYSxQMhaqgeB9KNgKBT/yqCHHNMdtkJBD7B5cxRPEl5szRS6Z3ls/1qPb4vUnNaGNm+zEftp+WTWsSxjha4//dn5p4+6iijb2QSEJBS66eivwMVXYy8CexPjTx7U3/XoOHxnP/nbWa9XRnF6WvUmpcfDmS7JH1NaHsT+qIOJBhCUUBRgOUrU5sA0tDMKxfVtGHlCDRG4EXbY5RxJIw15/QsMqxeebgJw6fnmJC0ohLvZDTwPvnRRX4yE4kFn+mzT0Fc7MtE0/vLPbV/E+cjhNNd1NpR7aLZ6ZS+AJINqMfVBA== 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: Kernel has few users of pasid_valid() and all but one checks if the process has PASID allocated. The helper takes ioasid_t as the input. Replace the helper with mm_valid_pasid() that takes mm_struct as the argument. The only call that checks PASID that is not tied to mm_struct is open-codded now. This is preparatory patch. It helps avoid ifdeffery: no need to dereference mm->pasid in generic code to check if the process has PASID. Signed-off-by: Kirill A. Shutemov Acked-by: Peter Zijlstra (Intel) --- arch/x86/kernel/traps.c | 6 +++--- drivers/iommu/iommu-sva.c | 4 ++-- include/linux/ioasid.h | 9 --------- include/linux/sched/mm.h | 8 +++++++- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c index d317dc3d06a3..8b83d8fbce71 100644 --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c @@ -671,15 +671,15 @@ static bool try_fixup_enqcmd_gp(void) if (!cpu_feature_enabled(X86_FEATURE_ENQCMD)) return false; - pasid = current->mm->pasid; - /* * If the mm has not been allocated a * PASID, the #GP can not be fixed up. */ - if (!pasid_valid(pasid)) + if (!mm_valid_pasid(current->mm)) return false; + pasid = current->mm->pasid; + /* * Did this thread already have its PASID activated? * If so, the #GP must be from something else. diff --git a/drivers/iommu/iommu-sva.c b/drivers/iommu/iommu-sva.c index 24bf9b2b58aa..4ee2929f0d7a 100644 --- a/drivers/iommu/iommu-sva.c +++ b/drivers/iommu/iommu-sva.c @@ -34,14 +34,14 @@ int iommu_sva_alloc_pasid(struct mm_struct *mm, ioasid_t min, ioasid_t max) mutex_lock(&iommu_sva_lock); /* Is a PASID already associated with this mm? */ - if (pasid_valid(mm->pasid)) { + if (mm_valid_pasid(mm)) { if (mm->pasid < min || mm->pasid >= max) ret = -EOVERFLOW; goto out; } pasid = ioasid_alloc(&iommu_sva_pasid, min, max, mm); - if (!pasid_valid(pasid)) + if (pasid == INVALID_IOASID) ret = -ENOMEM; else mm_pasid_set(mm, pasid); diff --git a/include/linux/ioasid.h b/include/linux/ioasid.h index af1c9d62e642..836ae09e92c2 100644 --- a/include/linux/ioasid.h +++ b/include/linux/ioasid.h @@ -40,10 +40,6 @@ void *ioasid_find(struct ioasid_set *set, ioasid_t ioasid, int ioasid_register_allocator(struct ioasid_allocator_ops *allocator); void ioasid_unregister_allocator(struct ioasid_allocator_ops *allocator); int ioasid_set_data(ioasid_t ioasid, void *data); -static inline bool pasid_valid(ioasid_t ioasid) -{ - return ioasid != INVALID_IOASID; -} #else /* !CONFIG_IOASID */ static inline ioasid_t ioasid_alloc(struct ioasid_set *set, ioasid_t min, @@ -74,10 +70,5 @@ static inline int ioasid_set_data(ioasid_t ioasid, void *data) return -ENOTSUPP; } -static inline bool pasid_valid(ioasid_t ioasid) -{ - return false; -} - #endif /* CONFIG_IOASID */ #endif /* __LINUX_IOASID_H */ diff --git a/include/linux/sched/mm.h b/include/linux/sched/mm.h index 2a243616f222..b69fe7e8c0ac 100644 --- a/include/linux/sched/mm.h +++ b/include/linux/sched/mm.h @@ -457,6 +457,11 @@ static inline void mm_pasid_init(struct mm_struct *mm) mm->pasid = INVALID_IOASID; } +static inline bool mm_valid_pasid(struct mm_struct *mm) +{ + return mm->pasid != INVALID_IOASID; +} + /* Associate a PASID with an mm_struct: */ static inline void mm_pasid_set(struct mm_struct *mm, u32 pasid) { @@ -465,13 +470,14 @@ static inline void mm_pasid_set(struct mm_struct *mm, u32 pasid) static inline void mm_pasid_drop(struct mm_struct *mm) { - if (pasid_valid(mm->pasid)) { + if (mm_valid_pasid(mm)) { ioasid_free(mm->pasid); mm->pasid = INVALID_IOASID; } } #else static inline void mm_pasid_init(struct mm_struct *mm) {} +static inline bool mm_valid_pasid(struct mm_struct *mm) { return false; } static inline void mm_pasid_set(struct mm_struct *mm, u32 pasid) {} static inline void mm_pasid_drop(struct mm_struct *mm) {} #endif