Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp2623287rdb; Tue, 12 Sep 2023 07:30:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG2PgunrOfDe1hddwWGp/jt1nnI6XCZUNcF5zf+C8xATdJaPVg9TtasZmlV97O9lzR9hPEq X-Received: by 2002:a17:90b:1958:b0:26b:698f:dda7 with SMTP id nk24-20020a17090b195800b0026b698fdda7mr10613941pjb.32.1694529024628; Tue, 12 Sep 2023 07:30:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694529024; cv=none; d=google.com; s=arc-20160816; b=cMsQLHCbyNQ35YXTlIj7vUMIcvvBAkfmincqwMqVBT2yaDNQhfCiYl/rJRHU9S02/o NencUYFSK+dsPIdHT2/w2CGyN4RkoVXLOvg1afgi2vFZYPKEnvltpoEVNpH5a2JCADgc uovyoQTPRB1/IviXEYTWMNarfe4XpZVMXECxNx++JRtDR8X/xlpq2u2wwz7qucXuqePt LS9tjFImVLN7E8T+9RWFCtdKZj9U+BvJbVwLos7UTRsrRh2tBjqVEr7AAqM2nzBXLeEN G8jyOtU/tIQ0k8NWQ7XfZcBKWwmN52xUDby3IYKGf8N+IJZSCy6FoUW5LaW2sCFcsvig NFsg== 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 2620:137:e000::3:1 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 morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id r9-20020a17090a940900b0026830486bdasi7904449pjo.118.2023.09.12.07.30.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 07:30:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; 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 2620:137:e000::3:1 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 morse.vger.email (Postfix) with ESMTP id 68ED48095DCE; Tue, 12 Sep 2023 06:00:47 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.8 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235369AbjILNAH (ORCPT + 99 others); Tue, 12 Sep 2023 09:00:07 -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 Content-Transfer-Encoding: 8bit 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 (morse.vger.email [0.0.0.0]); Tue, 12 Sep 2023 06:00:47 -0700 (PDT) X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email 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; -- 2.34.1