Skip to contentSkip to conversation

iommu/vt-d: Link cache tags of same iommu unit together

PATCH Superseded Zhenzhong Duan 2 participants 5 messages Dec 16, 2024 – Dec 18, 2024

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iommu/vt-d: Link cache tags of same iommu unit together

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.

---
 drivers/iommu/intel/cache.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/iommu/intel/cache.c +10 -1
index e5b89f728ad3..726052a841e0 100644
@@ -48,6 +48,8 @@ static int cache_tag_assign(struct dmar_domain *domain, u16 did,
 	struct intel_iommu *iommu = info->iommu;
 	struct cache_tag *tag, *temp;
 	unsigned long flags;
+	struct cache_tag *temp2 = list_entry(&domain->cache_tags,
+					     struct cache_tag, node);
 
 	tag = kzalloc(sizeof(*tag), GFP_KERNEL);
 	if (!tag)
@@ -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)
+			temp2 = temp;
 	}
-	list_add_tail(&tag->node, &domain->cache_tags);
+	/*
+	 * Link cache tags of same iommu unit together, so consponding
+	 * flush ops can be batched for iommu unit.
+	 */
+	list_add(&tag->node, &temp2->node);
+
 	spin_unlock_irqrestore(&domain->cache_lock, flags);
 	trace_cache_tag_assign(tag);
 
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 19 lines · Zhenzhong Duan

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.

---
  drivers/iommu/intel/cache.c | 11 ++++++++++-
  1 file changed, 10 insertions(+), 1 deletion(-)
drivers/iommu/intel/cache.c +0 -0
index e5b89f728ad3..726052a841e0 100644

drivers/iommu/intel/cache.c static int cache_tag_assign(struct dmar_domain *domain, u16 did, · line 52

Quoted 5 lines
drivers/iommu/intel/cache.c +2 -0
@@ -48,6 +48,8 @@ static int cache_tag_assign(struct dmar_domain *domain, u16 did,
  	struct intel_iommu *iommu = info->iommu;
  	struct cache_tag *tag, *temp;
  	unsigned long flags;
+	struct cache_tag *temp2 = list_entry(&domain->cache_tags,
+					     struct cache_tag, node);

Is this valid for a list head?

Quoted 20 lines
drivers/iommu/intel/cache.c +8 -1
  	tag = kzalloc(sizeof(*tag), GFP_KERNEL);
  	if (!tag)
@@ -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)
+			temp2 = temp;
  	}
-	list_add_tail(&tag->node, &domain->cache_tags);
+	/*
+	 * Link cache tags of same iommu unit together, so consponding
+	 * flush ops can be batched for iommu unit.
+	 */
+	list_add(&tag->node, &temp2->node);
+
  	spin_unlock_irqrestore(&domain->cache_lock, flags);
  	trace_cache_tag_assign(tag);
 
#2 lore raw
Quoted 27 lines

-----Original Message-----
From: Baolu Lu <[email protected]>
Subject: Re: [PATCH] iommu/vt-d: Link cache tags of same iommu unit together

drivers/iommu/intel/cache.c static int cache_tag_assign(struct dmar_domain *domain,

Quoted 19 lines · Zhenzhong Duan

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.

---
  drivers/iommu/intel/cache.c | 11 ++++++++++-
  1 file changed, 10 insertions(+), 1 deletion(-)
drivers/iommu/intel/cache.c +0 -0
index e5b89f728ad3..726052a841e0 100644
@@ -48,6 +48,8 @@ static int cache_tag_assign(struct dmar_domain *domain,

u16 did,

Quoted 7 lines

drivers/iommu/intel/cache.c static int cache_tag_assign(struct dmar_domain *domain, · line 52

Quoted 5 lines
drivers/iommu/intel/cache.c +2 -0
  	struct intel_iommu *iommu = info->iommu;
  	struct cache_tag *tag, *temp;
  	unsigned long flags;
+	struct cache_tag *temp2 = list_entry(&domain->cache_tags,
+					     struct cache_tag, node);

Is this valid for a list head?

Yes, it's not valid for list head but it's intentional, just want to avoid unnecessary temp2 check. If I don't do that way, patch will be:

drivers/iommu/intel/cache.c +12 -1
@@ -48,6 +48,7 @@ static int cache_tag_assign(struct dmar_domain *domain, u16 did,
        struct intel_iommu *iommu = info->iommu;
        struct cache_tag *tag, *temp;
        unsigned long flags;
+       struct cache_tag *temp2 = NULL;
 
        tag = kzalloc(sizeof(*tag), GFP_KERNEL);
        if (!tag)
@@ -73,8 +74,18 @@ static int cache_tag_assign(struct dmar_domain *domain, u16 did,
                        trace_cache_tag_assign(temp);
                        return 0;
                }
+               if (temp->iommu == iommu)
+                       temp2 = temp;
        }
-       list_add_tail(&tag->node, &domain->cache_tags);
+       /*
+        * Link cache tags of same iommu unit together, so consponding
+        * flush ops can be batched for iommu unit.
+        */
+       if (temp2)
+               list_add(&tag->node, &temp2->node);
+       else
+               list_add_tail((&tag->node, &domain->cache_tags);
+
        spin_unlock_irqrestore(&domain->cache_lock, flags);
        trace_cache_tag_assign(tag);
 

Thanks
Zhenzhong

Quoted 22 lines

drivers/iommu/intel/cache.c static int cache_tag_assign(struct dmar_domain

Quoted 5 lines
drivers/iommu/intel/cache.c +0 -0
  	tag = kzalloc(sizeof(*tag), GFP_KERNEL);
  	if (!tag)
@@ -73,8 +75,15 @@ static int cache_tag_assign(struct dmar_domain

*domain, u16 did,

Quoted 16 lines
drivers/iommu/intel/cache.c +8 -1
  			trace_cache_tag_assign(temp);
  			return 0;
  		}
+		if (temp->iommu == iommu)
+			temp2 = temp;
  	}
-	list_add_tail(&tag->node, &domain->cache_tags);
+	/*
+	 * Link cache tags of same iommu unit together, so consponding
+	 * flush ops can be batched for iommu unit.
+	 */
+	list_add(&tag->node, &temp2->node);
+
  	spin_unlock_irqrestore(&domain->cache_lock, flags);
  	trace_cache_tag_assign(tag);
 
maintainer
#3 lore raw
Quoted 53 lines · Zhenzhong
Quoted 25 lines

-----Original Message-----
From: Baolu Lu<[email protected]>
Subject: Re: [PATCH] iommu/vt-d: Link cache tags of same iommu unit together

drivers/iommu/intel/cache.c static int cache_tag_assign(struct dmar_domain *domain,

Quoted 19 lines · Zhenzhong Duan

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.

---
   drivers/iommu/intel/cache.c | 11 ++++++++++-
   1 file changed, 10 insertions(+), 1 deletion(-)
drivers/iommu/intel/cache.c +0 -0
index e5b89f728ad3..726052a841e0 100644
@@ -48,6 +48,8 @@ static int cache_tag_assign(struct dmar_domain *domain,

u16 did,

Quoted 6 lines

drivers/iommu/intel/cache.c static int cache_tag_assign(struct dmar_domain *domain, · line 52

Quoted 5 lines
drivers/iommu/intel/cache.c +2 -0
   	struct intel_iommu *iommu = info->iommu;
   	struct cache_tag *tag, *temp;
   	unsigned long flags;
+	struct cache_tag *temp2 = list_entry(&domain->cache_tags,
+					     struct cache_tag, node);

Is this valid for a list head?

Yes, it's not valid for list head but it's intentional, just want to avoid unnecessary temp2 check. If I don't do that way, patch will be:

drivers/iommu/intel/cache.c +4 -1
@@ -48,6 +48,7 @@ static int cache_tag_assign(struct dmar_domain *domain, u16 did,
         struct intel_iommu *iommu = info->iommu;
         struct cache_tag *tag, *temp;
         unsigned long flags;
+       struct cache_tag *temp2 = NULL;
 
         tag = kzalloc(sizeof(*tag), GFP_KERNEL);
         if (!tag)
@@ -73,8 +74,18 @@ static int cache_tag_assign(struct dmar_domain *domain, u16 did,
                         trace_cache_tag_assign(temp);
                         return 0;
                 }
+               if (temp->iommu == iommu)
+                       temp2 = temp;
         }
-       list_add_tail(&tag->node, &domain->cache_tags);
+       /*

drivers/iommu/intel/cache.c static int cache_tag_assign(struct dmar_domain *domain, u16 did, · line 90

Quoted 10 lines
drivers/iommu/intel/cache.c +8 -0
+        * Link cache tags of same iommu unit together, so consponding
+        * flush ops can be batched for iommu unit.
+        */
+       if (temp2)
+               list_add(&tag->node, &temp2->node);
+       else
+               list_add_tail((&tag->node, &domain->cache_tags);
+
         spin_unlock_irqrestore(&domain->cache_lock, flags);
         trace_cache_tag_assign(tag);

Perhaps we can make it like this?

drivers/iommu/intel/cache.c +10 -1
index 09694cca8752..cf0cca94d165 100644
@@ -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 consponding
+        * 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);
 

Thanks,
baolu

#4 lore raw
Quoted 75 lines

-----Original Message-----
From: Baolu Lu <[email protected]>
Subject: Re: [PATCH] iommu/vt-d: Link cache tags of same iommu unit together

Quoted 3 lines · Zhenzhong
Quoted 3 lines

-----Original Message-----
From: Baolu Lu<[email protected]>
Subject: Re: [PATCH] iommu/vt-d: Link cache tags of same iommu unit

together

Quoted 16 lines
Quoted 16 lines · Zhenzhong Duan
Quoted 14 lines

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.

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

drivers/iommu/intel/cache.c static int cache_tag_assign(struct dmar_domain

Quoted 5 lines
drivers/iommu/intel/cache.c +0 -0
index e5b89f728ad3..726052a841e0 100644
@@ -48,6 +48,8 @@ static int cache_tag_assign(struct dmar_domain

*domain,

drivers/iommu/intel/cache.c static int cache_tag_assign(struct dmar_domain *domain,

Quoted 13 lines
Quoted 7 lines

u16 did,

drivers/iommu/intel/cache.c static int cache_tag_assign(struct dmar_domain *domain, u16 did,

Quoted 5 lines
drivers/iommu/intel/cache.c +2 -0
   	struct intel_iommu *iommu = info->iommu;
   	struct cache_tag *tag, *temp;
   	unsigned long flags;
+	struct cache_tag *temp2 = list_entry(&domain->cache_tags,
+					     struct cache_tag, node);

Is this valid for a list head?

Yes, it's not valid for list head but it's intentional, just want to avoid unnecessary temp2 check. If I don't do that way, patch will be:

drivers/iommu/intel/cache.c +0 -0
@@ -48,6 +48,7 @@ static int cache_tag_assign(struct dmar_domain *domain,

u16 did,

drivers/iommu/intel/cache.c static int cache_tag_assign(struct dmar_domain

Quoted 8 lines
drivers/iommu/intel/cache.c +1 -0
         struct intel_iommu *iommu = info->iommu;
         struct cache_tag *tag, *temp;
         unsigned long flags;
+       struct cache_tag *temp2 = NULL;
 
         tag = kzalloc(sizeof(*tag), GFP_KERNEL);
         if (!tag)
@@ -73,8 +74,18 @@ static int cache_tag_assign(struct dmar_domain

*domain, u16 did,

Quoted 8 lines
drivers/iommu/intel/cache.c +3 -1
                         trace_cache_tag_assign(temp);
                         return 0;
                 }
+               if (temp->iommu == iommu)
+                       temp2 = temp;
         }
-       list_add_tail(&tag->node, &domain->cache_tags);
+       /*

drivers/iommu/intel/cache.c static int cache_tag_assign(struct dmar_domain *domain, u16 did, · line 88

Quoted 10 lines
drivers/iommu/intel/cache.c +8 -0
+        * Link cache tags of same iommu unit together, so consponding
+        * flush ops can be batched for iommu unit.
+        */
+       if (temp2)
+               list_add(&tag->node, &temp2->node);
+       else
+               list_add_tail((&tag->node, &domain->cache_tags);
+
         spin_unlock_irqrestore(&domain->cache_lock, flags);
         trace_cache_tag_assign(tag);
Quoted 1 line

Perhaps we can make it like this?

Good suggestion! Will do.

Thanks
Zhenzhong

Quoted 43 lines
drivers/iommu/intel/cache.c +1 -0
index 09694cca8752..cf0cca94d165 100644
@@ -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);
drivers/iommu/intel/cache.c +1 -0
@@ -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++;
drivers/iommu/intel/cache.c +8 -1
@@ -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 consponding
+        * 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);

Thanks,
baolu