Skip to content

Commit 9aa9e55

Browse files
joannekoongaxboe
authored andcommitted
io_uring/kbuf: return buffer id in buffer selection
Return the id of the selected buffer in io_buffer_select(). This is needed for kernel-managed buffer rings to later recycle the selected buffer. Signed-off-by: Joanne Koong <joannelkoong@gmail.com> Link: https://patch.msgid.link/20260306003224.3620942-5-joannelkoong@gmail.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent b6ffe53 commit 9aa9e55

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

include/linux/io_uring_types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ struct io_br_sel {
105105
void *kaddr;
106106
};
107107
ssize_t val;
108+
/* id of the selected buffer */
109+
unsigned buf_id;
108110
};
109111

110112

io_uring/kbuf.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ static struct io_br_sel io_ring_buffer_select(struct io_kiocb *req, size_t *len,
215215
req->flags |= REQ_F_BUFFER_RING | REQ_F_BUFFERS_COMMIT;
216216
req->buf_index = READ_ONCE(buf->bid);
217217
sel.buf_list = bl;
218+
sel.buf_id = req->buf_index;
218219
if (bl->flags & IOBL_KERNEL_MANAGED)
219220
sel.kaddr = (void *)(uintptr_t)READ_ONCE(buf->addr);
220221
else
@@ -238,10 +239,12 @@ struct io_br_sel io_buffer_select(struct io_kiocb *req, size_t *len,
238239

239240
bl = io_buffer_get_list(ctx, buf_group);
240241
if (likely(bl)) {
241-
if (bl->flags & IOBL_BUF_RING)
242+
if (bl->flags & IOBL_BUF_RING) {
242243
sel = io_ring_buffer_select(req, len, bl, issue_flags);
243-
else
244+
} else {
244245
sel.addr = io_provided_buffer_select(req, len, bl);
246+
sel.buf_id = req->buf_index;
247+
}
245248
}
246249
io_ring_submit_unlock(ctx, issue_flags);
247250
return sel;

0 commit comments

Comments
 (0)