userfaultfd: Add helper for checking UFFD feature support
PATCH v3 1/2 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.
--- include/lapi/userfaultfd.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
include/lapi/userfaultfd.h +20 -0
@@ -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__ */
Signature · 5 lines
2.54.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v3 2/2 userfaultfd: Use two-step handshake to probe features
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.
--- testcases/kernel/syscalls/userfaultfd/userfaultfd05.c | 4 +++- testcases/kernel/syscalls/userfaultfd/userfaultfd06.c | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-)
testcases/kernel/syscalls/userfaultfd/userfaultfd05.c +3 -1
@@ -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);
testcases/kernel/syscalls/userfaultfd/userfaultfd06.c +3 -3
@@ -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 ;
Signature · 5 lines
2.54.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v3 2/2] userfaultfd: Use two-step handshake to probe features
Hi!
testcases/kernel/syscalls/userfaultfd/userfaultfd05.c static void *handle_thread(void *arg LTP_ATTRIBUTE_UNUSED) · line 94
Quoted 9 lines
static void run(void)
{testcases/kernel/syscalls/userfaultfd/userfaultfd05.c +2
-1pthread_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?
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Ricardo,
--- [PATCH 1/2] ---
Quoted 5 lines · Ricardo Branco
userfaultfd: Add helper for checking UFFD feature support
Add
CHECK_UFFD_FEATURE()to perform the initialUFFDIO_APIhandshake 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] ---
Quoted 1 line · Ricardo Branco
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
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp