[PATCH] selftests/mm: mremap_test: handle ENOSYS for userfaultfd and add missing newlines

Park Tae-sun posted 1 patch 2 days, 9 hours ago
tools/testing/selftests/mm/mremap_test.c | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
[PATCH] selftests/mm: mremap_test: handle ENOSYS for userfaultfd and add missing newlines
Posted by Park Tae-sun 2 days, 9 hours ago
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 <ts930@dgu.ac.kr>
---
 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
Re: [PATCH] selftests/mm: mremap_test: handle ENOSYS for userfaultfd and add missing newlines
Posted by Sarthak Sharma 2 days, 8 hours ago
Hi Park Tae-sun!

On 9/22/26 12:21 PM, Park Tae-sun wrote:
> 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.

Thanks for the fix, but I have posted a series of patches already [1]
which include skipping incase of ENOSYS and fixing the newline issue in
ksft_test_result_skip(). If it is okay with you, can we go ahead with my
patches since it solves some other issues as well?

[1]
https://lore.kernel.org/all/20260917111951.188266-1-sarthak.sharma@arm.com/
Re: [PATCH] selftests/mm: mremap_test: handle ENOSYS for userfaultfd and add missing newlines
Posted by Park Tae-sun 2 days, 8 hours ago
Hi Sarthak,

Thanks for letting me know!

That sounds completely fine with me. I independently ran into the same
issue while testing mremap_test in QEMU on a minimal kernel without
CONFIG_USERFAULTFD, so I'm glad to see it addressed as part of your
larger series.

Feel free to add my:
Tested-by: Park Tae-sun <ts930@dgu.ac.kr>

Thanks,
Park Tae-sun
Re: [PATCH] selftests/mm: mremap_test: handle ENOSYS for userfaultfd and add missing newlines
Posted by Lorenzo Stoakes (ARM) 2 days, 8 hours ago
On Tue, Sep 22, 2026 at 04:19:40PM +0900, Park Tae-sun wrote:
> Hi Sarthak,
>
> Thanks for letting me know!
>
> That sounds completely fine with me. I independently ran into the same
> issue while testing mremap_test in QEMU on a minimal kernel without
> CONFIG_USERFAULTFD, so I'm glad to see it addressed as part of your
> larger series.
>
> Feel free to add my:
> Tested-by: Park Tae-sun <ts930@dgu.ac.kr>

Additionally, for future reference - you were missing cc's.

Fixing this is easy with b4 [0] (the recommended way of sending patches to
mm):

$ b4 prep --auto-to-cc

Alternatively, you can use scripts/get_maintainer.pl:

$ scripts/get_maintainer.pl --nogit-fallback <files-or-patches>

[0]: https://b4.docs.kernel.org/en/latest/contributor/send.html

Specifically, the following appear to be missing:

  david@kernel.org
  liam@infradead.org
  mhocko@suse.com
  rppt@kernel.org
  surenb@google.com
  vbabka@kernel.org

>
> Thanks,
> Park Tae-sun

--
Cheers, Lorenzo