]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iommu/vt-d: Split intel_iommu_enforce_cache_coherency()
authorJason Gunthorpe <jgg@nvidia.com>
Mon, 14 Jul 2025 04:50:25 +0000 (12:50 +0800)
committerWill Deacon <will@kernel.org>
Mon, 14 Jul 2025 10:18:04 +0000 (11:18 +0100)
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.

Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/6-v3-dbbe6f7e7ae3+124ffe-vtd_prep_jgg@nvidia.com
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
Link: https://lore.kernel.org/r/20250714045028.958850-9-baolu.lu@linux.intel.com
Signed-off-by: Will Deacon <will@kernel.org>
drivers/iommu/intel/iommu.c

index 940d1c6c224892136e249f37125a022ca0c8563e..d2451a8ee6e7f8096c5fc77366d75a6a6f867489 100644 (file)
@@ -3643,44 +3643,41 @@ static bool domain_support_force_snooping(struct dmar_domain *domain)
        return support;
 }
 
-static void domain_set_force_snooping(struct dmar_domain *domain)
+static bool intel_iommu_enforce_cache_coherency_fs(struct iommu_domain *domain)
 {
+       struct dmar_domain *dmar_domain = to_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;
-       }
+       guard(spinlock_irqsave)(&dmar_domain->lock);
+
+       if (dmar_domain->force_snooping)
+               return true;
 
-       list_for_each_entry(info, &domain->devices, link)
+       if (!domain_support_force_snooping(dmar_domain))
+               return false;
+
+       dmar_domain->force_snooping = true;
+       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(struct iommu_domain *domain)
+static bool intel_iommu_enforce_cache_coherency_ss(struct iommu_domain *domain)
 {
        struct dmar_domain *dmar_domain = to_dmar_domain(domain);
-       unsigned long flags;
 
-       if (dmar_domain->force_snooping)
-               return true;
-
-       spin_lock_irqsave(&dmar_domain->lock, flags);
+       guard(spinlock_irqsave)(&dmar_domain->lock);
        if (!domain_support_force_snooping(dmar_domain) ||
-           (!dmar_domain->use_first_level && dmar_domain->has_mappings)) {
-               spin_unlock_irqrestore(&dmar_domain->lock, flags);
+           dmar_domain->has_mappings)
                return false;
-       }
 
-       domain_set_force_snooping(dmar_domain);
+       /*
+        * 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;
        dmar_domain->force_snooping = true;
-       spin_unlock_irqrestore(&dmar_domain->lock, flags);
-
        return true;
 }
 
@@ -4398,7 +4395,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 = {
@@ -4411,7 +4408,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 = {