* [PATCH 5.9 0/3] send/recv msghdr init cleanups
@ 2020-07-12 17:41 Pavel Begunkov
2020-07-12 17:41 ` [PATCH 1/3] io_uring: rename sr->msg into umsg Pavel Begunkov
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Pavel Begunkov @ 2020-07-12 17:41 UTC (permalink / raw)
To: Jens Axboe, io-uring
A follow-up for the "msg_name" fix, cleaning it up and
deduplicating error prone parts.
Pavel Begunkov (3):
io_uring: rename __user *msg into umsg
io_uring: use more specific type in rcv/snd msg cp
io_uring: extract io_sendmsg_copy_hdr()
fs/io_uring.c | 86 +++++++++++++++++++++++++--------------------------
1 file changed, 43 insertions(+), 43 deletions(-)
--
2.24.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/3] io_uring: rename sr->msg into umsg
2020-07-12 17:41 [PATCH 5.9 0/3] send/recv msghdr init cleanups Pavel Begunkov
@ 2020-07-12 17:41 ` Pavel Begunkov
2020-07-12 17:41 ` [PATCH 2/3] io_uring: use more specific type in rcv/snd msg cp Pavel Begunkov
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Pavel Begunkov @ 2020-07-12 17:41 UTC (permalink / raw)
To: Jens Axboe, io-uring
Every second field in send/recv is called msg, make it a bit more
understandable by renaming ->msg, which is a user provided ptr,
to ->umsg.
Signed-off-by: Pavel Begunkov <[email protected]>
---
fs/io_uring.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index c03e953751cc..2cfcf111f58f 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -414,7 +414,7 @@ struct io_connect {
struct io_sr_msg {
struct file *file;
union {
- struct user_msghdr __user *msg;
+ struct user_msghdr __user *umsg;
void __user *buf;
};
int msg_flags;
@@ -3899,7 +3899,7 @@ static int io_sendmsg_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
return -EINVAL;
sr->msg_flags = READ_ONCE(sqe->msg_flags);
- sr->msg = u64_to_user_ptr(READ_ONCE(sqe->addr));
+ sr->umsg = u64_to_user_ptr(READ_ONCE(sqe->addr));
sr->len = READ_ONCE(sqe->len);
#ifdef CONFIG_COMPAT
@@ -3915,7 +3915,7 @@ static int io_sendmsg_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
io->msg.msg.msg_name = &io->msg.addr;
io->msg.iov = io->msg.fast_iov;
- ret = sendmsg_copy_msghdr(&io->msg.msg, sr->msg, sr->msg_flags,
+ ret = sendmsg_copy_msghdr(&io->msg.msg, sr->umsg, sr->msg_flags,
&io->msg.iov);
if (!ret)
req->flags |= REQ_F_NEED_CLEANUP;
@@ -3948,7 +3948,7 @@ static int io_sendmsg(struct io_kiocb *req, bool force_nonblock,
kmsg->msg.msg_name = &io.msg.addr;
io.msg.iov = io.msg.fast_iov;
- ret = sendmsg_copy_msghdr(&io.msg.msg, sr->msg,
+ ret = sendmsg_copy_msghdr(&io.msg.msg, sr->umsg,
sr->msg_flags, &io.msg.iov);
if (ret)
return ret;
@@ -4026,8 +4026,8 @@ static int __io_recvmsg_copy_hdr(struct io_kiocb *req, struct io_async_ctx *io)
size_t iov_len;
int ret;
- ret = __copy_msghdr_from_user(&io->msg.msg, sr->msg, &io->msg.uaddr,
- &uiov, &iov_len);
+ ret = __copy_msghdr_from_user(&io->msg.msg, sr->umsg,
+ &io->msg.uaddr, &uiov, &iov_len);
if (ret)
return ret;
@@ -4061,7 +4061,7 @@ static int __io_compat_recvmsg_copy_hdr(struct io_kiocb *req,
compat_size_t len;
int ret;
- msg_compat = (struct compat_msghdr __user *) sr->msg;
+ msg_compat = (struct compat_msghdr __user *) sr->umsg;
ret = __get_compat_msghdr(&io->msg.msg, msg_compat, &io->msg.uaddr,
&ptr, &len);
if (ret)
@@ -4138,7 +4138,7 @@ static int io_recvmsg_prep(struct io_kiocb *req,
return -EINVAL;
sr->msg_flags = READ_ONCE(sqe->msg_flags);
- sr->msg = u64_to_user_ptr(READ_ONCE(sqe->addr));
+ sr->umsg = u64_to_user_ptr(READ_ONCE(sqe->addr));
sr->len = READ_ONCE(sqe->len);
sr->bgid = READ_ONCE(sqe->buf_group);
@@ -4203,7 +4203,7 @@ static int io_recvmsg(struct io_kiocb *req, bool force_nonblock,
else if (force_nonblock)
flags |= MSG_DONTWAIT;
- ret = __sys_recvmsg_sock(sock, &kmsg->msg, req->sr_msg.msg,
+ ret = __sys_recvmsg_sock(sock, &kmsg->msg, req->sr_msg.umsg,
kmsg->uaddr, flags);
if (force_nonblock && ret == -EAGAIN)
return io_setup_async_msg(req, kmsg);
--
2.24.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/3] io_uring: use more specific type in rcv/snd msg cp
2020-07-12 17:41 [PATCH 5.9 0/3] send/recv msghdr init cleanups Pavel Begunkov
2020-07-12 17:41 ` [PATCH 1/3] io_uring: rename sr->msg into umsg Pavel Begunkov
@ 2020-07-12 17:41 ` Pavel Begunkov
2020-07-12 17:41 ` [PATCH 3/3] io_uring: extract io_sendmsg_copy_hdr() Pavel Begunkov
2020-07-12 20:26 ` [PATCH 5.9 0/3] send/recv msghdr init cleanups Jens Axboe
3 siblings, 0 replies; 5+ messages in thread
From: Pavel Begunkov @ 2020-07-12 17:41 UTC (permalink / raw)
To: Jens Axboe, io-uring
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: Pavel Begunkov <[email protected]>
---
fs/io_uring.c | 63 +++++++++++++++++++++++++--------------------------
1 file changed, 31 insertions(+), 32 deletions(-)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index 2cfcf111f58f..b496aebd6285 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -3931,7 +3931,7 @@ static int io_sendmsg(struct io_kiocb *req, bool force_nonblock,
sock = sock_from_file(req->file, &ret);
if (sock) {
- struct io_async_ctx io;
+ struct io_async_msghdr iomsg;
unsigned flags;
if (req->io) {
@@ -3944,14 +3944,13 @@ static int io_sendmsg(struct io_kiocb *req, bool force_nonblock,
} else {
struct io_sr_msg *sr = &req->sr_msg;
- kmsg = &io.msg;
- kmsg->msg.msg_name = &io.msg.addr;
-
- io.msg.iov = io.msg.fast_iov;
- ret = sendmsg_copy_msghdr(&io.msg.msg, sr->umsg,
- sr->msg_flags, &io.msg.iov);
+ iomsg.msg.msg_name = &iomsg.addr;
+ iomsg.iov = iomsg.fast_iov;
+ ret = sendmsg_copy_msghdr(&iomsg.msg, sr->umsg,
+ sr->msg_flags, &iomsg.iov);
if (ret)
return ret;
+ kmsg = &iomsg;
}
flags = req->sr_msg.msg_flags;
@@ -4019,30 +4018,31 @@ static int io_send(struct io_kiocb *req, bool force_nonblock,
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 iovec __user *uiov;
size_t iov_len;
int ret;
- ret = __copy_msghdr_from_user(&io->msg.msg, sr->umsg,
- &io->msg.uaddr, &uiov, &iov_len);
+ ret = __copy_msghdr_from_user(&iomsg->msg, sr->umsg,
+ &iomsg->uaddr, &uiov, &iov_len);
if (ret)
return ret;
if (req->flags & REQ_F_BUFFER_SELECT) {
if (iov_len > 1)
return -EINVAL;
- if (copy_from_user(io->msg.iov, uiov, sizeof(*uiov)))
+ if (copy_from_user(iomsg->iov, uiov, sizeof(*uiov)))
return -EFAULT;
- sr->len = io->msg.iov[0].iov_len;
- iov_iter_init(&io->msg.msg.msg_iter, READ, io->msg.iov, 1,
+ sr->len = iomsg->iov[0].iov_len;
+ iov_iter_init(&iomsg->msg.msg_iter, READ, iomsg->iov, 1,
sr->len);
- io->msg.iov = NULL;
+ iomsg->iov = NULL;
} else {
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)
ret = 0;
}
@@ -4052,7 +4052,7 @@ static int __io_recvmsg_copy_hdr(struct io_kiocb *req, struct io_async_ctx *io)
#ifdef CONFIG_COMPAT
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 io_sr_msg *sr = &req->sr_msg;
@@ -4062,7 +4062,7 @@ static int __io_compat_recvmsg_copy_hdr(struct io_kiocb *req,
int ret;
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);
if (ret)
return ret;
@@ -4079,12 +4079,12 @@ static int __io_compat_recvmsg_copy_hdr(struct io_kiocb *req,
return -EFAULT;
if (clen < 0)
return -EINVAL;
- sr->len = io->msg.iov[0].iov_len;
- io->msg.iov = NULL;
+ sr->len = iomsg->iov[0].iov_len;
+ iomsg->iov = NULL;
} else {
ret = compat_import_iovec(READ, uiov, len, UIO_FASTIOV,
- &io->msg.iov,
- &io->msg.msg.msg_iter);
+ &iomsg->iov,
+ &iomsg->msg.msg_iter);
if (ret < 0)
return ret;
}
@@ -4093,17 +4093,18 @@ static int __io_compat_recvmsg_copy_hdr(struct io_kiocb *req,
}
#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;
- io->msg.iov = io->msg.fast_iov;
+ iomsg->msg.msg_name = &iomsg->addr;
+ iomsg->iov = iomsg->fast_iov;
#ifdef CONFIG_COMPAT
if (req->ctx->compat)
- return __io_compat_recvmsg_copy_hdr(req, io);
+ return __io_compat_recvmsg_copy_hdr(req, iomsg);
#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,
@@ -4153,7 +4154,7 @@ static int io_recvmsg_prep(struct io_kiocb *req,
if (req->flags & REQ_F_NEED_CLEANUP)
return 0;
- ret = io_recvmsg_copy_hdr(req, io);
+ ret = io_recvmsg_copy_hdr(req, &io->msg);
if (!ret)
req->flags |= REQ_F_NEED_CLEANUP;
return ret;
@@ -4169,7 +4170,7 @@ static int io_recvmsg(struct io_kiocb *req, bool force_nonblock,
sock = sock_from_file(req->file, &ret);
if (sock) {
struct io_buffer *kbuf;
- struct io_async_ctx io;
+ struct io_async_msghdr iomsg;
unsigned flags;
if (req->io) {
@@ -4180,12 +4181,10 @@ static int io_recvmsg(struct io_kiocb *req, bool force_nonblock,
kmsg->iov = kmsg->fast_iov;
kmsg->msg.msg_iter.iov = kmsg->iov;
} else {
- kmsg = &io.msg;
- kmsg->msg.msg_name = &io.msg.addr;
-
- ret = io_recvmsg_copy_hdr(req, &io);
+ ret = io_recvmsg_copy_hdr(req, &iomsg);
if (ret)
return ret;
+ kmsg = &iomsg;
}
kbuf = io_recv_buffer_select(req, &cflags, !force_nonblock);
--
2.24.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/3] io_uring: extract io_sendmsg_copy_hdr()
2020-07-12 17:41 [PATCH 5.9 0/3] send/recv msghdr init cleanups Pavel Begunkov
2020-07-12 17:41 ` [PATCH 1/3] io_uring: rename sr->msg into umsg Pavel Begunkov
2020-07-12 17:41 ` [PATCH 2/3] io_uring: use more specific type in rcv/snd msg cp Pavel Begunkov
@ 2020-07-12 17:41 ` Pavel Begunkov
2020-07-12 20:26 ` [PATCH 5.9 0/3] send/recv msghdr init cleanups Jens Axboe
3 siblings, 0 replies; 5+ messages in thread
From: Pavel Begunkov @ 2020-07-12 17:41 UTC (permalink / raw)
To: Jens Axboe, io-uring
Don't repeat send msg initialisation code, it's error prone.
Extract and use a helper function.
Signed-off-by: Pavel Begunkov <[email protected]>
---
fs/io_uring.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index b496aebd6285..d87751f7b5ba 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -3889,6 +3889,15 @@ static int io_setup_async_msg(struct io_kiocb *req,
return -EAGAIN;
}
+static int io_sendmsg_copy_hdr(struct io_kiocb *req,
+ struct io_async_msghdr *iomsg)
+{
+ iomsg->iov = iomsg->fast_iov;
+ iomsg->msg.msg_name = &iomsg->addr;
+ return sendmsg_copy_msghdr(&iomsg->msg, req->sr_msg.umsg,
+ req->sr_msg.msg_flags, &iomsg->iov);
+}
+
static int io_sendmsg_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
{
struct io_sr_msg *sr = &req->sr_msg;
@@ -3913,10 +3922,7 @@ static int io_sendmsg_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
if (req->flags & REQ_F_NEED_CLEANUP)
return 0;
- io->msg.msg.msg_name = &io->msg.addr;
- io->msg.iov = io->msg.fast_iov;
- ret = sendmsg_copy_msghdr(&io->msg.msg, sr->umsg, sr->msg_flags,
- &io->msg.iov);
+ ret = io_sendmsg_copy_hdr(req, &io->msg);
if (!ret)
req->flags |= REQ_F_NEED_CLEANUP;
return ret;
@@ -3942,12 +3948,7 @@ static int io_sendmsg(struct io_kiocb *req, bool force_nonblock,
kmsg->iov = kmsg->fast_iov;
kmsg->msg.msg_iter.iov = kmsg->iov;
} else {
- struct io_sr_msg *sr = &req->sr_msg;
-
- iomsg.msg.msg_name = &iomsg.addr;
- iomsg.iov = iomsg.fast_iov;
- ret = sendmsg_copy_msghdr(&iomsg.msg, sr->umsg,
- sr->msg_flags, &iomsg.iov);
+ ret = io_sendmsg_copy_hdr(req, &iomsg);
if (ret)
return ret;
kmsg = &iomsg;
--
2.24.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 5.9 0/3] send/recv msghdr init cleanups
2020-07-12 17:41 [PATCH 5.9 0/3] send/recv msghdr init cleanups Pavel Begunkov
` (2 preceding siblings ...)
2020-07-12 17:41 ` [PATCH 3/3] io_uring: extract io_sendmsg_copy_hdr() Pavel Begunkov
@ 2020-07-12 20:26 ` Jens Axboe
3 siblings, 0 replies; 5+ messages in thread
From: Jens Axboe @ 2020-07-12 20:26 UTC (permalink / raw)
To: Pavel Begunkov, io-uring
On 7/12/20 11:41 AM, Pavel Begunkov wrote:
> A follow-up for the "msg_name" fix, cleaning it up and
> deduplicating error prone parts.
Thanks, applied.
--
Jens Axboe
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-07-12 20:26 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-07-12 17:41 [PATCH 5.9 0/3] send/recv msghdr init cleanups Pavel Begunkov
2020-07-12 17:41 ` [PATCH 1/3] io_uring: rename sr->msg into umsg Pavel Begunkov
2020-07-12 17:41 ` [PATCH 2/3] io_uring: use more specific type in rcv/snd msg cp Pavel Begunkov
2020-07-12 17:41 ` [PATCH 3/3] io_uring: extract io_sendmsg_copy_hdr() Pavel Begunkov
2020-07-12 20:26 ` [PATCH 5.9 0/3] send/recv msghdr init cleanups Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox