xref: /linux/include/uapi/linux/io_uring.h (revision c1ca757bd6f4632c510714631ddcc2d13030fe1e)
12b188cc1SJens Axboe /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
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>
132b188cc1SJens Axboe 
142b188cc1SJens Axboe /*
152b188cc1SJens Axboe  * IO submission data structure (Submission Queue Entry)
162b188cc1SJens Axboe  */
172b188cc1SJens Axboe struct io_uring_sqe {
182b188cc1SJens Axboe 	__u8	opcode;		/* type of operation for this sqe */
196b06314cSJens Axboe 	__u8	flags;		/* IOSQE_ flags */
202b188cc1SJens Axboe 	__u16	ioprio;		/* ioprio for the request */
212b188cc1SJens Axboe 	__s32	fd;		/* file descriptor to do IO on */
2217f2fe35SJens Axboe 	union {
232b188cc1SJens Axboe 		__u64	off;	/* offset into file */
2417f2fe35SJens Axboe 		__u64	addr2;
2517f2fe35SJens Axboe 	};
262b188cc1SJens Axboe 	__u64	addr;		/* pointer to buffer or iovecs */
272b188cc1SJens Axboe 	__u32	len;		/* buffer size or number of iovecs */
282b188cc1SJens Axboe 	union {
292b188cc1SJens Axboe 		__kernel_rwf_t	rw_flags;
30c992fe29SChristoph Hellwig 		__u32		fsync_flags;
31221c5eb2SJens Axboe 		__u16		poll_events;
325d17b4a4SJens Axboe 		__u32		sync_range_flags;
330fa03c62SJens Axboe 		__u32		msg_flags;
345262f567SJens Axboe 		__u32		timeout_flags;
3517f2fe35SJens Axboe 		__u32		accept_flags;
3662755e35SJens Axboe 		__u32		cancel_flags;
3715b71abeSJens Axboe 		__u32		open_flags;
38eddc7ef5SJens Axboe 		__u32		statx_flags;
394840e418SJens Axboe 		__u32		fadvise_advice;
402b188cc1SJens Axboe 	};
412b188cc1SJens Axboe 	__u64	user_data;	/* data to be passed back at completion time */
42edafcceeSJens Axboe 	union {
43edafcceeSJens Axboe 		__u16	buf_index;	/* index into fixed buffers, if used */
442b188cc1SJens Axboe 		__u64	__pad2[3];
452b188cc1SJens Axboe 	};
46edafcceeSJens Axboe };
472b188cc1SJens Axboe 
48def596e9SJens Axboe /*
496b06314cSJens Axboe  * sqe->flags
506b06314cSJens Axboe  */
516b06314cSJens Axboe #define IOSQE_FIXED_FILE	(1U << 0)	/* use fixed fileset */
52de0617e4SJens Axboe #define IOSQE_IO_DRAIN		(1U << 1)	/* issue after inflight IO */
539e645e11SJens Axboe #define IOSQE_IO_LINK		(1U << 2)	/* links next sqe */
544e88d6e7SJens Axboe #define IOSQE_IO_HARDLINK	(1U << 3)	/* like LINK, but stronger */
55ce35a47aSJens Axboe #define IOSQE_ASYNC		(1U << 4)	/* always go async */
566b06314cSJens Axboe 
576b06314cSJens Axboe /*
58def596e9SJens Axboe  * io_uring_setup() flags
59def596e9SJens Axboe  */
60def596e9SJens Axboe #define IORING_SETUP_IOPOLL	(1U << 0)	/* io_context is polled */
616c271ce2SJens Axboe #define IORING_SETUP_SQPOLL	(1U << 1)	/* SQ poll thread */
626c271ce2SJens Axboe #define IORING_SETUP_SQ_AFF	(1U << 2)	/* sq_thread_cpu is valid */
6333a107f0SJens Axboe #define IORING_SETUP_CQSIZE	(1U << 3)	/* app defines CQ size */
64def596e9SJens Axboe 
659e3aa61aSJens Axboe enum {
669e3aa61aSJens Axboe 	IORING_OP_NOP,
679e3aa61aSJens Axboe 	IORING_OP_READV,
689e3aa61aSJens Axboe 	IORING_OP_WRITEV,
699e3aa61aSJens Axboe 	IORING_OP_FSYNC,
709e3aa61aSJens Axboe 	IORING_OP_READ_FIXED,
719e3aa61aSJens Axboe 	IORING_OP_WRITE_FIXED,
729e3aa61aSJens Axboe 	IORING_OP_POLL_ADD,
739e3aa61aSJens Axboe 	IORING_OP_POLL_REMOVE,
749e3aa61aSJens Axboe 	IORING_OP_SYNC_FILE_RANGE,
759e3aa61aSJens Axboe 	IORING_OP_SENDMSG,
769e3aa61aSJens Axboe 	IORING_OP_RECVMSG,
779e3aa61aSJens Axboe 	IORING_OP_TIMEOUT,
789e3aa61aSJens Axboe 	IORING_OP_TIMEOUT_REMOVE,
799e3aa61aSJens Axboe 	IORING_OP_ACCEPT,
809e3aa61aSJens Axboe 	IORING_OP_ASYNC_CANCEL,
819e3aa61aSJens Axboe 	IORING_OP_LINK_TIMEOUT,
829e3aa61aSJens Axboe 	IORING_OP_CONNECT,
83d63d1b5eSJens Axboe 	IORING_OP_FALLOCATE,
8415b71abeSJens Axboe 	IORING_OP_OPENAT,
85b5dba59eSJens Axboe 	IORING_OP_CLOSE,
8605f3fb3cSJens Axboe 	IORING_OP_FILES_UPDATE,
87eddc7ef5SJens Axboe 	IORING_OP_STATX,
883a6820f2SJens Axboe 	IORING_OP_READ,
893a6820f2SJens Axboe 	IORING_OP_WRITE,
904840e418SJens Axboe 	IORING_OP_FADVISE,
91*c1ca757bSJens Axboe 	IORING_OP_MADVISE,
929e3aa61aSJens Axboe 
939e3aa61aSJens Axboe 	/* this goes last, obviously */
949e3aa61aSJens Axboe 	IORING_OP_LAST,
959e3aa61aSJens Axboe };
96c992fe29SChristoph Hellwig 
97c992fe29SChristoph Hellwig /*
98c992fe29SChristoph Hellwig  * sqe->fsync_flags
99c992fe29SChristoph Hellwig  */
100c992fe29SChristoph Hellwig #define IORING_FSYNC_DATASYNC	(1U << 0)
1012b188cc1SJens Axboe 
1022b188cc1SJens Axboe /*
103a41525abSJens Axboe  * sqe->timeout_flags
104a41525abSJens Axboe  */
105a41525abSJens Axboe #define IORING_TIMEOUT_ABS	(1U << 0)
106a41525abSJens Axboe 
107a41525abSJens Axboe /*
1082b188cc1SJens Axboe  * IO completion data structure (Completion Queue Entry)
1092b188cc1SJens Axboe  */
1102b188cc1SJens Axboe struct io_uring_cqe {
1112b188cc1SJens Axboe 	__u64	user_data;	/* sqe->data submission passed back */
1122b188cc1SJens Axboe 	__s32	res;		/* result code for this event */
1132b188cc1SJens Axboe 	__u32	flags;
1142b188cc1SJens Axboe };
1152b188cc1SJens Axboe 
1162b188cc1SJens Axboe /*
1172b188cc1SJens Axboe  * Magic offsets for the application to mmap the data it needs
1182b188cc1SJens Axboe  */
1192b188cc1SJens Axboe #define IORING_OFF_SQ_RING		0ULL
1202b188cc1SJens Axboe #define IORING_OFF_CQ_RING		0x8000000ULL
1212b188cc1SJens Axboe #define IORING_OFF_SQES			0x10000000ULL
1222b188cc1SJens Axboe 
1232b188cc1SJens Axboe /*
1242b188cc1SJens Axboe  * Filled with the offset for mmap(2)
1252b188cc1SJens Axboe  */
1262b188cc1SJens Axboe struct io_sqring_offsets {
1272b188cc1SJens Axboe 	__u32 head;
1282b188cc1SJens Axboe 	__u32 tail;
1292b188cc1SJens Axboe 	__u32 ring_mask;
1302b188cc1SJens Axboe 	__u32 ring_entries;
1312b188cc1SJens Axboe 	__u32 flags;
1322b188cc1SJens Axboe 	__u32 dropped;
1332b188cc1SJens Axboe 	__u32 array;
1342b188cc1SJens Axboe 	__u32 resv1;
1352b188cc1SJens Axboe 	__u64 resv2;
1362b188cc1SJens Axboe };
1372b188cc1SJens Axboe 
1386c271ce2SJens Axboe /*
1396c271ce2SJens Axboe  * sq_ring->flags
1406c271ce2SJens Axboe  */
1416c271ce2SJens Axboe #define IORING_SQ_NEED_WAKEUP	(1U << 0) /* needs io_uring_enter wakeup */
1426c271ce2SJens Axboe 
1432b188cc1SJens Axboe struct io_cqring_offsets {
1442b188cc1SJens Axboe 	__u32 head;
1452b188cc1SJens Axboe 	__u32 tail;
1462b188cc1SJens Axboe 	__u32 ring_mask;
1472b188cc1SJens Axboe 	__u32 ring_entries;
1482b188cc1SJens Axboe 	__u32 overflow;
1492b188cc1SJens Axboe 	__u32 cqes;
1502b188cc1SJens Axboe 	__u64 resv[2];
1512b188cc1SJens Axboe };
1522b188cc1SJens Axboe 
1532b188cc1SJens Axboe /*
1542b188cc1SJens Axboe  * io_uring_enter(2) flags
1552b188cc1SJens Axboe  */
1562b188cc1SJens Axboe #define IORING_ENTER_GETEVENTS	(1U << 0)
1576c271ce2SJens Axboe #define IORING_ENTER_SQ_WAKEUP	(1U << 1)
1582b188cc1SJens Axboe 
1592b188cc1SJens Axboe /*
1602b188cc1SJens Axboe  * Passed in for io_uring_setup(2). Copied back with updated info on success
1612b188cc1SJens Axboe  */
1622b188cc1SJens Axboe struct io_uring_params {
1632b188cc1SJens Axboe 	__u32 sq_entries;
1642b188cc1SJens Axboe 	__u32 cq_entries;
1652b188cc1SJens Axboe 	__u32 flags;
1666c271ce2SJens Axboe 	__u32 sq_thread_cpu;
1676c271ce2SJens Axboe 	__u32 sq_thread_idle;
168ac90f249SJens Axboe 	__u32 features;
169ac90f249SJens Axboe 	__u32 resv[4];
1702b188cc1SJens Axboe 	struct io_sqring_offsets sq_off;
1712b188cc1SJens Axboe 	struct io_cqring_offsets cq_off;
1722b188cc1SJens Axboe };
1732b188cc1SJens Axboe 
174edafcceeSJens Axboe /*
175ac90f249SJens Axboe  * io_uring_params->features flags
176ac90f249SJens Axboe  */
177ac90f249SJens Axboe #define IORING_FEAT_SINGLE_MMAP		(1U << 0)
1781d7bb1d5SJens Axboe #define IORING_FEAT_NODROP		(1U << 1)
179da8c9690SJens Axboe #define IORING_FEAT_SUBMIT_STABLE	(1U << 2)
180ba04291eSJens Axboe #define IORING_FEAT_RW_CUR_POS		(1U << 3)
181ac90f249SJens Axboe 
182ac90f249SJens Axboe /*
183edafcceeSJens Axboe  * io_uring_register(2) opcodes and arguments
184edafcceeSJens Axboe  */
185edafcceeSJens Axboe #define IORING_REGISTER_BUFFERS		0
186edafcceeSJens Axboe #define IORING_UNREGISTER_BUFFERS	1
1876b06314cSJens Axboe #define IORING_REGISTER_FILES		2
1886b06314cSJens Axboe #define IORING_UNREGISTER_FILES		3
1899b402849SJens Axboe #define IORING_REGISTER_EVENTFD		4
1909b402849SJens Axboe #define IORING_UNREGISTER_EVENTFD	5
191c3a31e60SJens Axboe #define IORING_REGISTER_FILES_UPDATE	6
192c3a31e60SJens Axboe 
193c3a31e60SJens Axboe struct io_uring_files_update {
194c3a31e60SJens Axboe 	__u32 offset;
1951292e972SEugene Syromiatnikov 	__u32 resv;
1961292e972SEugene Syromiatnikov 	__aligned_u64 /* __s32 * */ fds;
197c3a31e60SJens Axboe };
198edafcceeSJens Axboe 
1992b188cc1SJens Axboe #endif
200