[PATCH v2] iommu/vt-d: Link cache tags of same iommu unit together

Zhenzhong Duan posted 1 patch 12 months ago
drivers/iommu/intel/cache.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
[PATCH v2] iommu/vt-d: Link cache tags of same iommu unit together
Posted by Zhenzhong Duan 12 months ago
Cache tag invalidation requests for a domain are accumulated until a
different iommu unit is found when traversing the cache_tags linked list.
But cache tags of same iommu unit can be distributed in the linked list,
this make batched flush less efficient. E.g., one device backed by iommu0
is attached to a domain in between two devices attaching backed by iommu1.

Group cache tags together for same iommu unit in cache_tag_assign() to
maximize the performance of batched flush.

Co-developed-by: Lu Baolu <baolu.lu@linux.intel.com>
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
---
v2: avoid getting cache tag struct from list head (Baolu)

 drivers/iommu/intel/cache.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/intel/cache.c b/drivers/iommu/intel/cache.c
index 09694cca8752..fc35cba59145 100644
--- a/drivers/iommu/intel/cache.c
+++ b/drivers/iommu/intel/cache.c
@@ -47,6 +47,7 @@ static int cache_tag_assign(struct dmar_domain *domain, u16 did,
 	struct device_domain_info *info = dev_iommu_priv_get(dev);
 	struct intel_iommu *iommu = info->iommu;
 	struct cache_tag *tag, *temp;
+	struct list_head *prev;
 	unsigned long flags;
 
 	tag = kzalloc(sizeof(*tag), GFP_KERNEL);
@@ -65,6 +66,7 @@ static int cache_tag_assign(struct dmar_domain *domain, u16 did,
 		tag->dev = iommu->iommu.dev;
 
 	spin_lock_irqsave(&domain->cache_lock, flags);
+	prev = &domain->cache_tags;
 	list_for_each_entry(temp, &domain->cache_tags, node) {
 		if (cache_tage_match(temp, did, iommu, dev, pasid, type)) {
 			temp->users++;
@@ -73,8 +75,15 @@ static int cache_tag_assign(struct dmar_domain *domain, u16 did,
 			trace_cache_tag_assign(temp);
 			return 0;
 		}
+		if (temp->iommu == iommu)
+			prev = &temp->node;
 	}
-	list_add_tail(&tag->node, &domain->cache_tags);
+	/*
+	 * Link cache tags of same iommu unit together, so corresponding
+	 * flush ops can be batched for iommu unit.
+	 */
+	list_add(&tag->node, prev);
+
 	spin_unlock_irqrestore(&domain->cache_lock, flags);
 	trace_cache_tag_assign(tag);
 
-- 
2.34.1
Re: [PATCH v2] iommu/vt-d: Link cache tags of same iommu unit together
Posted by Baolu Lu 11 months, 2 weeks ago
On 12/19/24 13:43, Zhenzhong Duan wrote:
> Cache tag invalidation requests for a domain are accumulated until a
> different iommu unit is found when traversing the cache_tags linked list.
> But cache tags of same iommu unit can be distributed in the linked list,
> this make batched flush less efficient. E.g., one device backed by iommu0
> is attached to a domain in between two devices attaching backed by iommu1.
> 
> Group cache tags together for same iommu unit in cache_tag_assign() to
> maximize the performance of batched flush.
> 
> Co-developed-by: Lu Baolu<baolu.lu@linux.intel.com>
> Signed-off-by: Lu Baolu<baolu.lu@linux.intel.com>
> Signed-off-by: Zhenzhong Duan<zhenzhong.duan@intel.com>
> ---
> v2: avoid getting cache tag struct from list head (Baolu)
> 
>   drivers/iommu/intel/cache.c | 11 ++++++++++-
>   1 file changed, 10 insertions(+), 1 deletion(-)

Queued for v6.14. Thanks!