Commit c54d52c2 authored by Jens Axboe's avatar Jens Axboe

io_uring: make io_buffer_select() return the user address directly

There's no point in having callers provide a kbuf, we're just returning
the address anyway.
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 9396ed85
...@@ -3458,15 +3458,15 @@ static void io_buffer_add_list(struct io_ring_ctx *ctx, ...@@ -3458,15 +3458,15 @@ static void io_buffer_add_list(struct io_ring_ctx *ctx,
list_add(&bl->list, list); list_add(&bl->list, list);
} }
static struct io_buffer *io_buffer_select(struct io_kiocb *req, size_t *len, static void __user *io_buffer_select(struct io_kiocb *req, size_t *len,
int bgid, unsigned int issue_flags) int bgid, unsigned int issue_flags)
{ {
struct io_buffer *kbuf = req->kbuf; struct io_buffer *kbuf = req->kbuf;
struct io_ring_ctx *ctx = req->ctx; struct io_ring_ctx *ctx = req->ctx;
struct io_buffer_list *bl; struct io_buffer_list *bl;
if (req->flags & REQ_F_BUFFER_SELECTED) if (req->flags & REQ_F_BUFFER_SELECTED)
return kbuf; return u64_to_user_ptr(kbuf->addr);
io_ring_submit_lock(req->ctx, issue_flags); io_ring_submit_lock(req->ctx, issue_flags);
...@@ -3478,25 +3478,18 @@ static struct io_buffer *io_buffer_select(struct io_kiocb *req, size_t *len, ...@@ -3478,25 +3478,18 @@ static struct io_buffer *io_buffer_select(struct io_kiocb *req, size_t *len,
*len = kbuf->len; *len = kbuf->len;
req->flags |= REQ_F_BUFFER_SELECTED; req->flags |= REQ_F_BUFFER_SELECTED;
req->kbuf = kbuf; req->kbuf = kbuf;
} else { io_ring_submit_unlock(req->ctx, issue_flags);
kbuf = ERR_PTR(-ENOBUFS); return u64_to_user_ptr(kbuf->addr);
} }
io_ring_submit_unlock(req->ctx, issue_flags); io_ring_submit_unlock(req->ctx, issue_flags);
return kbuf; return ERR_PTR(-ENOBUFS);
} }
static void __user *io_rw_buffer_select(struct io_kiocb *req, size_t *len, static void __user *io_rw_buffer_select(struct io_kiocb *req, size_t *len,
unsigned int issue_flags) unsigned int issue_flags)
{ {
struct io_buffer *kbuf; return io_buffer_select(req, len, req->buf_index, issue_flags);
u16 bgid;
bgid = req->buf_index;
kbuf = io_buffer_select(req, len, bgid, issue_flags);
if (IS_ERR(kbuf))
return kbuf;
return u64_to_user_ptr(kbuf->addr);
} }
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
...@@ -5535,7 +5528,6 @@ static int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags) ...@@ -5535,7 +5528,6 @@ static int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags)
struct io_async_msghdr iomsg, *kmsg; struct io_async_msghdr iomsg, *kmsg;
struct io_sr_msg *sr = &req->sr_msg; struct io_sr_msg *sr = &req->sr_msg;
struct socket *sock; struct socket *sock;
struct io_buffer *kbuf;
unsigned flags; unsigned flags;
int ret, min_ret = 0; int ret, min_ret = 0;
bool force_nonblock = issue_flags & IO_URING_F_NONBLOCK; bool force_nonblock = issue_flags & IO_URING_F_NONBLOCK;
...@@ -5558,10 +5550,12 @@ static int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags) ...@@ -5558,10 +5550,12 @@ static int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags)
return io_setup_async_msg(req, kmsg); return io_setup_async_msg(req, kmsg);
if (req->flags & REQ_F_BUFFER_SELECT) { if (req->flags & REQ_F_BUFFER_SELECT) {
kbuf = io_buffer_select(req, &sr->len, sr->bgid, issue_flags); void __user *buf;
if (IS_ERR(kbuf))
return PTR_ERR(kbuf); buf = io_buffer_select(req, &sr->len, sr->bgid, issue_flags);
kmsg->fast_iov[0].iov_base = u64_to_user_ptr(kbuf->addr); if (IS_ERR(buf))
return PTR_ERR(buf);
kmsg->fast_iov[0].iov_base = buf;
kmsg->fast_iov[0].iov_len = sr->len; kmsg->fast_iov[0].iov_len = sr->len;
iov_iter_init(&kmsg->msg.msg_iter, READ, kmsg->fast_iov, 1, iov_iter_init(&kmsg->msg.msg_iter, READ, kmsg->fast_iov, 1,
sr->len); sr->len);
...@@ -5603,10 +5597,8 @@ static int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags) ...@@ -5603,10 +5597,8 @@ static int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags)
static int io_recv(struct io_kiocb *req, unsigned int issue_flags) static int io_recv(struct io_kiocb *req, unsigned int issue_flags)
{ {
struct io_buffer *kbuf;
struct io_sr_msg *sr = &req->sr_msg; struct io_sr_msg *sr = &req->sr_msg;
struct msghdr msg; struct msghdr msg;
void __user *buf = sr->buf;
struct socket *sock; struct socket *sock;
struct iovec iov; struct iovec iov;
unsigned flags; unsigned flags;
...@@ -5622,13 +5614,15 @@ static int io_recv(struct io_kiocb *req, unsigned int issue_flags) ...@@ -5622,13 +5614,15 @@ static int io_recv(struct io_kiocb *req, unsigned int issue_flags)
return -ENOTSOCK; return -ENOTSOCK;
if (req->flags & REQ_F_BUFFER_SELECT) { if (req->flags & REQ_F_BUFFER_SELECT) {
kbuf = io_buffer_select(req, &sr->len, sr->bgid, issue_flags); void __user *buf;
if (IS_ERR(kbuf))
return PTR_ERR(kbuf); buf = io_buffer_select(req, &sr->len, sr->bgid, issue_flags);
buf = u64_to_user_ptr(kbuf->addr); if (IS_ERR(buf))
return PTR_ERR(buf);
sr->buf = buf;
} }
ret = import_single_range(READ, buf, sr->len, &iov, &msg.msg_iter); ret = import_single_range(READ, sr->buf, sr->len, &iov, &msg.msg_iter);
if (unlikely(ret)) if (unlikely(ret))
goto out_free; goto out_free;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment