[LTP] [PATCH] lapi/userfaultfd: Handle ENOSYS in SAFE_USERFAULTFD

Wake Liu wakel@google.com
Wed Apr 29 10:51:44 CEST 2026


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 <andrea.cervesato@suse.com> 於 2026年4月29日週三 下午2:52寫道:
>
> Hi Wake,
>
> > 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.
> >
> > Signed-off-by: Wake Liu <wakel@google.com>
> > ---
> >  include/lapi/userfaultfd.h | 4 ++++
> >  1 file changed, 4 insertions(+)
> >
> > diff --git a/include/lapi/userfaultfd.h b/include/lapi/userfaultfd.h
> > index 0c9e34c84..09126d856 100644
> > --- a/include/lapi/userfaultfd.h
> > +++ b/include/lapi/userfaultfd.h
> > @@ -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
> andrea.cervesato@suse.com



-- 
Best Regards,
Wake Liu


More information about the ltp mailing list