Skip to content

Commit 9b40ba1

Browse files
committed
Merge tag 'for-7.2/io_uring-20260615' of git://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux
Pull io_uring updates from Jens Axboe: - Rework the task_work infrastructure. Both the local (DEFER_TASKRUN) and the normal (tctx) task_work lists were llist based, which is LIFO ordered, and hence each run had to do an O(n) list reversal pass first to restore queue order. Additionally, to cap the amount of task_work run, each method needed a retry list as well. Add a lockless MPCS FIFO queue (based on Dmitry Vyukov's intrusive MPSC algorithm) and switch both task_work lists to it. It performs better than llists and we can then also ditch the retry lists as well as entries are popped one-at-the-time. On top of those changes, run the tctx fallback task_work directly and remove the now-unused per-ctx fallback machinery entirely. - zcrx user notifications. Add a mechanism for zcrx to communicate conditions back to userspace via a dedicated CQE, with the initial users being notification on running out of buffers and on a frag copy fallback, plus shared-memory notification statistics. Alongside that, a series of zcrx reliability and cleanup fixes: more reliable scrubbing, poisoning pointers on unregistration, dropping an extra ifq close, adding a ctx back-pointer, reordering fd allocation in the export path, and killing a dead 'sock' member. - Allow using io_uring registered buffers for plain SEND and RECV, not just for the zero-copy send path. This enables targets like ublk's NBD backend to push/pull IO data directly to/from a registered buffer over a plain send/recv on a TCP socket. - Registered buffer improvements: account huge pages correctly, bump the io_mapped_ubuf length field to size_t, and raise the previous 1GB registered buffer size limit. - Restrict the ctx access exposed to io_uring BPF struct_ops programs by handing them an opaque type rather than the full io_ring_ctx, and add a separate MAINTAINERS entry for the bpf-ops code. - Allow opcode filtering on IORING_OP_CONNECT. - Validate ring-provided buffer addresses with access_ok(), and align the legacy buffer add limit with MAX_BIDS_PER_BGID. - Various other cleanups and minor fixes, including avoiding msghdr async data on connect/bind, dropping async_size for OP_LISTEN, making the POLL_FIRST receive side checks consistent, re-checking IO_WQ_BIT_EXIT for each linked work item, and using trace_call__##name() at guarded tracepoint call sites. * tag 'for-7.2/io_uring-20260615' of git://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux: (31 commits) io_uring/bpf-ops: add a separate maintainer entry io_uring/net: make POLL_FIRST receive side checks consistent io_uring: remove the per-ctx fallback task_work machinery io_uring: run the tctx task_work fallback directly io_uring: switch normal task_work to a mpscq io_uring: switch local task_work to a mpscq io_uring/mpscq: add lockless multi-producer, single-consumer FIFO queue io_uring: grab RCU read lock marking task run io_uring/zcrx: kill dead 'sock' member in struct io_zcrx_args io_uring/kbuf: validate ring provided buffer addresses with access_ok() io_uring/net: support registered buffer for plain send and recv io_uring/nop: Drop a wrong comment in struct io_nop io_uring/net: Remove async_size for OP_LISTEN io_uring/net: Avoid msghdr on op_connect/op_bind async data io_uring/bpf-ops: restrict ctx access to BPF io_uring/io-wq: re-check IO_WQ_BIT_EXIT for each linked work item io_uring/kbuf: align legacy buffer add limit with MAX_BIDS_PER_BGID io_uring/zcrx: add shared-memory notification statistics io_uring/zcrx: notify user on frag copy fallback io_uring/zcrx: notify user when out of buffers ...
2 parents d29fd59 + d9b710f commit 9b40ba1

31 files changed

Lines changed: 1004 additions & 360 deletions

MAINTAINERS

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13542,6 +13542,14 @@ T: git git://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux.git
1354213542
S: Maintained
1354313543
F: io_uring/zcrx.*
1354413544

13545+
IO_URING BPF-OPS
13546+
M: Pavel Begunkov <asml.silence@gmail.com>
13547+
L: io-uring@vger.kernel.org
13548+
T: git git://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux.git
13549+
S: Maintained
13550+
F: io_uring/bpf-ops.*
13551+
F: io_uring/loop.*
13552+
1354513553
IPMI SUBSYSTEM
1354613554
M: Corey Minyard <corey@minyard.net>
1354713555
L: openipmi-developer@lists.sourceforge.net (moderated for non-subscribers)

include/linux/io_uring_types.h

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,18 @@ struct io_wq_work_list {
5555
struct io_wq_work_node *last;
5656
};
5757

58+
/*
59+
* Lockless multi-producer, single-consumer FIFO queue, see
60+
* io_uring/mpscq.h for the implementation and rules. Defined here so
61+
* that it can be embedded in io_ring_ctx. This is the producer side
62+
* only - the consumer cursor is kept separately, on a cacheline that
63+
* isn't dirtied by the producers.
64+
*/
65+
struct mpscq {
66+
struct llist_node *tail; /* producers */
67+
struct llist_node stub;
68+
};
69+
5870
struct io_wq_work {
5971
struct io_wq_work_node list;
6072
atomic_t flags;
@@ -119,6 +131,11 @@ struct io_uring_task {
119131
const struct io_ring_ctx *last;
120132
struct task_struct *task;
121133
struct io_wq *io_wq;
134+
/*
135+
* Consumer cursor for ->task_list. Only popped by the task itself,
136+
* or by ->fallback_work once the task can no longer run task_work.
137+
*/
138+
struct llist_node *task_head;
122139
struct file *registered_rings[IO_RINGFD_REG_MAX];
123140

124141
struct xarray xa;
@@ -127,8 +144,13 @@ struct io_uring_task {
127144
atomic_t inflight_tracked;
128145
struct percpu_counter inflight;
129146

147+
/* drains ->task_list once the task can no longer run task_work */
148+
struct work_struct fallback_work;
149+
130150
struct { /* task_work */
131-
struct llist_head task_list;
151+
struct mpscq task_list;
152+
/* BIT(0) guards adding tw only once */
153+
unsigned long tw_pending;
132154
struct callback_head task_work;
133155
} ____cacheline_aligned_in_smp;
134156
};
@@ -290,6 +312,8 @@ enum {
290312
IO_RING_F_IOWQ_LIMITS_SET = BIT(12),
291313
};
292314

315+
struct iou_ctx {};
316+
293317
struct io_ring_ctx {
294318
/* const or read-mostly hot data */
295319
struct {
@@ -346,6 +370,14 @@ struct io_ring_ctx {
346370
bool poll_multi_queue;
347371
struct list_head iopoll_list;
348372

373+
/*
374+
* Consumer cursor for ->work_list, protected by ->uring_lock.
375+
* Deliberately kept away from the producer side of the queue,
376+
* as it's written for every popped entry, and the producer
377+
* cacheline is contended enough as it is.
378+
*/
379+
struct llist_node *work_head;
380+
349381
struct io_file_table file_table;
350382
struct io_rsrc_data buf_table;
351383
struct io_alloc_cache node_cache;
@@ -366,7 +398,7 @@ struct io_ring_ctx {
366398
struct io_alloc_cache rw_cache;
367399
struct io_alloc_cache cmd_cache;
368400

369-
int (*loop_step)(struct io_ring_ctx *ctx,
401+
int (*loop_step)(struct iou_ctx *,
370402
struct iou_loop_params *);
371403

372404
/*
@@ -403,8 +435,7 @@ struct io_ring_ctx {
403435
*/
404436
struct {
405437
struct io_rings __rcu *rings_rcu;
406-
struct llist_head work_llist;
407-
struct llist_head retry_llist;
438+
struct mpscq work_list;
408439
unsigned long check_cq;
409440
atomic_t cq_wait_nr;
410441
atomic_t cq_timeouts;
@@ -446,6 +477,9 @@ struct io_ring_ctx {
446477
/* Stores zcrx object pointers of type struct io_zcrx_ifq */
447478
struct xarray zcrx_ctxs;
448479

480+
/* Used for accounting references on pages in registered buffers */
481+
struct xarray hpage_acct;
482+
449483
u32 pers_next;
450484
struct xarray personalities;
451485

@@ -464,8 +498,6 @@ struct io_ring_ctx {
464498
struct mutex tctx_lock;
465499

466500
/* ctx exit and cancelation */
467-
struct llist_head fallback_llist;
468-
struct delayed_work fallback_work;
469501
struct work_struct exit_work;
470502
struct completion ref_comp;
471503

@@ -725,8 +757,6 @@ struct io_kiocb {
725757
*/
726758
u16 buf_index;
727759

728-
unsigned nr_tw;
729-
730760
/* REQ_F_* flags */
731761
io_req_flags_t flags;
732762

include/uapi/linux/io_uring/bpf_filter.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,22 @@ struct io_uring_bpf_ctx {
2727
__u64 mode;
2828
__u64 resolve;
2929
} open;
30+
/*
31+
* For CONNECT: fields are populated only when addr_len covers
32+
* them; unpopulated fields are zero from the caller-side memset
33+
* in io_uring_populate_bpf_ctx(). port and v4_addr are network
34+
* byte order. Filters may only issue BPF_LD|BPF_W|BPF_ABS at
35+
* 4-byte aligned offsets; load + mask for sub-word fields.
36+
*/
37+
struct {
38+
__u32 family; /* sa_family_t zero-extended */
39+
__be16 port;
40+
__u8 pad[2];
41+
union {
42+
__be32 v4_addr;
43+
__u8 v6_addr[16];
44+
};
45+
} connect;
3046
};
3147
};
3248

include/uapi/linux/io_uring/query.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ enum {
2323
IO_URING_QUERY_OPCODES = 0,
2424
IO_URING_QUERY_ZCRX = 1,
2525
IO_URING_QUERY_SCQ = 2,
26+
IO_URING_QUERY_ZCRX_NOTIF = 3,
2627

2728
__IO_URING_QUERY_MAX,
2829
};
@@ -62,6 +63,17 @@ struct io_uring_query_zcrx {
6263
__u64 __resv2;
6364
};
6465

66+
struct io_uring_query_zcrx_notif {
67+
/* Bitmask of supported ZCRX_NOTIF_* flags */
68+
__u32 notif_flags;
69+
/* Size of io_uring_zcrx_notif_stats */
70+
__u32 notif_stats_size;
71+
/* Required alignment for the stats struct within the region (ie stats_offset) */
72+
__u32 notif_stats_off_alignment;
73+
__u32 __resv1;
74+
__u64 __resv2[4];
75+
};
76+
6577
struct io_uring_query_scq {
6678
/* The SQ/CQ rings header size */
6779
__u64 hdr_size;

include/uapi/linux/io_uring/zcrx.h

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,32 @@ enum zcrx_features {
6565
* value in struct io_uring_zcrx_ifq_reg::rx_buf_len.
6666
*/
6767
ZCRX_FEATURE_RX_PAGE_SIZE = 1 << 0,
68+
ZCRX_FEATURE_NOTIFICATION = 1 << 1,
69+
};
70+
71+
enum zcrx_notification_type {
72+
ZCRX_NOTIF_NO_BUFFERS,
73+
ZCRX_NOTIF_COPY,
74+
75+
__ZCRX_NOTIF_TYPE_LAST,
76+
};
77+
78+
enum zcrx_notification_desc_flags {
79+
/* If set, stats_offset holds a valid offset to a notif_stats struct */
80+
ZCRX_NOTIF_DESC_FLAG_STATS = 1 << 0,
81+
};
82+
83+
struct zcrx_notif_stats {
84+
__u64 copy_count; /* cumulative copy-fallback CQEs */
85+
__u64 copy_bytes; /* cumulative bytes copied */
86+
};
87+
88+
struct zcrx_notification_desc {
89+
__u64 user_data;
90+
__u32 type_mask;
91+
__u32 flags; /* see enum zcrx_notification_desc_flags */
92+
__u64 stats_offset; /* offset from the beginning of refill ring region for stats */
93+
__u64 __resv2[9];
6894
};
6995

7096
/*
@@ -82,12 +108,14 @@ struct io_uring_zcrx_ifq_reg {
82108
struct io_uring_zcrx_offsets offsets;
83109
__u32 zcrx_id;
84110
__u32 rx_buf_len;
85-
__u64 __resv[3];
111+
__u64 notif_desc; /* see struct zcrx_notification_desc */
112+
__u64 __resv[2];
86113
};
87114

88115
enum zcrx_ctrl_op {
89116
ZCRX_CTRL_FLUSH_RQ,
90117
ZCRX_CTRL_EXPORT,
118+
ZCRX_CTRL_ARM_NOTIFICATION,
91119

92120
__ZCRX_CTRL_LAST,
93121
};
@@ -101,6 +129,11 @@ struct zcrx_ctrl_export {
101129
__u32 __resv1[11];
102130
};
103131

132+
struct zcrx_ctrl_arm_notif {
133+
__u32 notif_type;
134+
__u32 __resv[11];
135+
};
136+
104137
struct zcrx_ctrl {
105138
__u32 zcrx_id;
106139
__u32 op; /* see enum zcrx_ctrl_op */
@@ -109,6 +142,7 @@ struct zcrx_ctrl {
109142
union {
110143
struct zcrx_ctrl_export zc_export;
111144
struct zcrx_ctrl_flush_rq zc_flush;
145+
struct zcrx_ctrl_arm_notif zc_arm_notif;
112146
};
113147
};
114148

io_uring/bpf-ops.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,18 @@ static const struct btf_type *loop_params_type;
1414

1515
__bpf_kfunc_start_defs();
1616

17-
__bpf_kfunc int bpf_io_uring_submit_sqes(struct io_ring_ctx *ctx, u32 nr)
17+
__bpf_kfunc int bpf_io_uring_submit_sqes(struct iou_ctx *loop_ctx, u32 nr)
1818
{
19+
struct io_ring_ctx *ctx = io_loop_demangle_ctx(loop_ctx);
20+
1921
return io_submit_sqes(ctx, nr);
2022
}
2123

2224
__bpf_kfunc
23-
__u8 *bpf_io_uring_get_region(struct io_ring_ctx *ctx, __u32 region_id,
25+
__u8 *bpf_io_uring_get_region(struct iou_ctx *loop_ctx, __u32 region_id,
2426
const size_t rdwr_buf_size)
2527
{
28+
struct io_ring_ctx *ctx = io_loop_demangle_ctx(loop_ctx);
2629
struct io_mapped_region *r;
2730

2831
lockdep_assert_held(&ctx->uring_lock);
@@ -58,7 +61,7 @@ static const struct btf_kfunc_id_set bpf_io_uring_kfunc_set = {
5861
.set = &io_uring_kfunc_set,
5962
};
6063

61-
static int io_bpf_ops__loop_step(struct io_ring_ctx *ctx,
64+
static int io_bpf_ops__loop_step(struct iou_ctx *ctx,
6265
struct iou_loop_params *lp)
6366
{
6467
return IOU_LOOP_STOP;

io_uring/bpf-ops.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ enum {
1111
};
1212

1313
struct io_uring_bpf_ops {
14-
int (*loop_step)(struct io_ring_ctx *ctx, struct iou_loop_params *lp);
14+
int (*loop_step)(struct iou_ctx *, struct iou_loop_params *lp);
1515

1616
__u32 ring_fd;
1717
void *priv;

io_uring/cancel.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,8 +565,6 @@ __cold bool io_uring_try_cancel_requests(struct io_ring_ctx *ctx,
565565
mutex_unlock(&ctx->uring_lock);
566566
if (tctx)
567567
ret |= io_run_task_work() > 0;
568-
else
569-
ret |= flush_delayed_work(&ctx->fallback_work);
570568
return ret;
571569
}
572570

io_uring/fdinfo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ static void __io_uring_show_fdinfo(struct io_ring_ctx *ctx, struct seq_file *m)
224224
if (ctx->buf_table.nodes[i])
225225
buf = ctx->buf_table.nodes[i]->buf;
226226
if (buf)
227-
seq_printf(m, "%5u: 0x%llx/%u\n", i, buf->ubuf, buf->len);
227+
seq_printf(m, "%5u: 0x%llx/%zu\n", i, buf->ubuf, buf->len);
228228
else
229229
seq_printf(m, "%5u: <none>\n", i);
230230
}

io_uring/io-wq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,6 @@ static void io_worker_handle_work(struct io_wq_acct *acct,
602602
struct io_wq *wq = worker->wq;
603603

604604
do {
605-
bool do_kill = test_bit(IO_WQ_BIT_EXIT, &wq->state);
606605
struct io_wq_work *work;
607606

608607
/*
@@ -638,6 +637,7 @@ static void io_worker_handle_work(struct io_wq_acct *acct,
638637

639638
/* handle a whole dependent link */
640639
do {
640+
bool do_kill = test_bit(IO_WQ_BIT_EXIT, &wq->state);
641641
struct io_wq_work *next_hashed, *linked;
642642
unsigned int work_flags = atomic_read(&work->flags);
643643
unsigned int hash = __io_wq_is_hashed(work_flags)

0 commit comments

Comments
 (0)