xref: /linux/include/uapi/linux/io_uring.h (revision b3fdea6ecb55c3ceea866ff66486927e51a982b3)
19f5834c8SLukas Bulwahn /* SPDX-License-Identifier: (GPL-2.0 WITH Linux-syscall-note) OR MIT */
22b188cc1SJens Axboe /*
32b188cc1SJens Axboe  * Header file for the io_uring interface.
42b188cc1SJens Axboe  *
52b188cc1SJens Axboe  * Copyright (C) 2019 Jens Axboe
62b188cc1SJens Axboe  * Copyright (C) 2019 Christoph Hellwig
72b188cc1SJens Axboe  */
82b188cc1SJens Axboe #ifndef LINUX_IO_URING_H
92b188cc1SJens Axboe #define LINUX_IO_URING_H
102b188cc1SJens Axboe 
112b188cc1SJens Axboe #include <linux/fs.h>
122b188cc1SJens Axboe #include <linux/types.h>
1378a861b9SJens Axboe #include <linux/time_types.h>
142b188cc1SJens Axboe 
152b188cc1SJens Axboe /*
162b188cc1SJens Axboe  * IO submission data structure (Submission Queue Entry)
172b188cc1SJens Axboe  */
182b188cc1SJens Axboe struct io_uring_sqe {
192b188cc1SJens Axboe 	__u8	opcode;		/* type of operation for this sqe */
206b06314cSJens Axboe 	__u8	flags;		/* IOSQE_ flags */
212b188cc1SJens Axboe 	__u16	ioprio;		/* ioprio for the request */
222b188cc1SJens Axboe 	__s32	fd;		/* file descriptor to do IO on */
2317f2fe35SJens Axboe 	union {
242b188cc1SJens Axboe 		__u64	off;	/* offset into file */
2517f2fe35SJens Axboe 		__u64	addr2;
26bdb2c48eSPavel Begunkov 		struct {
27ee692a21SJens Axboe 			__u32	cmd_op;
28bdb2c48eSPavel Begunkov 			__u32	__pad1;
29bdb2c48eSPavel Begunkov 		};
3017f2fe35SJens Axboe 	};
317d67af2cSPavel Begunkov 	union {
322b188cc1SJens Axboe 		__u64	addr;	/* pointer to buffer or iovecs */
337d67af2cSPavel Begunkov 		__u64	splice_off_in;
347d67af2cSPavel Begunkov 	};
352b188cc1SJens Axboe 	__u32	len;		/* buffer size or number of iovecs */
362b188cc1SJens Axboe 	union {
372b188cc1SJens Axboe 		__kernel_rwf_t	rw_flags;
38c992fe29SChristoph Hellwig 		__u32		fsync_flags;
395769a351SJiufei Xue 		__u16		poll_events;	/* compatibility */
405769a351SJiufei Xue 		__u32		poll32_events;	/* word-reversed for BE */
415d17b4a4SJens Axboe 		__u32		sync_range_flags;
420fa03c62SJens Axboe 		__u32		msg_flags;
435262f567SJens Axboe 		__u32		timeout_flags;
4417f2fe35SJens Axboe 		__u32		accept_flags;
4562755e35SJens Axboe 		__u32		cancel_flags;
4615b71abeSJens Axboe 		__u32		open_flags;
47eddc7ef5SJens Axboe 		__u32		statx_flags;
484840e418SJens Axboe 		__u32		fadvise_advice;
497d67af2cSPavel Begunkov 		__u32		splice_flags;
5080a261fdSJens Axboe 		__u32		rename_flags;
5114a1143bSJens Axboe 		__u32		unlink_flags;
52cf30da90SDmitry Kadashev 		__u32		hardlink_flags;
53e9621e2bSStefan Roesch 		__u32		xattr_flags;
54e6130ebaSJens Axboe 		__u32		msg_ring_flags;
552b188cc1SJens Axboe 	};
562b188cc1SJens Axboe 	__u64	user_data;	/* data to be passed back at completion time */
57ddf0322dSJens Axboe 	/* pack this to avoid bogus arm OABI complaints */
58ddf0322dSJens Axboe 	union {
5975c6a039SJens Axboe 		/* index into fixed buffers, if used */
6075c6a039SJens Axboe 		__u16	buf_index;
61ddf0322dSJens Axboe 		/* for grouped buffer selection */
62ddf0322dSJens Axboe 		__u16	buf_group;
63ddf0322dSJens Axboe 	} __attribute__((packed));
6475c6a039SJens Axboe 	/* personality to use, if used */
6575c6a039SJens Axboe 	__u16	personality;
66b9445598SPavel Begunkov 	union {
677d67af2cSPavel Begunkov 		__s32	splice_fd_in;
68b9445598SPavel Begunkov 		__u32	file_index;
69b9445598SPavel Begunkov 	};
70ee692a21SJens Axboe 	union {
71ee692a21SJens Axboe 		struct {
72e9621e2bSStefan Roesch 			__u64	addr3;
73e9621e2bSStefan Roesch 			__u64	__pad2[1];
74edafcceeSJens Axboe 		};
75ebdeb7c0SJens Axboe 		/*
76ee692a21SJens Axboe 		 * If the ring is initialized with IORING_SETUP_SQE128, then
77ee692a21SJens Axboe 		 * this field is used for 80 bytes of arbitrary command data
78ebdeb7c0SJens Axboe 		 */
79ee692a21SJens Axboe 		__u8	cmd[0];
80ee692a21SJens Axboe 	};
812b188cc1SJens Axboe };
822b188cc1SJens Axboe 
831339f24bSJens Axboe /*
841339f24bSJens Axboe  * If sqe->file_index is set to this for opcodes that instantiate a new
851339f24bSJens Axboe  * direct descriptor (like openat/openat2/accept), then io_uring will allocate
861339f24bSJens Axboe  * an available direct descriptor instead of having the application pass one
871339f24bSJens Axboe  * in. The picked direct descriptor will be returned in cqe->res, or -ENFILE
881339f24bSJens Axboe  * if the space is full.
891339f24bSJens Axboe  */
901339f24bSJens Axboe #define IORING_FILE_INDEX_ALLOC		(~0U)
911339f24bSJens Axboe 
926b47ee6eSPavel Begunkov enum {
936b47ee6eSPavel Begunkov 	IOSQE_FIXED_FILE_BIT,
946b47ee6eSPavel Begunkov 	IOSQE_IO_DRAIN_BIT,
956b47ee6eSPavel Begunkov 	IOSQE_IO_LINK_BIT,
966b47ee6eSPavel Begunkov 	IOSQE_IO_HARDLINK_BIT,
976b47ee6eSPavel Begunkov 	IOSQE_ASYNC_BIT,
98bcda7baaSJens Axboe 	IOSQE_BUFFER_SELECT_BIT,
9904c76b41SPavel Begunkov 	IOSQE_CQE_SKIP_SUCCESS_BIT,
1006b47ee6eSPavel Begunkov };
1016b47ee6eSPavel Begunkov 
102def596e9SJens Axboe /*
1036b06314cSJens Axboe  * sqe->flags
1046b06314cSJens Axboe  */
1056b47ee6eSPavel Begunkov /* use fixed fileset */
1066b47ee6eSPavel Begunkov #define IOSQE_FIXED_FILE	(1U << IOSQE_FIXED_FILE_BIT)
1076b47ee6eSPavel Begunkov /* issue after inflight IO */
1086b47ee6eSPavel Begunkov #define IOSQE_IO_DRAIN		(1U << IOSQE_IO_DRAIN_BIT)
1096b47ee6eSPavel Begunkov /* links next sqe */
1106b47ee6eSPavel Begunkov #define IOSQE_IO_LINK		(1U << IOSQE_IO_LINK_BIT)
1116b47ee6eSPavel Begunkov /* like LINK, but stronger */
1126b47ee6eSPavel Begunkov #define IOSQE_IO_HARDLINK	(1U << IOSQE_IO_HARDLINK_BIT)
1136b47ee6eSPavel Begunkov /* always go async */
1146b47ee6eSPavel Begunkov #define IOSQE_ASYNC		(1U << IOSQE_ASYNC_BIT)
115bcda7baaSJens Axboe /* select buffer from sqe->buf_group */
116bcda7baaSJens Axboe #define IOSQE_BUFFER_SELECT	(1U << IOSQE_BUFFER_SELECT_BIT)
11704c76b41SPavel Begunkov /* don't post CQE if request succeeded */
11804c76b41SPavel Begunkov #define IOSQE_CQE_SKIP_SUCCESS	(1U << IOSQE_CQE_SKIP_SUCCESS_BIT)
1196b06314cSJens Axboe 
1206b06314cSJens Axboe /*
121def596e9SJens Axboe  * io_uring_setup() flags
122def596e9SJens Axboe  */
123def596e9SJens Axboe #define IORING_SETUP_IOPOLL	(1U << 0)	/* io_context is polled */
1246c271ce2SJens Axboe #define IORING_SETUP_SQPOLL	(1U << 1)	/* SQ poll thread */
1256c271ce2SJens Axboe #define IORING_SETUP_SQ_AFF	(1U << 2)	/* sq_thread_cpu is valid */
12633a107f0SJens Axboe #define IORING_SETUP_CQSIZE	(1U << 3)	/* app defines CQ size */
1278110c1a6SJens Axboe #define IORING_SETUP_CLAMP	(1U << 4)	/* clamp SQ/CQ ring sizes */
12824369c2eSPavel Begunkov #define IORING_SETUP_ATTACH_WQ	(1U << 5)	/* attach to existing wq */
1297e84e1c7SStefano Garzarella #define IORING_SETUP_R_DISABLED	(1U << 6)	/* start with ring disabled */
130bcbb7bf6SJens Axboe #define IORING_SETUP_SUBMIT_ALL	(1U << 7)	/* continue submit on error */
131e1169f06SJens Axboe /*
132e1169f06SJens Axboe  * Cooperative task running. When requests complete, they often require
133e1169f06SJens Axboe  * forcing the submitter to transition to the kernel to complete. If this
134e1169f06SJens Axboe  * flag is set, work will be done when the task transitions anyway, rather
135e1169f06SJens Axboe  * than force an inter-processor interrupt reschedule. This avoids interrupting
136e1169f06SJens Axboe  * a task running in userspace, and saves an IPI.
137e1169f06SJens Axboe  */
138e1169f06SJens Axboe #define IORING_SETUP_COOP_TASKRUN	(1U << 8)
139ef060ea9SJens Axboe /*
140ef060ea9SJens Axboe  * If COOP_TASKRUN is set, get notified if task work is available for
141ef060ea9SJens Axboe  * running and a kernel transition would be needed to run it. This sets
142ef060ea9SJens Axboe  * IORING_SQ_TASKRUN in the sq ring flags. Not valid with COOP_TASKRUN.
143ef060ea9SJens Axboe  */
144ef060ea9SJens Axboe #define IORING_SETUP_TASKRUN_FLAG	(1U << 9)
145ebdeb7c0SJens Axboe #define IORING_SETUP_SQE128		(1U << 10) /* SQEs are 128 byte */
1467a51e5b4SStefan Roesch #define IORING_SETUP_CQE32		(1U << 11) /* CQEs are 32 byte */
14797bbdc06SPavel Begunkov /*
14897bbdc06SPavel Begunkov  * Only one task is allowed to submit requests
14997bbdc06SPavel Begunkov  */
15097bbdc06SPavel Begunkov #define IORING_SETUP_SINGLE_ISSUER	(1U << 12)
151ebdeb7c0SJens Axboe 
152cc51eaa8SDylan Yudaken enum io_uring_op {
1539e3aa61aSJens Axboe 	IORING_OP_NOP,
1549e3aa61aSJens Axboe 	IORING_OP_READV,
1559e3aa61aSJens Axboe 	IORING_OP_WRITEV,
1569e3aa61aSJens Axboe 	IORING_OP_FSYNC,
1579e3aa61aSJens Axboe 	IORING_OP_READ_FIXED,
1589e3aa61aSJens Axboe 	IORING_OP_WRITE_FIXED,
1599e3aa61aSJens Axboe 	IORING_OP_POLL_ADD,
1609e3aa61aSJens Axboe 	IORING_OP_POLL_REMOVE,
1619e3aa61aSJens Axboe 	IORING_OP_SYNC_FILE_RANGE,
1629e3aa61aSJens Axboe 	IORING_OP_SENDMSG,
1639e3aa61aSJens Axboe 	IORING_OP_RECVMSG,
1649e3aa61aSJens Axboe 	IORING_OP_TIMEOUT,
1659e3aa61aSJens Axboe 	IORING_OP_TIMEOUT_REMOVE,
1669e3aa61aSJens Axboe 	IORING_OP_ACCEPT,
1679e3aa61aSJens Axboe 	IORING_OP_ASYNC_CANCEL,
1689e3aa61aSJens Axboe 	IORING_OP_LINK_TIMEOUT,
1699e3aa61aSJens Axboe 	IORING_OP_CONNECT,
170d63d1b5eSJens Axboe 	IORING_OP_FALLOCATE,
17115b71abeSJens Axboe 	IORING_OP_OPENAT,
172b5dba59eSJens Axboe 	IORING_OP_CLOSE,
17305f3fb3cSJens Axboe 	IORING_OP_FILES_UPDATE,
174eddc7ef5SJens Axboe 	IORING_OP_STATX,
1753a6820f2SJens Axboe 	IORING_OP_READ,
1763a6820f2SJens Axboe 	IORING_OP_WRITE,
1774840e418SJens Axboe 	IORING_OP_FADVISE,
178c1ca757bSJens Axboe 	IORING_OP_MADVISE,
179fddafaceSJens Axboe 	IORING_OP_SEND,
180fddafaceSJens Axboe 	IORING_OP_RECV,
181cebdb986SJens Axboe 	IORING_OP_OPENAT2,
1823e4827b0SJens Axboe 	IORING_OP_EPOLL_CTL,
1837d67af2cSPavel Begunkov 	IORING_OP_SPLICE,
184ddf0322dSJens Axboe 	IORING_OP_PROVIDE_BUFFERS,
185067524e9SJens Axboe 	IORING_OP_REMOVE_BUFFERS,
186f2a8d5c7SPavel Begunkov 	IORING_OP_TEE,
18736f4fa68SJens Axboe 	IORING_OP_SHUTDOWN,
18880a261fdSJens Axboe 	IORING_OP_RENAMEAT,
18914a1143bSJens Axboe 	IORING_OP_UNLINKAT,
190e34a02dcSDmitry Kadashev 	IORING_OP_MKDIRAT,
1917a8721f8SDmitry Kadashev 	IORING_OP_SYMLINKAT,
192cf30da90SDmitry Kadashev 	IORING_OP_LINKAT,
1934f57f06cSJens Axboe 	IORING_OP_MSG_RING,
194e9621e2bSStefan Roesch 	IORING_OP_FSETXATTR,
195e9621e2bSStefan Roesch 	IORING_OP_SETXATTR,
196a56834e0SStefan Roesch 	IORING_OP_FGETXATTR,
197a56834e0SStefan Roesch 	IORING_OP_GETXATTR,
1981374e08eSJens Axboe 	IORING_OP_SOCKET,
199ee692a21SJens Axboe 	IORING_OP_URING_CMD,
2009e3aa61aSJens Axboe 
2019e3aa61aSJens Axboe 	/* this goes last, obviously */
2029e3aa61aSJens Axboe 	IORING_OP_LAST,
2039e3aa61aSJens Axboe };
204c992fe29SChristoph Hellwig 
205c992fe29SChristoph Hellwig /*
206c992fe29SChristoph Hellwig  * sqe->fsync_flags
207c992fe29SChristoph Hellwig  */
208c992fe29SChristoph Hellwig #define IORING_FSYNC_DATASYNC	(1U << 0)
2092b188cc1SJens Axboe 
2102b188cc1SJens Axboe /*
211a41525abSJens Axboe  * sqe->timeout_flags
212a41525abSJens Axboe  */
213a41525abSJens Axboe #define IORING_TIMEOUT_ABS		(1U << 0)
2149c8e11b3SPavel Begunkov #define IORING_TIMEOUT_UPDATE		(1U << 1)
21550c1df2bSJens Axboe #define IORING_TIMEOUT_BOOTTIME		(1U << 2)
21650c1df2bSJens Axboe #define IORING_TIMEOUT_REALTIME		(1U << 3)
217f1042b6cSPavel Begunkov #define IORING_LINK_TIMEOUT_UPDATE	(1U << 4)
2186224590dSPavel Begunkov #define IORING_TIMEOUT_ETIME_SUCCESS	(1U << 5)
21950c1df2bSJens Axboe #define IORING_TIMEOUT_CLOCK_MASK	(IORING_TIMEOUT_BOOTTIME | IORING_TIMEOUT_REALTIME)
220f1042b6cSPavel Begunkov #define IORING_TIMEOUT_UPDATE_MASK	(IORING_TIMEOUT_UPDATE | IORING_LINK_TIMEOUT_UPDATE)
221a41525abSJens Axboe /*
2227d67af2cSPavel Begunkov  * sqe->splice_flags
2237d67af2cSPavel Begunkov  * extends splice(2) flags
2247d67af2cSPavel Begunkov  */
2257d67af2cSPavel Begunkov #define SPLICE_F_FD_IN_FIXED	(1U << 31) /* the last bit of __u32 */
2267d67af2cSPavel Begunkov 
2277d67af2cSPavel Begunkov /*
22888e41cf9SJens Axboe  * POLL_ADD flags. Note that since sqe->poll_events is the flag space, the
22988e41cf9SJens Axboe  * command flags for POLL_ADD are stored in sqe->len.
23088e41cf9SJens Axboe  *
23188e41cf9SJens Axboe  * IORING_POLL_ADD_MULTI	Multishot poll. Sets IORING_CQE_F_MORE if
23288e41cf9SJens Axboe  *				the poll handler will continue to report
23388e41cf9SJens Axboe  *				CQEs on behalf of the same SQE.
234b69de288SJens Axboe  *
235b69de288SJens Axboe  * IORING_POLL_UPDATE		Update existing poll request, matching
236b69de288SJens Axboe  *				sqe->addr as the old user_data field.
237b9ba8a44SJens Axboe  *
238b9ba8a44SJens Axboe  * IORING_POLL_LEVEL		Level triggered poll.
23988e41cf9SJens Axboe  */
24088e41cf9SJens Axboe #define IORING_POLL_ADD_MULTI	(1U << 0)
241b69de288SJens Axboe #define IORING_POLL_UPDATE_EVENTS	(1U << 1)
242b69de288SJens Axboe #define IORING_POLL_UPDATE_USER_DATA	(1U << 2)
243b9ba8a44SJens Axboe #define IORING_POLL_ADD_LEVEL		(1U << 3)
24488e41cf9SJens Axboe 
24588e41cf9SJens Axboe /*
2468e29da69SJens Axboe  * ASYNC_CANCEL flags.
2478e29da69SJens Axboe  *
2488e29da69SJens Axboe  * IORING_ASYNC_CANCEL_ALL	Cancel all requests that match the given key
2494bf94615SJens Axboe  * IORING_ASYNC_CANCEL_FD	Key off 'fd' for cancelation rather than the
2504bf94615SJens Axboe  *				request 'user_data'
251970f256eSJens Axboe  * IORING_ASYNC_CANCEL_ANY	Match any request
2527d8ca725SJens Axboe  * IORING_ASYNC_CANCEL_FD_FIXED	'fd' passed in is a fixed descriptor
2538e29da69SJens Axboe  */
2548e29da69SJens Axboe #define IORING_ASYNC_CANCEL_ALL	(1U << 0)
2554bf94615SJens Axboe #define IORING_ASYNC_CANCEL_FD	(1U << 1)
256970f256eSJens Axboe #define IORING_ASYNC_CANCEL_ANY	(1U << 2)
2577d8ca725SJens Axboe #define IORING_ASYNC_CANCEL_FD_FIXED	(1U << 3)
2588e29da69SJens Axboe 
2598e29da69SJens Axboe /*
26029c1ac23SPavel Begunkov  * send/sendmsg and recv/recvmsg flags (sqe->ioprio)
2610455d4ccSJens Axboe  *
2620455d4ccSJens Axboe  * IORING_RECVSEND_POLL_FIRST	If set, instead of first attempting to send
2630455d4ccSJens Axboe  *				or receive and arm poll if that yields an
2640455d4ccSJens Axboe  *				-EAGAIN result, arm poll upfront and skip
2650455d4ccSJens Axboe  *				the initial transfer attempt.
266*b3fdea6eSDylan Yudaken  *
267*b3fdea6eSDylan Yudaken  * IORING_RECV_MULTISHOT	Multishot recv. Sets IORING_CQE_F_MORE if
268*b3fdea6eSDylan Yudaken  *				the handler will continue to report
269*b3fdea6eSDylan Yudaken  *				CQEs on behalf of the same SQE.
2700455d4ccSJens Axboe  */
2710455d4ccSJens Axboe #define IORING_RECVSEND_POLL_FIRST	(1U << 0)
272*b3fdea6eSDylan Yudaken #define IORING_RECV_MULTISHOT	(1U << 1)
2730455d4ccSJens Axboe 
2740455d4ccSJens Axboe /*
275390ed29bSHao Xu  * accept flags stored in sqe->ioprio
276390ed29bSHao Xu  */
277390ed29bSHao Xu #define IORING_ACCEPT_MULTISHOT	(1U << 0)
278390ed29bSHao Xu 
279390ed29bSHao Xu /*
280e6130ebaSJens Axboe  * IORING_OP_MSG_RING command types, stored in sqe->addr
281e6130ebaSJens Axboe  */
282e6130ebaSJens Axboe enum {
283e6130ebaSJens Axboe 	IORING_MSG_DATA,	/* pass sqe->len as 'res' and off as user_data */
284e6130ebaSJens Axboe 	IORING_MSG_SEND_FD,	/* send a registered fd to another ring */
285e6130ebaSJens Axboe };
286e6130ebaSJens Axboe 
287e6130ebaSJens Axboe /*
288e6130ebaSJens Axboe  * IORING_OP_MSG_RING flags (sqe->msg_ring_flags)
289e6130ebaSJens Axboe  *
290e6130ebaSJens Axboe  * IORING_MSG_RING_CQE_SKIP	Don't post a CQE to the target ring. Not
291e6130ebaSJens Axboe  *				applicable for IORING_MSG_DATA, obviously.
292e6130ebaSJens Axboe  */
293e6130ebaSJens Axboe #define IORING_MSG_RING_CQE_SKIP	(1U << 0)
294e6130ebaSJens Axboe 
295e6130ebaSJens Axboe /*
2962b188cc1SJens Axboe  * IO completion data structure (Completion Queue Entry)
2972b188cc1SJens Axboe  */
2982b188cc1SJens Axboe struct io_uring_cqe {
2992b188cc1SJens Axboe 	__u64	user_data;	/* sqe->data submission passed back */
3002b188cc1SJens Axboe 	__s32	res;		/* result code for this event */
3012b188cc1SJens Axboe 	__u32	flags;
3027a51e5b4SStefan Roesch 
3037a51e5b4SStefan Roesch 	/*
3047a51e5b4SStefan Roesch 	 * If the ring is initialized with IORING_SETUP_CQE32, then this field
3057a51e5b4SStefan Roesch 	 * contains 16-bytes of padding, doubling the size of the CQE.
3067a51e5b4SStefan Roesch 	 */
3077a51e5b4SStefan Roesch 	__u64 big_cqe[];
3082b188cc1SJens Axboe };
3092b188cc1SJens Axboe 
3102b188cc1SJens Axboe /*
311bcda7baaSJens Axboe  * cqe->flags
312bcda7baaSJens Axboe  *
313bcda7baaSJens Axboe  * IORING_CQE_F_BUFFER	If set, the upper 16 bits are the buffer ID
31488e41cf9SJens Axboe  * IORING_CQE_F_MORE	If set, parent SQE will generate more CQE entries
315f548a12eSJens Axboe  * IORING_CQE_F_SOCK_NONEMPTY	If set, more data to read after socket recv
316bcda7baaSJens Axboe  */
317bcda7baaSJens Axboe #define IORING_CQE_F_BUFFER		(1U << 0)
31888e41cf9SJens Axboe #define IORING_CQE_F_MORE		(1U << 1)
319f548a12eSJens Axboe #define IORING_CQE_F_SOCK_NONEMPTY	(1U << 2)
320bcda7baaSJens Axboe 
321bcda7baaSJens Axboe enum {
322bcda7baaSJens Axboe 	IORING_CQE_BUFFER_SHIFT		= 16,
323bcda7baaSJens Axboe };
324bcda7baaSJens Axboe 
325bcda7baaSJens Axboe /*
3262b188cc1SJens Axboe  * Magic offsets for the application to mmap the data it needs
3272b188cc1SJens Axboe  */
3282b188cc1SJens Axboe #define IORING_OFF_SQ_RING		0ULL
3292b188cc1SJens Axboe #define IORING_OFF_CQ_RING		0x8000000ULL
3302b188cc1SJens Axboe #define IORING_OFF_SQES			0x10000000ULL
3312b188cc1SJens Axboe 
3322b188cc1SJens Axboe /*
3332b188cc1SJens Axboe  * Filled with the offset for mmap(2)
3342b188cc1SJens Axboe  */
3352b188cc1SJens Axboe struct io_sqring_offsets {
3362b188cc1SJens Axboe 	__u32 head;
3372b188cc1SJens Axboe 	__u32 tail;
3382b188cc1SJens Axboe 	__u32 ring_mask;
3392b188cc1SJens Axboe 	__u32 ring_entries;
3402b188cc1SJens Axboe 	__u32 flags;
3412b188cc1SJens Axboe 	__u32 dropped;
3422b188cc1SJens Axboe 	__u32 array;
3432b188cc1SJens Axboe 	__u32 resv1;
3442b188cc1SJens Axboe 	__u64 resv2;
3452b188cc1SJens Axboe };
3462b188cc1SJens Axboe 
3476c271ce2SJens Axboe /*
3486c271ce2SJens Axboe  * sq_ring->flags
3496c271ce2SJens Axboe  */
3506c271ce2SJens Axboe #define IORING_SQ_NEED_WAKEUP	(1U << 0) /* needs io_uring_enter wakeup */
3516d5f9049SXiaoguang Wang #define IORING_SQ_CQ_OVERFLOW	(1U << 1) /* CQ ring is overflown */
352ef060ea9SJens Axboe #define IORING_SQ_TASKRUN	(1U << 2) /* task should enter the kernel */
3536c271ce2SJens Axboe 
3542b188cc1SJens Axboe struct io_cqring_offsets {
3552b188cc1SJens Axboe 	__u32 head;
3562b188cc1SJens Axboe 	__u32 tail;
3572b188cc1SJens Axboe 	__u32 ring_mask;
3582b188cc1SJens Axboe 	__u32 ring_entries;
3592b188cc1SJens Axboe 	__u32 overflow;
3602b188cc1SJens Axboe 	__u32 cqes;
3610d9b5b3aSStefano Garzarella 	__u32 flags;
3620d9b5b3aSStefano Garzarella 	__u32 resv1;
3630d9b5b3aSStefano Garzarella 	__u64 resv2;
3642b188cc1SJens Axboe };
3652b188cc1SJens Axboe 
3662b188cc1SJens Axboe /*
3677e55a19cSStefano Garzarella  * cq_ring->flags
3687e55a19cSStefano Garzarella  */
3697e55a19cSStefano Garzarella 
3707e55a19cSStefano Garzarella /* disable eventfd notifications */
3717e55a19cSStefano Garzarella #define IORING_CQ_EVENTFD_DISABLED	(1U << 0)
3727e55a19cSStefano Garzarella 
3737e55a19cSStefano Garzarella /*
3742b188cc1SJens Axboe  * io_uring_enter(2) flags
3752b188cc1SJens Axboe  */
3762b188cc1SJens Axboe #define IORING_ENTER_GETEVENTS		(1U << 0)
3776c271ce2SJens Axboe #define IORING_ENTER_SQ_WAKEUP		(1U << 1)
37890554200SJens Axboe #define IORING_ENTER_SQ_WAIT		(1U << 2)
379c73ebb68SHao Xu #define IORING_ENTER_EXT_ARG		(1U << 3)
380e7a6c00dSJens Axboe #define IORING_ENTER_REGISTERED_RING	(1U << 4)
3812b188cc1SJens Axboe 
3822b188cc1SJens Axboe /*
3832b188cc1SJens Axboe  * Passed in for io_uring_setup(2). Copied back with updated info on success
3842b188cc1SJens Axboe  */
3852b188cc1SJens Axboe struct io_uring_params {
3862b188cc1SJens Axboe 	__u32 sq_entries;
3872b188cc1SJens Axboe 	__u32 cq_entries;
3882b188cc1SJens Axboe 	__u32 flags;
3896c271ce2SJens Axboe 	__u32 sq_thread_cpu;
3906c271ce2SJens Axboe 	__u32 sq_thread_idle;
391ac90f249SJens Axboe 	__u32 features;
39224369c2eSPavel Begunkov 	__u32 wq_fd;
39324369c2eSPavel Begunkov 	__u32 resv[3];
3942b188cc1SJens Axboe 	struct io_sqring_offsets sq_off;
3952b188cc1SJens Axboe 	struct io_cqring_offsets cq_off;
3962b188cc1SJens Axboe };
3972b188cc1SJens Axboe 
398edafcceeSJens Axboe /*
399ac90f249SJens Axboe  * io_uring_params->features flags
400ac90f249SJens Axboe  */
401ac90f249SJens Axboe #define IORING_FEAT_SINGLE_MMAP		(1U << 0)
4021d7bb1d5SJens Axboe #define IORING_FEAT_NODROP		(1U << 1)
403da8c9690SJens Axboe #define IORING_FEAT_SUBMIT_STABLE	(1U << 2)
404ba04291eSJens Axboe #define IORING_FEAT_RW_CUR_POS		(1U << 3)
405cccf0ee8SJens Axboe #define IORING_FEAT_CUR_PERSONALITY	(1U << 4)
406d7718a9dSJens Axboe #define IORING_FEAT_FAST_POLL		(1U << 5)
4075769a351SJiufei Xue #define IORING_FEAT_POLL_32BITS 	(1U << 6)
40828cea78aSJens Axboe #define IORING_FEAT_SQPOLL_NONFIXED	(1U << 7)
409c73ebb68SHao Xu #define IORING_FEAT_EXT_ARG		(1U << 8)
4101c0aa1faSJens Axboe #define IORING_FEAT_NATIVE_WORKERS	(1U << 9)
4119690557eSPavel Begunkov #define IORING_FEAT_RSRC_TAGS		(1U << 10)
41204c76b41SPavel Begunkov #define IORING_FEAT_CQE_SKIP		(1U << 11)
413c4212f3eSJens Axboe #define IORING_FEAT_LINKED_FILE		(1U << 12)
414ac90f249SJens Axboe 
415ac90f249SJens Axboe /*
416edafcceeSJens Axboe  * io_uring_register(2) opcodes and arguments
417edafcceeSJens Axboe  */
4189d4a75efSStefano Garzarella enum {
4199d4a75efSStefano Garzarella 	IORING_REGISTER_BUFFERS			= 0,
4209d4a75efSStefano Garzarella 	IORING_UNREGISTER_BUFFERS		= 1,
4219d4a75efSStefano Garzarella 	IORING_REGISTER_FILES			= 2,
4229d4a75efSStefano Garzarella 	IORING_UNREGISTER_FILES			= 3,
4239d4a75efSStefano Garzarella 	IORING_REGISTER_EVENTFD			= 4,
4249d4a75efSStefano Garzarella 	IORING_UNREGISTER_EVENTFD		= 5,
4259d4a75efSStefano Garzarella 	IORING_REGISTER_FILES_UPDATE		= 6,
4269d4a75efSStefano Garzarella 	IORING_REGISTER_EVENTFD_ASYNC		= 7,
4279d4a75efSStefano Garzarella 	IORING_REGISTER_PROBE			= 8,
4289d4a75efSStefano Garzarella 	IORING_REGISTER_PERSONALITY		= 9,
4299d4a75efSStefano Garzarella 	IORING_UNREGISTER_PERSONALITY		= 10,
43021b55dbcSStefano Garzarella 	IORING_REGISTER_RESTRICTIONS		= 11,
4317e84e1c7SStefano Garzarella 	IORING_REGISTER_ENABLE_RINGS		= 12,
432992da01aSPavel Begunkov 
433992da01aSPavel Begunkov 	/* extended with tagging */
434992da01aSPavel Begunkov 	IORING_REGISTER_FILES2			= 13,
435992da01aSPavel Begunkov 	IORING_REGISTER_FILES_UPDATE2		= 14,
436992da01aSPavel Begunkov 	IORING_REGISTER_BUFFERS2		= 15,
437992da01aSPavel Begunkov 	IORING_REGISTER_BUFFERS_UPDATE		= 16,
4389d4a75efSStefano Garzarella 
439fe76421dSJens Axboe 	/* set/clear io-wq thread affinities */
440fe76421dSJens Axboe 	IORING_REGISTER_IOWQ_AFF		= 17,
441fe76421dSJens Axboe 	IORING_UNREGISTER_IOWQ_AFF		= 18,
442fe76421dSJens Axboe 
443dd47c104SEugene Syromiatnikov 	/* set/get max number of io-wq workers */
4442e480058SJens Axboe 	IORING_REGISTER_IOWQ_MAX_WORKERS	= 19,
4452e480058SJens Axboe 
446e7a6c00dSJens Axboe 	/* register/unregister io_uring fd with the ring */
447e7a6c00dSJens Axboe 	IORING_REGISTER_RING_FDS		= 20,
448e7a6c00dSJens Axboe 	IORING_UNREGISTER_RING_FDS		= 21,
449e7a6c00dSJens Axboe 
450c7fb1942SJens Axboe 	/* register ring based provide buffer group */
451c7fb1942SJens Axboe 	IORING_REGISTER_PBUF_RING		= 22,
452c7fb1942SJens Axboe 	IORING_UNREGISTER_PBUF_RING		= 23,
453c7fb1942SJens Axboe 
45478a861b9SJens Axboe 	/* sync cancelation API */
45578a861b9SJens Axboe 	IORING_REGISTER_SYNC_CANCEL		= 24,
45678a861b9SJens Axboe 
4576e73dffbSPavel Begunkov 	/* register a range of fixed file slots for automatic slot allocation */
4586e73dffbSPavel Begunkov 	IORING_REGISTER_FILE_ALLOC_RANGE	= 25,
4596e73dffbSPavel Begunkov 
4609d4a75efSStefano Garzarella 	/* this goes last */
4619d4a75efSStefano Garzarella 	IORING_REGISTER_LAST
4629d4a75efSStefano Garzarella };
463c3a31e60SJens Axboe 
464dd47c104SEugene Syromiatnikov /* io-wq worker categories */
465dd47c104SEugene Syromiatnikov enum {
466dd47c104SEugene Syromiatnikov 	IO_WQ_BOUND,
467dd47c104SEugene Syromiatnikov 	IO_WQ_UNBOUND,
468dd47c104SEugene Syromiatnikov };
469dd47c104SEugene Syromiatnikov 
470269bbe5fSBijan Mottahedeh /* deprecated, see struct io_uring_rsrc_update */
471c3a31e60SJens Axboe struct io_uring_files_update {
472c3a31e60SJens Axboe 	__u32 offset;
4731292e972SEugene Syromiatnikov 	__u32 resv;
4741292e972SEugene Syromiatnikov 	__aligned_u64 /* __s32 * */ fds;
475c3a31e60SJens Axboe };
476edafcceeSJens Axboe 
477a8da73a3SJens Axboe /*
478a8da73a3SJens Axboe  * Register a fully sparse file space, rather than pass in an array of all
479a8da73a3SJens Axboe  * -1 file descriptors.
480a8da73a3SJens Axboe  */
481a8da73a3SJens Axboe #define IORING_RSRC_REGISTER_SPARSE	(1U << 0)
482a8da73a3SJens Axboe 
483792e3582SPavel Begunkov struct io_uring_rsrc_register {
484792e3582SPavel Begunkov 	__u32 nr;
485a8da73a3SJens Axboe 	__u32 flags;
486992da01aSPavel Begunkov 	__u64 resv2;
487792e3582SPavel Begunkov 	__aligned_u64 data;
488792e3582SPavel Begunkov 	__aligned_u64 tags;
489792e3582SPavel Begunkov };
490792e3582SPavel Begunkov 
491c3bdad02SPavel Begunkov struct io_uring_rsrc_update {
492c3bdad02SPavel Begunkov 	__u32 offset;
493c3bdad02SPavel Begunkov 	__u32 resv;
494c3bdad02SPavel Begunkov 	__aligned_u64 data;
495c3bdad02SPavel Begunkov };
496c3bdad02SPavel Begunkov 
497c3bdad02SPavel Begunkov struct io_uring_rsrc_update2 {
498c3bdad02SPavel Begunkov 	__u32 offset;
499c3bdad02SPavel Begunkov 	__u32 resv;
500c3bdad02SPavel Begunkov 	__aligned_u64 data;
501c3bdad02SPavel Begunkov 	__aligned_u64 tags;
502c3bdad02SPavel Begunkov 	__u32 nr;
503992da01aSPavel Begunkov 	__u32 resv2;
504c3bdad02SPavel Begunkov };
505c3bdad02SPavel Begunkov 
5064e0377a1Snoah /* Skip updating fd indexes set to this value in the fd table */
5074e0377a1Snoah #define IORING_REGISTER_FILES_SKIP	(-2)
5084e0377a1Snoah 
50966f4af93SJens Axboe #define IO_URING_OP_SUPPORTED	(1U << 0)
51066f4af93SJens Axboe 
51166f4af93SJens Axboe struct io_uring_probe_op {
51266f4af93SJens Axboe 	__u8 op;
51366f4af93SJens Axboe 	__u8 resv;
51466f4af93SJens Axboe 	__u16 flags;	/* IO_URING_OP_* flags */
51566f4af93SJens Axboe 	__u32 resv2;
51666f4af93SJens Axboe };
51766f4af93SJens Axboe 
51866f4af93SJens Axboe struct io_uring_probe {
51966f4af93SJens Axboe 	__u8 last_op;	/* last opcode supported */
52066f4af93SJens Axboe 	__u8 ops_len;	/* length of ops[] array below */
52166f4af93SJens Axboe 	__u16 resv;
52266f4af93SJens Axboe 	__u32 resv2[3];
5238fcf4c48SGustavo A. R. Silva 	struct io_uring_probe_op ops[];
52466f4af93SJens Axboe };
52566f4af93SJens Axboe 
52621b55dbcSStefano Garzarella struct io_uring_restriction {
52721b55dbcSStefano Garzarella 	__u16 opcode;
52821b55dbcSStefano Garzarella 	union {
52921b55dbcSStefano Garzarella 		__u8 register_op; /* IORING_RESTRICTION_REGISTER_OP */
53021b55dbcSStefano Garzarella 		__u8 sqe_op;      /* IORING_RESTRICTION_SQE_OP */
53121b55dbcSStefano Garzarella 		__u8 sqe_flags;   /* IORING_RESTRICTION_SQE_FLAGS_* */
53221b55dbcSStefano Garzarella 	};
53321b55dbcSStefano Garzarella 	__u8 resv;
53421b55dbcSStefano Garzarella 	__u32 resv2[3];
53521b55dbcSStefano Garzarella };
53621b55dbcSStefano Garzarella 
537c7fb1942SJens Axboe struct io_uring_buf {
538c7fb1942SJens Axboe 	__u64	addr;
539c7fb1942SJens Axboe 	__u32	len;
540c7fb1942SJens Axboe 	__u16	bid;
541c7fb1942SJens Axboe 	__u16	resv;
542c7fb1942SJens Axboe };
543c7fb1942SJens Axboe 
544c7fb1942SJens Axboe struct io_uring_buf_ring {
545c7fb1942SJens Axboe 	union {
546c7fb1942SJens Axboe 		/*
547c7fb1942SJens Axboe 		 * To avoid spilling into more pages than we need to, the
548c7fb1942SJens Axboe 		 * ring tail is overlaid with the io_uring_buf->resv field.
549c7fb1942SJens Axboe 		 */
550c7fb1942SJens Axboe 		struct {
551c7fb1942SJens Axboe 			__u64	resv1;
552c7fb1942SJens Axboe 			__u32	resv2;
553c7fb1942SJens Axboe 			__u16	resv3;
554c7fb1942SJens Axboe 			__u16	tail;
555c7fb1942SJens Axboe 		};
556c7fb1942SJens Axboe 		struct io_uring_buf	bufs[0];
557c7fb1942SJens Axboe 	};
558c7fb1942SJens Axboe };
559c7fb1942SJens Axboe 
560c7fb1942SJens Axboe /* argument for IORING_(UN)REGISTER_PBUF_RING */
561c7fb1942SJens Axboe struct io_uring_buf_reg {
562c7fb1942SJens Axboe 	__u64	ring_addr;
563c7fb1942SJens Axboe 	__u32	ring_entries;
564c7fb1942SJens Axboe 	__u16	bgid;
565c7fb1942SJens Axboe 	__u16	pad;
566c7fb1942SJens Axboe 	__u64	resv[3];
567c7fb1942SJens Axboe };
568c7fb1942SJens Axboe 
56921b55dbcSStefano Garzarella /*
57021b55dbcSStefano Garzarella  * io_uring_restriction->opcode values
57121b55dbcSStefano Garzarella  */
57221b55dbcSStefano Garzarella enum {
57321b55dbcSStefano Garzarella 	/* Allow an io_uring_register(2) opcode */
57421b55dbcSStefano Garzarella 	IORING_RESTRICTION_REGISTER_OP		= 0,
57521b55dbcSStefano Garzarella 
57621b55dbcSStefano Garzarella 	/* Allow an sqe opcode */
57721b55dbcSStefano Garzarella 	IORING_RESTRICTION_SQE_OP		= 1,
57821b55dbcSStefano Garzarella 
57921b55dbcSStefano Garzarella 	/* Allow sqe flags */
58021b55dbcSStefano Garzarella 	IORING_RESTRICTION_SQE_FLAGS_ALLOWED	= 2,
58121b55dbcSStefano Garzarella 
58221b55dbcSStefano Garzarella 	/* Require sqe flags (these flags must be set on each submission) */
58321b55dbcSStefano Garzarella 	IORING_RESTRICTION_SQE_FLAGS_REQUIRED	= 3,
58421b55dbcSStefano Garzarella 
58521b55dbcSStefano Garzarella 	IORING_RESTRICTION_LAST
58621b55dbcSStefano Garzarella };
58721b55dbcSStefano Garzarella 
588c73ebb68SHao Xu struct io_uring_getevents_arg {
589c73ebb68SHao Xu 	__u64	sigmask;
590c73ebb68SHao Xu 	__u32	sigmask_sz;
591c73ebb68SHao Xu 	__u32	pad;
592c73ebb68SHao Xu 	__u64	ts;
593c73ebb68SHao Xu };
594c73ebb68SHao Xu 
59578a861b9SJens Axboe /*
59678a861b9SJens Axboe  * Argument for IORING_REGISTER_SYNC_CANCEL
59778a861b9SJens Axboe  */
59878a861b9SJens Axboe struct io_uring_sync_cancel_reg {
59978a861b9SJens Axboe 	__u64				addr;
60078a861b9SJens Axboe 	__s32				fd;
60178a861b9SJens Axboe 	__u32				flags;
60278a861b9SJens Axboe 	struct __kernel_timespec	timeout;
60378a861b9SJens Axboe 	__u64				pad[4];
60478a861b9SJens Axboe };
60578a861b9SJens Axboe 
6066e73dffbSPavel Begunkov /*
6076e73dffbSPavel Begunkov  * Argument for IORING_REGISTER_FILE_ALLOC_RANGE
6086e73dffbSPavel Begunkov  * The range is specified as [off, off + len)
6096e73dffbSPavel Begunkov  */
6106e73dffbSPavel Begunkov struct io_uring_file_index_range {
6116e73dffbSPavel Begunkov 	__u32	off;
6126e73dffbSPavel Begunkov 	__u32	len;
6136e73dffbSPavel Begunkov 	__u64	resv;
6146e73dffbSPavel Begunkov };
6156e73dffbSPavel Begunkov 
6162b188cc1SJens Axboe #endif
617