From: Gabriel Krisman Bertazi <[email protected]>
To: [email protected]
Cc: [email protected], [email protected],
Gabriel Krisman Bertazi <[email protected]>
Subject: [PATCH v2 4/4] io_uring: Introduce IORING_OP_LISTEN
Date: Fri, 14 Jun 2024 12:30:47 -0400 [thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
IORING_OP_LISTEN provides the semantic of listen(2) via io_uring. While
this is an essentially synchronous system call, the main point is to
enable a network path to execute fully with io_uring registered and
descriptorless files.
Signed-off-by: Gabriel Krisman Bertazi <[email protected]>
---
changes since v1:
- Drop empty lines ahead of return (Jens).
---
include/uapi/linux/io_uring.h | 1 +
io_uring/net.c | 28 ++++++++++++++++++++++++++++
io_uring/net.h | 3 +++
io_uring/opdef.c | 13 +++++++++++++
4 files changed, 45 insertions(+)
diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h
index 4ef153d95c87..2aaf7ee256ac 100644
--- a/include/uapi/linux/io_uring.h
+++ b/include/uapi/linux/io_uring.h
@@ -258,6 +258,7 @@ enum io_uring_op {
IORING_OP_FIXED_FD_INSTALL,
IORING_OP_FTRUNCATE,
IORING_OP_BIND,
+ IORING_OP_LISTEN,
/* this goes last, obviously */
IORING_OP_LAST,
diff --git a/io_uring/net.c b/io_uring/net.c
index 8cbc29aff15c..028e126ab30c 100644
--- a/io_uring/net.c
+++ b/io_uring/net.c
@@ -56,6 +56,11 @@ struct io_bind {
int addr_len;
};
+struct io_listen {
+ struct file *file;
+ int backlog;
+};
+
struct io_sr_msg {
struct file *file;
union {
@@ -1751,6 +1756,29 @@ int io_bind(struct io_kiocb *req, unsigned int issue_flags)
return 0;
}
+int io_listen_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
+{
+ struct io_listen *listen = io_kiocb_to_cmd(req, struct io_listen);
+
+ if (sqe->addr || sqe->buf_index || sqe->rw_flags || sqe->splice_fd_in || sqe->addr2)
+ return -EINVAL;
+
+ listen->backlog = READ_ONCE(sqe->len);
+ return 0;
+}
+
+int io_listen(struct io_kiocb *req, unsigned int issue_flags)
+{
+ struct io_listen *listen = io_kiocb_to_cmd(req, struct io_listen);
+ int ret;
+
+ ret = __sys_listen_socket(sock_from_file(req->file), listen->backlog);
+ if (ret < 0)
+ req_set_fail(req);
+ io_req_set_res(req, ret, 0);
+ return 0;
+}
+
void io_netmsg_cache_free(const void *entry)
{
struct io_async_msghdr *kmsg = (struct io_async_msghdr *) entry;
diff --git a/io_uring/net.h b/io_uring/net.h
index 49f9a7bc1113..52bfee05f06a 100644
--- a/io_uring/net.h
+++ b/io_uring/net.h
@@ -52,6 +52,9 @@ void io_send_zc_cleanup(struct io_kiocb *req);
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);
+int io_listen_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe);
+int io_listen(struct io_kiocb *req, unsigned int issue_flags);
+
void io_netmsg_cache_free(const void *entry);
#else
static inline void io_netmsg_cache_free(const void *entry)
diff --git a/io_uring/opdef.c b/io_uring/opdef.c
index 19ee9445f024..7d5c51fb8e6e 100644
--- a/io_uring/opdef.c
+++ b/io_uring/opdef.c
@@ -503,6 +503,16 @@ const struct io_issue_def io_issue_defs[] = {
.async_size = sizeof(struct io_async_msghdr),
#else
.prep = io_eopnotsupp_prep,
+#endif
+ },
+ [IORING_OP_LISTEN] = {
+#if defined(CONFIG_NET)
+ .needs_file = 1,
+ .prep = io_listen_prep,
+ .issue = io_listen,
+ .async_size = sizeof(struct io_async_msghdr),
+#else
+ .prep = io_eopnotsupp_prep,
#endif
},
};
@@ -724,6 +734,9 @@ const struct io_cold_def io_cold_defs[] = {
[IORING_OP_BIND] = {
.name = "BIND",
},
+ [IORING_OP_LISTEN] = {
+ .name = "LISTEN",
+ },
};
const char *io_uring_get_opcode(u8 opcode)
--
2.45.2
next prev parent reply other threads:[~2024-06-14 16:30 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-14 16:30 [PATCH v2 1/4] net: Split a __sys_bind helper for io_uring Gabriel Krisman Bertazi
2024-06-14 16:30 ` [PATCH v2 2/4] net: Split a __sys_listen " Gabriel Krisman Bertazi
2024-06-14 22:44 ` Kuniyuki Iwashima
2024-06-19 0:50 ` Jakub Kicinski
2024-06-14 16:30 ` [PATCH v2 3/4] io_uring: Introduce IORING_OP_BIND Gabriel Krisman Bertazi
2024-06-14 22:46 ` Kuniyuki Iwashima
2024-06-15 0:27 ` Jens Axboe
2024-06-14 16:30 ` Gabriel Krisman Bertazi [this message]
2024-06-14 22:42 ` [PATCH v2 1/4] net: Split a __sys_bind helper for io_uring Kuniyuki Iwashima
2024-06-19 0:49 ` Jakub Kicinski
2024-06-19 13:40 ` Jens Axboe
2024-06-19 15:04 ` Jakub Kicinski
2024-06-19 15:06 ` Jens Axboe
2024-07-15 12:49 ` Matus Jokay
2024-07-15 13:59 ` Tetsuo Handa
2024-07-22 12:37 ` Matus Jokay
2024-06-19 14:58 ` Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox