Linux Test Project
 help / color / mirror / Atom feed
* [LTP] [PATCH v3 1/2] userfaultfd: Add helper for checking UFFD feature support
@ 2026-05-07  8:31 Ricardo Branco
  2026-05-07  8:31 ` [LTP] [PATCH v3 2/2] userfaultfd: Use two-step handshake to probe features Ricardo Branco
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Ricardo Branco @ 2026-05-07  8:31 UTC (permalink / raw)
  To: ltp

Add CHECK_UFFD_FEATURE() to perform the initial UFFDIO_API handshake
without requesting optional features and verify that the kernel reports
the requested feature bit.

Signed-off-by: Ricardo Branco <rbranco@suse.de>
---
 include/lapi/userfaultfd.h | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/include/lapi/userfaultfd.h b/include/lapi/userfaultfd.h
index aab3890b7..170dfadd4 100644
--- a/include/lapi/userfaultfd.h
+++ b/include/lapi/userfaultfd.h
@@ -277,4 +277,24 @@ retry:
 	return ret;
 }
 
+#define CHECK_UFFD_FEATURE(feature)	check_uffd_feature(feature, #feature)
+
+static inline void check_uffd_feature(uint64_t feature, const char *name)
+{
+	struct uffdio_api uffdio_api = {};
+	int uffd;
+
+	uffd = SAFE_USERFAULTFD(O_CLOEXEC | O_NONBLOCK, false);
+
+	uffdio_api.api = UFFD_API;
+	SAFE_IOCTL(uffd, UFFDIO_API, &uffdio_api);
+
+	if (!(uffdio_api.features & feature)) {
+		SAFE_CLOSE(uffd);
+		tst_brk(TCONF, "%s not supported", name);
+	}
+
+	SAFE_CLOSE(uffd);
+}
+
 #endif /* LAPI_USERFAULTFD_H__ */
-- 
2.54.0


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

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

* [LTP] [PATCH v3 2/2] userfaultfd: Use two-step handshake to probe features
  2026-05-07  8:31 [LTP] [PATCH v3 1/2] userfaultfd: Add helper for checking UFFD feature support Ricardo Branco
@ 2026-05-07  8:31 ` Ricardo Branco
  2026-05-07  8:34   ` Cyril Hrubis
  2026-05-07  8:33 ` [LTP] [PATCH v3 1/2] userfaultfd: Add helper for checking UFFD feature support Cyril Hrubis
  2026-05-07  9:40 ` [LTP] " linuxtestproject.agent
  2 siblings, 1 reply; 9+ messages in thread
From: Ricardo Branco @ 2026-05-07  8:31 UTC (permalink / raw)
  To: ltp

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.

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

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

diff --git a/testcases/kernel/syscalls/userfaultfd/userfaultfd05.c b/testcases/kernel/syscalls/userfaultfd/userfaultfd05.c
index 59956d85d..55ddc1a69 100644
--- a/testcases/kernel/syscalls/userfaultfd/userfaultfd05.c
+++ b/testcases/kernel/syscalls/userfaultfd/userfaultfd05.c
@@ -87,10 +87,12 @@ static void *handle_thread(void *arg LTP_ATTRIBUTE_UNUSED)
 static void run(void)
 {
 	pthread_t thr;
-	struct uffdio_api uffdio_api;
+	struct uffdio_api uffdio_api = {};
 	struct uffdio_register uffdio_register;
 	struct uffdio_writeprotect uffdio_writeprotect;
 
+	CHECK_UFFD_FEATURE(UFFD_FEATURE_PAGEFAULT_FLAG_WP);
+
 	set_pages();
 
 	uffd = SAFE_USERFAULTFD(O_CLOEXEC | O_NONBLOCK, false);
diff --git a/testcases/kernel/syscalls/userfaultfd/userfaultfd06.c b/testcases/kernel/syscalls/userfaultfd/userfaultfd06.c
index ec93d8ad6..c06de4ca2 100644
--- a/testcases/kernel/syscalls/userfaultfd/userfaultfd06.c
+++ b/testcases/kernel/syscalls/userfaultfd/userfaultfd06.c
@@ -99,6 +99,9 @@ static void run(void)
 
 	poison_fault_seen = 0;
 	sigbus_seen = 0;
+
+	CHECK_UFFD_FEATURE(UFFD_FEATURE_POISON);
+
 	set_pages();
 
 	uffd = SAFE_USERFAULTFD(O_CLOEXEC | O_NONBLOCK, false);
@@ -108,9 +111,6 @@ static void run(void)
 
 	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.54.0


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

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

* Re: [LTP] [PATCH v3 1/2] userfaultfd: Add helper for checking UFFD feature support
  2026-05-07  8:31 [LTP] [PATCH v3 1/2] userfaultfd: Add helper for checking UFFD feature support Ricardo Branco
  2026-05-07  8:31 ` [LTP] [PATCH v3 2/2] userfaultfd: Use two-step handshake to probe features Ricardo Branco
@ 2026-05-07  8:33 ` Cyril Hrubis
  2026-05-07  9:40 ` [LTP] " linuxtestproject.agent
  2 siblings, 0 replies; 9+ messages in thread
From: Cyril Hrubis @ 2026-05-07  8:33 UTC (permalink / raw)
  To: Ricardo Branco; +Cc: ltp

Hi!
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>

-- 
Cyril Hrubis
chrubis@suse.cz

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

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

* Re: [LTP] [PATCH v3 2/2] userfaultfd: Use two-step handshake to probe features
  2026-05-07  8:31 ` [LTP] [PATCH v3 2/2] userfaultfd: Use two-step handshake to probe features Ricardo Branco
@ 2026-05-07  8:34   ` Cyril Hrubis
  0 siblings, 0 replies; 9+ messages in thread
From: Cyril Hrubis @ 2026-05-07  8:34 UTC (permalink / raw)
  To: Ricardo Branco; +Cc: ltp

Hi!
>  static void run(void)
>  {
>  	pthread_t thr;
> -	struct uffdio_api uffdio_api;
> +	struct uffdio_api uffdio_api = {};
>  	struct uffdio_register uffdio_register;
>  	struct uffdio_writeprotect uffdio_writeprotect;
>  
> +	CHECK_UFFD_FEATURE(UFFD_FEATURE_PAGEFAULT_FLAG_WP);

Can we please move this into the test setup() so that it's executed only
once if the test is started with -i parameter?


-- 
Cyril Hrubis
chrubis@suse.cz

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

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

* Re: [LTP] userfaultfd: Add helper for checking UFFD feature support
  2026-05-07  8:31 [LTP] [PATCH v3 1/2] userfaultfd: Add helper for checking UFFD feature support Ricardo Branco
  2026-05-07  8:31 ` [LTP] [PATCH v3 2/2] userfaultfd: Use two-step handshake to probe features Ricardo Branco
  2026-05-07  8:33 ` [LTP] [PATCH v3 1/2] userfaultfd: Add helper for checking UFFD feature support Cyril Hrubis
@ 2026-05-07  9:40 ` linuxtestproject.agent
  2 siblings, 0 replies; 9+ messages in thread
From: linuxtestproject.agent @ 2026-05-07  9:40 UTC (permalink / raw)
  To: Ricardo Branco; +Cc: ltp

Hi Ricardo,

--- [PATCH 1/2] ---

On Thu, 7 May 2026, Ricardo Branco wrote:
> userfaultfd: Add helper for checking UFFD feature support
>
> Add CHECK_UFFD_FEATURE() to perform the initial UFFDIO_API handshake
> without requesting optional features and verify that the kernel reports
> the requested feature bit.

The body only explains the mechanism, not the motivation. Add a sentence
explaining why this helper is needed — e.g. "Without this two-step probe,
requesting an unsupported feature in UFFDIO_API fails with EINVAL,
causing tests to TBROK instead of TCONF."

--- [PATCH 2/2] ---

On Thu, 7 May 2026, Ricardo Branco wrote:
> Fixes: 1840ee23d172b5ab04cca7c2acfa48755b041911

Please verify this SHA resolves in the full LTP history; it is not
reachable in this clone.

Pre-existing issues noticed in the surrounding code (not introduced
by this patch):

- testcases/kernel/syscalls/userfaultfd/userfaultfd05.c — `wp_fault_seen`
  is never reset to 0 at the top of run(); on multi-iteration runs (-i N)
  the second iteration may falsely pass.

---
Note:

Our agent completed the review of the patch.

The agent can sometimes produce false positives although often its
findings are genuine. If you find issues with the review, please
comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

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

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

* Re: [LTP] userfaultfd: Add helper for checking UFFD feature support
  2026-05-07 12:28 [LTP] [PATCH v4 1/3] " Ricardo Branco
@ 2026-05-07 14:22 ` linuxtestproject.agent
  2026-05-07 14:40   ` Andrea Cervesato via ltp
  0 siblings, 1 reply; 9+ messages in thread
From: linuxtestproject.agent @ 2026-05-07 14:22 UTC (permalink / raw)
  To: Ricardo Branco; +Cc: ltp

Hi Ricardo,

--- [PATCH 1/3] ---

On Thu, 7 May 2026 14:28:53 +0200, Ricardo Branco wrote:
> [PATCH 1/3] userfaultfd: Add helper for checking UFFD feature support

> +	uffd = SAFE_USERFAULTFD(O_CLOEXEC | O_NONBLOCK, false);
> +
> +	uffdio_api.api = UFFD_API;
> +	SAFE_IOCTL(uffd, UFFDIO_API, &uffdio_api);

If SAFE_IOCTL calls tst_brk(TBROK) here, the local `uffd` is not
closed before the test runner takes over; the cleanup functions only
track the global `uffd`. Close it before the SAFE_IOCTL call, or
restructure to guarantee SAFE_CLOSE on all exit paths.

--- [PATCH 2/3] ---

On Thu, 7 May 2026 14:28:54 +0200, Ricardo Branco wrote:
> [PATCH 2/3] userfaultfd: Use two-step handshake to probe features

> Fixes: 1840ee23d172b5ab04cca7c2acfa48755b041911

This commit is not reachable in the local git history (grafted shallow
clone). Please verify the Fixes: tag resolves correctly against the
upstream LTP tree.

Pre-existing issues noticed in the surrounding code (not introduced
by this patch):

- testcases/kernel/syscalls/userfaultfd/userfaultfd06.c:142 — no
  .min_kver set; UFFD_FEATURE_POISON requires Linux 6.6.

---
Note:

Our agent completed the review of the patch.

The agent can sometimes produce false positives although often its
findings are genuine. If you find issues with the review, please
comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

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

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

* Re: [LTP] userfaultfd: Add helper for checking UFFD feature support
  2026-05-07 14:22 ` [LTP] " linuxtestproject.agent
@ 2026-05-07 14:40   ` Andrea Cervesato via ltp
  2026-05-07 14:43     ` Cyril Hrubis
  0 siblings, 1 reply; 9+ messages in thread
From: Andrea Cervesato via ltp @ 2026-05-07 14:40 UTC (permalink / raw)
  To: linuxtestproject.agent; +Cc: ltp

Hi!

> > +	uffd = SAFE_USERFAULTFD(O_CLOEXEC | O_NONBLOCK, false);
> > +
> > +	uffdio_api.api = UFFD_API;
> > +	SAFE_IOCTL(uffd, UFFDIO_API, &uffdio_api);
> 
> If SAFE_IOCTL calls tst_brk(TBROK) here, the local `uffd` is not
> closed before the test runner takes over; the cleanup functions only
> track the global `uffd`. Close it before the SAFE_IOCTL call, or
> restructure to guarantee SAFE_CLOSE on all exit paths.

This is not necessarily wrong, but since TBROK is called, fd is closed
with the process. We need to instruct the agent because I seen this
logical concept being missed a few times.

> 
> --- [PATCH 2/3] ---
> 
> On Thu, 7 May 2026 14:28:54 +0200, Ricardo Branco wrote:
> > [PATCH 2/3] userfaultfd: Use two-step handshake to probe features
> 
> > Fixes: 1840ee23d172b5ab04cca7c2acfa48755b041911
> 
> This commit is not reachable in the local git history (grafted shallow
> clone). Please verify the Fixes: tag resolves correctly against the
> upstream LTP tree.

Can you please double check this? Maybe we have an another issue
with the agent.

Regards,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
andrea.cervesato@suse.com

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

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

* Re: [LTP] userfaultfd: Add helper for checking UFFD feature support
  2026-05-07 14:40   ` Andrea Cervesato via ltp
@ 2026-05-07 14:43     ` Cyril Hrubis
  2026-05-07 16:57       ` Andrea Cervesato via ltp
  0 siblings, 1 reply; 9+ messages in thread
From: Cyril Hrubis @ 2026-05-07 14:43 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: ltp, linuxtestproject.agent

Hi!
> > --- [PATCH 2/3] ---
> > 
> > On Thu, 7 May 2026 14:28:54 +0200, Ricardo Branco wrote:
> > > [PATCH 2/3] userfaultfd: Use two-step handshake to probe features
> > 
> > > Fixes: 1840ee23d172b5ab04cca7c2acfa48755b041911
> > 
> > This commit is not reachable in the local git history (grafted shallow
> > clone). Please verify the Fixes: tag resolves correctly against the
> > upstream LTP tree.
> 
> Can you please double check this? Maybe we have an another issue
> with the agent.

The commit is there:

commit 1840ee23d172b5ab04cca7c2acfa48755b041911
Author: Li Wang <li.wang@linux.dev>
Date:   Fri Jan 23 19:54:19 2026 +0800

    userfaultfd05: require CONFIG_HAVE_ARCH_USERFAULTFD_WP


-- 
Cyril Hrubis
chrubis@suse.cz

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

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

* Re: [LTP] userfaultfd: Add helper for checking UFFD feature support
  2026-05-07 14:43     ` Cyril Hrubis
@ 2026-05-07 16:57       ` Andrea Cervesato via ltp
  0 siblings, 0 replies; 9+ messages in thread
From: Andrea Cervesato via ltp @ 2026-05-07 16:57 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: ltp, linuxtestproject.agent

> The commit is there:
> 
> commit 1840ee23d172b5ab04cca7c2acfa48755b041911
> Author: Li Wang <li.wang@linux.dev>
> Date:   Fri Jan 23 19:54:19 2026 +0800
> 
>     userfaultfd05: require CONFIG_HAVE_ARCH_USERFAULTFD_WP

sigh. Im wondering why it didn't catch it, this is the basics.

I think we need to separate the logical review from everything
that can be done with a linter. I will explore this possibility
in the next weeks when I will have more time.

Regards,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
andrea.cervesato@suse.com

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

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

end of thread, other threads:[~2026-05-07 16:57 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-07  8:31 [LTP] [PATCH v3 1/2] userfaultfd: Add helper for checking UFFD feature support Ricardo Branco
2026-05-07  8:31 ` [LTP] [PATCH v3 2/2] userfaultfd: Use two-step handshake to probe features Ricardo Branco
2026-05-07  8:34   ` Cyril Hrubis
2026-05-07  8:33 ` [LTP] [PATCH v3 1/2] userfaultfd: Add helper for checking UFFD feature support Cyril Hrubis
2026-05-07  9:40 ` [LTP] " linuxtestproject.agent
  -- strict thread matches above, loose matches on Subject: below --
2026-05-07 12:28 [LTP] [PATCH v4 1/3] " Ricardo Branco
2026-05-07 14:22 ` [LTP] " linuxtestproject.agent
2026-05-07 14:40   ` Andrea Cervesato via ltp
2026-05-07 14:43     ` Cyril Hrubis
2026-05-07 16:57       ` Andrea Cervesato via ltp

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