mm/mlock.c | 10 +++++++++- 1 files changed, 9 insertions(+), 1 deletions(-) diff --git a/mm/mlock.c b/mm/mlock.c index 2689a08c79af..080c219973ea 100644 --- a/mm/mlock.c +++ b/mm/mlock.c @@ -162,6 +162,7 @@ static long __mlock_vma_pages_range(struct vm_area_struct *vma, unsigned long addr = start; int nr_pages = (end - start) / PAGE_SIZE; int gup_flags; + long retval, offset; VM_BUG_ON(start & ~PAGE_MASK); VM_BUG_ON(end & ~PAGE_MASK); @@ -189,13 +190,20 @@ static long __mlock_vma_pages_range(struct vm_area_struct *vma, gup_flags |= FOLL_MLOCK; /* We don't try to access the guard page of a stack vma */ + offset = 0; if (stack_guard_page(vma, start)) { addr += PAGE_SIZE; nr_pages--; + offset = 1; } - return __get_user_pages(current, mm, addr, nr_pages, gup_flags, + retval = __get_user_pages(current, mm, addr, nr_pages, gup_flags, NULL, NULL, nonblocking); + + /* Get the return value correct even in the face of the guard page */ + if (retval < 0) + return offset ? : retval; + return retval + offset; } /*