Skip to content

Commit a26fa39

Browse files
committed
iommufd: Improve a few unclear bits of code
Correct a few items noticed late in review: - We should assert that the math in batch_clear_carry() doesn't underflow - user->locked should be -1 not 0 sicne we just did mmput - npages should not have been recalculated, it already has that value No functional change. Fixes: 8d160cd ("iommufd: Algorithms for PFN storage") Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Kevin Tian <[email protected]> Reviewed-by: Eric Auger <[email protected]> Reported-by: Binbin Wu <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent c9b8a83 commit a26fa39

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

drivers/iommu/iommufd/pages.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,10 @@ static void batch_clear_carry(struct pfn_batch *batch, unsigned int keep_pfns)
289289
if (!keep_pfns)
290290
return batch_clear(batch);
291291

292+
if (IS_ENABLED(CONFIG_IOMMUFD_TEST))
293+
WARN_ON(!batch->end ||
294+
batch->npfns[batch->end - 1] < keep_pfns);
295+
292296
batch->total_pfns = keep_pfns;
293297
batch->npfns[0] = keep_pfns;
294298
batch->pfns[0] = batch->pfns[batch->end - 1] +
@@ -723,7 +727,7 @@ static void pfn_reader_user_destroy(struct pfn_reader_user *user,
723727
mmap_read_unlock(pages->source_mm);
724728
if (pages->source_mm != current->mm)
725729
mmput(pages->source_mm);
726-
user->locked = 0;
730+
user->locked = -1;
727731
}
728732

729733
kfree(user->upages);
@@ -810,7 +814,6 @@ static int incr_user_locked_vm(struct iopt_pages *pages, unsigned long npages)
810814

811815
lock_limit = task_rlimit(pages->source_task, RLIMIT_MEMLOCK) >>
812816
PAGE_SHIFT;
813-
npages = pages->npinned - pages->last_npinned;
814817
do {
815818
cur_pages = atomic_long_read(&pages->source_user->locked_vm);
816819
new_pages = cur_pages + npages;

0 commit comments

Comments
 (0)