logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

userfaultfd.h (12017B)


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