UFFDIO_API(2const)

โœจ UFFDIO_API โ€” the userfaultfd glow-up ritual ๐Ÿ’…

okay so bestie, this is the manual page for UFFDIO_API(2const), and it lives in section 2const of the Linux manual pages, which is a whole vibe. it's giving "enable operation of the userfaultfd and perform API handshake." and honestly? it ate. let's get into it ๐Ÿซถ


๐Ÿ“š LIBRARY

Standard C library (libc, -lc). the usual. she's classic, she's reliable ๐Ÿ’–


๐ŸŒธ SYNOPSIS

#include <linux/userfaultfd.h>  /* Definition of UFFD* constants */
#include <sys/ioctl.h>

int ioctl(int fd, UFFDIO_API, struct uffdio_api *argp);
#include <linux/userfaultfd.h>

struct uffdio_api {
    __u64 api;       /* Requested API version (input) */
    __u64 features;  /* Requested features (input/output) */
    __u64 ioctls;    /* Available ioctl() operations (output) */
};

not me obsessing over a struct with exactly three fields. it's minimal, it's iconic, it's doing the most with the least ๐ŸŽ€


๐Ÿ’ซ DESCRIPTION

Enable operation of the userfaultfd and perform API handshake. yes bestie, that's the whole job. this is the "hi hello are we compatible ๐Ÿ‘€" conversation between your app and the kernel.

the api field is the API version your application is requesting. the kernel checks it can actually support that requested API version, and then sets the features and ioctls fields to bit masks representing all the available features and the generic ioctl(2) operations available. it's like a vibe check but for syscalls โœจ

Before Linux 4.11, the features field must be initialized to zero before the call to UFFDIO_API, and zero (i.e., no feature bits) is placed in the features field by the kernel upon return from ioctl(2). so basically the kernel was like "no thoughts, head empty, zero anyway" ๐Ÿ™ˆ

Since Linux 4.11, userfaultfd supports features that need to be enabled explicitly. to enable any of the features, one needs to set the corresponding feature bits in features when issuing the UFFDIO_API ioctl. no passive vibes here, you gotta ask for what you want, bestie.

For historical reasons, a temporary userfaultfd is needed to probe what userfaultfd features the kernel supports. the application needs to create a temporary userfaultfd, issue an UFFDIO_API ioctl with features set to zero. after the UFFDIO_API ioctl returns successfully, features should contain all the userfaultfd features that the kernel supports. the temporary userfaultfd can be safely closed after the probe. it's giving "trial run", it's giving "test the waters", it's giving "make a fake account to check the app out" ๐Ÿ˜ญ

โš ๏ธ If the application sets unsupported feature bits, the kernel will zero out the returned uffdio_api structure and return EINVAL. she said "nope, not on my watch" and wiped the whole board. rude but fair ๐Ÿ’€

The following feature bits may be set:

  • UFFD_FEATURE_EVENT_FORK (since Linux 4.11) โ€” When this feature is enabled, the userfaultfd objects associated with a parent process are duplicated into the child process during fork(2) and a UFFD_EVENT_FORK event is delivered to the userfaultfd monitor. family tree but make it syscalls ๐ŸŒˆ
  • UFFD_FEATURE_EVENT_REMAP (since Linux 4.11) โ€” If this feature is enabled, when the faulting process invokes mremap(2), the userfaultfd monitor will receive an event of type UFFD_EVENT_REMAP.
  • UFFD_FEATURE_EVENT_REMOVE (since Linux 4.11) โ€” If this feature is enabled, when the faulting process calls madvise(2) with the MADV_DONTNEED or MADV_REMOVE advice value to free a virtual memory area the userfaultfd monitor will receive an event of type UFFD_EVENT_REMOVE.
  • UFFD_FEATURE_EVENT_UNMAP (since Linux 4.11) โ€” If this feature is enabled, when the faulting process unmaps virtual memory either explicitly with munmap(2), or implicitly during either mmap(2) or mremap(2), the userfaultfd monitor will receive an event of type UFFD_EVENT_UNMAP.
  • UFFD_FEATURE_MISSING_HUGETLBFS (since Linux 4.11) โ€” If this feature bit is set, the kernel supports registering userfaultfd ranges on hugetlbfs virtual memory areas.
  • UFFD_FEATURE_MISSING_SHMEM (since Linux 4.11) โ€” If this feature bit is set, the kernel supports registering userfaultfd ranges on shared memory areas. This includes all kernel shared memory APIs: System V shared memory, tmpfs(5), shared mappings of /dev/zero, mmap(2) with the MAP_SHARED flag set, memfd_create(2), and so on. she's inclusive, she contains multitudes ๐Ÿ’œ
  • UFFD_FEATURE_SIGBUS (since Linux 4.14) โ€” If this feature bit is set, no page-fault events (UFFD_EVENT_PAGEFAULT) will be delivered. Instead, a SIGBUS signal will be sent to the faulting process. Applications using this feature will not require the use of a userfaultfd monitor for processing memory accesses to the regions registered with userfaultfd.
  • UFFD_FEATURE_THREAD_ID (since Linux 4.14) โ€” If this feature bit is set, uffd_msg.pagefault.feat.ptid will be set to the faulted thread ID for each page-fault message. we love knowing exactly which thread did the thing ๐Ÿซถ
  • UFFD_FEATURE_PAGEFAULT_FLAG_WP (since Linux 5.10) โ€” If this feature bit is set, userfaultfd supports write-protect faults for anonymous memory. (Note that shmem / hugetlbfs support is indicated by a separate feature.) note bestie, separate feature, don't get it twisted โœจ
  • UFFD_FEATURE_MINOR_HUGETLBFS (since Linux 5.13) โ€” If this feature bit is set, the kernel supports registering userfaultfd ranges in minor mode on hugetlbfs-backed memory areas.
  • UFFD_FEATURE_MINOR_SHMEM (since Linux 5.14) โ€” If this feature bit is set, the kernel supports registering userfaultfd ranges in minor mode on shmem-backed memory areas.
  • UFFD_FEATURE_EXACT_ADDRESS (since Linux 5.18) โ€” If this feature bit is set, uffd_msg.pagefault.address will be set to the exact page-fault address that was reported by the hardware, and will not mask the offset within the page. Note that old Linux versions might indicate the exact address as well, even though the feature bit is not set. so she might already be doing it and just not telling you ๐Ÿ™ˆ
  • UFFD_FEATURE_WP_HUGETLBFS_SHMEM (since Linux 5.19) โ€” If this feature bit is set, userfaultfd supports write-protect faults for hugetlbfs and shmem / tmpfs memory.
  • UFFD_FEATURE_WP_UNPOPULATED (since Linux 6.4) โ€” If this feature bit is set, the kernel will handle anonymous memory the same way as file memory, by allowing the user to write-protect unpopulated page table entries.
  • UFFD_FEATURE_POISON (since Linux 6.6) โ€” If this feature bit is set, the kernel supports resolving faults with the UFFDIO_POISON ioctl.
  • UFFD_FEATURE_WP_ASYNC (since Linux 6.7) โ€” If this feature bit is set, the write protection faults would be asynchronously resolved by the kernel.
  • UFFD_FEATURE_MOVE (since Linux 6.8) โ€” If this feature bit is set, the kernel supports resolving faults with the UFFDIO_MOVE ioctl.
  • UFFD_FEATURE_RWP (since Linux 7.2) โ€” If this feature bit is set, the kernel supports read-write-protection tracking, and the UFFDIO_REGISTER_MODE_RWP registration mode and the UFFDIO_RWPROTECT ioctl become available.
  • UFFD_FEATURE_RWP_ASYNC (since Linux 7.2) โ€” If this feature bit is set, the kernel will resolve read-write-protect faults in place without delivering a notification, automatically restoring page permissions and letting the faulted thread continue. This bit requires UFFD_FEATURE_RWP to be set in the same UFFDIO_API call. The async mode can also be toggled at runtime using the UFFDIO_SET_MODE(2const) ioctl. package deal bestie, you can't just take the async one and dip ๐ŸŒธ

The returned argp->ioctls field can contain the following bits:

  • 1 << _UFFDIO_API โ€” The UFFDIO_API operation is supported.
  • 1 << _UFFDIO_REGISTER โ€” The UFFDIO_REGISTER operation is supported.
  • 1 << _UFFDIO_UNREGISTER โ€” The UFFDIO_UNREGISTER operation is supported.
  • 1 << _UFFDIO_SET_MODE (since Linux 7.2) โ€” The UFFDIO_SET_MODE operation is supported. This is a file-descriptor-level ioctl and is reported once per userfaultfd, independent of any registered range. one per userfaultfd and she means it ๐Ÿ’…

๐ŸŽฏ RETURN VALUE

On success, 0 is returned. slay. โœ…

On error, -1 is returned and errno is set to indicate the error. we love a dramatic entrance ๐Ÿ˜ญ


๐Ÿšจ ERRORS

  • EFAULT โ€” argp refers to an address that is outside the calling process's accessible address space. you pointed at the void bestie, the void pointed back ๐Ÿ’€
  • EINVAL โ€” The API version requested in the api field is not supported by this kernel, or the features field passed to the kernel includes feature bits that are not supported by the current kernel version.
  • EINVAL โ€” A previous UFFDIO_API call already enabled one or more features for this userfaultfd. Calling UFFDIO_API twice, the first time with no features set, is explicitly allowed as per the two-step feature detection handshake. okay so this one is the allowed double-dip, do not panic โœจ
  • EPERM โ€” The UFFD_FEATURE_EVENT_FORK feature was enabled, but the calling process doesn't have the CAP_SYS_PTRACE capability. no cap, literally, you need the cap ๐Ÿงข

๐Ÿ“ STANDARDS

Linux. that's it. that's the standard. ๐Ÿ‡ฑ๐Ÿ‡ฎ๐Ÿ‡ณ๐Ÿ‡บ๐Ÿ‡ฝ


๐Ÿ•ฐ๏ธ HISTORY

Linux 4.3. she's been around, she's a little vintage, she's an icon ๐Ÿ‘‘


โš ๏ธ CAVEATS

If an error occurs, the kernel may zero the provided uffdio_api structure. The caller should treat its contents as unspecified, and reinitialize it before re-attempting another UFFDIO_API call.

bestie please. treat it as unspecified. do not read the vibes off a zeroed struct. reinitialize it, it's not that deep, but it IS that important ๐Ÿซถ

๐Ÿ’€ BUGS

In order to detect available userfault features and enable some subset of those features the userfaultfd file descriptor must be closed after the first UFFDIO_API operation that queries features availability and reopened before the second UFFDIO_API operation that actually enables the desired features.

so yeah, close it, reopen it, close it, reopen it. it's giving getting back together with your ex, except this time it's a file descriptor and it actually works ๐Ÿ˜ญ


๐ŸŒŸ EXAMPLES

See userfaultfd(2). the homework is over there, bestie, I'm not doing it for you ๐Ÿ“šโœจ


๐Ÿ‘€ SEE ALSO


and that's the page ๐Ÿ’– this was Linux man-pages 6.20, dated 2026-06-04, and honestly? iconic. periodt. go forth and handshake with your kernel, bestie, you've got this ๐Ÿฆ‹โœจ๐Ÿ’…

๐Ÿ“ฆ where this page comes from
  • arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
  • nixpkgs unstable: man-pages 6.20
  • ๐Ÿ“œ the page's license: Linux-man-pages-copyleft
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms