1*580ea358SJohn Hubbard /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2*580ea358SJohn Hubbard /*
3*580ea358SJohn Hubbard  *  include/linux/userfaultfd.h
4*580ea358SJohn Hubbard  *
5*580ea358SJohn Hubbard  *  Copyright (C) 2007  Davide Libenzi <[email protected]>
6*580ea358SJohn Hubbard  *  Copyright (C) 2015  Red Hat, Inc.
7*580ea358SJohn Hubbard  *
8*580ea358SJohn Hubbard  */
9*580ea358SJohn Hubbard 
10*580ea358SJohn Hubbard #ifndef _LINUX_USERFAULTFD_H
11*580ea358SJohn Hubbard #define _LINUX_USERFAULTFD_H
12*580ea358SJohn Hubbard 
13*580ea358SJohn Hubbard #include <linux/types.h>
14*580ea358SJohn Hubbard 
15*580ea358SJohn Hubbard /* ioctls for /dev/userfaultfd */
16*580ea358SJohn Hubbard #define USERFAULTFD_IOC 0xAA
17*580ea358SJohn Hubbard #define USERFAULTFD_IOC_NEW _IO(USERFAULTFD_IOC, 0x00)
18*580ea358SJohn Hubbard 
19*580ea358SJohn Hubbard /*
20*580ea358SJohn Hubbard  * If the UFFDIO_API is upgraded someday, the UFFDIO_UNREGISTER and
21*580ea358SJohn Hubbard  * UFFDIO_WAKE ioctls should be defined as _IOW and not as _IOR.  In
22*580ea358SJohn Hubbard  * userfaultfd.h we assumed the kernel was reading (instead _IOC_READ
23*580ea358SJohn Hubbard  * means the userland is reading).
24*580ea358SJohn Hubbard  */
25*580ea358SJohn Hubbard #define UFFD_API ((__u64)0xAA)
26*580ea358SJohn Hubbard #define UFFD_API_REGISTER_MODES (UFFDIO_REGISTER_MODE_MISSING |	\
27*580ea358SJohn Hubbard 				 UFFDIO_REGISTER_MODE_WP |	\
28*580ea358SJohn Hubbard 				 UFFDIO_REGISTER_MODE_MINOR)
29*580ea358SJohn Hubbard #define UFFD_API_FEATURES (UFFD_FEATURE_PAGEFAULT_FLAG_WP |	\
30*580ea358SJohn Hubbard 			   UFFD_FEATURE_EVENT_FORK |		\
31*580ea358SJohn Hubbard 			   UFFD_FEATURE_EVENT_REMAP |		\
32*580ea358SJohn Hubbard 			   UFFD_FEATURE_EVENT_REMOVE |		\
33*580ea358SJohn Hubbard 			   UFFD_FEATURE_EVENT_UNMAP |		\
34*580ea358SJohn Hubbard 			   UFFD_FEATURE_MISSING_HUGETLBFS |	\
35*580ea358SJohn Hubbard 			   UFFD_FEATURE_MISSING_SHMEM |		\
36*580ea358SJohn Hubbard 			   UFFD_FEATURE_SIGBUS |		\
37*580ea358SJohn Hubbard 			   UFFD_FEATURE_THREAD_ID |		\
38*580ea358SJohn Hubbard 			   UFFD_FEATURE_MINOR_HUGETLBFS |	\
39*580ea358SJohn Hubbard 			   UFFD_FEATURE_MINOR_SHMEM |		\
40*580ea358SJohn Hubbard 			   UFFD_FEATURE_EXACT_ADDRESS |		\
41*580ea358SJohn Hubbard 			   UFFD_FEATURE_WP_HUGETLBFS_SHMEM |	\
42*580ea358SJohn Hubbard 			   UFFD_FEATURE_WP_UNPOPULATED |	\
43*580ea358SJohn Hubbard 			   UFFD_FEATURE_POISON |		\
44*580ea358SJohn Hubbard 			   UFFD_FEATURE_WP_ASYNC |		\
45*580ea358SJohn Hubbard 			   UFFD_FEATURE_MOVE)
46*580ea358SJohn Hubbard #define UFFD_API_IOCTLS				\
47*580ea358SJohn Hubbard 	((__u64)1 << _UFFDIO_REGISTER |		\
48*580ea358SJohn Hubbard 	 (__u64)1 << _UFFDIO_UNREGISTER |	\
49*580ea358SJohn Hubbard 	 (__u64)1 << _UFFDIO_API)
50*580ea358SJohn Hubbard #define UFFD_API_RANGE_IOCTLS			\
51*580ea358SJohn Hubbard 	((__u64)1 << _UFFDIO_WAKE |		\
52*580ea358SJohn Hubbard 	 (__u64)1 << _UFFDIO_COPY |		\
53*580ea358SJohn Hubbard 	 (__u64)1 << _UFFDIO_ZEROPAGE |		\
54*580ea358SJohn Hubbard 	 (__u64)1 << _UFFDIO_MOVE |		\
55*580ea358SJohn Hubbard 	 (__u64)1 << _UFFDIO_WRITEPROTECT |	\
56*580ea358SJohn Hubbard 	 (__u64)1 << _UFFDIO_CONTINUE |		\
57*580ea358SJohn Hubbard 	 (__u64)1 << _UFFDIO_POISON)
58*580ea358SJohn Hubbard #define UFFD_API_RANGE_IOCTLS_BASIC		\
59*580ea358SJohn Hubbard 	((__u64)1 << _UFFDIO_WAKE |		\
60*580ea358SJohn Hubbard 	 (__u64)1 << _UFFDIO_COPY |		\
61*580ea358SJohn Hubbard 	 (__u64)1 << _UFFDIO_WRITEPROTECT |	\
62*580ea358SJohn Hubbard 	 (__u64)1 << _UFFDIO_CONTINUE |		\
63*580ea358SJohn Hubbard 	 (__u64)1 << _UFFDIO_POISON)
64*580ea358SJohn Hubbard 
65*580ea358SJohn Hubbard /*
66*580ea358SJohn Hubbard  * Valid ioctl command number range with this API is from 0x00 to
67*580ea358SJohn Hubbard  * 0x3F.  UFFDIO_API is the fixed number, everything else can be
68*580ea358SJohn Hubbard  * changed by implementing a different UFFD_API. If sticking to the
69*580ea358SJohn Hubbard  * same UFFD_API more ioctl can be added and userland will be aware of
70*580ea358SJohn Hubbard  * which ioctl the running kernel implements through the ioctl command
71*580ea358SJohn Hubbard  * bitmask written by the UFFDIO_API.
72*580ea358SJohn Hubbard  */
73*580ea358SJohn Hubbard #define _UFFDIO_REGISTER		(0x00)
74*580ea358SJohn Hubbard #define _UFFDIO_UNREGISTER		(0x01)
75*580ea358SJohn Hubbard #define _UFFDIO_WAKE			(0x02)
76*580ea358SJohn Hubbard #define _UFFDIO_COPY			(0x03)
77*580ea358SJohn Hubbard #define _UFFDIO_ZEROPAGE		(0x04)
78*580ea358SJohn Hubbard #define _UFFDIO_MOVE			(0x05)
79*580ea358SJohn Hubbard #define _UFFDIO_WRITEPROTECT		(0x06)
80*580ea358SJohn Hubbard #define _UFFDIO_CONTINUE		(0x07)
81*580ea358SJohn Hubbard #define _UFFDIO_POISON			(0x08)
82*580ea358SJohn Hubbard #define _UFFDIO_API			(0x3F)
83*580ea358SJohn Hubbard 
84*580ea358SJohn Hubbard /* userfaultfd ioctl ids */
85*580ea358SJohn Hubbard #define UFFDIO 0xAA
86*580ea358SJohn Hubbard #define UFFDIO_API		_IOWR(UFFDIO, _UFFDIO_API,	\
87*580ea358SJohn Hubbard 				      struct uffdio_api)
88*580ea358SJohn Hubbard #define UFFDIO_REGISTER		_IOWR(UFFDIO, _UFFDIO_REGISTER, \
89*580ea358SJohn Hubbard 				      struct uffdio_register)
90*580ea358SJohn Hubbard #define UFFDIO_UNREGISTER	_IOR(UFFDIO, _UFFDIO_UNREGISTER,	\
91*580ea358SJohn Hubbard 				     struct uffdio_range)
92*580ea358SJohn Hubbard #define UFFDIO_WAKE		_IOR(UFFDIO, _UFFDIO_WAKE,	\
93*580ea358SJohn Hubbard 				     struct uffdio_range)
94*580ea358SJohn Hubbard #define UFFDIO_COPY		_IOWR(UFFDIO, _UFFDIO_COPY,	\
95*580ea358SJohn Hubbard 				      struct uffdio_copy)
96*580ea358SJohn Hubbard #define UFFDIO_ZEROPAGE		_IOWR(UFFDIO, _UFFDIO_ZEROPAGE,	\
97*580ea358SJohn Hubbard 				      struct uffdio_zeropage)
98*580ea358SJohn Hubbard #define UFFDIO_MOVE		_IOWR(UFFDIO, _UFFDIO_MOVE,	\
99*580ea358SJohn Hubbard 				      struct uffdio_move)
100*580ea358SJohn Hubbard #define UFFDIO_WRITEPROTECT	_IOWR(UFFDIO, _UFFDIO_WRITEPROTECT, \
101*580ea358SJohn Hubbard 				      struct uffdio_writeprotect)
102*580ea358SJohn Hubbard #define UFFDIO_CONTINUE		_IOWR(UFFDIO, _UFFDIO_CONTINUE,	\
103*580ea358SJohn Hubbard 				      struct uffdio_continue)
104*580ea358SJohn Hubbard #define UFFDIO_POISON		_IOWR(UFFDIO, _UFFDIO_POISON, \
105*580ea358SJohn Hubbard 				      struct uffdio_poison)
106*580ea358SJohn Hubbard 
107*580ea358SJohn Hubbard /* read() structure */
108*580ea358SJohn Hubbard struct uffd_msg {
109*580ea358SJohn Hubbard 	__u8	event;
110*580ea358SJohn Hubbard 
111*580ea358SJohn Hubbard 	__u8	reserved1;
112*580ea358SJohn Hubbard 	__u16	reserved2;
113*580ea358SJohn Hubbard 	__u32	reserved3;
114*580ea358SJohn Hubbard 
115*580ea358SJohn Hubbard 	union {
116*580ea358SJohn Hubbard 		struct {
117*580ea358SJohn Hubbard 			__u64	flags;
118*580ea358SJohn Hubbard 			__u64	address;
119*580ea358SJohn Hubbard 			union {
120*580ea358SJohn Hubbard 				__u32 ptid;
121*580ea358SJohn Hubbard 			} feat;
122*580ea358SJohn Hubbard 		} pagefault;
123*580ea358SJohn Hubbard 
124*580ea358SJohn Hubbard 		struct {
125*580ea358SJohn Hubbard 			__u32	ufd;
126*580ea358SJohn Hubbard 		} fork;
127*580ea358SJohn Hubbard 
128*580ea358SJohn Hubbard 		struct {
129*580ea358SJohn Hubbard 			__u64	from;
130*580ea358SJohn Hubbard 			__u64	to;
131*580ea358SJohn Hubbard 			__u64	len;
132*580ea358SJohn Hubbard 		} remap;
133*580ea358SJohn Hubbard 
134*580ea358SJohn Hubbard 		struct {
135*580ea358SJohn Hubbard 			__u64	start;
136*580ea358SJohn Hubbard 			__u64	end;
137*580ea358SJohn Hubbard 		} remove;
138*580ea358SJohn Hubbard 
139*580ea358SJohn Hubbard 		struct {
140*580ea358SJohn Hubbard 			/* unused reserved fields */
141*580ea358SJohn Hubbard 			__u64	reserved1;
142*580ea358SJohn Hubbard 			__u64	reserved2;
143*580ea358SJohn Hubbard 			__u64	reserved3;
144*580ea358SJohn Hubbard 		} reserved;
145*580ea358SJohn Hubbard 	} arg;
146*580ea358SJohn Hubbard } __attribute__((packed));
147*580ea358SJohn Hubbard 
148*580ea358SJohn Hubbard /*
149*580ea358SJohn Hubbard  * Start at 0x12 and not at 0 to be more strict against bugs.
150*580ea358SJohn Hubbard  */
151*580ea358SJohn Hubbard #define UFFD_EVENT_PAGEFAULT	0x12
152*580ea358SJohn Hubbard #define UFFD_EVENT_FORK		0x13
153*580ea358SJohn Hubbard #define UFFD_EVENT_REMAP	0x14
154*580ea358SJohn Hubbard #define UFFD_EVENT_REMOVE	0x15
155*580ea358SJohn Hubbard #define UFFD_EVENT_UNMAP	0x16
156*580ea358SJohn Hubbard 
157*580ea358SJohn Hubbard /* flags for UFFD_EVENT_PAGEFAULT */
158*580ea358SJohn Hubbard #define UFFD_PAGEFAULT_FLAG_WRITE	(1<<0)	/* If this was a write fault */
159*580ea358SJohn Hubbard #define UFFD_PAGEFAULT_FLAG_WP		(1<<1)	/* If reason is VM_UFFD_WP */
160*580ea358SJohn Hubbard #define UFFD_PAGEFAULT_FLAG_MINOR	(1<<2)	/* If reason is VM_UFFD_MINOR */
161*580ea358SJohn Hubbard 
162*580ea358SJohn Hubbard struct uffdio_api {
163*580ea358SJohn Hubbard 	/* userland asks for an API number and the features to enable */
164*580ea358SJohn Hubbard 	__u64 api;
165*580ea358SJohn Hubbard 	/*
166*580ea358SJohn Hubbard 	 * Kernel answers below with the all available features for
167*580ea358SJohn Hubbard 	 * the API, this notifies userland of which events and/or
168*580ea358SJohn Hubbard 	 * which flags for each event are enabled in the current
169*580ea358SJohn Hubbard 	 * kernel.
170*580ea358SJohn Hubbard 	 *
171*580ea358SJohn Hubbard 	 * Note: UFFD_EVENT_PAGEFAULT and UFFD_PAGEFAULT_FLAG_WRITE
172*580ea358SJohn Hubbard 	 * are to be considered implicitly always enabled in all kernels as
173*580ea358SJohn Hubbard 	 * long as the uffdio_api.api requested matches UFFD_API.
174*580ea358SJohn Hubbard 	 *
175*580ea358SJohn Hubbard 	 * UFFD_FEATURE_MISSING_HUGETLBFS means an UFFDIO_REGISTER
176*580ea358SJohn Hubbard 	 * with UFFDIO_REGISTER_MODE_MISSING mode will succeed on
177*580ea358SJohn Hubbard 	 * hugetlbfs virtual memory ranges. Adding or not adding
178*580ea358SJohn Hubbard 	 * UFFD_FEATURE_MISSING_HUGETLBFS to uffdio_api.features has
179*580ea358SJohn Hubbard 	 * no real functional effect after UFFDIO_API returns, but
180*580ea358SJohn Hubbard 	 * it's only useful for an initial feature set probe at
181*580ea358SJohn Hubbard 	 * UFFDIO_API time. There are two ways to use it:
182*580ea358SJohn Hubbard 	 *
183*580ea358SJohn Hubbard 	 * 1) by adding UFFD_FEATURE_MISSING_HUGETLBFS to the
184*580ea358SJohn Hubbard 	 *    uffdio_api.features before calling UFFDIO_API, an error
185*580ea358SJohn Hubbard 	 *    will be returned by UFFDIO_API on a kernel without
186*580ea358SJohn Hubbard 	 *    hugetlbfs missing support
187*580ea358SJohn Hubbard 	 *
188*580ea358SJohn Hubbard 	 * 2) the UFFD_FEATURE_MISSING_HUGETLBFS can not be added in
189*580ea358SJohn Hubbard 	 *    uffdio_api.features and instead it will be set by the
190*580ea358SJohn Hubbard 	 *    kernel in the uffdio_api.features if the kernel supports
191*580ea358SJohn Hubbard 	 *    it, so userland can later check if the feature flag is
192*580ea358SJohn Hubbard 	 *    present in uffdio_api.features after UFFDIO_API
193*580ea358SJohn Hubbard 	 *    succeeded.
194*580ea358SJohn Hubbard 	 *
195*580ea358SJohn Hubbard 	 * UFFD_FEATURE_MISSING_SHMEM works the same as
196*580ea358SJohn Hubbard 	 * UFFD_FEATURE_MISSING_HUGETLBFS, but it applies to shmem
197*580ea358SJohn Hubbard 	 * (i.e. tmpfs and other shmem based APIs).
198*580ea358SJohn Hubbard 	 *
199*580ea358SJohn Hubbard 	 * UFFD_FEATURE_SIGBUS feature means no page-fault
200*580ea358SJohn Hubbard 	 * (UFFD_EVENT_PAGEFAULT) event will be delivered, instead
201*580ea358SJohn Hubbard 	 * a SIGBUS signal will be sent to the faulting process.
202*580ea358SJohn Hubbard 	 *
203*580ea358SJohn Hubbard 	 * UFFD_FEATURE_THREAD_ID pid of the page faulted task_struct will
204*580ea358SJohn Hubbard 	 * be returned, if feature is not requested 0 will be returned.
205*580ea358SJohn Hubbard 	 *
206*580ea358SJohn Hubbard 	 * UFFD_FEATURE_MINOR_HUGETLBFS indicates that minor faults
207*580ea358SJohn Hubbard 	 * can be intercepted (via REGISTER_MODE_MINOR) for
208*580ea358SJohn Hubbard 	 * hugetlbfs-backed pages.
209*580ea358SJohn Hubbard 	 *
210*580ea358SJohn Hubbard 	 * UFFD_FEATURE_MINOR_SHMEM indicates the same support as
211*580ea358SJohn Hubbard 	 * UFFD_FEATURE_MINOR_HUGETLBFS, but for shmem-backed pages instead.
212*580ea358SJohn Hubbard 	 *
213*580ea358SJohn Hubbard 	 * UFFD_FEATURE_EXACT_ADDRESS indicates that the exact address of page
214*580ea358SJohn Hubbard 	 * faults would be provided and the offset within the page would not be
215*580ea358SJohn Hubbard 	 * masked.
216*580ea358SJohn Hubbard 	 *
217*580ea358SJohn Hubbard 	 * UFFD_FEATURE_WP_HUGETLBFS_SHMEM indicates that userfaultfd
218*580ea358SJohn Hubbard 	 * write-protection mode is supported on both shmem and hugetlbfs.
219*580ea358SJohn Hubbard 	 *
220*580ea358SJohn Hubbard 	 * UFFD_FEATURE_WP_UNPOPULATED indicates that userfaultfd
221*580ea358SJohn Hubbard 	 * write-protection mode will always apply to unpopulated pages
222*580ea358SJohn Hubbard 	 * (i.e. empty ptes).  This will be the default behavior for shmem
223*580ea358SJohn Hubbard 	 * & hugetlbfs, so this flag only affects anonymous memory behavior
224*580ea358SJohn Hubbard 	 * when userfault write-protection mode is registered.
225*580ea358SJohn Hubbard 	 *
226*580ea358SJohn Hubbard 	 * UFFD_FEATURE_WP_ASYNC indicates that userfaultfd write-protection
227*580ea358SJohn Hubbard 	 * asynchronous mode is supported in which the write fault is
228*580ea358SJohn Hubbard 	 * automatically resolved and write-protection is un-set.
229*580ea358SJohn Hubbard 	 * It implies UFFD_FEATURE_WP_UNPOPULATED.
230*580ea358SJohn Hubbard 	 *
231*580ea358SJohn Hubbard 	 * UFFD_FEATURE_MOVE indicates that the kernel supports moving an
232*580ea358SJohn Hubbard 	 * existing page contents from userspace.
233*580ea358SJohn Hubbard 	 */
234*580ea358SJohn Hubbard #define UFFD_FEATURE_PAGEFAULT_FLAG_WP		(1<<0)
235*580ea358SJohn Hubbard #define UFFD_FEATURE_EVENT_FORK			(1<<1)
236*580ea358SJohn Hubbard #define UFFD_FEATURE_EVENT_REMAP		(1<<2)
237*580ea358SJohn Hubbard #define UFFD_FEATURE_EVENT_REMOVE		(1<<3)
238*580ea358SJohn Hubbard #define UFFD_FEATURE_MISSING_HUGETLBFS		(1<<4)
239*580ea358SJohn Hubbard #define UFFD_FEATURE_MISSING_SHMEM		(1<<5)
240*580ea358SJohn Hubbard #define UFFD_FEATURE_EVENT_UNMAP		(1<<6)
241*580ea358SJohn Hubbard #define UFFD_FEATURE_SIGBUS			(1<<7)
242*580ea358SJohn Hubbard #define UFFD_FEATURE_THREAD_ID			(1<<8)
243*580ea358SJohn Hubbard #define UFFD_FEATURE_MINOR_HUGETLBFS		(1<<9)
244*580ea358SJohn Hubbard #define UFFD_FEATURE_MINOR_SHMEM		(1<<10)
245*580ea358SJohn Hubbard #define UFFD_FEATURE_EXACT_ADDRESS		(1<<11)
246*580ea358SJohn Hubbard #define UFFD_FEATURE_WP_HUGETLBFS_SHMEM		(1<<12)
247*580ea358SJohn Hubbard #define UFFD_FEATURE_WP_UNPOPULATED		(1<<13)
248*580ea358SJohn Hubbard #define UFFD_FEATURE_POISON			(1<<14)
249*580ea358SJohn Hubbard #define UFFD_FEATURE_WP_ASYNC			(1<<15)
250*580ea358SJohn Hubbard #define UFFD_FEATURE_MOVE			(1<<16)
251*580ea358SJohn Hubbard 	__u64 features;
252*580ea358SJohn Hubbard 
253*580ea358SJohn Hubbard 	__u64 ioctls;
254*580ea358SJohn Hubbard };
255*580ea358SJohn Hubbard 
256*580ea358SJohn Hubbard struct uffdio_range {
257*580ea358SJohn Hubbard 	__u64 start;
258*580ea358SJohn Hubbard 	__u64 len;
259*580ea358SJohn Hubbard };
260*580ea358SJohn Hubbard 
261*580ea358SJohn Hubbard struct uffdio_register {
262*580ea358SJohn Hubbard 	struct uffdio_range range;
263*580ea358SJohn Hubbard #define UFFDIO_REGISTER_MODE_MISSING	((__u64)1<<0)
264*580ea358SJohn Hubbard #define UFFDIO_REGISTER_MODE_WP		((__u64)1<<1)
265*580ea358SJohn Hubbard #define UFFDIO_REGISTER_MODE_MINOR	((__u64)1<<2)
266*580ea358SJohn Hubbard 	__u64 mode;
267*580ea358SJohn Hubbard 
268*580ea358SJohn Hubbard 	/*
269*580ea358SJohn Hubbard 	 * kernel answers which ioctl commands are available for the
270*580ea358SJohn Hubbard 	 * range, keep at the end as the last 8 bytes aren't read.
271*580ea358SJohn Hubbard 	 */
272*580ea358SJohn Hubbard 	__u64 ioctls;
273*580ea358SJohn Hubbard };
274*580ea358SJohn Hubbard 
275*580ea358SJohn Hubbard struct uffdio_copy {
276*580ea358SJohn Hubbard 	__u64 dst;
277*580ea358SJohn Hubbard 	__u64 src;
278*580ea358SJohn Hubbard 	__u64 len;
279*580ea358SJohn Hubbard #define UFFDIO_COPY_MODE_DONTWAKE		((__u64)1<<0)
280*580ea358SJohn Hubbard 	/*
281*580ea358SJohn Hubbard 	 * UFFDIO_COPY_MODE_WP will map the page write protected on
282*580ea358SJohn Hubbard 	 * the fly.  UFFDIO_COPY_MODE_WP is available only if the
283*580ea358SJohn Hubbard 	 * write protected ioctl is implemented for the range
284*580ea358SJohn Hubbard 	 * according to the uffdio_register.ioctls.
285*580ea358SJohn Hubbard 	 */
286*580ea358SJohn Hubbard #define UFFDIO_COPY_MODE_WP			((__u64)1<<1)
287*580ea358SJohn Hubbard 	__u64 mode;
288*580ea358SJohn Hubbard 
289*580ea358SJohn Hubbard 	/*
290*580ea358SJohn Hubbard 	 * "copy" is written by the ioctl and must be at the end: the
291*580ea358SJohn Hubbard 	 * copy_from_user will not read the last 8 bytes.
292*580ea358SJohn Hubbard 	 */
293*580ea358SJohn Hubbard 	__s64 copy;
294*580ea358SJohn Hubbard };
295*580ea358SJohn Hubbard 
296*580ea358SJohn Hubbard struct uffdio_zeropage {
297*580ea358SJohn Hubbard 	struct uffdio_range range;
298*580ea358SJohn Hubbard #define UFFDIO_ZEROPAGE_MODE_DONTWAKE		((__u64)1<<0)
299*580ea358SJohn Hubbard 	__u64 mode;
300*580ea358SJohn Hubbard 
301*580ea358SJohn Hubbard 	/*
302*580ea358SJohn Hubbard 	 * "zeropage" is written by the ioctl and must be at the end:
303*580ea358SJohn Hubbard 	 * the copy_from_user will not read the last 8 bytes.
304*580ea358SJohn Hubbard 	 */
305*580ea358SJohn Hubbard 	__s64 zeropage;
306*580ea358SJohn Hubbard };
307*580ea358SJohn Hubbard 
308*580ea358SJohn Hubbard struct uffdio_writeprotect {
309*580ea358SJohn Hubbard 	struct uffdio_range range;
310*580ea358SJohn Hubbard /*
311*580ea358SJohn Hubbard  * UFFDIO_WRITEPROTECT_MODE_WP: set the flag to write protect a range,
312*580ea358SJohn Hubbard  * unset the flag to undo protection of a range which was previously
313*580ea358SJohn Hubbard  * write protected.
314*580ea358SJohn Hubbard  *
315*580ea358SJohn Hubbard  * UFFDIO_WRITEPROTECT_MODE_DONTWAKE: set the flag to avoid waking up
316*580ea358SJohn Hubbard  * any wait thread after the operation succeeds.
317*580ea358SJohn Hubbard  *
318*580ea358SJohn Hubbard  * NOTE: Write protecting a region (WP=1) is unrelated to page faults,
319*580ea358SJohn Hubbard  * therefore DONTWAKE flag is meaningless with WP=1.  Removing write
320*580ea358SJohn Hubbard  * protection (WP=0) in response to a page fault wakes the faulting
321*580ea358SJohn Hubbard  * task unless DONTWAKE is set.
322*580ea358SJohn Hubbard  */
323*580ea358SJohn Hubbard #define UFFDIO_WRITEPROTECT_MODE_WP		((__u64)1<<0)
324*580ea358SJohn Hubbard #define UFFDIO_WRITEPROTECT_MODE_DONTWAKE	((__u64)1<<1)
325*580ea358SJohn Hubbard 	__u64 mode;
326*580ea358SJohn Hubbard };
327*580ea358SJohn Hubbard 
328*580ea358SJohn Hubbard struct uffdio_continue {
329*580ea358SJohn Hubbard 	struct uffdio_range range;
330*580ea358SJohn Hubbard #define UFFDIO_CONTINUE_MODE_DONTWAKE		((__u64)1<<0)
331*580ea358SJohn Hubbard 	/*
332*580ea358SJohn Hubbard 	 * UFFDIO_CONTINUE_MODE_WP will map the page write protected on
333*580ea358SJohn Hubbard 	 * the fly.  UFFDIO_CONTINUE_MODE_WP is available only if the
334*580ea358SJohn Hubbard 	 * write protected ioctl is implemented for the range
335*580ea358SJohn Hubbard 	 * according to the uffdio_register.ioctls.
336*580ea358SJohn Hubbard 	 */
337*580ea358SJohn Hubbard #define UFFDIO_CONTINUE_MODE_WP			((__u64)1<<1)
338*580ea358SJohn Hubbard 	__u64 mode;
339*580ea358SJohn Hubbard 
340*580ea358SJohn Hubbard 	/*
341*580ea358SJohn Hubbard 	 * Fields below here are written by the ioctl and must be at the end:
342*580ea358SJohn Hubbard 	 * the copy_from_user will not read past here.
343*580ea358SJohn Hubbard 	 */
344*580ea358SJohn Hubbard 	__s64 mapped;
345*580ea358SJohn Hubbard };
346*580ea358SJohn Hubbard 
347*580ea358SJohn Hubbard struct uffdio_poison {
348*580ea358SJohn Hubbard 	struct uffdio_range range;
349*580ea358SJohn Hubbard #define UFFDIO_POISON_MODE_DONTWAKE		((__u64)1<<0)
350*580ea358SJohn Hubbard 	__u64 mode;
351*580ea358SJohn Hubbard 
352*580ea358SJohn Hubbard 	/*
353*580ea358SJohn Hubbard 	 * Fields below here are written by the ioctl and must be at the end:
354*580ea358SJohn Hubbard 	 * the copy_from_user will not read past here.
355*580ea358SJohn Hubbard 	 */
356*580ea358SJohn Hubbard 	__s64 updated;
357*580ea358SJohn Hubbard };
358*580ea358SJohn Hubbard 
359*580ea358SJohn Hubbard struct uffdio_move {
360*580ea358SJohn Hubbard 	__u64 dst;
361*580ea358SJohn Hubbard 	__u64 src;
362*580ea358SJohn Hubbard 	__u64 len;
363*580ea358SJohn Hubbard 	/*
364*580ea358SJohn Hubbard 	 * Especially if used to atomically remove memory from the
365*580ea358SJohn Hubbard 	 * address space the wake on the dst range is not needed.
366*580ea358SJohn Hubbard 	 */
367*580ea358SJohn Hubbard #define UFFDIO_MOVE_MODE_DONTWAKE		((__u64)1<<0)
368*580ea358SJohn Hubbard #define UFFDIO_MOVE_MODE_ALLOW_SRC_HOLES	((__u64)1<<1)
369*580ea358SJohn Hubbard 	__u64 mode;
370*580ea358SJohn Hubbard 	/*
371*580ea358SJohn Hubbard 	 * "move" is written by the ioctl and must be at the end: the
372*580ea358SJohn Hubbard 	 * copy_from_user will not read the last 8 bytes.
373*580ea358SJohn Hubbard 	 */
374*580ea358SJohn Hubbard 	__s64 move;
375*580ea358SJohn Hubbard };
376*580ea358SJohn Hubbard 
377*580ea358SJohn Hubbard /*
378*580ea358SJohn Hubbard  * Flags for the userfaultfd(2) system call itself.
379*580ea358SJohn Hubbard  */
380*580ea358SJohn Hubbard 
381*580ea358SJohn Hubbard /*
382*580ea358SJohn Hubbard  * Create a userfaultfd that can handle page faults only in user mode.
383*580ea358SJohn Hubbard  */
384*580ea358SJohn Hubbard #define UFFD_USER_MODE_ONLY 1
385*580ea358SJohn Hubbard 
386*580ea358SJohn Hubbard #endif /* _LINUX_USERFAULTFD_H */
387