Commit 1400e697 authored by Pavel Begunkov's avatar Pavel Begunkov Committed by Jens Axboe

io_uring: use more specific type in rcv/snd msg cp

send/recv msghdr initialisation works with struct io_async_msghdr, but
pulls the whole struct io_async_ctx for no reason. That complicates it
with composite accessing, e.g. io->msg.

Use and pass the most specific type, which is struct io_async_msghdr.
It is the larget field in union io_async_ctx and doesn't save stack
space, but looks clearer.
The most of the changes are replacing "io->msg." with "iomsg->"
Signed-off-by: default avatarPavel Begunkov <asml.silence@gmail.com>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 270a5940
...@@ -3935,7 +3935,7 @@ static int io_sendmsg(struct io_kiocb *req, bool force_nonblock, ...@@ -3935,7 +3935,7 @@ static int io_sendmsg(struct io_kiocb *req, bool force_nonblock,
sock = sock_from_file(req->file, &ret); sock = sock_from_file(req->file, &ret);
if (sock) { if (sock) {
struct io_async_ctx io; struct io_async_msghdr iomsg;
unsigned flags; unsigned flags;
if (req->io) { if (req->io) {
...@@ -3948,14 +3948,13 @@ static int io_sendmsg(struct io_kiocb *req, bool force_nonblock, ...@@ -3948,14 +3948,13 @@ static int io_sendmsg(struct io_kiocb *req, bool force_nonblock,
} else { } else {
struct io_sr_msg *sr = &req->sr_msg; struct io_sr_msg *sr = &req->sr_msg;
kmsg = &io.msg; iomsg.msg.msg_name = &iomsg.addr;
kmsg->msg.msg_name = &io.msg.addr; iomsg.iov = iomsg.fast_iov;
ret = sendmsg_copy_msghdr(&iomsg.msg, sr->umsg,
io.msg.iov = io.msg.fast_iov; sr->msg_flags, &iomsg.iov);
ret = sendmsg_copy_msghdr(&io.msg.msg, sr->umsg,
sr->msg_flags, &io.msg.iov);
if (ret) if (ret)
return ret; return ret;
kmsg = &iomsg;
} }
flags = req->sr_msg.msg_flags; flags = req->sr_msg.msg_flags;
...@@ -4023,30 +4022,31 @@ static int io_send(struct io_kiocb *req, bool force_nonblock, ...@@ -4023,30 +4022,31 @@ static int io_send(struct io_kiocb *req, bool force_nonblock,
return 0; return 0;
} }
static int __io_recvmsg_copy_hdr(struct io_kiocb *req, struct io_async_ctx *io) static int __io_recvmsg_copy_hdr(struct io_kiocb *req,
struct io_async_msghdr *iomsg)
{ {
struct io_sr_msg *sr = &req->sr_msg; struct io_sr_msg *sr = &req->sr_msg;
struct iovec __user *uiov; struct iovec __user *uiov;
size_t iov_len; size_t iov_len;
int ret; int ret;
ret = __copy_msghdr_from_user(&io->msg.msg, sr->umsg, ret = __copy_msghdr_from_user(&iomsg->msg, sr->umsg,
&io->msg.uaddr, &uiov, &iov_len); &iomsg->uaddr, &uiov, &iov_len);
if (ret) if (ret)
return ret; return ret;
if (req->flags & REQ_F_BUFFER_SELECT) { if (req->flags & REQ_F_BUFFER_SELECT) {
if (iov_len > 1) if (iov_len > 1)
return -EINVAL; return -EINVAL;
if (copy_from_user(io->msg.iov, uiov, sizeof(*uiov))) if (copy_from_user(iomsg->iov, uiov, sizeof(*uiov)))
return -EFAULT; return -EFAULT;
sr->len = io->msg.iov[0].iov_len; sr->len = iomsg->iov[0].iov_len;
iov_iter_init(&io->msg.msg.msg_iter, READ, io->msg.iov, 1, iov_iter_init(&iomsg->msg.msg_iter, READ, iomsg->iov, 1,
sr->len); sr->len);
io->msg.iov = NULL; iomsg->iov = NULL;
} else { } else {
ret = import_iovec(READ, uiov, iov_len, UIO_FASTIOV, ret = import_iovec(READ, uiov, iov_len, UIO_FASTIOV,
&io->msg.iov, &io->msg.msg.msg_iter); &iomsg->iov, &iomsg->msg.msg_iter);
if (ret > 0) if (ret > 0)
ret = 0; ret = 0;
} }
...@@ -4056,7 +4056,7 @@ static int __io_recvmsg_copy_hdr(struct io_kiocb *req, struct io_async_ctx *io) ...@@ -4056,7 +4056,7 @@ static int __io_recvmsg_copy_hdr(struct io_kiocb *req, struct io_async_ctx *io)
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
static int __io_compat_recvmsg_copy_hdr(struct io_kiocb *req, static int __io_compat_recvmsg_copy_hdr(struct io_kiocb *req,
struct io_async_ctx *io) struct io_async_msghdr *iomsg)
{ {
struct compat_msghdr __user *msg_compat; struct compat_msghdr __user *msg_compat;
struct io_sr_msg *sr = &req->sr_msg; struct io_sr_msg *sr = &req->sr_msg;
...@@ -4066,7 +4066,7 @@ static int __io_compat_recvmsg_copy_hdr(struct io_kiocb *req, ...@@ -4066,7 +4066,7 @@ static int __io_compat_recvmsg_copy_hdr(struct io_kiocb *req,
int ret; int ret;
msg_compat = (struct compat_msghdr __user *) sr->umsg; msg_compat = (struct compat_msghdr __user *) sr->umsg;
ret = __get_compat_msghdr(&io->msg.msg, msg_compat, &io->msg.uaddr, ret = __get_compat_msghdr(&iomsg->msg, msg_compat, &iomsg->uaddr,
&ptr, &len); &ptr, &len);
if (ret) if (ret)
return ret; return ret;
...@@ -4083,12 +4083,12 @@ static int __io_compat_recvmsg_copy_hdr(struct io_kiocb *req, ...@@ -4083,12 +4083,12 @@ static int __io_compat_recvmsg_copy_hdr(struct io_kiocb *req,
return -EFAULT; return -EFAULT;
if (clen < 0) if (clen < 0)
return -EINVAL; return -EINVAL;
sr->len = io->msg.iov[0].iov_len; sr->len = iomsg->iov[0].iov_len;
io->msg.iov = NULL; iomsg->iov = NULL;
} else { } else {
ret = compat_import_iovec(READ, uiov, len, UIO_FASTIOV, ret = compat_import_iovec(READ, uiov, len, UIO_FASTIOV,
&io->msg.iov, &iomsg->iov,
&io->msg.msg.msg_iter); &iomsg->msg.msg_iter);
if (ret < 0) if (ret < 0)
return ret; return ret;
} }
...@@ -4097,17 +4097,18 @@ static int __io_compat_recvmsg_copy_hdr(struct io_kiocb *req, ...@@ -4097,17 +4097,18 @@ static int __io_compat_recvmsg_copy_hdr(struct io_kiocb *req,
} }
#endif #endif
static int io_recvmsg_copy_hdr(struct io_kiocb *req, struct io_async_ctx *io) static int io_recvmsg_copy_hdr(struct io_kiocb *req,
struct io_async_msghdr *iomsg)
{ {
io->msg.msg.msg_name = &io->msg.addr; iomsg->msg.msg_name = &iomsg->addr;
io->msg.iov = io->msg.fast_iov; iomsg->iov = iomsg->fast_iov;
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
if (req->ctx->compat) if (req->ctx->compat)
return __io_compat_recvmsg_copy_hdr(req, io); return __io_compat_recvmsg_copy_hdr(req, iomsg);
#endif #endif
return __io_recvmsg_copy_hdr(req, io); return __io_recvmsg_copy_hdr(req, iomsg);
} }
static struct io_buffer *io_recv_buffer_select(struct io_kiocb *req, static struct io_buffer *io_recv_buffer_select(struct io_kiocb *req,
...@@ -4157,7 +4158,7 @@ static int io_recvmsg_prep(struct io_kiocb *req, ...@@ -4157,7 +4158,7 @@ static int io_recvmsg_prep(struct io_kiocb *req,
if (req->flags & REQ_F_NEED_CLEANUP) if (req->flags & REQ_F_NEED_CLEANUP)
return 0; return 0;
ret = io_recvmsg_copy_hdr(req, io); ret = io_recvmsg_copy_hdr(req, &io->msg);
if (!ret) if (!ret)
req->flags |= REQ_F_NEED_CLEANUP; req->flags |= REQ_F_NEED_CLEANUP;
return ret; return ret;
...@@ -4173,7 +4174,7 @@ static int io_recvmsg(struct io_kiocb *req, bool force_nonblock, ...@@ -4173,7 +4174,7 @@ static int io_recvmsg(struct io_kiocb *req, bool force_nonblock,
sock = sock_from_file(req->file, &ret); sock = sock_from_file(req->file, &ret);
if (sock) { if (sock) {
struct io_buffer *kbuf; struct io_buffer *kbuf;
struct io_async_ctx io; struct io_async_msghdr iomsg;
unsigned flags; unsigned flags;
if (req->io) { if (req->io) {
...@@ -4184,12 +4185,10 @@ static int io_recvmsg(struct io_kiocb *req, bool force_nonblock, ...@@ -4184,12 +4185,10 @@ static int io_recvmsg(struct io_kiocb *req, bool force_nonblock,
kmsg->iov = kmsg->fast_iov; kmsg->iov = kmsg->fast_iov;
kmsg->msg.msg_iter.iov = kmsg->iov; kmsg->msg.msg_iter.iov = kmsg->iov;
} else { } else {
kmsg = &io.msg; ret = io_recvmsg_copy_hdr(req, &iomsg);
kmsg->msg.msg_name = &io.msg.addr;
ret = io_recvmsg_copy_hdr(req, &io);
if (ret) if (ret)
return ret; return ret;
kmsg = &iomsg;
} }
kbuf = io_recv_buffer_select(req, &cflags, !force_nonblock); kbuf = io_recv_buffer_select(req, &cflags, !force_nonblock);
......
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