Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: (GPL-2.0 WITH Linux-syscall-note) OR MIT */
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 * this file is shared with liburing and that has to autodetect
15 * if linux/time_types.h is available or not, it can
16 * define UAPI_LINUX_IO_URING_H_SKIP_LINUX_TIME_TYPES_H
17 * if linux/time_types.h is not available
18 */
19#ifndef UAPI_LINUX_IO_URING_H_SKIP_LINUX_TIME_TYPES_H
20#include <linux/time_types.h>
21#endif
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27/*
28 * IO submission data structure (Submission Queue Entry)
29 */
30struct io_uring_sqe {
31 __u8 opcode; /* type of operation for this sqe */
32 __u8 flags; /* IOSQE_ flags */
33 __u16 ioprio; /* ioprio for the request */
34 __s32 fd; /* file descriptor to do IO on */
35 union {
36 __u64 off; /* offset into file */
37 __u64 addr2;
38 struct {
39 __u32 cmd_op;
40 __u32 __pad1;
41 };
42 };
43 union {
44 __u64 addr; /* pointer to buffer or iovecs */
45 __u64 splice_off_in;
46 struct {
47 __u32 level;
48 __u32 optname;
49 };
50 };
51 __u32 len; /* buffer size or number of iovecs */
52 union {
53 __u32 rw_flags;
54 __u32 fsync_flags;
55 __u16 poll_events; /* compatibility */
56 __u32 poll32_events; /* word-reversed for BE */
57 __u32 sync_range_flags;
58 __u32 msg_flags;
59 __u32 timeout_flags;
60 __u32 accept_flags;
61 __u32 cancel_flags;
62 __u32 open_flags;
63 __u32 statx_flags;
64 __u32 fadvise_advice;
65 __u32 splice_flags;
66 __u32 rename_flags;
67 __u32 unlink_flags;
68 __u32 hardlink_flags;
69 __u32 xattr_flags;
70 __u32 msg_ring_flags;
71 __u32 uring_cmd_flags;
72 __u32 waitid_flags;
73 __u32 futex_flags;
74 __u32 install_fd_flags;
75 __u32 nop_flags;
76 __u32 pipe_flags;
77 };
78 __u64 user_data; /* data to be passed back at completion time */
79 /* pack this to avoid bogus arm OABI complaints */
80 union {
81 /* index into fixed buffers, if used */
82 __u16 buf_index;
83 /* for grouped buffer selection */
84 __u16 buf_group;
85 } __attribute__((packed));
86 /* personality to use, if used */
87 __u16 personality;
88 union {
89 __s32 splice_fd_in;
90 __u32 file_index;
91 __u32 zcrx_ifq_idx;
92 __u32 optlen;
93 struct {
94 __u16 addr_len;
95 __u16 __pad3[1];
96 };
97 struct {
98 __u8 write_stream;
99 __u8 __pad4[3];
100 };
101 };
102 union {
103 struct {
104 __u64 addr3;
105 __u64 __pad2[1];
106 };
107 struct {
108 __u64 attr_ptr; /* pointer to attribute information */
109 __u64 attr_type_mask; /* bit mask of attributes */
110 };
111 __u64 optval;
112 /*
113 * If the ring is initialized with IORING_SETUP_SQE128, then
114 * this field is used for 80 bytes of arbitrary command data
115 */
116 __u8 cmd[0];
117 };
118};
119
120/* sqe->attr_type_mask flags */
121#define IORING_RW_ATTR_FLAG_PI (1U << 0)
122/* PI attribute information */
123struct io_uring_attr_pi {
124 __u16 flags;
125 __u16 app_tag;
126 __u32 len;
127 __u64 addr;
128 __u64 seed;
129 __u64 rsvd;
130};
131
132/*
133 * If sqe->file_index is set to this for opcodes that instantiate a new
134 * direct descriptor (like openat/openat2/accept), then io_uring will allocate
135 * an available direct descriptor instead of having the application pass one
136 * in. The picked direct descriptor will be returned in cqe->res, or -ENFILE
137 * if the space is full.
138 */
139#define IORING_FILE_INDEX_ALLOC (~0U)
140
141enum io_uring_sqe_flags_bit {
142 IOSQE_FIXED_FILE_BIT,
143 IOSQE_IO_DRAIN_BIT,
144 IOSQE_IO_LINK_BIT,
145 IOSQE_IO_HARDLINK_BIT,
146 IOSQE_ASYNC_BIT,
147 IOSQE_BUFFER_SELECT_BIT,
148 IOSQE_CQE_SKIP_SUCCESS_BIT,
149};
150
151/*
152 * sqe->flags
153 */
154/* use fixed fileset */
155#define IOSQE_FIXED_FILE (1U << IOSQE_FIXED_FILE_BIT)
156/* issue after inflight IO */
157#define IOSQE_IO_DRAIN (1U << IOSQE_IO_DRAIN_BIT)
158/* links next sqe */
159#define IOSQE_IO_LINK (1U << IOSQE_IO_LINK_BIT)
160/* like LINK, but stronger */
161#define IOSQE_IO_HARDLINK (1U << IOSQE_IO_HARDLINK_BIT)
162/* always go async */
163#define IOSQE_ASYNC (1U << IOSQE_ASYNC_BIT)
164/* select buffer from sqe->buf_group */
165#define IOSQE_BUFFER_SELECT (1U << IOSQE_BUFFER_SELECT_BIT)
166/* don't post CQE if request succeeded */
167#define IOSQE_CQE_SKIP_SUCCESS (1U << IOSQE_CQE_SKIP_SUCCESS_BIT)
168
169/*
170 * io_uring_setup() flags
171 */
172#define IORING_SETUP_IOPOLL (1U << 0) /* io_context is polled */
173#define IORING_SETUP_SQPOLL (1U << 1) /* SQ poll thread */
174#define IORING_SETUP_SQ_AFF (1U << 2) /* sq_thread_cpu is valid */
175#define IORING_SETUP_CQSIZE (1U << 3) /* app defines CQ size */
176#define IORING_SETUP_CLAMP (1U << 4) /* clamp SQ/CQ ring sizes */
177#define IORING_SETUP_ATTACH_WQ (1U << 5) /* attach to existing wq */
178#define IORING_SETUP_R_DISABLED (1U << 6) /* start with ring disabled */
179#define IORING_SETUP_SUBMIT_ALL (1U << 7) /* continue submit on error */
180/*
181 * Cooperative task running. When requests complete, they often require
182 * forcing the submitter to transition to the kernel to complete. If this
183 * flag is set, work will be done when the task transitions anyway, rather
184 * than force an inter-processor interrupt reschedule. This avoids interrupting
185 * a task running in userspace, and saves an IPI.
186 */
187#define IORING_SETUP_COOP_TASKRUN (1U << 8)
188/*
189 * If COOP_TASKRUN is set, get notified if task work is available for
190 * running and a kernel transition would be needed to run it. This sets
191 * IORING_SQ_TASKRUN in the sq ring flags. Not valid with COOP_TASKRUN.
192 */
193#define IORING_SETUP_TASKRUN_FLAG (1U << 9)
194#define IORING_SETUP_SQE128 (1U << 10) /* SQEs are 128 byte */
195#define IORING_SETUP_CQE32 (1U << 11) /* CQEs are 32 byte */
196/*
197 * Only one task is allowed to submit requests
198 */
199#define IORING_SETUP_SINGLE_ISSUER (1U << 12)
200
201/*
202 * Defer running task work to get events.
203 * Rather than running bits of task work whenever the task transitions
204 * try to do it just before it is needed.
205 */
206#define IORING_SETUP_DEFER_TASKRUN (1U << 13)
207
208/*
209 * Application provides the memory for the rings
210 */
211#define IORING_SETUP_NO_MMAP (1U << 14)
212
213/*
214 * Register the ring fd in itself for use with
215 * IORING_REGISTER_USE_REGISTERED_RING; return a registered fd index rather
216 * than an fd.
217 */
218#define IORING_SETUP_REGISTERED_FD_ONLY (1U << 15)
219
220/*
221 * Removes indirection through the SQ index array.
222 */
223#define IORING_SETUP_NO_SQARRAY (1U << 16)
224
225/* Use hybrid poll in iopoll process */
226#define IORING_SETUP_HYBRID_IOPOLL (1U << 17)
227
228/*
229 * Allow both 16b and 32b CQEs. If a 32b CQE is posted, it will have
230 * IORING_CQE_F_32 set in cqe->flags.
231 */
232#define IORING_SETUP_CQE_MIXED (1U << 18)
233
234/*
235 * Allow both 64b and 128b SQEs. If a 128b SQE is posted, it will have
236 * a 128b opcode.
237 */
238#define IORING_SETUP_SQE_MIXED (1U << 19)
239
240enum io_uring_op {
241 IORING_OP_NOP,
242 IORING_OP_READV,
243 IORING_OP_WRITEV,
244 IORING_OP_FSYNC,
245 IORING_OP_READ_FIXED,
246 IORING_OP_WRITE_FIXED,
247 IORING_OP_POLL_ADD,
248 IORING_OP_POLL_REMOVE,
249 IORING_OP_SYNC_FILE_RANGE,
250 IORING_OP_SENDMSG,
251 IORING_OP_RECVMSG,
252 IORING_OP_TIMEOUT,
253 IORING_OP_TIMEOUT_REMOVE,
254 IORING_OP_ACCEPT,
255 IORING_OP_ASYNC_CANCEL,
256 IORING_OP_LINK_TIMEOUT,
257 IORING_OP_CONNECT,
258 IORING_OP_FALLOCATE,
259 IORING_OP_OPENAT,
260 IORING_OP_CLOSE,
261 IORING_OP_FILES_UPDATE,
262 IORING_OP_STATX,
263 IORING_OP_READ,
264 IORING_OP_WRITE,
265 IORING_OP_FADVISE,
266 IORING_OP_MADVISE,
267 IORING_OP_SEND,
268 IORING_OP_RECV,
269 IORING_OP_OPENAT2,
270 IORING_OP_EPOLL_CTL,
271 IORING_OP_SPLICE,
272 IORING_OP_PROVIDE_BUFFERS,
273 IORING_OP_REMOVE_BUFFERS,
274 IORING_OP_TEE,
275 IORING_OP_SHUTDOWN,
276 IORING_OP_RENAMEAT,
277 IORING_OP_UNLINKAT,
278 IORING_OP_MKDIRAT,
279 IORING_OP_SYMLINKAT,
280 IORING_OP_LINKAT,
281 IORING_OP_MSG_RING,
282 IORING_OP_FSETXATTR,
283 IORING_OP_SETXATTR,
284 IORING_OP_FGETXATTR,
285 IORING_OP_GETXATTR,
286 IORING_OP_SOCKET,
287 IORING_OP_URING_CMD,
288 IORING_OP_SEND_ZC,
289 IORING_OP_SENDMSG_ZC,
290 IORING_OP_READ_MULTISHOT,
291 IORING_OP_WAITID,
292 IORING_OP_FUTEX_WAIT,
293 IORING_OP_FUTEX_WAKE,
294 IORING_OP_FUTEX_WAITV,
295 IORING_OP_FIXED_FD_INSTALL,
296 IORING_OP_FTRUNCATE,
297 IORING_OP_BIND,
298 IORING_OP_LISTEN,
299 IORING_OP_RECV_ZC,
300 IORING_OP_EPOLL_WAIT,
301 IORING_OP_READV_FIXED,
302 IORING_OP_WRITEV_FIXED,
303 IORING_OP_PIPE,
304 IORING_OP_NOP128,
305 IORING_OP_URING_CMD128,
306
307 /* this goes last, obviously */
308 IORING_OP_LAST,
309};
310
311/*
312 * sqe->uring_cmd_flags top 8bits aren't available for userspace
313 * IORING_URING_CMD_FIXED use registered buffer; pass this flag
314 * along with setting sqe->buf_index.
315 * IORING_URING_CMD_MULTISHOT must be used with buffer select, like other
316 * multishot commands. Not compatible with
317 * IORING_URING_CMD_FIXED, for now.
318 */
319#define IORING_URING_CMD_FIXED (1U << 0)
320#define IORING_URING_CMD_MULTISHOT (1U << 1)
321#define IORING_URING_CMD_MASK (IORING_URING_CMD_FIXED | IORING_URING_CMD_MULTISHOT)
322
323
324/*
325 * sqe->fsync_flags
326 */
327#define IORING_FSYNC_DATASYNC (1U << 0)
328
329/*
330 * sqe->timeout_flags
331 */
332#define IORING_TIMEOUT_ABS (1U << 0)
333#define IORING_TIMEOUT_UPDATE (1U << 1)
334#define IORING_TIMEOUT_BOOTTIME (1U << 2)
335#define IORING_TIMEOUT_REALTIME (1U << 3)
336#define IORING_LINK_TIMEOUT_UPDATE (1U << 4)
337#define IORING_TIMEOUT_ETIME_SUCCESS (1U << 5)
338#define IORING_TIMEOUT_MULTISHOT (1U << 6)
339#define IORING_TIMEOUT_CLOCK_MASK (IORING_TIMEOUT_BOOTTIME | IORING_TIMEOUT_REALTIME)
340#define IORING_TIMEOUT_UPDATE_MASK (IORING_TIMEOUT_UPDATE | IORING_LINK_TIMEOUT_UPDATE)
341/*
342 * sqe->splice_flags
343 * extends splice(2) flags
344 */
345#define SPLICE_F_FD_IN_FIXED (1U << 31) /* the last bit of __u32 */
346
347/*
348 * POLL_ADD flags. Note that since sqe->poll_events is the flag space, the
349 * command flags for POLL_ADD are stored in sqe->len.
350 *
351 * IORING_POLL_ADD_MULTI Multishot poll. Sets IORING_CQE_F_MORE if
352 * the poll handler will continue to report
353 * CQEs on behalf of the same SQE.
354 *
355 * IORING_POLL_UPDATE Update existing poll request, matching
356 * sqe->addr as the old user_data field.
357 *
358 * IORING_POLL_LEVEL Level triggered poll.
359 */
360#define IORING_POLL_ADD_MULTI (1U << 0)
361#define IORING_POLL_UPDATE_EVENTS (1U << 1)
362#define IORING_POLL_UPDATE_USER_DATA (1U << 2)
363#define IORING_POLL_ADD_LEVEL (1U << 3)
364
365/*
366 * ASYNC_CANCEL flags.
367 *
368 * IORING_ASYNC_CANCEL_ALL Cancel all requests that match the given key
369 * IORING_ASYNC_CANCEL_FD Key off 'fd' for cancelation rather than the
370 * request 'user_data'
371 * IORING_ASYNC_CANCEL_ANY Match any request
372 * IORING_ASYNC_CANCEL_FD_FIXED 'fd' passed in is a fixed descriptor
373 * IORING_ASYNC_CANCEL_USERDATA Match on user_data, default for no other key
374 * IORING_ASYNC_CANCEL_OP Match request based on opcode
375 */
376#define IORING_ASYNC_CANCEL_ALL (1U << 0)
377#define IORING_ASYNC_CANCEL_FD (1U << 1)
378#define IORING_ASYNC_CANCEL_ANY (1U << 2)
379#define IORING_ASYNC_CANCEL_FD_FIXED (1U << 3)
380#define IORING_ASYNC_CANCEL_USERDATA (1U << 4)
381#define IORING_ASYNC_CANCEL_OP (1U << 5)
382
383/*
384 * send/sendmsg and recv/recvmsg flags (sqe->ioprio)
385 *
386 * IORING_RECVSEND_POLL_FIRST If set, instead of first attempting to send
387 * or receive and arm poll if that yields an
388 * -EAGAIN result, arm poll upfront and skip
389 * the initial transfer attempt.
390 *
391 * IORING_RECV_MULTISHOT Multishot recv. Sets IORING_CQE_F_MORE if
392 * the handler will continue to report
393 * CQEs on behalf of the same SQE.
394 *
395 * IORING_RECVSEND_FIXED_BUF Use registered buffers, the index is stored in
396 * the buf_index field.
397 *
398 * IORING_SEND_ZC_REPORT_USAGE
399 * If set, SEND[MSG]_ZC should report
400 * the zerocopy usage in cqe.res
401 * for the IORING_CQE_F_NOTIF cqe.
402 * 0 is reported if zerocopy was actually possible.
403 * IORING_NOTIF_USAGE_ZC_COPIED if data was copied
404 * (at least partially).
405 *
406 * IORING_RECVSEND_BUNDLE Used with IOSQE_BUFFER_SELECT. If set, send or
407 * recv will grab as many buffers from the buffer
408 * group ID given and send them all. The completion
409 * result will be the number of buffers send, with
410 * the starting buffer ID in cqe->flags as per
411 * usual for provided buffer usage. The buffers
412 * will be contiguous from the starting buffer ID.
413 *
414 * IORING_SEND_VECTORIZED If set, SEND[_ZC] will take a pointer to a io_vec
415 * to allow vectorized send operations.
416 */
417#define IORING_RECVSEND_POLL_FIRST (1U << 0)
418#define IORING_RECV_MULTISHOT (1U << 1)
419#define IORING_RECVSEND_FIXED_BUF (1U << 2)
420#define IORING_SEND_ZC_REPORT_USAGE (1U << 3)
421#define IORING_RECVSEND_BUNDLE (1U << 4)
422#define IORING_SEND_VECTORIZED (1U << 5)
423
424/*
425 * cqe.res for IORING_CQE_F_NOTIF if
426 * IORING_SEND_ZC_REPORT_USAGE was requested
427 *
428 * It should be treated as a flag, all other
429 * bits of cqe.res should be treated as reserved!
430 */
431#define IORING_NOTIF_USAGE_ZC_COPIED (1U << 31)
432
433/*
434 * accept flags stored in sqe->ioprio
435 */
436#define IORING_ACCEPT_MULTISHOT (1U << 0)
437#define IORING_ACCEPT_DONTWAIT (1U << 1)
438#define IORING_ACCEPT_POLL_FIRST (1U << 2)
439
440/*
441 * IORING_OP_MSG_RING command types, stored in sqe->addr
442 */
443enum io_uring_msg_ring_flags {
444 IORING_MSG_DATA, /* pass sqe->len as 'res' and off as user_data */
445 IORING_MSG_SEND_FD, /* send a registered fd to another ring */
446};
447
448/*
449 * IORING_OP_MSG_RING flags (sqe->msg_ring_flags)
450 *
451 * IORING_MSG_RING_CQE_SKIP Don't post a CQE to the target ring. Not
452 * applicable for IORING_MSG_DATA, obviously.
453 */
454#define IORING_MSG_RING_CQE_SKIP (1U << 0)
455/* Pass through the flags from sqe->file_index to cqe->flags */
456#define IORING_MSG_RING_FLAGS_PASS (1U << 1)
457
458/*
459 * IORING_OP_FIXED_FD_INSTALL flags (sqe->install_fd_flags)
460 *
461 * IORING_FIXED_FD_NO_CLOEXEC Don't mark the fd as O_CLOEXEC
462 */
463#define IORING_FIXED_FD_NO_CLOEXEC (1U << 0)
464
465/*
466 * IORING_OP_NOP flags (sqe->nop_flags)
467 *
468 * IORING_NOP_INJECT_RESULT Inject result from sqe->result
469 */
470#define IORING_NOP_INJECT_RESULT (1U << 0)
471#define IORING_NOP_FILE (1U << 1)
472#define IORING_NOP_FIXED_FILE (1U << 2)
473#define IORING_NOP_FIXED_BUFFER (1U << 3)
474#define IORING_NOP_TW (1U << 4)
475#define IORING_NOP_CQE32 (1U << 5)
476
477/*
478 * IO completion data structure (Completion Queue Entry)
479 */
480struct io_uring_cqe {
481 __u64 user_data; /* sqe->user_data value passed back */
482 __s32 res; /* result code for this event */
483 __u32 flags;
484
485 /*
486 * If the ring is initialized with IORING_SETUP_CQE32, then this field
487 * contains 16-bytes of padding, doubling the size of the CQE.
488 */
489 __u64 big_cqe[];
490};
491
492/*
493 * cqe->flags
494 *
495 * IORING_CQE_F_BUFFER If set, the upper 16 bits are the buffer ID
496 * IORING_CQE_F_MORE If set, parent SQE will generate more CQE entries
497 * IORING_CQE_F_SOCK_NONEMPTY If set, more data to read after socket recv
498 * IORING_CQE_F_NOTIF Set for notification CQEs. Can be used to distinct
499 * them from sends.
500 * IORING_CQE_F_BUF_MORE If set, the buffer ID set in the completion will get
501 * more completions. In other words, the buffer is being
502 * partially consumed, and will be used by the kernel for
503 * more completions. This is only set for buffers used via
504 * the incremental buffer consumption, as provided by
505 * a ring buffer setup with IOU_PBUF_RING_INC. For any
506 * other provided buffer type, all completions with a
507 * buffer passed back is automatically returned to the
508 * application.
509 * IORING_CQE_F_SKIP If set, then the application/liburing must ignore this
510 * CQE. It's only purpose is to fill a gap in the ring,
511 * if a large CQE is attempted posted when the ring has
512 * just a single small CQE worth of space left before
513 * wrapping.
514 * IORING_CQE_F_32 If set, this is a 32b/big-cqe posting. Use with rings
515 * setup in a mixed CQE mode, where both 16b and 32b
516 * CQEs may be posted to the CQ ring.
517 */
518#define IORING_CQE_F_BUFFER (1U << 0)
519#define IORING_CQE_F_MORE (1U << 1)
520#define IORING_CQE_F_SOCK_NONEMPTY (1U << 2)
521#define IORING_CQE_F_NOTIF (1U << 3)
522#define IORING_CQE_F_BUF_MORE (1U << 4)
523#define IORING_CQE_F_SKIP (1U << 5)
524#define IORING_CQE_F_32 (1U << 15)
525
526#define IORING_CQE_BUFFER_SHIFT 16
527
528/*
529 * Magic offsets for the application to mmap the data it needs
530 */
531#define IORING_OFF_SQ_RING 0ULL
532#define IORING_OFF_CQ_RING 0x8000000ULL
533#define IORING_OFF_SQES 0x10000000ULL
534#define IORING_OFF_PBUF_RING 0x80000000ULL
535#define IORING_OFF_PBUF_SHIFT 16
536#define IORING_OFF_MMAP_MASK 0xf8000000ULL
537
538/*
539 * Filled with the offset for mmap(2)
540 */
541struct io_sqring_offsets {
542 __u32 head;
543 __u32 tail;
544 __u32 ring_mask;
545 __u32 ring_entries;
546 __u32 flags;
547 __u32 dropped;
548 __u32 array;
549 __u32 resv1;
550 __u64 user_addr;
551};
552
553/*
554 * sq_ring->flags
555 */
556#define IORING_SQ_NEED_WAKEUP (1U << 0) /* needs io_uring_enter wakeup */
557#define IORING_SQ_CQ_OVERFLOW (1U << 1) /* CQ ring is overflown */
558#define IORING_SQ_TASKRUN (1U << 2) /* task should enter the kernel */
559
560struct io_cqring_offsets {
561 __u32 head;
562 __u32 tail;
563 __u32 ring_mask;
564 __u32 ring_entries;
565 __u32 overflow;
566 __u32 cqes;
567 __u32 flags;
568 __u32 resv1;
569 __u64 user_addr;
570};
571
572/*
573 * cq_ring->flags
574 */
575
576/* disable eventfd notifications */
577#define IORING_CQ_EVENTFD_DISABLED (1U << 0)
578
579/*
580 * io_uring_enter(2) flags
581 */
582#define IORING_ENTER_GETEVENTS (1U << 0)
583#define IORING_ENTER_SQ_WAKEUP (1U << 1)
584#define IORING_ENTER_SQ_WAIT (1U << 2)
585#define IORING_ENTER_EXT_ARG (1U << 3)
586#define IORING_ENTER_REGISTERED_RING (1U << 4)
587#define IORING_ENTER_ABS_TIMER (1U << 5)
588#define IORING_ENTER_EXT_ARG_REG (1U << 6)
589#define IORING_ENTER_NO_IOWAIT (1U << 7)
590
591/*
592 * Passed in for io_uring_setup(2). Copied back with updated info on success
593 */
594struct io_uring_params {
595 __u32 sq_entries;
596 __u32 cq_entries;
597 __u32 flags;
598 __u32 sq_thread_cpu;
599 __u32 sq_thread_idle;
600 __u32 features;
601 __u32 wq_fd;
602 __u32 resv[3];
603 struct io_sqring_offsets sq_off;
604 struct io_cqring_offsets cq_off;
605};
606
607/*
608 * io_uring_params->features flags
609 */
610#define IORING_FEAT_SINGLE_MMAP (1U << 0)
611#define IORING_FEAT_NODROP (1U << 1)
612#define IORING_FEAT_SUBMIT_STABLE (1U << 2)
613#define IORING_FEAT_RW_CUR_POS (1U << 3)
614#define IORING_FEAT_CUR_PERSONALITY (1U << 4)
615#define IORING_FEAT_FAST_POLL (1U << 5)
616#define IORING_FEAT_POLL_32BITS (1U << 6)
617#define IORING_FEAT_SQPOLL_NONFIXED (1U << 7)
618#define IORING_FEAT_EXT_ARG (1U << 8)
619#define IORING_FEAT_NATIVE_WORKERS (1U << 9)
620#define IORING_FEAT_RSRC_TAGS (1U << 10)
621#define IORING_FEAT_CQE_SKIP (1U << 11)
622#define IORING_FEAT_LINKED_FILE (1U << 12)
623#define IORING_FEAT_REG_REG_RING (1U << 13)
624#define IORING_FEAT_RECVSEND_BUNDLE (1U << 14)
625#define IORING_FEAT_MIN_TIMEOUT (1U << 15)
626#define IORING_FEAT_RW_ATTR (1U << 16)
627#define IORING_FEAT_NO_IOWAIT (1U << 17)
628
629/*
630 * io_uring_register(2) opcodes and arguments
631 */
632enum io_uring_register_op {
633 IORING_REGISTER_BUFFERS = 0,
634 IORING_UNREGISTER_BUFFERS = 1,
635 IORING_REGISTER_FILES = 2,
636 IORING_UNREGISTER_FILES = 3,
637 IORING_REGISTER_EVENTFD = 4,
638 IORING_UNREGISTER_EVENTFD = 5,
639 IORING_REGISTER_FILES_UPDATE = 6,
640 IORING_REGISTER_EVENTFD_ASYNC = 7,
641 IORING_REGISTER_PROBE = 8,
642 IORING_REGISTER_PERSONALITY = 9,
643 IORING_UNREGISTER_PERSONALITY = 10,
644 IORING_REGISTER_RESTRICTIONS = 11,
645 IORING_REGISTER_ENABLE_RINGS = 12,
646
647 /* extended with tagging */
648 IORING_REGISTER_FILES2 = 13,
649 IORING_REGISTER_FILES_UPDATE2 = 14,
650 IORING_REGISTER_BUFFERS2 = 15,
651 IORING_REGISTER_BUFFERS_UPDATE = 16,
652
653 /* set/clear io-wq thread affinities */
654 IORING_REGISTER_IOWQ_AFF = 17,
655 IORING_UNREGISTER_IOWQ_AFF = 18,
656
657 /* set/get max number of io-wq workers */
658 IORING_REGISTER_IOWQ_MAX_WORKERS = 19,
659
660 /* register/unregister io_uring fd with the ring */
661 IORING_REGISTER_RING_FDS = 20,
662 IORING_UNREGISTER_RING_FDS = 21,
663
664 /* register ring based provide buffer group */
665 IORING_REGISTER_PBUF_RING = 22,
666 IORING_UNREGISTER_PBUF_RING = 23,
667
668 /* sync cancelation API */
669 IORING_REGISTER_SYNC_CANCEL = 24,
670
671 /* register a range of fixed file slots for automatic slot allocation */
672 IORING_REGISTER_FILE_ALLOC_RANGE = 25,
673
674 /* return status information for a buffer group */
675 IORING_REGISTER_PBUF_STATUS = 26,
676
677 /* set/clear busy poll settings */
678 IORING_REGISTER_NAPI = 27,
679 IORING_UNREGISTER_NAPI = 28,
680
681 IORING_REGISTER_CLOCK = 29,
682
683 /* clone registered buffers from source ring to current ring */
684 IORING_REGISTER_CLONE_BUFFERS = 30,
685
686 /* send MSG_RING without having a ring */
687 IORING_REGISTER_SEND_MSG_RING = 31,
688
689 /* register a netdev hw rx queue for zerocopy */
690 IORING_REGISTER_ZCRX_IFQ = 32,
691
692 /* resize CQ ring */
693 IORING_REGISTER_RESIZE_RINGS = 33,
694
695 IORING_REGISTER_MEM_REGION = 34,
696
697 /* query various aspects of io_uring, see linux/io_uring/query.h */
698 IORING_REGISTER_QUERY = 35,
699
700 /* auxiliary zcrx configuration, see enum zcrx_ctrl_op */
701 IORING_REGISTER_ZCRX_CTRL = 36,
702
703 /* this goes last */
704 IORING_REGISTER_LAST,
705
706 /* flag added to the opcode to use a registered ring fd */
707 IORING_REGISTER_USE_REGISTERED_RING = 1U << 31
708};
709
710/* io-wq worker categories */
711enum io_wq_type {
712 IO_WQ_BOUND,
713 IO_WQ_UNBOUND,
714};
715
716/* deprecated, see struct io_uring_rsrc_update */
717struct io_uring_files_update {
718 __u32 offset;
719 __u32 resv;
720 __aligned_u64 /* __s32 * */ fds;
721};
722
723enum {
724 /* initialise with user provided memory pointed by user_addr */
725 IORING_MEM_REGION_TYPE_USER = 1,
726};
727
728struct io_uring_region_desc {
729 __u64 user_addr;
730 __u64 size;
731 __u32 flags;
732 __u32 id;
733 __u64 mmap_offset;
734 __u64 __resv[4];
735};
736
737enum {
738 /* expose the region as registered wait arguments */
739 IORING_MEM_REGION_REG_WAIT_ARG = 1,
740};
741
742struct io_uring_mem_region_reg {
743 __u64 region_uptr; /* struct io_uring_region_desc * */
744 __u64 flags;
745 __u64 __resv[2];
746};
747
748/*
749 * Register a fully sparse file space, rather than pass in an array of all
750 * -1 file descriptors.
751 */
752#define IORING_RSRC_REGISTER_SPARSE (1U << 0)
753
754struct io_uring_rsrc_register {
755 __u32 nr;
756 __u32 flags;
757 __u64 resv2;
758 __aligned_u64 data;
759 __aligned_u64 tags;
760};
761
762struct io_uring_rsrc_update {
763 __u32 offset;
764 __u32 resv;
765 __aligned_u64 data;
766};
767
768struct io_uring_rsrc_update2 {
769 __u32 offset;
770 __u32 resv;
771 __aligned_u64 data;
772 __aligned_u64 tags;
773 __u32 nr;
774 __u32 resv2;
775};
776
777/* Skip updating fd indexes set to this value in the fd table */
778#define IORING_REGISTER_FILES_SKIP (-2)
779
780#define IO_URING_OP_SUPPORTED (1U << 0)
781
782struct io_uring_probe_op {
783 __u8 op;
784 __u8 resv;
785 __u16 flags; /* IO_URING_OP_* flags */
786 __u32 resv2;
787};
788
789struct io_uring_probe {
790 __u8 last_op; /* last opcode supported */
791 __u8 ops_len; /* length of ops[] array below */
792 __u16 resv;
793 __u32 resv2[3];
794 struct io_uring_probe_op ops[];
795};
796
797struct io_uring_restriction {
798 __u16 opcode;
799 union {
800 __u8 register_op; /* IORING_RESTRICTION_REGISTER_OP */
801 __u8 sqe_op; /* IORING_RESTRICTION_SQE_OP */
802 __u8 sqe_flags; /* IORING_RESTRICTION_SQE_FLAGS_* */
803 };
804 __u8 resv;
805 __u32 resv2[3];
806};
807
808struct io_uring_clock_register {
809 __u32 clockid;
810 __u32 __resv[3];
811};
812
813enum {
814 IORING_REGISTER_SRC_REGISTERED = (1U << 0),
815 IORING_REGISTER_DST_REPLACE = (1U << 1),
816};
817
818struct io_uring_clone_buffers {
819 __u32 src_fd;
820 __u32 flags;
821 __u32 src_off;
822 __u32 dst_off;
823 __u32 nr;
824 __u32 pad[3];
825};
826
827struct io_uring_buf {
828 __u64 addr;
829 __u32 len;
830 __u16 bid;
831 __u16 resv;
832};
833
834struct io_uring_buf_ring {
835 union {
836 /*
837 * To avoid spilling into more pages than we need to, the
838 * ring tail is overlaid with the io_uring_buf->resv field.
839 */
840 struct {
841 __u64 resv1;
842 __u32 resv2;
843 __u16 resv3;
844 __u16 tail;
845 };
846 __DECLARE_FLEX_ARRAY(struct io_uring_buf, bufs);
847 };
848};
849
850/*
851 * Flags for IORING_REGISTER_PBUF_RING.
852 *
853 * IOU_PBUF_RING_MMAP: If set, kernel will allocate the memory for the ring.
854 * The application must not set a ring_addr in struct
855 * io_uring_buf_reg, instead it must subsequently call
856 * mmap(2) with the offset set as:
857 * IORING_OFF_PBUF_RING | (bgid << IORING_OFF_PBUF_SHIFT)
858 * to get a virtual mapping for the ring.
859 * IOU_PBUF_RING_INC: If set, buffers consumed from this buffer ring can be
860 * consumed incrementally. Normally one (or more) buffers
861 * are fully consumed. With incremental consumptions, it's
862 * feasible to register big ranges of buffers, and each
863 * use of it will consume only as much as it needs. This
864 * requires that both the kernel and application keep
865 * track of where the current read/recv index is at.
866 */
867enum io_uring_register_pbuf_ring_flags {
868 IOU_PBUF_RING_MMAP = 1,
869 IOU_PBUF_RING_INC = 2,
870};
871
872/* argument for IORING_(UN)REGISTER_PBUF_RING */
873struct io_uring_buf_reg {
874 __u64 ring_addr;
875 __u32 ring_entries;
876 __u16 bgid;
877 __u16 flags;
878 __u64 resv[3];
879};
880
881/* argument for IORING_REGISTER_PBUF_STATUS */
882struct io_uring_buf_status {
883 __u32 buf_group; /* input */
884 __u32 head; /* output */
885 __u32 resv[8];
886};
887
888enum io_uring_napi_op {
889 /* register/ungister backward compatible opcode */
890 IO_URING_NAPI_REGISTER_OP = 0,
891
892 /* opcodes to update napi_list when static tracking is used */
893 IO_URING_NAPI_STATIC_ADD_ID = 1,
894 IO_URING_NAPI_STATIC_DEL_ID = 2
895};
896
897enum io_uring_napi_tracking_strategy {
898 /* value must be 0 for backward compatibility */
899 IO_URING_NAPI_TRACKING_DYNAMIC = 0,
900 IO_URING_NAPI_TRACKING_STATIC = 1,
901 IO_URING_NAPI_TRACKING_INACTIVE = 255
902};
903
904/* argument for IORING_(UN)REGISTER_NAPI */
905struct io_uring_napi {
906 __u32 busy_poll_to;
907 __u8 prefer_busy_poll;
908
909 /* a io_uring_napi_op value */
910 __u8 opcode;
911 __u8 pad[2];
912
913 /*
914 * for IO_URING_NAPI_REGISTER_OP, it is a
915 * io_uring_napi_tracking_strategy value.
916 *
917 * for IO_URING_NAPI_STATIC_ADD_ID/IO_URING_NAPI_STATIC_DEL_ID
918 * it is the napi id to add/del from napi_list.
919 */
920 __u32 op_param;
921 __u32 resv;
922};
923
924/*
925 * io_uring_restriction->opcode values
926 */
927enum io_uring_register_restriction_op {
928 /* Allow an io_uring_register(2) opcode */
929 IORING_RESTRICTION_REGISTER_OP = 0,
930
931 /* Allow an sqe opcode */
932 IORING_RESTRICTION_SQE_OP = 1,
933
934 /* Allow sqe flags */
935 IORING_RESTRICTION_SQE_FLAGS_ALLOWED = 2,
936
937 /* Require sqe flags (these flags must be set on each submission) */
938 IORING_RESTRICTION_SQE_FLAGS_REQUIRED = 3,
939
940 IORING_RESTRICTION_LAST
941};
942
943enum {
944 IORING_REG_WAIT_TS = (1U << 0),
945};
946
947/*
948 * Argument for io_uring_enter(2) with
949 * IORING_GETEVENTS | IORING_ENTER_EXT_ARG_REG set, where the actual argument
950 * is an index into a previously registered fixed wait region described by
951 * the below structure.
952 */
953struct io_uring_reg_wait {
954 struct __kernel_timespec ts;
955 __u32 min_wait_usec;
956 __u32 flags;
957 __u64 sigmask;
958 __u32 sigmask_sz;
959 __u32 pad[3];
960 __u64 pad2[2];
961};
962
963/*
964 * Argument for io_uring_enter(2) with IORING_GETEVENTS | IORING_ENTER_EXT_ARG
965 */
966struct io_uring_getevents_arg {
967 __u64 sigmask;
968 __u32 sigmask_sz;
969 __u32 min_wait_usec;
970 __u64 ts;
971};
972
973/*
974 * Argument for IORING_REGISTER_SYNC_CANCEL
975 */
976struct io_uring_sync_cancel_reg {
977 __u64 addr;
978 __s32 fd;
979 __u32 flags;
980 struct __kernel_timespec timeout;
981 __u8 opcode;
982 __u8 pad[7];
983 __u64 pad2[3];
984};
985
986/*
987 * Argument for IORING_REGISTER_FILE_ALLOC_RANGE
988 * The range is specified as [off, off + len)
989 */
990struct io_uring_file_index_range {
991 __u32 off;
992 __u32 len;
993 __u64 resv;
994};
995
996struct io_uring_recvmsg_out {
997 __u32 namelen;
998 __u32 controllen;
999 __u32 payloadlen;
1000 __u32 flags;
1001};
1002
1003/*
1004 * Argument for IORING_OP_URING_CMD when file is a socket
1005 */
1006enum io_uring_socket_op {
1007 SOCKET_URING_OP_SIOCINQ = 0,
1008 SOCKET_URING_OP_SIOCOUTQ,
1009 SOCKET_URING_OP_GETSOCKOPT,
1010 SOCKET_URING_OP_SETSOCKOPT,
1011 SOCKET_URING_OP_TX_TIMESTAMP,
1012 SOCKET_URING_OP_GETSOCKNAME,
1013};
1014
1015/*
1016 * SOCKET_URING_OP_TX_TIMESTAMP definitions
1017 */
1018
1019#define IORING_TIMESTAMP_HW_SHIFT 16
1020/* The cqe->flags bit from which the timestamp type is stored */
1021#define IORING_TIMESTAMP_TYPE_SHIFT (IORING_TIMESTAMP_HW_SHIFT + 1)
1022/* The cqe->flags flag signifying whether it's a hardware timestamp */
1023#define IORING_CQE_F_TSTAMP_HW ((__u32)1 << IORING_TIMESTAMP_HW_SHIFT)
1024
1025struct io_timespec {
1026 __u64 tv_sec;
1027 __u64 tv_nsec;
1028};
1029
1030/* Zero copy receive refill queue entry */
1031struct io_uring_zcrx_rqe {
1032 __u64 off;
1033 __u32 len;
1034 __u32 __pad;
1035};
1036
1037struct io_uring_zcrx_cqe {
1038 __u64 off;
1039 __u64 __pad;
1040};
1041
1042/* The bit from which area id is encoded into offsets */
1043#define IORING_ZCRX_AREA_SHIFT 48
1044#define IORING_ZCRX_AREA_MASK (~(((__u64)1 << IORING_ZCRX_AREA_SHIFT) - 1))
1045
1046struct io_uring_zcrx_offsets {
1047 __u32 head;
1048 __u32 tail;
1049 __u32 rqes;
1050 __u32 __resv2;
1051 __u64 __resv[2];
1052};
1053
1054enum io_uring_zcrx_area_flags {
1055 IORING_ZCRX_AREA_DMABUF = 1,
1056};
1057
1058struct io_uring_zcrx_area_reg {
1059 __u64 addr;
1060 __u64 len;
1061 __u64 rq_area_token;
1062 __u32 flags;
1063 __u32 dmabuf_fd;
1064 __u64 __resv2[2];
1065};
1066
1067enum zcrx_reg_flags {
1068 ZCRX_REG_IMPORT = 1,
1069};
1070
1071/*
1072 * Argument for IORING_REGISTER_ZCRX_IFQ
1073 */
1074struct io_uring_zcrx_ifq_reg {
1075 __u32 if_idx;
1076 __u32 if_rxq;
1077 __u32 rq_entries;
1078 __u32 flags;
1079
1080 __u64 area_ptr; /* pointer to struct io_uring_zcrx_area_reg */
1081 __u64 region_ptr; /* struct io_uring_region_desc * */
1082
1083 struct io_uring_zcrx_offsets offsets;
1084 __u32 zcrx_id;
1085 __u32 __resv2;
1086 __u64 __resv[3];
1087};
1088
1089enum zcrx_ctrl_op {
1090 ZCRX_CTRL_FLUSH_RQ,
1091 ZCRX_CTRL_EXPORT,
1092
1093 __ZCRX_CTRL_LAST,
1094};
1095
1096struct zcrx_ctrl_flush_rq {
1097 __u64 __resv[6];
1098};
1099
1100struct zcrx_ctrl_export {
1101 __u32 zcrx_fd;
1102 __u32 __resv1[11];
1103};
1104
1105struct zcrx_ctrl {
1106 __u32 zcrx_id;
1107 __u32 op; /* see enum zcrx_ctrl_op */
1108 __u64 __resv[2];
1109
1110 union {
1111 struct zcrx_ctrl_export zc_export;
1112 struct zcrx_ctrl_flush_rq zc_flush;
1113 };
1114};
1115
1116#ifdef __cplusplus
1117}
1118#endif
1119
1120#endif