blob: df0e09bb7dd5a20f068b6b2a916d6a33a3ccf5ef [file] [log] [blame]
Andrea Arcangeli10386282015-09-04 15:46:04 -07001/*
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
Andrea Arcangelia9b85f92015-09-04 15:46:37 -070014#include <linux/compiler.h>
15
Andrea Arcangeli10386282015-09-04 15:46:04 -070016#define UFFD_API ((__u64)0xAA)
Andrea Arcangelia9b85f92015-09-04 15:46:37 -070017/*
18 * After implementing the respective features it will become:
19 * #define UFFD_API_FEATURES (UFFD_FEATURE_PAGEFAULT_FLAG_WP | \
20 * UFFD_FEATURE_EVENT_FORK)
21 */
22#define UFFD_API_FEATURES (0)
Andrea Arcangeli10386282015-09-04 15:46:04 -070023#define UFFD_API_IOCTLS \
24 ((__u64)1 << _UFFDIO_REGISTER | \
25 (__u64)1 << _UFFDIO_UNREGISTER | \
26 (__u64)1 << _UFFDIO_API)
27#define UFFD_API_RANGE_IOCTLS \
Andrea Arcangeli1f1c6f02015-09-04 15:47:01 -070028 ((__u64)1 << _UFFDIO_WAKE | \
29 (__u64)1 << _UFFDIO_COPY | \
30 (__u64)1 << _UFFDIO_ZEROPAGE)
Andrea Arcangeli10386282015-09-04 15:46:04 -070031
32/*
33 * Valid ioctl command number range with this API is from 0x00 to
34 * 0x3F. UFFDIO_API is the fixed number, everything else can be
35 * changed by implementing a different UFFD_API. If sticking to the
36 * same UFFD_API more ioctl can be added and userland will be aware of
37 * which ioctl the running kernel implements through the ioctl command
38 * bitmask written by the UFFDIO_API.
39 */
40#define _UFFDIO_REGISTER (0x00)
41#define _UFFDIO_UNREGISTER (0x01)
42#define _UFFDIO_WAKE (0x02)
Andrea Arcangeli1f1c6f02015-09-04 15:47:01 -070043#define _UFFDIO_COPY (0x03)
44#define _UFFDIO_ZEROPAGE (0x04)
Andrea Arcangeli10386282015-09-04 15:46:04 -070045#define _UFFDIO_API (0x3F)
46
47/* userfaultfd ioctl ids */
48#define UFFDIO 0xAA
49#define UFFDIO_API _IOWR(UFFDIO, _UFFDIO_API, \
50 struct uffdio_api)
51#define UFFDIO_REGISTER _IOWR(UFFDIO, _UFFDIO_REGISTER, \
52 struct uffdio_register)
53#define UFFDIO_UNREGISTER _IOR(UFFDIO, _UFFDIO_UNREGISTER, \
54 struct uffdio_range)
55#define UFFDIO_WAKE _IOR(UFFDIO, _UFFDIO_WAKE, \
56 struct uffdio_range)
Andrea Arcangeli1f1c6f02015-09-04 15:47:01 -070057#define UFFDIO_COPY _IOWR(UFFDIO, _UFFDIO_COPY, \
58 struct uffdio_copy)
59#define UFFDIO_ZEROPAGE _IOWR(UFFDIO, _UFFDIO_ZEROPAGE, \
60 struct uffdio_zeropage)
Andrea Arcangeli10386282015-09-04 15:46:04 -070061
Andrea Arcangelia9b85f92015-09-04 15:46:37 -070062/* read() structure */
63struct uffd_msg {
64 __u8 event;
65
66 __u8 reserved1;
67 __u16 reserved2;
68 __u32 reserved3;
69
70 union {
71 struct {
72 __u64 flags;
73 __u64 address;
74 } pagefault;
75
76 struct {
77 /* unused reserved fields */
78 __u64 reserved1;
79 __u64 reserved2;
80 __u64 reserved3;
81 } reserved;
82 } arg;
83} __packed;
Andrea Arcangeli10386282015-09-04 15:46:04 -070084
Pavel Emelyanov3f602d22015-09-04 15:46:34 -070085/*
Andrea Arcangelia9b85f92015-09-04 15:46:37 -070086 * Start at 0x12 and not at 0 to be more strict against bugs.
Pavel Emelyanov3f602d22015-09-04 15:46:34 -070087 */
Andrea Arcangelia9b85f92015-09-04 15:46:37 -070088#define UFFD_EVENT_PAGEFAULT 0x12
89#if 0 /* not available yet */
90#define UFFD_EVENT_FORK 0x13
91#endif
92
93/* flags for UFFD_EVENT_PAGEFAULT */
94#define UFFD_PAGEFAULT_FLAG_WRITE (1<<0) /* If this was a write fault */
95#define UFFD_PAGEFAULT_FLAG_WP (1<<1) /* If reason is VM_UFFD_WP */
Pavel Emelyanov3f602d22015-09-04 15:46:34 -070096
Andrea Arcangeli10386282015-09-04 15:46:04 -070097struct uffdio_api {
Andrea Arcangelia9b85f92015-09-04 15:46:37 -070098 /* userland asks for an API number and the features to enable */
Andrea Arcangeli10386282015-09-04 15:46:04 -070099 __u64 api;
Andrea Arcangelia9b85f92015-09-04 15:46:37 -0700100 /*
101 * Kernel answers below with the all available features for
102 * the API, this notifies userland of which events and/or
103 * which flags for each event are enabled in the current
104 * kernel.
105 *
106 * Note: UFFD_EVENT_PAGEFAULT and UFFD_PAGEFAULT_FLAG_WRITE
107 * are to be considered implicitly always enabled in all kernels as
108 * long as the uffdio_api.api requested matches UFFD_API.
109 */
110#if 0 /* not available yet */
111#define UFFD_FEATURE_PAGEFAULT_FLAG_WP (1<<0)
112#define UFFD_FEATURE_EVENT_FORK (1<<1)
113#endif
Pavel Emelyanov3f602d22015-09-04 15:46:34 -0700114 __u64 features;
Andrea Arcangelia9b85f92015-09-04 15:46:37 -0700115
Andrea Arcangeli10386282015-09-04 15:46:04 -0700116 __u64 ioctls;
117};
118
119struct uffdio_range {
120 __u64 start;
121 __u64 len;
122};
123
124struct uffdio_register {
125 struct uffdio_range range;
126#define UFFDIO_REGISTER_MODE_MISSING ((__u64)1<<0)
127#define UFFDIO_REGISTER_MODE_WP ((__u64)1<<1)
128 __u64 mode;
129
130 /*
131 * kernel answers which ioctl commands are available for the
132 * range, keep at the end as the last 8 bytes aren't read.
133 */
134 __u64 ioctls;
135};
136
Andrea Arcangeli1f1c6f02015-09-04 15:47:01 -0700137struct uffdio_copy {
138 __u64 dst;
139 __u64 src;
140 __u64 len;
141 /*
142 * There will be a wrprotection flag later that allows to map
143 * pages wrprotected on the fly. And such a flag will be
144 * available if the wrprotection ioctl are implemented for the
145 * range according to the uffdio_register.ioctls.
146 */
147#define UFFDIO_COPY_MODE_DONTWAKE ((__u64)1<<0)
148 __u64 mode;
149
150 /*
151 * "copy" is written by the ioctl and must be at the end: the
152 * copy_from_user will not read the last 8 bytes.
153 */
154 __s64 copy;
155};
156
157struct uffdio_zeropage {
158 struct uffdio_range range;
159#define UFFDIO_ZEROPAGE_MODE_DONTWAKE ((__u64)1<<0)
160 __u64 mode;
161
162 /*
163 * "zeropage" is written by the ioctl and must be at the end:
164 * the copy_from_user will not read the last 8 bytes.
165 */
166 __s64 zeropage;
167};
168
Andrea Arcangeli10386282015-09-04 15:46:04 -0700169#endif /* _LINUX_USERFAULTFD_H */