* [PATCH 0/2] selftests/mm: fix userfaultfd tests with CONFIG_PTE_MARKER_UFFD_WP=n
@ 2026-11-22 8:20 kaleshsingh
2026-11-22 8:20 ` [PATCH 1/2] selftests/mm: uffd-wp-mremap: skip unsupported shmem and hugetlb cases kaleshsingh
2026-11-22 8:20 ` [PATCH 2/2] selftests/mm: uffd-unit-tests: filter required features per memory type kaleshsingh
0 siblings, 2 replies; 7+ messages in thread
From: kaleshsingh @ 2026-11-22 8:20 UTC (permalink / raw)
To: akpm
Cc: kernel-team, android-mm, Kalesh Singh, Mike Rapoport, Peter Xu,
David Hildenbrand, Lorenzo Stoakes, Liam R. Howlett,
Vlastimil Babka, Suren Baghdasaryan, Michal Hocko, Shuah Khan,
Ryan Roberts, linux-mm, linux-kselftest
From: Kalesh Singh <kaleshsingh@google.com>
With CONFIG_PTE_MARKER_UFFD_WP=n, userfaultfd write protection only
works on anonymous memory. uffd-wp-mremap then fails its shmem and
hugetlb cases, and uffd-unit-tests skips anonymous runs that would
pass. Patch 1 skips the unsupported uffd-wp-mremap cases and patch 2
filters uffd-unit-tests' required features per memory type.
Tested on arm64 device: with CONFIG_PTE_MARKER_UFFD_WP=n,
uffd-wp-mremap goes from 26 failures to none and uffd-unit-tests
passes 78 tests instead of 70; with =y, the results are unchanged.
Kalesh Singh (2):
selftests/mm: uffd-wp-mremap: skip unsupported shmem and hugetlb cases
selftests/mm: uffd-unit-tests: filter required features per memory
type
tools/testing/selftests/mm/uffd-unit-tests.c | 42 +++++++++++++++++---
tools/testing/selftests/mm/uffd-wp-mremap.c | 13 ++++--
2 files changed, 46 insertions(+), 9 deletions(-)
base-commit: 4843f6873f7c4835e62f2c73ba0fd538e57a2f22
--
2.56.1.750.gf70dc682cf-goog
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH 1/2] selftests/mm: uffd-wp-mremap: skip unsupported shmem and hugetlb cases 2026-11-22 8:20 [PATCH 0/2] selftests/mm: fix userfaultfd tests with CONFIG_PTE_MARKER_UFFD_WP=n kaleshsingh @ 2026-11-22 8:20 ` kaleshsingh 2026-11-24 14:13 ` Liam R. Howlett 2026-11-24 23:34 ` + selftests-mm-uffd-wp-mremap-skip-unsupported-shmem-and-hugetlb-cases.patch added to mm-new branch Andrew Morton 2026-11-22 8:20 ` [PATCH 2/2] selftests/mm: uffd-unit-tests: filter required features per memory type kaleshsingh 1 sibling, 2 replies; 7+ messages in thread From: kaleshsingh @ 2026-11-22 8:20 UTC (permalink / raw) To: akpm Cc: kernel-team, android-mm, Kalesh Singh, Lokesh Gidra, Mike Rapoport, Peter Xu, David Hildenbrand, Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka, Suren Baghdasaryan, Michal Hocko, Shuah Khan, Ryan Roberts, linux-mm, linux-kselftest From: Kalesh Singh <kaleshsingh@google.com> uffd-wp-mremap checks only for UFFD_FEATURE_PAGEFAULT_FLAG_WP before it runs. With CONFIG_PTE_MARKER_UFFD_WP=n the kernel keeps that feature but supports write protection on anonymous memory only, so the shmem and hugetlb cases fail with EINVAL from UFFDIO_REGISTER instead of skipping. Skip them when UFFD_FEATURE_WP_HUGETLBFS_SHMEM is missing. Fixes: b2466bb3b495 ("selftests/mm: introduce uffd-wp-mremap regression test") Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Lokesh Gidra <lokeshgidra@google.com> Signed-off-by: Kalesh Singh <kaleshsingh@google.com> --- tools/testing/selftests/mm/uffd-wp-mremap.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/mm/uffd-wp-mremap.c b/tools/testing/selftests/mm/uffd-wp-mremap.c index c48eaab8e75c..f7b272baa6f5 100644 --- a/tools/testing/selftests/mm/uffd-wp-mremap.c +++ b/tools/testing/selftests/mm/uffd-wp-mremap.c @@ -18,15 +18,14 @@ static int nr_thpsizes; static size_t thpsizes[20]; static int nr_hugetlbsizes; static unsigned long hugetlbsizes[10]; +static uint64_t uffd_features; static void check_uffd_wp_feature_supported(void) { - uint64_t features = 0; - - if (uffd_get_features(&features)) + if (uffd_get_features(&uffd_features)) ksft_exit_skip("failed to get available features (%d)\n", errno); - if (!(features & UFFD_FEATURE_PAGEFAULT_FLAG_WP)) + if (!(uffd_features & UFFD_FEATURE_PAGEFAULT_FLAG_WP)) ksft_exit_skip("uffd-wp feature not supported\n"); } @@ -180,6 +179,12 @@ static void test_one_folio(uffd_global_test_opts_t *gopts, size_t size, bool pri swapout ? "true" : "false", hugetlb ? "true" : "false"); + if ((!private || hugetlb) && + !(uffd_features & UFFD_FEATURE_WP_HUGETLBFS_SHMEM)) { + ksft_test_result_skip("uffd-wp on shmem and hugetlbfs is not supported\n"); + return; + } + /* Allocate a folio of required size and type. */ mem = alloc_one_folio(size, private, hugetlb); if (!mem) { -- 2.56.1.750.gf70dc682cf-goog ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] selftests/mm: uffd-wp-mremap: skip unsupported shmem and hugetlb cases 2026-11-22 8:20 ` [PATCH 1/2] selftests/mm: uffd-wp-mremap: skip unsupported shmem and hugetlb cases kaleshsingh @ 2026-11-24 14:13 ` Liam R. Howlett 2026-11-24 23:34 ` + selftests-mm-uffd-wp-mremap-skip-unsupported-shmem-and-hugetlb-cases.patch added to mm-new branch Andrew Morton 1 sibling, 0 replies; 7+ messages in thread From: Liam R. Howlett @ 2026-11-24 14:13 UTC (permalink / raw) To: kaleshsingh Cc: akpm, kernel-team, android-mm, Lokesh Gidra, Mike Rapoport, Peter Xu, David Hildenbrand, Lorenzo Stoakes, Vlastimil Babka, Suren Baghdasaryan, Michal Hocko, Shuah Khan, Ryan Roberts, linux-mm, linux-kselftest On 26/11/22 08:20AM, kaleshsingh@google.com wrote: > From: Kalesh Singh <kaleshsingh@google.com> > > uffd-wp-mremap checks only for UFFD_FEATURE_PAGEFAULT_FLAG_WP before it > runs. With CONFIG_PTE_MARKER_UFFD_WP=n the kernel keeps that feature > but supports write protection on anonymous memory only, so the shmem > and hugetlb cases fail with EINVAL from UFFDIO_REGISTER instead of > skipping. Skip them when UFFD_FEATURE_WP_HUGETLBFS_SHMEM is missing. > > Fixes: b2466bb3b495 ("selftests/mm: introduce uffd-wp-mremap regression test") > Cc: Andrew Morton <akpm@linux-foundation.org> > Cc: Lokesh Gidra <lokeshgidra@google.com> > Signed-off-by: Kalesh Singh <kaleshsingh@google.com> Reviewed-by: Liam R. Howlett (Google) <liam@infradead.org> > --- > tools/testing/selftests/mm/uffd-wp-mremap.c | 13 +++++++++---- > 1 file changed, 9 insertions(+), 4 deletions(-) > > diff --git a/tools/testing/selftests/mm/uffd-wp-mremap.c b/tools/testing/selftests/mm/uffd-wp-mremap.c > index c48eaab8e75c..f7b272baa6f5 100644 > --- a/tools/testing/selftests/mm/uffd-wp-mremap.c > +++ b/tools/testing/selftests/mm/uffd-wp-mremap.c > @@ -18,15 +18,14 @@ static int nr_thpsizes; > static size_t thpsizes[20]; > static int nr_hugetlbsizes; > static unsigned long hugetlbsizes[10]; > +static uint64_t uffd_features; > > static void check_uffd_wp_feature_supported(void) > { > - uint64_t features = 0; > - > - if (uffd_get_features(&features)) > + if (uffd_get_features(&uffd_features)) > ksft_exit_skip("failed to get available features (%d)\n", errno); > > - if (!(features & UFFD_FEATURE_PAGEFAULT_FLAG_WP)) > + if (!(uffd_features & UFFD_FEATURE_PAGEFAULT_FLAG_WP)) > ksft_exit_skip("uffd-wp feature not supported\n"); > } > > @@ -180,6 +179,12 @@ static void test_one_folio(uffd_global_test_opts_t *gopts, size_t size, bool pri > swapout ? "true" : "false", > hugetlb ? "true" : "false"); > > + if ((!private || hugetlb) && > + !(uffd_features & UFFD_FEATURE_WP_HUGETLBFS_SHMEM)) { > + ksft_test_result_skip("uffd-wp on shmem and hugetlbfs is not supported\n"); > + return; > + } > + > /* Allocate a folio of required size and type. */ > mem = alloc_one_folio(size, private, hugetlb); > if (!mem) { > -- > 2.56.1.750.gf70dc682cf-goog > ^ permalink raw reply [flat|nested] 7+ messages in thread
* + selftests-mm-uffd-wp-mremap-skip-unsupported-shmem-and-hugetlb-cases.patch added to mm-new branch 2026-11-22 8:20 ` [PATCH 1/2] selftests/mm: uffd-wp-mremap: skip unsupported shmem and hugetlb cases kaleshsingh 2026-11-24 14:13 ` Liam R. Howlett @ 2026-11-24 23:34 ` Andrew Morton 1 sibling, 0 replies; 7+ messages in thread From: Andrew Morton @ 2026-11-24 23:34 UTC (permalink / raw) To: mm-commits, vbabka, surenb, shuah, ryan.roberts, rppt, peterx, mhocko, lokeshgidra, ljs, liam, david, kaleshsingh, akpm The patch titled Subject: selftests/mm: uffd-wp-mremap: skip unsupported shmem and hugetlb cases has been added to the -mm mm-new branch. Its filename is selftests-mm-uffd-wp-mremap-skip-unsupported-shmem-and-hugetlb-cases.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/selftests-mm-uffd-wp-mremap-skip-unsupported-shmem-and-hugetlb-cases.patch This patch will later appear in the mm-new branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Note, mm-new is a provisional staging ground for work-in-progress patches, and acceptance into mm-new is a notification for others take notice and to finish up reviews. Please do not hesitate to respond to review feedback and post updated versions to replace or incrementally fixup patches in mm-new. The mm-new branch of mm.git is not included in linux-next If a few days of testing in mm-new is successful, the patch will me moved into mm.git's mm-unstable branch, which is included in linux-next Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via various branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there most days ------------------------------------------------------ From: Kalesh Singh <kaleshsingh@google.com> Subject: selftests/mm: uffd-wp-mremap: skip unsupported shmem and hugetlb cases Date: Sun, 22 Nov 2026 08:20:17 +0000 Patch series "selftests/mm: fix userfaultfd tests with CONFIG_PTE_MARKER_UFFD_WP=n". With CONFIG_PTE_MARKER_UFFD_WP=n, userfaultfd write protection only works on anonymous memory. uffd-wp-mremap then fails its shmem and hugetlb cases, and uffd-unit-tests skips anonymous runs that would pass. Patch 1 skips the unsupported uffd-wp-mremap cases and patch 2 filters uffd-unit-tests' required features per memory type. Tested on arm64 device: with CONFIG_PTE_MARKER_UFFD_WP=n, uffd-wp-mremap goes from 26 failures to none and uffd-unit-tests passes 78 tests instead of 70; with =y, the results are unchanged. This patch (of 2): uffd-wp-mremap checks only for UFFD_FEATURE_PAGEFAULT_FLAG_WP before it runs. With CONFIG_PTE_MARKER_UFFD_WP=n the kernel keeps that feature but supports write protection on anonymous memory only, so the shmem and hugetlb cases fail with EINVAL from UFFDIO_REGISTER instead of skipping. Skip them when UFFD_FEATURE_WP_HUGETLBFS_SHMEM is missing. Link: https://lore.kernel.org/20261122082020.1255434-1-kaleshsingh@google.com Link: https://patch.msgid.link/20261122082020.1255434-2-kaleshsingh@google.com Fixes: b2466bb3b495 ("selftests/mm: introduce uffd-wp-mremap regression test") Signed-off-by: Kalesh Singh <kaleshsingh@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Reviewed-by: Liam R. Howlett (Google) <liam@infradead.org> Cc: Lokesh Gidra <lokeshgidra@google.com> Cc: Mike Rapoport <rppt@kernel.org> Cc: Peter Xu <peterx@redhat.com> Cc: David Hildenbrand <david@kernel.org> Cc: Lorenzo Stoakes <ljs@kernel.org> Cc: Vlastimil Babka <vbabka@kernel.org> Cc: Suren Baghdasaryan <surenb@google.com> Cc: Michal Hocko <mhocko@suse.com> Cc: Shuah Khan <shuah@kernel.org> Cc: Ryan Roberts <ryan.roberts@arm.com> tools/testing/selftests/mm/uffd-wp-mremap.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) --- a/tools/testing/selftests/mm/uffd-wp-mremap.c~selftests-mm-uffd-wp-mremap-skip-unsupported-shmem-and-hugetlb-cases +++ a/tools/testing/selftests/mm/uffd-wp-mremap.c @@ -18,15 +18,14 @@ static int nr_thpsizes; static unsigned long thpsizes[20]; static int nr_hugetlbsizes; static unsigned long hugetlbsizes[10]; +static uint64_t uffd_features; static void check_uffd_wp_feature_supported(void) { - uint64_t features = 0; - - if (uffd_get_features(&features)) + if (uffd_get_features(&uffd_features)) ksft_exit_skip("failed to get available features (%d)\n", errno); - if (!(features & UFFD_FEATURE_PAGEFAULT_FLAG_WP)) + if (!(uffd_features & UFFD_FEATURE_PAGEFAULT_FLAG_WP)) ksft_exit_skip("uffd-wp feature not supported\n"); } @@ -180,6 +179,12 @@ static void test_one_folio(uffd_global_t swapout ? "true" : "false", hugetlb ? "true" : "false"); + if ((!private || hugetlb) && + !(uffd_features & UFFD_FEATURE_WP_HUGETLBFS_SHMEM)) { + ksft_test_result_skip("uffd-wp on shmem and hugetlbfs is not supported\n"); + return; + } + /* Allocate a folio of required size and type. */ mem = alloc_one_folio(size, private, hugetlb); if (!mem) { _ Patches currently in -mm which might be from kaleshsingh@google.com are mm-swap-make-swap_header-badpages-a-flexible-array.patch selftests-mm-uffd-wp-mremap-skip-unsupported-shmem-and-hugetlb-cases.patch selftests-mm-uffd-unit-tests-filter-required-features-per-memory-type.patch ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 2/2] selftests/mm: uffd-unit-tests: filter required features per memory type 2026-11-22 8:20 [PATCH 0/2] selftests/mm: fix userfaultfd tests with CONFIG_PTE_MARKER_UFFD_WP=n kaleshsingh 2026-11-22 8:20 ` [PATCH 1/2] selftests/mm: uffd-wp-mremap: skip unsupported shmem and hugetlb cases kaleshsingh @ 2026-11-22 8:20 ` kaleshsingh 2026-11-24 14:14 ` Liam R. Howlett 2026-11-24 23:34 ` + selftests-mm-uffd-unit-tests-filter-required-features-per-memory-type.patch added to mm-new branch Andrew Morton 1 sibling, 2 replies; 7+ messages in thread From: kaleshsingh @ 2026-11-22 8:20 UTC (permalink / raw) To: akpm Cc: kernel-team, android-mm, Kalesh Singh, Lokesh Gidra, Mike Rapoport, Peter Xu, David Hildenbrand, Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka, Suren Baghdasaryan, Michal Hocko, Shuah Khan, Ryan Roberts, linux-mm, linux-kselftest From: Kalesh Singh <kaleshsingh@google.com> CONFIG_PTE_MARKER_UFFD_WP defaults to y but can be turned off, and userfaultfd write protection then works only on anonymous memory. The kernel still reports UFFD_FEATURE_PAGEFAULT_FLAG_WP but no longer UFFD_FEATURE_WP_HUGETLBFS_SHMEM. uffd-unit-tests checks a test's whole feature mask for every memory type, so the tests that run on all memory types and require UFFD_FEATURE_WP_HUGETLBFS_SHMEM (register-ioctls, the wp-fork tests, rwp-wp-exclusive, sigbus-wp and events-wp) skip their anonymous runs too. Check and request only the features that apply to the memory type under test, and make minor-wp require UFFD_FEATURE_WP_HUGETLBFS_SHMEM, as it write-protects shmem and hugetlbfs. Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Lokesh Gidra <lokeshgidra@google.com> Signed-off-by: Kalesh Singh <kaleshsingh@google.com> --- tools/testing/selftests/mm/uffd-unit-tests.c | 42 +++++++++++++++++--- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/mm/uffd-unit-tests.c b/tools/testing/selftests/mm/uffd-unit-tests.c index 2a97ba1d6feb..d0dda2ec48fb 100644 --- a/tools/testing/selftests/mm/uffd-unit-tests.c +++ b/tools/testing/selftests/mm/uffd-unit-tests.c @@ -176,15 +176,44 @@ static void test_uffd_api(bool use_dev) } -static bool uffd_feature_supported(uffd_test_case_t *test) +/* + * Filter test->uffd_feature_required down to the features needed for @mem_type. + * For example, UFFD_FEATURE_WP_HUGETLBFS_SHMEM (gated on + * CONFIG_PTE_MARKER_UFFD_WP) only applies to shmem and hugetlbfs, so anonymous + * subtests should still run when it is absent. + */ +static uint64_t uffd_test_features(const uffd_test_case_t *test, + const mem_type_t *mem_type) +{ + const uint64_t shmem = UFFD_FEATURE_MISSING_SHMEM | + UFFD_FEATURE_MINOR_SHMEM; + const uint64_t hugetlb = UFFD_FEATURE_MISSING_HUGETLBFS | + UFFD_FEATURE_MINOR_HUGETLBFS; + uint64_t features = test->uffd_feature_required; + + switch (mem_type->mem_flag) { + case MEM_ANON: + return features & ~(shmem | hugetlb | + UFFD_FEATURE_WP_HUGETLBFS_SHMEM); + case MEM_SHMEM: + case MEM_SHMEM_PRIVATE: + return features & ~hugetlb; + case MEM_HUGETLB: + case MEM_HUGETLB_PRIVATE: + return features & ~shmem; + default: + return features; + } +} + +static bool uffd_feature_supported(uint64_t required) { uint64_t features; if (uffd_get_features(&features)) return false; - return (features & test->uffd_feature_required) == - test->uffd_feature_required; + return (features & required) == required; } static int pagemap_open(void) @@ -2417,6 +2446,7 @@ uffd_test_case_t uffd_tests[] = { .uffd_feature_required = UFFD_FEATURE_MINOR_HUGETLBFS | UFFD_FEATURE_MINOR_SHMEM | UFFD_FEATURE_PAGEFAULT_FLAG_WP | + UFFD_FEATURE_WP_HUGETLBFS_SHMEM | /* * HACK: here we leveraged WP_UNPOPULATED to detect whether * minor mode supports wr-protect. There's no feature flag @@ -2636,6 +2666,7 @@ int main(int argc, char *argv[]) mem_type_t *mem_type; uffd_test_args_t args; const char *errmsg; + uint64_t features; int i, j, opt; while ((opt = getopt(argc, argv, "f:hl")) != -1) { @@ -2711,11 +2742,12 @@ int main(int argc, char *argv[]) /* Initialize test arguments */ args.mem_type = mem_type; - if (!uffd_feature_supported(test)) { + features = uffd_test_features(test, mem_type); + if (!uffd_feature_supported(features)) { uffd_test_skip("feature missing"); continue; } - if (uffd_test_ctx_init(&gopts, test->uffd_feature_required, &errmsg)) { + if (uffd_test_ctx_init(&gopts, features, &errmsg)) { uffd_test_skip(errmsg); continue; } -- 2.56.1.750.gf70dc682cf-goog ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] selftests/mm: uffd-unit-tests: filter required features per memory type 2026-11-22 8:20 ` [PATCH 2/2] selftests/mm: uffd-unit-tests: filter required features per memory type kaleshsingh @ 2026-11-24 14:14 ` Liam R. Howlett 2026-11-24 23:34 ` + selftests-mm-uffd-unit-tests-filter-required-features-per-memory-type.patch added to mm-new branch Andrew Morton 1 sibling, 0 replies; 7+ messages in thread From: Liam R. Howlett @ 2026-11-24 14:14 UTC (permalink / raw) To: kaleshsingh Cc: akpm, kernel-team, android-mm, Lokesh Gidra, Mike Rapoport, Peter Xu, David Hildenbrand, Lorenzo Stoakes, Vlastimil Babka, Suren Baghdasaryan, Michal Hocko, Shuah Khan, Ryan Roberts, linux-mm, linux-kselftest On 26/11/22 08:20AM, kaleshsingh@google.com wrote: > From: Kalesh Singh <kaleshsingh@google.com> > > CONFIG_PTE_MARKER_UFFD_WP defaults to y but can be turned off, and > userfaultfd write protection then works only on anonymous memory. The > kernel still reports UFFD_FEATURE_PAGEFAULT_FLAG_WP but no longer > UFFD_FEATURE_WP_HUGETLBFS_SHMEM. > > uffd-unit-tests checks a test's whole feature mask for every memory > type, so the tests that run on all memory types and require > UFFD_FEATURE_WP_HUGETLBFS_SHMEM (register-ioctls, the wp-fork tests, > rwp-wp-exclusive, sigbus-wp and events-wp) skip their anonymous runs > too. Check and request only the features that apply to the memory type > under test, and make minor-wp require UFFD_FEATURE_WP_HUGETLBFS_SHMEM, > as it write-protects shmem and hugetlbfs. > > Cc: Andrew Morton <akpm@linux-foundation.org> > Cc: Lokesh Gidra <lokeshgidra@google.com> > Signed-off-by: Kalesh Singh <kaleshsingh@google.com> Reviewed-by: Liam R. Howlett (Google) <liam@infradead.org> > --- > tools/testing/selftests/mm/uffd-unit-tests.c | 42 +++++++++++++++++--- > 1 file changed, 37 insertions(+), 5 deletions(-) > > diff --git a/tools/testing/selftests/mm/uffd-unit-tests.c b/tools/testing/selftests/mm/uffd-unit-tests.c > index 2a97ba1d6feb..d0dda2ec48fb 100644 > --- a/tools/testing/selftests/mm/uffd-unit-tests.c > +++ b/tools/testing/selftests/mm/uffd-unit-tests.c > @@ -176,15 +176,44 @@ static void test_uffd_api(bool use_dev) > } > > > -static bool uffd_feature_supported(uffd_test_case_t *test) > +/* > + * Filter test->uffd_feature_required down to the features needed for @mem_type. > + * For example, UFFD_FEATURE_WP_HUGETLBFS_SHMEM (gated on > + * CONFIG_PTE_MARKER_UFFD_WP) only applies to shmem and hugetlbfs, so anonymous > + * subtests should still run when it is absent. > + */ > +static uint64_t uffd_test_features(const uffd_test_case_t *test, > + const mem_type_t *mem_type) > +{ > + const uint64_t shmem = UFFD_FEATURE_MISSING_SHMEM | > + UFFD_FEATURE_MINOR_SHMEM; > + const uint64_t hugetlb = UFFD_FEATURE_MISSING_HUGETLBFS | > + UFFD_FEATURE_MINOR_HUGETLBFS; > + uint64_t features = test->uffd_feature_required; > + > + switch (mem_type->mem_flag) { > + case MEM_ANON: > + return features & ~(shmem | hugetlb | > + UFFD_FEATURE_WP_HUGETLBFS_SHMEM); > + case MEM_SHMEM: > + case MEM_SHMEM_PRIVATE: > + return features & ~hugetlb; > + case MEM_HUGETLB: > + case MEM_HUGETLB_PRIVATE: > + return features & ~shmem; > + default: > + return features; > + } > +} > + > +static bool uffd_feature_supported(uint64_t required) > { > uint64_t features; > > if (uffd_get_features(&features)) > return false; > > - return (features & test->uffd_feature_required) == > - test->uffd_feature_required; > + return (features & required) == required; > } > > static int pagemap_open(void) > @@ -2417,6 +2446,7 @@ uffd_test_case_t uffd_tests[] = { > .uffd_feature_required = > UFFD_FEATURE_MINOR_HUGETLBFS | UFFD_FEATURE_MINOR_SHMEM | > UFFD_FEATURE_PAGEFAULT_FLAG_WP | > + UFFD_FEATURE_WP_HUGETLBFS_SHMEM | > /* > * HACK: here we leveraged WP_UNPOPULATED to detect whether > * minor mode supports wr-protect. There's no feature flag > @@ -2636,6 +2666,7 @@ int main(int argc, char *argv[]) > mem_type_t *mem_type; > uffd_test_args_t args; > const char *errmsg; > + uint64_t features; > int i, j, opt; > > while ((opt = getopt(argc, argv, "f:hl")) != -1) { > @@ -2711,11 +2742,12 @@ int main(int argc, char *argv[]) > /* Initialize test arguments */ > args.mem_type = mem_type; > > - if (!uffd_feature_supported(test)) { > + features = uffd_test_features(test, mem_type); > + if (!uffd_feature_supported(features)) { > uffd_test_skip("feature missing"); > continue; > } > - if (uffd_test_ctx_init(&gopts, test->uffd_feature_required, &errmsg)) { > + if (uffd_test_ctx_init(&gopts, features, &errmsg)) { > uffd_test_skip(errmsg); > continue; > } > -- > 2.56.1.750.gf70dc682cf-goog > ^ permalink raw reply [flat|nested] 7+ messages in thread
* + selftests-mm-uffd-unit-tests-filter-required-features-per-memory-type.patch added to mm-new branch 2026-11-22 8:20 ` [PATCH 2/2] selftests/mm: uffd-unit-tests: filter required features per memory type kaleshsingh 2026-11-24 14:14 ` Liam R. Howlett @ 2026-11-24 23:34 ` Andrew Morton 1 sibling, 0 replies; 7+ messages in thread From: Andrew Morton @ 2026-11-24 23:34 UTC (permalink / raw) To: mm-commits, vbabka, surenb, shuah, ryan.roberts, rppt, peterx, mhocko, lokeshgidra, ljs, liam, david, kaleshsingh, akpm The patch titled Subject: selftests/mm: uffd-unit-tests: filter required features per memory type has been added to the -mm mm-new branch. Its filename is selftests-mm-uffd-unit-tests-filter-required-features-per-memory-type.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/selftests-mm-uffd-unit-tests-filter-required-features-per-memory-type.patch This patch will later appear in the mm-new branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Note, mm-new is a provisional staging ground for work-in-progress patches, and acceptance into mm-new is a notification for others take notice and to finish up reviews. Please do not hesitate to respond to review feedback and post updated versions to replace or incrementally fixup patches in mm-new. The mm-new branch of mm.git is not included in linux-next If a few days of testing in mm-new is successful, the patch will me moved into mm.git's mm-unstable branch, which is included in linux-next Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via various branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there most days ------------------------------------------------------ From: Kalesh Singh <kaleshsingh@google.com> Subject: selftests/mm: uffd-unit-tests: filter required features per memory type Date: Sun, 22 Nov 2026 08:20:18 +0000 CONFIG_PTE_MARKER_UFFD_WP defaults to y but can be turned off, and userfaultfd write protection then works only on anonymous memory. The kernel still reports UFFD_FEATURE_PAGEFAULT_FLAG_WP but no longer UFFD_FEATURE_WP_HUGETLBFS_SHMEM. uffd-unit-tests checks a test's whole feature mask for every memory type, so the tests that run on all memory types and require UFFD_FEATURE_WP_HUGETLBFS_SHMEM (register-ioctls, the wp-fork tests, rwp-wp-exclusive, sigbus-wp and events-wp) skip their anonymous runs too. Check and request only the features that apply to the memory type under test, and make minor-wp require UFFD_FEATURE_WP_HUGETLBFS_SHMEM, as it write-protects shmem and hugetlbfs. Link: https://patch.msgid.link/20261122082020.1255434-3-kaleshsingh@google.com Signed-off-by: Kalesh Singh <kaleshsingh@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Reviewed-by: Liam R. Howlett (Google) <liam@infradead.org> Cc: Lokesh Gidra <lokeshgidra@google.com> Cc: Mike Rapoport <rppt@kernel.org> Cc: Peter Xu <peterx@redhat.com> Cc: David Hildenbrand <david@kernel.org> Cc: Lorenzo Stoakes <ljs@kernel.org> Cc: Vlastimil Babka <vbabka@kernel.org> Cc: Suren Baghdasaryan <surenb@google.com> Cc: Michal Hocko <mhocko@suse.com> Cc: Shuah Khan <shuah@kernel.org> Cc: Ryan Roberts <ryan.roberts@arm.com> tools/testing/selftests/mm/uffd-unit-tests.c | 42 ++++++++++++++--- 1 file changed, 37 insertions(+), 5 deletions(-) --- a/tools/testing/selftests/mm/uffd-unit-tests.c~selftests-mm-uffd-unit-tests-filter-required-features-per-memory-type +++ a/tools/testing/selftests/mm/uffd-unit-tests.c @@ -176,15 +176,44 @@ out: } -static bool uffd_feature_supported(uffd_test_case_t *test) +/* + * Filter test->uffd_feature_required down to the features needed for @mem_type. + * For example, UFFD_FEATURE_WP_HUGETLBFS_SHMEM (gated on + * CONFIG_PTE_MARKER_UFFD_WP) only applies to shmem and hugetlbfs, so anonymous + * subtests should still run when it is absent. + */ +static uint64_t uffd_test_features(const uffd_test_case_t *test, + const mem_type_t *mem_type) +{ + const uint64_t shmem = UFFD_FEATURE_MISSING_SHMEM | + UFFD_FEATURE_MINOR_SHMEM; + const uint64_t hugetlb = UFFD_FEATURE_MISSING_HUGETLBFS | + UFFD_FEATURE_MINOR_HUGETLBFS; + uint64_t features = test->uffd_feature_required; + + switch (mem_type->mem_flag) { + case MEM_ANON: + return features & ~(shmem | hugetlb | + UFFD_FEATURE_WP_HUGETLBFS_SHMEM); + case MEM_SHMEM: + case MEM_SHMEM_PRIVATE: + return features & ~hugetlb; + case MEM_HUGETLB: + case MEM_HUGETLB_PRIVATE: + return features & ~shmem; + default: + return features; + } +} + +static bool uffd_feature_supported(uint64_t required) { uint64_t features; if (uffd_get_features(&features)) return false; - return (features & test->uffd_feature_required) == - test->uffd_feature_required; + return (features & required) == required; } static int pagemap_open(void) @@ -2742,6 +2771,7 @@ uffd_test_case_t uffd_tests[] = { .uffd_feature_required = UFFD_FEATURE_MINOR_HUGETLBFS | UFFD_FEATURE_MINOR_SHMEM | UFFD_FEATURE_PAGEFAULT_FLAG_WP | + UFFD_FEATURE_WP_HUGETLBFS_SHMEM | /* * HACK: here we leveraged WP_UNPOPULATED to detect whether * minor mode supports wr-protect. There's no feature flag @@ -2961,6 +2991,7 @@ int main(int argc, char *argv[]) mem_type_t *mem_type; uffd_test_args_t args; const char *errmsg; + uint64_t features; int i, j, opt; while ((opt = getopt(argc, argv, "f:hl")) != -1) { @@ -3036,11 +3067,12 @@ int main(int argc, char *argv[]) /* Initialize test arguments */ args.mem_type = mem_type; - if (!uffd_feature_supported(test)) { + features = uffd_test_features(test, mem_type); + if (!uffd_feature_supported(features)) { uffd_test_skip("feature missing"); continue; } - if (uffd_test_ctx_init(&gopts, test->uffd_feature_required, &errmsg)) { + if (uffd_test_ctx_init(&gopts, features, &errmsg)) { uffd_test_skip(errmsg); continue; } _ Patches currently in -mm which might be from kaleshsingh@google.com are mm-swap-make-swap_header-badpages-a-flexible-array.patch selftests-mm-uffd-wp-mremap-skip-unsupported-shmem-and-hugetlb-cases.patch selftests-mm-uffd-unit-tests-filter-required-features-per-memory-type.patch ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-11-24 23:34 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-22 8:20 [PATCH 0/2] selftests/mm: fix userfaultfd tests with CONFIG_PTE_MARKER_UFFD_WP=n kaleshsingh 2026-11-22 8:20 ` [PATCH 1/2] selftests/mm: uffd-wp-mremap: skip unsupported shmem and hugetlb cases kaleshsingh 2026-11-24 14:13 ` Liam R. Howlett 2026-11-24 23:34 ` + selftests-mm-uffd-wp-mremap-skip-unsupported-shmem-and-hugetlb-cases.patch added to mm-new branch Andrew Morton 2026-11-22 8:20 ` [PATCH 2/2] selftests/mm: uffd-unit-tests: filter required features per memory type kaleshsingh 2026-11-24 14:14 ` Liam R. Howlett 2026-11-24 23:34 ` + selftests-mm-uffd-unit-tests-filter-required-features-per-memory-type.patch added to mm-new branch Andrew Morton
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.