Re: [PATCH v3] selftests/mm: Fix UFFDIO_API usage with proper two-step feature negotiation

From: David Hildenbrand
Date: Tue Jul 08 2025 - 11:30:04 EST


Key changes:

1. Use features=0 in the initial UFFDIO_API call to query supported
feature bits, rather than immediately requesting WP support.

2. Skip the test gracefully if:
- UFFDIO_API fails with EINVAL (e.g. unsupported API version), or
- UFFD_FEATURE_PAGEFAULT_FLAG_WP is not advertised by the kernel.

3. Close the initial userfaultfd and create a new one before enabling
the required feature, since UFFDIO_API can only be called once per fd.

4. Improve diagnostics by distinguishing between expected and unexpected
failures, using strerror() to report errors.

This ensures the test behaves correctly across a wider range of kernel
versions and configurations, while preserving the intended behavior on
kernels that support UFFD-WP.

Suggestted-by: David Hildenbrand <david@xxxxxxxxxx>

Skimming over this once again ... sorry.

Nit:

"Suggested-by:"

Likely Andrew can fix it up ... if the patch is not upstream yet (did not check).

--
Cheers,

David / dhildenb