Skip to contentSkip to conversation

iommu/iova: put free_iova_mem() outside of spinlock iova_rbtree_lock

PATCH Superseded chenxiang 4 participants 6 messages Apr 19, 2021 – May 18, 2021

Subsystems (2)
lore
Share & tools
lore

chenxiang

author
#0 lore raw

PATCH v3 1/1 iommu/iova: put free_iova_mem() outside of spinlock iova_rbtree_lock

From: Xiang Chen <[email protected]>

It is not necessary to put free_iova_mem() inside of spinlock/unlock iova_rbtree_lock which only leads to more completion for the spinlock. It has a small promote on the performance after the change. And also rename private_free_iova() as remove_iova() because the function will not free iova after that change.

---
 drivers/iommu/iova.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
drivers/iommu/iova.c +11 -7
index b7ecd5b..b6cf5f1 100644
@@ -412,12 +412,11 @@ private_find_iova(struct iova_domain *iovad, unsigned long pfn)
 	return NULL;
 }
 
-static void private_free_iova(struct iova_domain *iovad, struct iova *iova)
+static void remove_iova(struct iova_domain *iovad, struct iova *iova)
 {
 	assert_spin_locked(&iovad->iova_rbtree_lock);
 	__cached_rbnode_delete_update(iovad, iova);
 	rb_erase(&iova->node, &iovad->rbroot);
-	free_iova_mem(iova);
 }
 
 /**
@@ -452,8 +451,9 @@ __free_iova(struct iova_domain *iovad, struct iova *iova)
 	unsigned long flags;
 
 	spin_lock_irqsave(&iovad->iova_rbtree_lock, flags);
-	private_free_iova(iovad, iova);
+	remove_iova(iovad, iova);
 	spin_unlock_irqrestore(&iovad->iova_rbtree_lock, flags);
+	free_iova_mem(iova);
 }
 EXPORT_SYMBOL_GPL(__free_iova);
 
@@ -472,10 +472,13 @@ free_iova(struct iova_domain *iovad, unsigned long pfn)
 
 	spin_lock_irqsave(&iovad->iova_rbtree_lock, flags);
 	iova = private_find_iova(iovad, pfn);
-	if (iova)
-		private_free_iova(iovad, iova);
+	if (!iova) {
+		spin_unlock_irqrestore(&iovad->iova_rbtree_lock, flags);
+		return;
+	}
+	remove_iova(iovad, iova);
 	spin_unlock_irqrestore(&iovad->iova_rbtree_lock, flags);
-
+	free_iova_mem(iova);
 }
 EXPORT_SYMBOL_GPL(free_iova);
 
@@ -825,7 +828,8 @@ iova_magazine_free_pfns(struct iova_magazine *mag, struct iova_domain *iovad)
 		if (WARN_ON(!iova))
 			continue;
 
-		private_free_iova(iovad, iova);
+		remove_iova(iovad, iova);
+		free_iova_mem(iova);
 	}
 
 	spin_unlock_irqrestore(&iovad->iova_rbtree_lock, flags);
Signature · 6 lines
2.8.1

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Reviewed-by on v3 1/1
#1 lore raw
Quoted 9 lines · chenxiang

From: Xiang Chen<[email protected]>

It is not necessary to put free_iova_mem() inside of spinlock/unlock iova_rbtree_lock which only leads to more completion for the spinlock. It has a small promote on the performance after the change. And also rename private_free_iova() as remove_iova() because the function will not free iova after that change.

I think that you will need to resend after v5.13-rc1 comes out, however:

Quoted 2 lines

---
drivers/iommu/

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

maintainer
#2 lore raw
In reply to chenxiang
Quoted 8 lines · chenxiang

From: Xiang Chen <[email protected]>

It is not necessary to put free_iova_mem() inside of spinlock/unlock iova_rbtree_lock which only leads to more completion for the spinlock. It has a small promote on the performance after the change. And also rename private_free_iova() as remove_iova() because the function will not free iova after that change.

Quoted 4 lines
---
 drivers/iommu/iova.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

Looks good to me, but I'll wait for Robins opinion before applying.

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

#3 lore raw

Hi Joerg,

Quoted 9 lines · Joerg Roedel
Quoted 8 lines · chenxiang

From: Xiang Chen <[email protected]>

It is not necessary to put free_iova_mem() inside of spinlock/unlock iova_rbtree_lock which only leads to more completion for the spinlock. It has a small promote on the performance after the change. And also rename private_free_iova() as remove_iova() because the function will not free iova after that change.

Quoted 5 lines
Quoted 4 lines
---
  drivers/iommu/iova.c | 18 +++++++++++-------
  1 file changed, 11 insertions(+), 7 deletions(-)

Looks good to me, but I'll wait for Robins opinion before applying.

I have re-sent v3, and Robin has given his acked-by:
https://www.mail-archive.com/[email protected]/msg50950.html

Quoted 4 lines

.

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

maintainer
#4 lore raw
In reply to Joerg Roedel
Quoted 9 lines · Joerg Roedel
Quoted 8 lines · chenxiang

From: Xiang Chen <[email protected]>

It is not necessary to put free_iova_mem() inside of spinlock/unlock iova_rbtree_lock which only leads to more completion for the spinlock. It has a small promote on the performance after the change. And also rename private_free_iova() as remove_iova() because the function will not free iova after that change.

Quoted 6 lines
Quoted 4 lines
---
  drivers/iommu/iova.c | 18 +++++++++++-------
  1 file changed, 11 insertions(+), 7 deletions(-)

Looks good to me, but I'll wait for Robins opinion before applying.

Go ahead - I acked the resend[1] :)

Thanks,
Robin.

[1] https://lore.kernel.org/linux-iommu/[email protected]/
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu