Thread (34 messages) 34 messages, 3 authors, 2025-02-06

Re: [PATCH 16/19] iommu/amd: Use roundup_pow_two() instead of get_order()

From: Robin Murphy <robin.murphy@arm.com>
Date: 2025-02-05 16:23:34
Also in: asahi, linux-iommu, linux-patches, linux-riscv, linux-rockchip, linux-samsung-soc, linux-sunxi, linux-tegra

On 2025-02-04 6:34 pm, Jason Gunthorpe wrote:
   1 << (get_order(x) + PAGE_SHIFT) ==  roundup_pow_two()
...unless x < 2048, which does seem possible here if last_bdf is 
sufficiently small. Not too significant in the cases where the result is 
only rounded back up again for an allocation or remap anyway, but I do 
wonder about the use of dev_table_size in iommu_set_device_table(), and 
whether this change might break it, or whether it's already wrong for 
that case and this might actually fix it...

Thanks,
Robin.
quoted hunk ↗ jump to hunk
Use the shorter version.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
  drivers/iommu/amd/init.c | 5 +----
  1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c
index f1c5041647173c..7d77929bc63af3 100644
--- a/drivers/iommu/amd/init.c
+++ b/drivers/iommu/amd/init.c
@@ -247,10 +247,7 @@ static void init_translation_status(struct amd_iommu *iommu)
  
  static inline unsigned long tbl_size(int entry_size, int last_bdf)
  {
-	unsigned shift = PAGE_SHIFT +
-			 get_order((last_bdf + 1) * entry_size);
-
-	return 1UL << shift;
+	return roundup_pow_of_two((last_bdf + 1) * entry_size);
  }
  
  int amd_iommu_get_num_iommus(void)
  
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help