[LTP] [PATCH] userfaultfd05: handle kernels rejecting WP feature in UFFDIO_API
Petr Vorel
pvorel@suse.cz
Fri Jan 23 10:45:38 CET 2026
Hi Li, Ricardo,
> Commit 485a4cd2ba3 ("userfaultfd05: allow TCONF when UFFD-WP is unsupported")
> added a TCONF path for missing UFFD-WP, but it relied on checking
> uffdio_api.features after a failed ioctl (on RHEL-10).
> That is not sufficient: it did not handle the case where UFFDIO_API
> succeeds but the kernel does not advertise UFFD_FEATURE_PAGEFAULT_FLAG_WP
> in the returned features mask.
> So userfaultfd05 still fails on RHEL-9 s390x platform:
> userfaultfd05.c:106: TBROK: ioctl(3,((((2U|1U) << (((0+8)+8)+14)) |
> (((0xAA)) << (0+8)) | ((((0x00))) << 0) |
> ((((sizeof(struct uffdio_register)))) << ((0+8)+8)))),...)
> failed: EINVAL (22)
> Now, let's handle both behaviours by retrying UFFDIO_API with features=0
> on EINVAL and treating a successful retry as "WP unsupported" (TCONF).
> Also check the returned features mask after a successful UFFDIO_API and
> skip when WP is not advertised.
...
> if (ioctl(uffd, UFFDIO_API, &uffdio_api) < 0) {
> - if (!(uffdio_api.features & UFFD_FEATURE_PAGEFAULT_FLAG_WP))
> - tst_brk(TCONF, "UFFD write-protect unsupported");
> + int err = errno;
> + if (err == EINVAL) {
> + uffdio_api.api = UFFD_API;
> + uffdio_api.features = 0;
> +
> + if (ioctl(uffd, UFFDIO_API, &uffdio_api) == 0)
> + tst_brk(TCONF, "UFFD write-protect unsupported");
> + }
Wouldn't be better in this case to check kconfig for
CONFIG_HAVE_ARCH_USERFAULTFD_WP (untested, but it should work
Back to our discussion about how often using kconfig [1]. While I prefer to
avoid using it for tristate (kernel might be configured but module missing), but
here is just a feature.
[1] https://lore.kernel.org/ltp/CAASaF6wOSvi+07Pq5O6+f1Hkrq6WWMgpCaooJxWrO9uOvRM3pw@mail.gmail.com/
But I'm ok with it if you prefer exact check.
Reviewed-by: Petr Vorel <pvorel@suse.cz>
> - tst_brk(TBROK | TERRNO, "ioctl() on userfaultfd failed");
> + errno = err;
> + tst_brk(TBROK | TERRNO, "ioctl(UFFDIO_API) failed");
+1
> }
Kind regards,
Petr
> + if (!(uffdio_api.features & UFFD_FEATURE_PAGEFAULT_FLAG_WP))
> + tst_brk(TCONF, "UFFD write-protect unsupported");
> +
> uffdio_register.range.start = (unsigned long) page;
> uffdio_register.range.len = page_size;
> uffdio_register.mode = UFFDIO_REGISTER_MODE_WP;
More information about the ltp
mailing list