2 * include/linux/userfaultfd.h
4 * Copyright (C) 2007 Davide Libenzi <davidel@xmailserver.org>
5 * Copyright (C) 2015 Red Hat, Inc.
9 #ifndef _LINUX_USERFAULTFD_H
10 #define _LINUX_USERFAULTFD_H
12 #include <linux/types.h>
15 * If the UFFDIO_API is upgraded someday, the UFFDIO_UNREGISTER and
16 * UFFDIO_WAKE ioctls should be defined as _IOW and not as _IOR. In
17 * userfaultfd.h we assumed the kernel was reading (instead _IOC_READ
18 * means the userland is reading).
20 #define UFFD_API ((__u64)0xAA)
21 #define UFFD_API_FEATURES (UFFD_FEATURE_EVENT_FORK | \
22 UFFD_FEATURE_EVENT_REMAP | \
23 UFFD_FEATURE_EVENT_MADVDONTNEED)
24 #define UFFD_API_IOCTLS \
25 ((__u64)1 << _UFFDIO_REGISTER | \
26 (__u64)1 << _UFFDIO_UNREGISTER | \
27 (__u64)1 << _UFFDIO_API)
28 #define UFFD_API_RANGE_IOCTLS \
29 ((__u64)1 << _UFFDIO_WAKE | \
30 (__u64)1 << _UFFDIO_COPY | \
31 (__u64)1 << _UFFDIO_ZEROPAGE)
32 #define UFFD_API_RANGE_IOCTLS_HPAGE \
33 ((__u64)1 << _UFFDIO_WAKE | \
34 (__u64)1 << _UFFDIO_COPY)
37 * Valid ioctl command number range with this API is from 0x00 to
38 * 0x3F. UFFDIO_API is the fixed number, everything else can be
39 * changed by implementing a different UFFD_API. If sticking to the
40 * same UFFD_API more ioctl can be added and userland will be aware of
41 * which ioctl the running kernel implements through the ioctl command
42 * bitmask written by the UFFDIO_API.
44 #define _UFFDIO_REGISTER (0x00)
45 #define _UFFDIO_UNREGISTER (0x01)
46 #define _UFFDIO_WAKE (0x02)
47 #define _UFFDIO_COPY (0x03)
48 #define _UFFDIO_ZEROPAGE (0x04)
49 #define _UFFDIO_API (0x3F)
51 /* userfaultfd ioctl ids */
53 #define UFFDIO_API _IOWR(UFFDIO, _UFFDIO_API, \
55 #define UFFDIO_REGISTER _IOWR(UFFDIO, _UFFDIO_REGISTER, \
56 struct uffdio_register)
57 #define UFFDIO_UNREGISTER _IOR(UFFDIO, _UFFDIO_UNREGISTER, \
59 #define UFFDIO_WAKE _IOR(UFFDIO, _UFFDIO_WAKE, \
61 #define UFFDIO_COPY _IOWR(UFFDIO, _UFFDIO_COPY, \
63 #define UFFDIO_ZEROPAGE _IOWR(UFFDIO, _UFFDIO_ZEROPAGE, \
64 struct uffdio_zeropage)
66 /* read() structure */
96 /* unused reserved fields */
105 * Start at 0x12 and not at 0 to be more strict against bugs.
107 #define UFFD_EVENT_PAGEFAULT 0x12
108 #define UFFD_EVENT_FORK 0x13
109 #define UFFD_EVENT_REMAP 0x14
110 #define UFFD_EVENT_MADVDONTNEED 0x15
112 /* flags for UFFD_EVENT_PAGEFAULT */
113 #define UFFD_PAGEFAULT_FLAG_WRITE (1<<0) /* If this was a write fault */
114 #define UFFD_PAGEFAULT_FLAG_WP (1<<1) /* If reason is VM_UFFD_WP */
117 /* userland asks for an API number and the features to enable */
120 * Kernel answers below with the all available features for
121 * the API, this notifies userland of which events and/or
122 * which flags for each event are enabled in the current
125 * Note: UFFD_EVENT_PAGEFAULT and UFFD_PAGEFAULT_FLAG_WRITE
126 * are to be considered implicitly always enabled in all kernels as
127 * long as the uffdio_api.api requested matches UFFD_API.
129 #define UFFD_FEATURE_PAGEFAULT_FLAG_WP (1<<0)
130 #define UFFD_FEATURE_EVENT_FORK (1<<1)
131 #define UFFD_FEATURE_EVENT_REMAP (1<<2)
132 #define UFFD_FEATURE_EVENT_MADVDONTNEED (1<<3)
138 struct uffdio_range {
143 struct uffdio_register {
144 struct uffdio_range range;
145 #define UFFDIO_REGISTER_MODE_MISSING ((__u64)1<<0)
146 #define UFFDIO_REGISTER_MODE_WP ((__u64)1<<1)
150 * kernel answers which ioctl commands are available for the
151 * range, keep at the end as the last 8 bytes aren't read.
161 * There will be a wrprotection flag later that allows to map
162 * pages wrprotected on the fly. And such a flag will be
163 * available if the wrprotection ioctl are implemented for the
164 * range according to the uffdio_register.ioctls.
166 #define UFFDIO_COPY_MODE_DONTWAKE ((__u64)1<<0)
170 * "copy" is written by the ioctl and must be at the end: the
171 * copy_from_user will not read the last 8 bytes.
176 struct uffdio_zeropage {
177 struct uffdio_range range;
178 #define UFFDIO_ZEROPAGE_MODE_DONTWAKE ((__u64)1<<0)
182 * "zeropage" is written by the ioctl and must be at the end:
183 * the copy_from_user will not read the last 8 bytes.
188 #endif /* _LINUX_USERFAULTFD_H */