The patch titled Subject: mm/gup_benchmark: take the mmap lock around GUP has been added to the -mm tree. Its filename is mm-gup_benchmark-take-the-mmap-lock-around-gup.patch This patch should soon appear at https://ozlabs.org/~akpm/mmots/broken-out/mm-gup_benchmark-take-the-mmap-lock-around-gup.patch and later at https://ozlabs.org/~akpm/mmotm/broken-out/mm-gup_benchmark-take-the-mmap-lock-around-gup.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Jann Horn <jannh@xxxxxxxxxx> Subject: mm/gup_benchmark: take the mmap lock around GUP To be safe against concurrent changes to the VMA tree, we must take the mmap lock around GUP operations (excluding the GUP-fast family of operations, which will take the mmap lock by themselves if necessary). This code is only for testing, and it's only reachable by root through debugfs, so this doesn't really have any impact; however, if we want to add lockdep asserts into the GUP path, we need to have clean locking here. Link: https://lkml.kernel.org/r/CAG48ez3SG6ngZLtasxJ6LABpOnqCz5-QHqb0B4k44TQ8F9n6+w@xxxxxxxxxxxxxx Signed-off-by: Jann Horn <jannh@xxxxxxxxxx> Reviewed-by: Jason Gunthorpe <jgg@xxxxxxxxxx> Reviewed-by: John Hubbard <jhubbard@xxxxxxxxxx> Cc: "Eric W . Biederman" <ebiederm@xxxxxxxxxxxx> Cc: Michel Lespinasse <walken@xxxxxxxxxx> Cc: Mauro Carvalho Chehab <mchehab@xxxxxxxxxx> Cc: Sakari Ailus <sakari.ailus@xxxxxxxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- mm/gup_benchmark.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) --- a/mm/gup_benchmark.c~mm-gup_benchmark-take-the-mmap-lock-around-gup +++ a/mm/gup_benchmark.c @@ -72,6 +72,8 @@ static int __gup_benchmark_ioctl(unsigne int nr; struct page **pages; int ret = 0; + bool needs_mmap_lock = + cmd != GUP_FAST_BENCHMARK && cmd != PIN_FAST_BENCHMARK; if (gup->size > ULONG_MAX) return -EINVAL; @@ -81,6 +83,11 @@ static int __gup_benchmark_ioctl(unsigne if (!pages) return -ENOMEM; + if (needs_mmap_lock && mmap_read_lock_killable(current->mm)) { + ret = -EINTR; + goto free_pages; + } + i = 0; nr = gup->nr_pages_per_call; start_time = ktime_get(); @@ -120,9 +127,8 @@ static int __gup_benchmark_ioctl(unsigne pages + i, NULL); break; default: - kvfree(pages); ret = -EINVAL; - goto out; + goto unlock; } if (nr <= 0) @@ -150,8 +156,11 @@ static int __gup_benchmark_ioctl(unsigne end_time = ktime_get(); gup->put_delta_usec = ktime_us_delta(end_time, start_time); +unlock: + if (needs_mmap_lock) + mmap_read_unlock(current->mm); +free_pages: kvfree(pages); -out: return ret; } _ Patches currently in -mm which might be from jannh@xxxxxxxxxx are mm-mmu_notifier-fix-mmget-assert-in-__mmu_interval_notifier_insert.patch binfmt_elf_fdpic-stop-using-dump_emit-on-user-pointers-on-mmu.patch coredump-let-dump_emit-bail-out-on-short-writes.patch coredump-refactor-page-range-dumping-into-common-helper.patch coredump-rework-elf-elf_fdpic-vma_dump_size-into-common-helper.patch binfmt_elf-binfmt_elf_fdpic-use-a-vma-list-snapshot.patch mm-gup-take-mmap_lock-in-get_dump_page.patch mm-remove-the-now-unnecessary-mmget_still_valid-hack.patch mm-gup_benchmark-take-the-mmap-lock-around-gup.patch binfmt_elf-take-the-mmap-lock-around-find_extend_vma.patch mmap-locking-api-dont-check-locking-if-the-mm-isnt-live-yet.patch mm-gup-assert-that-the-mmap-lock-is-held-in-__get_user_pages.patch