public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH] userfaultfd05: handle kernels rejecting WP feature in UFFDIO_API
@ 2026-01-23  5:40 Li Wang via ltp
  2026-01-23  9:45 ` Petr Vorel
  2026-01-27 12:48 ` Cyril Hrubis
  0 siblings, 2 replies; 8+ messages in thread
From: Li Wang via ltp @ 2026-01-23  5:40 UTC (permalink / raw)
  To: ltp; +Cc: Ricardo Branco

Commit 485a4cd2ba3 ("userfaultfd05: allow TCONF when UFFD-WP is unsupported")
added a TCONF path for missing UFFD-WP, but it relied on checking
uffdio_api.features after a failed ioctl (on RHEL-10).

That is not sufficient: it did not handle the case where UFFDIO_API
succeeds but the kernel does not advertise UFFD_FEATURE_PAGEFAULT_FLAG_WP
in the returned features mask.

So userfaultfd05 still fails on RHEL-9 s390x platform:

    userfaultfd05.c:106: TBROK: ioctl(3,((((2U|1U) << (((0+8)+8)+14)) |
		    (((0xAA)) << (0+8)) | ((((0x00))) << 0) |
		    ((((sizeof(struct uffdio_register)))) << ((0+8)+8)))),...)
		    failed: EINVAL (22)

Now, let's handle both behaviours by retrying UFFDIO_API with features=0
on EINVAL and treating a successful retry as "WP unsupported" (TCONF).
Also check the returned features mask after a successful UFFDIO_API and
skip when WP is not advertised.

And preserve the original errno so real UFFDIO_API failures are still
reported as 'TBROK | TERRNO'.

Follow-up: 485a4cd2ba3 ("userfaultfd05: allow TCONF when UFFD-WP is unsupported")
Signed-off-by: Li Wang <liwang@redhat.com>
Cc: Ricardo Branco <rbranco@suse.com>
---
 .../kernel/syscalls/userfaultfd/userfaultfd05.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/testcases/kernel/syscalls/userfaultfd/userfaultfd05.c b/testcases/kernel/syscalls/userfaultfd/userfaultfd05.c
index 6cae45f20..4158b7b46 100644
--- a/testcases/kernel/syscalls/userfaultfd/userfaultfd05.c
+++ b/testcases/kernel/syscalls/userfaultfd/userfaultfd05.c
@@ -92,13 +92,24 @@ static void run(void)
 
 	uffdio_api.api = UFFD_API;
 	uffdio_api.features = UFFD_FEATURE_PAGEFAULT_FLAG_WP;
+
 	if (ioctl(uffd, UFFDIO_API, &uffdio_api) < 0) {
-		if (!(uffdio_api.features & UFFD_FEATURE_PAGEFAULT_FLAG_WP))
-			tst_brk(TCONF, "UFFD write-protect unsupported");
+		int err = errno;
+		if (err == EINVAL) {
+			uffdio_api.api = UFFD_API;
+			uffdio_api.features = 0;
+
+			if (ioctl(uffd, UFFDIO_API, &uffdio_api) == 0)
+				tst_brk(TCONF, "UFFD write-protect unsupported");
+		}
 
-		tst_brk(TBROK | TERRNO, "ioctl() on userfaultfd failed");
+		errno = err;
+		tst_brk(TBROK | TERRNO, "ioctl(UFFDIO_API) failed");
 	}
 
+	if (!(uffdio_api.features & UFFD_FEATURE_PAGEFAULT_FLAG_WP))
+		tst_brk(TCONF, "UFFD write-protect unsupported");
+
 	uffdio_register.range.start = (unsigned long) page;
 	uffdio_register.range.len = page_size;
 	uffdio_register.mode = UFFDIO_REGISTER_MODE_WP;
-- 
2.52.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-01-27 12:47 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-23  5:40 [LTP] [PATCH] userfaultfd05: handle kernels rejecting WP feature in UFFDIO_API Li Wang via ltp
2026-01-23  9:45 ` Petr Vorel
2026-01-23 11:34   ` Li Wang via ltp
2026-01-23 11:53     ` Petr Vorel
2026-01-23 12:02       ` Li Wang via ltp
2026-01-23 12:25         ` Petr Vorel
2026-01-26  6:02           ` Li Wang via ltp
2026-01-27 12:48 ` Cyril Hrubis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox