userfaultfd: hugetlbfs: allow registration of ranges containing huge pages
[linux-2.6-microblaze.git] / include / uapi / linux / userfaultfd.h
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
9 #ifndef _LINUX_USERFAULTFD_H
10 #define _LINUX_USERFAULTFD_H
11
12 #include <linux/types.h>
13
14 /*
15  * If the UFFDIO_API is upgraded someday, the UFFDIO_UNREGISTER and
16  * UFFDIO_WAKE ioctls should be defined as _IOW and not as _IOR.  In
17  * userfaultfd.h we assumed the kernel was reading (instead _IOC_READ
18  * means the userland is reading).
19  */
20 #define UFFD_API ((__u64)0xAA)
21 #define UFFD_API_FEATURES (UFFD_FEATURE_EVENT_FORK |        \
22                            UFFD_FEATURE_EVENT_REMAP |       \
23                            UFFD_FEATURE_EVENT_MADVDONTNEED)
24 #define UFFD_API_IOCTLS                         \
25         ((__u64)1 << _UFFDIO_REGISTER |         \
26          (__u64)1 << _UFFDIO_UNREGISTER |       \
27          (__u64)1 << _UFFDIO_API)
28 #define UFFD_API_RANGE_IOCTLS                   \
29         ((__u64)1 << _UFFDIO_WAKE |             \
30          (__u64)1 << _UFFDIO_COPY |             \
31          (__u64)1 << _UFFDIO_ZEROPAGE)
32 #define UFFD_API_RANGE_IOCTLS_HPAGE             \
33         ((__u64)1 << _UFFDIO_WAKE |             \
34          (__u64)1 << _UFFDIO_COPY)
35
36 /*
37  * Valid ioctl command number range with this API is from 0x00 to
38  * 0x3F.  UFFDIO_API is the fixed number, everything else can be
39  * changed by implementing a different UFFD_API. If sticking to the
40  * same UFFD_API more ioctl can be added and userland will be aware of
41  * which ioctl the running kernel implements through the ioctl command
42  * bitmask written by the UFFDIO_API.
43  */
44 #define _UFFDIO_REGISTER                (0x00)
45 #define _UFFDIO_UNREGISTER              (0x01)
46 #define _UFFDIO_WAKE                    (0x02)
47 #define _UFFDIO_COPY                    (0x03)
48 #define _UFFDIO_ZEROPAGE                (0x04)
49 #define _UFFDIO_API                     (0x3F)
50
51 /* userfaultfd ioctl ids */
52 #define UFFDIO 0xAA
53 #define UFFDIO_API              _IOWR(UFFDIO, _UFFDIO_API,      \
54                                       struct uffdio_api)
55 #define UFFDIO_REGISTER         _IOWR(UFFDIO, _UFFDIO_REGISTER, \
56                                       struct uffdio_register)
57 #define UFFDIO_UNREGISTER       _IOR(UFFDIO, _UFFDIO_UNREGISTER,        \
58                                      struct uffdio_range)
59 #define UFFDIO_WAKE             _IOR(UFFDIO, _UFFDIO_WAKE,      \
60                                      struct uffdio_range)
61 #define UFFDIO_COPY             _IOWR(UFFDIO, _UFFDIO_COPY,     \
62                                       struct uffdio_copy)
63 #define UFFDIO_ZEROPAGE         _IOWR(UFFDIO, _UFFDIO_ZEROPAGE, \
64                                       struct uffdio_zeropage)
65
66 /* read() structure */
67 struct uffd_msg {
68         __u8    event;
69
70         __u8    reserved1;
71         __u16   reserved2;
72         __u32   reserved3;
73
74         union {
75                 struct {
76                         __u64   flags;
77                         __u64   address;
78                 } pagefault;
79
80                 struct {
81                         __u32   ufd;
82                 } fork;
83
84                 struct {
85                         __u64   from;
86                         __u64   to;
87                         __u64   len;
88                 } remap;
89
90                 struct {
91                         __u64   start;
92                         __u64   end;
93                 } madv_dn;
94
95                 struct {
96                         /* unused reserved fields */
97                         __u64   reserved1;
98                         __u64   reserved2;
99                         __u64   reserved3;
100                 } reserved;
101         } arg;
102 } __packed;
103
104 /*
105  * Start at 0x12 and not at 0 to be more strict against bugs.
106  */
107 #define UFFD_EVENT_PAGEFAULT    0x12
108 #define UFFD_EVENT_FORK         0x13
109 #define UFFD_EVENT_REMAP        0x14
110 #define UFFD_EVENT_MADVDONTNEED 0x15
111
112 /* flags for UFFD_EVENT_PAGEFAULT */
113 #define UFFD_PAGEFAULT_FLAG_WRITE       (1<<0)  /* If this was a write fault */
114 #define UFFD_PAGEFAULT_FLAG_WP          (1<<1)  /* If reason is VM_UFFD_WP */
115
116 struct uffdio_api {
117         /* userland asks for an API number and the features to enable */
118         __u64 api;
119         /*
120          * Kernel answers below with the all available features for
121          * the API, this notifies userland of which events and/or
122          * which flags for each event are enabled in the current
123          * kernel.
124          *
125          * Note: UFFD_EVENT_PAGEFAULT and UFFD_PAGEFAULT_FLAG_WRITE
126          * are to be considered implicitly always enabled in all kernels as
127          * long as the uffdio_api.api requested matches UFFD_API.
128          */
129 #define UFFD_FEATURE_PAGEFAULT_FLAG_WP          (1<<0)
130 #define UFFD_FEATURE_EVENT_FORK                 (1<<1)
131 #define UFFD_FEATURE_EVENT_REMAP                (1<<2)
132 #define UFFD_FEATURE_EVENT_MADVDONTNEED         (1<<3)
133         __u64 features;
134
135         __u64 ioctls;
136 };
137
138 struct uffdio_range {
139         __u64 start;
140         __u64 len;
141 };
142
143 struct uffdio_register {
144         struct uffdio_range range;
145 #define UFFDIO_REGISTER_MODE_MISSING    ((__u64)1<<0)
146 #define UFFDIO_REGISTER_MODE_WP         ((__u64)1<<1)
147         __u64 mode;
148
149         /*
150          * kernel answers which ioctl commands are available for the
151          * range, keep at the end as the last 8 bytes aren't read.
152          */
153         __u64 ioctls;
154 };
155
156 struct uffdio_copy {
157         __u64 dst;
158         __u64 src;
159         __u64 len;
160         /*
161          * There will be a wrprotection flag later that allows to map
162          * pages wrprotected on the fly. And such a flag will be
163          * available if the wrprotection ioctl are implemented for the
164          * range according to the uffdio_register.ioctls.
165          */
166 #define UFFDIO_COPY_MODE_DONTWAKE               ((__u64)1<<0)
167         __u64 mode;
168
169         /*
170          * "copy" is written by the ioctl and must be at the end: the
171          * copy_from_user will not read the last 8 bytes.
172          */
173         __s64 copy;
174 };
175
176 struct uffdio_zeropage {
177         struct uffdio_range range;
178 #define UFFDIO_ZEROPAGE_MODE_DONTWAKE           ((__u64)1<<0)
179         __u64 mode;
180
181         /*
182          * "zeropage" is written by the ioctl and must be at the end:
183          * the copy_from_user will not read the last 8 bytes.
184          */
185         __s64 zeropage;
186 };
187
188 #endif /* _LINUX_USERFAULTFD_H */