Skip to content

Commit 53e6b65

Browse files
jpemartinsjgunthorpe
authored andcommitted
iommufd/iova_bitmap: Remove iterator logic
The newly introduced dynamic pinning/windowing greatly simplifies the code and there's no obvious performance advantage that has been identified that justifies maintinaing both schemes. Remove the iterator logic and have iova_bitmap_for_each() just invoke the callback with the total iova/length. Fixes: 2780025 ("iommufd/iova_bitmap: Handle recording beyond the mapped pages") Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joao Martins <[email protected]> Reviewed-by: Kevin Tian <[email protected]> Tested-by: Matt Ochs <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 7a7bba1 commit 53e6b65

File tree

1 file changed

+2
-95
lines changed

1 file changed

+2
-95
lines changed

drivers/iommu/iommufd/iova_bitmap.c

Lines changed: 2 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,6 @@ struct iova_bitmap {
116116

117117
/* length of the IOVA range for the whole bitmap */
118118
size_t length;
119-
120-
/* length of the IOVA range set ahead the pinned pages */
121-
unsigned long set_ahead_length;
122-
123-
/* true if it using the iterator otherwise it pins dynamically */
124-
bool iterator;
125119
};
126120

127121
/*
@@ -354,40 +348,6 @@ static bool iova_bitmap_mapped_range(struct iova_bitmap_map *mapped,
354348
(iova + length - 1) <= (mapped->iova + mapped->length - 1));
355349
}
356350

357-
/*
358-
* Returns true if there's not more data to iterate.
359-
*/
360-
static bool iova_bitmap_done(struct iova_bitmap *bitmap)
361-
{
362-
return bitmap->mapped_base_index >= bitmap->mapped_total_index;
363-
}
364-
365-
static int iova_bitmap_set_ahead(struct iova_bitmap *bitmap,
366-
size_t set_ahead_length)
367-
{
368-
int ret = 0;
369-
370-
while (set_ahead_length > 0 && !iova_bitmap_done(bitmap)) {
371-
unsigned long length = iova_bitmap_mapped_length(bitmap);
372-
unsigned long iova = iova_bitmap_mapped_iova(bitmap);
373-
374-
ret = iova_bitmap_get(bitmap);
375-
if (ret)
376-
break;
377-
378-
length = min(length, set_ahead_length);
379-
iova_bitmap_set(bitmap, iova, length);
380-
381-
set_ahead_length -= length;
382-
bitmap->mapped_base_index +=
383-
iova_bitmap_offset_to_index(bitmap, length - 1) + 1;
384-
iova_bitmap_put(bitmap);
385-
}
386-
387-
bitmap->set_ahead_length = 0;
388-
return ret;
389-
}
390-
391351
/*
392352
* Advances to a selected range, releases the current pinned
393353
* pages and pins the next set of bitmap pages.
@@ -409,36 +369,6 @@ static int iova_bitmap_advance_to(struct iova_bitmap *bitmap,
409369
return iova_bitmap_get(bitmap);
410370
}
411371

412-
/*
413-
* Advances to the next range, releases the current pinned
414-
* pages and pins the next set of bitmap pages.
415-
* Returns 0 on success or otherwise errno.
416-
*/
417-
static int iova_bitmap_advance(struct iova_bitmap *bitmap)
418-
{
419-
unsigned long iova = iova_bitmap_mapped_length(bitmap) - 1;
420-
unsigned long count = iova_bitmap_offset_to_index(bitmap, iova) + 1;
421-
422-
bitmap->mapped_base_index += count;
423-
424-
iova_bitmap_put(bitmap);
425-
426-
/* Iterate, set and skip any bits requested for next iteration */
427-
if (bitmap->set_ahead_length) {
428-
int ret;
429-
430-
ret = iova_bitmap_set_ahead(bitmap, bitmap->set_ahead_length);
431-
if (ret)
432-
return ret;
433-
}
434-
435-
if (iova_bitmap_done(bitmap))
436-
return 0;
437-
438-
/* When advancing the index we pin the next set of bitmap pages */
439-
return iova_bitmap_get(bitmap);
440-
}
441-
442372
/**
443373
* iova_bitmap_for_each() - Iterates over the bitmap
444374
* @bitmap: IOVA bitmap to iterate
@@ -455,23 +385,7 @@ static int iova_bitmap_advance(struct iova_bitmap *bitmap)
455385
int iova_bitmap_for_each(struct iova_bitmap *bitmap, void *opaque,
456386
iova_bitmap_fn_t fn)
457387
{
458-
int ret = 0;
459-
460-
ret = iova_bitmap_get(bitmap);
461-
if (ret)
462-
return ret;
463-
464-
bitmap->iterator = true;
465-
for (; !iova_bitmap_done(bitmap) && !ret;
466-
ret = iova_bitmap_advance(bitmap)) {
467-
ret = fn(bitmap, iova_bitmap_mapped_iova(bitmap),
468-
iova_bitmap_mapped_length(bitmap), opaque);
469-
if (ret)
470-
break;
471-
}
472-
bitmap->iterator = false;
473-
474-
return ret;
388+
return fn(bitmap, bitmap->iova, bitmap->length, opaque);
475389
}
476390
EXPORT_SYMBOL_NS_GPL(iova_bitmap_for_each, IOMMUFD);
477391

@@ -492,15 +406,12 @@ void iova_bitmap_set(struct iova_bitmap *bitmap,
492406
unsigned long cur_bit, last_bit, last_page_idx;
493407

494408
update_indexes:
495-
if (unlikely(!bitmap->iterator &&
496-
!iova_bitmap_mapped_range(mapped, iova, length))) {
409+
if (unlikely(!iova_bitmap_mapped_range(mapped, iova, length))) {
497410

498411
/*
499412
* The attempt to advance the base index to @iova
500413
* may fail if it's out of bounds, or pinning the pages
501414
* returns an error.
502-
*
503-
* It is a no-op if within a iova_bitmap_for_each() closure.
504415
*/
505416
if (iova_bitmap_advance_to(bitmap, iova))
506417
return;
@@ -523,10 +434,6 @@ void iova_bitmap_set(struct iova_bitmap *bitmap,
523434
unsigned long left =
524435
((last_bit - cur_bit + 1) << mapped->pgshift);
525436

526-
if (bitmap->iterator) {
527-
bitmap->set_ahead_length = left;
528-
return;
529-
}
530437
iova += (length - left);
531438
length = left;
532439
goto update_indexes;

0 commit comments

Comments
 (0)