]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iommufd/selftest: Fix iommufd_test_dirty() to handle <u8 bitmaps
authorJoao Martins <joao.m.martins@oracle.com>
Thu, 27 Jun 2024 11:00:56 +0000 (12:00 +0100)
committerJason Gunthorpe <jgg@nvidia.com>
Fri, 28 Jun 2024 16:12:22 +0000 (13:12 -0300)
The calculation returns 0 if it sets less than the number of bits per
byte. For calculating memory allocation from bits, lets round it up to
one byte.

Link: https://lore.kernel.org/r/20240627110105.62325-3-joao.m.martins@oracle.com
Reported-by: Matt Ochs <mochs@nvidia.com>
Fixes: a9af47e382a4 ("iommufd/selftest: Test IOMMU_HWPT_GET_DIRTY_BITMAP")
Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Tested-by: Matt Ochs <mochs@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
drivers/iommu/iommufd/selftest.c

index 7a2199470f3121da91e060bca82315a6944e37b8..654ed33390957916669f59b9b892bf4219d8d2a7 100644 (file)
@@ -1334,7 +1334,7 @@ static int iommufd_test_dirty(struct iommufd_ucmd *ucmd, unsigned int mockpt_id,
        }
 
        max = length / page_size;
-       bitmap_size = max / BITS_PER_BYTE;
+       bitmap_size = DIV_ROUND_UP(max, BITS_PER_BYTE);
 
        tmp = kvzalloc(bitmap_size, GFP_KERNEL_ACCOUNT);
        if (!tmp) {