Re: [PATCH] iommu/vt-d: Fix identity map bounds in si_domain_init()

From: Baolu Lu
Date: Tue Jul 09 2024 - 22:46:01 EST


On 7/10/24 7:49 AM, Jon Pan-Doh wrote:
Intel IOMMU operates on inclusive bounds (both generally aas well as
iommu_domain_identity_map()). Meanwhile, for_each_mem_pfn_range() uses
exclusive bounds for end_pfn. This creates an off-by-one error when
switching between the two.

Fixes: 5dfe8660a3d7 ("bootmem: Replace work_with_active_regions() with for_each_mem_pfn_range()")
Signed-off-by: Jon Pan-Doh<pandoh@xxxxxxxxxx>
Tested-by: Sudheer Dantuluri<dantuluris@xxxxxxxxxx>

Do you mind telling me on which platform did you test this fix? My
understanding is that modern VT-d hardware supports hardware pass
through mode, hence this piece of code won't be executed anymore.

Suggested-by: Gary Zibrat<gzibrat@xxxxxxxxxx>
---
drivers/iommu/intel/iommu.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index fd11a080380c..f55ec1fd7942 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -2071,7 +2071,7 @@ static int __init si_domain_init(int hw)
for_each_mem_pfn_range(i, nid, &start_pfn, &end_pfn, NULL) {
ret = iommu_domain_identity_map(si_domain,
mm_to_dma_pfn_start(start_pfn),
- mm_to_dma_pfn_end(end_pfn));
+ mm_to_dma_pfn_end(end_pfn-1));
if (ret)
return ret;
}

Thanks,
baolu