Skip to content

Commit c612261

Browse files
committed
Merge tag 'io_uring-7.0-20260320' of git://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux
Pull io_uring fixes from Jens Axboe: - A bit of a work-around for AF_UNIX recv multishot, as the in-kernel implementation doesn't properly signal EOF. We'll likely rework this one going forward, but the fix is sufficient for now - Two fixes for incrementally consumed buffers, for non-pollable files and for 0 byte reads * tag 'io_uring-7.0-20260320' of git://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux: io_uring/kbuf: propagate BUF_MORE through early buffer commit path io_uring/kbuf: fix missing BUF_MORE for incremental buffers at EOF io_uring/poll: fix multishot recv missing EOF on wakeup race
2 parents 9f582e3 + 418eab7 commit c612261

3 files changed

Lines changed: 21 additions & 5 deletions

File tree

include/linux/io_uring_types.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,7 @@ enum {
541541
REQ_F_BL_NO_RECYCLE_BIT,
542542
REQ_F_BUFFERS_COMMIT_BIT,
543543
REQ_F_BUF_NODE_BIT,
544+
REQ_F_BUF_MORE_BIT,
544545
REQ_F_HAS_METADATA_BIT,
545546
REQ_F_IMPORT_BUFFER_BIT,
546547
REQ_F_SQE_COPIED_BIT,
@@ -626,6 +627,8 @@ enum {
626627
REQ_F_BUFFERS_COMMIT = IO_REQ_FLAG(REQ_F_BUFFERS_COMMIT_BIT),
627628
/* buf node is valid */
628629
REQ_F_BUF_NODE = IO_REQ_FLAG(REQ_F_BUF_NODE_BIT),
630+
/* incremental buffer consumption, more space available */
631+
REQ_F_BUF_MORE = IO_REQ_FLAG(REQ_F_BUF_MORE_BIT),
629632
/* request has read/write metadata assigned */
630633
REQ_F_HAS_METADATA = IO_REQ_FLAG(REQ_F_HAS_METADATA_BIT),
631634
/*

io_uring/kbuf.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ struct io_provide_buf {
3434

3535
static bool io_kbuf_inc_commit(struct io_buffer_list *bl, int len)
3636
{
37+
/* No data consumed, return false early to avoid consuming the buffer */
38+
if (!len)
39+
return false;
40+
3741
while (len) {
3842
struct io_uring_buf *buf;
3943
u32 buf_len, this_len;
@@ -212,7 +216,8 @@ static struct io_br_sel io_ring_buffer_select(struct io_kiocb *req, size_t *len,
212216
sel.addr = u64_to_user_ptr(READ_ONCE(buf->addr));
213217

214218
if (io_should_commit(req, issue_flags)) {
215-
io_kbuf_commit(req, sel.buf_list, *len, 1);
219+
if (!io_kbuf_commit(req, sel.buf_list, *len, 1))
220+
req->flags |= REQ_F_BUF_MORE;
216221
sel.buf_list = NULL;
217222
}
218223
return sel;
@@ -345,7 +350,8 @@ int io_buffers_select(struct io_kiocb *req, struct buf_sel_arg *arg,
345350
*/
346351
if (ret > 0) {
347352
req->flags |= REQ_F_BUFFERS_COMMIT | REQ_F_BL_NO_RECYCLE;
348-
io_kbuf_commit(req, sel->buf_list, arg->out_len, ret);
353+
if (!io_kbuf_commit(req, sel->buf_list, arg->out_len, ret))
354+
req->flags |= REQ_F_BUF_MORE;
349355
}
350356
} else {
351357
ret = io_provided_buffers_select(req, &arg->out_len, sel->buf_list, arg->iovs);
@@ -391,8 +397,10 @@ static inline bool __io_put_kbuf_ring(struct io_kiocb *req,
391397

392398
if (bl)
393399
ret = io_kbuf_commit(req, bl, len, nr);
400+
if (ret && (req->flags & REQ_F_BUF_MORE))
401+
ret = false;
394402

395-
req->flags &= ~REQ_F_BUFFER_RING;
403+
req->flags &= ~(REQ_F_BUFFER_RING | REQ_F_BUF_MORE);
396404
return ret;
397405
}
398406

io_uring/poll.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ static int io_poll_check_events(struct io_kiocb *req, io_tw_token_t tw)
272272
atomic_andnot(IO_POLL_RETRY_FLAG, &req->poll_refs);
273273
v &= ~IO_POLL_RETRY_FLAG;
274274
}
275+
v &= IO_POLL_REF_MASK;
275276
}
276277

277278
/* the mask was stashed in __io_poll_execute */
@@ -304,8 +305,13 @@ static int io_poll_check_events(struct io_kiocb *req, io_tw_token_t tw)
304305
return IOU_POLL_REMOVE_POLL_USE_RES;
305306
}
306307
} else {
307-
int ret = io_poll_issue(req, tw);
308+
int ret;
308309

310+
/* multiple refs and HUP, ensure we loop once more */
311+
if ((req->cqe.res & (POLLHUP | POLLRDHUP)) && v != 1)
312+
v--;
313+
314+
ret = io_poll_issue(req, tw);
309315
if (ret == IOU_COMPLETE)
310316
return IOU_POLL_REMOVE_POLL_USE_RES;
311317
else if (ret == IOU_REQUEUE)
@@ -321,7 +327,6 @@ static int io_poll_check_events(struct io_kiocb *req, io_tw_token_t tw)
321327
* Release all references, retry if someone tried to restart
322328
* task_work while we were executing it.
323329
*/
324-
v &= IO_POLL_REF_MASK;
325330
} while (atomic_sub_return(v, &req->poll_refs) & IO_POLL_REF_MASK);
326331

327332
io_napi_add(req);

0 commit comments

Comments
 (0)