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