Gracefully skip test if userfaultfd is not supported (ENOSYS) or not
permitted (EPERM), instead of failing. This avoids misleading failures
with clear skip messages.
--------------
Before Patch
--------------
~ running ./hugepage-mremap
...
~ Bail out! userfaultfd: Function not implemented
~ Planned tests != run tests (1 != 0)
~ Totals: pass:0 fail:0 xfail:0 xpass:0 skip:0 error:0
~ [FAIL]
not ok 4 hugepage-mremap # exit=1
--------------
After Patch
--------------
~ running ./hugepage-mremap
...
~ ok 2 # SKIP userfaultfd is not supported/not enabled.
~ 1 skipped test(s) detected.
~ Totals: pass:0 fail:0 xfail:0 xpass:0 skip:1 error:0
~ [SKIP]
ok 4 hugepage-mremap # SKIP
Signed-off-by: Aboorva Devarajan <aboorvad@linux.ibm.com>
---
tools/testing/selftests/mm/hugepage-mremap.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/mm/hugepage-mremap.c b/tools/testing/selftests/mm/hugepage-mremap.c
index c463d1c09c9b..1a0e6dd87578 100644
--- a/tools/testing/selftests/mm/hugepage-mremap.c
+++ b/tools/testing/selftests/mm/hugepage-mremap.c
@@ -65,10 +65,20 @@ static void register_region_with_uffd(char *addr, size_t len)
struct uffdio_api uffdio_api;
/* Create and enable userfaultfd object. */
-
uffd = syscall(__NR_userfaultfd, O_CLOEXEC | O_NONBLOCK);
- if (uffd == -1)
- ksft_exit_fail_msg("userfaultfd: %s\n", strerror(errno));
+ if (uffd == -1) {
+ switch (errno) {
+ case EPERM:
+ ksft_exit_skip("No userfaultfd permissions, try running as root.\n");
+ break;
+ case ENOSYS:
+ ksft_exit_skip("userfaultfd is not supported/not enabled.\n");
+ break;
+ default:
+ ksft_exit_fail_msg("userfaultfd failed with %s\n", strerror(errno));
+ break;
+ }
+ }
uffdio_api.api = UFFD_API;
uffdio_api.features = 0;
--
2.43.5
On 03.07.25 08:06, Aboorva Devarajan wrote: > Gracefully skip test if userfaultfd is not supported (ENOSYS) or not > permitted (EPERM), instead of failing. This avoids misleading failures > with clear skip messages. > -------------- > Before Patch > -------------- > ~ running ./hugepage-mremap > ... > ~ Bail out! userfaultfd: Function not implemented > ~ Planned tests != run tests (1 != 0) > ~ Totals: pass:0 fail:0 xfail:0 xpass:0 skip:0 error:0 > ~ [FAIL] > not ok 4 hugepage-mremap # exit=1 > > -------------- > After Patch > -------------- > ~ running ./hugepage-mremap > ... > ~ ok 2 # SKIP userfaultfd is not supported/not enabled. > ~ 1 skipped test(s) detected. > ~ Totals: pass:0 fail:0 xfail:0 xpass:0 skip:1 error:0 > ~ [SKIP] > ok 4 hugepage-mremap # SKIP > > Signed-off-by: Aboorva Devarajan <aboorvad@linux.ibm.com> > --- > tools/testing/selftests/mm/hugepage-mremap.c | 16 +++++++++++++--- > 1 file changed, 13 insertions(+), 3 deletions(-) > > diff --git a/tools/testing/selftests/mm/hugepage-mremap.c b/tools/testing/selftests/mm/hugepage-mremap.c > index c463d1c09c9b..1a0e6dd87578 100644 > --- a/tools/testing/selftests/mm/hugepage-mremap.c > +++ b/tools/testing/selftests/mm/hugepage-mremap.c > @@ -65,10 +65,20 @@ static void register_region_with_uffd(char *addr, size_t len) > struct uffdio_api uffdio_api; > > /* Create and enable userfaultfd object. */ > - > uffd = syscall(__NR_userfaultfd, O_CLOEXEC | O_NONBLOCK); > - if (uffd == -1) > - ksft_exit_fail_msg("userfaultfd: %s\n", strerror(errno)); > + if (uffd == -1) { > + switch (errno) { > + case EPERM: > + ksft_exit_skip("No userfaultfd permissions, try running as root.\n"); "Insufficient permissions, try ..." ? > + break; > + case ENOSYS: > + ksft_exit_skip("userfaultfd is not supported/not enabled.\n"); > + break; Note that we have in tools/testing/selftests/mm/config CONFIG_USERFAULTFD=y But I don't have anything about making the test more versatile. Acked-by: David Hildenbrand <david@redhat.com> -- Cheers, David / dhildenb
On 3 Jul 2025, at 4:38, David Hildenbrand wrote: > On 03.07.25 08:06, Aboorva Devarajan wrote: >> Gracefully skip test if userfaultfd is not supported (ENOSYS) or not >> permitted (EPERM), instead of failing. This avoids misleading failures >> with clear skip messages. >> -------------- >> Before Patch >> -------------- >> ~ running ./hugepage-mremap >> ... >> ~ Bail out! userfaultfd: Function not implemented >> ~ Planned tests != run tests (1 != 0) >> ~ Totals: pass:0 fail:0 xfail:0 xpass:0 skip:0 error:0 >> ~ [FAIL] >> not ok 4 hugepage-mremap # exit=1 >> >> -------------- >> After Patch >> -------------- >> ~ running ./hugepage-mremap >> ... >> ~ ok 2 # SKIP userfaultfd is not supported/not enabled. >> ~ 1 skipped test(s) detected. >> ~ Totals: pass:0 fail:0 xfail:0 xpass:0 skip:1 error:0 >> ~ [SKIP] >> ok 4 hugepage-mremap # SKIP >> >> Signed-off-by: Aboorva Devarajan <aboorvad@linux.ibm.com> >> --- >> tools/testing/selftests/mm/hugepage-mremap.c | 16 +++++++++++++--- >> 1 file changed, 13 insertions(+), 3 deletions(-) >> >> diff --git a/tools/testing/selftests/mm/hugepage-mremap.c b/tools/testing/selftests/mm/hugepage-mremap.c >> index c463d1c09c9b..1a0e6dd87578 100644 >> --- a/tools/testing/selftests/mm/hugepage-mremap.c >> +++ b/tools/testing/selftests/mm/hugepage-mremap.c >> @@ -65,10 +65,20 @@ static void register_region_with_uffd(char *addr, size_t len) >> struct uffdio_api uffdio_api; >> /* Create and enable userfaultfd object. */ >> - >> uffd = syscall(__NR_userfaultfd, O_CLOEXEC | O_NONBLOCK); >> - if (uffd == -1) >> - ksft_exit_fail_msg("userfaultfd: %s\n", strerror(errno)); >> + if (uffd == -1) { >> + switch (errno) { >> + case EPERM: >> + ksft_exit_skip("No userfaultfd permissions, try running as root.\n"); > > "Insufficient permissions, try ..." ? > >> + break; >> + case ENOSYS: >> + ksft_exit_skip("userfaultfd is not supported/not enabled.\n"); >> + break; > > Note that we have in tools/testing/selftests/mm/config > > CONFIG_USERFAULTFD=y I added the same fix to guard-regions.c since I did not know the config file existed. And from git history, I learnt that I could use the command below to merge these config to my local config: “./scripts/kconfig/merge_config.sh .config tools/testing/selftests/xxx/config” Reviewed-by: Zi Yan <ziy@nvidia.com> Best Regards, Yan, Zi
© 2016 - 2025 Red Hat, Inc.