Skip to content

Commit 9bd008f

Browse files
yiliu1765joergroedel
authored andcommitted
iommu/vt-d: Add a helper to flush cache for updating present pasid entry
Generalize the logic for flushing pasid-related cache upon changes to bits other than SSADE and P which requires a different flow according to VT-d spec. No functional change is intended. Reviewed-by: Lu Baolu <[email protected]> Reviewed-by: Kevin Tian <[email protected]> Signed-off-by: Yi Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Lu Baolu <[email protected]> Signed-off-by: Joerg Roedel <[email protected]>
1 parent b45a377 commit 9bd008f

File tree

1 file changed

+34
-18
lines changed

1 file changed

+34
-18
lines changed

drivers/iommu/intel/pasid.c

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,39 @@ static void pasid_flush_caches(struct intel_iommu *iommu,
287287
}
288288
}
289289

290+
/*
291+
* This function is supposed to be used after caller updates the fields
292+
* except for the SSADE and P bit of a pasid table entry. It does the
293+
* below:
294+
* - Flush cacheline if needed
295+
* - Flush the caches per Table 28 ”Guidance to Software for Invalidations“
296+
* of VT-d spec 5.0.
297+
*/
298+
static void intel_pasid_flush_present(struct intel_iommu *iommu,
299+
struct device *dev,
300+
u32 pasid, u16 did,
301+
struct pasid_entry *pte)
302+
{
303+
if (!ecap_coherent(iommu->ecap))
304+
clflush_cache_range(pte, sizeof(*pte));
305+
306+
/*
307+
* VT-d spec 5.0 table28 states guides for cache invalidation:
308+
*
309+
* - PASID-selective-within-Domain PASID-cache invalidation
310+
* - PASID-selective PASID-based IOTLB invalidation
311+
* - If (pasid is RID_PASID)
312+
* - Global Device-TLB invalidation to affected functions
313+
* Else
314+
* - PASID-based Device-TLB invalidation (with S=1 and
315+
* Addr[63:12]=0x7FFFFFFF_FFFFF) to affected functions
316+
*/
317+
pasid_cache_invalidation_with_pasid(iommu, did, pasid);
318+
qi_flush_piotlb(iommu, did, pasid, 0, -1, 0);
319+
320+
devtlb_invalidation_with_pasid(iommu, dev, pasid);
321+
}
322+
290323
/*
291324
* Set up the scalable mode pasid table entry for first only
292325
* translation type.
@@ -526,24 +559,7 @@ void intel_pasid_setup_page_snoop_control(struct intel_iommu *iommu,
526559
did = pasid_get_domain_id(pte);
527560
spin_unlock(&iommu->lock);
528561

529-
if (!ecap_coherent(iommu->ecap))
530-
clflush_cache_range(pte, sizeof(*pte));
531-
532-
/*
533-
* VT-d spec 3.4 table23 states guides for cache invalidation:
534-
*
535-
* - PASID-selective-within-Domain PASID-cache invalidation
536-
* - PASID-selective PASID-based IOTLB invalidation
537-
* - If (pasid is RID_PASID)
538-
* - Global Device-TLB invalidation to affected functions
539-
* Else
540-
* - PASID-based Device-TLB invalidation (with S=1 and
541-
* Addr[63:12]=0x7FFFFFFF_FFFFF) to affected functions
542-
*/
543-
pasid_cache_invalidation_with_pasid(iommu, did, pasid);
544-
qi_flush_piotlb(iommu, did, pasid, 0, -1, 0);
545-
546-
devtlb_invalidation_with_pasid(iommu, dev, pasid);
562+
intel_pasid_flush_present(iommu, dev, pasid, did, pte);
547563
}
548564

549565
/**

0 commit comments

Comments
 (0)