Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp4602479rwb; Tue, 8 Aug 2023 10:47:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHBl3uYePpnzHfhzETm/QNPnaLzclzP/+UQSRGKtFkW59tQlwBEkhDSRCmN43hOLUhnIqRk X-Received: by 2002:a17:90a:850b:b0:269:44a3:bd1e with SMTP id l11-20020a17090a850b00b0026944a3bd1emr244019pjn.40.1691516878436; Tue, 08 Aug 2023 10:47:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691516878; cv=none; d=google.com; s=arc-20160816; b=YtchwktXi46/ZI6qEpgVUIr6xDKCMnRozlPGT89Um7xiwSBEH1BaSdyUoTtYZPvULN nQhuUz1mIznMNopeRC3hqWUTuem2s13jiMjGJJgFHjUkwfwRg8e6bjhuf45CVJCi3GsB Tqr+4hgGOfa5GO2sd7jgINZn2bPvpQFCVzbsh4cZKqle6W6V+QKHd5Nwkhj/d8j4lUga FyfiaNckDYQlF/kW+IIUWCgnFXKDyNR+pkG/vhpiUcLo9xZH1nrWCIM4+6XhvuiEa8ts /J7znl0LQK6t8bggkVOhGttDUs71m16C97agWlFUppcMkxpAc8F3P1URiypyrdPGgUcd uBQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=hwrXlwWXnHgR5P1lHMKOpYke+9OenhFg6O6J3cnGbkI=; fh=/lTHmTEAhz5c6hgBRAPnmJsxw5vDTKZT1TYa5ynR+LA=; b=gqR19eaJ0gHsEmDJZ8Z3VGwb/I9Cie4WR2vxtUCOx0Fp2ChaECaRPs5OyMLVGzhW4m t8MAntagyYlI1jSVO3xmaUR4q0J5Lg7JD336PT8KeZKMKr3fEwjq6vPpq/gd9+z91EtD xhBFBOc40uVbzzYx5SflHwHSNTJBa8yxxgTaOpvIOE9Zss1Lo2qeMX/n+6W/Drr1T1Qr FHmYu8QVCMUXCShp0yHSbPUjjeJz8diTbiwUfztwhhBY8+A90tfpGq26joxFOnPokSHr 4cMBWCBOoOHrE+1zIQQCeUhvqgD8xfqToCH7OC6+u7U94VTZT0t0YscBd01POeosg609 hhpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=NDybL29k; 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 t18-20020a17090aba9200b00265e48c115csi10954752pjr.114.2023.08.08.10.47.42; Tue, 08 Aug 2023 10:47:58 -0700 (PDT) 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=NDybL29k; 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 S233011AbjHHQnl (ORCPT + 99 others); Tue, 8 Aug 2023 12:43:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233001AbjHHQmv (ORCPT ); Tue, 8 Aug 2023 12:42:51 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E3E516573 for ; Tue, 8 Aug 2023 08:55:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1691510129; x=1723046129; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=tYDiAH1fMYfUAOK/ZKaC0vqEIMfToxnpSe9pfv0ypY4=; b=NDybL29kdRitC1wvXkzUepoovrwTNiMuNO0b9aBY0Uwnip3jIlMnfhd2 PYqiT++SDWXXlHq39thYHoeNStnduc8htBEuyruacnUB1SXOQv41Igjab InFxOS9/NwAh3ejoABgYDC2a6GB7rLyHAB3Cvp6JAMQSz8HqIos062yHP wwnPsDh67Ds53zdk+ggErNZOr6MtWZk983KBWz271E+vmNzr66Z6vJWX1 /tumqlXBd4R9t7YW9W44eTMBsTj4TTgu+yW1/BCRd5RWxW3TizO8oAxZM BjtTS1KUhRpFJ+ub98FkTtU3u4gVJGtZQPAfRmqzRlpk63mkzLrtAteVd A==; X-IronPort-AV: E=McAfee;i="6600,9927,10795"; a="437078663" X-IronPort-AV: E=Sophos;i="6.01,263,1684825200"; d="scan'208";a="437078663" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Aug 2023 00:50:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10795"; a="681146298" X-IronPort-AV: E=Sophos;i="6.01,263,1684825200"; d="scan'208";a="681146298" Received: from kechen-optiplex-9020.bj.intel.com ([10.238.156.126]) by orsmga003.jf.intel.com with ESMTP; 08 Aug 2023 00:49:57 -0700 From: Tina Zhang To: Jason Gunthorpe , Kevin Tian , Lu Baolu , Michael Shavit Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Tina Zhang Subject: [PATCH 2/5] iommu: Call helper function to get assigned pasid value Date: Tue, 8 Aug 2023 15:49:41 +0800 Message-Id: <20230808074944.7825-3-tina.zhang@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230808074944.7825-1-tina.zhang@intel.com> References: <20230808074944.7825-1-tina.zhang@intel.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE,URIBL_BLOCKED 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 Use the helper function mm_get_pasid() to get the mm assigned pasid value. Signed-off-by: Tina Zhang --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 12 ++++++------ drivers/iommu/intel/svm.c | 8 ++++---- drivers/iommu/iommu-sva.c | 14 +++++++------- 3 files changed, 17 insertions(+), 17 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 a5a63b1c947e..0b455654d365 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 @@ -204,7 +204,7 @@ static void arm_smmu_mm_invalidate_range(struct mmu_notifier *mn, if (!(smmu_domain->smmu->features & ARM_SMMU_FEAT_BTM)) arm_smmu_tlb_inv_range_asid(start, size, smmu_mn->cd->asid, PAGE_SIZE, false, 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) @@ -222,10 +222,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); @@ -279,7 +279,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; @@ -304,7 +304,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 @@ -312,7 +312,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/intel/svm.c b/drivers/iommu/intel/svm.c index e95b339e9cdc..e6377cff6a93 100644 --- a/drivers/iommu/intel/svm.c +++ b/drivers/iommu/intel/svm.c @@ -306,13 +306,13 @@ static int intel_svm_bind_mm(struct intel_iommu *iommu, struct device *dev, unsigned long sflags; int ret = 0; - svm = pasid_private_find(mm->pasid); + svm = pasid_private_find(mm_get_pasid(mm)); if (!svm) { svm = kzalloc(sizeof(*svm), GFP_KERNEL); if (!svm) return -ENOMEM; - svm->pasid = mm->pasid; + svm->pasid = mm_get_pasid(mm); svm->mm = mm; INIT_LIST_HEAD_RCU(&svm->devs); @@ -350,7 +350,7 @@ static int intel_svm_bind_mm(struct intel_iommu *iommu, struct device *dev, /* Setup the pasid table: */ sflags = cpu_feature_enabled(X86_FEATURE_LA57) ? PASID_FLAG_FL5LP : 0; - ret = intel_pasid_setup_first_level(iommu, dev, mm->pgd, mm->pasid, + ret = intel_pasid_setup_first_level(iommu, dev, mm->pgd, mm_get_pasid(mm), FLPT_DEFAULT_DID, sflags); if (ret) goto free_sdev; @@ -364,7 +364,7 @@ static int intel_svm_bind_mm(struct intel_iommu *iommu, struct device *dev, free_svm: if (list_empty(&svm->devs)) { mmu_notifier_unregister(&svm->notifier, mm); - pasid_private_remove(mm->pasid); + pasid_private_remove(mm_get_pasid(mm)); kfree(svm); } diff --git a/drivers/iommu/iommu-sva.c b/drivers/iommu/iommu-sva.c index 05c0fb2acbc4..0a4a1ed40814 100644 --- a/drivers/iommu/iommu-sva.c +++ b/drivers/iommu/iommu-sva.c @@ -28,7 +28,7 @@ static int iommu_sva_alloc_pasid(struct mm_struct *mm, ioasid_t min, ioasid_t ma mutex_lock(&iommu_sva_lock); /* Is a PASID already associated with this mm? */ if (mm_valid_pasid(mm)) { - if (mm->pasid < min || mm->pasid > max) + if (mm_get_pasid(mm) < min || mm_get_pasid(mm) > max) ret = -EOVERFLOW; goto out; } @@ -71,7 +71,7 @@ struct iommu_sva *iommu_sva_bind_device(struct device *dev, struct mm_struct *mm if (!max_pasids) return ERR_PTR(-EOPNOTSUPP); - /* Allocate mm->pasid if necessary. */ + /* Allocate pasid if necessary. */ ret = iommu_sva_alloc_pasid(mm, 1, max_pasids - 1); if (ret) return ERR_PTR(ret); @@ -82,7 +82,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); @@ -101,7 +101,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; @@ -133,7 +133,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); @@ -150,7 +150,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); @@ -217,5 +217,5 @@ void mm_pasid_drop(struct mm_struct *mm) if (likely(!mm_valid_pasid(mm))) return; - ida_free(&iommu_global_pasid_ida, mm->pasid); + ida_free(&iommu_global_pasid_ida, mm_get_pasid(mm)); } -- 2.17.1