From patchwork Tue Aug 8 07:49:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Tina" X-Patchwork-Id: 132732 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp2328924vqr; Tue, 8 Aug 2023 11:55:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHtV6aCMk0GaT8EjSfKsKWAHV/ShaQ1JtMHPszSf+IqQx4dl8xpV0UHb6VLVxccvQ0uWGNE X-Received: by 2002:a17:902:dac3:b0:1bb:f669:e856 with SMTP id q3-20020a170902dac300b001bbf669e856mr13164197plx.27.1691520956309; Tue, 08 Aug 2023 11:55:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691520956; cv=none; d=google.com; s=arc-20160816; b=JpZnsRhsuqUdsiVOzOsOweQS9L5rx6w5XTx3Hes30wmmtZQ42z8duMW/pSsdg7DRPD BQ1soGY5NGwMU2tgMdvZo/jjMusLuKwUOYAfce4bQ2uLXQflV1wLTzH9JuFN82+tTsX1 obDQXanJOezH1iw/9ymzXpzocN7zECIKP/4Yw9Go4rzEl5Of1CkIJX6SQ17Nk1IeK71/ S1wSeovHQdBRcKAoiXF7rDfBrrAwRNd+WsgEMJiPqhprtQhKLhIF/ZTXwwH+c2GZ7jwZ rFawn5UFgFjxOeXs0rLkRFyGuicfXn7MFw51pxKPJIzZO7hLDg6i6eklmSSf0WsuHCRB RE9A== 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=qABHr0MVq9K8OFDMUR2uH3R16FK+1ZBhSMiJ8AFkD4c=; fh=/lTHmTEAhz5c6hgBRAPnmJsxw5vDTKZT1TYa5ynR+LA=; b=f1JnRtfKhukhBAsqQo22oNmbABLE4WxeX0Il+Ve6bkSfo4LeuZ2OH9Y2S6VWi+wk5q dUSVHNll1k0l70H2HNdK0ms+bS5mBOXB+5nFkSiW0vmf8doXf13yPX6Db5daWqId/XKe V0ptnaof7x0V2Z5hwENibH8WAdtOgkuBe5bjOOCZQRQBK7Ty4PJEotl2vWyLDaFE0r+T H9OFEzGqVaZEMAeEcUA15FYRLSgtro8klY+V8CFyPBgrYWQeMqFFFFFILIKy/HrJdE6H w2EEfZLNh44PcyGaw6lbuY+Uyhr8T43fvw9ZREq93OOCPPYyNrdqMfHvWgyj5862BFwH JLHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=d8sCkdvS; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t3-20020a6549c3000000b00563477c3519si7288414pgs.488.2023.08.08.11.55.42; Tue, 08 Aug 2023 11:55:56 -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=d8sCkdvS; 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 S233062AbjHHQmy (ORCPT + 99 others); Tue, 8 Aug 2023 12:42:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233339AbjHHQmF (ORCPT ); Tue, 8 Aug 2023 12:42:05 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 648093DE36 for ; Tue, 8 Aug 2023 08:55:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1691510112; x=1723046112; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=A507Xs1crKDCNKJRmv5uCTlfgOCIAdl3cBwBkuALTds=; b=d8sCkdvSY+2/5Jy7IBlrAmH2+4Cw9hlFN+PUTfW/9L0pc8mX19/S59QN X01IxFeOJ5FYTXhjsv+/rJfAbTzFpvE4r7suXYs4p4VZYUIkvW6qp9Sap ascA4T+w9nKZtqBPj8tP+em5betumioyaTAD5jbf0x5HFJe5dxUy+QTUf ykk0xdeunqRzBTEYebnDctk/5m5baL/ojifz9wmy8D8+6+QSErJfE97oz 1dGQ55OcGsjVXUjcYSEUBWrLi/y9RYS+ekLvdy0YRrrrWEtNbSG54UVTj C2GfamrHQUWpkikVKq8DYRDwK5z1oz+12JhIN/rpiBLdCbXBlWMOnFPbp g==; X-IronPort-AV: E=McAfee;i="6600,9927,10795"; a="437078656" X-IronPort-AV: E=Sophos;i="6.01,263,1684825200"; d="scan'208";a="437078656" 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:49:59 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10795"; a="681146272" X-IronPort-AV: E=Sophos;i="6.01,263,1684825200"; d="scan'208";a="681146272" Received: from kechen-optiplex-9020.bj.intel.com ([10.238.156.126]) by orsmga003.jf.intel.com with ESMTP; 08 Aug 2023 00:49:51 -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 1/5] iommu: Add mm_get_pasid() helper function Date: Tue, 8 Aug 2023 15:49:40 +0800 Message-Id: <20230808074944.7825-2-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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773688277922493224 X-GMAIL-MSGID: 1773688277922493224 mm_get_pasid() is for getting mm pasid value. The motivation is to replace mm->pasid with an iommu private data structure that is introduced in a later patch. Signed-off-by: Tina Zhang --- arch/x86/kernel/traps.c | 2 +- include/linux/iommu.h | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c index 4a817d20ce3b..6e259b11cd87 100644 --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c @@ -678,7 +678,7 @@ static bool try_fixup_enqcmd_gp(void) if (!mm_valid_pasid(current->mm)) return false; - pasid = current->mm->pasid; + pasid = mm_get_pasid(current->mm); /* * Did this thread already have its PASID activated? diff --git a/include/linux/iommu.h b/include/linux/iommu.h index d31642596675..30e4d1ca39b5 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -1180,6 +1180,10 @@ static inline bool mm_valid_pasid(struct mm_struct *mm) { return mm->pasid != IOMMU_PASID_INVALID; } +static inline u32 mm_get_pasid(struct mm_struct *mm) +{ + return mm->pasid; +} void mm_pasid_drop(struct mm_struct *mm); struct iommu_sva *iommu_sva_bind_device(struct device *dev, struct mm_struct *mm); @@ -1202,6 +1206,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 void mm_pasid_drop(struct mm_struct *mm) {} #endif /* CONFIG_IOMMU_SVA */ From patchwork Tue Aug 8 07:49:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Tina" X-Patchwork-Id: 132641 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp2293702vqr; Tue, 8 Aug 2023 10:54:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEtkYdkdm/sDgU5XUkSW0dFQgIHDd+rT1CPp7wrdWAzY6e0N4VV6T2JcyP81JM/ozaTgl9G X-Received: by 2002:a17:90a:ca07:b0:268:d05c:2d7e with SMTP id x7-20020a17090aca0700b00268d05c2d7emr285598pjt.14.1691517243814; Tue, 08 Aug 2023 10:54:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691517243; cv=none; d=google.com; s=arc-20160816; b=n/zH9t8Zvje5a7C6Fz/IAlL2bPUfz3X4o/Qi4lnNE7DvJ8WagmU2r7VIEYCGJnfT7z EDDkiHy2Tf3ujgrJWK4jVLtDTUN3qKjFYEUx6SomWX4eSO1LTHBSR8EKaYOdr0PPNVRO Nn7sYCEGvbuRprlG2581soTV7SO2Uyq9g0gcrEKeXcFYataDaksYkoBF0+yK+/0lTIH4 WzdUONHssUR0+xtGdwB0WD7kMkJIcY+dUCOeUJsUKfD135kMEkky2u+Oak81TdudP6lB LhQsXaD432qh172sEoaPznTTYuTRMBC5ENAUJ+hw1aL1Lp/4mFLDghQomxug/+A1WrrM HiCQ== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mz4-20020a17090b378400b0026843142db7si10897995pjb.113.2023.08.08.10.53.50; Tue, 08 Aug 2023 10:54:03 -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 S233302AbjHHQnl (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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773684385232754560 X-GMAIL-MSGID: 1773684385232754560 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)); } From patchwork Tue Aug 8 07:49:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Tina" X-Patchwork-Id: 132629 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp2291466vqr; Tue, 8 Aug 2023 10:50:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEZqOjWizptjMH2GRCCy4ld+qfOfhWxzB3IpGSTtS9sV4fXv4Wug2LQRotgP5lgu8nr+4p2 X-Received: by 2002:a05:6a21:3b46:b0:137:8ddf:464b with SMTP id zy6-20020a056a213b4600b001378ddf464bmr166649pzb.36.1691517009660; Tue, 08 Aug 2023 10:50:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691517009; cv=none; d=google.com; s=arc-20160816; b=BGCTgd+5nxz7yY1NlNNiWvUv/yZKCiCPQSRjPR8inmeWig3s+JfKPy42zrnTazopQ7 DJ0xBgXS6yQUr6y2ToaLt95Higc8iwO5MiOjSsy/hcjU1qTd7gWbKeNI3pgsxxQZskYv zi3fyWboptfWZmlBju7EQ6oQvtxOJ1v9vljgYkXaiGZT20Eh1AF3aC5MkllDWWFe6wk5 kpjIckH9svyQItFUHBhXBR+yX4wQE7X1oghlrETgtVQ+wh0vvbJuLG22EriTeL4/da5a esFKXHupb0D9LhZNCyRxJ4mXHvgusZnD4Zy9pcjJR2BWEUzZiVZI46GJQvVlhugxJVcn XrTw== 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=DZW1mbxT0iFwJnNs0K13zoKD84DxDa15fA2yBWLZhGY=; fh=/lTHmTEAhz5c6hgBRAPnmJsxw5vDTKZT1TYa5ynR+LA=; b=rsQ8SWO6fWV8wCNPFoEX4zoKdGIuoKi2OCUi0f5aqhvfzaR4VqOiYVFDlUQg7gvoeF 3iov4eP4fXaNOhWx5UU8NNMgELyMBWvI8mgylypUn0Qsc4LZMcGmAIr1PiSyQYXW/5Mb 3bxbkt/ySVe92bUStureEmuYa9nVjuuk43S0fl95qXrzytOFlb7tEpLnFDsN8TjXfwyO be/8EqdSy9EB0lNlO0ceAJsgZs+Rni0lxqqBlJ8Jfc4k/TXBiQVTdjmvXzufQl0pPXWu SEywoW7rWZdh24BNyinuMtBUKEK6pKRhLNNNYwo3ZzUMfoOqE8ATcbiLE1xsR3vlZu9w T+Pw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=gJsxNnNl; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w23-20020a639357000000b00564b8e55214si5925190pgm.385.2023.08.08.10.49.55; Tue, 08 Aug 2023 10:50:09 -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=gJsxNnNl; 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 S233318AbjHHQnq (ORCPT + 99 others); Tue, 8 Aug 2023 12:43:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233120AbjHHQm5 (ORCPT ); Tue, 8 Aug 2023 12:42:57 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A939516578 for ; Tue, 8 Aug 2023 08:55:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1691510131; x=1723046131; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=lp2BCntolGG4mTS6F0ktq7rcph+RoXn5XygwILHKL8k=; b=gJsxNnNlVpD4h2H/u22UJdqSHBda8ZzXkCSpGsy9EvznFmfjO1BkMRIY qAsKy/OjueO38cNdAfvDDb84Wv+AzICdJ3wbaSDbUuO99YPtr5Ejf28dX hBvF0Rbcz8HjQMidX2wLUXG6iSfXmY/HvSpXYF3GFscfjQx+bGphqK7eY 7zqFmEx2unLz6kN2V31AVL7szy8jPZKapDpW5DIKFGDFcQJB/1uqHogc9 OoJaGJu+UBCOLhVMklmtTUOI3MsK28o5xOZDTECwooB8wc1m2AT6REEEo 83mkfDG/G68Md0qlEzax+h7BEwhfO18tcjJcFO3cZ/ZDG+nXeRsafmucz w==; X-IronPort-AV: E=McAfee;i="6600,9927,10795"; a="437078680" X-IronPort-AV: E=Sophos;i="6.01,263,1684825200"; d="scan'208";a="437078680" 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:02 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10795"; a="681146338" X-IronPort-AV: E=Sophos;i="6.01,263,1684825200"; d="scan'208";a="681146338" Received: from kechen-optiplex-9020.bj.intel.com ([10.238.156.126]) by orsmga003.jf.intel.com with ESMTP; 08 Aug 2023 00:50:00 -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 3/5] mm: Add structure to keep sva information Date: Tue, 8 Aug 2023 15:49:42 +0800 Message-Id: <20230808074944.7825-4-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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773684140147658046 X-GMAIL-MSGID: 1773684140147658046 Introduce iommu_mm_data structure to keep sva information (pasid and the related sva domains). Add iommu_mm pointer, pointing to an instance of iommu_mm_data structure, to mm. Signed-off-by: Tina Zhang --- include/linux/iommu.h | 5 +++++ include/linux/mm_types.h | 2 ++ 2 files changed, 7 insertions(+) diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 30e4d1ca39b5..435d1c1afd23 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -670,6 +670,11 @@ struct iommu_sva { struct iommu_domain *domain; }; +struct iommu_mm_data { + u32 pasid; + struct list_head sva_domains; +}; + int iommu_fwspec_init(struct device *dev, struct fwnode_handle *iommu_fwnode, const struct iommu_ops *ops); void iommu_fwspec_free(struct device *dev); diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 5e74ce4a28cd..3fd65b7537f0 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -595,6 +595,7 @@ struct mm_cid { #endif struct kioctx_table; +struct iommu_mm_data; struct mm_struct { struct { /* @@ -808,6 +809,7 @@ struct mm_struct { #ifdef CONFIG_IOMMU_SVA u32 pasid; + struct iommu_mm_data *iommu_mm; #endif #ifdef CONFIG_KSM /* From patchwork Tue Aug 8 07:49:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Tina" X-Patchwork-Id: 132725 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp2328471vqr; Tue, 8 Aug 2023 11:54:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF1U+bSA8bZ2oE238Vc02/GGJVoeVibY86bW42waJjIp1jm3MATpLwP7qfvbom9hntREuc+ X-Received: by 2002:a05:6a00:1884:b0:66c:a45:f00b with SMTP id x4-20020a056a00188400b0066c0a45f00bmr400045pfh.23.1691520898151; Tue, 08 Aug 2023 11:54:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691520898; cv=none; d=google.com; s=arc-20160816; b=gFrlHoA73TEnIuKkLeiJG2Zxdvo6r7T1GYmNay/7bbd/GY0LKENQmEQYIjFV1cW4nX 9i+af7oEReAhO+M9lBDrnhUzZH6Bpjnd+UZ2wYYrjfD5SBUzMBFmjouaGq/o/MT1qILG 1OJNs9A/R/OOUVCpVPHlpU4QWC/HiSeH8OBA7YptjqwW0TEpV3mQPKCUf6cTCboXhc+n IlsCrT0HHhzC7CKTPsUV5yGFddFjVzxKDZE3J325FGGuqEfr3+hb7lE2wPRrFGxmnKEL G9wKvXFQvL71tlnS5gxMnZLfrni8gdiwmGODTc76bVFqCnV5njjU37CwT/87FU4G9iFw 48eA== 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=9ufdnkDvxL10Z4assMNKiKS1ZN/LmP71ii+bjfYsC8U=; fh=/lTHmTEAhz5c6hgBRAPnmJsxw5vDTKZT1TYa5ynR+LA=; b=YknmMiFzv/Tcu4fyIlTwd+XFEJbyJt2RIrinABL0pHPY0261rcE0STK1jhnO82t/0t 4rY/UcIEPlkhaAuPVeQ+OzZkxhLyv9hVuOFW+hW9MifQPL4ig1lCTM4//mLEDBLHixm1 34L7u/dgOX191ECN9TUzSv86FQ7YGJhfaxEe1AjU0rINBx8J8gcMej8keyMnFg+LhL7u lh1wCcTGDyL7xN2q9TS7x50BLo5m5YAgljE4WL09SbCivWtBYtL0i2eLsS75vWCdtrWc 8uzxJoFiQRii4P4G/bmdqd9UbyIAUwkXeCY7TMdpAdltfX2Zhf93x89FQY5cxbbpqhZ/ sYFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=CU+03GQQ; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t30-20020a63955e000000b005443c85156bsi7796923pgn.222.2023.08.08.11.54.44; Tue, 08 Aug 2023 11:54: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=CU+03GQQ; 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 S233340AbjHHQoF (ORCPT + 99 others); Tue, 8 Aug 2023 12:44:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233283AbjHHQnT (ORCPT ); Tue, 8 Aug 2023 12:43:19 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8DE5C55BE for ; Tue, 8 Aug 2023 08:55:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1691510140; x=1723046140; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=myuEuHSAILfOpPq4xlnak3sZ+xUPplX7XLY6m7PLmVQ=; b=CU+03GQQ9mSjVpBtIpL9nud1fkd9DAzhFGu+k+lh+m7G55i9d8ASR8Ik 9/9ISSt5uLa+bI7umvw3dNJyNxVgS4pBXkN47IHc8IFJHkhG80pejRsr4 zF0UB/sQyEt4o433g1kd97JTLAlwOktB+kBWRffWH/mlXXWVOalBD9mcH 0AGEBI8aexYIbsDyKbSxZbzZ1k786UYasaxK90e6gAOj4XtzUxR32tMU6 uIi9zP1jL0+sMhPVL+XsQwoM2ijI6iZa7Z7Byp3HAy/h/rhrSOkJO0FNK lls0OGeMDFsL51hrp3p/KnXNH0J3FNy67epOZrXYfClEJHp/2gVLUCy8J w==; X-IronPort-AV: E=McAfee;i="6600,9927,10795"; a="437078693" X-IronPort-AV: E=Sophos;i="6.01,263,1684825200"; d="scan'208";a="437078693" 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:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10795"; a="681146403" X-IronPort-AV: E=Sophos;i="6.01,263,1684825200"; d="scan'208";a="681146403" Received: from kechen-optiplex-9020.bj.intel.com ([10.238.156.126]) by orsmga003.jf.intel.com with ESMTP; 08 Aug 2023 00:50:02 -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 4/5] iommu: Support mm PASID 1:n with sva domains Date: Tue, 8 Aug 2023 15:49:43 +0800 Message-Id: <20230808074944.7825-5-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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773679704454359348 X-GMAIL-MSGID: 1773688217714020785 Each mm bound to devices gets a PASID and corresponding sva domains allocated in iommu_sva_bind_device(), which are referenced by iommu_mm field of the mm. The PASID is released in __mmdrop(), while a sva domain is released when on one is using it (the reference count is decremented in iommu_sva_unbind_device()). Since the required info of PASID and sva domains is kept in struct iommu_mm_data of a mm, use mm->iommu_mm field instead of the old pasid field in mm struct. The sva domain list is protected by iommu_sva_lock. Besides, this patch removes mm_pasid_init(), as with the introduced iommu_mm structure, initializing mm pasid in mm_init() is unnecessary. Signed-off-by: Tina Zhang --- drivers/iommu/iommu-sva.c | 38 +++++++++++++++++++++++++------------- include/linux/iommu.h | 10 +++------- kernel/fork.c | 1 - 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/drivers/iommu/iommu-sva.c b/drivers/iommu/iommu-sva.c index 0a4a1ed40814..35366f51ad27 100644 --- a/drivers/iommu/iommu-sva.c +++ b/drivers/iommu/iommu-sva.c @@ -15,6 +15,7 @@ static DEFINE_IDA(iommu_global_pasid_ida); /* Allocate a PASID for the mm within range (inclusive) */ static int iommu_sva_alloc_pasid(struct mm_struct *mm, ioasid_t min, ioasid_t max) { + struct iommu_mm_data *iommu_mm = NULL; int ret = 0; if (min == IOMMU_PASID_INVALID || @@ -33,11 +34,22 @@ static int iommu_sva_alloc_pasid(struct mm_struct *mm, ioasid_t min, ioasid_t ma goto out; } + iommu_mm = kzalloc(sizeof(struct iommu_mm_data), GFP_KERNEL); + if (!iommu_mm) { + ret = -ENOMEM; + goto out; + } + ret = ida_alloc_range(&iommu_global_pasid_ida, min, max, GFP_KERNEL); - if (ret < 0) + if (ret < 0) { + kfree(iommu_mm); goto out; + } + + iommu_mm->pasid = ret; + mm->iommu_mm = iommu_mm; + INIT_LIST_HEAD(&mm->iommu_mm->sva_domains); - mm->pasid = ret; ret = 0; out: mutex_unlock(&iommu_sva_lock); @@ -82,16 +94,12 @@ 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_get_pasid(mm), - IOMMU_DOMAIN_SVA); - if (IS_ERR(domain)) { - ret = PTR_ERR(domain); - goto out_unlock; - } - - if (domain) { - domain->users++; - goto out; + list_for_each_entry(domain, &mm->iommu_mm->sva_domains, next) { + ret = iommu_attach_device_pasid(domain, dev, mm_get_pasid(mm)); + if (!ret) { + domain->users++; + goto out; + } } /* Allocate a new domain and set it on device pasid. */ @@ -105,6 +113,8 @@ struct iommu_sva *iommu_sva_bind_device(struct device *dev, struct mm_struct *mm if (ret) goto out_free_domain; domain->users = 1; + list_add(&domain->next, &mm->iommu_mm->sva_domains); + out: mutex_unlock(&iommu_sva_lock); handle->dev = dev; @@ -137,8 +147,9 @@ void iommu_sva_unbind_device(struct iommu_sva *handle) struct device *dev = handle->dev; mutex_lock(&iommu_sva_lock); + iommu_detach_device_pasid(domain, dev, pasid); if (--domain->users == 0) { - iommu_detach_device_pasid(domain, dev, pasid); + list_del(&domain->next); iommu_domain_free(domain); } mutex_unlock(&iommu_sva_lock); @@ -218,4 +229,5 @@ void mm_pasid_drop(struct mm_struct *mm) return; ida_free(&iommu_global_pasid_ida, mm_get_pasid(mm)); + kfree(mm->iommu_mm); } diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 435d1c1afd23..6a87df6d8637 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -109,6 +109,7 @@ struct iommu_domain { struct { /* IOMMU_DOMAIN_SVA */ struct mm_struct *mm; int users; + struct list_head next; }; }; }; @@ -1177,17 +1178,13 @@ static inline bool tegra_dev_iommu_get_stream_id(struct device *dev, u32 *stream } #ifdef CONFIG_IOMMU_SVA -static inline void mm_pasid_init(struct mm_struct *mm) -{ - mm->pasid = IOMMU_PASID_INVALID; -} static inline bool mm_valid_pasid(struct mm_struct *mm) { - return mm->pasid != IOMMU_PASID_INVALID; + return mm->iommu_mm ? true : false; } static inline u32 mm_get_pasid(struct mm_struct *mm) { - return mm->pasid; + return mm->iommu_mm ? mm->iommu_mm->pasid : IOMMU_PASID_INVALID; } void mm_pasid_drop(struct mm_struct *mm); struct iommu_sva *iommu_sva_bind_device(struct device *dev, @@ -1209,7 +1206,6 @@ static inline u32 iommu_sva_get_pasid(struct iommu_sva *handle) { return IOMMU_PASID_INVALID; } -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) { diff --git a/kernel/fork.c b/kernel/fork.c index d2e12b6d2b18..f06392dd1ca8 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -1274,7 +1274,6 @@ static struct mm_struct *mm_init(struct mm_struct *mm, struct task_struct *p, mm_init_cpumask(mm); mm_init_aio(mm); mm_init_owner(mm, p); - mm_pasid_init(mm); RCU_INIT_POINTER(mm->exe_file, NULL); mmu_notifier_subscriptions_init(mm); init_tlb_flush_pending(mm); From patchwork Tue Aug 8 07:49:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Tina" X-Patchwork-Id: 132578 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp2277619vqr; Tue, 8 Aug 2023 10:26:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IESgXCyvWXcFK5x9yT9EH2mJvl7/pg6YZBN+6h9dI+HM8rx9xjEYMz+vxIwRECMEAVbCmcY X-Received: by 2002:a05:6a21:3390:b0:140:a6ec:b56a with SMTP id yy16-20020a056a21339000b00140a6ecb56amr188509pzb.3.1691515609075; Tue, 08 Aug 2023 10:26:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691515609; cv=none; d=google.com; s=arc-20160816; b=T/8Bboa+Kve4DtFzH+cejjEO7FF5WaFD0E5SD34nG76TP9OKlNEDRLgxE+iVQ56lXA 6GjIizrArU1DS92ZbXLo4qyyI60nFqb0JrpTjLy6fvHM6f6gS50Uz6+6o/I5oQuWuCPx RSo+VKYPyEAjBZQFfJJhs3tZ3rDI4xPl1nGygnqSatoG3bmTqOIA1tkI8T0QEXIzARRI kOIIqwCmy8pq+lvMy6wrL+mBZwDmSffeGvyTAM9xxg2mdO7B8VVZp0KpGuto/yLTV+uC LIj+v1PXNWFg76aBrRORnAjIdQwBY2vXochQ1VNPo4DuW3/LBlZSpn9zFZudcODrV9G/ RkjQ== 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=EA6CGSY4cqRnEOjFp5kgQRSqBh30K2OQuevE3excNMw=; fh=/lTHmTEAhz5c6hgBRAPnmJsxw5vDTKZT1TYa5ynR+LA=; b=KvfJ49XoUHlnR61vrKZw5uYk+kuJOnlkVlPVnuALnDjYXLB2dV4isBHOK1U0RRHksL +tG3QaJkbJ/PQbnWSDjQGbcHWr65/KYZ6/gzyPh2ZAnT/m+YtFWSUlisboadGtcR/gej AOMO62+N0XLUscZxfonxwpbMtYwOm4U6vF8YTl92rrNpKmxs9OHIbo4lrHLBNVqJDkwm 8sqOm5ShVqcwVZKNL18S0wyu2MvmTNrZEa61zNqbLEm/bvEMBaOHG6TsuziEIeu8713p XGgIYIoqkFqDK0Fc6mZ2Rl3UX0A6WEWe9BTNGXFJSR7EW9VdLs2L96VfBDow9X4XGtWm 4cgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=A1Rd1L7b; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id fb36-20020a056a002da400b00686ae67b95bsi7626922pfb.225.2023.08.08.10.26.36; Tue, 08 Aug 2023 10:26:49 -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=A1Rd1L7b; 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 S233365AbjHHQoe (ORCPT + 99 others); Tue, 8 Aug 2023 12:44:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232829AbjHHQnk (ORCPT ); Tue, 8 Aug 2023 12:43:40 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3B3D91A3 for ; Tue, 8 Aug 2023 08:55:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1691510153; x=1723046153; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=G2jQdPpYRftTNVodh55koMoZtJhLjKxrlqOJq+ORzpU=; b=A1Rd1L7bR1BPzaq/aBMbePLUqBcwgb3AkeaYIqKCAX8A3uybvplC2HuT RIywbjKTXRyCMphmRLSF3Qb/OcrmplT7cWt1Z0sPPCVroZD32211E8wfQ vc1+SbtS9e6pQKh3wfuxa4Jb6EDqrbCV9IJ6k/QEBWISiMgT5IKt/hH3f qrulmnzymJ3K7NEH5rQ+f9pebtozqANSHqQCH9O4MFvbcZyUf34lidwYi DR/E4OkYXjlxDSE/Ro1gDGKkbyF4o8D+xiwbbaN77CSl3WrC4Krndql24 cQxc33VHT3VtaJEnFvHcJOzfw7nFnq4HtQwCYRD/JAElMTBWZBqs6QNxM g==; X-IronPort-AV: E=McAfee;i="6600,9927,10795"; a="437078719" X-IronPort-AV: E=Sophos;i="6.01,263,1684825200"; d="scan'208";a="437078719" 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:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10795"; a="681146448" X-IronPort-AV: E=Sophos;i="6.01,263,1684825200"; d="scan'208";a="681146448" Received: from kechen-optiplex-9020.bj.intel.com ([10.238.156.126]) by orsmga003.jf.intel.com with ESMTP; 08 Aug 2023 00:50:05 -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 5/5] mm: Deprecate pasid field Date: Tue, 8 Aug 2023 15:49:44 +0800 Message-Id: <20230808074944.7825-6-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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773682671229650971 X-GMAIL-MSGID: 1773682671229650971 Drop the pasid field, as all the information needed for sva domain management has been moved to the newly added iommu_mm field. Signed-off-by: Tina Zhang --- include/linux/mm_types.h | 1 - mm/init-mm.c | 3 --- 2 files changed, 4 deletions(-) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 3fd65b7537f0..6cb5cc53c480 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -808,7 +808,6 @@ struct mm_struct { struct work_struct async_put_work; #ifdef CONFIG_IOMMU_SVA - u32 pasid; struct iommu_mm_data *iommu_mm; #endif #ifdef CONFIG_KSM diff --git a/mm/init-mm.c b/mm/init-mm.c index efa97b57acfd..69719291463e 100644 --- a/mm/init-mm.c +++ b/mm/init-mm.c @@ -42,9 +42,6 @@ struct mm_struct init_mm = { #endif .user_ns = &init_user_ns, .cpu_bitmap = CPU_BITS_NONE, -#ifdef CONFIG_IOMMU_SVA - .pasid = IOMMU_PASID_INVALID, -#endif INIT_MM_CONTEXT(init_mm) };