Skip to content

Commit 583ef6b

Browse files
lorenzo-stoakesMa Wupeng
authored andcommitted
mm/gup: explicitly define and check internal GUP flags, disallow FOLL_TOUCH
stable inclusion from stable-v6.6.30 commit 49db746d39887287d8dc4ff76d760320388e9eeb bugzilla: https://gitee.com/openeuler/kernel/issues/I9MPZ8 Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=49db746d39887287d8dc4ff76d760320388e9eeb -------------------------------- [ Upstream commit 0f20bba1688bdf3b32df0162511a67d4eda15790 ] 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 <lstoakes@gmail.com> Reviewed-by: Arnd Bergmann <arnd@arndb.de> Reviewed-by: David Hildenbrand <david@redhat.com> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Arnaldo Carvalho de Melo <acme@kernel.org> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Ian Rogers <irogers@google.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: John Hubbard <jhubbard@nvidia.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Richard Cochran <richardcochran@gmail.com> Cc: Will Deacon <will@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Stable-dep-of: 631426ba1d45 ("mm/madvise: make MADV_POPULATE_(READ|WRITE) handle VM_FAULT_RETRY properly") Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: ZhangPeng <zhangpeng362@huawei.com>
1 parent 62f7c3b commit 583ef6b

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
@@ -2232,12 +2232,11 @@ static bool is_valid_gup_args(struct page **pages, int *locked,
22322232
/*
22332233
* These flags not allowed to be specified externally to the gup
22342234
* interfaces:
2235-
* - FOLL_PIN/FOLL_TRIED/FOLL_FAST_ONLY are internal only
2235+
* - FOLL_TOUCH/FOLL_PIN/FOLL_TRIED/FOLL_FAST_ONLY are internal only
22362236
* - FOLL_REMOTE is internal only and used on follow_page()
22372237
* - FOLL_UNLOCKABLE is internal only and used if locked is !NULL
22382238
*/
2239-
if (WARN_ON_ONCE(gup_flags & (FOLL_PIN | FOLL_TRIED | FOLL_UNLOCKABLE |
2240-
FOLL_REMOTE | FOLL_FAST_ONLY)))
2239+
if (WARN_ON_ONCE(gup_flags & INTERNAL_GUP_FLAGS))
22412240
return false;
22422241

22432242
gup_flags |= to_set;

mm/internal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,9 @@ enum {
11291129
FOLL_UNLOCKABLE = 1 << 21,
11301130
};
11311131

1132+
#define INTERNAL_GUP_FLAGS (FOLL_TOUCH | FOLL_TRIED | FOLL_REMOTE | FOLL_PIN | \
1133+
FOLL_FAST_ONLY | FOLL_UNLOCKABLE)
1134+
11321135
/*
11331136
* Indicates for which pages that are write-protected in the page table,
11341137
* whether GUP has to trigger unsharing via FAULT_FLAG_UNSHARE such that the

0 commit comments

Comments
 (0)