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