Debian Codegraph @

upstream/debian-trixie/man2/UFFDIO_API.2const

raw
1 .\" Copyright 2016, IBM Corporation.
2 .\" Written by Mike Rapoport <[email protected]>
3 .\" Copyright 2016, Michael Kerrisk <[email protected]>
4 .\" Copyright 2024, Alejandro Colomar <[email protected]>
5 .\"
6 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
7 .\"
8 .TH UFFDIO_API 2const 2024-06-17 "Linux man-pages 6.9.1"
9 .SH NAME
10 UFFDIO_API
11 \-
12 enable operation of the userfaultfd and perform API handshake
13 .SH LIBRARY
14 Standard C library
15 .RI ( libc ", " \-lc )
16 .SH SYNOPSIS
17 .nf
18 .BR "#include <linux/userfaultfd.h>" " /* Definition of " UFFD* " constants */"
19 .B #include <sys/ioctl.h>
20 .P
21 .BI "int ioctl(int " fd ", UFFDIO_API, struct uffdio_api *" argp );
22 .P
23 .B #include <linux/userfaultfd.h>
24 .P
25 .fi
26 .EX
27 .B struct uffdio_api {
28 .BR " __u64 api;" " /* Requested API version (input) */"
29 .BR " __u64 features;" " /* Requested features (input/output) */"
30 .BR " __u64 ioctls;" " /* Available ioctl() operations (output) */"
31 .B };
32 .EE
33 .SH DESCRIPTION
34 Enable operation of the userfaultfd and perform API handshake.
35 .P
36 The
37 .I api
38 field denotes the API version requested by the application.
39 The kernel verifies that it can support the requested API version,
40 and sets the
41 .I features
42 and
43 .I ioctls
44 fields to bit masks representing all the available features and the generic
45 .BR ioctl (2)
46 operations available.
47 .P
48 Since Linux 4.11,
49 applications should use the
50 .I features
51 field to perform a two-step handshake.
52 First,
53 .B UFFDIO_API
54 is called with the
55 .I features
56 field set to zero.
57 The kernel responds by setting all supported feature bits.
58 .P
59 Applications which do not require any specific features
60 can begin using the userfaultfd immediately.
61 Applications which do need specific features
62 should call
63 .B UFFDIO_API
64 again with a subset of the reported feature bits set
65 to enable those features.
66 .P
67 Before Linux 4.11, the
68 .I features
69 field must be initialized to zero before the call to
70 .BR UFFDIO_API ,
71 and zero (i.e., no feature bits) is placed in the
72 .I features
73 field by the kernel upon return from
74 .BR ioctl (2).
75 .P
76 If the application sets unsupported feature bits,
77 the kernel will zero out the returned
78 .I uffdio_api
79 structure and return
80 .BR EINVAL .
81 .P
82 The following feature bits may be set:
83 .TP
84 .BR UFFD_FEATURE_EVENT_FORK " (since Linux 4.11)"
85 When this feature is enabled,
86 the userfaultfd objects associated with a parent process are duplicated
87 into the child process during
88 .BR fork (2)
89 and a
90 .B UFFD_EVENT_FORK
91 event is delivered to the userfaultfd monitor
92 .TP
93 .BR UFFD_FEATURE_EVENT_REMAP " (since Linux 4.11)"
94 If this feature is enabled,
95 when the faulting process invokes
96 .BR mremap (2),
97 the userfaultfd monitor will receive an event of type
98 .BR UFFD_EVENT_REMAP .
99 .TP
100 .BR UFFD_FEATURE_EVENT_REMOVE " (since Linux 4.11)"
101 If this feature is enabled,
102 when the faulting process calls
103 .BR madvise (2)
104 with the
105 .B MADV_DONTNEED
106 or
107 .B MADV_REMOVE
108 advice value to free a virtual memory area
109 the userfaultfd monitor will receive an event of type
110 .BR UFFD_EVENT_REMOVE .
111 .TP
112 .BR UFFD_FEATURE_EVENT_UNMAP " (since Linux 4.11)"
113 If this feature is enabled,
114 when the faulting process unmaps virtual memory either explicitly with
115 .BR munmap (2),
116 or implicitly during either
117 .BR mmap (2)
118 or
119 .BR mremap (2),
120 the userfaultfd monitor will receive an event of type
121 .BR UFFD_EVENT_UNMAP .
122 .TP
123 .BR UFFD_FEATURE_MISSING_HUGETLBFS " (since Linux 4.11)"
124 If this feature bit is set,
125 the kernel supports registering userfaultfd ranges on hugetlbfs
126 virtual memory areas
127 .TP
128 .BR UFFD_FEATURE_MISSING_SHMEM " (since Linux 4.11)"
129 If this feature bit is set,
130 the kernel supports registering userfaultfd ranges on shared memory areas.
131 This includes all kernel shared memory APIs:
132 System V shared memory,
133 .BR tmpfs (5),
134 shared mappings of
135 .IR /dev/zero ,
136 .BR mmap (2)
137 with the
138 .B MAP_SHARED
139 flag set,
140 .BR memfd_create (2),
141 and so on.
142 .TP
143 .BR UFFD_FEATURE_SIGBUS " (since Linux 4.14)"
144 .\" commit 2d6d6f5a09a96cc1fec7ed992b825e05f64cb50e
145 If this feature bit is set, no page-fault events
146 .RB ( UFFD_EVENT_PAGEFAULT )
147 will be delivered.
148 Instead, a
149 .B SIGBUS
150 signal will be sent to the faulting process.
151 Applications using this
152 feature will not require the use of a userfaultfd monitor for processing
153 memory accesses to the regions registered with userfaultfd.
154 .TP
155 .BR UFFD_FEATURE_THREAD_ID " (since Linux 4.14)"
156 If this feature bit is set,
157 .I uffd_msg.pagefault.feat.ptid
158 will be set to the faulted thread ID for each page-fault message.
159 .TP
160 .BR UFFD_FEATURE_PAGEFAULT_FLAG_WP " (since Linux 5.10)"
161 If this feature bit is set,
162 userfaultfd supports write-protect faults
163 for anonymous memory.
164 (Note that shmem / hugetlbfs support
165 is indicated by a separate feature.)
166 .TP
167 .BR UFFD_FEATURE_MINOR_HUGETLBFS " (since Linux 5.13)"
168 If this feature bit is set,
169 the kernel supports registering userfaultfd ranges
170 in minor mode on hugetlbfs-backed memory areas.
171 .TP
172 .BR UFFD_FEATURE_MINOR_SHMEM " (since Linux 5.14)"
173 If this feature bit is set,
174 the kernel supports registering userfaultfd ranges
175 in minor mode on shmem-backed memory areas.
176 .TP
177 .BR UFFD_FEATURE_EXACT_ADDRESS " (since Linux 5.18)"
178 If this feature bit is set,
179 .I uffd_msg.pagefault.address
180 will be set to the exact page-fault address that was reported by the hardware,
181 and will not mask the offset within the page.
182 Note that old Linux versions might indicate the exact address as well,
183 even though the feature bit is not set.
184 .TP
185 .BR UFFD_FEATURE_WP_HUGETLBFS_SHMEM " (since Linux 5.19)"
186 If this feature bit is set,
187 userfaultfd supports write-protect faults
188 for hugetlbfs and shmem / tmpfs memory.
189 .TP
190 .BR UFFD_FEATURE_WP_UNPOPULATED " (since Linux 6.4)"
191 If this feature bit is set,
192 the kernel will handle anonymous memory the same way as file memory,
193 by allowing the user to write-protect unpopulated page table entries.
194 .TP
195 .BR UFFD_FEATURE_POISON " (since Linux 6.6)"
196 If this feature bit is set,
197 the kernel supports resolving faults with the
198 .B UFFDIO_POISON
199 ioctl.
200 .TP
201 .BR UFFD_FEATURE_WP_ASYNC " (since Linux 6.7)"
202 If this feature bit is set,
203 the write protection faults would be asynchronously resolved
204 by the kernel.
205 .P
206 The returned
207 .I argp->ioctls
208 field can contain the following bits:
209 .\" FIXME This user-space API seems not fully polished. Why are there
210 .\" not constants defined for each of the bit-mask values listed below?
211 .TP
212 .B 1 << _UFFDIO_API
213 The
214 .B UFFDIO_API
215 operation is supported.
216 .TP
217 .B 1 << _UFFDIO_REGISTER
218 The
219 .B UFFDIO_REGISTER
220 operation is supported.
221 .TP
222 .B 1 << _UFFDIO_UNREGISTER
223 The
224 .B UFFDIO_UNREGISTER
225 operation is supported.
226 .SH RETURN VALUE
227 On success,
228 0 is returned.
229 .P
230 On error, \-1 is returned and
231 .I errno
232 is set to indicate the error.
233 .SH ERRORS
234 .TP
235 .B EFAULT
236 .I argp
237 refers to an address that is outside the calling process's
238 accessible address space.
239 .TP
240 .B EINVAL
241 The API version requested in the
242 .I api
243 field is not supported by this kernel, or the
244 .I features
245 field passed to the kernel includes feature bits that are not supported
246 by the current kernel version.
247 .TP
248 .B EINVAL
249 A previous
250 .B UFFDIO_API
251 call already enabled one or more features for this userfaultfd.
252 Calling
253 .B UFFDIO_API
254 twice,
255 the first time with no features set,
256 is explicitly allowed
257 as per the two-step feature detection handshake.
258 .TP
259 .B EPERM
260 The
261 .B UFFD_FEATURE_EVENT_FORK
262 feature was enabled,
263 but the calling process doesn't have the
264 .B CAP_SYS_PTRACE
265 capability.
266 .SH STANDARDS
267 Linux.
268 .SH HISTORY
269 Linux 4.3.
270 .SH CAVEATS
271 If an error occurs,
272 the kernel may zero the provided
273 .I uffdio_api
274 structure.
275 The caller should treat its contents as unspecified,
276 and reinitialize it before re-attempting another
277 .B UFFDIO_API
278 call.
279 .SH BUGS
280 In order to detect available userfault features and
281 enable some subset of those features
282 the userfaultfd file descriptor must be closed after the first
283 .B UFFDIO_API
284 operation that queries features availability and reopened before
285 the second
286 .B UFFDIO_API
287 operation that actually enables the desired features.
288 .SH EXAMPLES
289 See
290 .BR userfaultfd (2).
291 .SH SEE ALSO
292 .BR ioctl (2),
293 .BR ioctl_userfaultfd (2),
294 .BR mmap (2),
295 .BR userfaultfd (2)
296 .P
297 .I linux.git/\:Documentation/\:admin\-guide/\:mm/\:userfaultfd.rst