From: Cong Wang <xiyou.wangcong@gmail.com> mainline inclusion from mainline-v5.11-rc1 commit 3a651b3a27a1ee35879499ead3942dc854a20968 category: bugfix bugzilla: https://gitee.com/src-openeuler/kernel/issues/ID5X4C Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=... ---------------------------------------- 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. Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com> Reviewed-by: Robin Murphy <robin.murphy@arm.com> Signed-off-by: John Garry <john.garry@huawei.com> Link: https://lore.kernel.org/r/1605608734-84416-5-git-send-email-john.garry@huawe... Signed-off-by: Will Deacon <will@kernel.org> Signed-off-by: Lin Yujun <linyujun809@h-partners.com> --- 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 99d5e942aff6..7e4a5cfe49ae 100644 --- a/drivers/iommu/iova.c +++ b/drivers/iommu/iova.c @@ -410,14 +410,18 @@ EXPORT_SYMBOL_GPL(__free_iova); * frees the iova from that domain. */ 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); /** -- 2.34.1