Skip to content

Commit 67f4c91

Browse files
davidhildenbrandakpm00
authored andcommitted
selftests: mm: gup_longterm: test unsharing logic when R/O pinning
In our FOLL_LONGTERM tests, we prefault the page tables for the GUP-fast test cases to be able to find a PTE and exercise the "longterm pinning allowed" logic on the GUP-fast path where possible. For now, we always prefault the page tables writable, resulting in PTEs that are writable. Let's cover more cases to also test if our unsharing logic works as expected (and is able to make progress when there is nothing to unshare) by mprotect'ing the range R/O when R/O-pinning, so we don't get PTEs that are writable. This change would have found an issue introduced by commit a12083d ("mm/gup: handle hugepd for follow_page()"), whereby R/O pinning was not able to make progress in all cases, because unsharing logic was not provided with the VMA to decide at some point that long-term R/O pinning a !anon page is fine. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: David Hildenbrand <[email protected]> Acked-by: Peter Xu <[email protected]> Cc: Shuah Khan <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent cc48be3 commit 67f4c91

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

tools/testing/selftests/mm/gup_longterm.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,22 @@ static void do_test(int fd, size_t size, enum test_type type, bool shared)
118118
return;
119119
}
120120

121-
/*
122-
* Fault in the page writable such that GUP-fast can eventually pin
123-
* it immediately.
124-
*/
121+
/* Fault in the page such that GUP-fast can pin it directly. */
125122
memset(mem, 0, size);
126123

127124
switch (type) {
128125
case TEST_TYPE_RO:
129126
case TEST_TYPE_RO_FAST:
127+
/*
128+
* Cover more cases regarding unsharing decisions when
129+
* long-term R/O pinning by mapping the page R/O.
130+
*/
131+
ret = mprotect(mem, size, PROT_READ);
132+
if (ret) {
133+
ksft_test_result_fail("mprotect() failed\n");
134+
goto munmap;
135+
}
136+
/* FALLTHROUGH */
130137
case TEST_TYPE_RW:
131138
case TEST_TYPE_RW_FAST: {
132139
struct pin_longterm_test args;
@@ -228,6 +235,7 @@ static void do_test(int fd, size_t size, enum test_type type, bool shared)
228235
assert(false);
229236
}
230237

238+
munmap:
231239
munmap(mem, size);
232240
}
233241

0 commit comments

Comments
 (0)