Skip to content

Commit 55b8fe7

Browse files
author
Andreas Gruenbacher
committed
gup: Introduce FOLL_NOFAULT flag to disable page faults
Introduce a new FOLL_NOFAULT flag that causes get_user_pages to return -EFAULT when it would otherwise trigger a page fault. This is roughly similar to FOLL_FAST_ONLY but available on all architectures, and less fragile. Signed-off-by: Andreas Gruenbacher <[email protected]>
1 parent 4fdccaa commit 55b8fe7

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

include/linux/mm.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2851,7 +2851,8 @@ struct page *follow_page(struct vm_area_struct *vma, unsigned long address,
28512851
#define FOLL_FORCE 0x10 /* get_user_pages read/write w/o permission */
28522852
#define FOLL_NOWAIT 0x20 /* if a disk transfer is needed, start the IO
28532853
* and return without waiting upon it */
2854-
#define FOLL_POPULATE 0x40 /* fault in page */
2854+
#define FOLL_POPULATE 0x40 /* fault in pages (with FOLL_MLOCK) */
2855+
#define FOLL_NOFAULT 0x80 /* do not fault in pages */
28552856
#define FOLL_HWPOISON 0x100 /* check page is hwpoisoned */
28562857
#define FOLL_NUMA 0x200 /* force NUMA hinting page fault */
28572858
#define FOLL_MIGRATION 0x400 /* wait for page to replace migration entry */

mm/gup.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,8 @@ static int faultin_page(struct vm_area_struct *vma,
918918
/* mlock all present pages, but do not fault in new pages */
919919
if ((*flags & (FOLL_POPULATE | FOLL_MLOCK)) == FOLL_MLOCK)
920920
return -ENOENT;
921+
if (*flags & FOLL_NOFAULT)
922+
return -EFAULT;
921923
if (*flags & FOLL_WRITE)
922924
fault_flags |= FAULT_FLAG_WRITE;
923925
if (*flags & FOLL_REMOTE)
@@ -2843,7 +2845,7 @@ static int internal_get_user_pages_fast(unsigned long start,
28432845

28442846
if (WARN_ON_ONCE(gup_flags & ~(FOLL_WRITE | FOLL_LONGTERM |
28452847
FOLL_FORCE | FOLL_PIN | FOLL_GET |
2846-
FOLL_FAST_ONLY)))
2848+
FOLL_FAST_ONLY | FOLL_NOFAULT)))
28472849
return -EINVAL;
28482850

28492851
if (gup_flags & FOLL_PIN)

0 commit comments

Comments
 (0)