---
name: "UFFDIO_API"
section: "2const"
platform: "linux"
package: "man-pages"
version: "6.19-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/UFFDIO_API"
---

# UFFDIO\_API(2const)

enable operation of the userfaultfd and perform API handshake

## NAME

UFFDIO\_API - enable operation of the userfaultfd and perform API handshake

## LIBRARY

Standard C library (*libc*, *-lc*)

## 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) */
};
```

## DESCRIPTION

Enable operation of the userfaultfd and perform API handshake.

The *api* field denotes the API version requested by the application. The kernel verifies that it can support the requested API version, and sets the *features* and *ioctls* fields to bit masks representing all the available features and the generic [**ioctl**(2)](/ioctl/2.md) operations available.

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)](/ioctl/2.md).

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.

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.

If the application sets unsupported feature bits, the kernel will zero out the returned *uffdio\_api* structure and return **EINVAL**.

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)](/fork/2.md) and a **UFFD\_EVENT\_FORK** event is delivered to the userfaultfd monitor

- **UFFD\_FEATURE\_EVENT\_REMAP** (since Linux 4.11)

  If this feature is enabled, when the faulting process invokes [**mremap**(2)](/mremap/2.md), 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)](/madvise/2.md) 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)](/munmap/2.md), or implicitly during either [**mmap**(2)](/mmap/2.md) or [**mremap**(2)](/mremap/2.md), 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)](/tmpfs/5.md), shared mappings of */dev/zero*, [**mmap**(2)](/mmap/2.md) with the **MAP\_SHARED** flag set, [**memfd\_create**(2)](/memfd_create/2.md), and so on.

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

- **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.)

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

- **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)](/UFFDIO_SET_MODE/2const.md) ioctl.

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.

## RETURN VALUE

On success, 0 is returned.

On error, -1 is returned and *errno* is set to indicate the error.

## ERRORS

- **EFAULT**

  *argp* refers to an address that is outside the calling process's accessible address space.

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

- **EPERM**

  The **UFFD\_FEATURE\_EVENT\_FORK** feature was enabled, but the calling process doesn't have the **CAP\_SYS\_PTRACE** capability.

## STANDARDS

Linux.

## HISTORY

Linux 4.3.

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

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

## EXAMPLES

See [**userfaultfd**(2)](/userfaultfd/2.md).

## SEE ALSO

[**ioctl**(2)](/ioctl/2.md), [**ioctl\_userfaultfd**(2)](/ioctl_userfaultfd/2.md), [**mmap**(2)](/mmap/2.md), [**userfaultfd**(2)](/userfaultfd/2.md)

*linux.git/Documentation/admin-guide/mm/userfaultfd.rst*
