Skip to content

Commit c9459cb

Browse files
lorenzo-stoakesSasha Levin
authored andcommitted
mm/gup: explicitly define and check internal GUP flags, disallow FOLL_TOUCH
[ Upstream commit 0f20bba ] Rather than open-coding a list of internal GUP flags in is_valid_gup_args(), define which ones are internal. In addition, explicitly check to see if the user passed in FOLL_TOUCH somehow, as this appears to have been accidentally excluded. Link: https://lkml.kernel.org/r/971e013dfe20915612ea8b704e801d7aef9a66b6.1696288092.git.lstoakes@gmail.com Signed-off-by: Lorenzo Stoakes <[email protected]> Reviewed-by: Arnd Bergmann <[email protected]> Reviewed-by: David Hildenbrand <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Arnaldo Carvalho de Melo <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Ian Rogers <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: John Hubbard <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Oleg Nesterov <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Richard Cochran <[email protected]> Cc: Will Deacon <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Stable-dep-of: 631426b ("mm/madvise: make MADV_POPULATE_(READ|WRITE) handle VM_FAULT_RETRY properly") Signed-off-by: Sasha Levin <[email protected]>
1 parent 6ba8a2a commit c9459cb

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

mm/gup.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2227,12 +2227,11 @@ static bool is_valid_gup_args(struct page **pages, int *locked,
22272227
/*
22282228
* These flags not allowed to be specified externally to the gup
22292229
* interfaces:
2230-
* - FOLL_PIN/FOLL_TRIED/FOLL_FAST_ONLY are internal only
2230+
* - FOLL_TOUCH/FOLL_PIN/FOLL_TRIED/FOLL_FAST_ONLY are internal only
22312231
* - FOLL_REMOTE is internal only and used on follow_page()
22322232
* - FOLL_UNLOCKABLE is internal only and used if locked is !NULL
22332233
*/
2234-
if (WARN_ON_ONCE(gup_flags & (FOLL_PIN | FOLL_TRIED | FOLL_UNLOCKABLE |
2235-
FOLL_REMOTE | FOLL_FAST_ONLY)))
2234+
if (WARN_ON_ONCE(gup_flags & INTERNAL_GUP_FLAGS))
22362235
return false;
22372236

22382237
gup_flags |= to_set;

mm/internal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,9 @@ enum {
964964
FOLL_UNLOCKABLE = 1 << 21,
965965
};
966966

967+
#define INTERNAL_GUP_FLAGS (FOLL_TOUCH | FOLL_TRIED | FOLL_REMOTE | FOLL_PIN | \
968+
FOLL_FAST_ONLY | FOLL_UNLOCKABLE)
969+
967970
/*
968971
* Indicates for which pages that are write-protected in the page table,
969972
* whether GUP has to trigger unsharing via FAULT_FLAG_UNSHARE such that the

0 commit comments

Comments
 (0)