]> git.baikalelectronics.ru Git - kernel.git/commitdiff
mm/gup_benchmark: handle gup failures
authorMichael S. Tsirkin <mst@redhat.com>
Fri, 13 Apr 2018 22:35:16 +0000 (15:35 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sat, 14 Apr 2018 00:10:27 +0000 (17:10 -0700)
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.

[akpm@linux-foundation.org: simplification]
Link: http://lkml.kernel.org/r/1522962072-182137-3-git-send-email-mst@redhat.com
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Huang Ying <ying.huang@intel.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Thorsten Leemhuis <regressions@leemhuis.info>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
mm/gup_benchmark.c

index 5c8e2abeaa1598afbe0462762db25d2a017d814a..0f44759486e22e68ce88c9d73a4fdecd7eb925aa 100644 (file)
@@ -23,7 +23,7 @@ static int __gup_benchmark_ioctl(unsigned int cmd,
        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(unsigned int cmd,
                }
 
                nr = get_user_pages_fast(addr, nr, gup->flags & 1, pages + i);
+               if (nr <= 0)
+                       break;
                i += nr;
        }
        end_time = ktime_get();