2 This file is part of Valgrind, a dynamic binary instrumentation framework.
4 Copyright (C) 2019 Bart Van Assche <bvanassche@acm.org>
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
11 This program is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, see <http://www.gnu.org/licenses/>.
19 The GNU General Public License is contained in the file COPYING.
22 #ifndef _VKI_IO_URING_H_
23 #define _VKI_IO_URING_H_
25 // Derived from linux-5.2/include/uapi/linux/io_uring.h */
28 * IO submission data structure (Submission Queue Entry)
30 struct vki_io_uring_sqe
{
31 __vki_u8 opcode
; /* type of operation for this sqe */
32 __vki_u8 flags
; /* IOSQE_ flags */
33 __vki_u16 ioprio
; /* ioprio for the request */
34 __vki_s32 fd
; /* file descriptor to do IO on */
35 __vki_u64 off
; /* offset into file */
36 __vki_u64 addr
; /* pointer to buffer or iovecs */
37 __vki_u32 len
; /* buffer size or number of iovecs */
40 __vki_u32 fsync_flags
;
41 __vki_u16 poll_events
;
42 __vki_u32 sync_range_flags
;
45 __vki_u64 user_data
; /* data to be passed back at completion time */
47 __vki_u16 buf_index
; /* index into fixed buffers, if used */
55 #define VKI_IOSQE_FIXED_FILE (1U << 0) /* use fixed fileset */
56 #define VKI_IOSQE_IO_DRAIN (1U << 1) /* issue after inflight IO */
57 #define VKI_IOSQE_IO_LINK (1U << 2) /* links next sqe */
60 * io_uring_setup() flags
62 #define VKI_IORING_SETUP_IOPOLL (1U << 0) /* io_context is polled */
63 #define VKI_IORING_SETUP_SQPOLL (1U << 1) /* SQ poll thread */
64 #define VKI_IORING_SETUP_SQ_AFF (1U << 2) /* sq_thread_cpu is valid */
66 #define VKI_IORING_OP_NOP 0
67 #define VKI_IORING_OP_READV 1
68 #define VKI_IORING_OP_WRITEV 2
69 #define VKI_IORING_OP_FSYNC 3
70 #define VKI_IORING_OP_READ_FIXED 4
71 #define VKI_IORING_OP_WRITE_FIXED 5
72 #define VKI_IORING_OP_POLL_ADD 6
73 #define VKI_IORING_OP_POLL_REMOVE 7
74 #define VKI_IORING_OP_SYNC_FILE_RANGE 8
75 #define VKI_IORING_OP_SENDMSG 9
76 #define VKI_IORING_OP_RECVMSG 10
81 #define VKI_IORING_FSYNC_DATASYNC (1U << 0)
84 * IO completion data structure (Completion Queue Entry)
86 struct vki_io_uring_cqe
{
87 __vki_u64 user_data
; /* sqe->data submission passed back */
88 __vki_s32 res
; /* result code for this event */
93 * Magic offsets for the application to mmap the data it needs
95 #define VKI_IORING_OFF_SQ_RING 0ULL
96 #define VKI_IORING_OFF_CQ_RING 0x8000000ULL
97 #define VKI_IORING_OFF_SQES 0x10000000ULL
100 * Filled with the offset for mmap(2)
102 struct vki_io_sqring_offsets
{
106 __vki_u32 ring_entries
;
117 #define VKI_IORING_SQ_NEED_WAKEUP (1U << 0) /* needs io_uring_enter wakeup */
119 struct vki_io_cqring_offsets
{
123 __vki_u32 ring_entries
;
130 * io_uring_enter(2) flags
132 #define VKI_IORING_ENTER_GETEVENTS (1U << 0)
133 #define VKI_IORING_ENTER_SQ_WAKEUP (1U << 1)
136 * Passed in for io_uring_setup(2). Copied back with updated info on success
138 struct vki_io_uring_params
{
139 __vki_u32 sq_entries
;
140 __vki_u32 cq_entries
;
142 __vki_u32 sq_thread_cpu
;
143 __vki_u32 sq_thread_idle
;
145 struct vki_io_sqring_offsets sq_off
;
146 struct vki_io_cqring_offsets cq_off
;
150 * io_uring_register(2) opcodes and arguments
152 #define VKI_IORING_REGISTER_BUFFERS 0
153 #define VKI_IORING_UNREGISTER_BUFFERS 1
154 #define VKI_IORING_REGISTER_FILES 2
155 #define VKI_IORING_UNREGISTER_FILES 3
156 #define VKI_IORING_REGISTER_EVENTFD 4
157 #define VKI_IORING_UNREGISTER_EVENTFD 5