Skip to contentSkip to conversation

trivial cleanups to net operations

PATCH Superseded Gabriel Krisman Bertazi 2 participants 5 messages Jun 2 io_uring

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover trivial cleanups to net operations

Gabriel Krisman Bertazi (3):
io_uring: Avoid msghdr on op_connect/op_bind async data
io_uring: Remove async_size for OP_LISTEN
io_uring: Drop wrong comment in OP_NOP

 io_uring/net.c   | 15 +++++++--------
 io_uring/net.h   |  4 ++++
 io_uring/nop.c   |  1 -
 io_uring/opdef.c |  5 ++---
 4 files changed, 13 insertions(+), 12 deletions(-)
Signature · 1 line
2.54.0
#1 lore raw

PATCH 1/3 io_uring: Avoid msghdr on op_connect/op_bind async data

Both IORING_OP_CONNECT and IORING_OP_BIND reuse the msghdr object for just to store sockaddr. Beyond allocating a much larger object than needed, msghdr can also wrap an iovec, which will be recycled unnecessarily. This splits the sockaddr into an async type.

---
 io_uring/net.c   | 15 +++++++--------
 io_uring/net.h   |  4 ++++
 io_uring/opdef.c |  4 ++--
 3 files changed, 13 insertions(+), 10 deletions(-)
io_uring/net.c +7 -8
index cceb5c1409ca..1da811100132 100644
@@ -1677,7 +1677,7 @@ void io_socket_bpf_populate(struct io_uring_bpf_ctx *bctx, struct io_kiocb *req)
 void io_connect_bpf_populate(struct io_uring_bpf_ctx *bctx, struct io_kiocb *req)
 {
 	struct io_connect *conn = io_kiocb_to_cmd(req, struct io_connect);
-	struct io_async_msghdr *iomsg = req->async_data;
+	struct io_async_sockaddr *iomsg = req->async_data;
 	struct sockaddr_storage *ss = &iomsg->addr;
 
 	/*
@@ -1772,7 +1772,7 @@ int io_socket(struct io_kiocb *req, unsigned int issue_flags)
 int io_connect_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
 {
 	struct io_connect *conn = io_kiocb_to_cmd(req, struct io_connect);
-	struct io_async_msghdr *io;
+	struct io_async_sockaddr *io;
 
 	if (sqe->len || sqe->buf_index || sqe->rw_flags || sqe->splice_fd_in)
 		return -EINVAL;
@@ -1781,7 +1781,7 @@ int io_connect_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
 	conn->addr_len =  READ_ONCE(sqe->addr2);
 	conn->in_progress = conn->seen_econnaborted = false;
 
-	io = io_msg_alloc_async(req);
+	io = io_uring_alloc_async_data(NULL, req);
 	if (unlikely(!io))
 		return -ENOMEM;
 
@@ -1791,7 +1791,7 @@ int io_connect_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
 int io_connect(struct io_kiocb *req, unsigned int issue_flags)
 {
 	struct io_connect *connect = io_kiocb_to_cmd(req, struct io_connect);
-	struct io_async_msghdr *io = req->async_data;
+	struct io_async_sockaddr *io = req->async_data;
 	unsigned file_flags;
 	int ret;
 	bool force_nonblock = issue_flags & IO_URING_F_NONBLOCK;
@@ -1835,7 +1835,6 @@ int io_connect(struct io_kiocb *req, unsigned int issue_flags)
 out:
 	if (ret < 0)
 		req_set_fail(req);
-	io_req_msg_cleanup(req, issue_flags);
 	io_req_set_res(req, ret, 0);
 	return IOU_COMPLETE;
 }
@@ -1844,7 +1843,7 @@ int io_bind_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
 {
 	struct io_bind *bind = io_kiocb_to_cmd(req, struct io_bind);
 	struct sockaddr __user *uaddr;
-	struct io_async_msghdr *io;
+	struct io_async_sockaddr *io;
 
 	if (sqe->len || sqe->buf_index || sqe->rw_flags || sqe->splice_fd_in)
 		return -EINVAL;
@@ -1852,7 +1851,7 @@ int io_bind_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
 	uaddr = u64_to_user_ptr(READ_ONCE(sqe->addr));
 	bind->addr_len =  READ_ONCE(sqe->addr2);
 
-	io = io_msg_alloc_async(req);
+	io = io_uring_alloc_async_data(NULL, req);
 	if (unlikely(!io))
 		return -ENOMEM;
 	return move_addr_to_kernel(uaddr, bind->addr_len, &io->addr);
@@ -1861,7 +1860,7 @@ int io_bind_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
 int io_bind(struct io_kiocb *req, unsigned int issue_flags)
 {
 	struct io_bind *bind = io_kiocb_to_cmd(req, struct io_bind);
-	struct io_async_msghdr *io = req->async_data;
+	struct io_async_sockaddr *io = req->async_data;
 	struct socket *sock;
 	int ret;
 
io_uring/net.h +4 -0
index 51fda715d3c0..b296ec4eefb2 100644
@@ -5,6 +5,10 @@
 #include <linux/io_uring_types.h>
 #include <uapi/linux/io_uring/bpf_filter.h>
 
+struct io_async_sockaddr {
+	struct sockaddr_storage		addr;
+};
+
 struct io_async_msghdr {
 #if defined(CONFIG_NET)
 	struct iou_vec				vec;
io_uring/opdef.c +2 -2
index 8ea6bd274607..ffa28224cc8f 100644
@@ -204,7 +204,7 @@ const struct io_issue_def io_issue_defs[] = {
 		.pollout		= 1,
 #if defined(CONFIG_NET)
 		.filter_pdu_size	= sizeof_field(struct io_uring_bpf_ctx, connect),
-		.async_size		= sizeof(struct io_async_msghdr),
+		.async_size		= sizeof(struct io_async_sockaddr),
 		.prep			= io_connect_prep,
 		.issue			= io_connect,
 		.filter_populate	= io_connect_bpf_populate,
@@ -505,7 +505,7 @@ const struct io_issue_def io_issue_defs[] = {
 		.needs_file		= 1,
 		.prep			= io_bind_prep,
 		.issue			= io_bind,
-		.async_size		= sizeof(struct io_async_msghdr),
+		.async_size		= sizeof(struct io_async_sockaddr),
 #else
 		.prep			= io_eopnotsupp_prep,
 #endif
Signature · 1 line
2.54.0
maintainer
#2 lore raw

Re: [PATCH 1/3] io_uring: Avoid msghdr on op_connect/op_bind async data

Quoted 4 lines · Gabriel Krisman Bertazi

Both IORING_OP_CONNECT and IORING_OP_BIND reuse the msghdr object for just to store sockaddr. Beyond allocating a much larger object than needed, msghdr can also wrap an iovec, which will be recycled unnecessarily. This splits the sockaddr into an async type.

Note: please prefix things that are net related as:

io_uring/net: Avoid msghdr on op_connect/op_bind async data

io_uring/net.h line 11

Quoted 12 lines
io_uring/net.h +4 -0
index 51fda715d3c0..b296ec4eefb2 100644
@@ -5,6 +5,10 @@
 #include <linux/io_uring_types.h>
 #include <uapi/linux/io_uring/bpf_filter.h>
 
+struct io_async_sockaddr {
+	struct sockaddr_storage		addr;
+};
+

Why not just use sockaddr_storage directly?

io_uring/net.c void io_socket_bpf_populate(struct io_uring_bpf_ctx *bctx, struct io_kiocb *req) · line 1681

Quoted 11 lines
io_uring/net.c +1 -1
index cceb5c1409ca..1da811100132 100644
@@ -1677,7 +1677,7 @@ void io_socket_bpf_populate(struct io_uring_bpf_ctx *bctx, struct io_kiocb *req)
 void io_connect_bpf_populate(struct io_uring_bpf_ctx *bctx, struct io_kiocb *req)
 {
 	struct io_connect *conn = io_kiocb_to_cmd(req, struct io_connect);
-	struct io_async_msghdr *iomsg = req->async_data;
+	struct io_async_sockaddr *iomsg = req->async_data;
 	struct sockaddr_storage *ss = &iomsg->addr;

and if we did that, then this line goes away and it just becomes:

	struct sockaddr_storage *ss = req->async_data;

instead?

Other than that, looks good to me, whole series in fact.

Signature · 1 line
Jens Axboe
#3 lore raw

PATCH 2/3 io_uring: Remove async_size for OP_LISTEN

In reply to Gabriel Krisman Bertazi

OP_LISTEN does not use async_data. Remove it.

---
 io_uring/opdef.c | 1 -
 1 file changed, 1 deletion(-)
io_uring/opdef.c +0 -1
index ffa28224cc8f..a6215ee95a3f 100644
@@ -515,7 +515,6 @@ const struct io_issue_def io_issue_defs[] = {
 		.needs_file		= 1,
 		.prep			= io_listen_prep,
 		.issue			= io_listen,
-		.async_size		= sizeof(struct io_async_msghdr),
 #else
 		.prep			= io_eopnotsupp_prep,
 #endif
Signature · 1 line
2.54.0
#4 lore raw

PATCH 3/3 io_uring: Drop wrong comment in OP_NOP

In reply to Gabriel Krisman Bertazi

This was copy-pasted from io_rw, where the comment actually makes sense. Here, we don't have struct kiocb. Drop the comment.

---
 io_uring/nop.c | 1 -
 1 file changed, 1 deletion(-)
io_uring/nop.c +0 -1
index 3caf07878f8a..e3333b5ed4e0 100644
@@ -12,7 +12,6 @@
 #include "nop.h"
 
 struct io_nop {
-	/* NOTE: kiocb has the file as the first member, so don't do it here */
 	struct file     *file;
 	int             result;
 	int		fd;
Signature · 1 line
2.54.0