xref: /linux/include/uapi/linux/io_uring.h (revision 8fcf4c48f44bd7b1b75db139f56ff1ad6477379e)
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;
542b188cc1SJens Axboe 	};
552b188cc1SJens Axboe 	__u64	user_data;	/* data to be passed back at completion time */
56ddf0322dSJens Axboe 	/* pack this to avoid bogus arm OABI complaints */
57ddf0322dSJens Axboe 	union {
5875c6a039SJens Axboe 		/* index into fixed buffers, if used */
5975c6a039SJens Axboe 		__u16	buf_index;
60ddf0322dSJens Axboe 		/* for grouped buffer selection */
61ddf0322dSJens Axboe 		__u16	buf_group;
62ddf0322dSJens Axboe 	} __attribute__((packed));
6375c6a039SJens Axboe 	/* personality to use, if used */
6475c6a039SJens Axboe 	__u16	personality;
65b9445598SPavel Begunkov 	union {
667d67af2cSPavel Begunkov 		__s32	splice_fd_in;
67b9445598SPavel Begunkov 		__u32	file_index;
68b9445598SPavel Begunkov 	};
69ee692a21SJens Axboe 	union {
70ee692a21SJens Axboe 		struct {
71e9621e2bSStefan Roesch 			__u64	addr3;
72e9621e2bSStefan Roesch 			__u64	__pad2[1];
73edafcceeSJens Axboe 		};
74ebdeb7c0SJens Axboe 		/*
75ee692a21SJens Axboe 		 * If the ring is initialized with IORING_SETUP_SQE128, then
76ee692a21SJens Axboe 		 * this field is used for 80 bytes of arbitrary command data
77ebdeb7c0SJens Axboe 		 */
78ee692a21SJens Axboe 		__u8	cmd[0];
79ee692a21SJens Axboe 	};
802b188cc1SJens Axboe };
812b188cc1SJens Axboe 
821339f24bSJens Axboe /*
831339f24bSJens Axboe  * If sqe->file_index is set to this for opcodes that instantiate a new
841339f24bSJens Axboe  * direct descriptor (like openat/openat2/accept), then io_uring will allocate
851339f24bSJens Axboe  * an available direct descriptor instead of having the application pass one
861339f24bSJens Axboe  * in. The picked direct descriptor will be returned in cqe->res, or -ENFILE
871339f24bSJens Axboe  * if the space is full.
881339f24bSJens Axboe  */
891339f24bSJens Axboe #define IORING_FILE_INDEX_ALLOC		(~0U)
901339f24bSJens Axboe 
916b47ee6eSPavel Begunkov enum {
926b47ee6eSPavel Begunkov 	IOSQE_FIXED_FILE_BIT,
936b47ee6eSPavel Begunkov 	IOSQE_IO_DRAIN_BIT,
946b47ee6eSPavel Begunkov 	IOSQE_IO_LINK_BIT,
956b47ee6eSPavel Begunkov 	IOSQE_IO_HARDLINK_BIT,
966b47ee6eSPavel Begunkov 	IOSQE_ASYNC_BIT,
97bcda7baaSJens Axboe 	IOSQE_BUFFER_SELECT_BIT,
9804c76b41SPavel Begunkov 	IOSQE_CQE_SKIP_SUCCESS_BIT,
996b47ee6eSPavel Begunkov };
1006b47ee6eSPavel Begunkov 
101def596e9SJens Axboe /*
1026b06314cSJens Axboe  * sqe->flags
1036b06314cSJens Axboe  */
1046b47ee6eSPavel Begunkov /* use fixed fileset */
1056b47ee6eSPavel Begunkov #define IOSQE_FIXED_FILE	(1U << IOSQE_FIXED_FILE_BIT)
1066b47ee6eSPavel Begunkov /* issue after inflight IO */
1076b47ee6eSPavel Begunkov #define IOSQE_IO_DRAIN		(1U << IOSQE_IO_DRAIN_BIT)
1086b47ee6eSPavel Begunkov /* links next sqe */
1096b47ee6eSPavel Begunkov #define IOSQE_IO_LINK		(1U << IOSQE_IO_LINK_BIT)
1106b47ee6eSPavel Begunkov /* like LINK, but stronger */
1116b47ee6eSPavel Begunkov #define IOSQE_IO_HARDLINK	(1U << IOSQE_IO_HARDLINK_BIT)
1126b47ee6eSPavel Begunkov /* always go async */
1136b47ee6eSPavel Begunkov #define IOSQE_ASYNC		(1U << IOSQE_ASYNC_BIT)
114bcda7baaSJens Axboe /* select buffer from sqe->buf_group */
115bcda7baaSJens Axboe #define IOSQE_BUFFER_SELECT	(1U << IOSQE_BUFFER_SELECT_BIT)
11604c76b41SPavel Begunkov /* don't post CQE if request succeeded */
11704c76b41SPavel Begunkov #define IOSQE_CQE_SKIP_SUCCESS	(1U << IOSQE_CQE_SKIP_SUCCESS_BIT)
1186b06314cSJens Axboe 
1196b06314cSJens Axboe /*
120def596e9SJens Axboe  * io_uring_setup() flags
121def596e9SJens Axboe  */
122def596e9SJens Axboe #define IORING_SETUP_IOPOLL	(1U << 0)	/* io_context is polled */
1236c271ce2SJens Axboe #define IORING_SETUP_SQPOLL	(1U << 1)	/* SQ poll thread */
1246c271ce2SJens Axboe #define IORING_SETUP_SQ_AFF	(1U << 2)	/* sq_thread_cpu is valid */
12533a107f0SJens Axboe #define IORING_SETUP_CQSIZE	(1U << 3)	/* app defines CQ size */
1268110c1a6SJens Axboe #define IORING_SETUP_CLAMP	(1U << 4)	/* clamp SQ/CQ ring sizes */
12724369c2eSPavel Begunkov #define IORING_SETUP_ATTACH_WQ	(1U << 5)	/* attach to existing wq */
1287e84e1c7SStefano Garzarella #define IORING_SETUP_R_DISABLED	(1U << 6)	/* start with ring disabled */
129bcbb7bf6SJens Axboe #define IORING_SETUP_SUBMIT_ALL	(1U << 7)	/* continue submit on error */
130e1169f06SJens Axboe /*
131e1169f06SJens Axboe  * Cooperative task running. When requests complete, they often require
132e1169f06SJens Axboe  * forcing the submitter to transition to the kernel to complete. If this
133e1169f06SJens Axboe  * flag is set, work will be done when the task transitions anyway, rather
134e1169f06SJens Axboe  * than force an inter-processor interrupt reschedule. This avoids interrupting
135e1169f06SJens Axboe  * a task running in userspace, and saves an IPI.
136e1169f06SJens Axboe  */
137e1169f06SJens Axboe #define IORING_SETUP_COOP_TASKRUN	(1U << 8)
138ef060ea9SJens Axboe /*
139ef060ea9SJens Axboe  * If COOP_TASKRUN is set, get notified if task work is available for
140ef060ea9SJens Axboe  * running and a kernel transition would be needed to run it. This sets
141ef060ea9SJens Axboe  * IORING_SQ_TASKRUN in the sq ring flags. Not valid with COOP_TASKRUN.
142ef060ea9SJens Axboe  */
143ef060ea9SJens Axboe #define IORING_SETUP_TASKRUN_FLAG	(1U << 9)
144ebdeb7c0SJens Axboe #define IORING_SETUP_SQE128		(1U << 10) /* SQEs are 128 byte */
1457a51e5b4SStefan Roesch #define IORING_SETUP_CQE32		(1U << 11) /* CQEs are 32 byte */
14697bbdc06SPavel Begunkov /*
14797bbdc06SPavel Begunkov  * Only one task is allowed to submit requests
14897bbdc06SPavel Begunkov  */
14997bbdc06SPavel Begunkov #define IORING_SETUP_SINGLE_ISSUER	(1U << 12)
150ebdeb7c0SJens Axboe 
151cc51eaa8SDylan Yudaken enum io_uring_op {
1529e3aa61aSJens Axboe 	IORING_OP_NOP,
1539e3aa61aSJens Axboe 	IORING_OP_READV,
1549e3aa61aSJens Axboe 	IORING_OP_WRITEV,
1559e3aa61aSJens Axboe 	IORING_OP_FSYNC,
1569e3aa61aSJens Axboe 	IORING_OP_READ_FIXED,
1579e3aa61aSJens Axboe 	IORING_OP_WRITE_FIXED,
1589e3aa61aSJens Axboe 	IORING_OP_POLL_ADD,
1599e3aa61aSJens Axboe 	IORING_OP_POLL_REMOVE,
1609e3aa61aSJens Axboe 	IORING_OP_SYNC_FILE_RANGE,
1619e3aa61aSJens Axboe 	IORING_OP_SENDMSG,
1629e3aa61aSJens Axboe 	IORING_OP_RECVMSG,
1639e3aa61aSJens Axboe 	IORING_OP_TIMEOUT,
1649e3aa61aSJens Axboe 	IORING_OP_TIMEOUT_REMOVE,
1659e3aa61aSJens Axboe 	IORING_OP_ACCEPT,
1669e3aa61aSJens Axboe 	IORING_OP_ASYNC_CANCEL,
1679e3aa61aSJens Axboe 	IORING_OP_LINK_TIMEOUT,
1689e3aa61aSJens Axboe 	IORING_OP_CONNECT,
169d63d1b5eSJens Axboe 	IORING_OP_FALLOCATE,
17015b71abeSJens Axboe 	IORING_OP_OPENAT,
171b5dba59eSJens Axboe 	IORING_OP_CLOSE,
17205f3fb3cSJens Axboe 	IORING_OP_FILES_UPDATE,
173eddc7ef5SJens Axboe 	IORING_OP_STATX,
1743a6820f2SJens Axboe 	IORING_OP_READ,
1753a6820f2SJens Axboe 	IORING_OP_WRITE,
1764840e418SJens Axboe 	IORING_OP_FADVISE,
177c1ca757bSJens Axboe 	IORING_OP_MADVISE,
178fddafaceSJens Axboe 	IORING_OP_SEND,
179fddafaceSJens Axboe 	IORING_OP_RECV,
180cebdb986SJens Axboe 	IORING_OP_OPENAT2,
1813e4827b0SJens Axboe 	IORING_OP_EPOLL_CTL,
1827d67af2cSPavel Begunkov 	IORING_OP_SPLICE,
183ddf0322dSJens Axboe 	IORING_OP_PROVIDE_BUFFERS,
184067524e9SJens Axboe 	IORING_OP_REMOVE_BUFFERS,
185f2a8d5c7SPavel Begunkov 	IORING_OP_TEE,
18636f4fa68SJens Axboe 	IORING_OP_SHUTDOWN,
18780a261fdSJens Axboe 	IORING_OP_RENAMEAT,
18814a1143bSJens Axboe 	IORING_OP_UNLINKAT,
189e34a02dcSDmitry Kadashev 	IORING_OP_MKDIRAT,
1907a8721f8SDmitry Kadashev 	IORING_OP_SYMLINKAT,
191cf30da90SDmitry Kadashev 	IORING_OP_LINKAT,
1924f57f06cSJens Axboe 	IORING_OP_MSG_RING,
193e9621e2bSStefan Roesch 	IORING_OP_FSETXATTR,
194e9621e2bSStefan Roesch 	IORING_OP_SETXATTR,
195a56834e0SStefan Roesch 	IORING_OP_FGETXATTR,
196a56834e0SStefan Roesch 	IORING_OP_GETXATTR,
1971374e08eSJens Axboe 	IORING_OP_SOCKET,
198ee692a21SJens Axboe 	IORING_OP_URING_CMD,
1999e3aa61aSJens Axboe 
2009e3aa61aSJens Axboe 	/* this goes last, obviously */
2019e3aa61aSJens Axboe 	IORING_OP_LAST,
2029e3aa61aSJens Axboe };
203c992fe29SChristoph Hellwig 
204c992fe29SChristoph Hellwig /*
205c992fe29SChristoph Hellwig  * sqe->fsync_flags
206c992fe29SChristoph Hellwig  */
207c992fe29SChristoph Hellwig #define IORING_FSYNC_DATASYNC	(1U << 0)
2082b188cc1SJens Axboe 
2092b188cc1SJens Axboe /*
210a41525abSJens Axboe  * sqe->timeout_flags
211a41525abSJens Axboe  */
212a41525abSJens Axboe #define IORING_TIMEOUT_ABS		(1U << 0)
2139c8e11b3SPavel Begunkov #define IORING_TIMEOUT_UPDATE		(1U << 1)
21450c1df2bSJens Axboe #define IORING_TIMEOUT_BOOTTIME		(1U << 2)
21550c1df2bSJens Axboe #define IORING_TIMEOUT_REALTIME		(1U << 3)
216f1042b6cSPavel Begunkov #define IORING_LINK_TIMEOUT_UPDATE	(1U << 4)
2176224590dSPavel Begunkov #define IORING_TIMEOUT_ETIME_SUCCESS	(1U << 5)
21850c1df2bSJens Axboe #define IORING_TIMEOUT_CLOCK_MASK	(IORING_TIMEOUT_BOOTTIME | IORING_TIMEOUT_REALTIME)
219f1042b6cSPavel Begunkov #define IORING_TIMEOUT_UPDATE_MASK	(IORING_TIMEOUT_UPDATE | IORING_LINK_TIMEOUT_UPDATE)
220a41525abSJens Axboe /*
2217d67af2cSPavel Begunkov  * sqe->splice_flags
2227d67af2cSPavel Begunkov  * extends splice(2) flags
2237d67af2cSPavel Begunkov  */
2247d67af2cSPavel Begunkov #define SPLICE_F_FD_IN_FIXED	(1U << 31) /* the last bit of __u32 */
2257d67af2cSPavel Begunkov 
2267d67af2cSPavel Begunkov /*
22788e41cf9SJens Axboe  * POLL_ADD flags. Note that since sqe->poll_events is the flag space, the
22888e41cf9SJens Axboe  * command flags for POLL_ADD are stored in sqe->len.
22988e41cf9SJens Axboe  *
23088e41cf9SJens Axboe  * IORING_POLL_ADD_MULTI	Multishot poll. Sets IORING_CQE_F_MORE if
23188e41cf9SJens Axboe  *				the poll handler will continue to report
23288e41cf9SJens Axboe  *				CQEs on behalf of the same SQE.
233b69de288SJens Axboe  *
234b69de288SJens Axboe  * IORING_POLL_UPDATE		Update existing poll request, matching
235b69de288SJens Axboe  *				sqe->addr as the old user_data field.
236b9ba8a44SJens Axboe  *
237b9ba8a44SJens Axboe  * IORING_POLL_LEVEL		Level triggered poll.
23888e41cf9SJens Axboe  */
23988e41cf9SJens Axboe #define IORING_POLL_ADD_MULTI	(1U << 0)
240b69de288SJens Axboe #define IORING_POLL_UPDATE_EVENTS	(1U << 1)
241b69de288SJens Axboe #define IORING_POLL_UPDATE_USER_DATA	(1U << 2)
242b9ba8a44SJens Axboe #define IORING_POLL_ADD_LEVEL		(1U << 3)
24388e41cf9SJens Axboe 
24488e41cf9SJens Axboe /*
2458e29da69SJens Axboe  * ASYNC_CANCEL flags.
2468e29da69SJens Axboe  *
2478e29da69SJens Axboe  * IORING_ASYNC_CANCEL_ALL	Cancel all requests that match the given key
2484bf94615SJens Axboe  * IORING_ASYNC_CANCEL_FD	Key off 'fd' for cancelation rather than the
2494bf94615SJens Axboe  *				request 'user_data'
250970f256eSJens Axboe  * IORING_ASYNC_CANCEL_ANY	Match any request
2517d8ca725SJens Axboe  * IORING_ASYNC_CANCEL_FD_FIXED	'fd' passed in is a fixed descriptor
2528e29da69SJens Axboe  */
2538e29da69SJens Axboe #define IORING_ASYNC_CANCEL_ALL	(1U << 0)
2544bf94615SJens Axboe #define IORING_ASYNC_CANCEL_FD	(1U << 1)
255970f256eSJens Axboe #define IORING_ASYNC_CANCEL_ANY	(1U << 2)
2567d8ca725SJens Axboe #define IORING_ASYNC_CANCEL_FD_FIXED	(1U << 3)
2578e29da69SJens Axboe 
2588e29da69SJens Axboe /*
25929c1ac23SPavel Begunkov  * send/sendmsg and recv/recvmsg flags (sqe->ioprio)
2600455d4ccSJens Axboe  *
2610455d4ccSJens Axboe  * IORING_RECVSEND_POLL_FIRST	If set, instead of first attempting to send
2620455d4ccSJens Axboe  *				or receive and arm poll if that yields an
2630455d4ccSJens Axboe  *				-EAGAIN result, arm poll upfront and skip
2640455d4ccSJens Axboe  *				the initial transfer attempt.
2650455d4ccSJens Axboe  */
2660455d4ccSJens Axboe #define IORING_RECVSEND_POLL_FIRST	(1U << 0)
2670455d4ccSJens Axboe 
2680455d4ccSJens Axboe /*
269390ed29bSHao Xu  * accept flags stored in sqe->ioprio
270390ed29bSHao Xu  */
271390ed29bSHao Xu #define IORING_ACCEPT_MULTISHOT	(1U << 0)
272390ed29bSHao Xu 
273390ed29bSHao Xu /*
2742b188cc1SJens Axboe  * IO completion data structure (Completion Queue Entry)
2752b188cc1SJens Axboe  */
2762b188cc1SJens Axboe struct io_uring_cqe {
2772b188cc1SJens Axboe 	__u64	user_data;	/* sqe->data submission passed back */
2782b188cc1SJens Axboe 	__s32	res;		/* result code for this event */
2792b188cc1SJens Axboe 	__u32	flags;
2807a51e5b4SStefan Roesch 
2817a51e5b4SStefan Roesch 	/*
2827a51e5b4SStefan Roesch 	 * If the ring is initialized with IORING_SETUP_CQE32, then this field
2837a51e5b4SStefan Roesch 	 * contains 16-bytes of padding, doubling the size of the CQE.
2847a51e5b4SStefan Roesch 	 */
2857a51e5b4SStefan Roesch 	__u64 big_cqe[];
2862b188cc1SJens Axboe };
2872b188cc1SJens Axboe 
2882b188cc1SJens Axboe /*
289bcda7baaSJens Axboe  * cqe->flags
290bcda7baaSJens Axboe  *
291bcda7baaSJens Axboe  * IORING_CQE_F_BUFFER	If set, the upper 16 bits are the buffer ID
29288e41cf9SJens Axboe  * IORING_CQE_F_MORE	If set, parent SQE will generate more CQE entries
293f548a12eSJens Axboe  * IORING_CQE_F_SOCK_NONEMPTY	If set, more data to read after socket recv
294bcda7baaSJens Axboe  */
295bcda7baaSJens Axboe #define IORING_CQE_F_BUFFER		(1U << 0)
29688e41cf9SJens Axboe #define IORING_CQE_F_MORE		(1U << 1)
297f548a12eSJens Axboe #define IORING_CQE_F_SOCK_NONEMPTY	(1U << 2)
298bcda7baaSJens Axboe 
299bcda7baaSJens Axboe enum {
300bcda7baaSJens Axboe 	IORING_CQE_BUFFER_SHIFT		= 16,
301bcda7baaSJens Axboe };
302bcda7baaSJens Axboe 
303bcda7baaSJens Axboe /*
3042b188cc1SJens Axboe  * Magic offsets for the application to mmap the data it needs
3052b188cc1SJens Axboe  */
3062b188cc1SJens Axboe #define IORING_OFF_SQ_RING		0ULL
3072b188cc1SJens Axboe #define IORING_OFF_CQ_RING		0x8000000ULL
3082b188cc1SJens Axboe #define IORING_OFF_SQES			0x10000000ULL
3092b188cc1SJens Axboe 
3102b188cc1SJens Axboe /*
3112b188cc1SJens Axboe  * Filled with the offset for mmap(2)
3122b188cc1SJens Axboe  */
3132b188cc1SJens Axboe struct io_sqring_offsets {
3142b188cc1SJens Axboe 	__u32 head;
3152b188cc1SJens Axboe 	__u32 tail;
3162b188cc1SJens Axboe 	__u32 ring_mask;
3172b188cc1SJens Axboe 	__u32 ring_entries;
3182b188cc1SJens Axboe 	__u32 flags;
3192b188cc1SJens Axboe 	__u32 dropped;
3202b188cc1SJens Axboe 	__u32 array;
3212b188cc1SJens Axboe 	__u32 resv1;
3222b188cc1SJens Axboe 	__u64 resv2;
3232b188cc1SJens Axboe };
3242b188cc1SJens Axboe 
3256c271ce2SJens Axboe /*
3266c271ce2SJens Axboe  * sq_ring->flags
3276c271ce2SJens Axboe  */
3286c271ce2SJens Axboe #define IORING_SQ_NEED_WAKEUP	(1U << 0) /* needs io_uring_enter wakeup */
3296d5f9049SXiaoguang Wang #define IORING_SQ_CQ_OVERFLOW	(1U << 1) /* CQ ring is overflown */
330ef060ea9SJens Axboe #define IORING_SQ_TASKRUN	(1U << 2) /* task should enter the kernel */
3316c271ce2SJens Axboe 
3322b188cc1SJens Axboe struct io_cqring_offsets {
3332b188cc1SJens Axboe 	__u32 head;
3342b188cc1SJens Axboe 	__u32 tail;
3352b188cc1SJens Axboe 	__u32 ring_mask;
3362b188cc1SJens Axboe 	__u32 ring_entries;
3372b188cc1SJens Axboe 	__u32 overflow;
3382b188cc1SJens Axboe 	__u32 cqes;
3390d9b5b3aSStefano Garzarella 	__u32 flags;
3400d9b5b3aSStefano Garzarella 	__u32 resv1;
3410d9b5b3aSStefano Garzarella 	__u64 resv2;
3422b188cc1SJens Axboe };
3432b188cc1SJens Axboe 
3442b188cc1SJens Axboe /*
3457e55a19cSStefano Garzarella  * cq_ring->flags
3467e55a19cSStefano Garzarella  */
3477e55a19cSStefano Garzarella 
3487e55a19cSStefano Garzarella /* disable eventfd notifications */
3497e55a19cSStefano Garzarella #define IORING_CQ_EVENTFD_DISABLED	(1U << 0)
3507e55a19cSStefano Garzarella 
3517e55a19cSStefano Garzarella /*
3522b188cc1SJens Axboe  * io_uring_enter(2) flags
3532b188cc1SJens Axboe  */
3542b188cc1SJens Axboe #define IORING_ENTER_GETEVENTS		(1U << 0)
3556c271ce2SJens Axboe #define IORING_ENTER_SQ_WAKEUP		(1U << 1)
35690554200SJens Axboe #define IORING_ENTER_SQ_WAIT		(1U << 2)
357c73ebb68SHao Xu #define IORING_ENTER_EXT_ARG		(1U << 3)
358e7a6c00dSJens Axboe #define IORING_ENTER_REGISTERED_RING	(1U << 4)
3592b188cc1SJens Axboe 
3602b188cc1SJens Axboe /*
3612b188cc1SJens Axboe  * Passed in for io_uring_setup(2). Copied back with updated info on success
3622b188cc1SJens Axboe  */
3632b188cc1SJens Axboe struct io_uring_params {
3642b188cc1SJens Axboe 	__u32 sq_entries;
3652b188cc1SJens Axboe 	__u32 cq_entries;
3662b188cc1SJens Axboe 	__u32 flags;
3676c271ce2SJens Axboe 	__u32 sq_thread_cpu;
3686c271ce2SJens Axboe 	__u32 sq_thread_idle;
369ac90f249SJens Axboe 	__u32 features;
37024369c2eSPavel Begunkov 	__u32 wq_fd;
37124369c2eSPavel Begunkov 	__u32 resv[3];
3722b188cc1SJens Axboe 	struct io_sqring_offsets sq_off;
3732b188cc1SJens Axboe 	struct io_cqring_offsets cq_off;
3742b188cc1SJens Axboe };
3752b188cc1SJens Axboe 
376edafcceeSJens Axboe /*
377ac90f249SJens Axboe  * io_uring_params->features flags
378ac90f249SJens Axboe  */
379ac90f249SJens Axboe #define IORING_FEAT_SINGLE_MMAP		(1U << 0)
3801d7bb1d5SJens Axboe #define IORING_FEAT_NODROP		(1U << 1)
381da8c9690SJens Axboe #define IORING_FEAT_SUBMIT_STABLE	(1U << 2)
382ba04291eSJens Axboe #define IORING_FEAT_RW_CUR_POS		(1U << 3)
383cccf0ee8SJens Axboe #define IORING_FEAT_CUR_PERSONALITY	(1U << 4)
384d7718a9dSJens Axboe #define IORING_FEAT_FAST_POLL		(1U << 5)
3855769a351SJiufei Xue #define IORING_FEAT_POLL_32BITS 	(1U << 6)
38628cea78aSJens Axboe #define IORING_FEAT_SQPOLL_NONFIXED	(1U << 7)
387c73ebb68SHao Xu #define IORING_FEAT_EXT_ARG		(1U << 8)
3881c0aa1faSJens Axboe #define IORING_FEAT_NATIVE_WORKERS	(1U << 9)
3899690557eSPavel Begunkov #define IORING_FEAT_RSRC_TAGS		(1U << 10)
39004c76b41SPavel Begunkov #define IORING_FEAT_CQE_SKIP		(1U << 11)
391c4212f3eSJens Axboe #define IORING_FEAT_LINKED_FILE		(1U << 12)
392ac90f249SJens Axboe 
393ac90f249SJens Axboe /*
394edafcceeSJens Axboe  * io_uring_register(2) opcodes and arguments
395edafcceeSJens Axboe  */
3969d4a75efSStefano Garzarella enum {
3979d4a75efSStefano Garzarella 	IORING_REGISTER_BUFFERS			= 0,
3989d4a75efSStefano Garzarella 	IORING_UNREGISTER_BUFFERS		= 1,
3999d4a75efSStefano Garzarella 	IORING_REGISTER_FILES			= 2,
4009d4a75efSStefano Garzarella 	IORING_UNREGISTER_FILES			= 3,
4019d4a75efSStefano Garzarella 	IORING_REGISTER_EVENTFD			= 4,
4029d4a75efSStefano Garzarella 	IORING_UNREGISTER_EVENTFD		= 5,
4039d4a75efSStefano Garzarella 	IORING_REGISTER_FILES_UPDATE		= 6,
4049d4a75efSStefano Garzarella 	IORING_REGISTER_EVENTFD_ASYNC		= 7,
4059d4a75efSStefano Garzarella 	IORING_REGISTER_PROBE			= 8,
4069d4a75efSStefano Garzarella 	IORING_REGISTER_PERSONALITY		= 9,
4079d4a75efSStefano Garzarella 	IORING_UNREGISTER_PERSONALITY		= 10,
40821b55dbcSStefano Garzarella 	IORING_REGISTER_RESTRICTIONS		= 11,
4097e84e1c7SStefano Garzarella 	IORING_REGISTER_ENABLE_RINGS		= 12,
410992da01aSPavel Begunkov 
411992da01aSPavel Begunkov 	/* extended with tagging */
412992da01aSPavel Begunkov 	IORING_REGISTER_FILES2			= 13,
413992da01aSPavel Begunkov 	IORING_REGISTER_FILES_UPDATE2		= 14,
414992da01aSPavel Begunkov 	IORING_REGISTER_BUFFERS2		= 15,
415992da01aSPavel Begunkov 	IORING_REGISTER_BUFFERS_UPDATE		= 16,
4169d4a75efSStefano Garzarella 
417fe76421dSJens Axboe 	/* set/clear io-wq thread affinities */
418fe76421dSJens Axboe 	IORING_REGISTER_IOWQ_AFF		= 17,
419fe76421dSJens Axboe 	IORING_UNREGISTER_IOWQ_AFF		= 18,
420fe76421dSJens Axboe 
421dd47c104SEugene Syromiatnikov 	/* set/get max number of io-wq workers */
4222e480058SJens Axboe 	IORING_REGISTER_IOWQ_MAX_WORKERS	= 19,
4232e480058SJens Axboe 
424e7a6c00dSJens Axboe 	/* register/unregister io_uring fd with the ring */
425e7a6c00dSJens Axboe 	IORING_REGISTER_RING_FDS		= 20,
426e7a6c00dSJens Axboe 	IORING_UNREGISTER_RING_FDS		= 21,
427e7a6c00dSJens Axboe 
428c7fb1942SJens Axboe 	/* register ring based provide buffer group */
429c7fb1942SJens Axboe 	IORING_REGISTER_PBUF_RING		= 22,
430c7fb1942SJens Axboe 	IORING_UNREGISTER_PBUF_RING		= 23,
431c7fb1942SJens Axboe 
43278a861b9SJens Axboe 	/* sync cancelation API */
43378a861b9SJens Axboe 	IORING_REGISTER_SYNC_CANCEL		= 24,
43478a861b9SJens Axboe 
4359d4a75efSStefano Garzarella 	/* this goes last */
4369d4a75efSStefano Garzarella 	IORING_REGISTER_LAST
4379d4a75efSStefano Garzarella };
438c3a31e60SJens Axboe 
439dd47c104SEugene Syromiatnikov /* io-wq worker categories */
440dd47c104SEugene Syromiatnikov enum {
441dd47c104SEugene Syromiatnikov 	IO_WQ_BOUND,
442dd47c104SEugene Syromiatnikov 	IO_WQ_UNBOUND,
443dd47c104SEugene Syromiatnikov };
444dd47c104SEugene Syromiatnikov 
445269bbe5fSBijan Mottahedeh /* deprecated, see struct io_uring_rsrc_update */
446c3a31e60SJens Axboe struct io_uring_files_update {
447c3a31e60SJens Axboe 	__u32 offset;
4481292e972SEugene Syromiatnikov 	__u32 resv;
4491292e972SEugene Syromiatnikov 	__aligned_u64 /* __s32 * */ fds;
450c3a31e60SJens Axboe };
451edafcceeSJens Axboe 
452a8da73a3SJens Axboe /*
453a8da73a3SJens Axboe  * Register a fully sparse file space, rather than pass in an array of all
454a8da73a3SJens Axboe  * -1 file descriptors.
455a8da73a3SJens Axboe  */
456a8da73a3SJens Axboe #define IORING_RSRC_REGISTER_SPARSE	(1U << 0)
457a8da73a3SJens Axboe 
458792e3582SPavel Begunkov struct io_uring_rsrc_register {
459792e3582SPavel Begunkov 	__u32 nr;
460a8da73a3SJens Axboe 	__u32 flags;
461992da01aSPavel Begunkov 	__u64 resv2;
462792e3582SPavel Begunkov 	__aligned_u64 data;
463792e3582SPavel Begunkov 	__aligned_u64 tags;
464792e3582SPavel Begunkov };
465792e3582SPavel Begunkov 
466c3bdad02SPavel Begunkov struct io_uring_rsrc_update {
467c3bdad02SPavel Begunkov 	__u32 offset;
468c3bdad02SPavel Begunkov 	__u32 resv;
469c3bdad02SPavel Begunkov 	__aligned_u64 data;
470c3bdad02SPavel Begunkov };
471c3bdad02SPavel Begunkov 
472c3bdad02SPavel Begunkov struct io_uring_rsrc_update2 {
473c3bdad02SPavel Begunkov 	__u32 offset;
474c3bdad02SPavel Begunkov 	__u32 resv;
475c3bdad02SPavel Begunkov 	__aligned_u64 data;
476c3bdad02SPavel Begunkov 	__aligned_u64 tags;
477c3bdad02SPavel Begunkov 	__u32 nr;
478992da01aSPavel Begunkov 	__u32 resv2;
479c3bdad02SPavel Begunkov };
480c3bdad02SPavel Begunkov 
4814e0377a1Snoah /* Skip updating fd indexes set to this value in the fd table */
4824e0377a1Snoah #define IORING_REGISTER_FILES_SKIP	(-2)
4834e0377a1Snoah 
48466f4af93SJens Axboe #define IO_URING_OP_SUPPORTED	(1U << 0)
48566f4af93SJens Axboe 
48666f4af93SJens Axboe struct io_uring_probe_op {
48766f4af93SJens Axboe 	__u8 op;
48866f4af93SJens Axboe 	__u8 resv;
48966f4af93SJens Axboe 	__u16 flags;	/* IO_URING_OP_* flags */
49066f4af93SJens Axboe 	__u32 resv2;
49166f4af93SJens Axboe };
49266f4af93SJens Axboe 
49366f4af93SJens Axboe struct io_uring_probe {
49466f4af93SJens Axboe 	__u8 last_op;	/* last opcode supported */
49566f4af93SJens Axboe 	__u8 ops_len;	/* length of ops[] array below */
49666f4af93SJens Axboe 	__u16 resv;
49766f4af93SJens Axboe 	__u32 resv2[3];
498*8fcf4c48SGustavo A. R. Silva 	struct io_uring_probe_op ops[];
49966f4af93SJens Axboe };
50066f4af93SJens Axboe 
50121b55dbcSStefano Garzarella struct io_uring_restriction {
50221b55dbcSStefano Garzarella 	__u16 opcode;
50321b55dbcSStefano Garzarella 	union {
50421b55dbcSStefano Garzarella 		__u8 register_op; /* IORING_RESTRICTION_REGISTER_OP */
50521b55dbcSStefano Garzarella 		__u8 sqe_op;      /* IORING_RESTRICTION_SQE_OP */
50621b55dbcSStefano Garzarella 		__u8 sqe_flags;   /* IORING_RESTRICTION_SQE_FLAGS_* */
50721b55dbcSStefano Garzarella 	};
50821b55dbcSStefano Garzarella 	__u8 resv;
50921b55dbcSStefano Garzarella 	__u32 resv2[3];
51021b55dbcSStefano Garzarella };
51121b55dbcSStefano Garzarella 
512c7fb1942SJens Axboe struct io_uring_buf {
513c7fb1942SJens Axboe 	__u64	addr;
514c7fb1942SJens Axboe 	__u32	len;
515c7fb1942SJens Axboe 	__u16	bid;
516c7fb1942SJens Axboe 	__u16	resv;
517c7fb1942SJens Axboe };
518c7fb1942SJens Axboe 
519c7fb1942SJens Axboe struct io_uring_buf_ring {
520c7fb1942SJens Axboe 	union {
521c7fb1942SJens Axboe 		/*
522c7fb1942SJens Axboe 		 * To avoid spilling into more pages than we need to, the
523c7fb1942SJens Axboe 		 * ring tail is overlaid with the io_uring_buf->resv field.
524c7fb1942SJens Axboe 		 */
525c7fb1942SJens Axboe 		struct {
526c7fb1942SJens Axboe 			__u64	resv1;
527c7fb1942SJens Axboe 			__u32	resv2;
528c7fb1942SJens Axboe 			__u16	resv3;
529c7fb1942SJens Axboe 			__u16	tail;
530c7fb1942SJens Axboe 		};
531c7fb1942SJens Axboe 		struct io_uring_buf	bufs[0];
532c7fb1942SJens Axboe 	};
533c7fb1942SJens Axboe };
534c7fb1942SJens Axboe 
535c7fb1942SJens Axboe /* argument for IORING_(UN)REGISTER_PBUF_RING */
536c7fb1942SJens Axboe struct io_uring_buf_reg {
537c7fb1942SJens Axboe 	__u64	ring_addr;
538c7fb1942SJens Axboe 	__u32	ring_entries;
539c7fb1942SJens Axboe 	__u16	bgid;
540c7fb1942SJens Axboe 	__u16	pad;
541c7fb1942SJens Axboe 	__u64	resv[3];
542c7fb1942SJens Axboe };
543c7fb1942SJens Axboe 
54421b55dbcSStefano Garzarella /*
54521b55dbcSStefano Garzarella  * io_uring_restriction->opcode values
54621b55dbcSStefano Garzarella  */
54721b55dbcSStefano Garzarella enum {
54821b55dbcSStefano Garzarella 	/* Allow an io_uring_register(2) opcode */
54921b55dbcSStefano Garzarella 	IORING_RESTRICTION_REGISTER_OP		= 0,
55021b55dbcSStefano Garzarella 
55121b55dbcSStefano Garzarella 	/* Allow an sqe opcode */
55221b55dbcSStefano Garzarella 	IORING_RESTRICTION_SQE_OP		= 1,
55321b55dbcSStefano Garzarella 
55421b55dbcSStefano Garzarella 	/* Allow sqe flags */
55521b55dbcSStefano Garzarella 	IORING_RESTRICTION_SQE_FLAGS_ALLOWED	= 2,
55621b55dbcSStefano Garzarella 
55721b55dbcSStefano Garzarella 	/* Require sqe flags (these flags must be set on each submission) */
55821b55dbcSStefano Garzarella 	IORING_RESTRICTION_SQE_FLAGS_REQUIRED	= 3,
55921b55dbcSStefano Garzarella 
56021b55dbcSStefano Garzarella 	IORING_RESTRICTION_LAST
56121b55dbcSStefano Garzarella };
56221b55dbcSStefano Garzarella 
563c73ebb68SHao Xu struct io_uring_getevents_arg {
564c73ebb68SHao Xu 	__u64	sigmask;
565c73ebb68SHao Xu 	__u32	sigmask_sz;
566c73ebb68SHao Xu 	__u32	pad;
567c73ebb68SHao Xu 	__u64	ts;
568c73ebb68SHao Xu };
569c73ebb68SHao Xu 
57078a861b9SJens Axboe /*
57178a861b9SJens Axboe  * Argument for IORING_REGISTER_SYNC_CANCEL
57278a861b9SJens Axboe  */
57378a861b9SJens Axboe struct io_uring_sync_cancel_reg {
57478a861b9SJens Axboe 	__u64				addr;
57578a861b9SJens Axboe 	__s32				fd;
57678a861b9SJens Axboe 	__u32				flags;
57778a861b9SJens Axboe 	struct __kernel_timespec	timeout;
57878a861b9SJens Axboe 	__u64				pad[4];
57978a861b9SJens Axboe };
58078a861b9SJens Axboe 
5812b188cc1SJens Axboe #endif
582