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, |
| 19 | }; |
| 20 | |
| 21 | struct io_uring_cmd { |
| 22 | struct file *file; |
| 23 | const void *cmd; |
Kanchan Joshi | 5756a3a | 2022-08-23 21:44:41 +0530 | [diff] [blame] | 24 | union { |
| 25 | /* callback to defer completions to task context */ |
| 26 | void (*task_work_cb)(struct io_uring_cmd *cmd); |
| 27 | /* used for polled completion */ |
| 28 | void *cookie; |
| 29 | }; |
Jens Axboe | ee692a2 | 2022-05-11 11:17:45 +0530 | [diff] [blame] | 30 | u32 cmd_op; |
Anuj Gupta | 9cda70f6 | 2022-09-30 11:57:39 +0530 | [diff] [blame] | 31 | u32 flags; |
Jens Axboe | ee692a2 | 2022-05-11 11:17:45 +0530 | [diff] [blame] | 32 | u8 pdu[32]; /* available inline for free use */ |
| 33 | }; |
| 34 | |
Jens Axboe | 0f21220 | 2020-09-13 13:09:39 -0600 | [diff] [blame] | 35 | #if defined(CONFIG_IO_URING) |
Anuj Gupta | a9216fa | 2022-09-30 11:57:38 +0530 | [diff] [blame] | 36 | int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw, |
| 37 | struct iov_iter *iter, void *ioucmd); |
Jens Axboe | ee692a2 | 2022-05-11 11:17:45 +0530 | [diff] [blame] | 38 | void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret, ssize_t res2); |
| 39 | void io_uring_cmd_complete_in_task(struct io_uring_cmd *ioucmd, |
| 40 | void (*task_work_cb)(struct io_uring_cmd *)); |
Jens Axboe | a3ec600 | 2020-09-18 20:41:00 -0600 | [diff] [blame] | 41 | struct sock *io_uring_get_socket(struct file *file); |
Hao Xu | f552a27 | 2021-08-12 12:14:35 +0800 | [diff] [blame] | 42 | void __io_uring_cancel(bool cancel_all); |
Jens Axboe | 0f21220 | 2020-09-13 13:09:39 -0600 | [diff] [blame] | 43 | void __io_uring_free(struct task_struct *tsk); |
Jens Axboe | e7a6c00 | 2022-03-04 08:22:22 -0700 | [diff] [blame] | 44 | void io_uring_unreg_ringfd(void); |
Dylan Yudaken | 33337d0 | 2022-04-26 01:29:05 -0700 | [diff] [blame] | 45 | const char *io_uring_get_opcode(u8 opcode); |
Jens Axboe | 0f21220 | 2020-09-13 13:09:39 -0600 | [diff] [blame] | 46 | |
Hao Xu | f552a27 | 2021-08-12 12:14:35 +0800 | [diff] [blame] | 47 | static inline void io_uring_files_cancel(void) |
Jens Axboe | 0f21220 | 2020-09-13 13:09:39 -0600 | [diff] [blame] | 48 | { |
Jens Axboe | e7a6c00 | 2022-03-04 08:22:22 -0700 | [diff] [blame] | 49 | if (current->io_uring) { |
| 50 | io_uring_unreg_ringfd(); |
Hao Xu | f552a27 | 2021-08-12 12:14:35 +0800 | [diff] [blame] | 51 | __io_uring_cancel(false); |
Jens Axboe | e7a6c00 | 2022-03-04 08:22:22 -0700 | [diff] [blame] | 52 | } |
Pavel Begunkov | 3f48cf1 | 2021-04-11 01:46:27 +0100 | [diff] [blame] | 53 | } |
| 54 | static inline void io_uring_task_cancel(void) |
| 55 | { |
Hao Xu | a4aadd1 | 2021-08-12 12:14:34 +0800 | [diff] [blame] | 56 | if (current->io_uring) |
Hao Xu | f552a27 | 2021-08-12 12:14:35 +0800 | [diff] [blame] | 57 | __io_uring_cancel(true); |
Jens Axboe | 0f21220 | 2020-09-13 13:09:39 -0600 | [diff] [blame] | 58 | } |
| 59 | static inline void io_uring_free(struct task_struct *tsk) |
| 60 | { |
| 61 | if (tsk->io_uring) |
| 62 | __io_uring_free(tsk); |
| 63 | } |
| 64 | #else |
Geert Uytterhoeven | 0e0abad | 2022-10-04 14:39:10 +0200 | [diff] [blame^] | 65 | 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] | 66 | struct iov_iter *iter, void *ioucmd) |
| 67 | { |
| 68 | return -EOPNOTSUPP; |
| 69 | } |
Jens Axboe | ee692a2 | 2022-05-11 11:17:45 +0530 | [diff] [blame] | 70 | static inline void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret, |
| 71 | ssize_t ret2) |
| 72 | { |
| 73 | } |
| 74 | static inline void io_uring_cmd_complete_in_task(struct io_uring_cmd *ioucmd, |
| 75 | void (*task_work_cb)(struct io_uring_cmd *)) |
| 76 | { |
| 77 | } |
Jens Axboe | a3ec600 | 2020-09-18 20:41:00 -0600 | [diff] [blame] | 78 | static inline struct sock *io_uring_get_socket(struct file *file) |
| 79 | { |
| 80 | return NULL; |
| 81 | } |
Jens Axboe | 0f21220 | 2020-09-13 13:09:39 -0600 | [diff] [blame] | 82 | static inline void io_uring_task_cancel(void) |
| 83 | { |
| 84 | } |
Hao Xu | f552a27 | 2021-08-12 12:14:35 +0800 | [diff] [blame] | 85 | static inline void io_uring_files_cancel(void) |
Jens Axboe | 0f21220 | 2020-09-13 13:09:39 -0600 | [diff] [blame] | 86 | { |
| 87 | } |
| 88 | static inline void io_uring_free(struct task_struct *tsk) |
| 89 | { |
| 90 | } |
Dylan Yudaken | 33337d0 | 2022-04-26 01:29:05 -0700 | [diff] [blame] | 91 | static inline const char *io_uring_get_opcode(u8 opcode) |
| 92 | { |
| 93 | return ""; |
| 94 | } |
Jens Axboe | 0f21220 | 2020-09-13 13:09:39 -0600 | [diff] [blame] | 95 | #endif |
| 96 | |
| 97 | #endif |