lapi/userfaultfd: Handle ENOSYS in SAFE_USERFAULTFD
PATCH 1/1 lapi/userfaultfd: Handle ENOSYS in SAFE_USERFAULTFD
When CONFIG_USERFAULTFD is not enabled in the kernel, the userfaultfd syscall returns ENOSYS. Currently, SAFE_USERFAULTFD calls tst_brk(TBROK) for any error other than EPERM, causing tests to fail when they should be skipped.
Add a check for ENOSYS to return TCONF, so that tests using SAFE_USERFAULTFD are skipped appropriately on kernels without userfaultfd support.
--- include/lapi/userfaultfd.h | 4 ++++ 1 file changed, 4 insertions(+)
include/lapi/userfaultfd.h +4 -0
@@ -244,6 +244,10 @@ static inline int safe_userfaultfd(const char *file, const int lineno, int retry: ret =tst_syscall (__NR_userfaultfd, flags);if (ret ==-1 ) { +if (errno ==ENOSYS ) { +tst_brk_ (file, lineno,TCONF |TERRNO , +"userfaultfd() is not supported by this kernel" ); + }if (errno ==EPERM ) {if (retry && !(flags &UFFD_USER_MODE_ONLY )) { flags |=UFFD_USER_MODE_ONLY ;
Signature · 5 lines
2.54.0.545.g6539524ca2-goog -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Wake,
Quoted 19 lines
When
CONFIG_USERFAULTFDis not enabled in the kernel, the userfaultfd syscall returns ENOSYS. Currently,SAFE_USERFAULTFDcallstst_brk(TBROK)for any error other than EPERM, causing tests to fail when they should be skipped.Add a check for ENOSYS to return TCONF, so that tests using
SAFE_USERFAULTFDare skipped appropriately on kernels without userfaultfd support.Signed-off-by Wake Liu <[email protected]>--- include/lapi/userfaultfd.h | 4 ++++ 1 file changed, 4 insertions(+)include/lapi/userfaultfd.h +0
-0
include/lapi/userfaultfd.h static inline int safe_userfaultfd(const char *file, const int lineno, int · line 247
Quoted 4 lines
include/lapi/userfaultfd.h +1
-0@@ -244,6 +244,10 @@ static inline int safe_userfaultfd(const char *file, const int lineno, int retry: ret =tst_syscall (__NR_userfaultfd, flags);if (ret ==-1 ) { +if (errno ==ENOSYS ) {
This is already handled in the tst_syscall() implementation. The solution would be to use:
static struct tst_test test = {
..
.needs_kconfigs = (const char *[]) {
"CONFIG_USERFAULTFD=y",
NULL
}
};for all the tests which need this configuration.
Where did you see this issue? Do you have a use case scenario where this happened?
Kind regards,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
I encountered this issue during Android GKI (Generic Kernel Image) and VTS (Vendor Test Suite) testing on various device targets (e.g., Pixel 6, virtual devices). In our testing environment, we run the same test suite against a wide variety of kernel versions and configurations.
Specifically, on some kernels where CONFIG_USERFAULTFD is disabled, the userfaultfd() syscall returns ENOSYS. While you mentioned tst_syscall() handles it, in the version/configuration we are using, tst_syscall() returns -1 and sets errno to ENOSYS. This is then passed to safe_userfaultfd(), which currently only checks for EPERM to skip (TCONF) and falls back to TBROK for any other error, including ENOSYS.
Andrea Cervesato <[email protected]> 於 2026年4月29日週三 下午2:52寫道:
Quoted 48 lines
Hi Wake,
Quoted 19 lines
When
CONFIG_USERFAULTFDis not enabled in the kernel, the userfaultfd syscall returns ENOSYS. Currently,SAFE_USERFAULTFDcallstst_brk(TBROK)for any error other than EPERM, causing tests to fail when they should be skipped.Add a check for ENOSYS to return TCONF, so that tests using
SAFE_USERFAULTFDare skipped appropriately on kernels without userfaultfd support.Signed-off-by Wake Liu <[email protected]>--- include/lapi/userfaultfd.h | 4 ++++ 1 file changed, 4 insertions(+)include/lapi/userfaultfd.h +0
-0include/lapi/userfaultfd.h static inline int safe_userfaultfd(const char *file, const int lineno, int · line 247
Quoted 4 lines
include/lapi/userfaultfd.h +1
-0@@ -244,6 +244,10 @@ static inline int safe_userfaultfd(const char *file, const int lineno, int retry: ret =tst_syscall (__NR_userfaultfd, flags);if (ret ==-1 ) { +if (errno ==ENOSYS ) {This is already handled in the
tst_syscall()implementation. The solution would be to use:static struct
tst_testtest = {
...needs_kconfigs = (const char *[]) { "CONFIG_USERFAULTFD=y", NULL } };for all the tests which need this configuration.
Where did you see this issue? Do you have a use case scenario where this happened?
Kind regards,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Signature · 5 lines
Best Regards, Wake Liu -- Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 11 lines
I encountered this issue during Android GKI (Generic Kernel Image) and VTS (Vendor Test Suite) testing on various device targets (e.g., Pixel 6, virtual devices). In our testing environment, we run the same test suite against a wide variety of kernel versions and configurations.
Specifically, on some kernels where
CONFIG_USERFAULTFDis disabled, theuserfaultfd()syscall returns ENOSYS. While you mentionedtst_syscall()handles it, in the version/configuration we are using,tst_syscall()returns -1 and sets errno to ENOSYS. This is then passed tosafe_userfaultfd(), which currently only checks for EPERM to skip (TCONF) and falls back to TBROK for any other error, including ENOSYS.
I'm a bit puzzled because according to the tst_syscall() implementation this should not happen. If syscall returns -1 with errno == ENOSYS, the tst_syscall() implementation will always TCONF. This is visible in include/lapi/syscalls.h generated by the build system before compiling.
Please provide the exact test that is failing, as well as the logs you have seen having this issue.
Regards,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Thank you for your reply and for pointing out the behavior of tst_syscall().
I must apologize for the confusion. You are absolutely correct
that tst_syscall() automatically handles ENOSYS and
returns TCONF. I assumed it was ENOSYS without looking closely at
the exact error code in the logs.
After checking the logs again, I found that in our Android GKI
testing environment (kernel 6.12.74-android16), the
userfaultfd() syscall actually returns EOPNOTSUPP (95) instead of
ENOSYS when CONFIG_USERFAULTFD is disabled.
Here is the relevant log snippet for userfaultfd04:
external/ltp/testcases/kernel/syscalls/userfaultfd/userfaultfd04.c:73:
TBROK: syscall(__NR_userfaultfd, 526336)
failed: EOPNOTSUPP (95)
Because the error was EOPNOTSUPP, the TCONF logic in tst_syscall()
(which only checks for ENOSYS) was bypassed, and
the error fell through to safe_userfaultfd(). Sincesafe_userfaultfd() only handles EPERM for TCONF and defaults to
TBROK for everything else, it resulted in the TBROK failure.
Given this behavior, I think we should update the patch to handle
EOPNOTSUPP in safe_userfaultfd() as well (and maybe
keep ENOSYS just in case other kernels do return it).
What do you think about this? I would be happy to send a v2 patch
addressing this.
Andrea Cervesato <[email protected]> 於 2026年4月29日週三 下午5:22寫道:
Quoted 27 lines
Quoted 6 lines
I encountered this issue during Android GKI (Generic Kernel Image) and VTS (Vendor Test Suite) testing on various device targets (e.g., Pixel 6, virtual devices). In our testing environment, we run the same test suite against a wide variety of kernel versions and configurations.
Quoted 6 lines
Specifically, on some kernels where
CONFIG_USERFAULTFDis disabled, theuserfaultfd()syscall returns ENOSYS. While you mentionedtst_syscall()handles it, in the version/configuration we are using,tst_syscall()returns -1 and sets errno to ENOSYS. This is then passed tosafe_userfaultfd(), which currently only checks for EPERM to skip (TCONF) and falls back to TBROK for any other error, including ENOSYS.I'm a bit puzzled because according to the
tst_syscall()implementation this should not happen. If syscall returns -1 with errno == ENOSYS, thetst_syscall()implementation will always TCONF. This is visible ininclude/lapi/syscalls.hgenerated by the build system before compiling.Please provide the exact test that is failing, as well as the logs you have seen having this issue.
Regards,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Signature · 5 lines
Best Regards, Wake Liu -- Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 3 lines
What do you think about this? I would be happy to send a v2 patch
addressing this.
no everything makes more sense :-) the right way to handle this issue is to use needs_kconfig as I explained in the first email.
Feel free to follow that pattern after trying it out. It should work.
Kind regards,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 1/1 syscalls/userfaultfd04: Require CONFIG_USERFAULTFD=y
The test fails with TBROK on systems where CONFIG_USERFAULTFD is not enabled because SAFE_USERFAULTFD calls tst_syscall(__NR_userfaultfd) which fails (e.g., returning ENOSYS or EOPNOTSUPP), and SAFE_USERFAULTFD calls tst_brk(TBROK) for errors other than EPERM.
Fix this by adding CONFIG_USERFAULTFD=y to .needs_kconfigs, so that the test is skipped with TCONF on kernels without userfaultfd support.
--- testcases/kernel/syscalls/userfaultfd/userfaultfd04.c | 4 ++++ 1 file changed, 4 insertions(+)
testcases/kernel/syscalls/userfaultfd/userfaultfd04.c +4 -0
@@ -98,4 +98,8 @@ static void run(void)static struct tst_test test = { .test_all = run, + .needs_kconfigs = (const char *[]) { +"CONFIG_USERFAULTFD=y" , +NULL + } };
Signature · 5 lines
2.54.0.545.g6539524ca2-goog -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] syscalls/userfaultfd04: Require CONFIG_USERFAULTFD=y
Hi Wake,
testcases/kernel/syscalls/userfaultfd/userfaultfd04.c static void run(void) · line 104
Quoted 6 lines · Wake Liu
syscalls/userfaultfd04: Require
CONFIG_USERFAULTFD=ytestcases/kernel/syscalls/userfaultfd/userfaultfd04.c +4
-0+ .needs_kconfigs = (const char *[]) { +"CONFIG_USERFAULTFD=y" , +NULL + }
---
Note:
Our agent completed the review of the patch. The full review can be found at: https://github.com/linux-test-project/ltp-agent/actions/runs/25108331937
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
Re: [LTP] [PATCH] syscalls/userfaultfd04: Require CONFIG_USERFAULTFD=y
In reply to Wake Liu via ltp--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Andrea Cervesato via ltp
AppliedRe: [LTP] [PATCH] syscalls/userfaultfd04: Require CONFIG_USERFAULTFD=y
In reply to Wake Liu via ltpMerged, Thanks!
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Wake,
include/lapi/userfaultfd.h static inline int safe_userfaultfd(const char *file, const int lineno, int · line 250
Quoted 6 lines · Wake Liu
lapi/userfaultfd: Handle ENOSYS in
SAFE_USERFAULTFDinclude/lapi/userfaultfd.h +4
-0+if (errno ==ENOSYS ) { +tst_brk_ (file, lineno,TCONF |TERRNO , +"userfaultfd() is not supported by this kernel" ); + }
The fix is correct, but since this is a bug fix, please add a Fixes:
tag pointing to the commit that introduced SAFE_USERFAULTFD without ENOSYS handling.
---
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
Hi Wake,
Quoted 3 lines
The fix is correct, but since this is a bug fix, please add a Fixes:
tag pointing to the commit that introducedSAFE_USERFAULTFDwithout ENOSYS handling.
Please ignore this review, this is a corner case that needs to be updated in our reviewer agent.
Regards,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 8 lines
include/lapi/userfaultfd.h | 4 ++++ 1 file changed, 4 insertions(+)include/lapi/userfaultfd.h +0
-0
include/lapi/userfaultfd.h static inline int safe_userfaultfd(const char *file, const int lineno, int · line 250
Quoted 7 lines
include/lapi/userfaultfd.h +4
-0@@ -244,6 +244,10 @@ static inline int safe_userfaultfd(const char *file, const int lineno, int retry: ret =tst_syscall (__NR_userfaultfd, flags);if (ret ==-1 ) { +if (errno ==ENOSYS ) { +tst_brk_ (file, lineno,TCONF |TERRNO , +"userfaultfd() is not supported by this kernel" ); + }
The tst_syscall() code has already branch that checks for ENOSYS and calls tst_brk(TCONF, ...) which looks like:
#define TST_SYSCALL_BRK__(NR, SNR) ({ \
tst_brk(TCONF, \
"syscall(%d) " SNR " not supported on your arch", NR); \
})#define tst_syscall(NR, ...) ({ \intptr_t tst_ret; \
if (NR == __LTP__NR_INVALID_SYSCALL) { \
errno = ENOSYS; \
tst_ret = -1; \
} else { \
tst_ret = syscall(NR, ##__VA_ARGS__); \
} \
if (tst_ret == -1 && errno == ENOSYS) { \
TST_SYSCALL_BRK__(NR, #NR); \
} \tst_ret; \
})
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp