[Devel] [PATCH RHEL8 COMMIT] mm/gup: fix __get_user_pages() on fault retry of hugetlb

Konstantin Khorenko khorenko at virtuozzo.com
Mon Apr 20 10:34:08 MSK 2020


The commit is pushed to "branch-rh8-4.18.0-80.1.2.vz8.3.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-80.1.2.vz8.3.6
------>
commit 2a2c0236eabd1c7483e50b1c04828b94fc15b645
Author: Peter Xu <peterx at redhat.com>
Date:   Mon Apr 20 10:34:07 2020 +0300

    mm/gup: fix __get_user_pages() on fault retry of hugetlb
    
    When follow_hugetlb_page() returns with *locked==0, it means we've got a
    VM_FAULT_RETRY within the fauling process and we've released the mmap_sem.
    When that happens, we should stop and bail out.
    
    Signed-off-by: Peter Xu <peterx at redhat.com>
    Signed-off-by: Andrew Morton <akpm at linux-foundation.org>
    Tested-by: Brian Geffon <bgeffon at google.com>
    Cc: Andrea Arcangeli <aarcange at redhat.com>
    Cc: Bobby Powers <bobbypowers at gmail.com>
    Cc: David Hildenbrand <david at redhat.com>
    Cc: Denis Plotnikov <dplotnikov at virtuozzo.com>
    Cc: "Dr . David Alan Gilbert" <dgilbert at redhat.com>
    Cc: Hugh Dickins <hughd at google.com>
    Cc: Jerome Glisse <jglisse at redhat.com>
    Cc: Johannes Weiner <hannes at cmpxchg.org>
    Cc: "Kirill A . Shutemov" <kirill at shutemov.name>
    Cc: Martin Cracauer <cracauer at cons.org>
    Cc: Marty McFadden <mcfadden8 at llnl.gov>
    Cc: Matthew Wilcox <willy at infradead.org>
    Cc: Maya Gokhale <gokhale2 at llnl.gov>
    Cc: Mel Gorman <mgorman at suse.de>
    Cc: Mike Kravetz <mike.kravetz at oracle.com>
    Cc: Mike Rapoport <rppt at linux.vnet.ibm.com>
    Cc: Pavel Emelyanov <xemul at openvz.org>
    Link: http://lkml.kernel.org/r/20200220155353.8676-3-peterx@redhat.com
    Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>
    
    https://jira.sw.ru/browse/PSBM-102938
    (cherry picked from commit ad415db817964e96df824e8bb1a861527f8012b6)
    Signed-off-by: Andrey Ryabinin <aryabinin at virtuozzo.com>
---
 mm/gup.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/mm/gup.c b/mm/gup.c
index f609ac36aa9a..e06aa55b65b2 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -699,6 +699,15 @@ static long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
 				i = follow_hugetlb_page(mm, vma, pages, vmas,
 						&start, &nr_pages, i,
 						gup_flags, locked);
+				if (locked && *locked == 0) {
+					/*
+					 * We've got a VM_FAULT_RETRY
+					 * and we've lost mmap_sem.
+					 * We must stop here.
+					 */
+					BUG_ON(gup_flags & FOLL_NOWAIT);
+					goto out;
+				}
 				continue;
 			}
 		}
@@ -755,6 +764,7 @@ static long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
 		start += page_increm * PAGE_SIZE;
 		nr_pages -= page_increm;
 	} while (nr_pages);
+out:
 	return i;
 }
 


More information about the Devel mailing list