Skip to content

Commit b66509b

Browse files
isilenceaxboe
authored andcommitted
io_uring: split out cmd api into a separate header
linux/io_uring.h is slowly becoming a rubbish bin where we put anything exposed to other subsystems. For instance, the task exit hooks and io_uring cmd infra are completely orthogonal and don't need each other's definitions. Start cleaning it up by splitting out all command bits into a new header file. Signed-off-by: Pavel Begunkov <[email protected]> Link: https://lore.kernel.org/r/7ec50bae6e21f371d3850796e716917fc141225a.1701391955.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <[email protected]>
1 parent e0b23d9 commit b66509b

File tree

11 files changed

+110
-94
lines changed

11 files changed

+110
-94
lines changed

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11102,6 +11102,7 @@ L: [email protected]
1110211102
S: Maintained
1110311103
T: git git://git.kernel.dk/linux-block
1110411104
T: git git://git.kernel.dk/liburing
11105+
F: include/linux/io_uring/
1110511106
F: include/linux/io_uring.h
1110611107
F: include/linux/io_uring_types.h
1110711108
F: include/trace/events/io_uring.h

drivers/block/ublk_drv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#include <linux/sched/mm.h>
3737
#include <linux/uaccess.h>
3838
#include <linux/cdev.h>
39-
#include <linux/io_uring.h>
39+
#include <linux/io_uring/cmd.h>
4040
#include <linux/blk-mq.h>
4141
#include <linux/delay.h>
4242
#include <linux/mm.h>

drivers/nvme/host/ioctl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
#include <linux/ptrace.h> /* for force_successful_syscall_return */
77
#include <linux/nvme_ioctl.h>
8-
#include <linux/io_uring.h>
8+
#include <linux/io_uring/cmd.h>
99
#include "nvme.h"
1010

1111
enum {

include/linux/io_uring.h

Lines changed: 1 addition & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -6,71 +6,13 @@
66
#include <linux/xarray.h>
77
#include <uapi/linux/io_uring.h>
88

9-
enum io_uring_cmd_flags {
10-
IO_URING_F_COMPLETE_DEFER = 1,
11-
IO_URING_F_UNLOCKED = 2,
12-
/* the request is executed from poll, it should not be freed */
13-
IO_URING_F_MULTISHOT = 4,
14-
/* executed by io-wq */
15-
IO_URING_F_IOWQ = 8,
16-
/* int's last bit, sign checks are usually faster than a bit test */
17-
IO_URING_F_NONBLOCK = INT_MIN,
18-
19-
/* ctx state flags, for URING_CMD */
20-
IO_URING_F_SQE128 = (1 << 8),
21-
IO_URING_F_CQE32 = (1 << 9),
22-
IO_URING_F_IOPOLL = (1 << 10),
23-
24-
/* set when uring wants to cancel a previously issued command */
25-
IO_URING_F_CANCEL = (1 << 11),
26-
IO_URING_F_COMPAT = (1 << 12),
27-
};
28-
29-
/* only top 8 bits of sqe->uring_cmd_flags for kernel internal use */
30-
#define IORING_URING_CMD_CANCELABLE (1U << 30)
31-
#define IORING_URING_CMD_POLLED (1U << 31)
32-
33-
struct io_uring_cmd {
34-
struct file *file;
35-
const struct io_uring_sqe *sqe;
36-
union {
37-
/* callback to defer completions to task context */
38-
void (*task_work_cb)(struct io_uring_cmd *cmd, unsigned);
39-
/* used for polled completion */
40-
void *cookie;
41-
};
42-
u32 cmd_op;
43-
u32 flags;
44-
u8 pdu[32]; /* available inline for free use */
45-
};
46-
47-
static inline const void *io_uring_sqe_cmd(const struct io_uring_sqe *sqe)
48-
{
49-
return sqe->cmd;
50-
}
51-
529
#if defined(CONFIG_IO_URING)
53-
int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw,
54-
struct iov_iter *iter, void *ioucmd);
55-
void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret, ssize_t res2,
56-
unsigned issue_flags);
5710
struct sock *io_uring_get_socket(struct file *file);
5811
void __io_uring_cancel(bool cancel_all);
5912
void __io_uring_free(struct task_struct *tsk);
6013
void io_uring_unreg_ringfd(void);
6114
const char *io_uring_get_opcode(u8 opcode);
62-
void __io_uring_cmd_do_in_task(struct io_uring_cmd *ioucmd,
63-
void (*task_work_cb)(struct io_uring_cmd *, unsigned),
64-
unsigned flags);
65-
/* users should follow semantics of IOU_F_TWQ_LAZY_WAKE */
66-
void io_uring_cmd_do_in_task_lazy(struct io_uring_cmd *ioucmd,
67-
void (*task_work_cb)(struct io_uring_cmd *, unsigned));
68-
69-
static inline void io_uring_cmd_complete_in_task(struct io_uring_cmd *ioucmd,
70-
void (*task_work_cb)(struct io_uring_cmd *, unsigned))
71-
{
72-
__io_uring_cmd_do_in_task(ioucmd, task_work_cb, 0);
73-
}
15+
int io_uring_cmd_sock(struct io_uring_cmd *cmd, unsigned int issue_flags);
7416

7517
static inline void io_uring_files_cancel(void)
7618
{
@@ -89,28 +31,7 @@ static inline void io_uring_free(struct task_struct *tsk)
8931
if (tsk->io_uring)
9032
__io_uring_free(tsk);
9133
}
92-
int io_uring_cmd_sock(struct io_uring_cmd *cmd, unsigned int issue_flags);
93-
void io_uring_cmd_mark_cancelable(struct io_uring_cmd *cmd,
94-
unsigned int issue_flags);
95-
struct task_struct *io_uring_cmd_get_task(struct io_uring_cmd *cmd);
9634
#else
97-
static inline int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw,
98-
struct iov_iter *iter, void *ioucmd)
99-
{
100-
return -EOPNOTSUPP;
101-
}
102-
static inline void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret,
103-
ssize_t ret2, unsigned issue_flags)
104-
{
105-
}
106-
static inline void io_uring_cmd_complete_in_task(struct io_uring_cmd *ioucmd,
107-
void (*task_work_cb)(struct io_uring_cmd *, unsigned))
108-
{
109-
}
110-
static inline void io_uring_cmd_do_in_task_lazy(struct io_uring_cmd *ioucmd,
111-
void (*task_work_cb)(struct io_uring_cmd *, unsigned))
112-
{
113-
}
11435
static inline struct sock *io_uring_get_socket(struct file *file)
11536
{
11637
return NULL;
@@ -133,14 +54,6 @@ static inline int io_uring_cmd_sock(struct io_uring_cmd *cmd,
13354
{
13455
return -EOPNOTSUPP;
13556
}
136-
static inline void io_uring_cmd_mark_cancelable(struct io_uring_cmd *cmd,
137-
unsigned int issue_flags)
138-
{
139-
}
140-
static inline struct task_struct *io_uring_cmd_get_task(struct io_uring_cmd *cmd)
141-
{
142-
return NULL;
143-
}
14457
#endif
14558

14659
#endif

include/linux/io_uring/cmd.h

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/* SPDX-License-Identifier: GPL-2.0-or-later */
2+
#ifndef _LINUX_IO_URING_CMD_H
3+
#define _LINUX_IO_URING_CMD_H
4+
5+
#include <uapi/linux/io_uring.h>
6+
#include <linux/io_uring_types.h>
7+
8+
/* only top 8 bits of sqe->uring_cmd_flags for kernel internal use */
9+
#define IORING_URING_CMD_CANCELABLE (1U << 30)
10+
#define IORING_URING_CMD_POLLED (1U << 31)
11+
12+
struct io_uring_cmd {
13+
struct file *file;
14+
const struct io_uring_sqe *sqe;
15+
union {
16+
/* callback to defer completions to task context */
17+
void (*task_work_cb)(struct io_uring_cmd *cmd, unsigned);
18+
/* used for polled completion */
19+
void *cookie;
20+
};
21+
u32 cmd_op;
22+
u32 flags;
23+
u8 pdu[32]; /* available inline for free use */
24+
};
25+
26+
static inline const void *io_uring_sqe_cmd(const struct io_uring_sqe *sqe)
27+
{
28+
return sqe->cmd;
29+
}
30+
31+
#if defined(CONFIG_IO_URING)
32+
int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw,
33+
struct iov_iter *iter, void *ioucmd);
34+
void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret, ssize_t res2,
35+
unsigned issue_flags);
36+
void __io_uring_cmd_do_in_task(struct io_uring_cmd *ioucmd,
37+
void (*task_work_cb)(struct io_uring_cmd *, unsigned),
38+
unsigned flags);
39+
/* users should follow semantics of IOU_F_TWQ_LAZY_WAKE */
40+
void io_uring_cmd_do_in_task_lazy(struct io_uring_cmd *ioucmd,
41+
void (*task_work_cb)(struct io_uring_cmd *, unsigned));
42+
43+
static inline void io_uring_cmd_complete_in_task(struct io_uring_cmd *ioucmd,
44+
void (*task_work_cb)(struct io_uring_cmd *, unsigned))
45+
{
46+
__io_uring_cmd_do_in_task(ioucmd, task_work_cb, 0);
47+
}
48+
49+
void io_uring_cmd_mark_cancelable(struct io_uring_cmd *cmd,
50+
unsigned int issue_flags);
51+
struct task_struct *io_uring_cmd_get_task(struct io_uring_cmd *cmd);
52+
53+
#else
54+
static inline int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw,
55+
struct iov_iter *iter, void *ioucmd)
56+
{
57+
return -EOPNOTSUPP;
58+
}
59+
static inline void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret,
60+
ssize_t ret2, unsigned issue_flags)
61+
{
62+
}
63+
static inline void io_uring_cmd_complete_in_task(struct io_uring_cmd *ioucmd,
64+
void (*task_work_cb)(struct io_uring_cmd *, unsigned))
65+
{
66+
}
67+
static inline void io_uring_cmd_do_in_task_lazy(struct io_uring_cmd *ioucmd,
68+
void (*task_work_cb)(struct io_uring_cmd *, unsigned))
69+
{
70+
}
71+
static inline void io_uring_cmd_mark_cancelable(struct io_uring_cmd *cmd,
72+
unsigned int issue_flags)
73+
{
74+
}
75+
static inline struct task_struct *io_uring_cmd_get_task(struct io_uring_cmd *cmd)
76+
{
77+
return NULL;
78+
}
79+
#endif
80+
81+
#endif /* _LINUX_IO_URING_CMD_H */

include/linux/io_uring_types.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,26 @@
77
#include <linux/llist.h>
88
#include <uapi/linux/io_uring.h>
99

10+
enum io_uring_cmd_flags {
11+
IO_URING_F_COMPLETE_DEFER = 1,
12+
IO_URING_F_UNLOCKED = 2,
13+
/* the request is executed from poll, it should not be freed */
14+
IO_URING_F_MULTISHOT = 4,
15+
/* executed by io-wq */
16+
IO_URING_F_IOWQ = 8,
17+
/* int's last bit, sign checks are usually faster than a bit test */
18+
IO_URING_F_NONBLOCK = INT_MIN,
19+
20+
/* ctx state flags, for URING_CMD */
21+
IO_URING_F_SQE128 = (1 << 8),
22+
IO_URING_F_CQE32 = (1 << 9),
23+
IO_URING_F_IOPOLL = (1 << 10),
24+
25+
/* set when uring wants to cancel a previously issued command */
26+
IO_URING_F_CANCEL = (1 << 11),
27+
IO_URING_F_COMPAT = (1 << 12),
28+
};
29+
1030
struct io_wq_work_node {
1131
struct io_wq_work_node *next;
1232
};

io_uring/io_uring.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
#include <linux/fadvise.h>
7171
#include <linux/task_work.h>
7272
#include <linux/io_uring.h>
73+
#include <linux/io_uring/cmd.h>
7374
#include <linux/audit.h>
7475
#include <linux/security.h>
7576
#include <asm/shmparam.h>

io_uring/rw.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <linux/poll.h>
1111
#include <linux/nospec.h>
1212
#include <linux/compat.h>
13-
#include <linux/io_uring.h>
13+
#include <linux/io_uring/cmd.h>
1414

1515
#include <uapi/linux/io_uring.h>
1616

io_uring/uring_cmd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <linux/kernel.h>
33
#include <linux/errno.h>
44
#include <linux/file.h>
5-
#include <linux/io_uring.h>
5+
#include <linux/io_uring/cmd.h>
66
#include <linux/security.h>
77
#include <linux/nospec.h>
88

security/selinux/hooks.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
#include <uapi/linux/mount.h>
9292
#include <linux/fsnotify.h>
9393
#include <linux/fanotify.h>
94-
#include <linux/io_uring.h>
94+
#include <linux/io_uring/cmd.h>
9595

9696
#include "avc.h"
9797
#include "objsec.h"

0 commit comments

Comments
 (0)