2024-03-04 08:15:46

by LeoLiu-oc

[permalink] [raw]
Subject: [PATCH] iommu/dma: Fix not fully traversing iova reservations issue

From: leoliu-oc <[email protected]>

For multiple devices in the same iommu group, sorted later device (based
on Bus:Dev.Func) have the RMRR.

Sorted earlier device (without RMRR) initialized the iova domain causing
the sorted later device goto done_unlock.

Then, the sorted later device (with RMRR) cannot execute the
iova_reserve_iommu_regions to reserve the RMRR in the group's iova domain,
and other devices (in the same group) alloc iova in RMRR are permitted.

DMA iova addresses conflict with RMRR in this case.

Goto iova_reserve_iommu_regions could avoid the problem (make sure all
devices of the same group execute reserve iova)

Signed-off-by: leoliu-oc <[email protected]>
---
drivers/iommu/dma-iommu.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
index 50ccc4f1ef81..2b6c6bf4bccf 100644
--- a/drivers/iommu/dma-iommu.c
+++ b/drivers/iommu/dma-iommu.c
@@ -709,7 +709,7 @@ static int iommu_dma_init_domain(struct iommu_domain *domain, dma_addr_t base,
}

ret = 0;
- goto done_unlock;
+ goto iova_reserve;
}

init_iova_domain(iovad, 1UL << order, base_pfn);
@@ -724,6 +724,7 @@ static int iommu_dma_init_domain(struct iommu_domain *domain, dma_addr_t base,
(!device_iommu_capable(dev, IOMMU_CAP_DEFERRED_FLUSH) || iommu_dma_init_fq(domain)))
domain->type = IOMMU_DOMAIN_DMA;

+iova_reserve:
ret = iova_reserve_iommu_regions(dev, domain);

done_unlock:
--
2.34.1