Skip to contentSkip to conversation

trivial cleanups to net operations

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

lore
Share & tools
lore
#0 lore raw

v2 cover trivial cleanups to net operations

v2 only touches patch 1 to apply the changes requested by Jens. More information on the changelog.

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

 io_uring/net.c   | 30 ++++++++++++++----------------
 io_uring/nop.c   |  1 -
 io_uring/opdef.c |  5 ++---
 3 files changed, 16 insertions(+), 20 deletions(-)
Signature · 1 line
2.54.0
#1 lore raw

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

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

---
Since v1:
- use sockaddr directly

---
 io_uring/net.c   | 30 ++++++++++++++----------------
 io_uring/opdef.c |  4 ++--
 2 files changed, 16 insertions(+), 18 deletions(-)
io_uring/net.c +14 -16
index cceb5c1409ca..7ff5975e118b 100644
@@ -1677,8 +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 sockaddr_storage *ss = &iomsg->addr;
+	struct sockaddr_storage *ss = req->async_data;
 
 	/*
 	 * move_addr_to_kernel() skips the copy for addr_len == 0, so
@@ -1772,7 +1771,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 sockaddr_storage *addr;
 
 	if (sqe->len || sqe->buf_index || sqe->rw_flags || sqe->splice_fd_in)
 		return -EINVAL;
@@ -1781,17 +1780,17 @@ 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);
-	if (unlikely(!io))
+	addr = io_uring_alloc_async_data(NULL, req);
+	if (unlikely(!addr))
 		return -ENOMEM;
 
-	return move_addr_to_kernel(conn->addr, conn->addr_len, &io->addr);
+	return move_addr_to_kernel(conn->addr, conn->addr_len, addr);
 }
 
 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 sockaddr_storage *addr = req->async_data;
 	unsigned file_flags;
 	int ret;
 	bool force_nonblock = issue_flags & IO_URING_F_NONBLOCK;
@@ -1805,8 +1804,7 @@ int io_connect(struct io_kiocb *req, unsigned int issue_flags)
 
 	file_flags = force_nonblock ? O_NONBLOCK : 0;
 
-	ret = __sys_connect_file(req->file, &io->addr, connect->addr_len,
-				 file_flags);
+	ret = __sys_connect_file(req->file, addr, connect->addr_len, file_flags);
 	if ((ret == -EAGAIN || ret == -EINPROGRESS || ret == -ECONNABORTED)
 	    && force_nonblock) {
 		if (ret == -EINPROGRESS) {
@@ -1835,7 +1833,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 +1841,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 sockaddr_storage *addr;
 
 	if (sqe->len || sqe->buf_index || sqe->rw_flags || sqe->splice_fd_in)
 		return -EINVAL;
@@ -1852,16 +1849,17 @@ 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);
-	if (unlikely(!io))
+	addr = io_uring_alloc_async_data(NULL, req);
+	if (unlikely(!addr))
 		return -ENOMEM;
-	return move_addr_to_kernel(uaddr, bind->addr_len, &io->addr);
+	return move_addr_to_kernel(uaddr, bind->addr_len, addr);
 }
 
+
 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 sockaddr_storage *addr = req->async_data;
 	struct socket *sock;
 	int ret;
 
@@ -1869,7 +1867,7 @@ int io_bind(struct io_kiocb *req, unsigned int issue_flags)
 	if (unlikely(!sock))
 		return -ENOTSOCK;
 
-	ret = __sys_bind_socket(sock, &io->addr, bind->addr_len);
+	ret = __sys_bind_socket(sock, addr, bind->addr_len);
 	if (ret < 0)
 		req_set_fail(req);
 	io_req_set_res(req, ret, 0);
io_uring/opdef.c +2 -2
index 8ea6bd274607..517bad015505 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 sockaddr_storage),
 		.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 sockaddr_storage),
 #else
 		.prep			= io_eopnotsupp_prep,
 #endif
Signature · 1 line
2.54.0
#2 lore raw

PATCH v2 2/3 io_uring/net: 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 517bad015505..88a45c7d897f 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
#3 lore raw

PATCH v2 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
maintainer Applied
#4 lore raw
In reply to Gabriel Krisman Bertazi
Quoted 9 lines · Gabriel Krisman Bertazi

v2 only touches patch 1 to apply the changes requested by Jens. More information on the changelog.

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

[...]

Applied, thanks!

[1/3] io_uring/net: Avoid msghdr on op_connect/op_bind async data
(no commit info)
[2/3] io_uring/net: Remove async_size for OP_LISTEN
(no commit info)
[3/3] io_uring: Drop wrong comment in OP_NOP
(no commit info)

Best regards,

Signature · 1 line
Jens Axboe