userfaultfd.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * include/linux/userfaultfd.h
  3. *
  4. * Copyright (C) 2007 Davide Libenzi <davidel@xmailserver.org>
  5. * Copyright (C) 2015 Red Hat, Inc.
  6. *
  7. */
  8. #ifndef _LINUX_USERFAULTFD_H
  9. #define _LINUX_USERFAULTFD_H
  10. #include <linux/types.h>
  11. #define UFFD_API ((__u64)0xAA)
  12. /*
  13. * After implementing the respective features it will become:
  14. * #define UFFD_API_FEATURES (UFFD_FEATURE_PAGEFAULT_FLAG_WP | \
  15. * UFFD_FEATURE_EVENT_FORK)
  16. */
  17. #define UFFD_API_FEATURES (0)
  18. #define UFFD_API_IOCTLS \
  19. ((__u64)1 << _UFFDIO_REGISTER | \
  20. (__u64)1 << _UFFDIO_UNREGISTER | \
  21. (__u64)1 << _UFFDIO_API)
  22. #define UFFD_API_RANGE_IOCTLS \
  23. ((__u64)1 << _UFFDIO_WAKE | \
  24. (__u64)1 << _UFFDIO_COPY | \
  25. (__u64)1 << _UFFDIO_ZEROPAGE)
  26. /*
  27. * Valid ioctl command number range with this API is from 0x00 to
  28. * 0x3F. UFFDIO_API is the fixed number, everything else can be
  29. * changed by implementing a different UFFD_API. If sticking to the
  30. * same UFFD_API more ioctl can be added and userland will be aware of
  31. * which ioctl the running kernel implements through the ioctl command
  32. * bitmask written by the UFFDIO_API.
  33. */
  34. #define _UFFDIO_REGISTER (0x00)
  35. #define _UFFDIO_UNREGISTER (0x01)
  36. #define _UFFDIO_WAKE (0x02)
  37. #define _UFFDIO_COPY (0x03)
  38. #define _UFFDIO_ZEROPAGE (0x04)
  39. #define _UFFDIO_API (0x3F)
  40. /* userfaultfd ioctl ids */
  41. #define UFFDIO 0xAA
  42. #define UFFDIO_API _IOWR(UFFDIO, _UFFDIO_API, \
  43. struct uffdio_api)
  44. #define UFFDIO_REGISTER _IOWR(UFFDIO, _UFFDIO_REGISTER, \
  45. struct uffdio_register)
  46. #define UFFDIO_UNREGISTER _IOR(UFFDIO, _UFFDIO_UNREGISTER, \
  47. struct uffdio_range)
  48. #define UFFDIO_WAKE _IOR(UFFDIO, _UFFDIO_WAKE, \
  49. struct uffdio_range)
  50. #define UFFDIO_COPY _IOWR(UFFDIO, _UFFDIO_COPY, \
  51. struct uffdio_copy)
  52. #define UFFDIO_ZEROPAGE _IOWR(UFFDIO, _UFFDIO_ZEROPAGE, \
  53. struct uffdio_zeropage)
  54. /* read() structure */
  55. struct uffd_msg {
  56. __u8 event;
  57. __u8 reserved1;
  58. __u16 reserved2;
  59. __u32 reserved3;
  60. union {
  61. struct {
  62. __u64 flags;
  63. __u64 address;
  64. } pagefault;
  65. struct {
  66. /* unused reserved fields */
  67. __u64 reserved1;
  68. __u64 reserved2;
  69. __u64 reserved3;
  70. } reserved;
  71. } arg;
  72. } __packed;
  73. /*
  74. * Start at 0x12 and not at 0 to be more strict against bugs.
  75. */
  76. #define UFFD_EVENT_PAGEFAULT 0x12
  77. #if 0 /* not available yet */
  78. #define UFFD_EVENT_FORK 0x13
  79. #endif
  80. /* flags for UFFD_EVENT_PAGEFAULT */
  81. #define UFFD_PAGEFAULT_FLAG_WRITE (1<<0) /* If this was a write fault */
  82. #define UFFD_PAGEFAULT_FLAG_WP (1<<1) /* If reason is VM_UFFD_WP */
  83. struct uffdio_api {
  84. /* userland asks for an API number and the features to enable */
  85. __u64 api;
  86. /*
  87. * Kernel answers below with the all available features for
  88. * the API, this notifies userland of which events and/or
  89. * which flags for each event are enabled in the current
  90. * kernel.
  91. *
  92. * Note: UFFD_EVENT_PAGEFAULT and UFFD_PAGEFAULT_FLAG_WRITE
  93. * are to be considered implicitly always enabled in all kernels as
  94. * long as the uffdio_api.api requested matches UFFD_API.
  95. */
  96. #if 0 /* not available yet */
  97. #define UFFD_FEATURE_PAGEFAULT_FLAG_WP (1<<0)
  98. #define UFFD_FEATURE_EVENT_FORK (1<<1)
  99. #endif
  100. __u64 features;
  101. __u64 ioctls;
  102. };
  103. struct uffdio_range {
  104. __u64 start;
  105. __u64 len;
  106. };
  107. struct uffdio_register {
  108. struct uffdio_range range;
  109. #define UFFDIO_REGISTER_MODE_MISSING ((__u64)1<<0)
  110. #define UFFDIO_REGISTER_MODE_WP ((__u64)1<<1)
  111. __u64 mode;
  112. /*
  113. * kernel answers which ioctl commands are available for the
  114. * range, keep at the end as the last 8 bytes aren't read.
  115. */
  116. __u64 ioctls;
  117. };
  118. struct uffdio_copy {
  119. __u64 dst;
  120. __u64 src;
  121. __u64 len;
  122. /*
  123. * There will be a wrprotection flag later that allows to map
  124. * pages wrprotected on the fly. And such a flag will be
  125. * available if the wrprotection ioctl are implemented for the
  126. * range according to the uffdio_register.ioctls.
  127. */
  128. #define UFFDIO_COPY_MODE_DONTWAKE ((__u64)1<<0)
  129. __u64 mode;
  130. /*
  131. * "copy" is written by the ioctl and must be at the end: the
  132. * copy_from_user will not read the last 8 bytes.
  133. */
  134. __s64 copy;
  135. };
  136. struct uffdio_zeropage {
  137. struct uffdio_range range;
  138. #define UFFDIO_ZEROPAGE_MODE_DONTWAKE ((__u64)1<<0)
  139. __u64 mode;
  140. /*
  141. * "zeropage" is written by the ioctl and must be at the end:
  142. * the copy_from_user will not read the last 8 bytes.
  143. */
  144. __s64 zeropage;
  145. };
  146. #endif /* _LINUX_USERFAULTFD_H */