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