Skip to content

Commit 4bbcbc6

Browse files
jpemartinsjgunthorpe
authored andcommitted
iommufd/iova_bitmap: Consider page offset for the pages to be pinned
For small bitmaps that aren't PAGE_SIZE aligned *and* that are less than 512 pages in bitmap length, use an extra page to be able to cover the entire range e.g. [1M..3G] which would be iterated more efficiently in a single iteration, rather than two. 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 fe13166 commit 4bbcbc6

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

drivers/iommu/iommufd/iova_bitmap.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,18 +178,19 @@ static int iova_bitmap_get(struct iova_bitmap *bitmap)
178178
bitmap->mapped_base_index) *
179179
sizeof(*bitmap->bitmap), PAGE_SIZE);
180180

181-
/*
182-
* We always cap at max number of 'struct page' a base page can fit.
183-
* This is, for example, on x86 means 2M of bitmap data max.
184-
*/
185-
npages = min(npages, PAGE_SIZE / sizeof(struct page *));
186-
187181
/*
188182
* Bitmap address to be pinned is calculated via pointer arithmetic
189183
* with bitmap u64 word index.
190184
*/
191185
addr = bitmap->bitmap + bitmap->mapped_base_index;
192186

187+
/*
188+
* We always cap at max number of 'struct page' a base page can fit.
189+
* This is, for example, on x86 means 2M of bitmap data max.
190+
*/
191+
npages = min(npages + !!offset_in_page(addr),
192+
PAGE_SIZE / sizeof(struct page *));
193+
193194
ret = pin_user_pages_fast((unsigned long)addr, npages,
194195
FOLL_WRITE, mapped->pages);
195196
if (ret <= 0)

0 commit comments

Comments
 (0)