xref: /openbmc/linux/include/uapi/linux/io_uring.h (revision 4df933252827af69cb087e3df1294e4945a6f6c6)
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 /*
3  * Header file for the io_uring interface.
4  *
5  * Copyright (C) 2019 Jens Axboe
6  * Copyright (C) 2019 Christoph Hellwig
7  */
8 #ifndef LINUX_IO_URING_H
9 #define LINUX_IO_URING_H
10 
11 #include <linux/fs.h>
12 #include <linux/types.h>
13 
14 /*
15  * IO submission data structure (Submission Queue Entry)
16  */
17 struct io_uring_sqe {
18 	__u8	opcode;		/* type of operation for this sqe */
19 	__u8	flags;		/* IOSQE_ flags */
20 	__u16	ioprio;		/* ioprio for the request */
21 	__s32	fd;		/* file descriptor to do IO on */
22 	union {
23 		__u64	off;	/* offset into file */
24 		__u64	addr2;
25 	};
26 	__u64	addr;		/* pointer to buffer or iovecs */
27 	__u32	len;		/* buffer size or number of iovecs */
28 	union {
29 		__kernel_rwf_t	rw_flags;
30 		__u32		fsync_flags;
31 		__u16		poll_events;
32 		__u32		sync_range_flags;
33 		__u32		msg_flags;
34 		__u32		timeout_flags;
35 		__u32		accept_flags;
36 		__u32		cancel_flags;
37 		__u32		open_flags;
38 		__u32		statx_flags;
39 		__u32		fadvise_advice;
40 	};
41 	__u64	user_data;	/* data to be passed back at completion time */
42 	union {
43 		struct {
44 			/* index into fixed buffers, if used */
45 			__u16	buf_index;
46 			/* personality to use, if used */
47 			__u16	personality;
48 		};
49 		__u64	__pad2[3];
50 	};
51 };
52 
53 enum {
54 	IOSQE_FIXED_FILE_BIT,
55 	IOSQE_IO_DRAIN_BIT,
56 	IOSQE_IO_LINK_BIT,
57 	IOSQE_IO_HARDLINK_BIT,
58 	IOSQE_ASYNC_BIT,
59 };
60 
61 /*
62  * sqe->flags
63  */
64 /* use fixed fileset */
65 #define IOSQE_FIXED_FILE	(1U << IOSQE_FIXED_FILE_BIT)
66 /* issue after inflight IO */
67 #define IOSQE_IO_DRAIN		(1U << IOSQE_IO_DRAIN_BIT)
68 /* links next sqe */
69 #define IOSQE_IO_LINK		(1U << IOSQE_IO_LINK_BIT)
70 /* like LINK, but stronger */
71 #define IOSQE_IO_HARDLINK	(1U << IOSQE_IO_HARDLINK_BIT)
72 /* always go async */
73 #define IOSQE_ASYNC		(1U << IOSQE_ASYNC_BIT)
74 
75 /*
76  * io_uring_setup() flags
77  */
78 #define IORING_SETUP_IOPOLL	(1U << 0)	/* io_context is polled */
79 #define IORING_SETUP_SQPOLL	(1U << 1)	/* SQ poll thread */
80 #define IORING_SETUP_SQ_AFF	(1U << 2)	/* sq_thread_cpu is valid */
81 #define IORING_SETUP_CQSIZE	(1U << 3)	/* app defines CQ size */
82 #define IORING_SETUP_CLAMP	(1U << 4)	/* clamp SQ/CQ ring sizes */
83 #define IORING_SETUP_ATTACH_WQ	(1U << 5)	/* attach to existing wq */
84 
85 enum {
86 	IORING_OP_NOP,
87 	IORING_OP_READV,
88 	IORING_OP_WRITEV,
89 	IORING_OP_FSYNC,
90 	IORING_OP_READ_FIXED,
91 	IORING_OP_WRITE_FIXED,
92 	IORING_OP_POLL_ADD,
93 	IORING_OP_POLL_REMOVE,
94 	IORING_OP_SYNC_FILE_RANGE,
95 	IORING_OP_SENDMSG,
96 	IORING_OP_RECVMSG,
97 	IORING_OP_TIMEOUT,
98 	IORING_OP_TIMEOUT_REMOVE,
99 	IORING_OP_ACCEPT,
100 	IORING_OP_ASYNC_CANCEL,
101 	IORING_OP_LINK_TIMEOUT,
102 	IORING_OP_CONNECT,
103 	IORING_OP_FALLOCATE,
104 	IORING_OP_OPENAT,
105 	IORING_OP_CLOSE,
106 	IORING_OP_FILES_UPDATE,
107 	IORING_OP_STATX,
108 	IORING_OP_READ,
109 	IORING_OP_WRITE,
110 	IORING_OP_FADVISE,
111 	IORING_OP_MADVISE,
112 	IORING_OP_SEND,
113 	IORING_OP_RECV,
114 	IORING_OP_OPENAT2,
115 	IORING_OP_EPOLL_CTL,
116 
117 	/* this goes last, obviously */
118 	IORING_OP_LAST,
119 };
120 
121 /*
122  * sqe->fsync_flags
123  */
124 #define IORING_FSYNC_DATASYNC	(1U << 0)
125 
126 /*
127  * sqe->timeout_flags
128  */
129 #define IORING_TIMEOUT_ABS	(1U << 0)
130 
131 /*
132  * IO completion data structure (Completion Queue Entry)
133  */
134 struct io_uring_cqe {
135 	__u64	user_data;	/* sqe->data submission passed back */
136 	__s32	res;		/* result code for this event */
137 	__u32	flags;
138 };
139 
140 /*
141  * Magic offsets for the application to mmap the data it needs
142  */
143 #define IORING_OFF_SQ_RING		0ULL
144 #define IORING_OFF_CQ_RING		0x8000000ULL
145 #define IORING_OFF_SQES			0x10000000ULL
146 
147 /*
148  * Filled with the offset for mmap(2)
149  */
150 struct io_sqring_offsets {
151 	__u32 head;
152 	__u32 tail;
153 	__u32 ring_mask;
154 	__u32 ring_entries;
155 	__u32 flags;
156 	__u32 dropped;
157 	__u32 array;
158 	__u32 resv1;
159 	__u64 resv2;
160 };
161 
162 /*
163  * sq_ring->flags
164  */
165 #define IORING_SQ_NEED_WAKEUP	(1U << 0) /* needs io_uring_enter wakeup */
166 
167 struct io_cqring_offsets {
168 	__u32 head;
169 	__u32 tail;
170 	__u32 ring_mask;
171 	__u32 ring_entries;
172 	__u32 overflow;
173 	__u32 cqes;
174 	__u64 resv[2];
175 };
176 
177 /*
178  * io_uring_enter(2) flags
179  */
180 #define IORING_ENTER_GETEVENTS	(1U << 0)
181 #define IORING_ENTER_SQ_WAKEUP	(1U << 1)
182 
183 /*
184  * Passed in for io_uring_setup(2). Copied back with updated info on success
185  */
186 struct io_uring_params {
187 	__u32 sq_entries;
188 	__u32 cq_entries;
189 	__u32 flags;
190 	__u32 sq_thread_cpu;
191 	__u32 sq_thread_idle;
192 	__u32 features;
193 	__u32 wq_fd;
194 	__u32 resv[3];
195 	struct io_sqring_offsets sq_off;
196 	struct io_cqring_offsets cq_off;
197 };
198 
199 /*
200  * io_uring_params->features flags
201  */
202 #define IORING_FEAT_SINGLE_MMAP		(1U << 0)
203 #define IORING_FEAT_NODROP		(1U << 1)
204 #define IORING_FEAT_SUBMIT_STABLE	(1U << 2)
205 #define IORING_FEAT_RW_CUR_POS		(1U << 3)
206 #define IORING_FEAT_CUR_PERSONALITY	(1U << 4)
207 
208 /*
209  * io_uring_register(2) opcodes and arguments
210  */
211 #define IORING_REGISTER_BUFFERS		0
212 #define IORING_UNREGISTER_BUFFERS	1
213 #define IORING_REGISTER_FILES		2
214 #define IORING_UNREGISTER_FILES		3
215 #define IORING_REGISTER_EVENTFD		4
216 #define IORING_UNREGISTER_EVENTFD	5
217 #define IORING_REGISTER_FILES_UPDATE	6
218 #define IORING_REGISTER_EVENTFD_ASYNC	7
219 #define IORING_REGISTER_PROBE		8
220 #define IORING_REGISTER_PERSONALITY	9
221 #define IORING_UNREGISTER_PERSONALITY	10
222 
223 struct io_uring_files_update {
224 	__u32 offset;
225 	__u32 resv;
226 	__aligned_u64 /* __s32 * */ fds;
227 };
228 
229 #define IO_URING_OP_SUPPORTED	(1U << 0)
230 
231 struct io_uring_probe_op {
232 	__u8 op;
233 	__u8 resv;
234 	__u16 flags;	/* IO_URING_OP_* flags */
235 	__u32 resv2;
236 };
237 
238 struct io_uring_probe {
239 	__u8 last_op;	/* last opcode supported */
240 	__u8 ops_len;	/* length of ops[] array below */
241 	__u16 resv;
242 	__u32 resv2[3];
243 	struct io_uring_probe_op ops[0];
244 };
245 
246 #endif
247