[PATCH v2 09/13] selftests/mm: skip uffd-wp-mremap if UFFD write-protect is unsupported

Sayali Patil posted 13 patches 3 weeks, 5 days ago
Only 12 patches received!
There is a newer version of this series
[PATCH v2 09/13] selftests/mm: skip uffd-wp-mremap if UFFD write-protect is unsupported
Posted by Sayali Patil 3 weeks, 5 days ago
The uffd-wp-mremap test requires the UFFD_FEATURE_PAGEFAULT_FLAG_WP
capability. On systems where userfaultfd write-protect is
not supported, uffd_register() fails and the test reports failures.

Check for the required feature at startup and skip the test when the
UFFD_FEATURE_PAGEFAULT_FLAG_WP capability is not present,
preventing false failures on unsupported configurations.

Before patch:
 running ./uffd-wp-mremap
 ------------------------
  [INFO] detected THP size: 256 KiB
  [INFO] detected THP size: 512 KiB
  [INFO] detected THP size: 1024 KiB
  [INFO] detected THP size: 2048 KiB
  [INFO] detected hugetlb page size: 2048 KiB
  [INFO] detected hugetlb page size: 1048576 KiB
 1..24
  [RUN] test_one_folio(size=65536, private=false, swapout=false,
  hugetlb=false)
 not ok 1 uffd_register() failed
  [RUN] test_one_folio(size=65536, private=true, swapout=false,
  hugetlb=false)
 not ok 2 uffd_register() failed
  [RUN] test_one_folio(size=65536, private=false, swapout=true,
  hugetlb=false)
 not ok 3 uffd_register() failed
  [RUN] test_one_folio(size=65536, private=true, swapout=true,
  hugetlb=false)
 not ok 4 uffd_register() failed
  [RUN] test_one_folio(size=262144, private=false, swapout=false,
  hugetlb=false)
 not ok 5 uffd_register() failed
  [RUN] test_one_folio(size=524288, private=false, swapout=false,
  hugetlb=false)
 not ok 6 uffd_register() failed
 .
 .
 .
 Bail out! 24 out of 24 tests failed
  Totals: pass:0 fail:24 xfail:0 xpass:0 skip:0 error:0
 [FAIL]
not ok 1 uffd-wp-mremap # exit=1

After patch:
 running ./uffd-wp-mremap
 ------------------------
 1..0 # SKIP uffd-wp feature not supported
 [SKIP]
ok 1 uffd-wp-mremap # SKIP

Acked-by: Zi Yan <ziy@nvidia.com>
Signed-off-by: Sayali Patil <sayalip@linux.ibm.com>
---
 tools/testing/selftests/mm/uffd-wp-mremap.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/tools/testing/selftests/mm/uffd-wp-mremap.c b/tools/testing/selftests/mm/uffd-wp-mremap.c
index 17186d4a4147..73d53a4da389 100644
--- a/tools/testing/selftests/mm/uffd-wp-mremap.c
+++ b/tools/testing/selftests/mm/uffd-wp-mremap.c
@@ -19,6 +19,17 @@ static size_t thpsizes[20];
 static int nr_hugetlbsizes;
 static size_t hugetlbsizes[10];
 
+static void uffd_wp_feature_supported(void)
+{
+	uint64_t features;
+
+	if (uffd_get_features(&features) && errno == ENOENT)
+		ksft_exit_skip("failed to get available features (%d)\n", errno);
+
+	if (!(features & UFFD_FEATURE_PAGEFAULT_FLAG_WP))
+		ksft_exit_skip("uffd-wp feature not supported\n");
+}
+
 static int detect_thp_sizes(size_t sizes[], int max)
 {
 	int count = 0;
@@ -336,6 +347,8 @@ int main(int argc, char **argv)
 	struct thp_settings settings;
 	int i, j, plan = 0;
 
+	uffd_wp_feature_supported();
+
 	pagesize = getpagesize();
 	nr_thpsizes = detect_thp_sizes(thpsizes, ARRAY_SIZE(thpsizes));
 	nr_hugetlbsizes = detect_hugetlb_page_sizes(hugetlbsizes,
-- 
2.52.0
Re: [PATCH v2 09/13] selftests/mm: skip uffd-wp-mremap if UFFD write-protect is unsupported
Posted by David Hildenbrand (Arm) 3 weeks, 5 days ago
On 3/12/26 13:25, Sayali Patil wrote:
> The uffd-wp-mremap test requires the UFFD_FEATURE_PAGEFAULT_FLAG_WP
> capability. On systems where userfaultfd write-protect is
> not supported, uffd_register() fails and the test reports failures.
> 
> Check for the required feature at startup and skip the test when the
> UFFD_FEATURE_PAGEFAULT_FLAG_WP capability is not present,
> preventing false failures on unsupported configurations.
> 
> Before patch:
>  running ./uffd-wp-mremap
>  ------------------------
>   [INFO] detected THP size: 256 KiB
>   [INFO] detected THP size: 512 KiB
>   [INFO] detected THP size: 1024 KiB
>   [INFO] detected THP size: 2048 KiB
>   [INFO] detected hugetlb page size: 2048 KiB
>   [INFO] detected hugetlb page size: 1048576 KiB
>  1..24
>   [RUN] test_one_folio(size=65536, private=false, swapout=false,
>   hugetlb=false)
>  not ok 1 uffd_register() failed
>   [RUN] test_one_folio(size=65536, private=true, swapout=false,
>   hugetlb=false)
>  not ok 2 uffd_register() failed
>   [RUN] test_one_folio(size=65536, private=false, swapout=true,
>   hugetlb=false)
>  not ok 3 uffd_register() failed
>   [RUN] test_one_folio(size=65536, private=true, swapout=true,
>   hugetlb=false)
>  not ok 4 uffd_register() failed
>   [RUN] test_one_folio(size=262144, private=false, swapout=false,
>   hugetlb=false)
>  not ok 5 uffd_register() failed
>   [RUN] test_one_folio(size=524288, private=false, swapout=false,
>   hugetlb=false)
>  not ok 6 uffd_register() failed
>  .
>  .
>  .
>  Bail out! 24 out of 24 tests failed
>   Totals: pass:0 fail:24 xfail:0 xpass:0 skip:0 error:0
>  [FAIL]
> not ok 1 uffd-wp-mremap # exit=1
> 
> After patch:
>  running ./uffd-wp-mremap
>  ------------------------
>  1..0 # SKIP uffd-wp feature not supported
>  [SKIP]
> ok 1 uffd-wp-mremap # SKIP
> 
> Acked-by: Zi Yan <ziy@nvidia.com>
> Signed-off-by: Sayali Patil <sayalip@linux.ibm.com>
> ---
>  tools/testing/selftests/mm/uffd-wp-mremap.c | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
> 
> diff --git a/tools/testing/selftests/mm/uffd-wp-mremap.c b/tools/testing/selftests/mm/uffd-wp-mremap.c
> index 17186d4a4147..73d53a4da389 100644
> --- a/tools/testing/selftests/mm/uffd-wp-mremap.c
> +++ b/tools/testing/selftests/mm/uffd-wp-mremap.c
> @@ -19,6 +19,17 @@ static size_t thpsizes[20];
>  static int nr_hugetlbsizes;
>  static size_t hugetlbsizes[10];
>  
> +static void uffd_wp_feature_supported(void)

Likely that function should be called

"check_uffd_wp_feature_supported()"

Because right now it reads as if it would be returning a bool.

Acked-by: David Hildenbrand (Arm) <david@kernel.org>

-- 
Cheers,

David
Re: [PATCH v2 09/13] selftests/mm: skip uffd-wp-mremap if UFFD write-protect is unsupported
Posted by Sayali Patil 3 weeks, 4 days ago
On 12/03/26 18:20, David Hildenbrand (Arm) wrote:
> On 3/12/26 13:25, Sayali Patil wrote:
>> The uffd-wp-mremap test requires the UFFD_FEATURE_PAGEFAULT_FLAG_WP
>> capability. On systems where userfaultfd write-protect is
>> not supported, uffd_register() fails and the test reports failures.
>>
>> Check for the required feature at startup and skip the test when the
>> UFFD_FEATURE_PAGEFAULT_FLAG_WP capability is not present,
>> preventing false failures on unsupported configurations.
>>
>> Before patch:
>>   running ./uffd-wp-mremap
>>   ------------------------
>>    [INFO] detected THP size: 256 KiB
>>    [INFO] detected THP size: 512 KiB
>>    [INFO] detected THP size: 1024 KiB
>>    [INFO] detected THP size: 2048 KiB
>>    [INFO] detected hugetlb page size: 2048 KiB
>>    [INFO] detected hugetlb page size: 1048576 KiB
>>   1..24
>>    [RUN] test_one_folio(size=65536, private=false, swapout=false,
>>    hugetlb=false)
>>   not ok 1 uffd_register() failed
>>    [RUN] test_one_folio(size=65536, private=true, swapout=false,
>>    hugetlb=false)
>>   not ok 2 uffd_register() failed
>>    [RUN] test_one_folio(size=65536, private=false, swapout=true,
>>    hugetlb=false)
>>   not ok 3 uffd_register() failed
>>    [RUN] test_one_folio(size=65536, private=true, swapout=true,
>>    hugetlb=false)
>>   not ok 4 uffd_register() failed
>>    [RUN] test_one_folio(size=262144, private=false, swapout=false,
>>    hugetlb=false)
>>   not ok 5 uffd_register() failed
>>    [RUN] test_one_folio(size=524288, private=false, swapout=false,
>>    hugetlb=false)
>>   not ok 6 uffd_register() failed
>>   .
>>   .
>>   .
>>   Bail out! 24 out of 24 tests failed
>>    Totals: pass:0 fail:24 xfail:0 xpass:0 skip:0 error:0
>>   [FAIL]
>> not ok 1 uffd-wp-mremap # exit=1
>>
>> After patch:
>>   running ./uffd-wp-mremap
>>   ------------------------
>>   1..0 # SKIP uffd-wp feature not supported
>>   [SKIP]
>> ok 1 uffd-wp-mremap # SKIP
>>
>> Acked-by: Zi Yan <ziy@nvidia.com>
>> Signed-off-by: Sayali Patil <sayalip@linux.ibm.com>
>> ---
>>   tools/testing/selftests/mm/uffd-wp-mremap.c | 13 +++++++++++++
>>   1 file changed, 13 insertions(+)
>>
>> diff --git a/tools/testing/selftests/mm/uffd-wp-mremap.c b/tools/testing/selftests/mm/uffd-wp-mremap.c
>> index 17186d4a4147..73d53a4da389 100644
>> --- a/tools/testing/selftests/mm/uffd-wp-mremap.c
>> +++ b/tools/testing/selftests/mm/uffd-wp-mremap.c
>> @@ -19,6 +19,17 @@ static size_t thpsizes[20];
>>   static int nr_hugetlbsizes;
>>   static size_t hugetlbsizes[10];
>>   
>> +static void uffd_wp_feature_supported(void)
> Likely that function should be called
>
> "check_uffd_wp_feature_supported()"
>
> Because right now it reads as if it would be returning a bool.
>
> Acked-by: David Hildenbrand (Arm) <david@kernel.org>
>
Thanks for the review. I'll rename it to
"check_uffd_wp_feature_supported()" in the next version.
Re: [PATCH v2 09/13] selftests/mm: skip uffd-wp-mremap if UFFD write-protect is unsupported
Posted by Andrew Morton 1 week, 6 days ago
On Fri, 13 Mar 2026 19:56:01 +0530 Sayali Patil <sayalip@linux.ibm.com> wrote:

> >
> > Because right now it reads as if it would be returning a bool.
> >
> > Acked-by: David Hildenbrand (Arm) <david@kernel.org>
> >
> Thanks for the review. I'll rename it to
> "check_uffd_wp_feature_supported()" in the next version.

There was no next version.  I added this:

--- a/tools/testing/selftests/mm/uffd-wp-mremap.c~selftests-mm-skip-uffd-wp-mremap-if-uffd-write-protect-is-unsupported-fix
+++ a/tools/testing/selftests/mm/uffd-wp-mremap.c
@@ -19,7 +19,7 @@ static size_t thpsizes[20];
 static int nr_hugetlbsizes;
 static size_t hugetlbsizes[10];
 
-static void uffd_wp_feature_supported(void)
+static void check_uffd_wp_feature_supported(void)
 {
 	uint64_t features;
 
@@ -347,7 +347,7 @@ int main(int argc, char **argv)
 	struct thp_settings settings;
 	int i, j, plan = 0;
 
-	uffd_wp_feature_supported();
+	check_uffd_wp_feature_supported();
 
 	pagesize = getpagesize();
 	nr_thpsizes = detect_thp_sizes(thpsizes, ARRAY_SIZE(thpsizes));
_
Re: [PATCH v2 09/13] selftests/mm: skip uffd-wp-mremap if UFFD write-protect is unsupported
Posted by Sayali Patil 1 week, 4 days ago
On 25/03/26 05:26, Andrew Morton wrote:
> On Fri, 13 Mar 2026 19:56:01 +0530 Sayali Patil <sayalip@linux.ibm.com> wrote:
>
>>> Because right now it reads as if it would be returning a bool.
>>>
>>> Acked-by: David Hildenbrand (Arm) <david@kernel.org>
>>>
>> Thanks for the review. I'll rename it to
>> "check_uffd_wp_feature_supported()" in the next version.
> There was no next version.  I added this:
>
> --- a/tools/testing/selftests/mm/uffd-wp-mremap.c~selftests-mm-skip-uffd-wp-mremap-if-uffd-write-protect-is-unsupported-fix
> +++ a/tools/testing/selftests/mm/uffd-wp-mremap.c
> @@ -19,7 +19,7 @@ static size_t thpsizes[20];
>   static int nr_hugetlbsizes;
>   static size_t hugetlbsizes[10];
>   
> -static void uffd_wp_feature_supported(void)
> +static void check_uffd_wp_feature_supported(void)
>   {
>   	uint64_t features;
>   
> @@ -347,7 +347,7 @@ int main(int argc, char **argv)
>   	struct thp_settings settings;
>   	int i, j, plan = 0;
>   
> -	uffd_wp_feature_supported();
> +	check_uffd_wp_feature_supported();
>   
>   	pagesize = getpagesize();
>   	nr_thpsizes = detect_thp_sizes(thpsizes, ARRAY_SIZE(thpsizes));
> _
>
Hi Andrew,
I have some updates to [PATCH v2 04/13] selftests/mm: fix cgroup task 
placement and tolerance in hugetlb_reparenting_test.sh, as Venkat 
reported failures with the current version.

Should I send a v3 of the full series, or just a fixup patch for 
hugetlb_reparenting_test.sh? Also, if you prefer a v3, should I include 
above fix for 
selftests-mm-skip-uffd-wp-mremap-if-uffd-write-protect-is-unsupported as 
well?

Thanks,
Sayali
Re: [PATCH v2 09/13] selftests/mm: skip uffd-wp-mremap if UFFD write-protect is unsupported
Posted by Andrew Morton 1 week, 4 days ago
On Thu, 26 Mar 2026 23:31:10 +0530 Sayali Patil <sayalip@linux.ibm.com> wrote:

> >   	pagesize = getpagesize();
> >   	nr_thpsizes = detect_thp_sizes(thpsizes, ARRAY_SIZE(thpsizes));
> > _
> >
> Hi Andrew,
> I have some updates to [PATCH v2 04/13] selftests/mm: fix cgroup task 
> placement and tolerance in hugetlb_reparenting_test.sh, as Venkat 
> reported failures with the current version.
> 
> Should I send a v3 of the full series, or just a fixup patch for 
> hugetlb_reparenting_test.sh?

A full resend is fine, thanks.  I'll prepare a diff showing all the
changes since v2 for you to double-check and for people who already
reviewed v2.

> Also, if you prefer a v3, should I include 
> above fix for 
> selftests-mm-skip-uffd-wp-mremap-if-uffd-write-protect-is-unsupported as 
> well?

Yes please, integrate all fixups.  

You may choose to track those fixups the way I do:

[avagin@google.com: fix lock leak in mfill_get_vma()]
  Link: https://lkml.kernel.org/r/20260316173829.1126728-1-avagin@google.com
[akpm@linux-foundation.org: update mfill_copy_folio_retry()]
  Link: https://lkml.kernel.org/r/20260316173829.1126728-1-avagin@google.com
Link: https://lkml.kernel.org/r/20260306171815.3160826-6-rppt@kernel.org
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Signed-off-by: Andrei Vagin <avagin@google.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Axel Rasmussen <axelrasmussen@google.com>
...

Other people also do this sometimes, usually not.