Skip to content

Commit 4c72e2b

Browse files
committed
Merge tag 'for-6.8/io_uring-2024-01-08' of git://git.kernel.dk/linux
Pull io_uring updates from Jens Axboe: "Mostly just come fixes and cleanups, but one feature as well. In detail: - Harden the check for handling IOPOLL based on return (Pavel) - Various minor optimizations (Pavel) - Drop remnants of SCM_RIGHTS fd passing support, now that it's no longer supported since 6.7 (me) - Fix for a case where bytes_done wasn't initialized properly on a failure condition for read/write requests (me) - Move the register related code to a separate file (me) - Add support for returning the provided ring buffer head (me) - Add support for adding a direct descriptor to the normal file table (me, Christian Brauner) - Fix for ensuring pending task_work for a ring with DEFER_TASKRUN is run even if we timeout waiting (me)" * tag 'for-6.8/io_uring-2024-01-08' of git://git.kernel.dk/linux: io_uring: ensure local task_work is run on wait timeout io_uring/kbuf: add method for returning provided buffer ring head io_uring/rw: ensure io->bytes_done is always initialized io_uring: drop any code related to SCM_RIGHTS io_uring/unix: drop usage of io_uring socket io_uring/register: move io_uring_register(2) related code to register.c io_uring/openclose: add support for IORING_OP_FIXED_FD_INSTALL io_uring/cmd: inline io_uring_cmd_get_task io_uring/cmd: inline io_uring_cmd_do_in_task_lazy io_uring: split out cmd api into a separate header io_uring: optimise ltimeout for inline execution io_uring: don't check iopoll if request completes
2 parents 01d550f + 6ff1407 commit 4c72e2b

26 files changed

Lines changed: 890 additions & 947 deletions

File tree

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11142,6 +11142,7 @@ L: io-uring@vger.kernel.org
1114211142
S: Maintained
1114311143
T: git git://git.kernel.dk/linux-block
1114411144
T: git git://git.kernel.dk/liburing
11145+
F: include/linux/io_uring/
1114511146
F: include/linux/io_uring.h
1114611147
F: include/linux/io_uring_types.h
1114711148
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: 4 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -6,66 +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-
32-
struct io_uring_cmd {
33-
struct file *file;
34-
const struct io_uring_sqe *sqe;
35-
/* callback to defer completions to task context */
36-
void (*task_work_cb)(struct io_uring_cmd *cmd, unsigned);
37-
u32 cmd_op;
38-
u32 flags;
39-
u8 pdu[32]; /* available inline for free use */
40-
};
41-
42-
static inline const void *io_uring_sqe_cmd(const struct io_uring_sqe *sqe)
43-
{
44-
return sqe->cmd;
45-
}
46-
479
#if defined(CONFIG_IO_URING)
48-
int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw,
49-
struct iov_iter *iter, void *ioucmd);
50-
void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret, ssize_t res2,
51-
unsigned issue_flags);
52-
struct sock *io_uring_get_socket(struct file *file);
5310
void __io_uring_cancel(bool cancel_all);
5411
void __io_uring_free(struct task_struct *tsk);
5512
void io_uring_unreg_ringfd(void);
5613
const char *io_uring_get_opcode(u8 opcode);
57-
void __io_uring_cmd_do_in_task(struct io_uring_cmd *ioucmd,
58-
void (*task_work_cb)(struct io_uring_cmd *, unsigned),
59-
unsigned flags);
60-
/* users should follow semantics of IOU_F_TWQ_LAZY_WAKE */
61-
void io_uring_cmd_do_in_task_lazy(struct io_uring_cmd *ioucmd,
62-
void (*task_work_cb)(struct io_uring_cmd *, unsigned));
63-
64-
static inline void io_uring_cmd_complete_in_task(struct io_uring_cmd *ioucmd,
65-
void (*task_work_cb)(struct io_uring_cmd *, unsigned))
66-
{
67-
__io_uring_cmd_do_in_task(ioucmd, task_work_cb, 0);
68-
}
14+
int io_uring_cmd_sock(struct io_uring_cmd *cmd, unsigned int issue_flags);
15+
bool io_is_uring_fops(struct file *file);
6916

7017
static inline void io_uring_files_cancel(void)
7118
{
@@ -84,32 +31,7 @@ static inline void io_uring_free(struct task_struct *tsk)
8431
if (tsk->io_uring)
8532
__io_uring_free(tsk);
8633
}
87-
int io_uring_cmd_sock(struct io_uring_cmd *cmd, unsigned int issue_flags);
88-
void io_uring_cmd_mark_cancelable(struct io_uring_cmd *cmd,
89-
unsigned int issue_flags);
90-
struct task_struct *io_uring_cmd_get_task(struct io_uring_cmd *cmd);
9134
#else
92-
static inline int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw,
93-
struct iov_iter *iter, void *ioucmd)
94-
{
95-
return -EOPNOTSUPP;
96-
}
97-
static inline void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret,
98-
ssize_t ret2, unsigned issue_flags)
99-
{
100-
}
101-
static inline void io_uring_cmd_complete_in_task(struct io_uring_cmd *ioucmd,
102-
void (*task_work_cb)(struct io_uring_cmd *, unsigned))
103-
{
104-
}
105-
static inline void io_uring_cmd_do_in_task_lazy(struct io_uring_cmd *ioucmd,
106-
void (*task_work_cb)(struct io_uring_cmd *, unsigned))
107-
{
108-
}
109-
static inline struct sock *io_uring_get_socket(struct file *file)
110-
{
111-
return NULL;
112-
}
11335
static inline void io_uring_task_cancel(void)
11436
{
11537
}
@@ -128,13 +50,9 @@ static inline int io_uring_cmd_sock(struct io_uring_cmd *cmd,
12850
{
12951
return -EOPNOTSUPP;
13052
}
131-
static inline void io_uring_cmd_mark_cancelable(struct io_uring_cmd *cmd,
132-
unsigned int issue_flags)
133-
{
134-
}
135-
static inline struct task_struct *io_uring_cmd_get_task(struct io_uring_cmd *cmd)
53+
static inline bool io_is_uring_fops(struct file *file)
13654
{
137-
return NULL;
55+
return false;
13856
}
13957
#endif
14058

include/linux/io_uring/cmd.h

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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+
11+
struct io_uring_cmd {
12+
struct file *file;
13+
const struct io_uring_sqe *sqe;
14+
/* callback to defer completions to task context */
15+
void (*task_work_cb)(struct io_uring_cmd *cmd, unsigned);
16+
u32 cmd_op;
17+
u32 flags;
18+
u8 pdu[32]; /* available inline for free use */
19+
};
20+
21+
static inline const void *io_uring_sqe_cmd(const struct io_uring_sqe *sqe)
22+
{
23+
return sqe->cmd;
24+
}
25+
26+
#if defined(CONFIG_IO_URING)
27+
int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw,
28+
struct iov_iter *iter, void *ioucmd);
29+
void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret, ssize_t res2,
30+
unsigned issue_flags);
31+
void __io_uring_cmd_do_in_task(struct io_uring_cmd *ioucmd,
32+
void (*task_work_cb)(struct io_uring_cmd *, unsigned),
33+
unsigned flags);
34+
35+
void io_uring_cmd_mark_cancelable(struct io_uring_cmd *cmd,
36+
unsigned int issue_flags);
37+
38+
#else
39+
static inline int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw,
40+
struct iov_iter *iter, void *ioucmd)
41+
{
42+
return -EOPNOTSUPP;
43+
}
44+
static inline void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret,
45+
ssize_t ret2, unsigned issue_flags)
46+
{
47+
}
48+
static inline void __io_uring_cmd_do_in_task(struct io_uring_cmd *ioucmd,
49+
void (*task_work_cb)(struct io_uring_cmd *, unsigned),
50+
unsigned flags)
51+
{
52+
}
53+
static inline void io_uring_cmd_mark_cancelable(struct io_uring_cmd *cmd,
54+
unsigned int issue_flags)
55+
{
56+
}
57+
#endif
58+
59+
/* users must follow the IOU_F_TWQ_LAZY_WAKE semantics */
60+
static inline void io_uring_cmd_do_in_task_lazy(struct io_uring_cmd *ioucmd,
61+
void (*task_work_cb)(struct io_uring_cmd *, unsigned))
62+
{
63+
__io_uring_cmd_do_in_task(ioucmd, task_work_cb, IOU_F_TWQ_LAZY_WAKE);
64+
}
65+
66+
static inline void io_uring_cmd_complete_in_task(struct io_uring_cmd *ioucmd,
67+
void (*task_work_cb)(struct io_uring_cmd *, unsigned))
68+
{
69+
__io_uring_cmd_do_in_task(ioucmd, task_work_cb, 0);
70+
}
71+
72+
static inline struct task_struct *io_uring_cmd_get_task(struct io_uring_cmd *cmd)
73+
{
74+
return cmd_to_io_kiocb(cmd)->task;
75+
}
76+
77+
#endif /* _LINUX_IO_URING_CMD_H */

include/linux/io_uring_types.h

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

10+
enum {
11+
/*
12+
* A hint to not wake right away but delay until there are enough of
13+
* tw's queued to match the number of CQEs the task is waiting for.
14+
*
15+
* Must not be used wirh requests generating more than one CQE.
16+
* It's also ignored unless IORING_SETUP_DEFER_TASKRUN is set.
17+
*/
18+
IOU_F_TWQ_LAZY_WAKE = 1,
19+
};
20+
21+
enum io_uring_cmd_flags {
22+
IO_URING_F_COMPLETE_DEFER = 1,
23+
IO_URING_F_UNLOCKED = 2,
24+
/* the request is executed from poll, it should not be freed */
25+
IO_URING_F_MULTISHOT = 4,
26+
/* executed by io-wq */
27+
IO_URING_F_IOWQ = 8,
28+
/* int's last bit, sign checks are usually faster than a bit test */
29+
IO_URING_F_NONBLOCK = INT_MIN,
30+
31+
/* ctx state flags, for URING_CMD */
32+
IO_URING_F_SQE128 = (1 << 8),
33+
IO_URING_F_CQE32 = (1 << 9),
34+
IO_URING_F_IOPOLL = (1 << 10),
35+
36+
/* set when uring wants to cancel a previously issued command */
37+
IO_URING_F_CANCEL = (1 << 11),
38+
IO_URING_F_COMPAT = (1 << 12),
39+
};
40+
1041
struct io_wq_work_node {
1142
struct io_wq_work_node *next;
1243
};
@@ -358,9 +389,6 @@ struct io_ring_ctx {
358389
struct wait_queue_head rsrc_quiesce_wq;
359390
unsigned rsrc_quiesce;
360391

361-
#if defined(CONFIG_UNIX)
362-
struct socket *ring_sock;
363-
#endif
364392
/* hashed buffered write serialization */
365393
struct io_wq_hash *hash_map;
366394

include/uapi/linux/io_uring.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ struct io_uring_sqe {
7171
__u32 uring_cmd_flags;
7272
__u32 waitid_flags;
7373
__u32 futex_flags;
74+
__u32 install_fd_flags;
7475
};
7576
__u64 user_data; /* data to be passed back at completion time */
7677
/* pack this to avoid bogus arm OABI complaints */
@@ -253,6 +254,7 @@ enum io_uring_op {
253254
IORING_OP_FUTEX_WAIT,
254255
IORING_OP_FUTEX_WAKE,
255256
IORING_OP_FUTEX_WAITV,
257+
IORING_OP_FIXED_FD_INSTALL,
256258

257259
/* this goes last, obviously */
258260
IORING_OP_LAST,
@@ -386,6 +388,13 @@ enum {
386388
/* Pass through the flags from sqe->file_index to cqe->flags */
387389
#define IORING_MSG_RING_FLAGS_PASS (1U << 1)
388390

391+
/*
392+
* IORING_OP_FIXED_FD_INSTALL flags (sqe->install_fd_flags)
393+
*
394+
* IORING_FIXED_FD_NO_CLOEXEC Don't mark the fd as O_CLOEXEC
395+
*/
396+
#define IORING_FIXED_FD_NO_CLOEXEC (1U << 0)
397+
389398
/*
390399
* IO completion data structure (Completion Queue Entry)
391400
*/
@@ -558,6 +567,9 @@ enum {
558567
/* register a range of fixed file slots for automatic slot allocation */
559568
IORING_REGISTER_FILE_ALLOC_RANGE = 25,
560569

570+
/* return status information for a buffer group */
571+
IORING_REGISTER_PBUF_STATUS = 26,
572+
561573
/* this goes last */
562574
IORING_REGISTER_LAST,
563575

@@ -684,6 +696,13 @@ struct io_uring_buf_reg {
684696
__u64 resv[3];
685697
};
686698

699+
/* argument for IORING_REGISTER_PBUF_STATUS */
700+
struct io_uring_buf_status {
701+
__u32 buf_group; /* input */
702+
__u32 head; /* output */
703+
__u32 resv[8];
704+
};
705+
687706
/*
688707
* io_uring_restriction->opcode values
689708
*/

io_uring/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ obj-$(CONFIG_IO_URING) += io_uring.o xattr.o nop.o fs.o splice.o \
88
statx.o net.o msg_ring.o timeout.o \
99
sqpoll.o fdinfo.o tctx.o poll.o \
1010
cancel.o kbuf.o rsrc.o rw.o opdef.o \
11-
notif.o waitid.o
11+
notif.o waitid.o register.o
1212
obj-$(CONFIG_IO_WQ) += io-wq.o
1313
obj-$(CONFIG_FUTEX) += futex.o

io_uring/filetable.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,10 @@ static int io_install_fixed_file(struct io_ring_ctx *ctx, struct file *file,
8787
io_file_bitmap_clear(&ctx->file_table, slot_index);
8888
}
8989

90-
ret = io_scm_file_account(ctx, file);
91-
if (!ret) {
92-
*io_get_tag_slot(ctx->file_data, slot_index) = 0;
93-
io_fixed_file_set(file_slot, file);
94-
io_file_bitmap_set(&ctx->file_table, slot_index);
95-
}
96-
return ret;
90+
*io_get_tag_slot(ctx->file_data, slot_index) = 0;
91+
io_fixed_file_set(file_slot, file);
92+
io_file_bitmap_set(&ctx->file_table, slot_index);
93+
return 0;
9794
}
9895

9996
int __io_fixed_fd_install(struct io_ring_ctx *ctx, struct file *file,

0 commit comments

Comments
 (0)