Skip to content

Commit b00c51e

Browse files
committed
io_uring/net: cache provided buffer group value for multishot receives
If we're using ring provided buffers with multishot receive, and we end up doing an io-wq based issue at some points that also needs to select a buffer, we'll lose the initially assigned buffer group as io_ring_buffer_select() correctly clears the buffer group list as the issue isn't serialized by the ctx uring_lock. This is fine for normal receives as the request puts the buffer and finishes, but for multishot, we will re-arm and do further receives. On the next trigger for this multishot receive, the receive will try and pick from a buffer group whose value is the same as the buffer ID of the las receive. That is obviously incorrect, and will result in a premature -ENOUFS error for the receive even if we had available buffers in the correct group. Cache the buffer group value at prep time, so we can restore it for future receives. This only needs doing for the above mentioned case, but just do it by default to keep it easier to read. Cc: [email protected] Fixes: b3fdea6 ("io_uring: multishot recv") Fixes: 9bb6690 ("io_uring: support multishot in recvmsg") Cc: Dylan Yudaken <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 8caa03f commit b00c51e

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

io_uring/net.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ struct io_sr_msg {
6262
u16 flags;
6363
/* initialised and used only by !msg send variants */
6464
u16 addr_len;
65+
u16 buf_group;
6566
void __user *addr;
6667
/* used only for send zerocopy */
6768
struct io_kiocb *notif;
@@ -580,6 +581,15 @@ int io_recvmsg_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
580581
if (req->opcode == IORING_OP_RECV && sr->len)
581582
return -EINVAL;
582583
req->flags |= REQ_F_APOLL_MULTISHOT;
584+
/*
585+
* Store the buffer group for this multishot receive separately,
586+
* as if we end up doing an io-wq based issue that selects a
587+
* buffer, it has to be committed immediately and that will
588+
* clear ->buf_list. This means we lose the link to the buffer
589+
* list, and the eventual buffer put on completion then cannot
590+
* restore it.
591+
*/
592+
sr->buf_group = req->buf_index;
583593
}
584594

585595
#ifdef CONFIG_COMPAT
@@ -596,6 +606,7 @@ static inline void io_recv_prep_retry(struct io_kiocb *req)
596606

597607
sr->done_io = 0;
598608
sr->len = 0; /* get from the provided buffer */
609+
req->buf_index = sr->buf_group;
599610
}
600611

601612
/*

0 commit comments

Comments
 (0)