19f5834c8SLukas Bulwahn /* SPDX-License-Identifier: (GPL-2.0 WITH Linux-syscall-note) OR MIT */ 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> 1378a861b9SJens Axboe #include <linux/time_types.h> 142b188cc1SJens Axboe 15e1d0c6d0SAmmar Faizi #ifdef __cplusplus 16e1d0c6d0SAmmar Faizi extern "C" { 17e1d0c6d0SAmmar Faizi #endif 18e1d0c6d0SAmmar Faizi 192b188cc1SJens Axboe /* 202b188cc1SJens Axboe * IO submission data structure (Submission Queue Entry) 212b188cc1SJens Axboe */ 222b188cc1SJens Axboe struct io_uring_sqe { 232b188cc1SJens Axboe __u8 opcode; /* type of operation for this sqe */ 246b06314cSJens Axboe __u8 flags; /* IOSQE_ flags */ 252b188cc1SJens Axboe __u16 ioprio; /* ioprio for the request */ 262b188cc1SJens Axboe __s32 fd; /* file descriptor to do IO on */ 2717f2fe35SJens Axboe union { 282b188cc1SJens Axboe __u64 off; /* offset into file */ 2917f2fe35SJens Axboe __u64 addr2; 30bdb2c48eSPavel Begunkov struct { 31ee692a21SJens Axboe __u32 cmd_op; 32bdb2c48eSPavel Begunkov __u32 __pad1; 33bdb2c48eSPavel Begunkov }; 3417f2fe35SJens Axboe }; 357d67af2cSPavel Begunkov union { 362b188cc1SJens Axboe __u64 addr; /* pointer to buffer or iovecs */ 377d67af2cSPavel Begunkov __u64 splice_off_in; 387d67af2cSPavel Begunkov }; 392b188cc1SJens Axboe __u32 len; /* buffer size or number of iovecs */ 402b188cc1SJens Axboe union { 412b188cc1SJens Axboe __kernel_rwf_t rw_flags; 42c992fe29SChristoph Hellwig __u32 fsync_flags; 435769a351SJiufei Xue __u16 poll_events; /* compatibility */ 445769a351SJiufei Xue __u32 poll32_events; /* word-reversed for BE */ 455d17b4a4SJens Axboe __u32 sync_range_flags; 460fa03c62SJens Axboe __u32 msg_flags; 475262f567SJens Axboe __u32 timeout_flags; 4817f2fe35SJens Axboe __u32 accept_flags; 4962755e35SJens Axboe __u32 cancel_flags; 5015b71abeSJens Axboe __u32 open_flags; 51eddc7ef5SJens Axboe __u32 statx_flags; 524840e418SJens Axboe __u32 fadvise_advice; 537d67af2cSPavel Begunkov __u32 splice_flags; 5480a261fdSJens Axboe __u32 rename_flags; 5514a1143bSJens Axboe __u32 unlink_flags; 56cf30da90SDmitry Kadashev __u32 hardlink_flags; 57e9621e2bSStefan Roesch __u32 xattr_flags; 58e6130ebaSJens Axboe __u32 msg_ring_flags; 592b188cc1SJens Axboe }; 602b188cc1SJens Axboe __u64 user_data; /* data to be passed back at completion time */ 61ddf0322dSJens Axboe /* pack this to avoid bogus arm OABI complaints */ 62ddf0322dSJens Axboe union { 6375c6a039SJens Axboe /* index into fixed buffers, if used */ 6475c6a039SJens Axboe __u16 buf_index; 65ddf0322dSJens Axboe /* for grouped buffer selection */ 66ddf0322dSJens Axboe __u16 buf_group; 67ddf0322dSJens Axboe } __attribute__((packed)); 6875c6a039SJens Axboe /* personality to use, if used */ 6975c6a039SJens Axboe __u16 personality; 70b9445598SPavel Begunkov union { 717d67af2cSPavel Begunkov __s32 splice_fd_in; 72b9445598SPavel Begunkov __u32 file_index; 7306a5464bSPavel Begunkov struct { 74092aeedbSPavel Begunkov __u16 addr_len; 75b48c312bSPavel Begunkov __u16 __pad3[1]; 7606a5464bSPavel Begunkov }; 77b9445598SPavel Begunkov }; 78ee692a21SJens Axboe union { 79ee692a21SJens Axboe struct { 80e9621e2bSStefan Roesch __u64 addr3; 81e9621e2bSStefan Roesch __u64 __pad2[1]; 82edafcceeSJens Axboe }; 83ebdeb7c0SJens Axboe /* 84ee692a21SJens Axboe * If the ring is initialized with IORING_SETUP_SQE128, then 85ee692a21SJens Axboe * this field is used for 80 bytes of arbitrary command data 86ebdeb7c0SJens Axboe */ 87ee692a21SJens Axboe __u8 cmd[0]; 88ee692a21SJens Axboe }; 892b188cc1SJens Axboe }; 902b188cc1SJens Axboe 911339f24bSJens Axboe /* 921339f24bSJens Axboe * If sqe->file_index is set to this for opcodes that instantiate a new 931339f24bSJens Axboe * direct descriptor (like openat/openat2/accept), then io_uring will allocate 941339f24bSJens Axboe * an available direct descriptor instead of having the application pass one 951339f24bSJens Axboe * in. The picked direct descriptor will be returned in cqe->res, or -ENFILE 961339f24bSJens Axboe * if the space is full. 971339f24bSJens Axboe */ 981339f24bSJens Axboe #define IORING_FILE_INDEX_ALLOC (~0U) 991339f24bSJens Axboe 1006b47ee6eSPavel Begunkov enum { 1016b47ee6eSPavel Begunkov IOSQE_FIXED_FILE_BIT, 1026b47ee6eSPavel Begunkov IOSQE_IO_DRAIN_BIT, 1036b47ee6eSPavel Begunkov IOSQE_IO_LINK_BIT, 1046b47ee6eSPavel Begunkov IOSQE_IO_HARDLINK_BIT, 1056b47ee6eSPavel Begunkov IOSQE_ASYNC_BIT, 106bcda7baaSJens Axboe IOSQE_BUFFER_SELECT_BIT, 10704c76b41SPavel Begunkov IOSQE_CQE_SKIP_SUCCESS_BIT, 1086b47ee6eSPavel Begunkov }; 1096b47ee6eSPavel Begunkov 110def596e9SJens Axboe /* 1116b06314cSJens Axboe * sqe->flags 1126b06314cSJens Axboe */ 1136b47ee6eSPavel Begunkov /* use fixed fileset */ 1146b47ee6eSPavel Begunkov #define IOSQE_FIXED_FILE (1U << IOSQE_FIXED_FILE_BIT) 1156b47ee6eSPavel Begunkov /* issue after inflight IO */ 1166b47ee6eSPavel Begunkov #define IOSQE_IO_DRAIN (1U << IOSQE_IO_DRAIN_BIT) 1176b47ee6eSPavel Begunkov /* links next sqe */ 1186b47ee6eSPavel Begunkov #define IOSQE_IO_LINK (1U << IOSQE_IO_LINK_BIT) 1196b47ee6eSPavel Begunkov /* like LINK, but stronger */ 1206b47ee6eSPavel Begunkov #define IOSQE_IO_HARDLINK (1U << IOSQE_IO_HARDLINK_BIT) 1216b47ee6eSPavel Begunkov /* always go async */ 1226b47ee6eSPavel Begunkov #define IOSQE_ASYNC (1U << IOSQE_ASYNC_BIT) 123bcda7baaSJens Axboe /* select buffer from sqe->buf_group */ 124bcda7baaSJens Axboe #define IOSQE_BUFFER_SELECT (1U << IOSQE_BUFFER_SELECT_BIT) 12504c76b41SPavel Begunkov /* don't post CQE if request succeeded */ 12604c76b41SPavel Begunkov #define IOSQE_CQE_SKIP_SUCCESS (1U << IOSQE_CQE_SKIP_SUCCESS_BIT) 1276b06314cSJens Axboe 1286b06314cSJens Axboe /* 129def596e9SJens Axboe * io_uring_setup() flags 130def596e9SJens Axboe */ 131def596e9SJens Axboe #define IORING_SETUP_IOPOLL (1U << 0) /* io_context is polled */ 1326c271ce2SJens Axboe #define IORING_SETUP_SQPOLL (1U << 1) /* SQ poll thread */ 1336c271ce2SJens Axboe #define IORING_SETUP_SQ_AFF (1U << 2) /* sq_thread_cpu is valid */ 13433a107f0SJens Axboe #define IORING_SETUP_CQSIZE (1U << 3) /* app defines CQ size */ 1358110c1a6SJens Axboe #define IORING_SETUP_CLAMP (1U << 4) /* clamp SQ/CQ ring sizes */ 13624369c2eSPavel Begunkov #define IORING_SETUP_ATTACH_WQ (1U << 5) /* attach to existing wq */ 1377e84e1c7SStefano Garzarella #define IORING_SETUP_R_DISABLED (1U << 6) /* start with ring disabled */ 138bcbb7bf6SJens Axboe #define IORING_SETUP_SUBMIT_ALL (1U << 7) /* continue submit on error */ 139e1169f06SJens Axboe /* 140e1169f06SJens Axboe * Cooperative task running. When requests complete, they often require 141e1169f06SJens Axboe * forcing the submitter to transition to the kernel to complete. If this 142e1169f06SJens Axboe * flag is set, work will be done when the task transitions anyway, rather 143e1169f06SJens Axboe * than force an inter-processor interrupt reschedule. This avoids interrupting 144e1169f06SJens Axboe * a task running in userspace, and saves an IPI. 145e1169f06SJens Axboe */ 146e1169f06SJens Axboe #define IORING_SETUP_COOP_TASKRUN (1U << 8) 147ef060ea9SJens Axboe /* 148ef060ea9SJens Axboe * If COOP_TASKRUN is set, get notified if task work is available for 149ef060ea9SJens Axboe * running and a kernel transition would be needed to run it. This sets 150ef060ea9SJens Axboe * IORING_SQ_TASKRUN in the sq ring flags. Not valid with COOP_TASKRUN. 151ef060ea9SJens Axboe */ 152ef060ea9SJens Axboe #define IORING_SETUP_TASKRUN_FLAG (1U << 9) 153ebdeb7c0SJens Axboe #define IORING_SETUP_SQE128 (1U << 10) /* SQEs are 128 byte */ 1547a51e5b4SStefan Roesch #define IORING_SETUP_CQE32 (1U << 11) /* CQEs are 32 byte */ 15597bbdc06SPavel Begunkov /* 15697bbdc06SPavel Begunkov * Only one task is allowed to submit requests 15797bbdc06SPavel Begunkov */ 15897bbdc06SPavel Begunkov #define IORING_SETUP_SINGLE_ISSUER (1U << 12) 159ebdeb7c0SJens Axboe 160c0e0d6baSDylan Yudaken /* 161c0e0d6baSDylan Yudaken * Defer running task work to get events. 162c0e0d6baSDylan Yudaken * Rather than running bits of task work whenever the task transitions 163c0e0d6baSDylan Yudaken * try to do it just before it is needed. 164c0e0d6baSDylan Yudaken */ 165c0e0d6baSDylan Yudaken #define IORING_SETUP_DEFER_TASKRUN (1U << 13) 166c0e0d6baSDylan Yudaken 167cc51eaa8SDylan Yudaken enum io_uring_op { 1689e3aa61aSJens Axboe IORING_OP_NOP, 1699e3aa61aSJens Axboe IORING_OP_READV, 1709e3aa61aSJens Axboe IORING_OP_WRITEV, 1719e3aa61aSJens Axboe IORING_OP_FSYNC, 1729e3aa61aSJens Axboe IORING_OP_READ_FIXED, 1739e3aa61aSJens Axboe IORING_OP_WRITE_FIXED, 1749e3aa61aSJens Axboe IORING_OP_POLL_ADD, 1759e3aa61aSJens Axboe IORING_OP_POLL_REMOVE, 1769e3aa61aSJens Axboe IORING_OP_SYNC_FILE_RANGE, 1779e3aa61aSJens Axboe IORING_OP_SENDMSG, 1789e3aa61aSJens Axboe IORING_OP_RECVMSG, 1799e3aa61aSJens Axboe IORING_OP_TIMEOUT, 1809e3aa61aSJens Axboe IORING_OP_TIMEOUT_REMOVE, 1819e3aa61aSJens Axboe IORING_OP_ACCEPT, 1829e3aa61aSJens Axboe IORING_OP_ASYNC_CANCEL, 1839e3aa61aSJens Axboe IORING_OP_LINK_TIMEOUT, 1849e3aa61aSJens Axboe IORING_OP_CONNECT, 185d63d1b5eSJens Axboe IORING_OP_FALLOCATE, 18615b71abeSJens Axboe IORING_OP_OPENAT, 187b5dba59eSJens Axboe IORING_OP_CLOSE, 188d9808cebSPavel Begunkov IORING_OP_FILES_UPDATE, 189eddc7ef5SJens Axboe IORING_OP_STATX, 1903a6820f2SJens Axboe IORING_OP_READ, 1913a6820f2SJens Axboe IORING_OP_WRITE, 1924840e418SJens Axboe IORING_OP_FADVISE, 193c1ca757bSJens Axboe IORING_OP_MADVISE, 194fddafaceSJens Axboe IORING_OP_SEND, 195fddafaceSJens Axboe IORING_OP_RECV, 196cebdb986SJens Axboe IORING_OP_OPENAT2, 1973e4827b0SJens Axboe IORING_OP_EPOLL_CTL, 1987d67af2cSPavel Begunkov IORING_OP_SPLICE, 199ddf0322dSJens Axboe IORING_OP_PROVIDE_BUFFERS, 200067524e9SJens Axboe IORING_OP_REMOVE_BUFFERS, 201f2a8d5c7SPavel Begunkov IORING_OP_TEE, 20236f4fa68SJens Axboe IORING_OP_SHUTDOWN, 20380a261fdSJens Axboe IORING_OP_RENAMEAT, 20414a1143bSJens Axboe IORING_OP_UNLINKAT, 205e34a02dcSDmitry Kadashev IORING_OP_MKDIRAT, 2067a8721f8SDmitry Kadashev IORING_OP_SYMLINKAT, 207cf30da90SDmitry Kadashev IORING_OP_LINKAT, 2084f57f06cSJens Axboe IORING_OP_MSG_RING, 209e9621e2bSStefan Roesch IORING_OP_FSETXATTR, 210e9621e2bSStefan Roesch IORING_OP_SETXATTR, 211a56834e0SStefan Roesch IORING_OP_FGETXATTR, 212a56834e0SStefan Roesch IORING_OP_GETXATTR, 2131374e08eSJens Axboe IORING_OP_SOCKET, 214ee692a21SJens Axboe IORING_OP_URING_CMD, 215b48c312bSPavel Begunkov IORING_OP_SEND_ZC, 216*493108d9SPavel Begunkov IORING_OP_SENDMSG_ZC, 2179e3aa61aSJens Axboe 2189e3aa61aSJens Axboe /* this goes last, obviously */ 2199e3aa61aSJens Axboe IORING_OP_LAST, 2209e3aa61aSJens Axboe }; 221c992fe29SChristoph Hellwig 222c992fe29SChristoph Hellwig /* 223c992fe29SChristoph Hellwig * sqe->fsync_flags 224c992fe29SChristoph Hellwig */ 225c992fe29SChristoph Hellwig #define IORING_FSYNC_DATASYNC (1U << 0) 2262b188cc1SJens Axboe 2272b188cc1SJens Axboe /* 228a41525abSJens Axboe * sqe->timeout_flags 229a41525abSJens Axboe */ 230a41525abSJens Axboe #define IORING_TIMEOUT_ABS (1U << 0) 2319c8e11b3SPavel Begunkov #define IORING_TIMEOUT_UPDATE (1U << 1) 23250c1df2bSJens Axboe #define IORING_TIMEOUT_BOOTTIME (1U << 2) 23350c1df2bSJens Axboe #define IORING_TIMEOUT_REALTIME (1U << 3) 234f1042b6cSPavel Begunkov #define IORING_LINK_TIMEOUT_UPDATE (1U << 4) 2356224590dSPavel Begunkov #define IORING_TIMEOUT_ETIME_SUCCESS (1U << 5) 23650c1df2bSJens Axboe #define IORING_TIMEOUT_CLOCK_MASK (IORING_TIMEOUT_BOOTTIME | IORING_TIMEOUT_REALTIME) 237f1042b6cSPavel Begunkov #define IORING_TIMEOUT_UPDATE_MASK (IORING_TIMEOUT_UPDATE | IORING_LINK_TIMEOUT_UPDATE) 238a41525abSJens Axboe /* 2397d67af2cSPavel Begunkov * sqe->splice_flags 2407d67af2cSPavel Begunkov * extends splice(2) flags 2417d67af2cSPavel Begunkov */ 2427d67af2cSPavel Begunkov #define SPLICE_F_FD_IN_FIXED (1U << 31) /* the last bit of __u32 */ 2437d67af2cSPavel Begunkov 2447d67af2cSPavel Begunkov /* 24588e41cf9SJens Axboe * POLL_ADD flags. Note that since sqe->poll_events is the flag space, the 24688e41cf9SJens Axboe * command flags for POLL_ADD are stored in sqe->len. 24788e41cf9SJens Axboe * 24888e41cf9SJens Axboe * IORING_POLL_ADD_MULTI Multishot poll. Sets IORING_CQE_F_MORE if 24988e41cf9SJens Axboe * the poll handler will continue to report 25088e41cf9SJens Axboe * CQEs on behalf of the same SQE. 251b69de288SJens Axboe * 252b69de288SJens Axboe * IORING_POLL_UPDATE Update existing poll request, matching 253b69de288SJens Axboe * sqe->addr as the old user_data field. 254b9ba8a44SJens Axboe * 255b9ba8a44SJens Axboe * IORING_POLL_LEVEL Level triggered poll. 25688e41cf9SJens Axboe */ 25788e41cf9SJens Axboe #define IORING_POLL_ADD_MULTI (1U << 0) 258b69de288SJens Axboe #define IORING_POLL_UPDATE_EVENTS (1U << 1) 259b69de288SJens Axboe #define IORING_POLL_UPDATE_USER_DATA (1U << 2) 260b9ba8a44SJens Axboe #define IORING_POLL_ADD_LEVEL (1U << 3) 26188e41cf9SJens Axboe 26288e41cf9SJens Axboe /* 2638e29da69SJens Axboe * ASYNC_CANCEL flags. 2648e29da69SJens Axboe * 2658e29da69SJens Axboe * IORING_ASYNC_CANCEL_ALL Cancel all requests that match the given key 2664bf94615SJens Axboe * IORING_ASYNC_CANCEL_FD Key off 'fd' for cancelation rather than the 2674bf94615SJens Axboe * request 'user_data' 268970f256eSJens Axboe * IORING_ASYNC_CANCEL_ANY Match any request 2697d8ca725SJens Axboe * IORING_ASYNC_CANCEL_FD_FIXED 'fd' passed in is a fixed descriptor 2708e29da69SJens Axboe */ 2718e29da69SJens Axboe #define IORING_ASYNC_CANCEL_ALL (1U << 0) 2724bf94615SJens Axboe #define IORING_ASYNC_CANCEL_FD (1U << 1) 273970f256eSJens Axboe #define IORING_ASYNC_CANCEL_ANY (1U << 2) 2747d8ca725SJens Axboe #define IORING_ASYNC_CANCEL_FD_FIXED (1U << 3) 2758e29da69SJens Axboe 2768e29da69SJens Axboe /* 27729c1ac23SPavel Begunkov * send/sendmsg and recv/recvmsg flags (sqe->ioprio) 2780455d4ccSJens Axboe * 2790455d4ccSJens Axboe * IORING_RECVSEND_POLL_FIRST If set, instead of first attempting to send 2800455d4ccSJens Axboe * or receive and arm poll if that yields an 2810455d4ccSJens Axboe * -EAGAIN result, arm poll upfront and skip 2820455d4ccSJens Axboe * the initial transfer attempt. 283b3fdea6eSDylan Yudaken * 284b3fdea6eSDylan Yudaken * IORING_RECV_MULTISHOT Multishot recv. Sets IORING_CQE_F_MORE if 285b3fdea6eSDylan Yudaken * the handler will continue to report 286b3fdea6eSDylan Yudaken * CQEs on behalf of the same SQE. 28710c7d33eSPavel Begunkov * 28810c7d33eSPavel Begunkov * IORING_RECVSEND_FIXED_BUF Use registered buffers, the index is stored in 28910c7d33eSPavel Begunkov * the buf_index field. 2900455d4ccSJens Axboe */ 2910455d4ccSJens Axboe #define IORING_RECVSEND_POLL_FIRST (1U << 0) 292b3fdea6eSDylan Yudaken #define IORING_RECV_MULTISHOT (1U << 1) 29310c7d33eSPavel Begunkov #define IORING_RECVSEND_FIXED_BUF (1U << 2) 2940455d4ccSJens Axboe 2950455d4ccSJens Axboe /* 296390ed29bSHao Xu * accept flags stored in sqe->ioprio 297390ed29bSHao Xu */ 298390ed29bSHao Xu #define IORING_ACCEPT_MULTISHOT (1U << 0) 299390ed29bSHao Xu 300390ed29bSHao Xu /* 301e6130ebaSJens Axboe * IORING_OP_MSG_RING command types, stored in sqe->addr 302e6130ebaSJens Axboe */ 303e6130ebaSJens Axboe enum { 304e6130ebaSJens Axboe IORING_MSG_DATA, /* pass sqe->len as 'res' and off as user_data */ 305e6130ebaSJens Axboe IORING_MSG_SEND_FD, /* send a registered fd to another ring */ 306e6130ebaSJens Axboe }; 307e6130ebaSJens Axboe 308e6130ebaSJens Axboe /* 309e6130ebaSJens Axboe * IORING_OP_MSG_RING flags (sqe->msg_ring_flags) 310e6130ebaSJens Axboe * 311e6130ebaSJens Axboe * IORING_MSG_RING_CQE_SKIP Don't post a CQE to the target ring. Not 312e6130ebaSJens Axboe * applicable for IORING_MSG_DATA, obviously. 313e6130ebaSJens Axboe */ 314e6130ebaSJens Axboe #define IORING_MSG_RING_CQE_SKIP (1U << 0) 315e6130ebaSJens Axboe 316e6130ebaSJens Axboe /* 3172b188cc1SJens Axboe * IO completion data structure (Completion Queue Entry) 3182b188cc1SJens Axboe */ 3192b188cc1SJens Axboe struct io_uring_cqe { 3202b188cc1SJens Axboe __u64 user_data; /* sqe->data submission passed back */ 3212b188cc1SJens Axboe __s32 res; /* result code for this event */ 3222b188cc1SJens Axboe __u32 flags; 3237a51e5b4SStefan Roesch 3247a51e5b4SStefan Roesch /* 3257a51e5b4SStefan Roesch * If the ring is initialized with IORING_SETUP_CQE32, then this field 3267a51e5b4SStefan Roesch * contains 16-bytes of padding, doubling the size of the CQE. 3277a51e5b4SStefan Roesch */ 3287a51e5b4SStefan Roesch __u64 big_cqe[]; 3292b188cc1SJens Axboe }; 3302b188cc1SJens Axboe 3312b188cc1SJens Axboe /* 332bcda7baaSJens Axboe * cqe->flags 333bcda7baaSJens Axboe * 334bcda7baaSJens Axboe * IORING_CQE_F_BUFFER If set, the upper 16 bits are the buffer ID 33588e41cf9SJens Axboe * IORING_CQE_F_MORE If set, parent SQE will generate more CQE entries 336f548a12eSJens Axboe * IORING_CQE_F_SOCK_NONEMPTY If set, more data to read after socket recv 337b48c312bSPavel Begunkov * IORING_CQE_F_NOTIF Set for notification CQEs. Can be used to distinct 338b48c312bSPavel Begunkov * them from sends. 339bcda7baaSJens Axboe */ 340bcda7baaSJens Axboe #define IORING_CQE_F_BUFFER (1U << 0) 34188e41cf9SJens Axboe #define IORING_CQE_F_MORE (1U << 1) 342f548a12eSJens Axboe #define IORING_CQE_F_SOCK_NONEMPTY (1U << 2) 343b48c312bSPavel Begunkov #define IORING_CQE_F_NOTIF (1U << 3) 344bcda7baaSJens Axboe 345bcda7baaSJens Axboe enum { 346bcda7baaSJens Axboe IORING_CQE_BUFFER_SHIFT = 16, 347bcda7baaSJens Axboe }; 348bcda7baaSJens Axboe 349bcda7baaSJens Axboe /* 3502b188cc1SJens Axboe * Magic offsets for the application to mmap the data it needs 3512b188cc1SJens Axboe */ 3522b188cc1SJens Axboe #define IORING_OFF_SQ_RING 0ULL 3532b188cc1SJens Axboe #define IORING_OFF_CQ_RING 0x8000000ULL 3542b188cc1SJens Axboe #define IORING_OFF_SQES 0x10000000ULL 3552b188cc1SJens Axboe 3562b188cc1SJens Axboe /* 3572b188cc1SJens Axboe * Filled with the offset for mmap(2) 3582b188cc1SJens Axboe */ 3592b188cc1SJens Axboe struct io_sqring_offsets { 3602b188cc1SJens Axboe __u32 head; 3612b188cc1SJens Axboe __u32 tail; 3622b188cc1SJens Axboe __u32 ring_mask; 3632b188cc1SJens Axboe __u32 ring_entries; 3642b188cc1SJens Axboe __u32 flags; 3652b188cc1SJens Axboe __u32 dropped; 3662b188cc1SJens Axboe __u32 array; 3672b188cc1SJens Axboe __u32 resv1; 3682b188cc1SJens Axboe __u64 resv2; 3692b188cc1SJens Axboe }; 3702b188cc1SJens Axboe 3716c271ce2SJens Axboe /* 3726c271ce2SJens Axboe * sq_ring->flags 3736c271ce2SJens Axboe */ 3746c271ce2SJens Axboe #define IORING_SQ_NEED_WAKEUP (1U << 0) /* needs io_uring_enter wakeup */ 3756d5f9049SXiaoguang Wang #define IORING_SQ_CQ_OVERFLOW (1U << 1) /* CQ ring is overflown */ 376ef060ea9SJens Axboe #define IORING_SQ_TASKRUN (1U << 2) /* task should enter the kernel */ 3776c271ce2SJens Axboe 3782b188cc1SJens Axboe struct io_cqring_offsets { 3792b188cc1SJens Axboe __u32 head; 3802b188cc1SJens Axboe __u32 tail; 3812b188cc1SJens Axboe __u32 ring_mask; 3822b188cc1SJens Axboe __u32 ring_entries; 3832b188cc1SJens Axboe __u32 overflow; 3842b188cc1SJens Axboe __u32 cqes; 3850d9b5b3aSStefano Garzarella __u32 flags; 3860d9b5b3aSStefano Garzarella __u32 resv1; 3870d9b5b3aSStefano Garzarella __u64 resv2; 3882b188cc1SJens Axboe }; 3892b188cc1SJens Axboe 3902b188cc1SJens Axboe /* 3917e55a19cSStefano Garzarella * cq_ring->flags 3927e55a19cSStefano Garzarella */ 3937e55a19cSStefano Garzarella 3947e55a19cSStefano Garzarella /* disable eventfd notifications */ 3957e55a19cSStefano Garzarella #define IORING_CQ_EVENTFD_DISABLED (1U << 0) 3967e55a19cSStefano Garzarella 3977e55a19cSStefano Garzarella /* 3982b188cc1SJens Axboe * io_uring_enter(2) flags 3992b188cc1SJens Axboe */ 4002b188cc1SJens Axboe #define IORING_ENTER_GETEVENTS (1U << 0) 4016c271ce2SJens Axboe #define IORING_ENTER_SQ_WAKEUP (1U << 1) 40290554200SJens Axboe #define IORING_ENTER_SQ_WAIT (1U << 2) 403c73ebb68SHao Xu #define IORING_ENTER_EXT_ARG (1U << 3) 404e7a6c00dSJens Axboe #define IORING_ENTER_REGISTERED_RING (1U << 4) 4052b188cc1SJens Axboe 4062b188cc1SJens Axboe /* 4072b188cc1SJens Axboe * Passed in for io_uring_setup(2). Copied back with updated info on success 4082b188cc1SJens Axboe */ 4092b188cc1SJens Axboe struct io_uring_params { 4102b188cc1SJens Axboe __u32 sq_entries; 4112b188cc1SJens Axboe __u32 cq_entries; 4122b188cc1SJens Axboe __u32 flags; 4136c271ce2SJens Axboe __u32 sq_thread_cpu; 4146c271ce2SJens Axboe __u32 sq_thread_idle; 415ac90f249SJens Axboe __u32 features; 41624369c2eSPavel Begunkov __u32 wq_fd; 41724369c2eSPavel Begunkov __u32 resv[3]; 4182b188cc1SJens Axboe struct io_sqring_offsets sq_off; 4192b188cc1SJens Axboe struct io_cqring_offsets cq_off; 4202b188cc1SJens Axboe }; 4212b188cc1SJens Axboe 422edafcceeSJens Axboe /* 423ac90f249SJens Axboe * io_uring_params->features flags 424ac90f249SJens Axboe */ 425ac90f249SJens Axboe #define IORING_FEAT_SINGLE_MMAP (1U << 0) 4261d7bb1d5SJens Axboe #define IORING_FEAT_NODROP (1U << 1) 427da8c9690SJens Axboe #define IORING_FEAT_SUBMIT_STABLE (1U << 2) 428ba04291eSJens Axboe #define IORING_FEAT_RW_CUR_POS (1U << 3) 429cccf0ee8SJens Axboe #define IORING_FEAT_CUR_PERSONALITY (1U << 4) 430d7718a9dSJens Axboe #define IORING_FEAT_FAST_POLL (1U << 5) 4315769a351SJiufei Xue #define IORING_FEAT_POLL_32BITS (1U << 6) 43228cea78aSJens Axboe #define IORING_FEAT_SQPOLL_NONFIXED (1U << 7) 433c73ebb68SHao Xu #define IORING_FEAT_EXT_ARG (1U << 8) 4341c0aa1faSJens Axboe #define IORING_FEAT_NATIVE_WORKERS (1U << 9) 4359690557eSPavel Begunkov #define IORING_FEAT_RSRC_TAGS (1U << 10) 43604c76b41SPavel Begunkov #define IORING_FEAT_CQE_SKIP (1U << 11) 437c4212f3eSJens Axboe #define IORING_FEAT_LINKED_FILE (1U << 12) 438ac90f249SJens Axboe 439ac90f249SJens Axboe /* 440edafcceeSJens Axboe * io_uring_register(2) opcodes and arguments 441edafcceeSJens Axboe */ 4429d4a75efSStefano Garzarella enum { 4439d4a75efSStefano Garzarella IORING_REGISTER_BUFFERS = 0, 4449d4a75efSStefano Garzarella IORING_UNREGISTER_BUFFERS = 1, 4459d4a75efSStefano Garzarella IORING_REGISTER_FILES = 2, 4469d4a75efSStefano Garzarella IORING_UNREGISTER_FILES = 3, 4479d4a75efSStefano Garzarella IORING_REGISTER_EVENTFD = 4, 4489d4a75efSStefano Garzarella IORING_UNREGISTER_EVENTFD = 5, 4499d4a75efSStefano Garzarella IORING_REGISTER_FILES_UPDATE = 6, 4509d4a75efSStefano Garzarella IORING_REGISTER_EVENTFD_ASYNC = 7, 4519d4a75efSStefano Garzarella IORING_REGISTER_PROBE = 8, 4529d4a75efSStefano Garzarella IORING_REGISTER_PERSONALITY = 9, 4539d4a75efSStefano Garzarella IORING_UNREGISTER_PERSONALITY = 10, 45421b55dbcSStefano Garzarella IORING_REGISTER_RESTRICTIONS = 11, 4557e84e1c7SStefano Garzarella IORING_REGISTER_ENABLE_RINGS = 12, 456992da01aSPavel Begunkov 457992da01aSPavel Begunkov /* extended with tagging */ 458992da01aSPavel Begunkov IORING_REGISTER_FILES2 = 13, 459992da01aSPavel Begunkov IORING_REGISTER_FILES_UPDATE2 = 14, 460992da01aSPavel Begunkov IORING_REGISTER_BUFFERS2 = 15, 461992da01aSPavel Begunkov IORING_REGISTER_BUFFERS_UPDATE = 16, 4629d4a75efSStefano Garzarella 463fe76421dSJens Axboe /* set/clear io-wq thread affinities */ 464fe76421dSJens Axboe IORING_REGISTER_IOWQ_AFF = 17, 465fe76421dSJens Axboe IORING_UNREGISTER_IOWQ_AFF = 18, 466fe76421dSJens Axboe 467dd47c104SEugene Syromiatnikov /* set/get max number of io-wq workers */ 4682e480058SJens Axboe IORING_REGISTER_IOWQ_MAX_WORKERS = 19, 4692e480058SJens Axboe 470e7a6c00dSJens Axboe /* register/unregister io_uring fd with the ring */ 471e7a6c00dSJens Axboe IORING_REGISTER_RING_FDS = 20, 472e7a6c00dSJens Axboe IORING_UNREGISTER_RING_FDS = 21, 473e7a6c00dSJens Axboe 474c7fb1942SJens Axboe /* register ring based provide buffer group */ 475c7fb1942SJens Axboe IORING_REGISTER_PBUF_RING = 22, 476c7fb1942SJens Axboe IORING_UNREGISTER_PBUF_RING = 23, 477c7fb1942SJens Axboe 47878a861b9SJens Axboe /* sync cancelation API */ 47978a861b9SJens Axboe IORING_REGISTER_SYNC_CANCEL = 24, 48078a861b9SJens Axboe 4816e73dffbSPavel Begunkov /* register a range of fixed file slots for automatic slot allocation */ 4826e73dffbSPavel Begunkov IORING_REGISTER_FILE_ALLOC_RANGE = 25, 4836e73dffbSPavel Begunkov 4849d4a75efSStefano Garzarella /* this goes last */ 4859d4a75efSStefano Garzarella IORING_REGISTER_LAST 4869d4a75efSStefano Garzarella }; 487c3a31e60SJens Axboe 488dd47c104SEugene Syromiatnikov /* io-wq worker categories */ 489dd47c104SEugene Syromiatnikov enum { 490dd47c104SEugene Syromiatnikov IO_WQ_BOUND, 491dd47c104SEugene Syromiatnikov IO_WQ_UNBOUND, 492dd47c104SEugene Syromiatnikov }; 493dd47c104SEugene Syromiatnikov 494269bbe5fSBijan Mottahedeh /* deprecated, see struct io_uring_rsrc_update */ 495c3a31e60SJens Axboe struct io_uring_files_update { 496c3a31e60SJens Axboe __u32 offset; 4971292e972SEugene Syromiatnikov __u32 resv; 4981292e972SEugene Syromiatnikov __aligned_u64 /* __s32 * */ fds; 499c3a31e60SJens Axboe }; 500edafcceeSJens Axboe 501a8da73a3SJens Axboe /* 502a8da73a3SJens Axboe * Register a fully sparse file space, rather than pass in an array of all 503a8da73a3SJens Axboe * -1 file descriptors. 504a8da73a3SJens Axboe */ 505a8da73a3SJens Axboe #define IORING_RSRC_REGISTER_SPARSE (1U << 0) 506a8da73a3SJens Axboe 507792e3582SPavel Begunkov struct io_uring_rsrc_register { 508792e3582SPavel Begunkov __u32 nr; 509a8da73a3SJens Axboe __u32 flags; 510992da01aSPavel Begunkov __u64 resv2; 511792e3582SPavel Begunkov __aligned_u64 data; 512792e3582SPavel Begunkov __aligned_u64 tags; 513792e3582SPavel Begunkov }; 514792e3582SPavel Begunkov 515c3bdad02SPavel Begunkov struct io_uring_rsrc_update { 516c3bdad02SPavel Begunkov __u32 offset; 517c3bdad02SPavel Begunkov __u32 resv; 518c3bdad02SPavel Begunkov __aligned_u64 data; 519c3bdad02SPavel Begunkov }; 520c3bdad02SPavel Begunkov 521c3bdad02SPavel Begunkov struct io_uring_rsrc_update2 { 522c3bdad02SPavel Begunkov __u32 offset; 523c3bdad02SPavel Begunkov __u32 resv; 524c3bdad02SPavel Begunkov __aligned_u64 data; 525c3bdad02SPavel Begunkov __aligned_u64 tags; 526c3bdad02SPavel Begunkov __u32 nr; 527992da01aSPavel Begunkov __u32 resv2; 528c3bdad02SPavel Begunkov }; 529c3bdad02SPavel Begunkov 530bc24d6bdSPavel Begunkov struct io_uring_notification_slot { 531bc24d6bdSPavel Begunkov __u64 tag; 532bc24d6bdSPavel Begunkov __u64 resv[3]; 533bc24d6bdSPavel Begunkov }; 534bc24d6bdSPavel Begunkov 535bc24d6bdSPavel Begunkov struct io_uring_notification_register { 536bc24d6bdSPavel Begunkov __u32 nr_slots; 537bc24d6bdSPavel Begunkov __u32 resv; 538bc24d6bdSPavel Begunkov __u64 resv2; 539bc24d6bdSPavel Begunkov __u64 data; 540bc24d6bdSPavel Begunkov __u64 resv3; 541bc24d6bdSPavel Begunkov }; 542bc24d6bdSPavel Begunkov 5434e0377a1Snoah /* Skip updating fd indexes set to this value in the fd table */ 5444e0377a1Snoah #define IORING_REGISTER_FILES_SKIP (-2) 5454e0377a1Snoah 54666f4af93SJens Axboe #define IO_URING_OP_SUPPORTED (1U << 0) 54766f4af93SJens Axboe 54866f4af93SJens Axboe struct io_uring_probe_op { 54966f4af93SJens Axboe __u8 op; 55066f4af93SJens Axboe __u8 resv; 55166f4af93SJens Axboe __u16 flags; /* IO_URING_OP_* flags */ 55266f4af93SJens Axboe __u32 resv2; 55366f4af93SJens Axboe }; 55466f4af93SJens Axboe 55566f4af93SJens Axboe struct io_uring_probe { 55666f4af93SJens Axboe __u8 last_op; /* last opcode supported */ 55766f4af93SJens Axboe __u8 ops_len; /* length of ops[] array below */ 55866f4af93SJens Axboe __u16 resv; 55966f4af93SJens Axboe __u32 resv2[3]; 5608fcf4c48SGustavo A. R. Silva struct io_uring_probe_op ops[]; 56166f4af93SJens Axboe }; 56266f4af93SJens Axboe 56321b55dbcSStefano Garzarella struct io_uring_restriction { 56421b55dbcSStefano Garzarella __u16 opcode; 56521b55dbcSStefano Garzarella union { 56621b55dbcSStefano Garzarella __u8 register_op; /* IORING_RESTRICTION_REGISTER_OP */ 56721b55dbcSStefano Garzarella __u8 sqe_op; /* IORING_RESTRICTION_SQE_OP */ 56821b55dbcSStefano Garzarella __u8 sqe_flags; /* IORING_RESTRICTION_SQE_FLAGS_* */ 56921b55dbcSStefano Garzarella }; 57021b55dbcSStefano Garzarella __u8 resv; 57121b55dbcSStefano Garzarella __u32 resv2[3]; 57221b55dbcSStefano Garzarella }; 57321b55dbcSStefano Garzarella 574c7fb1942SJens Axboe struct io_uring_buf { 575c7fb1942SJens Axboe __u64 addr; 576c7fb1942SJens Axboe __u32 len; 577c7fb1942SJens Axboe __u16 bid; 578c7fb1942SJens Axboe __u16 resv; 579c7fb1942SJens Axboe }; 580c7fb1942SJens Axboe 581c7fb1942SJens Axboe struct io_uring_buf_ring { 582c7fb1942SJens Axboe union { 583c7fb1942SJens Axboe /* 584c7fb1942SJens Axboe * To avoid spilling into more pages than we need to, the 585c7fb1942SJens Axboe * ring tail is overlaid with the io_uring_buf->resv field. 586c7fb1942SJens Axboe */ 587c7fb1942SJens Axboe struct { 588c7fb1942SJens Axboe __u64 resv1; 589c7fb1942SJens Axboe __u32 resv2; 590c7fb1942SJens Axboe __u16 resv3; 591c7fb1942SJens Axboe __u16 tail; 592c7fb1942SJens Axboe }; 593c7fb1942SJens Axboe struct io_uring_buf bufs[0]; 594c7fb1942SJens Axboe }; 595c7fb1942SJens Axboe }; 596c7fb1942SJens Axboe 597c7fb1942SJens Axboe /* argument for IORING_(UN)REGISTER_PBUF_RING */ 598c7fb1942SJens Axboe struct io_uring_buf_reg { 599c7fb1942SJens Axboe __u64 ring_addr; 600c7fb1942SJens Axboe __u32 ring_entries; 601c7fb1942SJens Axboe __u16 bgid; 602c7fb1942SJens Axboe __u16 pad; 603c7fb1942SJens Axboe __u64 resv[3]; 604c7fb1942SJens Axboe }; 605c7fb1942SJens Axboe 60621b55dbcSStefano Garzarella /* 60721b55dbcSStefano Garzarella * io_uring_restriction->opcode values 60821b55dbcSStefano Garzarella */ 60921b55dbcSStefano Garzarella enum { 61021b55dbcSStefano Garzarella /* Allow an io_uring_register(2) opcode */ 61121b55dbcSStefano Garzarella IORING_RESTRICTION_REGISTER_OP = 0, 61221b55dbcSStefano Garzarella 61321b55dbcSStefano Garzarella /* Allow an sqe opcode */ 61421b55dbcSStefano Garzarella IORING_RESTRICTION_SQE_OP = 1, 61521b55dbcSStefano Garzarella 61621b55dbcSStefano Garzarella /* Allow sqe flags */ 61721b55dbcSStefano Garzarella IORING_RESTRICTION_SQE_FLAGS_ALLOWED = 2, 61821b55dbcSStefano Garzarella 61921b55dbcSStefano Garzarella /* Require sqe flags (these flags must be set on each submission) */ 62021b55dbcSStefano Garzarella IORING_RESTRICTION_SQE_FLAGS_REQUIRED = 3, 62121b55dbcSStefano Garzarella 62221b55dbcSStefano Garzarella IORING_RESTRICTION_LAST 62321b55dbcSStefano Garzarella }; 62421b55dbcSStefano Garzarella 625c73ebb68SHao Xu struct io_uring_getevents_arg { 626c73ebb68SHao Xu __u64 sigmask; 627c73ebb68SHao Xu __u32 sigmask_sz; 628c73ebb68SHao Xu __u32 pad; 629c73ebb68SHao Xu __u64 ts; 630c73ebb68SHao Xu }; 631c73ebb68SHao Xu 63278a861b9SJens Axboe /* 63378a861b9SJens Axboe * Argument for IORING_REGISTER_SYNC_CANCEL 63478a861b9SJens Axboe */ 63578a861b9SJens Axboe struct io_uring_sync_cancel_reg { 63678a861b9SJens Axboe __u64 addr; 63778a861b9SJens Axboe __s32 fd; 63878a861b9SJens Axboe __u32 flags; 63978a861b9SJens Axboe struct __kernel_timespec timeout; 64078a861b9SJens Axboe __u64 pad[4]; 64178a861b9SJens Axboe }; 64278a861b9SJens Axboe 6436e73dffbSPavel Begunkov /* 6446e73dffbSPavel Begunkov * Argument for IORING_REGISTER_FILE_ALLOC_RANGE 6456e73dffbSPavel Begunkov * The range is specified as [off, off + len) 6466e73dffbSPavel Begunkov */ 6476e73dffbSPavel Begunkov struct io_uring_file_index_range { 6486e73dffbSPavel Begunkov __u32 off; 6496e73dffbSPavel Begunkov __u32 len; 6506e73dffbSPavel Begunkov __u64 resv; 6516e73dffbSPavel Begunkov }; 6526e73dffbSPavel Begunkov 6539bb66906SDylan Yudaken struct io_uring_recvmsg_out { 6549bb66906SDylan Yudaken __u32 namelen; 6559bb66906SDylan Yudaken __u32 controllen; 6569bb66906SDylan Yudaken __u32 payloadlen; 6579bb66906SDylan Yudaken __u32 flags; 6589bb66906SDylan Yudaken }; 6599bb66906SDylan Yudaken 660e1d0c6d0SAmmar Faizi #ifdef __cplusplus 661e1d0c6d0SAmmar Faizi } 662e1d0c6d0SAmmar Faizi #endif 663e1d0c6d0SAmmar Faizi 6642b188cc1SJens Axboe #endif 665