Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp856560rwb; Wed, 9 Nov 2022 09:25:03 -0800 (PST) X-Google-Smtp-Source: AMsMyM67frF2Pg+K5JGOlv9tJl9rtgmQ4MSgwLpQpyjSTYO0+mTwnoyEkooBMPG3wRACxbEY/RmT X-Received: by 2002:a17:902:f7d4:b0:188:505b:529 with SMTP id h20-20020a170902f7d400b00188505b0529mr36380315plw.173.1668014703193; Wed, 09 Nov 2022 09:25:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668014703; cv=none; d=google.com; s=arc-20160816; b=xw6NI4VlRibsieHlVYB1XbDFjFikpCRKsMxU83v9Q/IlANE7kIKQ2XACeRy846sIab 4yRjIT94OIv/mex/fJUYJOxV3B7zOy8CzKKLbMd0gSapGFfkDgJz2Y1nW8HlBEGIqUqZ wZ+M4AkkfzmebMFc675p1OslAn4zgIkz7wTbyyx5L21JU5HHuZONvrd7+XzLzHRBGr7m Kzn+36XWYl725VXVBhxu4xUUDmCYuYZab20MGKcYWTFAQBd1Ym3LcZW+u70vLoJGbq2x 0IhdhubaxrmOpOBudUE/SLt6UpzQeOIpS+Yekd9Psx/LF5hMkqHCGyL6ooAbZbxemd4A nKPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=v6wuQwTfMALR6lvNsecDGxi6bxXpGHSsmKWj6R9xe/Y=; b=e5QWHNV1Jdy7KIMlfbKWaUG6dG0WyllolxRnZ9FzTTmVM/e8K7yzkrUHdrAals9QL1 eNQ2WVzCmZxVBPFsZVMwWjbiQcEi0+aRNxkZSJ5fPA6ZG2r7RO2A1ooTZn9i5UoK99RL M47vRMUNSamQ2NKJC9Bv4VzjWHVA1J/XOLlKUKNo/oS0JA9l/AEAtnLxD/7QIW1CDxtq jbHz/GrY+hfcUxoKMNeN/Tov/lY/Qt0CNn1cs4Ab8dPxMFySAmqaqPHR+nj7CID10Ug/ R+wKwnkDqcDVED78b5S1NJppUdnwLyrVgoQJ3dUmLfk0EqTBmfknXwUnx70JEub/Zc+C isLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QE7gBA6K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r11-20020a632b0b000000b0047005e8d872si18114687pgr.782.2022.11.09.09.24.50; Wed, 09 Nov 2022 09:25:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QE7gBA6K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231387AbiKIQwv (ORCPT + 92 others); Wed, 9 Nov 2022 11:52:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230146AbiKIQwf (ORCPT ); Wed, 9 Nov 2022 11:52:35 -0500 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E62082497B for ; Wed, 9 Nov 2022 08:52:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1668012737; x=1699548737; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xa2QDdupIWc8VqMdeXFZWdKQnRlx2ren8j3nAoeW+Vo=; b=QE7gBA6K3X0DnPMoL66EMNoxYY/MEk90HlsinTg4ztdhgAo3Smu44mQi F0VcxHgzmvcpHKaFrQxZA9o8Jhn2DtSVdnB25DJ+I8RVitaz65SNSjF58 Gbe4SoX6L+XxQ1mrMJesb9I6XrzjZFZtG7seNqF4Pry/vjGz7ztSax/9c TJ1xMRb4CxrUKbTB7TaDI+7otAicqUBZgoUWXb0iNXzUvkqKKZ7OeF1yN t1dqS9IVsSIsRD9Yzhvj3Cy8Er0O04NKPNAu9KAfqG0mMPHQULKbkIQHF f3HuPLZ2T71+tfIEaMlaKYUONwFsBQzXpf/KimCSQUNQrExgJPSbLG8Qq w==; X-IronPort-AV: E=McAfee;i="6500,9779,10526"; a="291419872" X-IronPort-AV: E=Sophos;i="5.96,151,1665471600"; d="scan'208";a="291419872" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Nov 2022 08:52:16 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10526"; a="668053279" X-IronPort-AV: E=Sophos;i="5.96,151,1665471600"; d="scan'208";a="668053279" Received: from dschramm-mobl.ger.corp.intel.com (HELO box.shutemov.name) ([10.251.219.85]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Nov 2022 08:52:10 -0800 Received: by box.shutemov.name (Postfix, from userid 1000) id BE39D109476; Wed, 9 Nov 2022 19:52:00 +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 , linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: [PATCHv12 10/16] iommu/sva: Replace pasid_valid() helper with mm_valid_pasid() Date: Wed, 9 Nov 2022 19:51:34 +0300 Message-Id: <20221109165140.9137-11-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221109165140.9137-1-kirill.shutemov@linux.intel.com> References: <20221109165140.9137-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- arch/x86/kernel/traps.c | 6 +++--- drivers/iommu/iommu-sva-lib.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 178015a820f0..3bdc37ae7d1c 100644 --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c @@ -664,15 +664,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-lib.c b/drivers/iommu/iommu-sva-lib.c index 106506143896..27be6b81e0b5 100644 --- a/drivers/iommu/iommu-sva-lib.c +++ b/drivers/iommu/iommu-sva-lib.c @@ -33,14 +33,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 -- 2.38.0