2 * include/linux/userfaultfd.h
5 * Copyright (C) 2015 Red Hat, Inc.
9 #ifndef _LINUX_USERFAULTFD_H
10 #define _LINUX_USERFAULTFD_H
12 #include <linux/types.h>
14 #include <linux/compiler.h>
16 #define UFFD_API ((__u64)0xAA)
18 * After implementing the respective features it will become:
19 * #define UFFD_API_FEATURES (UFFD_FEATURE_PAGEFAULT_FLAG_WP | \
20 * UFFD_FEATURE_EVENT_FORK)
22 #define UFFD_API_FEATURES (0)
23 #define UFFD_API_IOCTLS \
24 ((__u64)1 << _UFFDIO_REGISTER | \
25 (__u64)1 << _UFFDIO_UNREGISTER | \
26 (__u64)1 << _UFFDIO_API)
27 #define UFFD_API_RANGE_IOCTLS \
28 ((__u64)1 << _UFFDIO_WAKE | \
29 (__u64)1 << _UFFDIO_COPY | \
30 (__u64)1 << _UFFDIO_ZEROPAGE)
33 * Valid ioctl command number range with this API is from 0x00 to
34 * 0x3F. UFFDIO_API is the fixed number, everything else can be
35 * changed by implementing a different UFFD_API. If sticking to the
36 * same UFFD_API more ioctl can be added and userland will be aware of
37 * which ioctl the running kernel implements through the ioctl command
38 * bitmask written by the UFFDIO_API.
40 #define _UFFDIO_REGISTER (0x00)
41 #define _UFFDIO_UNREGISTER (0x01)
42 #define _UFFDIO_WAKE (0x02)
43 #define _UFFDIO_COPY (0x03)
44 #define _UFFDIO_ZEROPAGE (0x04)
45 #define _UFFDIO_API (0x3F)
47 /* userfaultfd ioctl ids */
49 #define UFFDIO_API _IOWR(UFFDIO, _UFFDIO_API, \
51 #define UFFDIO_REGISTER _IOWR(UFFDIO, _UFFDIO_REGISTER, \
52 struct uffdio_register)
53 #define UFFDIO_UNREGISTER _IOR(UFFDIO, _UFFDIO_UNREGISTER, \
55 #define UFFDIO_WAKE _IOR(UFFDIO, _UFFDIO_WAKE, \
57 #define UFFDIO_COPY _IOWR(UFFDIO, _UFFDIO_COPY, \
59 #define UFFDIO_ZEROPAGE _IOWR(UFFDIO, _UFFDIO_ZEROPAGE, \
60 struct uffdio_zeropage)
62 /* read() structure */
77 /* unused reserved fields */
86 * Start at 0x12 and not at 0 to be more strict against bugs.
88 #define UFFD_EVENT_PAGEFAULT 0x12
89 #if 0 /* not available yet */
90 #define UFFD_EVENT_FORK 0x13
93 /* flags for UFFD_EVENT_PAGEFAULT */
94 #define UFFD_PAGEFAULT_FLAG_WRITE (1<<0) /* If this was a write fault */
95 #define UFFD_PAGEFAULT_FLAG_WP (1<<1) /* If reason is VM_UFFD_WP */
98 /* userland asks for an API number and the features to enable */
101 * Kernel answers below with the all available features for
102 * the API, this notifies userland of which events and/or
103 * which flags for each event are enabled in the current
106 * Note: UFFD_EVENT_PAGEFAULT and UFFD_PAGEFAULT_FLAG_WRITE
107 * are to be considered implicitly always enabled in all kernels as
108 * long as the uffdio_api.api requested matches UFFD_API.
110 #if 0 /* not available yet */
111 #define UFFD_FEATURE_PAGEFAULT_FLAG_WP (1<<0)
112 #define UFFD_FEATURE_EVENT_FORK (1<<1)
119 struct uffdio_range {
124 struct uffdio_register {
125 struct uffdio_range range;
126 #define UFFDIO_REGISTER_MODE_MISSING ((__u64)1<<0)
127 #define UFFDIO_REGISTER_MODE_WP ((__u64)1<<1)
131 * kernel answers which ioctl commands are available for the
132 * range, keep at the end as the last 8 bytes aren't read.
142 * There will be a wrprotection flag later that allows to map
143 * pages wrprotected on the fly. And such a flag will be
144 * available if the wrprotection ioctl are implemented for the
145 * range according to the uffdio_register.ioctls.
147 #define UFFDIO_COPY_MODE_DONTWAKE ((__u64)1<<0)
151 * "copy" is written by the ioctl and must be at the end: the
152 * copy_from_user will not read the last 8 bytes.
157 struct uffdio_zeropage {
158 struct uffdio_range range;
159 #define UFFDIO_ZEROPAGE_MODE_DONTWAKE ((__u64)1<<0)
163 * "zeropage" is written by the ioctl and must be at the end:
164 * the copy_from_user will not read the last 8 bytes.
169 #endif /* _LINUX_USERFAULTFD_H */