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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

Use the shorter version.

Signed-off-by: Jason Gunthorpe <jgg@xxxxxxxxxx>
---
  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)





[Index of Archives]     [ARM Kernel]     [Linux ARM]     [Linux ARM MSM]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux