Skip to content

Conversation

@roypat
Copy link
Contributor

@roypat roypat commented Jun 25, 2025

With Linux 5.13, UFFD got support for intercepting minor faults (e.g. where the page to be faulted in is present in the page cache, and only the userspace page table entries need to be established). This was realized by adding a new mode, MODE_MINOR, upon which the uffd will receive events with UFFD_PAGEFAULT_FLAG_MINOR set. These can then be resolved by issuing the UFFDIO_CONTINUE ioctl, which operates almost exactly like UFFDIO_COPY, expect that it doesnt do any memory population (since for minor faults, the memory contents are already there, in the page cache).

Since this adds a new linux version based feature flag to userfaultfd-sys (and thus userfaultfd), I added some preliminary commits to try to avoid having to duplicate the ever-increasing number of uffd-related constants into yet another file, but if that's not wanted, am also happy to drop those.

@bchalios
Copy link
Collaborator

bchalios commented Aug 18, 2025

@roypat Other than the commit message fix above LGTM. Thanks for the refactoring on the exports. Cool stuff!

roypat added 4 commits August 18, 2025 10:38
This ioctl was only added in linux 5.7 [1], so remove the bindings for
the ioctl number from the 4_11 and 4_14 features. The actual
writeprotect functionality was already gated behind the linux5_7
feature.

[1]: https://man7.org/linux/man-pages/man2/UFFDIO_WRITEPROTECT.2const.html

Signed-off-by: Patrick Roy <roypat@amazon.co.uk>
Extend the "constants are correct" tests to also cover the writeprotect
related constants.

Signed-off-by: Patrick Roy <roypat@amazon.co.uk>
Change the linux{major}_{minor} files that contain handwritten
bindings for constants that bindgen doesnt understand to be
"incremental" (e.g. linux4_14 only contains constants that are new to
4_14 and just reexports the 4_11 constants for old ones), to avoid
redefining an ever increasing set of constants with each version.

Also adjust the test that checks the api features and available ioctl
constants to only verify that the rust-defined set of features is a
subset of the kernel available features. For example running the test
on a 6.8 host kernel with the 5.7 feature means the kernel has more
features than the uffd crate supports, but this does not mean that the
crate definitions are _wrong_, just that they are incomplete.

Signed-off-by: Patrick Roy <roypat@amazon.co.uk>
With Linux 5.13, uffd got support for minor page fault notifications
(e.g. a page was already in the page cache, but not present in the
userspace page tables). Notifications are enabled by registering with
UFFDIO_REGISTER_MODE_MINOR, and resolved via the UFFDIO_CONTINUE ioctl.
Add support for these in userfaultfd-sys, as well as utility wrappers in
the main crate.

Signed-off-by: Patrick Roy <roypat@amazon.co.uk>
@bchalios bchalios merged commit 701c960 into bytecodealliance:main Aug 18, 2025
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants