Skip to content

Commit 22d169b

Browse files
maluka-dmytrojoergroedel
authored andcommitted
iommu/vt-d: Flush cache for PASID table before using it
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: 194b334 ("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>
1 parent 10e60d8 commit 22d169b

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

drivers/iommu/intel/pasid.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ static struct pasid_entry *intel_pasid_get_entry(struct device *dev, u32 pasid)
153153
if (!entries)
154154
return NULL;
155155

156+
if (!ecap_coherent(info->iommu->ecap))
157+
clflush_cache_range(entries, VTD_PAGE_SIZE);
158+
156159
/*
157160
* The pasid directory table entry won't be freed after
158161
* allocation. No worry about the race with free and
@@ -165,10 +168,8 @@ static struct pasid_entry *intel_pasid_get_entry(struct device *dev, u32 pasid)
165168
iommu_free_pages(entries);
166169
goto retry;
167170
}
168-
if (!ecap_coherent(info->iommu->ecap)) {
169-
clflush_cache_range(entries, VTD_PAGE_SIZE);
171+
if (!ecap_coherent(info->iommu->ecap))
170172
clflush_cache_range(&dir[dir_index].val, sizeof(*dir));
171-
}
172173
}
173174

174175
return &entries[index];

0 commit comments

Comments
 (0)