Skip to contentSkip to conversation

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

PATCH In review Park Tae-sun 3 participants 4 messages Sep 22

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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

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

---
 tools/testing/selftests/mm/mremap_test.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)
tools/testing/selftests/mm/mremap_test.c +12 -7
index 131d9d6db867..1fa2f6aa1a19 100644
@@ -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 */
 
Signature · 1 line
2.43.0
#1 lore raw

Hi Park Tae-sun!

Quoted 15 lines · Park Tae-sun

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:

Quoted 6 lines

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/[email protected]/

author Tested-by
#2 lore raw

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:

Thanks,
Park Tae-sun

#3 lore raw
Quoted 11 lines · Park Tae-sun

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:

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:

[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]

Quoted 3 lines

Thanks,
Park Tae-sun

--
Cheers, Lorenzo