[LTP] [PATCH] userfaultfd: Add test using UFFDIO_CONTINUE

Ricardo Branco rbranco@suse.de
Mon Mar 30 11:24:07 CEST 2026



On 3/30/26 10:31 AM, Andrea Cervesato wrote:
>> +static int page_size;
>> +static char *page;
>> +static int uffd;
>> +static int memfd = -1;
> uffd must be initialized to -1. Zero is a valid fd (stdin).

Will also fix the other tests in the "Minor fixes" patch.

> Also, reset_pages() is the .cleanup callback but never closes uffd. If
> run() aborts after SAFE_USERFAULTFD() but before spawning the thread
> (e.g. TCONF at the feature check), uffd leaks. Add:
>
> 	if (uffd != -1)
> 		SAFE_CLOSE(uffd);

Ditto.

>> +	SAFE_IOCTL(uffd, UFFDIO_CONTINUE, &uffdio_continue);
>> +
>> +	close(uffd);
>> +	return NULL;
> Use SAFE_CLOSE(uffd) instead of close(uffd).

Ditto here.

>> +	uffdio_continue.range.start =
>> +		msg.arg.pagefault.address & ~(page_size - 1);
> page_size is int, so ~(page_size - 1) produces a signed int mask that
> gets sign-extended when applied to the __u64 address. Cast to avoid
> relying on implementation-defined behavior:
>
> 	msg.arg.pagefault.address & ~((unsigned long)page_size - 1);

Shall we declare page_size as long because sysconf() returns long?

Also needs fixing the other tests.  I used userfaultfd01.c as template.

Best,
Ricardo.


More information about the ltp mailing list