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 * this file is shared with liburing and that has to autodetect 15 * if linux/time_types.h is available or not, it can 16 * define UAPI_LINUX_IO_URING_H_SKIP_LINUX_TIME_TYPES_H 17 * if linux/time_types.h is not available 18 */ 19 #ifndef UAPI_LINUX_IO_URING_H_SKIP_LINUX_TIME_TYPES_H 20 #include <linux/time_types.h> 21 #endif 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 /* 28 * IO submission data structure (Submission Queue Entry) 29 */ 30 struct io_uring_sqe { 31 __u8 opcode; /* type of operation for this sqe */ 32 __u8 flags; /* IOSQE_ flags */ 33 __u16 ioprio; /* ioprio for the request */ 34 __s32 fd; /* file descriptor to do IO on */ 35 union { 36 __u64 off; /* offset into file */ 37 __u64 addr2; 38 struct { 39 __u32 cmd_op; 40 __u32 __pad1; 41 }; 42 }; 43 union { 44 __u64 addr; /* pointer to buffer or iovecs */ 45 __u64 splice_off_in; 46 struct { 47 __u32 level; 48 __u32 optname; 49 }; 50 }; 51 __u32 len; /* buffer size or number of iovecs */ 52 union { 53 __u32 rw_flags; 54 __u32 fsync_flags; 55 __u16 poll_events; /* compatibility */ 56 __u32 poll32_events; /* word-reversed for BE */ 57 __u32 sync_range_flags; 58 __u32 msg_flags; 59 __u32 timeout_flags; 60 __u32 accept_flags; 61 __u32 cancel_flags; 62 __u32 open_flags; 63 __u32 statx_flags; 64 __u32 fadvise_advice; 65 __u32 splice_flags; 66 __u32 rename_flags; 67 __u32 unlink_flags; 68 __u32 hardlink_flags; 69 __u32 xattr_flags; 70 __u32 msg_ring_flags; 71 __u32 uring_cmd_flags; 72 __u32 waitid_flags; 73 __u32 futex_flags; 74 __u32 install_fd_flags; 75 __u32 nop_flags; 76 __u32 pipe_flags; 77 }; 78 __u64 user_data; /* data to be passed back at completion time */ 79 /* pack this to avoid bogus arm OABI complaints */ 80 union { 81 /* index into fixed buffers, if used */ 82 __u16 buf_index; 83 /* for grouped buffer selection */ 84 __u16 buf_group; 85 } __attribute__((packed)); 86 /* personality to use, if used */ 87 __u16 personality; 88 union { 89 __s32 splice_fd_in; 90 __u32 file_index; 91 __u32 zcrx_ifq_idx; 92 __u32 optlen; 93 struct { 94 __u16 addr_len; 95 __u16 __pad3[1]; 96 }; 97 struct { 98 __u8 write_stream; 99 __u8 __pad4[3]; 100 }; 101 }; 102 union { 103 struct { 104 __u64 addr3; 105 __u64 __pad2[1]; 106 }; 107 struct { 108 __u64 attr_ptr; /* pointer to attribute information */ 109 __u64 attr_type_mask; /* bit mask of attributes */ 110 }; 111 __u64 optval; 112 /* 113 * If the ring is initialized with IORING_SETUP_SQE128, then 114 * this field is used for 80 bytes of arbitrary command data 115 */ 116 __u8 cmd[0]; 117 }; 118 }; 119 120 /* sqe->attr_type_mask flags */ 121 #define IORING_RW_ATTR_FLAG_PI (1U << 0) 122 /* PI attribute information */ 123 struct io_uring_attr_pi { 124 __u16 flags; 125 __u16 app_tag; 126 __u32 len; 127 __u64 addr; 128 __u64 seed; 129 __u64 rsvd; 130 }; 131 132 /* 133 * If sqe->file_index is set to this for opcodes that instantiate a new 134 * direct descriptor (like openat/openat2/accept), then io_uring will allocate 135 * an available direct descriptor instead of having the application pass one 136 * in. The picked direct descriptor will be returned in cqe->res, or -ENFILE 137 * if the space is full. 138 */ 139 #define IORING_FILE_INDEX_ALLOC (~0U) 140 141 enum io_uring_sqe_flags_bit { 142 IOSQE_FIXED_FILE_BIT, 143 IOSQE_IO_DRAIN_BIT, 144 IOSQE_IO_LINK_BIT, 145 IOSQE_IO_HARDLINK_BIT, 146 IOSQE_ASYNC_BIT, 147 IOSQE_BUFFER_SELECT_BIT, 148 IOSQE_CQE_SKIP_SUCCESS_BIT, 149 }; 150 151 /* 152 * sqe->flags 153 */ 154 /* use fixed fileset */ 155 #define IOSQE_FIXED_FILE (1U << IOSQE_FIXED_FILE_BIT) 156 /* issue after inflight IO */ 157 #define IOSQE_IO_DRAIN (1U << IOSQE_IO_DRAIN_BIT) 158 /* links next sqe */ 159 #define IOSQE_IO_LINK (1U << IOSQE_IO_LINK_BIT) 160 /* like LINK, but stronger */ 161 #define IOSQE_IO_HARDLINK (1U << IOSQE_IO_HARDLINK_BIT) 162 /* always go async */ 163 #define IOSQE_ASYNC (1U << IOSQE_ASYNC_BIT) 164 /* select buffer from sqe->buf_group */ 165 #define IOSQE_BUFFER_SELECT (1U << IOSQE_BUFFER_SELECT_BIT) 166 /* don't post CQE if request succeeded */ 167 #define IOSQE_CQE_SKIP_SUCCESS (1U << IOSQE_CQE_SKIP_SUCCESS_BIT) 168 169 /* 170 * io_uring_setup() flags 171 */ 172 #define IORING_SETUP_IOPOLL (1U << 0) /* io_context is polled */ 173 #define IORING_SETUP_SQPOLL (1U << 1) /* SQ poll thread */ 174 #define IORING_SETUP_SQ_AFF (1U << 2) /* sq_thread_cpu is valid */ 175 #define IORING_SETUP_CQSIZE (1U << 3) /* app defines CQ size */ 176 #define IORING_SETUP_CLAMP (1U << 4) /* clamp SQ/CQ ring sizes */ 177 #define IORING_SETUP_ATTACH_WQ (1U << 5) /* attach to existing wq */ 178 #define IORING_SETUP_R_DISABLED (1U << 6) /* start with ring disabled */ 179 #define IORING_SETUP_SUBMIT_ALL (1U << 7) /* continue submit on error */ 180 /* 181 * Cooperative task running. When requests complete, they often require 182 * forcing the submitter to transition to the kernel to complete. If this 183 * flag is set, work will be done when the task transitions anyway, rather 184 * than force an inter-processor interrupt reschedule. This avoids interrupting 185 * a task running in userspace, and saves an IPI. 186 */ 187 #define IORING_SETUP_COOP_TASKRUN (1U << 8) 188 /* 189 * If COOP_TASKRUN is set, get notified if task work is available for 190 * running and a kernel transition would be needed to run it. This sets 191 * IORING_SQ_TASKRUN in the sq ring flags. Not valid without COOP_TASKRUN 192 * or DEFER_TASKRUN. 193 */ 194 #define IORING_SETUP_TASKRUN_FLAG (1U << 9) 195 #define IORING_SETUP_SQE128 (1U << 10) /* SQEs are 128 byte */ 196 #define IORING_SETUP_CQE32 (1U << 11) /* CQEs are 32 byte */ 197 /* 198 * Only one task is allowed to submit requests 199 */ 200 #define IORING_SETUP_SINGLE_ISSUER (1U << 12) 201 202 /* 203 * Defer running task work to get events. 204 * Rather than running bits of task work whenever the task transitions 205 * try to do it just before it is needed. 206 */ 207 #define IORING_SETUP_DEFER_TASKRUN (1U << 13) 208 209 /* 210 * Application provides the memory for the rings 211 */ 212 #define IORING_SETUP_NO_MMAP (1U << 14) 213 214 /* 215 * Register the ring fd in itself for use with 216 * IORING_REGISTER_USE_REGISTERED_RING; return a registered fd index rather 217 * than an fd. 218 */ 219 #define IORING_SETUP_REGISTERED_FD_ONLY (1U << 15) 220 221 /* 222 * Removes indirection through the SQ index array. 223 */ 224 #define IORING_SETUP_NO_SQARRAY (1U << 16) 225 226 /* Use hybrid poll in iopoll process */ 227 #define IORING_SETUP_HYBRID_IOPOLL (1U << 17) 228 229 /* 230 * Allow both 16b and 32b CQEs. If a 32b CQE is posted, it will have 231 * IORING_CQE_F_32 set in cqe->flags. 232 */ 233 #define IORING_SETUP_CQE_MIXED (1U << 18) 234 235 /* 236 * Allow both 64b and 128b SQEs. If a 128b SQE is posted, it will have 237 * a 128b opcode. 238 */ 239 #define IORING_SETUP_SQE_MIXED (1U << 19) 240 241 /* 242 * When set, io_uring ignores SQ head and tail and fetches SQEs to submit 243 * starting from index 0 instead from the index stored in the head pointer. 244 * IOW, the user should place all SQE at the beginning of the SQ memory 245 * before issuing a submission syscall. 246 * 247 * It requires IORING_SETUP_NO_SQARRAY and is incompatible with 248 * IORING_SETUP_SQPOLL. The user must also never change the SQ head and tail 249 * values and keep it set to 0. Any other value is undefined behaviour. 250 */ 251 #define IORING_SETUP_SQ_REWIND (1U << 20) 252 253 enum io_uring_op { 254 IORING_OP_NOP, 255 IORING_OP_READV, 256 IORING_OP_WRITEV, 257 IORING_OP_FSYNC, 258 IORING_OP_READ_FIXED, 259 IORING_OP_WRITE_FIXED, 260 IORING_OP_POLL_ADD, 261 IORING_OP_POLL_REMOVE, 262 IORING_OP_SYNC_FILE_RANGE, 263 IORING_OP_SENDMSG, 264 IORING_OP_RECVMSG, 265 IORING_OP_TIMEOUT, 266 IORING_OP_TIMEOUT_REMOVE, 267 IORING_OP_ACCEPT, 268 IORING_OP_ASYNC_CANCEL, 269 IORING_OP_LINK_TIMEOUT, 270 IORING_OP_CONNECT, 271 IORING_OP_FALLOCATE, 272 IORING_OP_OPENAT, 273 IORING_OP_CLOSE, 274 IORING_OP_FILES_UPDATE, 275 IORING_OP_STATX, 276 IORING_OP_READ, 277 IORING_OP_WRITE, 278 IORING_OP_FADVISE, 279 IORING_OP_MADVISE, 280 IORING_OP_SEND, 281 IORING_OP_RECV, 282 IORING_OP_OPENAT2, 283 IORING_OP_EPOLL_CTL, 284 IORING_OP_SPLICE, 285 IORING_OP_PROVIDE_BUFFERS, 286 IORING_OP_REMOVE_BUFFERS, 287 IORING_OP_TEE, 288 IORING_OP_SHUTDOWN, 289 IORING_OP_RENAMEAT, 290 IORING_OP_UNLINKAT, 291 IORING_OP_MKDIRAT, 292 IORING_OP_SYMLINKAT, 293 IORING_OP_LINKAT, 294 IORING_OP_MSG_RING, 295 IORING_OP_FSETXATTR, 296 IORING_OP_SETXATTR, 297 IORING_OP_FGETXATTR, 298 IORING_OP_GETXATTR, 299 IORING_OP_SOCKET, 300 IORING_OP_URING_CMD, 301 IORING_OP_SEND_ZC, 302 IORING_OP_SENDMSG_ZC, 303 IORING_OP_READ_MULTISHOT, 304 IORING_OP_WAITID, 305 IORING_OP_FUTEX_WAIT, 306 IORING_OP_FUTEX_WAKE, 307 IORING_OP_FUTEX_WAITV, 308 IORING_OP_FIXED_FD_INSTALL, 309 IORING_OP_FTRUNCATE, 310 IORING_OP_BIND, 311 IORING_OP_LISTEN, 312 IORING_OP_RECV_ZC, 313 IORING_OP_EPOLL_WAIT, 314 IORING_OP_READV_FIXED, 315 IORING_OP_WRITEV_FIXED, 316 IORING_OP_PIPE, 317 IORING_OP_NOP128, 318 IORING_OP_URING_CMD128, 319 320 /* this goes last, obviously */ 321 IORING_OP_LAST, 322 }; 323 324 /* 325 * sqe->uring_cmd_flags top 8bits aren't available for userspace 326 * IORING_URING_CMD_FIXED use registered buffer; pass this flag 327 * along with setting sqe->buf_index. 328 * IORING_URING_CMD_MULTISHOT must be used with buffer select, like other 329 * multishot commands. Not compatible with 330 * IORING_URING_CMD_FIXED, for now. 331 */ 332 #define IORING_URING_CMD_FIXED (1U << 0) 333 #define IORING_URING_CMD_MULTISHOT (1U << 1) 334 #define IORING_URING_CMD_MASK (IORING_URING_CMD_FIXED | IORING_URING_CMD_MULTISHOT) 335 336 337 /* 338 * sqe->fsync_flags 339 */ 340 #define IORING_FSYNC_DATASYNC (1U << 0) 341 342 /* 343 * sqe->timeout_flags 344 */ 345 #define IORING_TIMEOUT_ABS (1U << 0) 346 #define IORING_TIMEOUT_UPDATE (1U << 1) 347 #define IORING_TIMEOUT_BOOTTIME (1U << 2) 348 #define IORING_TIMEOUT_REALTIME (1U << 3) 349 #define IORING_LINK_TIMEOUT_UPDATE (1U << 4) 350 #define IORING_TIMEOUT_ETIME_SUCCESS (1U << 5) 351 #define IORING_TIMEOUT_MULTISHOT (1U << 6) 352 #define IORING_TIMEOUT_CLOCK_MASK (IORING_TIMEOUT_BOOTTIME | IORING_TIMEOUT_REALTIME) 353 #define IORING_TIMEOUT_UPDATE_MASK (IORING_TIMEOUT_UPDATE | IORING_LINK_TIMEOUT_UPDATE) 354 /* 355 * sqe->splice_flags 356 * extends splice(2) flags 357 */ 358 #define SPLICE_F_FD_IN_FIXED (1U << 31) /* the last bit of __u32 */ 359 360 /* 361 * POLL_ADD flags. Note that since sqe->poll_events is the flag space, the 362 * command flags for POLL_ADD are stored in sqe->len. 363 * 364 * IORING_POLL_ADD_MULTI Multishot poll. Sets IORING_CQE_F_MORE if 365 * the poll handler will continue to report 366 * CQEs on behalf of the same SQE. 367 * 368 * IORING_POLL_UPDATE Update existing poll request, matching 369 * sqe->addr as the old user_data field. 370 * 371 * IORING_POLL_LEVEL Level triggered poll. 372 */ 373 #define IORING_POLL_ADD_MULTI (1U << 0) 374 #define IORING_POLL_UPDATE_EVENTS (1U << 1) 375 #define IORING_POLL_UPDATE_USER_DATA (1U << 2) 376 #define IORING_POLL_ADD_LEVEL (1U << 3) 377 378 /* 379 * ASYNC_CANCEL flags. 380 * 381 * IORING_ASYNC_CANCEL_ALL Cancel all requests that match the given key 382 * IORING_ASYNC_CANCEL_FD Key off 'fd' for cancelation rather than the 383 * request 'user_data' 384 * IORING_ASYNC_CANCEL_ANY Match any request 385 * IORING_ASYNC_CANCEL_FD_FIXED 'fd' passed in is a fixed descriptor 386 * IORING_ASYNC_CANCEL_USERDATA Match on user_data, default for no other key 387 * IORING_ASYNC_CANCEL_OP Match request based on opcode 388 */ 389 #define IORING_ASYNC_CANCEL_ALL (1U << 0) 390 #define IORING_ASYNC_CANCEL_FD (1U << 1) 391 #define IORING_ASYNC_CANCEL_ANY (1U << 2) 392 #define IORING_ASYNC_CANCEL_FD_FIXED (1U << 3) 393 #define IORING_ASYNC_CANCEL_USERDATA (1U << 4) 394 #define IORING_ASYNC_CANCEL_OP (1U << 5) 395 396 /* 397 * send/sendmsg and recv/recvmsg flags (sqe->ioprio) 398 * 399 * IORING_RECVSEND_POLL_FIRST If set, instead of first attempting to send 400 * or receive and arm poll if that yields an 401 * -EAGAIN result, arm poll upfront and skip 402 * the initial transfer attempt. 403 * 404 * IORING_RECV_MULTISHOT Multishot recv. Sets IORING_CQE_F_MORE if 405 * the handler will continue to report 406 * CQEs on behalf of the same SQE. 407 * 408 * IORING_RECVSEND_FIXED_BUF Use registered buffers, the index is stored in 409 * the buf_index field. 410 * 411 * IORING_SEND_ZC_REPORT_USAGE 412 * If set, SEND[MSG]_ZC should report 413 * the zerocopy usage in cqe.res 414 * for the IORING_CQE_F_NOTIF cqe. 415 * 0 is reported if zerocopy was actually possible. 416 * IORING_NOTIF_USAGE_ZC_COPIED if data was copied 417 * (at least partially). 418 * 419 * IORING_RECVSEND_BUNDLE Used with IOSQE_BUFFER_SELECT. If set, send or 420 * recv will grab as many buffers from the buffer 421 * group ID given and send them all. The completion 422 * result will be the number of buffers send, with 423 * the starting buffer ID in cqe->flags as per 424 * usual for provided buffer usage. The buffers 425 * will be contiguous from the starting buffer ID. 426 * 427 * IORING_SEND_VECTORIZED If set, SEND[_ZC] will take a pointer to a io_vec 428 * to allow vectorized send operations. 429 */ 430 #define IORING_RECVSEND_POLL_FIRST (1U << 0) 431 #define IORING_RECV_MULTISHOT (1U << 1) 432 #define IORING_RECVSEND_FIXED_BUF (1U << 2) 433 #define IORING_SEND_ZC_REPORT_USAGE (1U << 3) 434 #define IORING_RECVSEND_BUNDLE (1U << 4) 435 #define IORING_SEND_VECTORIZED (1U << 5) 436 437 /* 438 * cqe.res for IORING_CQE_F_NOTIF if 439 * IORING_SEND_ZC_REPORT_USAGE was requested 440 * 441 * It should be treated as a flag, all other 442 * bits of cqe.res should be treated as reserved! 443 */ 444 #define IORING_NOTIF_USAGE_ZC_COPIED (1U << 31) 445 446 /* 447 * accept flags stored in sqe->ioprio 448 */ 449 #define IORING_ACCEPT_MULTISHOT (1U << 0) 450 #define IORING_ACCEPT_DONTWAIT (1U << 1) 451 #define IORING_ACCEPT_POLL_FIRST (1U << 2) 452 453 /* 454 * IORING_OP_MSG_RING command types, stored in sqe->addr 455 */ 456 enum io_uring_msg_ring_flags { 457 IORING_MSG_DATA, /* pass sqe->len as 'res' and off as user_data */ 458 IORING_MSG_SEND_FD, /* send a registered fd to another ring */ 459 }; 460 461 /* 462 * IORING_OP_MSG_RING flags (sqe->msg_ring_flags) 463 * 464 * IORING_MSG_RING_CQE_SKIP Don't post a CQE to the target ring. Not 465 * applicable for IORING_MSG_DATA, obviously. 466 */ 467 #define IORING_MSG_RING_CQE_SKIP (1U << 0) 468 /* Pass through the flags from sqe->file_index to cqe->flags */ 469 #define IORING_MSG_RING_FLAGS_PASS (1U << 1) 470 471 /* 472 * IORING_OP_FIXED_FD_INSTALL flags (sqe->install_fd_flags) 473 * 474 * IORING_FIXED_FD_NO_CLOEXEC Don't mark the fd as O_CLOEXEC 475 */ 476 #define IORING_FIXED_FD_NO_CLOEXEC (1U << 0) 477 478 /* 479 * IORING_OP_NOP flags (sqe->nop_flags) 480 * 481 * IORING_NOP_INJECT_RESULT Inject result from sqe->result 482 */ 483 #define IORING_NOP_INJECT_RESULT (1U << 0) 484 #define IORING_NOP_FILE (1U << 1) 485 #define IORING_NOP_FIXED_FILE (1U << 2) 486 #define IORING_NOP_FIXED_BUFFER (1U << 3) 487 #define IORING_NOP_TW (1U << 4) 488 #define IORING_NOP_CQE32 (1U << 5) 489 490 /* 491 * IO completion data structure (Completion Queue Entry) 492 */ 493 struct io_uring_cqe { 494 __u64 user_data; /* sqe->user_data value passed back */ 495 __s32 res; /* result code for this event */ 496 __u32 flags; 497 498 /* 499 * If the ring is initialized with IORING_SETUP_CQE32, then this field 500 * contains 16-bytes of padding, doubling the size of the CQE. 501 */ 502 __u64 big_cqe[]; 503 }; 504 505 /* 506 * cqe->flags 507 * 508 * IORING_CQE_F_BUFFER If set, the upper 16 bits are the buffer ID 509 * IORING_CQE_F_MORE If set, parent SQE will generate more CQE entries 510 * IORING_CQE_F_SOCK_NONEMPTY If set, more data to read after socket recv 511 * IORING_CQE_F_NOTIF Set for notification CQEs. Can be used to distinct 512 * them from sends. 513 * IORING_CQE_F_BUF_MORE If set, the buffer ID set in the completion will get 514 * more completions. In other words, the buffer is being 515 * partially consumed, and will be used by the kernel for 516 * more completions. This is only set for buffers used via 517 * the incremental buffer consumption, as provided by 518 * a ring buffer setup with IOU_PBUF_RING_INC. For any 519 * other provided buffer type, all completions with a 520 * buffer passed back is automatically returned to the 521 * application. 522 * IORING_CQE_F_SKIP If set, then the application/liburing must ignore this 523 * CQE. It's only purpose is to fill a gap in the ring, 524 * if a large CQE is attempted posted when the ring has 525 * just a single small CQE worth of space left before 526 * wrapping. 527 * IORING_CQE_F_32 If set, this is a 32b/big-cqe posting. Use with rings 528 * setup in a mixed CQE mode, where both 16b and 32b 529 * CQEs may be posted to the CQ ring. 530 */ 531 #define IORING_CQE_F_BUFFER (1U << 0) 532 #define IORING_CQE_F_MORE (1U << 1) 533 #define IORING_CQE_F_SOCK_NONEMPTY (1U << 2) 534 #define IORING_CQE_F_NOTIF (1U << 3) 535 #define IORING_CQE_F_BUF_MORE (1U << 4) 536 #define IORING_CQE_F_SKIP (1U << 5) 537 #define IORING_CQE_F_32 (1U << 15) 538 539 #define IORING_CQE_BUFFER_SHIFT 16 540 541 /* 542 * Magic offsets for the application to mmap the data it needs 543 */ 544 #define IORING_OFF_SQ_RING 0ULL 545 #define IORING_OFF_CQ_RING 0x8000000ULL 546 #define IORING_OFF_SQES 0x10000000ULL 547 #define IORING_OFF_PBUF_RING 0x80000000ULL 548 #define IORING_OFF_PBUF_SHIFT 16 549 #define IORING_OFF_MMAP_MASK 0xf8000000ULL 550 551 /* 552 * Filled with the offset for mmap(2) 553 */ 554 struct io_sqring_offsets { 555 __u32 head; 556 __u32 tail; 557 __u32 ring_mask; 558 __u32 ring_entries; 559 __u32 flags; 560 __u32 dropped; 561 __u32 array; 562 __u32 resv1; 563 __u64 user_addr; 564 }; 565 566 /* 567 * sq_ring->flags 568 */ 569 #define IORING_SQ_NEED_WAKEUP (1U << 0) /* needs io_uring_enter wakeup */ 570 #define IORING_SQ_CQ_OVERFLOW (1U << 1) /* CQ ring is overflown */ 571 #define IORING_SQ_TASKRUN (1U << 2) /* task should enter the kernel */ 572 573 struct io_cqring_offsets { 574 __u32 head; 575 __u32 tail; 576 __u32 ring_mask; 577 __u32 ring_entries; 578 __u32 overflow; 579 __u32 cqes; 580 __u32 flags; 581 __u32 resv1; 582 __u64 user_addr; 583 }; 584 585 /* 586 * cq_ring->flags 587 */ 588 589 /* disable eventfd notifications */ 590 #define IORING_CQ_EVENTFD_DISABLED (1U << 0) 591 592 /* 593 * io_uring_enter(2) flags 594 */ 595 #define IORING_ENTER_GETEVENTS (1U << 0) 596 #define IORING_ENTER_SQ_WAKEUP (1U << 1) 597 #define IORING_ENTER_SQ_WAIT (1U << 2) 598 #define IORING_ENTER_EXT_ARG (1U << 3) 599 #define IORING_ENTER_REGISTERED_RING (1U << 4) 600 #define IORING_ENTER_ABS_TIMER (1U << 5) 601 #define IORING_ENTER_EXT_ARG_REG (1U << 6) 602 #define IORING_ENTER_NO_IOWAIT (1U << 7) 603 604 /* 605 * Passed in for io_uring_setup(2). Copied back with updated info on success 606 */ 607 struct io_uring_params { 608 __u32 sq_entries; 609 __u32 cq_entries; 610 __u32 flags; 611 __u32 sq_thread_cpu; 612 __u32 sq_thread_idle; 613 __u32 features; 614 __u32 wq_fd; 615 __u32 resv[3]; 616 struct io_sqring_offsets sq_off; 617 struct io_cqring_offsets cq_off; 618 }; 619 620 /* 621 * io_uring_params->features flags 622 */ 623 #define IORING_FEAT_SINGLE_MMAP (1U << 0) 624 #define IORING_FEAT_NODROP (1U << 1) 625 #define IORING_FEAT_SUBMIT_STABLE (1U << 2) 626 #define IORING_FEAT_RW_CUR_POS (1U << 3) 627 #define IORING_FEAT_CUR_PERSONALITY (1U << 4) 628 #define IORING_FEAT_FAST_POLL (1U << 5) 629 #define IORING_FEAT_POLL_32BITS (1U << 6) 630 #define IORING_FEAT_SQPOLL_NONFIXED (1U << 7) 631 #define IORING_FEAT_EXT_ARG (1U << 8) 632 #define IORING_FEAT_NATIVE_WORKERS (1U << 9) 633 #define IORING_FEAT_RSRC_TAGS (1U << 10) 634 #define IORING_FEAT_CQE_SKIP (1U << 11) 635 #define IORING_FEAT_LINKED_FILE (1U << 12) 636 #define IORING_FEAT_REG_REG_RING (1U << 13) 637 #define IORING_FEAT_RECVSEND_BUNDLE (1U << 14) 638 #define IORING_FEAT_MIN_TIMEOUT (1U << 15) 639 #define IORING_FEAT_RW_ATTR (1U << 16) 640 #define IORING_FEAT_NO_IOWAIT (1U << 17) 641 642 /* 643 * io_uring_register(2) opcodes and arguments 644 */ 645 enum io_uring_register_op { 646 IORING_REGISTER_BUFFERS = 0, 647 IORING_UNREGISTER_BUFFERS = 1, 648 IORING_REGISTER_FILES = 2, 649 IORING_UNREGISTER_FILES = 3, 650 IORING_REGISTER_EVENTFD = 4, 651 IORING_UNREGISTER_EVENTFD = 5, 652 IORING_REGISTER_FILES_UPDATE = 6, 653 IORING_REGISTER_EVENTFD_ASYNC = 7, 654 IORING_REGISTER_PROBE = 8, 655 IORING_REGISTER_PERSONALITY = 9, 656 IORING_UNREGISTER_PERSONALITY = 10, 657 IORING_REGISTER_RESTRICTIONS = 11, 658 IORING_REGISTER_ENABLE_RINGS = 12, 659 660 /* extended with tagging */ 661 IORING_REGISTER_FILES2 = 13, 662 IORING_REGISTER_FILES_UPDATE2 = 14, 663 IORING_REGISTER_BUFFERS2 = 15, 664 IORING_REGISTER_BUFFERS_UPDATE = 16, 665 666 /* set/clear io-wq thread affinities */ 667 IORING_REGISTER_IOWQ_AFF = 17, 668 IORING_UNREGISTER_IOWQ_AFF = 18, 669 670 /* set/get max number of io-wq workers */ 671 IORING_REGISTER_IOWQ_MAX_WORKERS = 19, 672 673 /* register/unregister io_uring fd with the ring */ 674 IORING_REGISTER_RING_FDS = 20, 675 IORING_UNREGISTER_RING_FDS = 21, 676 677 /* register ring based provide buffer group */ 678 IORING_REGISTER_PBUF_RING = 22, 679 IORING_UNREGISTER_PBUF_RING = 23, 680 681 /* sync cancelation API */ 682 IORING_REGISTER_SYNC_CANCEL = 24, 683 684 /* register a range of fixed file slots for automatic slot allocation */ 685 IORING_REGISTER_FILE_ALLOC_RANGE = 25, 686 687 /* return status information for a buffer group */ 688 IORING_REGISTER_PBUF_STATUS = 26, 689 690 /* set/clear busy poll settings */ 691 IORING_REGISTER_NAPI = 27, 692 IORING_UNREGISTER_NAPI = 28, 693 694 IORING_REGISTER_CLOCK = 29, 695 696 /* clone registered buffers from source ring to current ring */ 697 IORING_REGISTER_CLONE_BUFFERS = 30, 698 699 /* send MSG_RING without having a ring */ 700 IORING_REGISTER_SEND_MSG_RING = 31, 701 702 /* register a netdev hw rx queue for zerocopy */ 703 IORING_REGISTER_ZCRX_IFQ = 32, 704 705 /* resize CQ ring */ 706 IORING_REGISTER_RESIZE_RINGS = 33, 707 708 IORING_REGISTER_MEM_REGION = 34, 709 710 /* query various aspects of io_uring, see linux/io_uring/query.h */ 711 IORING_REGISTER_QUERY = 35, 712 713 /* auxiliary zcrx configuration, see enum zcrx_ctrl_op */ 714 IORING_REGISTER_ZCRX_CTRL = 36, 715 716 /* register bpf filtering programs */ 717 IORING_REGISTER_BPF_FILTER = 37, 718 719 /* this goes last */ 720 IORING_REGISTER_LAST, 721 722 /* flag added to the opcode to use a registered ring fd */ 723 IORING_REGISTER_USE_REGISTERED_RING = 1U << 31 724 }; 725 726 /* io-wq worker categories */ 727 enum io_wq_type { 728 IO_WQ_BOUND, 729 IO_WQ_UNBOUND, 730 }; 731 732 /* deprecated, see struct io_uring_rsrc_update */ 733 struct io_uring_files_update { 734 __u32 offset; 735 __u32 resv; 736 __aligned_u64 /* __s32 * */ fds; 737 }; 738 739 enum { 740 /* initialise with user provided memory pointed by user_addr */ 741 IORING_MEM_REGION_TYPE_USER = 1, 742 }; 743 744 struct io_uring_region_desc { 745 __u64 user_addr; 746 __u64 size; 747 __u32 flags; 748 __u32 id; 749 __u64 mmap_offset; 750 __u64 __resv[4]; 751 }; 752 753 enum { 754 /* expose the region as registered wait arguments */ 755 IORING_MEM_REGION_REG_WAIT_ARG = 1, 756 }; 757 758 struct io_uring_mem_region_reg { 759 __u64 region_uptr; /* struct io_uring_region_desc * */ 760 __u64 flags; 761 __u64 __resv[2]; 762 }; 763 764 /* 765 * Register a fully sparse file space, rather than pass in an array of all 766 * -1 file descriptors. 767 */ 768 #define IORING_RSRC_REGISTER_SPARSE (1U << 0) 769 770 struct io_uring_rsrc_register { 771 __u32 nr; 772 __u32 flags; 773 __u64 resv2; 774 __aligned_u64 data; 775 __aligned_u64 tags; 776 }; 777 778 struct io_uring_rsrc_update { 779 __u32 offset; 780 __u32 resv; 781 __aligned_u64 data; 782 }; 783 784 struct io_uring_rsrc_update2 { 785 __u32 offset; 786 __u32 resv; 787 __aligned_u64 data; 788 __aligned_u64 tags; 789 __u32 nr; 790 __u32 resv2; 791 }; 792 793 /* Skip updating fd indexes set to this value in the fd table */ 794 #define IORING_REGISTER_FILES_SKIP (-2) 795 796 #define IO_URING_OP_SUPPORTED (1U << 0) 797 798 struct io_uring_probe_op { 799 __u8 op; 800 __u8 resv; 801 __u16 flags; /* IO_URING_OP_* flags */ 802 __u32 resv2; 803 }; 804 805 struct io_uring_probe { 806 __u8 last_op; /* last opcode supported */ 807 __u8 ops_len; /* length of ops[] array below */ 808 __u16 resv; 809 __u32 resv2[3]; 810 struct io_uring_probe_op ops[]; 811 }; 812 813 struct io_uring_restriction { 814 __u16 opcode; 815 union { 816 __u8 register_op; /* IORING_RESTRICTION_REGISTER_OP */ 817 __u8 sqe_op; /* IORING_RESTRICTION_SQE_OP */ 818 __u8 sqe_flags; /* IORING_RESTRICTION_SQE_FLAGS_* */ 819 }; 820 __u8 resv; 821 __u32 resv2[3]; 822 }; 823 824 struct io_uring_task_restriction { 825 __u16 flags; 826 __u16 nr_res; 827 __u32 resv[3]; 828 __DECLARE_FLEX_ARRAY(struct io_uring_restriction, restrictions); 829 }; 830 831 struct io_uring_clock_register { 832 __u32 clockid; 833 __u32 __resv[3]; 834 }; 835 836 enum { 837 IORING_REGISTER_SRC_REGISTERED = (1U << 0), 838 IORING_REGISTER_DST_REPLACE = (1U << 1), 839 }; 840 841 struct io_uring_clone_buffers { 842 __u32 src_fd; 843 __u32 flags; 844 __u32 src_off; 845 __u32 dst_off; 846 __u32 nr; 847 __u32 pad[3]; 848 }; 849 850 struct io_uring_buf { 851 __u64 addr; 852 __u32 len; 853 __u16 bid; 854 __u16 resv; 855 }; 856 857 struct io_uring_buf_ring { 858 union { 859 /* 860 * To avoid spilling into more pages than we need to, the 861 * ring tail is overlaid with the io_uring_buf->resv field. 862 */ 863 struct { 864 __u64 resv1; 865 __u32 resv2; 866 __u16 resv3; 867 __u16 tail; 868 }; 869 __DECLARE_FLEX_ARRAY(struct io_uring_buf, bufs); 870 }; 871 }; 872 873 /* 874 * Flags for IORING_REGISTER_PBUF_RING. 875 * 876 * IOU_PBUF_RING_MMAP: If set, kernel will allocate the memory for the ring. 877 * The application must not set a ring_addr in struct 878 * io_uring_buf_reg, instead it must subsequently call 879 * mmap(2) with the offset set as: 880 * IORING_OFF_PBUF_RING | (bgid << IORING_OFF_PBUF_SHIFT) 881 * to get a virtual mapping for the ring. 882 * IOU_PBUF_RING_INC: If set, buffers consumed from this buffer ring can be 883 * consumed incrementally. Normally one (or more) buffers 884 * are fully consumed. With incremental consumptions, it's 885 * feasible to register big ranges of buffers, and each 886 * use of it will consume only as much as it needs. This 887 * requires that both the kernel and application keep 888 * track of where the current read/recv index is at. 889 */ 890 enum io_uring_register_pbuf_ring_flags { 891 IOU_PBUF_RING_MMAP = 1, 892 IOU_PBUF_RING_INC = 2, 893 }; 894 895 /* argument for IORING_(UN)REGISTER_PBUF_RING */ 896 struct io_uring_buf_reg { 897 __u64 ring_addr; 898 __u32 ring_entries; 899 __u16 bgid; 900 __u16 flags; 901 __u64 resv[3]; 902 }; 903 904 /* argument for IORING_REGISTER_PBUF_STATUS */ 905 struct io_uring_buf_status { 906 __u32 buf_group; /* input */ 907 __u32 head; /* output */ 908 __u32 resv[8]; 909 }; 910 911 enum io_uring_napi_op { 912 /* register/ungister backward compatible opcode */ 913 IO_URING_NAPI_REGISTER_OP = 0, 914 915 /* opcodes to update napi_list when static tracking is used */ 916 IO_URING_NAPI_STATIC_ADD_ID = 1, 917 IO_URING_NAPI_STATIC_DEL_ID = 2 918 }; 919 920 enum io_uring_napi_tracking_strategy { 921 /* value must be 0 for backward compatibility */ 922 IO_URING_NAPI_TRACKING_DYNAMIC = 0, 923 IO_URING_NAPI_TRACKING_STATIC = 1, 924 IO_URING_NAPI_TRACKING_INACTIVE = 255 925 }; 926 927 /* argument for IORING_(UN)REGISTER_NAPI */ 928 struct io_uring_napi { 929 __u32 busy_poll_to; 930 __u8 prefer_busy_poll; 931 932 /* a io_uring_napi_op value */ 933 __u8 opcode; 934 __u8 pad[2]; 935 936 /* 937 * for IO_URING_NAPI_REGISTER_OP, it is a 938 * io_uring_napi_tracking_strategy value. 939 * 940 * for IO_URING_NAPI_STATIC_ADD_ID/IO_URING_NAPI_STATIC_DEL_ID 941 * it is the napi id to add/del from napi_list. 942 */ 943 __u32 op_param; 944 __u32 resv; 945 }; 946 947 /* 948 * io_uring_restriction->opcode values 949 */ 950 enum io_uring_register_restriction_op { 951 /* Allow an io_uring_register(2) opcode */ 952 IORING_RESTRICTION_REGISTER_OP = 0, 953 954 /* Allow an sqe opcode */ 955 IORING_RESTRICTION_SQE_OP = 1, 956 957 /* Allow sqe flags */ 958 IORING_RESTRICTION_SQE_FLAGS_ALLOWED = 2, 959 960 /* Require sqe flags (these flags must be set on each submission) */ 961 IORING_RESTRICTION_SQE_FLAGS_REQUIRED = 3, 962 963 IORING_RESTRICTION_LAST 964 }; 965 966 enum { 967 IORING_REG_WAIT_TS = (1U << 0), 968 }; 969 970 /* 971 * Argument for io_uring_enter(2) with 972 * IORING_GETEVENTS | IORING_ENTER_EXT_ARG_REG set, where the actual argument 973 * is an index into a previously registered fixed wait region described by 974 * the below structure. 975 */ 976 struct io_uring_reg_wait { 977 struct __kernel_timespec ts; 978 __u32 min_wait_usec; 979 __u32 flags; 980 __u64 sigmask; 981 __u32 sigmask_sz; 982 __u32 pad[3]; 983 __u64 pad2[2]; 984 }; 985 986 /* 987 * Argument for io_uring_enter(2) with IORING_GETEVENTS | IORING_ENTER_EXT_ARG 988 */ 989 struct io_uring_getevents_arg { 990 __u64 sigmask; 991 __u32 sigmask_sz; 992 __u32 min_wait_usec; 993 __u64 ts; 994 }; 995 996 /* 997 * Argument for IORING_REGISTER_SYNC_CANCEL 998 */ 999 struct io_uring_sync_cancel_reg { 1000 __u64 addr; 1001 __s32 fd; 1002 __u32 flags; 1003 struct __kernel_timespec timeout; 1004 __u8 opcode; 1005 __u8 pad[7]; 1006 __u64 pad2[3]; 1007 }; 1008 1009 /* 1010 * Argument for IORING_REGISTER_FILE_ALLOC_RANGE 1011 * The range is specified as [off, off + len) 1012 */ 1013 struct io_uring_file_index_range { 1014 __u32 off; 1015 __u32 len; 1016 __u64 resv; 1017 }; 1018 1019 struct io_uring_recvmsg_out { 1020 __u32 namelen; 1021 __u32 controllen; 1022 __u32 payloadlen; 1023 __u32 flags; 1024 }; 1025 1026 /* 1027 * Argument for IORING_OP_URING_CMD when file is a socket 1028 */ 1029 enum io_uring_socket_op { 1030 SOCKET_URING_OP_SIOCINQ = 0, 1031 SOCKET_URING_OP_SIOCOUTQ, 1032 SOCKET_URING_OP_GETSOCKOPT, 1033 SOCKET_URING_OP_SETSOCKOPT, 1034 SOCKET_URING_OP_TX_TIMESTAMP, 1035 SOCKET_URING_OP_GETSOCKNAME, 1036 }; 1037 1038 /* 1039 * SOCKET_URING_OP_TX_TIMESTAMP definitions 1040 */ 1041 1042 #define IORING_TIMESTAMP_HW_SHIFT 16 1043 /* The cqe->flags bit from which the timestamp type is stored */ 1044 #define IORING_TIMESTAMP_TYPE_SHIFT (IORING_TIMESTAMP_HW_SHIFT + 1) 1045 /* The cqe->flags flag signifying whether it's a hardware timestamp */ 1046 #define IORING_CQE_F_TSTAMP_HW ((__u32)1 << IORING_TIMESTAMP_HW_SHIFT) 1047 1048 struct io_timespec { 1049 __u64 tv_sec; 1050 __u64 tv_nsec; 1051 }; 1052 1053 /* Zero copy receive refill queue entry */ 1054 struct io_uring_zcrx_rqe { 1055 __u64 off; 1056 __u32 len; 1057 __u32 __pad; 1058 }; 1059 1060 struct io_uring_zcrx_cqe { 1061 __u64 off; 1062 __u64 __pad; 1063 }; 1064 1065 /* The bit from which area id is encoded into offsets */ 1066 #define IORING_ZCRX_AREA_SHIFT 48 1067 #define IORING_ZCRX_AREA_MASK (~(((__u64)1 << IORING_ZCRX_AREA_SHIFT) - 1)) 1068 1069 struct io_uring_zcrx_offsets { 1070 __u32 head; 1071 __u32 tail; 1072 __u32 rqes; 1073 __u32 __resv2; 1074 __u64 __resv[2]; 1075 }; 1076 1077 enum io_uring_zcrx_area_flags { 1078 IORING_ZCRX_AREA_DMABUF = 1, 1079 }; 1080 1081 struct io_uring_zcrx_area_reg { 1082 __u64 addr; 1083 __u64 len; 1084 __u64 rq_area_token; 1085 __u32 flags; 1086 __u32 dmabuf_fd; 1087 __u64 __resv2[2]; 1088 }; 1089 1090 enum zcrx_reg_flags { 1091 ZCRX_REG_IMPORT = 1, 1092 }; 1093 1094 enum zcrx_features { 1095 /* 1096 * The user can ask for the desired rx page size by passing the 1097 * value in struct io_uring_zcrx_ifq_reg::rx_buf_len. 1098 */ 1099 ZCRX_FEATURE_RX_PAGE_SIZE = 1 << 0, 1100 }; 1101 1102 /* 1103 * Argument for IORING_REGISTER_ZCRX_IFQ 1104 */ 1105 struct io_uring_zcrx_ifq_reg { 1106 __u32 if_idx; 1107 __u32 if_rxq; 1108 __u32 rq_entries; 1109 __u32 flags; 1110 1111 __u64 area_ptr; /* pointer to struct io_uring_zcrx_area_reg */ 1112 __u64 region_ptr; /* struct io_uring_region_desc * */ 1113 1114 struct io_uring_zcrx_offsets offsets; 1115 __u32 zcrx_id; 1116 __u32 rx_buf_len; 1117 __u64 __resv[3]; 1118 }; 1119 1120 enum zcrx_ctrl_op { 1121 ZCRX_CTRL_FLUSH_RQ, 1122 ZCRX_CTRL_EXPORT, 1123 1124 __ZCRX_CTRL_LAST, 1125 }; 1126 1127 struct zcrx_ctrl_flush_rq { 1128 __u64 __resv[6]; 1129 }; 1130 1131 struct zcrx_ctrl_export { 1132 __u32 zcrx_fd; 1133 __u32 __resv1[11]; 1134 }; 1135 1136 struct zcrx_ctrl { 1137 __u32 zcrx_id; 1138 __u32 op; /* see enum zcrx_ctrl_op */ 1139 __u64 __resv[2]; 1140 1141 union { 1142 struct zcrx_ctrl_export zc_export; 1143 struct zcrx_ctrl_flush_rq zc_flush; 1144 }; 1145 }; 1146 1147 #ifdef __cplusplus 1148 } 1149 #endif 1150 1151 #endif 1152