Skip to content

Commit e934464

Browse files
Ethsanwilldeacon
authored andcommitted
iommu/vt-d: Deduplicate cache_tag_flush_all by reusing flush_range
The logic in cache_tag_flush_all() to iterate over cache tags and issue TLB invalidations is largely duplicated in cache_tag_flush_range(), with the only difference being the range parameters. Extend cache_tag_flush_range() to handle a full address space flush when called with start = 0 and end = ULONG_MAX. This allows cache_tag_flush_all() to simply delegate to cache_tag_flush_range() Signed-off-by: Ethan Milon <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Lu Baolu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent 3141153 commit e934464

File tree

2 files changed

+8
-31
lines changed

2 files changed

+8
-31
lines changed

drivers/iommu/intel/cache.c

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,13 @@ void cache_tag_flush_range(struct dmar_domain *domain, unsigned long start,
435435
struct cache_tag *tag;
436436
unsigned long flags;
437437

438-
addr = calculate_psi_aligned_address(start, end, &pages, &mask);
438+
if (start == 0 && end == ULONG_MAX) {
439+
addr = 0;
440+
pages = -1;
441+
mask = MAX_AGAW_PFN_WIDTH;
442+
} else {
443+
addr = calculate_psi_aligned_address(start, end, &pages, &mask);
444+
}
439445

440446
spin_lock_irqsave(&domain->cache_lock, flags);
441447
list_for_each_entry(tag, &domain->cache_tags, node) {
@@ -476,31 +482,7 @@ void cache_tag_flush_range(struct dmar_domain *domain, unsigned long start,
476482
*/
477483
void cache_tag_flush_all(struct dmar_domain *domain)
478484
{
479-
struct intel_iommu *iommu = NULL;
480-
struct cache_tag *tag;
481-
unsigned long flags;
482-
483-
spin_lock_irqsave(&domain->cache_lock, flags);
484-
list_for_each_entry(tag, &domain->cache_tags, node) {
485-
if (iommu && iommu != tag->iommu)
486-
qi_batch_flush_descs(iommu, domain->qi_batch);
487-
iommu = tag->iommu;
488-
489-
switch (tag->type) {
490-
case CACHE_TAG_IOTLB:
491-
case CACHE_TAG_NESTING_IOTLB:
492-
cache_tag_flush_iotlb(domain, tag, 0, -1, 0, 0);
493-
break;
494-
case CACHE_TAG_DEVTLB:
495-
case CACHE_TAG_NESTING_DEVTLB:
496-
cache_tag_flush_devtlb_psi(domain, tag, 0, MAX_AGAW_PFN_WIDTH);
497-
break;
498-
}
499-
500-
trace_cache_tag_flush_all(tag);
501-
}
502-
qi_batch_flush_descs(iommu, domain->qi_batch);
503-
spin_unlock_irqrestore(&domain->cache_lock, flags);
485+
cache_tag_flush_range(domain, 0, ULONG_MAX, 0);
504486
}
505487

506488
/*

drivers/iommu/intel/trace.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,6 @@ DEFINE_EVENT(cache_tag_log, cache_tag_unassign,
130130
TP_ARGS(tag)
131131
);
132132

133-
DEFINE_EVENT(cache_tag_log, cache_tag_flush_all,
134-
TP_PROTO(struct cache_tag *tag),
135-
TP_ARGS(tag)
136-
);
137-
138133
DECLARE_EVENT_CLASS(cache_tag_flush,
139134
TP_PROTO(struct cache_tag *tag, unsigned long start, unsigned long end,
140135
unsigned long addr, unsigned long pages, unsigned long mask),

0 commit comments

Comments
 (0)