io_uring.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757
  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. #include <linux/fs.h>
  11. #include <linux/types.h>
  12. /*
  13. * this file is shared with liburing and that has to autodetect
  14. * if linux/time_types.h is available or not, it can
  15. * define UAPI_LINUX_IO_URING_H_SKIP_LINUX_TIME_TYPES_H
  16. * if linux/time_types.h is not available
  17. */
  18. #ifndef UAPI_LINUX_IO_URING_H_SKIP_LINUX_TIME_TYPES_H
  19. #include <linux/time_types.h>
  20. #endif
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /*
  25. * IO submission data structure (Submission Queue Entry)
  26. */
  27. struct io_uring_sqe {
  28. __u8 opcode; /* type of operation for this sqe */
  29. __u8 flags; /* IOSQE_ flags */
  30. __u16 ioprio; /* ioprio for the request */
  31. __s32 fd; /* file descriptor to do IO on */
  32. union {
  33. __u64 off; /* offset into file */
  34. __u64 addr2;
  35. struct {
  36. __u32 cmd_op;
  37. __u32 __pad1;
  38. };
  39. };
  40. union {
  41. __u64 addr; /* pointer to buffer or iovecs */
  42. __u64 splice_off_in;
  43. struct {
  44. __u32 level;
  45. __u32 optname;
  46. };
  47. };
  48. __u32 len; /* buffer size or number of iovecs */
  49. union {
  50. __kernel_rwf_t rw_flags;
  51. __u32 fsync_flags;
  52. __u16 poll_events; /* compatibility */
  53. __u32 poll32_events; /* word-reversed for BE */
  54. __u32 sync_range_flags;
  55. __u32 msg_flags;
  56. __u32 timeout_flags;
  57. __u32 accept_flags;
  58. __u32 cancel_flags;
  59. __u32 open_flags;
  60. __u32 statx_flags;
  61. __u32 fadvise_advice;
  62. __u32 splice_flags;
  63. __u32 rename_flags;
  64. __u32 unlink_flags;
  65. __u32 hardlink_flags;
  66. __u32 xattr_flags;
  67. __u32 msg_ring_flags;
  68. __u32 uring_cmd_flags;
  69. __u32 waitid_flags;
  70. __u32 futex_flags;
  71. };
  72. __u64 user_data; /* data to be passed back at completion time */
  73. /* pack this to avoid bogus arm OABI complaints */
  74. union {
  75. /* index into fixed buffers, if used */
  76. __u16 buf_index;
  77. /* for grouped buffer selection */
  78. __u16 buf_group;
  79. } __attribute__((packed));
  80. /* personality to use, if used */
  81. __u16 personality;
  82. union {
  83. __s32 splice_fd_in;
  84. __u32 file_index;
  85. __u32 optlen;
  86. struct {
  87. __u16 addr_len;
  88. __u16 __pad3[1];
  89. };
  90. };
  91. union {
  92. struct {
  93. __u64 addr3;
  94. __u64 __pad2[1];
  95. };
  96. __u64 optval;
  97. /*
  98. * If the ring is initialized with IORING_SETUP_SQE128, then
  99. * this field is used for 80 bytes of arbitrary command data
  100. */
  101. __u8 cmd[0];
  102. };
  103. };
  104. /*
  105. * If sqe->file_index is set to this for opcodes that instantiate a new
  106. * direct descriptor (like openat/openat2/accept), then io_uring will allocate
  107. * an available direct descriptor instead of having the application pass one
  108. * in. The picked direct descriptor will be returned in cqe->res, or -ENFILE
  109. * if the space is full.
  110. */
  111. #define IORING_FILE_INDEX_ALLOC (~0U)
  112. enum {
  113. IOSQE_FIXED_FILE_BIT,
  114. IOSQE_IO_DRAIN_BIT,
  115. IOSQE_IO_LINK_BIT,
  116. IOSQE_IO_HARDLINK_BIT,
  117. IOSQE_ASYNC_BIT,
  118. IOSQE_BUFFER_SELECT_BIT,
  119. IOSQE_CQE_SKIP_SUCCESS_BIT,
  120. };
  121. /*
  122. * sqe->flags
  123. */
  124. /* use fixed fileset */
  125. #define IOSQE_FIXED_FILE (1U << IOSQE_FIXED_FILE_BIT)
  126. /* issue after inflight IO */
  127. #define IOSQE_IO_DRAIN (1U << IOSQE_IO_DRAIN_BIT)
  128. /* links next sqe */
  129. #define IOSQE_IO_LINK (1U << IOSQE_IO_LINK_BIT)
  130. /* like LINK, but stronger */
  131. #define IOSQE_IO_HARDLINK (1U << IOSQE_IO_HARDLINK_BIT)
  132. /* always go async */
  133. #define IOSQE_ASYNC (1U << IOSQE_ASYNC_BIT)
  134. /* select buffer from sqe->buf_group */
  135. #define IOSQE_BUFFER_SELECT (1U << IOSQE_BUFFER_SELECT_BIT)
  136. /* don't post CQE if request succeeded */
  137. #define IOSQE_CQE_SKIP_SUCCESS (1U << IOSQE_CQE_SKIP_SUCCESS_BIT)
  138. /*
  139. * io_uring_setup() flags
  140. */
  141. #define IORING_SETUP_IOPOLL (1U << 0) /* io_context is polled */
  142. #define IORING_SETUP_SQPOLL (1U << 1) /* SQ poll thread */
  143. #define IORING_SETUP_SQ_AFF (1U << 2) /* sq_thread_cpu is valid */
  144. #define IORING_SETUP_CQSIZE (1U << 3) /* app defines CQ size */
  145. #define IORING_SETUP_CLAMP (1U << 4) /* clamp SQ/CQ ring sizes */
  146. #define IORING_SETUP_ATTACH_WQ (1U << 5) /* attach to existing wq */
  147. #define IORING_SETUP_R_DISABLED (1U << 6) /* start with ring disabled */
  148. #define IORING_SETUP_SUBMIT_ALL (1U << 7) /* continue submit on error */
  149. /*
  150. * Cooperative task running. When requests complete, they often require
  151. * forcing the submitter to transition to the kernel to complete. If this
  152. * flag is set, work will be done when the task transitions anyway, rather
  153. * than force an inter-processor interrupt reschedule. This avoids interrupting
  154. * a task running in userspace, and saves an IPI.
  155. */
  156. #define IORING_SETUP_COOP_TASKRUN (1U << 8)
  157. /*
  158. * If COOP_TASKRUN is set, get notified if task work is available for
  159. * running and a kernel transition would be needed to run it. This sets
  160. * IORING_SQ_TASKRUN in the sq ring flags. Not valid with COOP_TASKRUN.
  161. */
  162. #define IORING_SETUP_TASKRUN_FLAG (1U << 9)
  163. #define IORING_SETUP_SQE128 (1U << 10) /* SQEs are 128 byte */
  164. #define IORING_SETUP_CQE32 (1U << 11) /* CQEs are 32 byte */
  165. /*
  166. * Only one task is allowed to submit requests
  167. */
  168. #define IORING_SETUP_SINGLE_ISSUER (1U << 12)
  169. /*
  170. * Defer running task work to get events.
  171. * Rather than running bits of task work whenever the task transitions
  172. * try to do it just before it is needed.
  173. */
  174. #define IORING_SETUP_DEFER_TASKRUN (1U << 13)
  175. /*
  176. * Application provides the memory for the rings
  177. */
  178. #define IORING_SETUP_NO_MMAP (1U << 14)
  179. /*
  180. * Register the ring fd in itself for use with
  181. * IORING_REGISTER_USE_REGISTERED_RING; return a registered fd index rather
  182. * than an fd.
  183. */
  184. #define IORING_SETUP_REGISTERED_FD_ONLY (1U << 15)
  185. /*
  186. * Removes indirection through the SQ index array.
  187. */
  188. #define IORING_SETUP_NO_SQARRAY (1U << 16)
  189. enum io_uring_op {
  190. IORING_OP_NOP,
  191. IORING_OP_READV,
  192. IORING_OP_WRITEV,
  193. IORING_OP_FSYNC,
  194. IORING_OP_READ_FIXED,
  195. IORING_OP_WRITE_FIXED,
  196. IORING_OP_POLL_ADD,
  197. IORING_OP_POLL_REMOVE,
  198. IORING_OP_SYNC_FILE_RANGE,
  199. IORING_OP_SENDMSG,
  200. IORING_OP_RECVMSG,
  201. IORING_OP_TIMEOUT,
  202. IORING_OP_TIMEOUT_REMOVE,
  203. IORING_OP_ACCEPT,
  204. IORING_OP_ASYNC_CANCEL,
  205. IORING_OP_LINK_TIMEOUT,
  206. IORING_OP_CONNECT,
  207. IORING_OP_FALLOCATE,
  208. IORING_OP_OPENAT,
  209. IORING_OP_CLOSE,
  210. IORING_OP_FILES_UPDATE,
  211. IORING_OP_STATX,
  212. IORING_OP_READ,
  213. IORING_OP_WRITE,
  214. IORING_OP_FADVISE,
  215. IORING_OP_MADVISE,
  216. IORING_OP_SEND,
  217. IORING_OP_RECV,
  218. IORING_OP_OPENAT2,
  219. IORING_OP_EPOLL_CTL,
  220. IORING_OP_SPLICE,
  221. IORING_OP_PROVIDE_BUFFERS,
  222. IORING_OP_REMOVE_BUFFERS,
  223. IORING_OP_TEE,
  224. IORING_OP_SHUTDOWN,
  225. IORING_OP_RENAMEAT,
  226. IORING_OP_UNLINKAT,
  227. IORING_OP_MKDIRAT,
  228. IORING_OP_SYMLINKAT,
  229. IORING_OP_LINKAT,
  230. IORING_OP_MSG_RING,
  231. IORING_OP_FSETXATTR,
  232. IORING_OP_SETXATTR,
  233. IORING_OP_FGETXATTR,
  234. IORING_OP_GETXATTR,
  235. IORING_OP_SOCKET,
  236. IORING_OP_URING_CMD,
  237. IORING_OP_SEND_ZC,
  238. IORING_OP_SENDMSG_ZC,
  239. IORING_OP_READ_MULTISHOT,
  240. IORING_OP_WAITID,
  241. IORING_OP_FUTEX_WAIT,
  242. IORING_OP_FUTEX_WAKE,
  243. IORING_OP_FUTEX_WAITV,
  244. /* this goes last, obviously */
  245. IORING_OP_LAST,
  246. };
  247. /*
  248. * sqe->uring_cmd_flags top 8bits aren't available for userspace
  249. * IORING_URING_CMD_FIXED use registered buffer; pass this flag
  250. * along with setting sqe->buf_index.
  251. */
  252. #define IORING_URING_CMD_FIXED (1U << 0)
  253. #define IORING_URING_CMD_MASK IORING_URING_CMD_FIXED
  254. /*
  255. * sqe->fsync_flags
  256. */
  257. #define IORING_FSYNC_DATASYNC (1U << 0)
  258. /*
  259. * sqe->timeout_flags
  260. */
  261. #define IORING_TIMEOUT_ABS (1U << 0)
  262. #define IORING_TIMEOUT_UPDATE (1U << 1)
  263. #define IORING_TIMEOUT_BOOTTIME (1U << 2)
  264. #define IORING_TIMEOUT_REALTIME (1U << 3)
  265. #define IORING_LINK_TIMEOUT_UPDATE (1U << 4)
  266. #define IORING_TIMEOUT_ETIME_SUCCESS (1U << 5)
  267. #define IORING_TIMEOUT_MULTISHOT (1U << 6)
  268. #define IORING_TIMEOUT_CLOCK_MASK (IORING_TIMEOUT_BOOTTIME | IORING_TIMEOUT_REALTIME)
  269. #define IORING_TIMEOUT_UPDATE_MASK (IORING_TIMEOUT_UPDATE | IORING_LINK_TIMEOUT_UPDATE)
  270. /*
  271. * sqe->splice_flags
  272. * extends splice(2) flags
  273. */
  274. #define SPLICE_F_FD_IN_FIXED (1U << 31) /* the last bit of __u32 */
  275. /*
  276. * POLL_ADD flags. Note that since sqe->poll_events is the flag space, the
  277. * command flags for POLL_ADD are stored in sqe->len.
  278. *
  279. * IORING_POLL_ADD_MULTI Multishot poll. Sets IORING_CQE_F_MORE if
  280. * the poll handler will continue to report
  281. * CQEs on behalf of the same SQE.
  282. *
  283. * IORING_POLL_UPDATE Update existing poll request, matching
  284. * sqe->addr as the old user_data field.
  285. *
  286. * IORING_POLL_LEVEL Level triggered poll.
  287. */
  288. #define IORING_POLL_ADD_MULTI (1U << 0)
  289. #define IORING_POLL_UPDATE_EVENTS (1U << 1)
  290. #define IORING_POLL_UPDATE_USER_DATA (1U << 2)
  291. #define IORING_POLL_ADD_LEVEL (1U << 3)
  292. /*
  293. * ASYNC_CANCEL flags.
  294. *
  295. * IORING_ASYNC_CANCEL_ALL Cancel all requests that match the given key
  296. * IORING_ASYNC_CANCEL_FD Key off 'fd' for cancelation rather than the
  297. * request 'user_data'
  298. * IORING_ASYNC_CANCEL_ANY Match any request
  299. * IORING_ASYNC_CANCEL_FD_FIXED 'fd' passed in is a fixed descriptor
  300. * IORING_ASYNC_CANCEL_USERDATA Match on user_data, default for no other key
  301. * IORING_ASYNC_CANCEL_OP Match request based on opcode
  302. */
  303. #define IORING_ASYNC_CANCEL_ALL (1U << 0)
  304. #define IORING_ASYNC_CANCEL_FD (1U << 1)
  305. #define IORING_ASYNC_CANCEL_ANY (1U << 2)
  306. #define IORING_ASYNC_CANCEL_FD_FIXED (1U << 3)
  307. #define IORING_ASYNC_CANCEL_USERDATA (1U << 4)
  308. #define IORING_ASYNC_CANCEL_OP (1U << 5)
  309. /*
  310. * send/sendmsg and recv/recvmsg flags (sqe->ioprio)
  311. *
  312. * IORING_RECVSEND_POLL_FIRST If set, instead of first attempting to send
  313. * or receive and arm poll if that yields an
  314. * -EAGAIN result, arm poll upfront and skip
  315. * the initial transfer attempt.
  316. *
  317. * IORING_RECV_MULTISHOT Multishot recv. Sets IORING_CQE_F_MORE if
  318. * the handler will continue to report
  319. * CQEs on behalf of the same SQE.
  320. *
  321. * IORING_RECVSEND_FIXED_BUF Use registered buffers, the index is stored in
  322. * the buf_index field.
  323. *
  324. * IORING_SEND_ZC_REPORT_USAGE
  325. * If set, SEND[MSG]_ZC should report
  326. * the zerocopy usage in cqe.res
  327. * for the IORING_CQE_F_NOTIF cqe.
  328. * 0 is reported if zerocopy was actually possible.
  329. * IORING_NOTIF_USAGE_ZC_COPIED if data was copied
  330. * (at least partially).
  331. */
  332. #define IORING_RECVSEND_POLL_FIRST (1U << 0)
  333. #define IORING_RECV_MULTISHOT (1U << 1)
  334. #define IORING_RECVSEND_FIXED_BUF (1U << 2)
  335. #define IORING_SEND_ZC_REPORT_USAGE (1U << 3)
  336. /*
  337. * cqe.res for IORING_CQE_F_NOTIF if
  338. * IORING_SEND_ZC_REPORT_USAGE was requested
  339. *
  340. * It should be treated as a flag, all other
  341. * bits of cqe.res should be treated as reserved!
  342. */
  343. #define IORING_NOTIF_USAGE_ZC_COPIED (1U << 31)
  344. /*
  345. * accept flags stored in sqe->ioprio
  346. */
  347. #define IORING_ACCEPT_MULTISHOT (1U << 0)
  348. /*
  349. * IORING_OP_MSG_RING command types, stored in sqe->addr
  350. */
  351. enum {
  352. IORING_MSG_DATA, /* pass sqe->len as 'res' and off as user_data */
  353. IORING_MSG_SEND_FD, /* send a registered fd to another ring */
  354. };
  355. /*
  356. * IORING_OP_MSG_RING flags (sqe->msg_ring_flags)
  357. *
  358. * IORING_MSG_RING_CQE_SKIP Don't post a CQE to the target ring. Not
  359. * applicable for IORING_MSG_DATA, obviously.
  360. */
  361. #define IORING_MSG_RING_CQE_SKIP (1U << 0)
  362. /* Pass through the flags from sqe->file_index to cqe->flags */
  363. #define IORING_MSG_RING_FLAGS_PASS (1U << 1)
  364. /*
  365. * IO completion data structure (Completion Queue Entry)
  366. */
  367. struct io_uring_cqe {
  368. __u64 user_data; /* sqe->data submission passed back */
  369. __s32 res; /* result code for this event */
  370. __u32 flags;
  371. /*
  372. * If the ring is initialized with IORING_SETUP_CQE32, then this field
  373. * contains 16-bytes of padding, doubling the size of the CQE.
  374. */
  375. __u64 big_cqe[];
  376. };
  377. /*
  378. * cqe->flags
  379. *
  380. * IORING_CQE_F_BUFFER If set, the upper 16 bits are the buffer ID
  381. * IORING_CQE_F_MORE If set, parent SQE will generate more CQE entries
  382. * IORING_CQE_F_SOCK_NONEMPTY If set, more data to read after socket recv
  383. * IORING_CQE_F_NOTIF Set for notification CQEs. Can be used to distinct
  384. * them from sends.
  385. */
  386. #define IORING_CQE_F_BUFFER (1U << 0)
  387. #define IORING_CQE_F_MORE (1U << 1)
  388. #define IORING_CQE_F_SOCK_NONEMPTY (1U << 2)
  389. #define IORING_CQE_F_NOTIF (1U << 3)
  390. enum {
  391. IORING_CQE_BUFFER_SHIFT = 16,
  392. };
  393. /*
  394. * Magic offsets for the application to mmap the data it needs
  395. */
  396. #define IORING_OFF_SQ_RING 0ULL
  397. #define IORING_OFF_CQ_RING 0x8000000ULL
  398. #define IORING_OFF_SQES 0x10000000ULL
  399. #define IORING_OFF_PBUF_RING 0x80000000ULL
  400. #define IORING_OFF_PBUF_SHIFT 16
  401. #define IORING_OFF_MMAP_MASK 0xf8000000ULL
  402. /*
  403. * Filled with the offset for mmap(2)
  404. */
  405. struct io_sqring_offsets {
  406. __u32 head;
  407. __u32 tail;
  408. __u32 ring_mask;
  409. __u32 ring_entries;
  410. __u32 flags;
  411. __u32 dropped;
  412. __u32 array;
  413. __u32 resv1;
  414. __u64 user_addr;
  415. };
  416. /*
  417. * sq_ring->flags
  418. */
  419. #define IORING_SQ_NEED_WAKEUP (1U << 0) /* needs io_uring_enter wakeup */
  420. #define IORING_SQ_CQ_OVERFLOW (1U << 1) /* CQ ring is overflown */
  421. #define IORING_SQ_TASKRUN (1U << 2) /* task should enter the kernel */
  422. struct io_cqring_offsets {
  423. __u32 head;
  424. __u32 tail;
  425. __u32 ring_mask;
  426. __u32 ring_entries;
  427. __u32 overflow;
  428. __u32 cqes;
  429. __u32 flags;
  430. __u32 resv1;
  431. __u64 user_addr;
  432. };
  433. /*
  434. * cq_ring->flags
  435. */
  436. /* disable eventfd notifications */
  437. #define IORING_CQ_EVENTFD_DISABLED (1U << 0)
  438. /*
  439. * io_uring_enter(2) flags
  440. */
  441. #define IORING_ENTER_GETEVENTS (1U << 0)
  442. #define IORING_ENTER_SQ_WAKEUP (1U << 1)
  443. #define IORING_ENTER_SQ_WAIT (1U << 2)
  444. #define IORING_ENTER_EXT_ARG (1U << 3)
  445. #define IORING_ENTER_REGISTERED_RING (1U << 4)
  446. /*
  447. * Passed in for io_uring_setup(2). Copied back with updated info on success
  448. */
  449. struct io_uring_params {
  450. __u32 sq_entries;
  451. __u32 cq_entries;
  452. __u32 flags;
  453. __u32 sq_thread_cpu;
  454. __u32 sq_thread_idle;
  455. __u32 features;
  456. __u32 wq_fd;
  457. __u32 resv[3];
  458. struct io_sqring_offsets sq_off;
  459. struct io_cqring_offsets cq_off;
  460. };
  461. /*
  462. * io_uring_params->features flags
  463. */
  464. #define IORING_FEAT_SINGLE_MMAP (1U << 0)
  465. #define IORING_FEAT_NODROP (1U << 1)
  466. #define IORING_FEAT_SUBMIT_STABLE (1U << 2)
  467. #define IORING_FEAT_RW_CUR_POS (1U << 3)
  468. #define IORING_FEAT_CUR_PERSONALITY (1U << 4)
  469. #define IORING_FEAT_FAST_POLL (1U << 5)
  470. #define IORING_FEAT_POLL_32BITS (1U << 6)
  471. #define IORING_FEAT_SQPOLL_NONFIXED (1U << 7)
  472. #define IORING_FEAT_EXT_ARG (1U << 8)
  473. #define IORING_FEAT_NATIVE_WORKERS (1U << 9)
  474. #define IORING_FEAT_RSRC_TAGS (1U << 10)
  475. #define IORING_FEAT_CQE_SKIP (1U << 11)
  476. #define IORING_FEAT_LINKED_FILE (1U << 12)
  477. #define IORING_FEAT_REG_REG_RING (1U << 13)
  478. /*
  479. * io_uring_register(2) opcodes and arguments
  480. */
  481. enum {
  482. IORING_REGISTER_BUFFERS = 0,
  483. IORING_UNREGISTER_BUFFERS = 1,
  484. IORING_REGISTER_FILES = 2,
  485. IORING_UNREGISTER_FILES = 3,
  486. IORING_REGISTER_EVENTFD = 4,
  487. IORING_UNREGISTER_EVENTFD = 5,
  488. IORING_REGISTER_FILES_UPDATE = 6,
  489. IORING_REGISTER_EVENTFD_ASYNC = 7,
  490. IORING_REGISTER_PROBE = 8,
  491. IORING_REGISTER_PERSONALITY = 9,
  492. IORING_UNREGISTER_PERSONALITY = 10,
  493. IORING_REGISTER_RESTRICTIONS = 11,
  494. IORING_REGISTER_ENABLE_RINGS = 12,
  495. /* extended with tagging */
  496. IORING_REGISTER_FILES2 = 13,
  497. IORING_REGISTER_FILES_UPDATE2 = 14,
  498. IORING_REGISTER_BUFFERS2 = 15,
  499. IORING_REGISTER_BUFFERS_UPDATE = 16,
  500. /* set/clear io-wq thread affinities */
  501. IORING_REGISTER_IOWQ_AFF = 17,
  502. IORING_UNREGISTER_IOWQ_AFF = 18,
  503. /* set/get max number of io-wq workers */
  504. IORING_REGISTER_IOWQ_MAX_WORKERS = 19,
  505. /* register/unregister io_uring fd with the ring */
  506. IORING_REGISTER_RING_FDS = 20,
  507. IORING_UNREGISTER_RING_FDS = 21,
  508. /* register ring based provide buffer group */
  509. IORING_REGISTER_PBUF_RING = 22,
  510. IORING_UNREGISTER_PBUF_RING = 23,
  511. /* sync cancelation API */
  512. IORING_REGISTER_SYNC_CANCEL = 24,
  513. /* register a range of fixed file slots for automatic slot allocation */
  514. IORING_REGISTER_FILE_ALLOC_RANGE = 25,
  515. /* this goes last */
  516. IORING_REGISTER_LAST,
  517. /* flag added to the opcode to use a registered ring fd */
  518. IORING_REGISTER_USE_REGISTERED_RING = 1U << 31
  519. };
  520. /* io-wq worker categories */
  521. enum {
  522. IO_WQ_BOUND,
  523. IO_WQ_UNBOUND,
  524. };
  525. /* deprecated, see struct io_uring_rsrc_update */
  526. struct io_uring_files_update {
  527. __u32 offset;
  528. __u32 resv;
  529. __aligned_u64 /* __s32 * */ fds;
  530. };
  531. /*
  532. * Register a fully sparse file space, rather than pass in an array of all
  533. * -1 file descriptors.
  534. */
  535. #define IORING_RSRC_REGISTER_SPARSE (1U << 0)
  536. struct io_uring_rsrc_register {
  537. __u32 nr;
  538. __u32 flags;
  539. __u64 resv2;
  540. __aligned_u64 data;
  541. __aligned_u64 tags;
  542. };
  543. struct io_uring_rsrc_update {
  544. __u32 offset;
  545. __u32 resv;
  546. __aligned_u64 data;
  547. };
  548. struct io_uring_rsrc_update2 {
  549. __u32 offset;
  550. __u32 resv;
  551. __aligned_u64 data;
  552. __aligned_u64 tags;
  553. __u32 nr;
  554. __u32 resv2;
  555. };
  556. /* Skip updating fd indexes set to this value in the fd table */
  557. #define IORING_REGISTER_FILES_SKIP (-2)
  558. #define IO_URING_OP_SUPPORTED (1U << 0)
  559. struct io_uring_probe_op {
  560. __u8 op;
  561. __u8 resv;
  562. __u16 flags; /* IO_URING_OP_* flags */
  563. __u32 resv2;
  564. };
  565. struct io_uring_probe {
  566. __u8 last_op; /* last opcode supported */
  567. __u8 ops_len; /* length of ops[] array below */
  568. __u16 resv;
  569. __u32 resv2[3];
  570. struct io_uring_probe_op ops[];
  571. };
  572. struct io_uring_restriction {
  573. __u16 opcode;
  574. union {
  575. __u8 register_op; /* IORING_RESTRICTION_REGISTER_OP */
  576. __u8 sqe_op; /* IORING_RESTRICTION_SQE_OP */
  577. __u8 sqe_flags; /* IORING_RESTRICTION_SQE_FLAGS_* */
  578. };
  579. __u8 resv;
  580. __u32 resv2[3];
  581. };
  582. struct io_uring_buf {
  583. __u64 addr;
  584. __u32 len;
  585. __u16 bid;
  586. __u16 resv;
  587. };
  588. struct io_uring_buf_ring {
  589. union {
  590. /*
  591. * To avoid spilling into more pages than we need to, the
  592. * ring tail is overlaid with the io_uring_buf->resv field.
  593. */
  594. struct {
  595. __u64 resv1;
  596. __u32 resv2;
  597. __u16 resv3;
  598. __u16 tail;
  599. };
  600. __DECLARE_FLEX_ARRAY(struct io_uring_buf, bufs);
  601. };
  602. };
  603. /*
  604. * Flags for IORING_REGISTER_PBUF_RING.
  605. *
  606. * IOU_PBUF_RING_MMAP: If set, kernel will allocate the memory for the ring.
  607. * The application must not set a ring_addr in struct
  608. * io_uring_buf_reg, instead it must subsequently call
  609. * mmap(2) with the offset set as:
  610. * IORING_OFF_PBUF_RING | (bgid << IORING_OFF_PBUF_SHIFT)
  611. * to get a virtual mapping for the ring.
  612. */
  613. enum {
  614. IOU_PBUF_RING_MMAP = 1,
  615. };
  616. /* argument for IORING_(UN)REGISTER_PBUF_RING */
  617. struct io_uring_buf_reg {
  618. __u64 ring_addr;
  619. __u32 ring_entries;
  620. __u16 bgid;
  621. __u16 flags;
  622. __u64 resv[3];
  623. };
  624. /*
  625. * io_uring_restriction->opcode values
  626. */
  627. enum {
  628. /* Allow an io_uring_register(2) opcode */
  629. IORING_RESTRICTION_REGISTER_OP = 0,
  630. /* Allow an sqe opcode */
  631. IORING_RESTRICTION_SQE_OP = 1,
  632. /* Allow sqe flags */
  633. IORING_RESTRICTION_SQE_FLAGS_ALLOWED = 2,
  634. /* Require sqe flags (these flags must be set on each submission) */
  635. IORING_RESTRICTION_SQE_FLAGS_REQUIRED = 3,
  636. IORING_RESTRICTION_LAST
  637. };
  638. struct io_uring_getevents_arg {
  639. __u64 sigmask;
  640. __u32 sigmask_sz;
  641. __u32 pad;
  642. __u64 ts;
  643. };
  644. /*
  645. * Argument for IORING_REGISTER_SYNC_CANCEL
  646. */
  647. struct io_uring_sync_cancel_reg {
  648. __u64 addr;
  649. __s32 fd;
  650. __u32 flags;
  651. struct __kernel_timespec timeout;
  652. __u8 opcode;
  653. __u8 pad[7];
  654. __u64 pad2[3];
  655. };
  656. /*
  657. * Argument for IORING_REGISTER_FILE_ALLOC_RANGE
  658. * The range is specified as [off, off + len)
  659. */
  660. struct io_uring_file_index_range {
  661. __u32 off;
  662. __u32 len;
  663. __u64 resv;
  664. };
  665. struct io_uring_recvmsg_out {
  666. __u32 namelen;
  667. __u32 controllen;
  668. __u32 payloadlen;
  669. __u32 flags;
  670. };
  671. /*
  672. * Argument for IORING_OP_URING_CMD when file is a socket
  673. */
  674. enum {
  675. SOCKET_URING_OP_SIOCINQ = 0,
  676. SOCKET_URING_OP_SIOCOUTQ,
  677. SOCKET_URING_OP_GETSOCKOPT,
  678. SOCKET_URING_OP_SETSOCKOPT,
  679. };
  680. #ifdef __cplusplus
  681. }
  682. #endif
  683. #endif