Re: [Patch v3 3/3] iommu: avoid taking iova_rbtree_lock twice

From: John Garry
Date: Tue Mar 03 2020 - 06:33:15 EST


On 21/01/2020 09:56, Robin Murphy wrote:
On 18/12/2019 4:39 am, Cong Wang wrote:
Both find_iova() and __free_iova() take iova_rbtree_lock,
there is no reason to take and release it twice inside
free_iova().

Fold them into one critical section by calling the unlock
versions instead.

Makes sense to me.

Reviewed-by: Robin Murphy <robin.murphy@xxxxxxx>

Reviewed-by: John Garry <john.garry@xxxxxxxxxx>

Could we at least get this patch picked up? It should be ok to take in isolation, since there is some debate on the other 2 patches in this series. Thanks


Cc: Joerg Roedel <joro@xxxxxxxxxx>
Cc: John Garry <john.garry@xxxxxxxxxx>
Signed-off-by: Cong Wang <xiyou.wangcong@xxxxxxxxx>
---
 drivers/iommu/iova.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c
index 184d4c0e20b5..f46f8f794678 100644
--- a/drivers/iommu/iova.c
+++ b/drivers/iommu/iova.c
@@ -390,10 +390,14 @@ EXPORT_SYMBOL_GPL(__free_iova);
 void
 free_iova(struct iova_domain *iovad, unsigned long pfn)
 {
-ÂÂÂ struct iova *iova = find_iova(iovad, pfn);
+ÂÂÂ unsigned long flags;
+ÂÂÂ struct iova *iova;
+ÂÂÂ spin_lock_irqsave(&iovad->iova_rbtree_lock, flags);
+ÂÂÂ iova = private_find_iova(iovad, pfn);
ÂÂÂÂÂ if (iova)
-ÂÂÂÂÂÂÂ __free_iova(iovad, iova);
+ÂÂÂÂÂÂÂ private_free_iova(iovad, iova);
+ÂÂÂ spin_unlock_irqrestore(&iovad->iova_rbtree_lock, flags);
 }
 EXPORT_SYMBOL_GPL(free_iova);

.