[LTP] [PATCH v6 2/2] userfaultfd: Add new test using UFFDIO_CONTINUE
Ricardo Branco
rbranco@suse.de
Tue May 5 16:28:54 CEST 2026
On 5/5/26 4:12 PM, Cyril Hrubis wrote:
>> +static void run(void)
>> +{
>> + pthread_t thr;
>> + struct uffdio_api uffdio_api = {};
>> + struct uffdio_register uffdio_register;
>> +
>> + set_pages();
>> +
>> + uffd = SAFE_USERFAULTFD(O_CLOEXEC | O_NONBLOCK, true);
>> + uffdio_api.api = UFFD_API;
>> + uffdio_api.features = 0;
>> + SAFE_IOCTL(uffd, UFFDIO_API, &uffdio_api);
>> + if (!(uffdio_api.features & UFFD_FEATURE_MINOR_SHMEM))
>> + tst_brk(TCONF, "UFFD_FEATURE_MINOR_SHMEM not supported");
>> + SAFE_CLOSE(uffd);
>> +
>> + uffd = SAFE_USERFAULTFD(O_CLOEXEC | O_NONBLOCK, false);
>> +
>> + uffdio_api.api = UFFD_API;
>> + uffdio_api.features = UFFD_FEATURE_MINOR_SHMEM;
>> +
>> + SAFE_IOCTL(uffd, UFFDIO_API, &uffdio_api);
>> +
>> + uffdio_register.range.start = (unsigned long) page;
>> + uffdio_register.range.len = page_size;
>> + uffdio_register.mode = UFFDIO_REGISTER_MODE_MINOR;
>> +
>> + SAFE_IOCTL(uffd, UFFDIO_REGISTER, &uffdio_register);
>> +
>> + /*
>> + * Drop PTEs while retaining the cached shmem page so the next access
>> + * faults in MINOR mode.
>> + */
>> + if (madvise(page, page_size, MADV_DONTNEED) < 0)
>> + tst_brk(TBROK | TERRNO, "madvise MADV_DONTNEED failed");
>> +
>> + SAFE_PTHREAD_CREATE(&thr, NULL, (void *) handle_thread, NULL);
>> +
>> + char c = page[0];
>> +
>> + if (c == 'Z')
>> + tst_res(TPASS, "Pagefault handled via UFFDIO_CONTINUE");
>> + else
>> + tst_res(TFAIL, "pagefault not handled via UFFDIO_CONTINUE, got '%c'", c);
>> +
>> + SAFE_PTHREAD_JOIN(thr, NULL);
>> + reset_pages();
>> +}
>> +
>> +static struct tst_test test = {
>> + .test_all = run,
>> + /*
>> + * UFFDIO_CONTINUE is available since 5.13 but
>> + * UFFD_FEATURE_MINOR_SHMEM appeared in 5.14
>> + */
>> + .min_kver = "5.14",
> Should we do a runtime check in the test setup here as well?
We're checking for UFFD_FEATURE_MINOR_SHMEM it the 2 step handshake.
Cheers,
R
More information about the ltp
mailing list