Jens Axboe | 0f21220 | 2020-09-13 13:09:39 -0600 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 | #ifndef _LINUX_IO_URING_H |
| 3 | #define _LINUX_IO_URING_H |
| 4 | |
| 5 | #include <linux/sched.h> |
| 6 | #include <linux/xarray.h> |
Anuj Gupta | a9216fa | 2022-09-30 11:57:38 +0530 | [diff] [blame] | 7 | #include <uapi/linux/io_uring.h> |
Jens Axboe | 98447d6 | 2020-10-14 10:48:51 -0600 | [diff] [blame] | 8 | |
Jens Axboe | ee692a2 | 2022-05-11 11:17:45 +0530 | [diff] [blame] | 9 | enum io_uring_cmd_flags { |
| 10 | IO_URING_F_COMPLETE_DEFER = 1, |
| 11 | IO_URING_F_UNLOCKED = 2, |
| 12 | /* int's last bit, sign checks are usually faster than a bit test */ |
| 13 | IO_URING_F_NONBLOCK = INT_MIN, |
| 14 | |
| 15 | /* ctx state flags, for URING_CMD */ |
| 16 | IO_URING_F_SQE128 = 4, |
| 17 | IO_URING_F_CQE32 = 8, |
| 18 | IO_URING_F_IOPOLL = 16, |
Pavel Begunkov | 9148286 | 2022-11-17 18:40:16 +0000 | [diff] [blame] | 19 | |
| 20 | /* the request is executed from poll, it should not be freed */ |
| 21 | IO_URING_F_MULTISHOT = 32, |
Jens Axboe | ee692a2 | 2022-05-11 11:17:45 +0530 | [diff] [blame] | 22 | }; |
| 23 | |
| 24 | struct io_uring_cmd { |
| 25 | struct file *file; |
| 26 | const void *cmd; |
Kanchan Joshi | 5756a3a | 2022-08-23 21:44:41 +0530 | [diff] [blame] | 27 | union { |
| 28 | /* callback to defer completions to task context */ |
Jens Axboe | e5da118 | 2023-03-20 20:01:25 -0600 | [diff] [blame] | 29 | void (*task_work_cb)(struct io_uring_cmd *cmd, unsigned); |
Kanchan Joshi | 5756a3a | 2022-08-23 21:44:41 +0530 | [diff] [blame] | 30 | /* used for polled completion */ |
| 31 | void *cookie; |
| 32 | }; |
Jens Axboe | ee692a2 | 2022-05-11 11:17:45 +0530 | [diff] [blame] | 33 | u32 cmd_op; |
Anuj Gupta | 9cda70f6 | 2022-09-30 11:57:39 +0530 | [diff] [blame] | 34 | u32 flags; |
Jens Axboe | ee692a2 | 2022-05-11 11:17:45 +0530 | [diff] [blame] | 35 | u8 pdu[32]; /* available inline for free use */ |
| 36 | }; |
| 37 | |
Jens Axboe | 0f21220 | 2020-09-13 13:09:39 -0600 | [diff] [blame] | 38 | #if defined(CONFIG_IO_URING) |
Anuj Gupta | a9216fa | 2022-09-30 11:57:38 +0530 | [diff] [blame] | 39 | int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw, |
| 40 | struct iov_iter *iter, void *ioucmd); |
Jens Axboe | e5da118 | 2023-03-20 20:01:25 -0600 | [diff] [blame] | 41 | void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret, ssize_t res2, |
| 42 | unsigned issue_flags); |
Jens Axboe | ee692a2 | 2022-05-11 11:17:45 +0530 | [diff] [blame] | 43 | void io_uring_cmd_complete_in_task(struct io_uring_cmd *ioucmd, |
Jens Axboe | e5da118 | 2023-03-20 20:01:25 -0600 | [diff] [blame] | 44 | void (*task_work_cb)(struct io_uring_cmd *, unsigned)); |
Hao Xu | f552a27 | 2021-08-12 12:14:35 +0800 | [diff] [blame] | 45 | void __io_uring_cancel(bool cancel_all); |
Jens Axboe | 0f21220 | 2020-09-13 13:09:39 -0600 | [diff] [blame] | 46 | void __io_uring_free(struct task_struct *tsk); |
Jens Axboe | e7a6c00 | 2022-03-04 08:22:22 -0700 | [diff] [blame] | 47 | void io_uring_unreg_ringfd(void); |
Dylan Yudaken | 33337d0 | 2022-04-26 01:29:05 -0700 | [diff] [blame] | 48 | const char *io_uring_get_opcode(u8 opcode); |
Jens Axboe | 28fe81b | 2024-03-13 18:10:12 -0600 | [diff] [blame] | 49 | bool io_is_uring_fops(struct file *file); |
Jens Axboe | 0f21220 | 2020-09-13 13:09:39 -0600 | [diff] [blame] | 50 | |
Hao Xu | f552a27 | 2021-08-12 12:14:35 +0800 | [diff] [blame] | 51 | static inline void io_uring_files_cancel(void) |
Jens Axboe | 0f21220 | 2020-09-13 13:09:39 -0600 | [diff] [blame] | 52 | { |
Jens Axboe | e7a6c00 | 2022-03-04 08:22:22 -0700 | [diff] [blame] | 53 | if (current->io_uring) { |
| 54 | io_uring_unreg_ringfd(); |
Hao Xu | f552a27 | 2021-08-12 12:14:35 +0800 | [diff] [blame] | 55 | __io_uring_cancel(false); |
Jens Axboe | e7a6c00 | 2022-03-04 08:22:22 -0700 | [diff] [blame] | 56 | } |
Pavel Begunkov | 3f48cf1 | 2021-04-11 01:46:27 +0100 | [diff] [blame] | 57 | } |
| 58 | static inline void io_uring_task_cancel(void) |
| 59 | { |
Hao Xu | a4aadd1 | 2021-08-12 12:14:34 +0800 | [diff] [blame] | 60 | if (current->io_uring) |
Hao Xu | f552a27 | 2021-08-12 12:14:35 +0800 | [diff] [blame] | 61 | __io_uring_cancel(true); |
Jens Axboe | 0f21220 | 2020-09-13 13:09:39 -0600 | [diff] [blame] | 62 | } |
| 63 | static inline void io_uring_free(struct task_struct *tsk) |
| 64 | { |
| 65 | if (tsk->io_uring) |
| 66 | __io_uring_free(tsk); |
| 67 | } |
| 68 | #else |
Geert Uytterhoeven | 0e0abad | 2022-10-04 14:39:10 +0200 | [diff] [blame] | 69 | static inline int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw, |
Anuj Gupta | a9216fa | 2022-09-30 11:57:38 +0530 | [diff] [blame] | 70 | struct iov_iter *iter, void *ioucmd) |
| 71 | { |
| 72 | return -EOPNOTSUPP; |
| 73 | } |
Jens Axboe | 28fe81b | 2024-03-13 18:10:12 -0600 | [diff] [blame] | 74 | static inline bool io_is_uring_fops(struct file *file) |
| 75 | { |
| 76 | return false; |
| 77 | } |
Jens Axboe | ee692a2 | 2022-05-11 11:17:45 +0530 | [diff] [blame] | 78 | static inline void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret, |
Jens Axboe | e5da118 | 2023-03-20 20:01:25 -0600 | [diff] [blame] | 79 | ssize_t ret2, unsigned issue_flags) |
Jens Axboe | ee692a2 | 2022-05-11 11:17:45 +0530 | [diff] [blame] | 80 | { |
| 81 | } |
| 82 | static inline void io_uring_cmd_complete_in_task(struct io_uring_cmd *ioucmd, |
Jens Axboe | e5da118 | 2023-03-20 20:01:25 -0600 | [diff] [blame] | 83 | void (*task_work_cb)(struct io_uring_cmd *, unsigned)) |
Jens Axboe | ee692a2 | 2022-05-11 11:17:45 +0530 | [diff] [blame] | 84 | { |
| 85 | } |
Jens Axboe | 0f21220 | 2020-09-13 13:09:39 -0600 | [diff] [blame] | 86 | static inline void io_uring_task_cancel(void) |
| 87 | { |
| 88 | } |
Hao Xu | f552a27 | 2021-08-12 12:14:35 +0800 | [diff] [blame] | 89 | static inline void io_uring_files_cancel(void) |
Jens Axboe | 0f21220 | 2020-09-13 13:09:39 -0600 | [diff] [blame] | 90 | { |
| 91 | } |
| 92 | static inline void io_uring_free(struct task_struct *tsk) |
| 93 | { |
| 94 | } |
Dylan Yudaken | 33337d0 | 2022-04-26 01:29:05 -0700 | [diff] [blame] | 95 | static inline const char *io_uring_get_opcode(u8 opcode) |
| 96 | { |
| 97 | return ""; |
| 98 | } |
Jens Axboe | 0f21220 | 2020-09-13 13:09:39 -0600 | [diff] [blame] | 99 | #endif |
| 100 | |
| 101 | #endif |