From patchwork Tue Sep 12 12:59:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Tina" X-Patchwork-Id: 139570 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp325815vqi; Thu, 14 Sep 2023 05:56:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEnrDTakBLtXcDoyxCZwWrUANlJTxEzpvFYUCA/dTRuDxn1ve3bMaQ/TuXWWR1+c6XnX4h7 X-Received: by 2002:a05:6a21:7988:b0:157:e67c:59 with SMTP id bh8-20020a056a21798800b00157e67c0059mr4590252pzc.29.1694696213990; Thu, 14 Sep 2023 05:56:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694696213; cv=none; d=google.com; s=arc-20160816; b=RrUP6beBNv9cHXFb0tYuWDQw4GLeELIVg05kqhZF+DM6KuKS6gPs9t/WE8E2QLAHD5 FYigHDGpiTNd7MfOdotDH5ylmaY7dI7F4LgS8yTYfztQSOvU1hGSiQavRLTFByr0SJWI np/2HAmCDSI5a4aMkWkzSr6n0jusP0YYeowkycAuAP3K6yshPFe6wF0f7XAuZvKVAI2P Jur4fFkUVRH7NSZotMVjyjpcTUkeZ9Iyhj7+r99x4Ovmew+2jV/4/RHIwGOFOyB/BkZQ IzV98meJLDrmgloVx2OVJYUunTFnj3IBuEnZmJDygk5DGzy5frKEHRHPbrzJF+lbrMB0 UOhg== 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=1iZIvlQa5pXt8UQjFw1F25c4K9F/kTnWuMnmUfKrJy8=; fh=zW1GPeUL3MQGLvvmLmBmaazP2MzqJ1fOEi8He5Dzy3k=; b=GpWA9D7NFxZUZRpq2lUSTqrAgvdpEcYLO4Cx+qdoGaRjUkaSI9jUbSbHvne0NweE2Y QN1WMNc5S2O23wzxhR8LypsVz/ofxjgK6dSqukIakORAAswohXPYMmt0TYBhGrgx4IQp YtMW+zXlFzNZciXowYFd5hTwdV7K3zMJRfz06J4Kx6GVomnnhcBJXuG+qHogtRRlDy0p QOl2Y56BwEKcqBdeSDnYcY0SGrLJYwl1eZBd1o3HaIPPOANT/SOxo6oy2xJY3wZ6YuBx hgfv8fT3pAkk31Z7aET1J9URPtVhejHSW+dnXNi4S71YNR9e23/nWVZXgobg3nf/K5Kv fDFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ef+P3D9n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id p10-20020a056a0026ca00b0068e2f34e100si1525064pfw.67.2023.09.14.05.56.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 05:56:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ef+P3D9n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id DED3384FF2FF; Tue, 12 Sep 2023 06:00:15 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235413AbjILNAI (ORCPT + 37 others); Tue, 12 Sep 2023 09:00:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235339AbjILM77 (ORCPT ); Tue, 12 Sep 2023 08:59:59 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A086510D8 for ; Tue, 12 Sep 2023 05:59:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694523595; x=1726059595; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uWBODskc0U2+ZZHSwiVmG/haTZP+gN8VzdgvjDqfqdE=; b=ef+P3D9nrT1m2ExT6RdxbbnddiVWLvD/uMqP0qIjeJBxQnaDPDoTTYRv XUkTfTwhzz8UDC3+MV3k/cQU6AAXwIhE/dg0Xi38WhSm+5vQDclpSZrLG 0HF8iOJMB/x4RSSfA1xnajEu+naI0pjSim+Lh2biyYasvM+xVAHUGfeB6 WQKbg8x/DoOGUhK+hGGCpBICIwdeeNFmD02xR0EOTvtf9Sd9PTsjmuZss 5ozt6/YXXjKiVsV3TX6uyyCdhD9FodJ9p0C/Gisx2spF1Kf/OFvui6uS/ Y0iay/9scLLshvh6pdtj0bJT01RcHZ/Cjc5sPJT137abNCXJoLOFVbJhi g==; X-IronPort-AV: E=McAfee;i="6600,9927,10831"; a="378277321" X-IronPort-AV: E=Sophos;i="6.02,139,1688454000"; d="scan'208";a="378277321" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Sep 2023 05:59:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10831"; a="858799310" X-IronPort-AV: E=Sophos;i="6.02,139,1688454000"; d="scan'208";a="858799310" Received: from tongshi-mobl.ccr.corp.intel.com (HELO tinazhan-desk1.intel.com) ([10.255.28.214]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Sep 2023 05:59:53 -0700 From: Tina Zhang To: Jason Gunthorpe , Kevin Tian , Lu Baolu Cc: Michael Shavit , Vasant Hegde , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Tina Zhang Subject: [PATCH v4 3/6] iommu: Introduce mm_get_pasid() helper function Date: Tue, 12 Sep 2023 20:59:33 +0800 Message-Id: <20230912125936.722348-4-tina.zhang@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230912125936.722348-1-tina.zhang@intel.com> References: <20230912125936.722348-1-tina.zhang@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Tue, 12 Sep 2023 06:00:16 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777017777037646800 X-GMAIL-MSGID: 1777017777037646800 Use the helper function mm_get_pasid() to get a mm assigned pasid value. The motivation is to replace mm->pasid with an iommu private data structure that is introduced in a later patch. Reviewed-by: Lu Baolu Signed-off-by: Tina Zhang --- Changes in v4: - Rebase to v6.6-rc1. Changes in v2: - Update commit message. - Let mm_get_enqcmd_pasid() call mm_get_pasid() to get pasid. drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 12 ++++++------ drivers/iommu/iommu-sva.c | 12 ++++++------ include/linux/iommu.h | 10 +++++++++- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c index 4d83edc2be99..dbb3af323ede 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c @@ -215,7 +215,7 @@ static void arm_smmu_mm_arch_invalidate_secondary_tlbs(struct mmu_notifier *mn, smmu_domain); } - arm_smmu_atc_inv_domain(smmu_domain, mm->pasid, start, size); + arm_smmu_atc_inv_domain(smmu_domain, mm_get_pasid(mm), start, size); } static void arm_smmu_mm_release(struct mmu_notifier *mn, struct mm_struct *mm) @@ -233,10 +233,10 @@ static void arm_smmu_mm_release(struct mmu_notifier *mn, struct mm_struct *mm) * DMA may still be running. Keep the cd valid to avoid C_BAD_CD events, * but disable translation. */ - arm_smmu_write_ctx_desc(smmu_domain, mm->pasid, &quiet_cd); + arm_smmu_write_ctx_desc(smmu_domain, mm_get_pasid(mm), &quiet_cd); arm_smmu_tlb_inv_asid(smmu_domain->smmu, smmu_mn->cd->asid); - arm_smmu_atc_inv_domain(smmu_domain, mm->pasid, 0, 0); + arm_smmu_atc_inv_domain(smmu_domain, mm_get_pasid(mm), 0, 0); smmu_mn->cleared = true; mutex_unlock(&sva_lock); @@ -290,7 +290,7 @@ arm_smmu_mmu_notifier_get(struct arm_smmu_domain *smmu_domain, goto err_free_cd; } - ret = arm_smmu_write_ctx_desc(smmu_domain, mm->pasid, cd); + ret = arm_smmu_write_ctx_desc(smmu_domain, mm_get_pasid(mm), cd); if (ret) goto err_put_notifier; @@ -315,7 +315,7 @@ static void arm_smmu_mmu_notifier_put(struct arm_smmu_mmu_notifier *smmu_mn) return; list_del(&smmu_mn->list); - arm_smmu_write_ctx_desc(smmu_domain, mm->pasid, NULL); + arm_smmu_write_ctx_desc(smmu_domain, mm_get_pasid(mm), NULL); /* * If we went through clear(), we've already invalidated, and no @@ -323,7 +323,7 @@ static void arm_smmu_mmu_notifier_put(struct arm_smmu_mmu_notifier *smmu_mn) */ if (!smmu_mn->cleared) { arm_smmu_tlb_inv_asid(smmu_domain->smmu, cd->asid); - arm_smmu_atc_inv_domain(smmu_domain, mm->pasid, 0, 0); + arm_smmu_atc_inv_domain(smmu_domain, mm_get_pasid(mm), 0, 0); } /* Frees smmu_mn */ diff --git a/drivers/iommu/iommu-sva.c b/drivers/iommu/iommu-sva.c index b78671a8a914..0f956ecd0c9b 100644 --- a/drivers/iommu/iommu-sva.c +++ b/drivers/iommu/iommu-sva.c @@ -23,7 +23,7 @@ static int iommu_sva_alloc_pasid(struct mm_struct *mm, struct device *dev) mutex_lock(&iommu_sva_lock); /* Is a PASID already associated with this mm? */ if (mm_valid_pasid(mm)) { - if (mm->pasid >= dev->iommu->max_pasids) + if (mm_get_pasid(mm) >= dev->iommu->max_pasids) ret = -EOVERFLOW; goto out; } @@ -73,7 +73,7 @@ struct iommu_sva *iommu_sva_bind_device(struct device *dev, struct mm_struct *mm mutex_lock(&iommu_sva_lock); /* Search for an existing domain. */ - domain = iommu_get_domain_for_dev_pasid(dev, mm->pasid, + domain = iommu_get_domain_for_dev_pasid(dev, mm_get_pasid(mm), IOMMU_DOMAIN_SVA); if (IS_ERR(domain)) { ret = PTR_ERR(domain); @@ -92,7 +92,7 @@ struct iommu_sva *iommu_sva_bind_device(struct device *dev, struct mm_struct *mm goto out_unlock; } - ret = iommu_attach_device_pasid(domain, dev, mm->pasid); + ret = iommu_attach_device_pasid(domain, dev, mm_get_pasid(mm)); if (ret) goto out_free_domain; domain->users = 1; @@ -124,7 +124,7 @@ EXPORT_SYMBOL_GPL(iommu_sva_bind_device); void iommu_sva_unbind_device(struct iommu_sva *handle) { struct iommu_domain *domain = handle->domain; - ioasid_t pasid = domain->mm->pasid; + ioasid_t pasid = mm_get_pasid(domain->mm); struct device *dev = handle->dev; mutex_lock(&iommu_sva_lock); @@ -141,7 +141,7 @@ u32 iommu_sva_get_pasid(struct iommu_sva *handle) { struct iommu_domain *domain = handle->domain; - return domain->mm->pasid; + return mm_get_pasid(domain->mm); } EXPORT_SYMBOL_GPL(iommu_sva_get_pasid); @@ -208,5 +208,5 @@ void mm_pasid_drop(struct mm_struct *mm) if (likely(!mm_valid_pasid(mm))) return; - iommu_free_global_pasid(mm->pasid); + iommu_free_global_pasid(mm_get_pasid(mm)); } diff --git a/include/linux/iommu.h b/include/linux/iommu.h index a4eab6697fe1..db2510da28c1 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -1189,10 +1189,14 @@ static inline bool mm_valid_pasid(struct mm_struct *mm) { return mm->pasid != IOMMU_PASID_INVALID; } -static inline u32 mm_get_enqcmd_pasid(struct mm_struct *mm) +static inline u32 mm_get_pasid(struct mm_struct *mm) { return mm->pasid; } +static inline u32 mm_get_enqcmd_pasid(struct mm_struct *mm) +{ + return mm_get_pasid(mm); +} void mm_pasid_drop(struct mm_struct *mm); struct iommu_sva *iommu_sva_bind_device(struct device *dev, struct mm_struct *mm); @@ -1215,6 +1219,10 @@ static inline u32 iommu_sva_get_pasid(struct iommu_sva *handle) } static inline void mm_pasid_init(struct mm_struct *mm) {} static inline bool mm_valid_pasid(struct mm_struct *mm) { return false; } +static inline u32 mm_get_pasid(struct mm_struct *mm) +{ + return IOMMU_PASID_INVALID; +} static inline u32 mm_get_enqcmd_pasid(struct mm_struct *mm) { return IOMMU_PASID_INVALID;