Skip to content
This repository was archived by the owner on Oct 30, 2021. It is now read-only.

Commit 810a56b

Browse files
mjkravetztorvalds
authored andcommitted
userfaultfd: hugetlbfs: fix __mcopy_atomic_hugetlb retry/error processing
The new routine copy_huge_page_from_user() uses kmap_atomic() to map PAGE_SIZE pages. However, this prevents page faults in the subsequent call to copy_from_user(). This is OK in the case where the routine is copied with mmap_sema held. However, in another case we want to allow page faults. So, add a new argument allow_pagefault to indicate if the routine should allow page faults. [dan.carpenter@oracle.com: unmap the correct pointer] Link: http://lkml.kernel.org/r/20170113082608.GA3548@mwanda [akpm@linux-foundation.org: kunmap() takes a page*, per Hugh] Link: http://lkml.kernel.org/r/20161216144821.5183-20-aarcange@redhat.com Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com> Signed-off-by: Andrea Arcangeli <aarcange@redhat.com> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Cc: "Dr. David Alan Gilbert" <dgilbert@redhat.com> Cc: Hillf Danton <hillf.zj@alibaba-inc.com> Cc: Michael Rapoport <RAPOPORT@il.ibm.com> Cc: Mike Rapoport <rppt@linux.vnet.ibm.com> Cc: Pavel Emelyanov <xemul@parallels.com> Cc: Hugh Dickins <hughd@google.com> Cc: Hugh Dickins <hughd@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 60d4d2d commit 810a56b

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

include/linux/mm.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -2426,7 +2426,8 @@ extern void copy_user_huge_page(struct page *dst, struct page *src,
24262426
unsigned int pages_per_huge_page);
24272427
extern long copy_huge_page_from_user(struct page *dst_page,
24282428
const void __user *usr_src,
2429-
unsigned int pages_per_huge_page);
2429+
unsigned int pages_per_huge_page,
2430+
bool allow_pagefault);
24302431
#endif /* CONFIG_TRANSPARENT_HUGEPAGE || CONFIG_HUGETLBFS */
24312432

24322433
extern struct page_ext_operations debug_guardpage_ops;

mm/hugetlb.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -3973,7 +3973,7 @@ int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm,
39733973

39743974
ret = copy_huge_page_from_user(page,
39753975
(const void __user *) src_addr,
3976-
pages_per_huge_page(h));
3976+
pages_per_huge_page(h), false);
39773977

39783978
/* fallback to copy_from_user outside mmap_sem */
39793979
if (unlikely(ret)) {

mm/memory.c

+10-3
Original file line numberDiff line numberDiff line change
@@ -4155,19 +4155,26 @@ void copy_user_huge_page(struct page *dst, struct page *src,
41554155

41564156
long copy_huge_page_from_user(struct page *dst_page,
41574157
const void __user *usr_src,
4158-
unsigned int pages_per_huge_page)
4158+
unsigned int pages_per_huge_page,
4159+
bool allow_pagefault)
41594160
{
41604161
void *src = (void *)usr_src;
41614162
void *page_kaddr;
41624163
unsigned long i, rc = 0;
41634164
unsigned long ret_val = pages_per_huge_page * PAGE_SIZE;
41644165

41654166
for (i = 0; i < pages_per_huge_page; i++) {
4166-
page_kaddr = kmap_atomic(dst_page + i);
4167+
if (allow_pagefault)
4168+
page_kaddr = kmap(dst_page + i);
4169+
else
4170+
page_kaddr = kmap_atomic(dst_page + i);
41674171
rc = copy_from_user(page_kaddr,
41684172
(const void __user *)(src + i * PAGE_SIZE),
41694173
PAGE_SIZE);
4170-
kunmap_atomic(page_kaddr);
4174+
if (allow_pagefault)
4175+
kunmap(dst_page + i);
4176+
else
4177+
kunmap_atomic(page_kaddr);
41714178

41724179
ret_val -= (PAGE_SIZE - rc);
41734180
if (rc)

mm/userfaultfd.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ static __always_inline ssize_t __mcopy_atomic_hugetlb(struct mm_struct *dst_mm,
274274

275275
err = copy_huge_page_from_user(page,
276276
(const void __user *)src_addr,
277-
pages_per_huge_page(h));
277+
pages_per_huge_page(h), true);
278278
if (unlikely(err)) {
279279
err = -EFAULT;
280280
goto out;

0 commit comments

Comments
 (0)