Skip to contentSkip to conversation

Fixed an off-by-one error in the AMD IOMMU driver.

PATCH Applied Neil Turton 2 participants 2 messages May 14, 2009 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fixed an off-by-one error in the AMD IOMMU driver.

The variable amd_iommu_last_bdf holds the maximum bdf of any device controlled by an IOMMU, so the number of device entries needed is amd_iommu_last_bdf+1. The function tbl_size used amd_iommu_last_bdf instead. This would be a problem if the last device were a large enough power of 2.

---
 arch/x86/kernel/amd_iommu_init.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/kernel/amd_iommu_init.c +1 -1
index 42c33ce..61479ba 100644
@@ -175,7 +175,7 @@ static inline void update_last_devid(u16 devid)
 static inline unsigned long tbl_size(int entry_size)
 {
 	unsigned shift = PAGE_SHIFT +
-			 get_order(amd_iommu_last_bdf * entry_size);
+			 get_order(((int)amd_iommu_last_bdf+1) * entry_size);
 
 	return 1UL << shift;
 }
Signature · 1 line
1.5.5
#1 lore raw
Quoted 16 lines · Neil Turton

The variable amd_iommu_last_bdf holds the maximum bdf of any device controlled by an IOMMU, so the number of device entries needed is amd_iommu_last_bdf+1. The function tbl_size used amd_iommu_last_bdf instead. This would be a problem if the last device were a large enough power of 2.

---
 arch/x86/kernel/amd_iommu_init.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/kernel/amd_iommu_init.c +0 -0
index 42c33ce..61479ba 100644

arch/x86/kernel/amd_iommu_init.c static inline void update_last_devid(u16 devid) · line 181

Quoted 8 lines
arch/x86/kernel/amd_iommu_init.c +1 -1
@@ -175,7 +175,7 @@ static inline void update_last_devid(u16 devid)
 static inline unsigned long tbl_size(int entry_size)
 {
 	unsigned shift = PAGE_SHIFT +
-			 get_order(amd_iommu_last_bdf * entry_size);
+			 get_order(((int)amd_iommu_last_bdf+1) * entry_size);
 
 	return 1UL << shift;
 }

Applied, thanks Neil.

Signature · 6 lines
           | Advanced Micro Devices GmbH
 Operating | Karl-Hammerschmidt-Str. 34, 85609 Dornach bei München
 System    | 
 Research  | Geschäftsführer: Thomas M. McCoy, Giuliano Meroni
 Center    | Sitz: Dornach, Gemeinde Aschheim, Landkreis München
           | Registergericht München, HRB Nr. 43632