When running mremap_test on a kernel built without CONFIG_USERFAULTFD,
test 26 fails:

    userfaultfd: Function not implemented
    not ok 26 mremap move multiple invalid vmas

This happens because mremap_move_multi_invalid_vmas() only checks for
EPERM, so ENOSYS is treated as an unexpected failure instead of being
skipped.

In addition, ksft_test_result_skip() in both
mremap_move_multi_invalid_vmas() and its fallback stub is missing a
trailing newline, which causes the subsequent TAP summary count to get
stuck on the same line:

    ok 26 # SKIP ... - missing uffd# 1 skipped test(s) detected...

Fix this following the switch pattern in guard-regions.c (lines 1498-1506):
check for EPERM (advising running as root) and ENOSYS (missing uffd), move
perror() to default so expected skips don't print noise to stderr, and add
the missing '\n' to both skip strings.

Tested:
- On a minimal kernel without CONFIG_USERFAULTFD in QEMU:
    ok 26 # SKIP mremap move multiple invalid vmas - missing uffd
    # Totals: pass:22 fail:0 xfail:3 xpass:0 skip:1 error:0

- As an unprivileged user on host (vm.unprivileged_userfaultfd=0):
    ok 26 # SKIP mremap move multiple invalid vmas -
          no uffd permissions, try running as root
    # 1 skipped test(s) detected.

- On a kernel with CONFIG_USERFAULTFD=y in QEMU:
    ok 26 mremap move multiple invalid vmas
    # Totals: pass:23 fail:0 xfail:3 xpass:0 skip:0 error:0

Signed-off-by: Park Tae-sun <[email protected]>
---
 tools/testing/selftests/mm/mremap_test.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/tools/testing/selftests/mm/mremap_test.c 
b/tools/testing/selftests/mm/mremap_test.c
index 131d9d6db867..1fa2f6aa1a19 100644
--- a/tools/testing/selftests/mm/mremap_test.c
+++ b/tools/testing/selftests/mm/mremap_test.c
@@ -743,14 +743,19 @@ static void mremap_move_multi_invalid_vmas(FILE *maps_fp,
 
        uffd = syscall(__NR_userfaultfd, O_NONBLOCK);
        if (uffd == -1) {
-               err = errno;
-               perror("userfaultfd");
-               if (err == EPERM) {
-                       ksft_test_result_skip("%s - missing uffd", test_name);
+               switch (errno) {
+               case EPERM:
+                       ksft_test_result_skip("%s - no uffd permissions, try 
running as root\n",
+                                             test_name);
                        return;
+               case ENOSYS:
+                       ksft_test_result_skip("%s - missing uffd\n", test_name);
+                       return;
+               default:
+                       perror("userfaultfd");
+                       success = false;
+                       goto out;
                }
-               success = false;
-               goto out;
        }
        if (ioctl(uffd, UFFDIO_API, &api)) {
                perror("ioctl UFFDIO_API");
@@ -965,7 +970,7 @@ static void mremap_move_multi_invalid_vmas(FILE *maps_fp, 
unsigned long page_siz
 {
        char *test_name = "mremap move multiple invalid vmas";
 
-       ksft_test_result_skip("%s - missing uffd", test_name);
+       ksft_test_result_skip("%s - missing uffd\n", test_name);
 }
 #endif /* __NR_userfaultfd */
 
-- 
2.43.0


Reply via email to