Skip to content

Add support for UFFDIO_CONTINUE and UFFDIO_REGISTER_MODE_MINOR #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

roypat
Copy link

@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.

roypat added 4 commits June 25, 2025 14:45
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_zeropage.2const.html

Signed-off-by: Patrick Roy <[email protected]>
Extend the "constants are correct" tests to also cover the writeprotect
related constants.

Signed-off-by: Patrick Roy <[email protected]>
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 <[email protected]>
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 <[email protected]>
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