Skip to content

Commit 09e35a4

Browse files
mstsirkintorvalds
authored andcommitted
mm/gup_benchmark: handle gup failures
Patch series "mm/get_user_pages_fast fixes, cleanups", v2. Turns out get_user_pages_fast and __get_user_pages_fast return different values on error when given a single page: __get_user_pages_fast returns 0. get_user_pages_fast returns either 0 or an error. Callers of get_user_pages_fast expect an error so fix it up to return an error consistently. Stress the difference between get_user_pages_fast and __get_user_pages_fast to make sure callers aren't confused. This patch (of 3): __gup_benchmark_ioctl does not handle the case where get_user_pages_fast fails: - a negative return code will cause a buffer overrun - returning with partial success will cause use of uninitialized memory. [[email protected]: simplification] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Michael S. Tsirkin <[email protected]> Reviewed-by: Andrew Morton <[email protected]> Cc: Kirill A. Shutemov <[email protected]> Cc: Huang Ying <[email protected]> Cc: Jonathan Corbet <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Thorsten Leemhuis <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 60bb83b commit 09e35a4

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

mm/gup_benchmark.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ static int __gup_benchmark_ioctl(unsigned int cmd,
2323
struct page **pages;
2424

2525
nr_pages = gup->size / PAGE_SIZE;
26-
pages = kvmalloc(sizeof(void *) * nr_pages, GFP_KERNEL);
26+
pages = kvzalloc(sizeof(void *) * nr_pages, GFP_KERNEL);
2727
if (!pages)
2828
return -ENOMEM;
2929

@@ -41,6 +41,8 @@ static int __gup_benchmark_ioctl(unsigned int cmd,
4141
}
4242

4343
nr = get_user_pages_fast(addr, nr, gup->flags & 1, pages + i);
44+
if (nr <= 0)
45+
break;
4446
i += nr;
4547
}
4648
end_time = ktime_get();

0 commit comments

Comments
 (0)