Skip to contentSkip to conversation

mm/gup_benchmark: handle gup failures

PATCH New [email protected] 1 participant 1 message Apr 13, 2018

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH 2/27 mm/gup_benchmark: handle gup failures

From: "Michael S. Tsirkin" <[email protected]>
Subject: 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]
Cc Kirill A. Shutemov <[email protected]>
Cc Huang Ying <[email protected]>
Cc Jonathan Corbet <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Thorsten Leemhuis <[email protected]>

---

 mm/gup_benchmark.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
mm/gup_benchmark.c renamed from mm/gup_benchmark.c~mm-gup_benchmark-handle-gup-failures +3 -1
diff -puN mm/gup_benchmark.c~mm-gup_benchmark-handle-gup-failures mm/gup_benchmark.c
@@ -23,7 +23,7 @@ static int __gup_benchmark_ioctl(unsigne
 	struct page **pages;
 
 	nr_pages = gup->size / PAGE_SIZE;
-	pages = kvmalloc(sizeof(void *) * nr_pages, GFP_KERNEL);
+	pages = kvzalloc(sizeof(void *) * nr_pages, GFP_KERNEL);
 	if (!pages)
 		return -ENOMEM;
 
@@ -41,6 +41,8 @@ static int __gup_benchmark_ioctl(unsigne
 		}
 
 		nr = get_user_pages_fast(addr, nr, gup->flags & 1, pages + i);
+		if (nr <= 0)
+			break;
 		i += nr;
 	}
 	end_time = ktime_get();

_