NVME over MPTCP
Subsystems (5)
Geliang Tang
reviewerv8 cover NVME over MPTCP
From: Geliang Tang <[email protected]>
v8:
- address comments reported by ai-review for v7.
- add RCU protection for queue->port on target side.
- add RCU protection ctrl->proto on host side.
- check !msk->first instead of "IS_ERR(msk->first)".
- fix return value of mptcp_sock_set_syncnt.
- update selftest.
- fix CI error: "[SKIP] Could not run all tests without nvme".
v7:
- address comments reported by ai-review.
- change sockops in nvmet_tcp_port and nvme_tcp_ctrl as a pointer.
- add null checks for queue->port->sockops in nvmet_tcp_set_queue_sock.
- add inline for mptcp_sock_set_priority and mptcp_sock_set_tos in
mptcp.h
- use "ssk = msk->first" instead of "ssk = __mptcp_nmpc_sk(msk)" in mptcp_sock_set_priority, mptcp_sock_no_linger and mptcp_sock_set_tos.
- drop sk_is_tcp in nvmet_tcp_done_recv_pdu
- move ctrl->sockops setting before nvme_init_ctrl in
nvme_tcp_alloc_ctrl
- define nvme_mptcp_ctrl_ops
- add MODULE_ALIAS("nvme-mptcp")
- add more CONFIG_MPTCP checks
- update selftest
- Link: https://patchwork.kernel.org/project/mptcp/cover/[email protected]/
v6:
- introduce nvmet_tcp_sockops and nvme_tcp_sockops structures
- fix set_reuseaddr, set_nodelay and set_syncnt, add sockopt_seq_inc
calls, only set the first subflow, and synchronize to other subflows in sync_socket_options
- Add implementations for no_linger, set_priority and set_tos
- This version no longer depends on the "mptcp: fix stall because of
data_ready" series of fixes
- Link: https://patchwork.kernel.org/project/mptcp/cover/[email protected]/
v5:
- address comments reported by ai-review: set msk->nodelay to true in mptcp_sock_set_nodelay, set sk->sk_reuse to ssk->sk_reuse in mptcp_sock_set_reuseaddr, add mptcp_nvme.sh to TEST_PROGS, and adjust
the order of patches.
- remove TLS-related options from .allowed_opts of
nvme_mptcp_transport.
- some cleanups for selftest.
- Link: https://patchwork.kernel.org/project/mptcp/cover/[email protected]/
v4:
- a new patch to set nvme iopolicy as Nilay suggested.
- resend all set to trigger AI review.
- Link: https://patchwork.kernel.org/project/mptcp/cover/[email protected]/
v3:
- update the implementation of sock_set_nodelay: originally it only set
the first subflow, but now it sets every subflow.
- use sk_is_msk helper in this set.
- update the selftest to perform testing under a multi-interface
environment.
- Link: https://patchwork.kernel.org/project/mptcp/cover/[email protected]/
v2:
- Patch 1 fixes the timeout issue reported in v1, thanks to Paolo and Gang
Yan for their help.
- Patch 5 implements an MPTCP-specific sock_set_syncnt helper.
- Link: https://patchwork.kernel.org/project/mptcp/cover/[email protected]/
This series (previously named "MPTCP support to 'NVME over TCP'") had three RFC versions sent to Hannes in May, with subsequent revisions based on his input. Following that, I initiated the process of upstreaming the dependent "implement mptcp read_sock" series to the main MPTCP repository, which has been merged into net-next recently.
Geliang Tang (7):
nvmet-tcp: define target tcp_proto struct
nvmet-tcp: register target mptcp transport
nvmet-tcp: implement target mptcp proto
nvme-tcp: define host tcp_proto struct
nvme-tcp: register host mptcp transport
nvme-tcp: implement host mptcp proto
selftests: mptcp: add NVMe over MPTCP test
drivers/nvme/host/tcp.c | 108 +++++++- drivers/nvme/target/configfs.c | 1 + drivers/nvme/target/tcp.c | 112 +++++++- include/linux/nvme.h | 1 + include/net/mptcp.h | 27 ++ net/mptcp/protocol.h | 1 + net/mptcp/sockopt.c | 116 +++++++++ tools/testing/selftests/net/mptcp/Makefile | 1 + tools/testing/selftests/net/mptcp/config | 7 + .../testing/selftests/net/mptcp/mptcp_lib.sh | 12 + .../testing/selftests/net/mptcp/mptcp_nvme.sh | 240 ++++++++++++++++++ 11 files changed, 607 insertions(+), 19 deletions(-) create mode 100755 tools/testing/selftests/net/mptcp/mptcp_nvme.sh
Signature · 1 line
2.51.0
Geliang Tang
reviewerRFC v8 1/7 nvmet-tcp: define target tcp_proto struct
From: Geliang Tang <[email protected]>
To add MPTCP support in "NVMe over TCP", the target side needs to pass IPPROTO_MPTCP to sock_create() instead of IPPROTO_TCP to create an MPTCP socket. Additionally, the setsockopt operations for this socket need to be switched to a set of MPTCP-specific functions.
This patch defines the nvmet_tcp_proto structure, which contains the protocol of the socket and a set of function pointers for these socket operations. A "proto" field is also added to struct nvmet_tcp_port.
A TCP-specific version of struct nvmet_tcp_proto is defined. In nvmet_tcp_add_port(), port->proto is set to nvmet_tcp_proto based on whether trtype is TCP. All locations that previously called TCP setsockopt functions are updated to call the corresponding function pointers in the nvmet_tcp_proto structure.
This new nvmet_fabrics_ops is selected in nvmet_tcp_done_recv_pdu() based on the protocol type.
RCU protection is added when accessing queue->port in the I/O path (nvmet_tcp_alloc_cmd, nvmet_tcp_done_recv_pdu, nvmet_tcp_set_queue_sock) to prevent use-after-free when a port is removed while asynchronous operations (e.g., TLS handshake) are pending. The port structure is released using kfree_rcu() in nvmet_tcp_remove_port(), and queue->port is assigned using rcu_assign_pointer() in nvmet_tcp_alloc_queue().
--- drivers/nvme/target/tcp.c | 66 ++++++++++++++++++++++++++++++++------- 1 file changed, 55 insertions(+), 11 deletions(-)
drivers/nvme/target/tcp.c +55 -11
@@ -18,6 +18,7 @@#include <net/handshake.h> #include <linux/inet.h> #include <linux/llist.h> +#include <linux/rcupdate.h> #include <trace/events/sock.h> #include "nvmet.h"
@@ -198,12 +199,24 @@ struct nvmet_tcp_queue {void (*write_space)(struct sock *); }; +struct nvmet_tcp_proto { +int protocol; +void (*set_reuseaddr)(struct sock *sk); +void (*set_nodelay)(struct sock *sk); +void (*set_priority)(struct sock *sk,u32 priority); +void (*no_linger)(struct sock *sk); +void (*set_tos)(struct sock *sk,int val); +const struct nvmet_fabrics_ops *ops; +}; +struct nvmet_tcp_port { +struct rcu_head rcu;struct socket *sock;struct work_struct accept_work;struct nvmet_port *nport;struct sockaddr_storage addr;void (*data_ready)(struct sock *); +const struct nvmet_tcp_proto *proto; };static DEFINE_IDA (nvmet_tcp_queue_ida);
@@ -1027,6 +1040,7 @@ static int nvmet_tcp_done_recv_pdu(struct nvmet_tcp_queue *queue) {struct nvme_tcp_hdr *hdr = &queue->pdu.cmd.hdr;struct nvme_command *nvme_cmd = &queue->pdu.cmd.cmd; +const struct nvmet_fabrics_ops *ops;struct nvmet_req *req;int ret;
@@ -1067,7 +1081,10 @@ static int nvmet_tcp_done_recv_pdu(struct nvmet_tcp_queue *queue) req = &queue->cmd->req;memcpy (req->cmd, nvme_cmd,sizeof (*nvme_cmd)); -if (unlikely (!nvmet_req_init (req, &queue->nvme_sq, &nvmet_tcp_ops))) { +rcu_read_lock (); + ops =rcu_dereference (queue->port)->proto->ops; +rcu_read_unlock (); +if (unlikely (!nvmet_req_init (req, &queue->nvme_sq, ops))) { pr_err("failed cmd %p id %d opcode %d, data_len: %d, status: %04x\n", req->cmd, req->cmd->common.command_id, req->cmd->common.opcode,
@@ -1686,6 +1703,7 @@ static int nvmet_tcp_set_queue_sock(struct nvmet_tcp_queue *queue) {struct socket *sock = queue->sock;struct inet_sock *inet =inet_sk (sock->sk); +const struct nvmet_tcp_proto *proto;int ret; ret = kernel_getsockname(sock,
@@ -1698,19 +1716,23 @@ static int nvmet_tcp_set_queue_sock(struct nvmet_tcp_queue *queue)if (ret <0 )return ret; +rcu_read_lock (); + proto =rcu_dereference (queue->port)->proto; +rcu_read_unlock (); +/* * Cleanup whatever is sitting in the TCP transmit queue on socket * close. This is done to prevent stale data from being sent should * the network connection be restored before TCP times out. */ -sock_no_linger (sock->sk); + proto->no_linger (sock->sk);if (so_priority >0 ) -sock_set_priority (sock->sk, so_priority); + proto->set_priority (sock->sk, so_priority);/* Set socket type of service */ if (inet->rcv_tos >0 ) -ip_sock_set_tos (sock->sk, inet->rcv_tos); + proto->set_tos (sock->sk, inet->rcv_tos); ret =0 ;write_lock_bh (&sock->sk->sk_callback_lock);
@@ -2030,6 +2052,16 @@ static void nvmet_tcp_listen_data_ready(struct sock *sk)read_unlock_bh (&sk->sk_callback_lock); } +static const struct nvmet_tcp_proto nvmet_tcp_proto = { + .protocol =IPPROTO_TCP , + .set_reuseaddr = sock_set_reuseaddr, + .set_nodelay = tcp_sock_set_nodelay, + .set_priority = sock_set_priority, + .no_linger = sock_no_linger, + .set_tos = ip_sock_set_tos, + .ops = &nvmet_tcp_ops, +}; +static int nvmet_tcp_add_port (struct nvmet_port *nport) {struct nvmet_tcp_port *port;
@@ -2054,6 +2086,13 @@ static int nvmet_tcp_add_port(struct nvmet_port *nport) goto err_port; } +if (nport->disc_addr.trtype ==NVMF_TRTYPE_TCP ) { + port->proto = &nvmet_tcp_proto; + }else { + ret = -EINVAL ; + goto err_port; + } + ret =inet_pton_with_scope (&init_net, af, nport->disc_addr.traddr, nport->disc_addr.trsvcid, &port->addr);if (ret) {
@@ -2068,7 +2107,7 @@ static int nvmet_tcp_add_port(struct nvmet_port *nport) port->nport->inline_data_size =NVMET_TCP_DEF_INLINE_DATA_SIZE ; ret =sock_create (port->addr.ss_family,SOCK_STREAM , -IPPROTO_TCP , &port->sock); + port->proto->protocol, &port->sock);if (ret) {pr_err ("failed to create a socket\n" ); goto err_port;
@@ -2077,10 +2116,10 @@ static int nvmet_tcp_add_port(struct nvmet_port *nport) port->sock->sk->sk_user_data = port; port->data_ready = port->sock->sk->sk_data_ready; port->sock->sk->sk_data_ready = nvmet_tcp_listen_data_ready; -sock_set_reuseaddr (port->sock->sk); -tcp_sock_set_nodelay (port->sock->sk); + port->proto->set_reuseaddr (port->sock->sk); + port->proto->set_nodelay (port->sock->sk);if (so_priority >0 ) -sock_set_priority (port->sock->sk, so_priority); + port->proto->set_priority (port->sock->sk, so_priority); ret =kernel_bind (port->sock, (struct sockaddr_unsized *)&port->addr,sizeof (port->addr));
@@ -2111,11 +2150,16 @@ static int nvmet_tcp_add_port(struct nvmet_port *nport)static void nvmet_tcp_destroy_port_queues (struct nvmet_tcp_port *port) {struct nvmet_tcp_queue *queue; +struct nvmet_tcp_port *qport;mutex_lock (&nvmet_tcp_queue_mutex); -list_for_each_entry (queue, &nvmet_tcp_queue_list, queue_list) -if (queue->port == port) +list_for_each_entry (queue, &nvmet_tcp_queue_list, queue_list) { +rcu_read_lock (); + qport =rcu_dereference (queue->port); +rcu_read_unlock (); +if (qport == port)kernel_sock_shutdown (queue->sock,SHUT_RDWR ); + }mutex_unlock (&nvmet_tcp_queue_mutex); }
@@ -2135,7 +2179,7 @@ static void nvmet_tcp_remove_port(struct nvmet_port *nport)nvmet_tcp_destroy_port_queues (port);sock_release (port->sock); -kfree (port); +kfree_rcu (port, rcu); }static void nvmet_tcp_delete_ctrl (struct nvmet_ctrl *ctrl)
Signature · 1 line
2.51.0
Geliang Tang
reviewerRFC v8 2/7 nvmet-tcp: register target mptcp transport
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
This patch adds a new nvme target transport type NVMF_TRTYPE_MPTCP for MPTCP. And defines a new nvmet_fabrics_ops named nvmet_mptcp_ops, which is almost the same as nvmet_tcp_ops except .type. It is registered in nvmet_tcp_init() and unregistered in nvmet_tcp_exit().
A MODULE_ALIAS for "nvmet-transport-4" is also added.
v2:
- use trtype instead of tsas (Hannes).
v3:
- check mptcp protocol from disc_addr.trtype instead of passing a
parameter (Hannes).
v4:
- check CONFIG_MPTCP.
--- drivers/nvme/target/configfs.c | 1 + drivers/nvme/target/tcp.c | 27 +++++++++++++++++++++++++++ include/linux/nvme.h | 1 + 3 files changed, 29 insertions(+)
drivers/nvme/target/configfs.c +1 -0
@@ -38,6 +38,7 @@ static struct nvmet_type_name_map nvmet_transport[] = { { NVMF_TRTYPE_RDMA, "rdma" }, { NVMF_TRTYPE_FC, "fc" }, { NVMF_TRTYPE_TCP, "tcp" }, + { NVMF_TRTYPE_MPTCP, "mptcp" }, { NVMF_TRTYPE_PCI, "pci" }, { NVMF_TRTYPE_LOOP, "loop" }, };
drivers/nvme/target/tcp.c +27 -0
@@ -2264,6 +2264,21 @@ static const struct nvmet_fabrics_ops nvmet_tcp_ops = { .host_traddr = nvmet_tcp_host_port_addr, }; +#ifdef CONFIG_MPTCP +static const struct nvmet_fabrics_ops nvmet_mptcp_ops = { + .owner =THIS_MODULE , + .type =NVMF_TRTYPE_MPTCP , + .msdbd =1 , + .add_port = nvmet_tcp_add_port, + .remove_port = nvmet_tcp_remove_port, + .queue_response = nvmet_tcp_queue_response, + .delete_ctrl = nvmet_tcp_delete_ctrl, + .install_queue = nvmet_tcp_install_queue, + .disc_traddr = nvmet_tcp_disc_port_addr, + .host_traddr = nvmet_tcp_host_port_addr, +}; +#endif +static int __init nvmet_tcp_init (void ) {int ret;
@@ -2277,6 +2292,14 @@ static int __init nvmet_tcp_init(void)if (ret) goto err; +#ifdef CONFIG_MPTCP + ret =nvmet_register_transport (&nvmet_mptcp_ops); +if (ret) { +nvmet_unregister_transport (&nvmet_tcp_ops); + goto err; + } +#endif +return 0 ; err:destroy_workqueue (nvmet_tcp_wq);
@@ -2287,6 +2310,9 @@ static void __exit nvmet_tcp_exit(void) {struct nvmet_tcp_queue *queue; +#ifdef CONFIG_MPTCP +nvmet_unregister_transport (&nvmet_mptcp_ops); +#endif nvmet_unregister_transport (&nvmet_tcp_ops);flush_workqueue (nvmet_wq);
@@ -2306,3 +2332,4 @@ module_exit(nvmet_tcp_exit);MODULE_DESCRIPTION ("NVMe target TCP transport driver" );MODULE_LICENSE ("GPL v2" );MODULE_ALIAS ("nvmet-transport-3" );/* 3 == NVMF_TRTYPE_TCP */ +MODULE_ALIAS ("nvmet-transport-4" );/* 4 == NVMF_TRTYPE_MPTCP */
include/linux/nvme.h +1 -0
@@ -68,6 +68,7 @@ enum {NVMF_TRTYPE_RDMA =1 ,/* RDMA */ NVMF_TRTYPE_FC =2 ,/* Fibre Channel */ NVMF_TRTYPE_TCP =3 ,/* TCP/IP */ +NVMF_TRTYPE_MPTCP =4 ,/* Multipath TCP */ NVMF_TRTYPE_LOOP =254 ,/* Reserved for host usage */ NVMF_TRTYPE_MAX, };
Signature · 1 line
2.51.0
Geliang Tang
reviewerRFC v8 3/7 nvmet-tcp: implement target mptcp proto
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
This patch introduces a new NVMe target transport type NVMF_TRTYPE_MPTCP to support MPTCP.
An MPTCP-specific version of struct nvmet_tcp_proto is implemented, and it is assigned to port->proto when the transport type is MPTCP.
Dedicated MPTCP helpers are introduced for setting socket options. These helpers set the values on the first subflow socket of an MPTCP connection. The values are then synchronized to other newly created subflows in sync_socket_options().
--- drivers/nvme/target/tcp.c | 19 ++++++++ include/net/mptcp.h | 20 +++++++++ net/mptcp/sockopt.c | 91 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 130 insertions(+)
drivers/nvme/target/tcp.c +19 -0
@@ -225,6 +225,9 @@ static DEFINE_MUTEX(nvmet_tcp_queue_mutex);static struct workqueue_struct *nvmet_tcp_wq;static const struct nvmet_fabrics_ops nvmet_tcp_ops; +#ifdef CONFIG_MPTCP +static const struct nvmet_fabrics_ops nvmet_mptcp_ops; +#endif static void nvmet_tcp_free_cmd (struct nvmet_tcp_cmd *c);static void nvmet_tcp_free_cmd_buffers (struct nvmet_tcp_cmd *cmd);
@@ -2062,6 +2065,18 @@ static const struct nvmet_tcp_proto nvmet_tcp_proto = { .ops = &nvmet_tcp_ops, }; +#ifdef CONFIG_MPTCP +static const struct nvmet_tcp_proto nvmet_mptcp_proto = { + .protocol =IPPROTO_MPTCP , + .set_reuseaddr = mptcp_sock_set_reuseaddr, + .set_nodelay = mptcp_sock_set_nodelay, + .set_priority = mptcp_sock_set_priority, + .no_linger = mptcp_sock_no_linger, + .set_tos = mptcp_sock_set_tos, + .ops = &nvmet_mptcp_ops, +}; +#endif +static int nvmet_tcp_add_port (struct nvmet_port *nport) {struct nvmet_tcp_port *port;
@@ -2088,6 +2103,10 @@ static int nvmet_tcp_add_port(struct nvmet_port *nport)if (nport->disc_addr.trtype ==NVMF_TRTYPE_TCP ) { port->proto = &nvmet_tcp_proto; +#ifdef CONFIG_MPTCP + }else if (nport->disc_addr.trtype ==NVMF_TRTYPE_MPTCP ) { + port->proto = &nvmet_mptcp_proto; +#endif }else { ret = -EINVAL ; goto err_port;
include/net/mptcp.h +20 -0
@@ -237,6 +237,16 @@ static inline __be32 mptcp_reset_option(const struct sk_buff *skb) }void mptcp_active_detect_blackhole (struct sock *sk,bool expired); + +void mptcp_sock_set_reuseaddr (struct sock *sk); + +void mptcp_sock_set_nodelay (struct sock *sk); + +void mptcp_sock_set_priority (struct sock *sk,u32 priority); + +void mptcp_sock_no_linger (struct sock *sk); + +void mptcp_sock_set_tos (struct sock *sk,int val);#else static inline void mptcp_init (void )
@@ -323,6 +333,16 @@ static inline struct request_sock *mptcp_subflow_reqsk_alloc(const struct requesstatic inline __be32 mptcp_reset_option (const struct sk_buff *skb) {return htonl (0u ); }static inline void mptcp_active_detect_blackhole (struct sock *sk,bool expired) { } + +static inline void mptcp_sock_set_reuseaddr (struct sock *sk) { } + +static inline void mptcp_sock_set_nodelay (struct sock *sk) { } + +static inline void mptcp_sock_set_priority (struct sock *sk,u32 priority) { } + +static inline void mptcp_sock_no_linger (struct sock *sk) { } + +static inline void mptcp_sock_set_tos (struct sock *sk,int val) { }#endif /* CONFIG_MPTCP */ #if IS_ENABLED (CONFIG_MPTCP_IPV6 )
net/mptcp/sockopt.c +91 -0
106 lines not on this page · raw message
Signature · 1 line
2.51.0
Geliang Tang
reviewerRFC v8 4/7 nvme-tcp: define host tcp_proto struct
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
To add MPTCP support in "NVMe over TCP", the host side needs to pass IPPROTO_MPTCP to sock_create_kern() instead of IPPROTO_TCP to create an MPTCP socket.
Similar to the target-side nvmet_tcp_proto, this patch defines the host-side nvme_tcp_proto structure, which contains the protocol of the socket and a set of function pointers for socket operations. The only difference is that it defines .set_syncnt instead of .set_reuseaddr.
A TCP-specific version of this structure is defined, and a proto field is added to nvme_tcp_ctrl. When the transport string is "tcp", it is assigned to ctrl->proto using RCU assignment.
All locations that previously called TCP setsockopt functions are updated to call the corresponding function pointers in the nvme_tcp_proto structure. RCU protection is added when accessing ctrl->proto in the I/O path (nvme_tcp_alloc_queue()) to prevent use-after-free when the controller is being removed concurrently. The proto field is released using kfree_rcu() in nvme_tcp_free_ctrl().
--- drivers/nvme/host/tcp.c | 53 ++++++++++++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 8 deletions(-)
drivers/nvme/host/tcp.c +45 -8
@@ -11,6 +11,7 @@#include <linux/crc32.h> #include <linux/nvme-tcp.h> #include <linux/nvme-keyring.h> +#include <linux/rcupdate.h> #include <net/sock.h> #include <net/tcp.h> #include <net/tls.h>
@@ -182,7 +183,19 @@ struct nvme_tcp_queue {void (*write_space)(struct sock *); }; +struct nvme_tcp_proto { +int protocol; +int (*set_syncnt)(struct sock *sk,int val); +void (*set_nodelay)(struct sock *sk); +void (*no_linger)(struct sock *sk); +void (*set_priority)(struct sock *sk,u32 priority); +void (*set_tos)(struct sock *sk,int val); +const struct nvme_ctrl_ops *ops; +}; +struct nvme_tcp_ctrl { +struct rcu_head rcu; +/* read only in the hot path */ struct nvme_tcp_queue *queues;struct blk_mq_tag_set tag_set;
@@ -198,6 +211,8 @@ struct nvme_tcp_ctrl {struct delayed_work connect_work;struct nvme_tcp_request async_req;u32 io_queues[HCTX_MAX_TYPES ]; + +const struct nvme_tcp_proto *proto; };static LIST_HEAD (nvme_tcp_ctrl_list);
@@ -1767,6 +1782,7 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl, int qid, {struct nvme_tcp_ctrl *ctrl =to_tcp_ctrl (nctrl);struct nvme_tcp_queue *queue = &ctrl->queues[qid]; +const struct nvme_tcp_proto *proto;int ret, rcv_pdu_size;struct file *sock_file;
@@ -1783,9 +1799,13 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl, int qid, queue->cmnd_capsule_len =sizeof (struct nvme_command ) +NVME_TCP_ADMIN_CCSZ ; +rcu_read_lock (); + proto =rcu_dereference (ctrl->proto); +rcu_read_unlock (); + ret =sock_create_kern (current->nsproxy->net_ns, ctrl->addr.ss_family,SOCK_STREAM , -IPPROTO_TCP , &queue->sock); + proto->protocol, &queue->sock);if (ret) {dev_err (nctrl->device,"failed to create socket: %d\n" , ret);
@@ -1802,24 +1822,24 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl, int qid,nvme_tcp_reclassify_socket (queue->sock);/* Single syn retry */ -tcp_sock_set_syncnt (queue->sock->sk,1 ); + proto->set_syncnt (queue->sock->sk,1 );/* Set TCP no delay */ -tcp_sock_set_nodelay (queue->sock->sk); + proto->set_nodelay (queue->sock->sk);/* * Cleanup whatever is sitting in the TCP transmit queue on socket * close. This is done to prevent stale data from being sent should * the network connection be restored before TCP times out. */ -sock_no_linger (queue->sock->sk); + proto->no_linger (queue->sock->sk);if (so_priority >0 ) -sock_set_priority (queue->sock->sk, so_priority); + proto->set_priority (queue->sock->sk, so_priority);/* Set socket type of service */ if (nctrl->opts->tos >=0 ) -ip_sock_set_tos (queue->sock->sk, nctrl->opts->tos); + proto->set_tos (queue->sock->sk, nctrl->opts->tos);/* Set 10 seconds timeout for icresp recvmsg */ queue->sock->sk->sk_rcvtimeo =10 *HZ ;
@@ -2564,7 +2584,7 @@ static void nvme_tcp_free_ctrl(struct nvme_ctrl *nctrl)nvmf_free_options (nctrl->opts); free_ctrl:kfree (ctrl->queues); -kfree (ctrl); +kfree_rcu (ctrl, rcu); }static void nvme_tcp_set_sg_null (struct nvme_command *c)
@@ -2886,6 +2906,16 @@ nvme_tcp_existing_controller(struct nvmf_ctrl_options *opts)return found; } +static const struct nvme_tcp_proto nvme_tcp_proto = { + .protocol =IPPROTO_TCP , + .set_syncnt = tcp_sock_set_syncnt, + .set_nodelay = tcp_sock_set_nodelay, + .no_linger = sock_no_linger, + .set_priority = sock_set_priority, + .set_tos = ip_sock_set_tos, + .ops = &nvme_tcp_ctrl_ops, +}; +static struct nvme_tcp_ctrl *nvme_tcp_alloc_ctrl (struct device *dev,struct nvmf_ctrl_options *opts) {
@@ -2950,13 +2980,20 @@ static struct nvme_tcp_ctrl *nvme_tcp_alloc_ctrl(struct device *dev, goto out_free_ctrl; } +if (!strcmp (ctrl->ctrl.opts->transport,"tcp" )) { +rcu_assign_pointer (ctrl->proto, &nvme_tcp_proto); + }else { + ret = -EINVAL ; + goto out_free_ctrl; + } + ctrl->queues =kzalloc_objs (*ctrl->queues, ctrl->ctrl.queue_count);if (!ctrl->queues) { ret = -ENOMEM ; goto out_free_ctrl; } - ret =nvme_init_ctrl (&ctrl->ctrl, dev, &nvme_tcp_ctrl_ops,0 ); + ret =nvme_init_ctrl (&ctrl->ctrl, dev, ctrl->proto->ops,0 );if (ret) goto out_kfree_queues;
Signature · 1 line
2.51.0
Geliang Tang
reviewerRFC v8 5/7 nvme-tcp: register host mptcp transport
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
This patch defines a new nvmf_transport_ops named nvme_mptcp_transport, which is almost the same as nvme_tcp_transport except .type and .allowed_opts.
MPTCP currently does not support TLS. The four TLS-related options (NVMF_OPT_TLS, NVMF_OPT_KEYRING, NVMF_OPT_TLS_KEY, and NVMF_OPT_CONCAT) have been removed from allowed_opts. They will be added back once MPTCP TLS is supported.
It is registered in nvme_tcp_init_module() and unregistered in nvme_tcp_cleanup_module().
A separate nvme_mptcp_ctrl_ops structure with .name = "mptcp" is defined and used for MPTCP controllers.
A MODULE_ALIAS("nvme-mptcp") declaration alongside the other module metadata is added at the end of the file.
v2:
- use 'trtype' instead of '--mptcp' (Hannes)
v3:
- check mptcp protocol from opts->transport instead of passing a
parameter (Hannes).
v4:
- check CONFIG_MPTCP.
--- drivers/nvme/host/tcp.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
drivers/nvme/host/tcp.c +21 -0
@@ -3060,6 +3060,20 @@ static struct nvmf_transport_ops nvme_tcp_transport = { .create_ctrl = nvme_tcp_create_ctrl, }; +#ifdef CONFIG_MPTCP +static struct nvmf_transport_ops nvme_mptcp_transport = { + .name ="mptcp" , + .module =THIS_MODULE , + .required_opts =NVMF_OPT_TRADDR , + .allowed_opts =NVMF_OPT_TRSVCID |NVMF_OPT_RECONNECT_DELAY | +NVMF_OPT_HOST_TRADDR |NVMF_OPT_CTRL_LOSS_TMO | +NVMF_OPT_HDR_DIGEST |NVMF_OPT_DATA_DIGEST | +NVMF_OPT_NR_WRITE_QUEUES |NVMF_OPT_NR_POLL_QUEUES | +NVMF_OPT_TOS |NVMF_OPT_HOST_IFACE , + .create_ctrl = nvme_tcp_create_ctrl, +}; +#endif +static int __init nvme_tcp_init_module (void ) {unsigned int wq_flags =WQ_MEM_RECLAIM |WQ_HIGHPRI |WQ_SYSFS ;
@@ -3085,6 +3099,9 @@ static int __init nvme_tcp_init_module(void)atomic_set (&nvme_tcp_cpu_queues[cpu],0 );nvmf_register_transport (&nvme_tcp_transport); +#ifdef CONFIG_MPTCP +nvmf_register_transport (&nvme_mptcp_transport); +#endif return 0 ; }
@@ -3092,6 +3109,9 @@ static void __exit nvme_tcp_cleanup_module(void) {struct nvme_tcp_ctrl *ctrl; +#ifdef CONFIG_MPTCP +nvmf_unregister_transport (&nvme_mptcp_transport); +#endif nvmf_unregister_transport (&nvme_tcp_transport);mutex_lock (&nvme_tcp_ctrl_mutex);
@@ -3108,3 +3128,4 @@ module_exit(nvme_tcp_cleanup_module);MODULE_DESCRIPTION ("NVMe host TCP transport driver" );MODULE_LICENSE ("GPL v2" ); +MODULE_ALIAS ("nvme-mptcp" );
Signature · 1 line
2.51.0
Geliang Tang
reviewerRFC v8 6/7 nvme-tcp: implement host mptcp proto
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
An MPTCP-specific version of struct nvme_tcp_proto is implemented, and it is assigned to ctrl->proto when the transport string is "mptcp".
The socket option setting logic is similar to the target side, except that mptcp_sock_set_syncnt is newly defined for the host side.
It sets the value on the first subflow socket of an MPTCP connection. The value is then synchronized to other newly created subflows in sync_socket_options().
A separate nvme_mptcp_ctrl_ops structure with .name = "mptcp" is defined and used for MPTCP controllers.
--- drivers/nvme/host/tcp.c | 34 ++++++++++++++++++++++++++++++++++ include/net/mptcp.h | 7 +++++++ net/mptcp/protocol.h | 1 + net/mptcp/sockopt.c | 25 +++++++++++++++++++++++++ 4 files changed, 67 insertions(+)
drivers/nvme/host/tcp.c +34 -0
@@ -2889,6 +2889,24 @@ static const struct nvme_ctrl_ops nvme_tcp_ctrl_ops = { .get_virt_boundary = nvmf_get_virt_boundary, }; +#ifdef CONFIG_MPTCP +static const struct nvme_ctrl_ops nvme_mptcp_ctrl_ops = { + .name ="mptcp" , + .module =THIS_MODULE , + .flags =NVME_F_FABRICS |NVME_F_BLOCKING , + .reg_read32 = nvmf_reg_read32, + .reg_read64 = nvmf_reg_read64, + .reg_write32 = nvmf_reg_write32, + .subsystem_reset = nvmf_subsystem_reset, + .free_ctrl = nvme_tcp_free_ctrl, + .submit_async_event = nvme_tcp_submit_async_event, + .delete_ctrl = nvme_tcp_delete_ctrl, + .get_address = nvme_tcp_get_address, + .stop_ctrl = nvme_tcp_stop_ctrl, + .get_virt_boundary = nvmf_get_virt_boundary, +}; +#endif +static bool nvme_tcp_existing_controller (struct nvmf_ctrl_options *opts) {
@@ -2916,6 +2934,18 @@ static const struct nvme_tcp_proto nvme_tcp_proto = { .ops = &nvme_tcp_ctrl_ops, }; +#ifdef CONFIG_MPTCP +static const struct nvme_tcp_proto nvme_mptcp_proto = { + .protocol =IPPROTO_MPTCP , + .set_syncnt = mptcp_sock_set_syncnt, + .set_nodelay = mptcp_sock_set_nodelay, + .no_linger = mptcp_sock_no_linger, + .set_priority = mptcp_sock_set_priority, + .set_tos = mptcp_sock_set_tos, + .ops = &nvme_mptcp_ctrl_ops, +}; +#endif +static struct nvme_tcp_ctrl *nvme_tcp_alloc_ctrl (struct device *dev,struct nvmf_ctrl_options *opts) {
@@ -2982,6 +3012,10 @@ static struct nvme_tcp_ctrl *nvme_tcp_alloc_ctrl(struct device *dev,if (!strcmp (ctrl->ctrl.opts->transport,"tcp" )) {rcu_assign_pointer (ctrl->proto, &nvme_tcp_proto); +#ifdef CONFIG_MPTCP + }else if (!strcmp (ctrl->ctrl.opts->transport,"mptcp" )) { +rcu_assign_pointer (ctrl->proto, &nvme_mptcp_proto); +#endif }else { ret = -EINVAL ; goto out_free_ctrl;
include/net/mptcp.h +7 -0
@@ -247,6 +247,8 @@ void mptcp_sock_set_priority(struct sock *sk, u32 priority);void mptcp_sock_no_linger (struct sock *sk);void mptcp_sock_set_tos (struct sock *sk,int val); + +int mptcp_sock_set_syncnt (struct sock *sk,int val);#else static inline void mptcp_init (void )
@@ -343,6 +345,11 @@ static inline void mptcp_sock_set_priority(struct sock *sk, u32 priority) { }static inline void mptcp_sock_no_linger (struct sock *sk) { }static inline void mptcp_sock_set_tos (struct sock *sk,int val) { } + +static inline int mptcp_sock_set_syncnt (struct sock *sk,int val) +{ +return 0 ; +}#endif /* CONFIG_MPTCP */ #if IS_ENABLED (CONFIG_MPTCP_IPV6 )
net/mptcp/protocol.h +1 -0
@@ -335,6 +335,7 @@ struct mptcp_sock {int keepalive_idle;int keepalive_intvl;int maxseg; +int icsk_syn_retries;struct work_struct work;struct sk_buff *ooo_last_skb;struct rb_root out_of_order_queue;
net/mptcp/sockopt.c +25 -0
@@ -1592,6 +1592,7 @@ static void sync_socket_options(struct mptcp_sock *msk, struct sock *ssk) priority =READ_ONCE (sk->sk_priority);if (priority >0 )sock_set_priority (ssk, priority); +tcp_sock_set_syncnt (ssk, msk->icsk_syn_retries); }void mptcp_sockopt_sync_locked (struct mptcp_sock *msk,struct sock *ssk)
@@ -1743,3 +1744,27 @@ void mptcp_sock_set_tos(struct sock *sk, int val)release_sock (sk); }EXPORT_SYMBOL (mptcp_sock_set_tos); + +int mptcp_sock_set_syncnt (struct sock *sk,int val) +{ +struct mptcp_sock *msk =mptcp_sk (sk); +struct sock *ssk; +int ret =0 ; + +if (val <1 || val >MAX_TCP_SYNCNT ) +return -EINVAL ; + +lock_sock (sk); +sockopt_seq_inc (msk); + msk->icsk_syn_retries = val; + ssk =__mptcp_nmpc_sk (msk); +if (IS_ERR (ssk)) { + ret =PTR_ERR (ssk); + goto unlock; + } +tcp_sock_set_syncnt (ssk, val); +unlock: +release_sock (sk); +return ret; +} +EXPORT_SYMBOL (mptcp_sock_set_syncnt);
Signature · 1 line
2.51.0
Geliang Tang
reviewerRFC v8 7/7 selftests: mptcp: add NVMe over MPTCP test
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
A test case for NVMe over MPTCP has been implemented. It verifies the proper functionality of nvme list, discover, connect, and disconnect commands. Additionally, read/write performance has been evaluated using fio.
This test simulates four NICs on both target and host sides, each limited to 100MB/s. It shows that 'NVMe over MPTCP' delivered bandwidth up to four times that of standard TCP:
# ./mptcp_nvme.sh tcp READ: bw=112MiB/s (118MB/s), 112MiB/s-112MiB/s (118MB/s-118MB/s), io=1123MiB (1177MB), run=10018-10018msec WRITE: bw=112MiB/s (117MB/s), 112MiB/s-112MiB/s (117MB/s-117MB/s), io=1118MiB (1173MB), run=10018-10018msec
# ./mptcp_nvme.sh mptcp READ: bw=427MiB/s (448MB/s), 427MiB/s-427MiB/s (448MB/s-448MB/s), io=4286MiB (4494MB), run=10039-10039msec WRITE: bw=387MiB/s (406MB/s), 387MiB/s-387MiB/s (406MB/s-406MB/s), io=3885MiB (4073MB), run=10043-10043msec
Also add NVMe iopolicy testing to mptcp_nvme.sh, with the default set to "numa". It can be set to "round-robin" or "queue-depth".
# ./mptcp_nvme.sh mptcp round-robin
--- tools/testing/selftests/net/mptcp/Makefile | 1 + tools/testing/selftests/net/mptcp/config | 7 + .../testing/selftests/net/mptcp/mptcp_lib.sh | 12 + .../testing/selftests/net/mptcp/mptcp_nvme.sh | 240 ++++++++++++++++++ 4 files changed, 260 insertions(+) create mode 100755 tools/testing/selftests/net/mptcp/mptcp_nvme.sh
tools/testing/selftests/net/mptcp/Makefile +1 -0
@@ -13,6 +13,7 @@ TEST_PROGS := \ mptcp_connect_sendfile.sh \ mptcp_connect_splice.sh \ mptcp_join.sh \ + mptcp_nvme.sh \ mptcp_sockopt.sh \ pm_netlink.sh \ simult_flows.sh \
tools/testing/selftests/net/mptcp/config +7 -0
@@ -34,3 +34,10 @@ CONFIG_NFT_SOCKET=m CONFIG_NFT_TPROXY=m CONFIG_SYN_COOKIES=y CONFIG_VETH=y +CONFIG_CONFIGFS_FS=y +CONFIG_NVME_CORE=y +CONFIG_NVME_FABRICS=y +CONFIG_NVME_TCP=y +CONFIG_NVME_TARGET=y +CONFIG_NVME_TARGET_TCP=y +CONFIG_NVME_MULTIPATH=y
tools/testing/selftests/net/mptcp/mptcp_lib.sh +12 -0
@@ -526,6 +526,18 @@ mptcp_lib_check_tools() { exit ${KSFT_SKIP} fi ;; + "nvme") + if ! nvme --version &> /dev/null; then + mptcp_lib_pr_skip "Could not run test without nvme tool" + exit ${KSFT_SKIP} + fi + ;; + "fio") + if ! fio -h &> /dev/null; then + mptcp_lib_pr_skip "Could not run test without fio tool" + exit ${KSFT_SKIP} + fi + ;; *) mptcp_lib_pr_fail "Internal error: unsupported tool: ${tool}" exit ${KSFT_FAIL}
tools/testing/selftests/net/mptcp/mptcp_nvme.sh new file +240 -0
240 lines not on this page · raw message
Signature · 1 line
2.51.0
Hi Geliang,
Thank you for your modifications, that's great!
Our CI did some validations and here is its report:
- KVM Validation: normal (except selftest_mptcp_join): Success! ✅
- KVM Validation: normal (only selftest_mptcp_join): Success! ✅
- KVM Validation: debug (except selftest_mptcp_join): Unstable: 1 failed test(s): packetdrill_dss ⚠️
- KVM Validation: debug (only selftest_mptcp_join): Success! ✅
- KVM Validation: btf-normal (only bpftest_all): Success! ✅
- KVM Validation: btf-debug (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/23850182531
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/dd36aba092d9
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=1075844
If there are some issues, you can reproduce them using the same environment as the one used by the CI thanks to a docker image, e.g.:
$ cd [kernel source code]
$ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
--pull always mptcp/mptcp-upstream-virtme-docker:latest \
auto-normalFor more details:
https://github.com/multipath-tcp/mptcp-upstream-virtme-docker
Please note that despite all the efforts that have been already done to have a stable tests suite when executed on a public CI like here, it is possible some reported issues are not due to your modifications. Still, do not hesitate to help us improve that ;-)
Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)