public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Ricardo Branco <rbranco@suse.de>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH] userfaultfd: Use two-step handshake to probe features
Date: Sat, 11 Apr 2026 11:24:51 +0200	[thread overview]
Message-ID: <20260411092452.211540-1-rbranco@suse.de> (raw)

userfaultfd05 and userfaultfd06 assume that
UFFD_FEATURE_PAGEFAULT_FLAG_WP and UFFD_FEATURE_POISON are available
when setting up userfaultfd.

On kernels where either feature is unavailable at runtime,
UFFDIO_API fails with EINVAL and the tests end up as TBROK instead of
being skipped.

Fix this by using the required two-step handshake and skip with TCONF
if the required feature bit is absent.

Also remove userfaultfd05's needs_kconfigs check, since runtime
feature probing is sufficient here.

Link: https://github.com/linux-test-project/ltp/issues/1289

Signed-off-by: Ricardo Branco <rbranco@suse.de>
---
 testcases/kernel/syscalls/userfaultfd/userfaultfd05.c | 11 +++++++----
 testcases/kernel/syscalls/userfaultfd/userfaultfd06.c | 10 +++++++---
 2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/testcases/kernel/syscalls/userfaultfd/userfaultfd05.c b/testcases/kernel/syscalls/userfaultfd/userfaultfd05.c
index e25a227cf..5412f12e1 100644
--- a/testcases/kernel/syscalls/userfaultfd/userfaultfd05.c
+++ b/testcases/kernel/syscalls/userfaultfd/userfaultfd05.c
@@ -89,7 +89,14 @@ static void run(void)
 	set_pages();
 
 	uffd = SAFE_USERFAULTFD(O_CLOEXEC | O_NONBLOCK, false);
+	uffdio_api.api = UFFD_API;
+	uffdio_api.features = 0;
+	SAFE_IOCTL(uffd, UFFDIO_API, &uffdio_api);
+	if (!(uffdio_api.features & UFFD_FEATURE_PAGEFAULT_FLAG_WP))
+		tst_brk(TCONF, "UFFD_FEATURE_PAGEFAULT_FLAG_WP not supported");
+	SAFE_CLOSE(uffd);
 
+	uffd = SAFE_USERFAULTFD(O_CLOEXEC | O_NONBLOCK, false);
 	uffdio_api.api = UFFD_API;
 	uffdio_api.features = UFFD_FEATURE_PAGEFAULT_FLAG_WP;
 
@@ -124,8 +131,4 @@ static void run(void)
 static struct tst_test test = {
 	.test_all = run,
 	.min_kver = "5.7",
-	.needs_kconfigs = (const char *[]) {
-		"CONFIG_HAVE_ARCH_USERFAULTFD_WP=y",
-		NULL
-	}
 };
diff --git a/testcases/kernel/syscalls/userfaultfd/userfaultfd06.c b/testcases/kernel/syscalls/userfaultfd/userfaultfd06.c
index 5b1252c35..7ad682f5a 100644
--- a/testcases/kernel/syscalls/userfaultfd/userfaultfd06.c
+++ b/testcases/kernel/syscalls/userfaultfd/userfaultfd06.c
@@ -100,15 +100,19 @@ static void run(void)
 	set_pages();
 
 	uffd = SAFE_USERFAULTFD(O_CLOEXEC | O_NONBLOCK, false);
+	uffdio_api.api = UFFD_API;
+	uffdio_api.features = 0;
+	SAFE_IOCTL(uffd, UFFDIO_API, &uffdio_api);
+	if (!(uffdio_api.features & UFFD_FEATURE_POISON))
+		tst_brk(TCONF, "UFFD_FEATURE_POISON not supported");
+	SAFE_CLOSE(uffd);
 
+	uffd = SAFE_USERFAULTFD(O_CLOEXEC | O_NONBLOCK, false);
 	uffdio_api.api = UFFD_API;
 	uffdio_api.features = UFFD_FEATURE_POISON;
 
 	SAFE_IOCTL(uffd, UFFDIO_API, &uffdio_api);
 
-	if (!(uffdio_api.features & UFFD_FEATURE_POISON))
-		tst_brk(TCONF, "UFFD_FEATURE_POISON not supported");
-
 	uffdio_register.range.start = (unsigned long) page;
 	uffdio_register.range.len = page_size;
 	uffdio_register.mode = UFFDIO_REGISTER_MODE_MISSING;
-- 
2.53.0


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

             reply	other threads:[~2026-04-11  9:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-11  9:24 Ricardo Branco [this message]
2026-04-11  9:46 ` [LTP] userfaultfd: Use two-step handshake to probe features acervesato
2026-04-11 10:39 ` acervesato

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260411092452.211540-1-rbranco@suse.de \
    --to=rbranco@suse.de \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox