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 6/7] iommu/vt-d: Split intel_iommu_enforce_cache_coherency()
Date: Thu, 12 Jun 2025 11:31:38 -0300 [thread overview]
Message-ID: <6-v2-e5c01fc5ce82+26216-vtd_prep_jgg@nvidia.com> (raw)
In-Reply-To: <0-v2-e5c01fc5ce82+26216-vtd_prep_jgg@nvidia.com>
First Stage and Second Stage have very different ways to deny
no-snoop. The first stage uses the PGSNP bit which is global per-PASID so
enabling requires loading new PASID entries for all the attached devices.
Second stage uses a bit per PTE, so enabling just requires telling future
maps to set the bit.
Since we now have two domain ops we can have two functions that can
directly code their required actions instead of a bunch of logic dancing
around use_first_level.
Combine domain_set_force_snooping() into the new functions since they are
the only caller.
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
drivers/iommu/intel/iommu.c | 56 +++++++++++++++++--------------------
1 file changed, 26 insertions(+), 30 deletions(-)
diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index 7a5c794e488614..5fd4b82576ca44 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -3629,44 +3629,40 @@ static bool domain_support_force_snooping(struct dmar_domain *domain)
return support;
}
-static void domain_set_force_snooping(struct dmar_domain *domain)
-{
- struct device_domain_info *info;
-
- assert_spin_locked(&domain->lock);
- /*
- * Second level page table supports per-PTE snoop control. The
- * iommu_map() interface will handle this by setting SNP bit.
- */
- if (!domain->use_first_level) {
- domain->set_pte_snp = true;
- return;
- }
-
- list_for_each_entry(info, &domain->devices, link)
- intel_pasid_setup_page_snoop_control(info->iommu, info->dev,
- IOMMU_NO_PASID);
-}
-
-static bool intel_iommu_enforce_cache_coherency(struct iommu_domain *domain)
+static bool intel_iommu_enforce_cache_coherency_fs(struct iommu_domain *domain)
{
struct dmar_domain *dmar_domain = to_dmar_domain(domain);
- unsigned long flags;
+ struct device_domain_info *info;
+
+ guard(spinlock_irqsave)(&dmar_domain->lock);
if (dmar_domain->force_snooping)
return true;
- spin_lock_irqsave(&dmar_domain->lock, flags);
- if (!domain_support_force_snooping(dmar_domain) ||
- (!dmar_domain->use_first_level && dmar_domain->has_mappings)) {
- spin_unlock_irqrestore(&dmar_domain->lock, flags);
+ if (!domain_support_force_snooping(dmar_domain))
return false;
- }
- domain_set_force_snooping(dmar_domain);
dmar_domain->force_snooping = true;
- spin_unlock_irqrestore(&dmar_domain->lock, flags);
+ list_for_each_entry(info, &dmar_domain->devices, link)
+ intel_pasid_setup_page_snoop_control(info->iommu, info->dev,
+ IOMMU_NO_PASID);
+ return true;
+}
+static bool intel_iommu_enforce_cache_coherency_ss(struct iommu_domain *domain)
+{
+ struct dmar_domain *dmar_domain = to_dmar_domain(domain);
+
+ guard(spinlock_irqsave)(&dmar_domain->lock);
+ if (!domain_support_force_snooping(dmar_domain) ||
+ dmar_domain->has_mappings)
+ return false;
+
+ /*
+ * Second level page table supports per-PTE snoop control. The
+ * iommu_map() interface will handle this by setting SNP bit.
+ */
+ dmar_domain->set_pte_snp = true;
return true;
}
@@ -4381,7 +4377,7 @@ const struct iommu_domain_ops intel_fs_paging_domain_ops = {
.iotlb_sync = intel_iommu_tlb_sync,
.iova_to_phys = intel_iommu_iova_to_phys,
.free = intel_iommu_domain_free,
- .enforce_cache_coherency = intel_iommu_enforce_cache_coherency,
+ .enforce_cache_coherency = intel_iommu_enforce_cache_coherency_fs,
};
const struct iommu_domain_ops intel_ss_paging_domain_ops = {
@@ -4394,7 +4390,7 @@ const struct iommu_domain_ops intel_ss_paging_domain_ops = {
.iotlb_sync = intel_iommu_tlb_sync,
.iova_to_phys = intel_iommu_iova_to_phys,
.free = intel_iommu_domain_free,
- .enforce_cache_coherency = intel_iommu_enforce_cache_coherency,
+ .enforce_cache_coherency = intel_iommu_enforce_cache_coherency_ss,
};
const struct iommu_ops intel_iommu_ops = {
--
2.43.0
next prev 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 ` [PATCH v2 2/7] iommu/vt-d: Fold domain_exit() into intel_iommu_domain_free() Jason Gunthorpe
2025-06-13 9:32 ` 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 ` Jason Gunthorpe [this message]
2025-06-13 9:56 ` [PATCH v2 6/7] iommu/vt-d: Split intel_iommu_enforce_cache_coherency() 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=6-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