io_uring: abstract out provided buffer list selection

In preparation for providing another way to select a buffer, move the
existing logic into a helper.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
Jens Axboe 2022-04-30 12:22:02 -06:00
parent b66e65f414
commit 149c69b04a

View File

@ -3448,29 +3448,41 @@ static int io_buffer_add_list(struct io_ring_ctx *ctx,
return xa_err(xa_store(&ctx->io_bl_xa, bgid, bl, GFP_KERNEL));
}
static void __user *io_provided_buffer_select(struct io_kiocb *req, size_t *len,
struct io_buffer_list *bl,
unsigned int issue_flags)
{
struct io_buffer *kbuf;
if (list_empty(&bl->buf_list))
return ERR_PTR(-ENOBUFS);
kbuf = list_first_entry(&bl->buf_list, struct io_buffer, list);
list_del(&kbuf->list);
if (*len > kbuf->len)
*len = kbuf->len;
req->flags |= REQ_F_BUFFER_SELECTED;
req->kbuf = kbuf;
io_ring_submit_unlock(req->ctx, issue_flags);
return u64_to_user_ptr(kbuf->addr);
}
static void __user *io_buffer_select(struct io_kiocb *req, size_t *len,
unsigned int issue_flags)
{
struct io_buffer *kbuf = req->kbuf;
struct io_ring_ctx *ctx = req->ctx;
struct io_buffer_list *bl;
io_ring_submit_lock(req->ctx, issue_flags);
bl = io_buffer_get_list(ctx, req->buf_index);
if (bl && !list_empty(&bl->buf_list)) {
kbuf = list_first_entry(&bl->buf_list, struct io_buffer, list);
list_del(&kbuf->list);
if (*len > kbuf->len)
*len = kbuf->len;
req->flags |= REQ_F_BUFFER_SELECTED;
req->kbuf = kbuf;
if (unlikely(!bl)) {
io_ring_submit_unlock(req->ctx, issue_flags);
return u64_to_user_ptr(kbuf->addr);
return ERR_PTR(-ENOBUFS);
}
io_ring_submit_unlock(req->ctx, issue_flags);
return ERR_PTR(-ENOBUFS);
/* selection helpers drop the submit lock again, if needed */
return io_provided_buffer_select(req, len, bl, issue_flags);
}
#ifdef CONFIG_COMPAT