Skip to contentSkip to conversation

iommu/vt-d: Fix identity map bounds in si_domain_init()

PATCH Applied Jon Pan-Doh 4 participants 7 messages Jul 9, 2024 – Jul 12, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iommu/vt-d: Fix identity map bounds in si_domain_init()

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()")
---
 drivers/iommu/intel/iommu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/intel/iommu.c +1 -1
index fd11a080380c..f55ec1fd7942 100644
@@ -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;
 		}
Signature · 1 line
2.45.2.803.g4e1b14247a-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines

From: Jon Pan-Doh <[email protected]>
Sent: Wednesday, July 10, 2024 7:49 AM

Intel IOMMU operates on inclusive bounds (both generally aas well as

s/aas/as/

Quoted 7 lines

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()")

this doesn't appear to be the original commit introducing this bug.

Even the old work_with_active_regions() way used exclusive end_pfn while it's not adjusted when calling iommu_domain_identity_map().

Quoted 3 lines

otherwise,

#2 lore raw
Quoted 1 line · Kevin

s/aas/as/

Ack.

Quoted 7 lines
Quoted 2 lines
Fixes 5dfe8660a3d7 ("bootmem: Replace work_with_active_regions() with

for_each_mem_pfn_range()")

this doesn't appear to be the original commit introducing this bug.

Even the old work_with_active_regions() way used exclusive end_pfn while it's not adjusted when calling iommu_domain_identity_map().

Oops. I did not look far enough back. I believe the correct tag is

Fixes c5395d5c4a82 ("intel-iommu: Clean up iommu_domain_identity_map()")

I'll send out a v2 once Baolu's comments are addressed.

Thanks,
Jon

maintainer
#3 lore raw
In reply to Jon Pan-Doh
Quoted 8 lines · Jon Pan-Doh

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()")

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.

Quoted 10 lines
---
  drivers/iommu/intel/iommu.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/intel/iommu.c +0 -0
index fd11a080380c..f55ec1fd7942 100644

drivers/iommu/intel/iommu.c static int __init si_domain_init(int hw) · line 2077

Quoted 8 lines
drivers/iommu/intel/iommu.c +1 -1
@@ -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

#4 lore raw
Quoted 3 lines · Baolu Lu

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.

We tested it in a VM using an emulated vIOMMU setup. Hope that helps.

Thanks,
Jon

maintainer Reviewed-by
#5 lore raw
Quoted 5 lines · Jon Pan-Doh
Quoted 3 lines · Baolu Lu

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.

We tested it in a VM using an emulated vIOMMU setup. Hope that helps.

Okay, that's fine then. If you send a new version, you can take my

Thanks,
baolu

maintainer Applied
#6 lore raw
In reply to Jon Pan-Doh
Quoted 6 lines · Jon Pan-Doh

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.

Applied to iommu (intel/vt-d), thanks!

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

      https://git.kernel.org/iommu/c/31000732d56b

Cheers,

Signature · 5 lines
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev