]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
mm/gup.c: Fix return value for __gup_longterm_locked()
authorShigeru Yoshida <syoshida@redhat.com>
Sun, 21 Aug 2022 18:35:47 +0000 (03:35 +0900)
committerAndrew Morton <akpm@linux-foundation.org>
Fri, 26 Aug 2022 05:02:53 +0000 (22:02 -0700)
__get_user_pages_locked() may return the number of pages less than
nr_pages.  So __gup_longterm_locked() have to return the number of pages
__get_user_pages_locked() returns if it succeeded, not nr_pages requested.

Link: https://lkml.kernel.org/r/20220821183547.950370-1-syoshida@redhat.com
Fixes: 61c63c2076d9 (mm/gup.c: simplify and fix check_and_migrate_movable_pages() return codes)
Signed-off-by: Shigeru Yoshida <syoshida@redhat.com>
Reviewed-by: John Hubbard <jhubbard@nvidia.com>
Reported-by: syzbot+616ff0452fec30f4dcfd@syzkaller.appspotmail.com
Reviewed-by: Alistair Popple <apopple@nvidia.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/gup.c

index 5aa7531a703bb51f030a0b20c2f81608850f7735..542cf74c59b0d920acdf1f5e2a890fae9cf7bc28 100644 (file)
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -2068,22 +2068,22 @@ static long __gup_longterm_locked(struct mm_struct *mm,
                                  unsigned int gup_flags)
 {
        unsigned int flags;
-       long rc;
+       long rc, nr_pinned_pages;
 
        if (!(gup_flags & FOLL_LONGTERM))
                return __get_user_pages_locked(mm, start, nr_pages, pages, vmas,
                                               NULL, gup_flags);
        flags = memalloc_pin_save();
        do {
-               rc = __get_user_pages_locked(mm, start, nr_pages, pages, vmas,
-                                            NULL, gup_flags);
-               if (rc <= 0)
+               nr_pinned_pages = __get_user_pages_locked(mm, start, nr_pages, pages, vmas,
+                                                         NULL, gup_flags);
+               if (nr_pinned_pages <= 0)
                        break;
-               rc = check_and_migrate_movable_pages(rc, pages, gup_flags);
+               rc = check_and_migrate_movable_pages(nr_pinned_pages, pages, gup_flags);
        } while (rc == -EAGAIN);
        memalloc_pin_restore(flags);
 
-       return rc ? rc : nr_pages;
+       return rc ? rc : nr_pinned_pages;
 }
 
 static bool is_valid_gup_flags(unsigned int gup_flags)