Linux IOMMU Development
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@nvidia.com>
To: Lu Baolu <baolu.lu@linux.intel.com>,
	David Woodhouse <dwmw2@infradead.org>,
	iommu@lists.linux.dev, Joerg Roedel <joro@8bytes.org>,
	Robin Murphy <robin.murphy@arm.com>,
	Will Deacon <will@kernel.org>
Cc: patches@lists.linux.dev, Wei Wang <wei.w.wang@intel.com>
Subject: [PATCH v2 2/7] iommu/vt-d: Fold domain_exit() into intel_iommu_domain_free()
Date: Thu, 12 Jun 2025 11:31:34 -0300	[thread overview]
Message-ID: <2-v2-e5c01fc5ce82+26216-vtd_prep_jgg@nvidia.com> (raw)
In-Reply-To: <0-v2-e5c01fc5ce82+26216-vtd_prep_jgg@nvidia.com>

It has only one caller, no need for two functions.

Correct the WARN_ON() error handling to leak the entire page table if the
HW is still referencing it so we don't UAF during WARN_ON recovery.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/iommu/intel/iommu.c | 38 ++++++++++++++++++-------------------
 1 file changed, 18 insertions(+), 20 deletions(-)

diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index b42bb091088ff5..7119f4be1b1393 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -1396,23 +1396,6 @@ void domain_detach_iommu(struct dmar_domain *domain, struct intel_iommu *iommu)
 	}
 }
 
-static void domain_exit(struct dmar_domain *domain)
-{
-	if (domain->pgd) {
-		struct iommu_pages_list freelist =
-			IOMMU_PAGES_LIST_INIT(freelist);
-
-		domain_unmap(domain, 0, DOMAIN_MAX_PFN(domain->gaw), &freelist);
-		iommu_put_pages_list(&freelist);
-	}
-
-	if (WARN_ON(!list_empty(&domain->devices)))
-		return;
-
-	kfree(domain->qi_batch);
-	kfree(domain);
-}
-
 /*
  * For kdump cases, old valid entries may be cached due to the
  * in-flight DMA and copied pgtable, but there is no unmapping
@@ -3392,9 +3375,24 @@ static void intel_iommu_domain_free(struct iommu_domain *domain)
 {
 	struct dmar_domain *dmar_domain = to_dmar_domain(domain);
 
-	WARN_ON(dmar_domain->nested_parent &&
-		!list_empty(&dmar_domain->s1_domains));
-	domain_exit(dmar_domain);
+	if (WARN_ON(dmar_domain->nested_parent &&
+		!list_empty(&dmar_domain->s1_domains)))
+		return;
+
+	if (WARN_ON(!list_empty(&dmar_domain->devices)))
+		return;
+
+	if (dmar_domain->pgd) {
+		struct iommu_pages_list freelist =
+			IOMMU_PAGES_LIST_INIT(freelist);
+
+		domain_unmap(dmar_domain, 0, DOMAIN_MAX_PFN(dmar_domain->gaw),
+			     &freelist);
+		iommu_put_pages_list(&freelist);
+	}
+
+	kfree(dmar_domain->qi_batch);
+	kfree(dmar_domain);
 }
 
 int paging_domain_compatible(struct iommu_domain *domain, struct device *dev)
-- 
2.43.0


  parent reply	other threads:[~2025-06-12 14:31 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-12 14:31 [PATCH v2 0/7] Reorganize Intel VT-D to be ready for iommupt Jason Gunthorpe
2025-06-12 14:31 ` [PATCH v2 1/7] iommu/vt-d: Lift the __pa to domain_setup_first_level/intel_svm_set_dev_pasid() Jason Gunthorpe
2025-06-13  9:31   ` Tian, Kevin
2025-06-12 14:31 ` Jason Gunthorpe [this message]
2025-06-13  9:32   ` [PATCH v2 2/7] iommu/vt-d: Fold domain_exit() into intel_iommu_domain_free() Tian, Kevin
2025-06-12 14:31 ` [PATCH v2 3/7] iommu/vt-d: Do not wipe out the page table NID when devices detach Jason Gunthorpe
2025-06-13  9:33   ` Tian, Kevin
2025-06-12 14:31 ` [PATCH v2 4/7] iommu/vt-d: Split intel_iommu_domain_alloc_paging_flags() Jason Gunthorpe
2025-06-13  9:35   ` Tian, Kevin
2025-06-12 14:31 ` [PATCH v2 5/7] iommu/vt-d: Create unique domain ops for each stage Jason Gunthorpe
2025-06-13  9:38   ` Tian, Kevin
2025-06-13 12:58     ` Jason Gunthorpe
2025-06-12 14:31 ` [PATCH v2 6/7] iommu/vt-d: Split intel_iommu_enforce_cache_coherency() Jason Gunthorpe
2025-06-13  9:56   ` Tian, Kevin
2025-06-13 13:12     ` Jason Gunthorpe
2025-06-30  6:11       ` Baolu Lu
2025-06-30 15:04         ` Jason Gunthorpe
2025-06-12 14:31 ` [PATCH v2 7/7] iommu/vt-d: Split paging_domain_compatible() Jason Gunthorpe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2-v2-e5c01fc5ce82+26216-vtd_prep_jgg@nvidia.com \
    --to=jgg@nvidia.com \
    --cc=baolu.lu@linux.intel.com \
    --cc=dwmw2@infradead.org \
    --cc=iommu@lists.linux.dev \
    --cc=joro@8bytes.org \
    --cc=patches@lists.linux.dev \
    --cc=robin.murphy@arm.com \
    --cc=wei.w.wang@intel.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox