]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iommu/vt-d: Flush cache for PASID table before using it
authorDmytro Maluka <dmaluka@chromium.org>
Thu, 22 Jan 2026 01:48:52 +0000 (09:48 +0800)
committerJoerg Roedel <joerg.roedel@amd.com>
Thu, 22 Jan 2026 08:20:29 +0000 (09:20 +0100)
When writing the address of a freshly allocated zero-initialized PASID
table to a PASID directory entry, do that after the CPU cache flush for
this PASID table, not before it, to avoid the time window when this
PASID table may be already used by non-coherent IOMMU hardware while
its contents in RAM is still some random old data, not zero-initialized.

Fixes: 194b3348bdbb ("iommu/vt-d: Fix PASID directory pointer coherency")
Signed-off-by: Dmytro Maluka <dmaluka@chromium.org>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Link: https://lore.kernel.org/r/20251221123508.37495-1-dmaluka@chromium.org
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
drivers/iommu/intel/pasid.c

index 99692f88b8834c9a94e1731627be5c889349f956..6379b211f12b0f452b6614f8800bdb26405d1927 100644 (file)
@@ -153,6 +153,9 @@ retry:
                if (!entries)
                        return NULL;
 
+               if (!ecap_coherent(info->iommu->ecap))
+                       clflush_cache_range(entries, VTD_PAGE_SIZE);
+
                /*
                 * The pasid directory table entry won't be freed after
                 * allocation. No worry about the race with free and
@@ -165,10 +168,8 @@ retry:
                        iommu_free_pages(entries);
                        goto retry;
                }
-               if (!ecap_coherent(info->iommu->ecap)) {
-                       clflush_cache_range(entries, VTD_PAGE_SIZE);
+               if (!ecap_coherent(info->iommu->ecap))
                        clflush_cache_range(&dir[dir_index].val, sizeof(*dir));
-               }
        }
 
        return &entries[index];