[LTP] [PATCH v2] userfaultfd: Use two-step handshake to probe features
Cyril Hrubis
chrubis@suse.cz
Mon May 4 19:48:19 CEST 2026
Hi!
> >> + uffd = SAFE_USERFAULTFD(O_CLOEXEC | O_NONBLOCK, false);
> >> + uffdio_api.api = UFFD_API;
> >> + 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);
> > I do not get why are we adding this code when we do the same just a few
> > lines below. Shouldn't just this suffice?
>
> That's why the comment is needed because it isn't obvious.
>
> We need to do the 2 step handshake, first with uffdio_api.features set
> to zero, then again with the desired features.
The obviously the comment is not useful because it does not explain
anything :-).
Looking at the kernel code, it seems to set the output flags
uncoditionally so we can use that.
Or check for EINVAL when we pass unsupported flags.
However I would put this code into a common header and call it only in
the test setup (so that it's not executed on each test iteration).
#define CHECK_UFFD_FLAG(flag) do { \
... \
if (!(uffdio_api.features & (flag))) \
tst_brk(TCONF, #flag " not supported"); \
... \
} while (0)
--
Cyril Hrubis
chrubis@suse.cz
More information about the ltp
mailing list