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; /* compatibility */ 35 __u32 poll32_events; /* word-reversed for BE */ 36 __u32 sync_range_flags; 37 __u32 msg_flags; 38 __u32 timeout_flags; 39 __u32 accept_flags; 40 __u32 cancel_flags; 41 __u32 open_flags; 42 __u32 statx_flags; 43 __u32 fadvise_advice; 44 __u32 splice_flags; 45 __u32 rename_flags; 46 __u32 unlink_flags; 47 }; 48 __u64 user_data; /* data to be passed back at completion time */ 49 union { 50 struct { 51 /* pack this to avoid bogus arm OABI complaints */ 52 union { 53 /* index into fixed buffers, if used */ 54 __u16 buf_index; 55 /* for grouped buffer selection */ 56 __u16 buf_group; 57 } __attribute__((packed)); 58 /* personality to use, if used */ 59 __u16 personality; 60 __s32 splice_fd_in; 61 }; 62 __u64 __pad2[3]; 63 }; 64 }; 65 66 enum { 67 IOSQE_FIXED_FILE_BIT, 68 IOSQE_IO_DRAIN_BIT, 69 IOSQE_IO_LINK_BIT, 70 IOSQE_IO_HARDLINK_BIT, 71 IOSQE_ASYNC_BIT, 72 IOSQE_BUFFER_SELECT_BIT, 73 }; 74 75 /* 76 * sqe->flags 77 */ 78 /* use fixed fileset */ 79 #define IOSQE_FIXED_FILE (1U << IOSQE_FIXED_FILE_BIT) 80 /* issue after inflight IO */ 81 #define IOSQE_IO_DRAIN (1U << IOSQE_IO_DRAIN_BIT) 82 /* links next sqe */ 83 #define IOSQE_IO_LINK (1U << IOSQE_IO_LINK_BIT) 84 /* like LINK, but stronger */ 85 #define IOSQE_IO_HARDLINK (1U << IOSQE_IO_HARDLINK_BIT) 86 /* always go async */ 87 #define IOSQE_ASYNC (1U << IOSQE_ASYNC_BIT) 88 /* select buffer from sqe->buf_group */ 89 #define IOSQE_BUFFER_SELECT (1U << IOSQE_BUFFER_SELECT_BIT) 90 91 /* 92 * io_uring_setup() flags 93 */ 94 #define IORING_SETUP_IOPOLL (1U << 0) /* io_context is polled */ 95 #define IORING_SETUP_SQPOLL (1U << 1) /* SQ poll thread */ 96 #define IORING_SETUP_SQ_AFF (1U << 2) /* sq_thread_cpu is valid */ 97 #define IORING_SETUP_CQSIZE (1U << 3) /* app defines CQ size */ 98 #define IORING_SETUP_CLAMP (1U << 4) /* clamp SQ/CQ ring sizes */ 99 #define IORING_SETUP_ATTACH_WQ (1U << 5) /* attach to existing wq */ 100 #define IORING_SETUP_R_DISABLED (1U << 6) /* start with ring disabled */ 101 102 enum { 103 IORING_OP_NOP, 104 IORING_OP_READV, 105 IORING_OP_WRITEV, 106 IORING_OP_FSYNC, 107 IORING_OP_READ_FIXED, 108 IORING_OP_WRITE_FIXED, 109 IORING_OP_POLL_ADD, 110 IORING_OP_POLL_REMOVE, 111 IORING_OP_SYNC_FILE_RANGE, 112 IORING_OP_SENDMSG, 113 IORING_OP_RECVMSG, 114 IORING_OP_TIMEOUT, 115 IORING_OP_TIMEOUT_REMOVE, 116 IORING_OP_ACCEPT, 117 IORING_OP_ASYNC_CANCEL, 118 IORING_OP_LINK_TIMEOUT, 119 IORING_OP_CONNECT, 120 IORING_OP_FALLOCATE, 121 IORING_OP_OPENAT, 122 IORING_OP_CLOSE, 123 IORING_OP_FILES_UPDATE, 124 IORING_OP_STATX, 125 IORING_OP_READ, 126 IORING_OP_WRITE, 127 IORING_OP_FADVISE, 128 IORING_OP_MADVISE, 129 IORING_OP_SEND, 130 IORING_OP_RECV, 131 IORING_OP_OPENAT2, 132 IORING_OP_EPOLL_CTL, 133 IORING_OP_SPLICE, 134 IORING_OP_PROVIDE_BUFFERS, 135 IORING_OP_REMOVE_BUFFERS, 136 IORING_OP_TEE, 137 IORING_OP_SHUTDOWN, 138 IORING_OP_RENAMEAT, 139 IORING_OP_UNLINKAT, 140 141 /* this goes last, obviously */ 142 IORING_OP_LAST, 143 }; 144 145 /* 146 * sqe->fsync_flags 147 */ 148 #define IORING_FSYNC_DATASYNC (1U << 0) 149 150 /* 151 * sqe->timeout_flags 152 */ 153 #define IORING_TIMEOUT_ABS (1U << 0) 154 #define IORING_TIMEOUT_UPDATE (1U << 1) 155 156 /* 157 * sqe->splice_flags 158 * extends splice(2) flags 159 */ 160 #define SPLICE_F_FD_IN_FIXED (1U << 31) /* the last bit of __u32 */ 161 162 /* 163 * IO completion data structure (Completion Queue Entry) 164 */ 165 struct io_uring_cqe { 166 __u64 user_data; /* sqe->data submission passed back */ 167 __s32 res; /* result code for this event */ 168 __u32 flags; 169 }; 170 171 /* 172 * cqe->flags 173 * 174 * IORING_CQE_F_BUFFER If set, the upper 16 bits are the buffer ID 175 */ 176 #define IORING_CQE_F_BUFFER (1U << 0) 177 178 enum { 179 IORING_CQE_BUFFER_SHIFT = 16, 180 }; 181 182 /* 183 * Magic offsets for the application to mmap the data it needs 184 */ 185 #define IORING_OFF_SQ_RING 0ULL 186 #define IORING_OFF_CQ_RING 0x8000000ULL 187 #define IORING_OFF_SQES 0x10000000ULL 188 189 /* 190 * Filled with the offset for mmap(2) 191 */ 192 struct io_sqring_offsets { 193 __u32 head; 194 __u32 tail; 195 __u32 ring_mask; 196 __u32 ring_entries; 197 __u32 flags; 198 __u32 dropped; 199 __u32 array; 200 __u32 resv1; 201 __u64 resv2; 202 }; 203 204 /* 205 * sq_ring->flags 206 */ 207 #define IORING_SQ_NEED_WAKEUP (1U << 0) /* needs io_uring_enter wakeup */ 208 #define IORING_SQ_CQ_OVERFLOW (1U << 1) /* CQ ring is overflown */ 209 210 struct io_cqring_offsets { 211 __u32 head; 212 __u32 tail; 213 __u32 ring_mask; 214 __u32 ring_entries; 215 __u32 overflow; 216 __u32 cqes; 217 __u32 flags; 218 __u32 resv1; 219 __u64 resv2; 220 }; 221 222 /* 223 * cq_ring->flags 224 */ 225 226 /* disable eventfd notifications */ 227 #define IORING_CQ_EVENTFD_DISABLED (1U << 0) 228 229 /* 230 * io_uring_enter(2) flags 231 */ 232 #define IORING_ENTER_GETEVENTS (1U << 0) 233 #define IORING_ENTER_SQ_WAKEUP (1U << 1) 234 #define IORING_ENTER_SQ_WAIT (1U << 2) 235 #define IORING_ENTER_EXT_ARG (1U << 3) 236 237 /* 238 * Passed in for io_uring_setup(2). Copied back with updated info on success 239 */ 240 struct io_uring_params { 241 __u32 sq_entries; 242 __u32 cq_entries; 243 __u32 flags; 244 __u32 sq_thread_cpu; 245 __u32 sq_thread_idle; 246 __u32 features; 247 __u32 wq_fd; 248 __u32 resv[3]; 249 struct io_sqring_offsets sq_off; 250 struct io_cqring_offsets cq_off; 251 }; 252 253 /* 254 * io_uring_params->features flags 255 */ 256 #define IORING_FEAT_SINGLE_MMAP (1U << 0) 257 #define IORING_FEAT_NODROP (1U << 1) 258 #define IORING_FEAT_SUBMIT_STABLE (1U << 2) 259 #define IORING_FEAT_RW_CUR_POS (1U << 3) 260 #define IORING_FEAT_CUR_PERSONALITY (1U << 4) 261 #define IORING_FEAT_FAST_POLL (1U << 5) 262 #define IORING_FEAT_POLL_32BITS (1U << 6) 263 #define IORING_FEAT_SQPOLL_NONFIXED (1U << 7) 264 #define IORING_FEAT_EXT_ARG (1U << 8) 265 #define IORING_FEAT_NATIVE_WORKERS (1U << 9) 266 267 /* 268 * io_uring_register(2) opcodes and arguments 269 */ 270 enum { 271 IORING_REGISTER_BUFFERS = 0, 272 IORING_UNREGISTER_BUFFERS = 1, 273 IORING_REGISTER_FILES = 2, 274 IORING_UNREGISTER_FILES = 3, 275 IORING_REGISTER_EVENTFD = 4, 276 IORING_UNREGISTER_EVENTFD = 5, 277 IORING_REGISTER_FILES_UPDATE = 6, 278 IORING_REGISTER_EVENTFD_ASYNC = 7, 279 IORING_REGISTER_PROBE = 8, 280 IORING_REGISTER_PERSONALITY = 9, 281 IORING_UNREGISTER_PERSONALITY = 10, 282 IORING_REGISTER_RESTRICTIONS = 11, 283 IORING_REGISTER_ENABLE_RINGS = 12, 284 285 /* this goes last */ 286 IORING_REGISTER_LAST 287 }; 288 289 /* deprecated, see struct io_uring_rsrc_update */ 290 struct io_uring_files_update { 291 __u32 offset; 292 __u32 resv; 293 __aligned_u64 /* __s32 * */ fds; 294 }; 295 296 struct io_uring_rsrc_update { 297 __u32 offset; 298 __u32 resv; 299 __aligned_u64 data; 300 }; 301 302 /* Skip updating fd indexes set to this value in the fd table */ 303 #define IORING_REGISTER_FILES_SKIP (-2) 304 305 #define IO_URING_OP_SUPPORTED (1U << 0) 306 307 struct io_uring_probe_op { 308 __u8 op; 309 __u8 resv; 310 __u16 flags; /* IO_URING_OP_* flags */ 311 __u32 resv2; 312 }; 313 314 struct io_uring_probe { 315 __u8 last_op; /* last opcode supported */ 316 __u8 ops_len; /* length of ops[] array below */ 317 __u16 resv; 318 __u32 resv2[3]; 319 struct io_uring_probe_op ops[0]; 320 }; 321 322 struct io_uring_restriction { 323 __u16 opcode; 324 union { 325 __u8 register_op; /* IORING_RESTRICTION_REGISTER_OP */ 326 __u8 sqe_op; /* IORING_RESTRICTION_SQE_OP */ 327 __u8 sqe_flags; /* IORING_RESTRICTION_SQE_FLAGS_* */ 328 }; 329 __u8 resv; 330 __u32 resv2[3]; 331 }; 332 333 /* 334 * io_uring_restriction->opcode values 335 */ 336 enum { 337 /* Allow an io_uring_register(2) opcode */ 338 IORING_RESTRICTION_REGISTER_OP = 0, 339 340 /* Allow an sqe opcode */ 341 IORING_RESTRICTION_SQE_OP = 1, 342 343 /* Allow sqe flags */ 344 IORING_RESTRICTION_SQE_FLAGS_ALLOWED = 2, 345 346 /* Require sqe flags (these flags must be set on each submission) */ 347 IORING_RESTRICTION_SQE_FLAGS_REQUIRED = 3, 348 349 IORING_RESTRICTION_LAST 350 }; 351 352 struct io_uring_getevents_arg { 353 __u64 sigmask; 354 __u32 sigmask_sz; 355 __u32 pad; 356 __u64 ts; 357 }; 358 359 #endif 360