Skip to content

Commit 418eab7

Browse files
committed
io_uring/kbuf: propagate BUF_MORE through early buffer commit path
When io_should_commit() returns true (eg for non-pollable files), buffer commit happens at buffer selection time and sel->buf_list is set to NULL. When __io_put_kbufs() generates CQE flags at completion time, it calls __io_put_kbuf_ring() which finds a NULL buffer_list and hence cannot determine whether the buffer was consumed or not. This means that IORING_CQE_F_BUF_MORE is never set for non-pollable input with incrementally consumed buffers. Likewise for io_buffers_select(), which always commits upfront and discards the return value of io_kbuf_commit(). Add REQ_F_BUF_MORE to store the result of io_kbuf_commit() during early commit. Then __io_put_kbuf_ring() can check this flag and set IORING_F_BUF_MORE accordingy. Reported-by: Martin Michaelis <code@mgjm.de> Cc: stable@vger.kernel.org Fixes: ae98dbf ("io_uring/kbuf: add support for incremental buffer consumption") Link: axboe/liburing#1553 Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 3ecd3e0 commit 418eab7

2 files changed

Lines changed: 10 additions & 3 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: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ static struct io_br_sel io_ring_buffer_select(struct io_kiocb *req, size_t *len,
216216
sel.addr = u64_to_user_ptr(READ_ONCE(buf->addr));
217217

218218
if (io_should_commit(req, issue_flags)) {
219-
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;
220221
sel.buf_list = NULL;
221222
}
222223
return sel;
@@ -349,7 +350,8 @@ int io_buffers_select(struct io_kiocb *req, struct buf_sel_arg *arg,
349350
*/
350351
if (ret > 0) {
351352
req->flags |= REQ_F_BUFFERS_COMMIT | REQ_F_BL_NO_RECYCLE;
352-
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;
353355
}
354356
} else {
355357
ret = io_provided_buffers_select(req, &arg->out_len, sel->buf_list, arg->iovs);
@@ -395,8 +397,10 @@ static inline bool __io_put_kbuf_ring(struct io_kiocb *req,
395397

396398
if (bl)
397399
ret = io_kbuf_commit(req, bl, len, nr);
400+
if (ret && (req->flags & REQ_F_BUF_MORE))
401+
ret = false;
398402

399-
req->flags &= ~REQ_F_BUFFER_RING;
403+
req->flags &= ~(REQ_F_BUFFER_RING | REQ_F_BUF_MORE);
400404
return ret;
401405
}
402406

0 commit comments

Comments
 (0)