[LTP] [PATCH v2] userfaultfd: Use two-step handshake to probe features
Ricardo Branco
rbranco@suse.de
Tue May 5 13:27:23 CEST 2026
On 5/4/26 7:48 PM, Cyril Hrubis wrote:
> 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)
>
Will add this macro. Let's keep doing the 2 step handshake though.
More information about the ltp
mailing list