[LTP] [PATCH v2] userfaultfd: Use two-step handshake to probe features

Ricardo Branco rbranco@suse.de
Mon May 4 17:59:44 CEST 2026



On 5/4/26 5:50 PM, Cyril Hrubis wrote:
>> +	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.

>> index 5b1252c35..e1b3c2f6f 100644
>> --- a/testcases/kernel/syscalls/userfaultfd/userfaultfd06.c
>> +++ b/testcases/kernel/syscalls/userfaultfd/userfaultfd06.c
>> @@ -97,18 +97,25 @@ static void run(void)
>>   
>>   	poison_fault_seen = 0;
>>   	sigbus_seen = 0;
>> -	set_pages();
>>   
>> +	/*
>> +	 * Two-step handshake to check if feature is available
>> +	 */
>>   	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_POISON))
>> +		tst_brk(TCONF, "UFFD_FEATURE_POISON not supported");
>> +	SAFE_CLOSE(uffd);
>>   
>> +	set_pages();
>> +
>> +	uffd = SAFE_USERFAULTFD(O_CLOEXEC | O_NONBLOCK, false);
>>   	uffdio_api.api = UFFD_API;
>>   	uffdio_api.features = UFFD_FEATURE_POISON;
>>
>>   	SAFE_IOCTL(uffd, UFFDIO_API, &uffdio_api);
>>   
>> -	if (!(uffdio_api.features & UFFD_FEATURE_POISON))
>> -		tst_brk(TCONF, "UFFD_FEATURE_POISON not supported");
>> -
> This does not seem to make any sense. The code already checks for the
> feature, or do I miss something?

Context: https://github.com/linux-test-project/ltp/issues/1289


More information about the ltp mailing list