Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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