Skip to content

Commit d18411e

Browse files
jpemartinsjgunthorpe
authored andcommitted
iommufd/iova_bitmap: Switch iova_bitmap::bitmap to an u8 array
iova_bitmap_mapped_length() don't deal correctly with the small bitmaps (< 2M bitmaps) when the starting address isn't u64 aligned, leading to skipping a tiny part of the IOVA range. This is materialized as not marking data dirty that should otherwise have been. Fix that by using a u8 * in the internal state of IOVA bitmap. Most of the data structures use the type of the bitmap to adjust its indexes, thus changing the type of the bitmap decreases the granularity of the bitmap indexes. Fixes: b058ea3 ("vfio/iova_bitmap: refactor iova_bitmap_set() to better handle page boundaries") Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joao Martins <[email protected]> Tested-by: Avihai Horon <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent a4ab7de commit d18411e

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

drivers/iommu/iommufd/iova_bitmap.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ struct iova_bitmap {
100100
struct iova_bitmap_map mapped;
101101

102102
/* userspace address of the bitmap */
103-
u64 __user *bitmap;
103+
u8 __user *bitmap;
104104

105105
/* u64 index that @mapped points to */
106106
unsigned long mapped_base_index;
@@ -162,7 +162,7 @@ static int iova_bitmap_get(struct iova_bitmap *bitmap)
162162
{
163163
struct iova_bitmap_map *mapped = &bitmap->mapped;
164164
unsigned long npages;
165-
u64 __user *addr;
165+
u8 __user *addr;
166166
long ret;
167167

168168
/*
@@ -247,7 +247,7 @@ struct iova_bitmap *iova_bitmap_alloc(unsigned long iova, size_t length,
247247

248248
mapped = &bitmap->mapped;
249249
mapped->pgshift = __ffs(page_size);
250-
bitmap->bitmap = data;
250+
bitmap->bitmap = (u8 __user *)data;
251251
bitmap->mapped_total_index =
252252
iova_bitmap_offset_to_index(bitmap, length - 1) + 1;
253253
bitmap->iova = iova;
@@ -304,7 +304,7 @@ static unsigned long iova_bitmap_mapped_remaining(struct iova_bitmap *bitmap)
304304

305305
remaining = bitmap->mapped_total_index - bitmap->mapped_base_index;
306306
remaining = min_t(unsigned long, remaining,
307-
bytes / sizeof(*bitmap->bitmap));
307+
DIV_ROUND_UP(bytes, sizeof(*bitmap->bitmap)));
308308

309309
return remaining;
310310
}

0 commit comments

Comments
 (0)