NVME over MPTCP
Subsystems (5)
Geliang Tang
reviewerv14 cover NVME over MPTCP
From: Geliang Tang <[email protected]>
v14:
- Patch 1:
- Add const struct nvmet_fabrics_ops *ops back to struct nvmet_tcp_proto,
instead of using queue->port->nport->tr_ops
- Add protocol validation
"if (port->proto->protocol != newsock->sk->sk_protocol)"
when allocating a new queue - Add out_put_port label for error path cleanup
- Patch 3:
- Drop all "if (sk->sk_protocol != IPPROTO_MPTCP)" checks in MPTCP helpers
- Patch 6:
- Drop all "if (sk->sk_protocol != IPPROTO_MPTCP)" checks in MPTCP helpers
- Patch 7:
- Drop "/dev/nvme*cn1" from device discovery loop, only check "/dev/nvme*n1" to ensure fio tests multipath head device
- Per sashiko's comment, "../../../subsystems/${nqn}" does not work.
- Drop patch 12 in v13.
v13:
- Patch 1
- adds kref reference counting to struct nvmet_tcp_port
- Patch 2
- add nvmet_tcp_done_recv_pdu to use tr_ops from nport structure instead of hardcoded nvmet_tcp_ops (moved from v12 Patch 1)
- Patch 4
- split mptcp_sock_set_tos into __mptcp_sock_set_tos (internal) and mptcp_sock_set_tos (get rcv_tos from first subflow)
- add protocol validation to all MPTCP helpers
- Patch 7
- export __mptcp_sock_set_tos
- add protocol validation to mptcp_sock_set_syncnt
- Patch 12 (new)
- fix module unload race with concurrent sysfs controller deletion
v12:
- Patch 1 (new):
- Add nvmet_tcp_done_recv_pdu to use tr_ops from nport structure instead of hardcoded nvmet_tcp_ops
- Patch 2:
- Remove RCU protection for proto access
- Store proto pointer directly in struct nvmet_tcp_queue instead of struct nvmet_tcp_port
- Determine proto based on port->sock->sk->sk_protocol during queue allocation
- Delete port->proto field from struct nvmet_tcp_port
- Remove RCU annotations and rcu_dereference() for proto access
- Patch 3:
- Add nvmet_mptcp_registered flag to track successful MPTCP transport registration
- Only unregister MPTCP transport during module exit if registration succeeded
- Guard MODULE_ALIAS("nvmet-transport-4") with #ifdef CONFIG_MPTCP
- Patch 4:
- Remove unnecessary sock_hold()/sock_put() pairs in MPTCP helpers
- Remove redundant priority >= 0 check in sync_socket_options()
- Patch 8:
- Move trap cleanup EXIT before init() to ensure cleanup runs on early failure
- Export variables (nqn, path, port, etc.) immediately upon definition
- Patch 9:
- Skip iopolicy setting gracefully when iopolicy sysfs file does not exist (kernel without NVMe multipath support)
v11:
Patch 2 (new):
- Add RCU protection for host_iface validation to fix a pre-existing use-after-free issue when validating network interface names.
Patch 3:
- Add RCU protection for queue->port access in nvmet_tcp_alloc_cmd (previously missing).
- Cache proto pointer in nvmet_tcp_done_recv_pdu before releasing RCU lock.
Patch 4:
- Remove nvmet_unregister_transport(&nvmet_tcp_ops) on MPTCP registration failure (MPTCP is optional, TCP continues to work).
Patch 5:
- Update MPTCP helper functions to iterate over all subflows using mptcp_for_each_subflow().
- Add sock_hold() with explanatory comment for concurrent subflow closure protection.
- Fix priority synchronization in sync_socket_options: change condition from priority > 0 to priority >= 0 to allow priority 0.
Patch 9:
- Simplify validate_params: use regex ^[1-4]$ for path validation.
- Remove tc_args quotes in init() to allow proper word splitting for netem parameters.
v10:
Patch 1 (new):
- Add Fixes tag to the commit that checks return value of nvmet_tcp_set_queue_sock.
Patch 2:
- Fix RCU read lock release issue in nvmet_tcp_done_recv_pdu:
move rcu_read_unlock() after nvmet_req_init().
- Fix RCU read lock release issue in nvmet_tcp_set_queue_sock:
cache proto pointer before releasing RCU lock.
- Add missing NULL checks for queue->port in nvmet_tcp_alloc_cmd, nvmet_tcp_try_peek_pdu and nvmet_tcp_tls_handshake.
- Add __rcu annotation to queue->port in struct nvmet_tcp_queue.
- Use rcu_access_pointer() instead of rcu_dereference() in nvmet_tcp_destroy_port_queues.
- Remove redundant kfree_rcu() in nvmet_tcp_remove_port, use kfree() since synchronize_rcu() already guarantees safety.
Patch 4:
- Add lock_sock_nested(ssk, SINGLE_DEPTH_NESTING) to all MPTCP helpers to avoid lockdep warnings.
- Fix mptcp_sock_no_linger to properly set linger on subflow inside the lock.
Patch 8:
- Move init before trap cleanup to prevent cleanup errors when early exit occurs.
- Fix usage text: change default path value from 4 to 1 to match actual behavior.
- Fix break 2 to break (only one loop level).
Patch 9:
- Change grep -B 5 to grep (without -B) to avoid matching host NVMe devices.
v9:
Patch 1:
- add NULL pointer checks for RCU dereference in nvmet_tcp_done_recv_pdu and nvmet_tcp_set_queue_sock.
- clear queue->port using rcu_assign_pointer and add synchronize_rcu in nvmet_tcp_destroy_port_queues.
- use kfree_rcu for port structure in nvmet_tcp_remove_port.
Patch 2:
- change module init order, make MPTCP registration optional to prevent UAF.
Patch 3:
- fix mptcp_sock_set_priority to save config on main socket first, use READ_ONCE and sock_hold.
- fix mptcp_sock_no_linger to use READ_ONCE and sock_hold, call sock_no_linger on ssk.
- fix mptcp_sock_set_tos to use READ_ONCE and sock_hold.
Patch 4:
- remove unnecessary RCU protection for ctrl->proto (points to static data).
- remove rcu_head from nvme_tcp_ctrl, use kfree instead of kfree_rcu.
Patch 6:
- add msk->icsk_syn_retries check before calling tcp_sock_set_syncnt in sync_socket_options.
- fix mptcp_sock_set_syncnt to always return 0 after saving config.
Patch 7:
- split selftests into two patches.
- fix tool check order (call mptcp_lib_check_tools before temp_file creation).
- add unshare -m in cleanup to prevent configfs mount leakage.
- improve device name parsing from nvme connect output.
Patch 8:
- add iopolicy tests with set_io_policy function and error checking.
- add loss parameter for packet loss simulation (delay 5ms loss 0.5%).
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".
- Link: https://patchwork.kernel.org/project/mptcp/cover/[email protected]/
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 (10):
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
selftests: mptcp: nvme: add iopolicy tests
nvmet-tcp: check return value of set_queue_sock
nvme-tcp: add RCU protection for host_iface validation
drivers/nvme/host/tcp.c | 107 ++++- drivers/nvme/target/configfs.c | 1 + drivers/nvme/target/tcp.c | 152 ++++++- include/linux/nvme.h | 1 + include/net/mptcp.h | 31 ++ net/mptcp/sockopt.c | 151 +++++++ tools/testing/selftests/net/mptcp/Makefile | 1 + tools/testing/selftests/net/mptcp/config | 8 + .../testing/selftests/net/mptcp/mptcp_lib.sh | 12 + .../testing/selftests/net/mptcp/mptcp_nvme.sh | 399 ++++++++++++++++++ 10 files changed, 840 insertions(+), 23 deletions(-) create mode 100755 tools/testing/selftests/net/mptcp/mptcp_nvme.sh
Signature · 1 line
2.53.0
Geliang Tang
reviewerRFC v14 1/10 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 TCP-specific version of struct nvmet_tcp_proto is defined. In nvmet_tcp_add_port(), a local proto variable is set based on trtype. All locations that previously called TCP setsockopt functions are updated to call the corresponding function pointers in the nvmet_tcp_proto structure.
Add kref reference counting to struct nvmet_tcp_port to prevent use-after-free when a port is removed while queues still hold references to it. A proto field is added to struct nvmet_tcp_port, which points to the appropriate protocol structure.
Also validate that the socket protocol matches the port protocol when allocating a new queue.
--- drivers/nvme/target/tcp.c | 99 ++++++++++++++++++++++++++++++++++----- 1 file changed, 86 insertions(+), 13 deletions(-)
drivers/nvme/target/tcp.c +86 -13
@@ -198,12 +198,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); +const struct nvmet_fabrics_ops *ops; +}; +struct nvmet_tcp_port {struct socket *sock;struct work_struct accept_work;struct nvmet_port *nport; +struct kref kref;struct sockaddr_storage addr;void (*data_ready)(struct sock *); +const struct nvmet_tcp_proto *proto; };static DEFINE_IDA (nvmet_tcp_queue_ida);
@@ -1081,7 +1093,8 @@ 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))) { +if (unlikely (!nvmet_req_init (req, &queue->nvme_sq, + queue->port->proto->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,
@@ -1597,6 +1610,21 @@ static void nvmet_tcp_free_cmd_data_in_buffers(struct nvmet_tcp_queue *queue)nvmet_tcp_free_cmd_buffers (&queue->connect); } +static void nvmet_tcp_port_release (struct kref *kref) +{ +struct nvmet_tcp_port *port =container_of (kref, + struct nvmet_tcp_port, + kref); + +kfree (port); +} + +static void nvmet_tcp_port_put (struct nvmet_tcp_port *port) +{ +if (port) +kref_put (&port->kref, nvmet_tcp_port_release); +} +static void nvmet_tcp_release_queue_work (struct work_struct *w) { struct nvmet_tcp_queue *queue =
@@ -1623,6 +1651,8 @@ static void nvmet_tcp_release_queue_work(struct work_struct *w)nvmet_tcp_free_cmds (queue);ida_free (&nvmet_tcp_queue_ida, queue->idx);page_frag_cache_drain (&queue->pf_cache); +nvmet_tcp_port_put (queue->port); + queue->port =NULL ;kfree (queue); }
@@ -1696,7 +1726,6 @@ static void nvmet_tcp_state_change(struct sock *sk)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);int ret; ret = kernel_getsockname(sock,
@@ -1714,14 +1743,13 @@ static int nvmet_tcp_set_queue_sock(struct nvmet_tcp_queue *queue)* 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); + queue->port->proto->no_linger (sock->sk);if (so_priority >0 ) -sock_set_priority (sock->sk, so_priority); + queue->port->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); + queue->port->proto->set_tos (sock->sk); ret =0 ;write_lock_bh (&sock->sk->sk_callback_lock);
@@ -1904,6 +1932,13 @@ static int nvmet_tcp_tls_handshake(struct nvmet_tcp_queue *queue)static void nvmet_tcp_tls_handshake_timeout (struct work_struct *w) {}#endif +static struct nvmet_tcp_port *nvmet_tcp_port_get (struct nvmet_tcp_port *port) +{ +if (port) +kref_get (&port->kref); +return port; +} +static void nvmet_tcp_alloc_queue (struct nvmet_tcp_port *port,struct socket *newsock) {
@@ -1911,6 +1946,11 @@ static void nvmet_tcp_alloc_queue(struct nvmet_tcp_port *port,struct file *sock_file =NULL ;int ret; +if (port->proto->protocol != newsock->sk->sk_protocol) { + ret = -EINVAL ; + goto out_release; + } + queue =kzalloc_obj (*queue);if (!queue) { ret = -ENOMEM ;
@@ -1921,7 +1961,11 @@ static void nvmet_tcp_alloc_queue(struct nvmet_tcp_port *port,INIT_WORK (&queue->io_work, nvmet_tcp_io_work);kref_init (&queue->kref); queue->sock = newsock; - queue->port = port; + queue->port =nvmet_tcp_port_get (port); +if (!queue->port) { + ret = -EINVAL ; + goto out_free_queue; + } queue->nr_cmds =0 ;spin_lock_init (&queue->state_lock); if (queue->port->nport->disc_addr.tsas.tcp.sectype ==
@@ -1936,7 +1980,7 @@ static void nvmet_tcp_alloc_queue(struct nvmet_tcp_port *port, sock_file =sock_alloc_file (queue->sock,O_CLOEXEC ,NULL );if (IS_ERR (sock_file)) { ret =PTR_ERR (sock_file); - goto out_free_queue; + goto out_put_port; } queue->idx =ida_alloc (&nvmet_tcp_queue_ida,GFP_KERNEL );
@@ -1999,6 +2043,8 @@ static void nvmet_tcp_alloc_queue(struct nvmet_tcp_port *port,ida_free (&nvmet_tcp_queue_ida, queue->idx); out_sock:fput (queue->sock->file); +out_put_port: +nvmet_tcp_port_put (queue->port); out_free_queue:kfree (queue); out_release:
@@ -2041,6 +2087,24 @@ static void nvmet_tcp_listen_data_ready(struct sock *sk)read_unlock_bh (&sk->sk_callback_lock); } +static void tcp_sock_set_tos (struct sock *sk) +{ +struct inet_sock *inet =inet_sk (sk); + +if (inet->rcv_tos >0 ) +ip_sock_set_tos (sk, inet->rcv_tos); +} + +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 = tcp_sock_set_tos, + .ops = &nvmet_tcp_ops, +}; +static int nvmet_tcp_add_port (struct nvmet_port *nport) {struct nvmet_tcp_port *port;
@@ -2051,6 +2115,8 @@ static int nvmet_tcp_add_port(struct nvmet_port *nport)if (!port)return -ENOMEM ; +kref_init (&port->kref); +switch (nport->disc_addr.adrfam) {case NVMF_ADDR_FAMILY_IP4 : af =AF_INET ;
@@ -2065,6 +2131,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) {
@@ -2079,7 +2152,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;
@@ -2088,10 +2161,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));
@@ -2146,7 +2219,7 @@ static void nvmet_tcp_remove_port(struct nvmet_port *nport)nvmet_tcp_destroy_port_queues (port);sock_release (port->sock); -kfree (port); +nvmet_tcp_port_put (port); }static void nvmet_tcp_delete_ctrl (struct nvmet_ctrl *ctrl)
Signature · 1 line
2.53.0
Geliang Tang
reviewerRFC v14 2/10 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.
Note: NVMF_TRTYPE_MPTCP is temporarily assigned 4, a value currently reserved in the NVMe over Fabrics specification. A request will be submitted to the NVMe working group to officially allocate this value for MPTCP.
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 | 29 +++++++++++++++++++++++++++++ include/linux/nvme.h | 1 + 3 files changed, 31 insertions(+)
drivers/nvme/target/configfs.c +1 -0
@@ -37,6 +37,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 +29 -0
@@ -2304,6 +2304,23 @@ static const struct nvmet_fabrics_ops nvmet_tcp_ops = { .host_traddr = nvmet_tcp_host_port_addr, }; +#ifdef CONFIG_MPTCP +static bool nvmet_mptcp_registered; + +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;
@@ -2317,6 +2334,11 @@ static int __init nvmet_tcp_init(void)if (ret) goto err; +#ifdef CONFIG_MPTCP +if (!nvmet_register_transport (&nvmet_mptcp_ops)) + nvmet_mptcp_registered = true; +#endif +return 0 ; err:destroy_workqueue (nvmet_tcp_wq);
@@ -2327,6 +2349,10 @@ static void __exit nvmet_tcp_exit(void) {struct nvmet_tcp_queue *queue; +#ifdef CONFIG_MPTCP +if (nvmet_mptcp_registered) +nvmet_unregister_transport (&nvmet_mptcp_ops); +#endif nvmet_unregister_transport (&nvmet_tcp_ops);flush_workqueue (nvmet_wq);
@@ -2346,3 +2372,6 @@ 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 */ +#ifdef CONFIG_MPTCP +MODULE_ALIAS ("nvmet-transport-4" );/* 4 == NVMF_TRTYPE_MPTCP */ +#endif
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.53.0
Geliang Tang
reviewerRFC v14 3/10 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 queue->proto when the transport type is MPTCP.
Dedicated MPTCP helpers are introduced for setting socket options. Most of these helpers (set_nodelay, set_priority, no_linger, set_tos) set the values on all existing subflows using mptcp_for_each_subflow(). The set_reuseaddr helper only applies to the first subflow. 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 | 123 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 162 insertions(+)
drivers/nvme/target/tcp.c +19 -0
@@ -224,6 +224,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);
@@ -2105,6 +2108,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;
@@ -2133,6 +2148,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);#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) { }#endif /* CONFIG_MPTCP */ #if IS_ENABLED (CONFIG_MPTCP_IPV6 )
net/mptcp/sockopt.c +123 -0
132 lines not on this page · raw message
Signature · 1 line
2.53.0
Geliang Tang
reviewerRFC v14 4/10 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.
All locations that previously called TCP setsockopt functions are updated to call the corresponding function pointers in the nvme_tcp_proto structure. The controller's proto pointer is set during initialization and remains valid throughout the controller's lifetime.
--- drivers/nvme/host/tcp.c | 44 ++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-)
drivers/nvme/host/tcp.c +37 -7
@@ -182,6 +182,16 @@ 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 {/* read only in the hot path */ struct nvme_tcp_queue *queues;
@@ -198,6 +208,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);
@@ -1799,7 +1811,7 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl, int qid, ret =sock_create_kern (current->nsproxy->net_ns, ctrl->addr.ss_family,SOCK_STREAM , -IPPROTO_TCP , &queue->sock); + ctrl->proto->protocol, &queue->sock);if (ret) {dev_err (nctrl->device,"failed to create socket: %d\n" , ret);
@@ -1816,24 +1828,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 ); + ctrl->proto->set_syncnt (queue->sock->sk,1 );/* Set TCP no delay */ -tcp_sock_set_nodelay (queue->sock->sk); + ctrl->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); + ctrl->proto->no_linger (queue->sock->sk);if (so_priority >0 ) -sock_set_priority (queue->sock->sk, so_priority); + ctrl->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); + ctrl->proto->set_tos (queue->sock->sk, nctrl->opts->tos);/* Set 10 seconds timeout for icresp recvmsg */ queue->sock->sk->sk_rcvtimeo =10 *HZ ;
@@ -2900,6 +2912,17 @@ 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) {
@@ -2964,13 +2987,20 @@ static struct nvme_tcp_ctrl *nvme_tcp_alloc_ctrl(struct device *dev, goto out_free_ctrl; } +if (!strcmp (ctrl->ctrl.opts->transport,"tcp" )) { + 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.53.0
Geliang Tang
reviewerRFC v14 5/10 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 .name 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 MODULE_ALIAS("nvme-mptcp") declaration 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 | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
drivers/nvme/host/tcp.c +23 -0
@@ -3067,6 +3067,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 ;
@@ -3092,6 +3106,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 ; }
@@ -3099,6 +3116,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);
@@ -3116,3 +3136,6 @@ module_exit(nvme_tcp_cleanup_module);MODULE_DESCRIPTION ("NVMe host TCP transport driver" );MODULE_LICENSE ("GPL v2" );MODULE_ALIAS ("nvme-tcp" ); +#ifdef CONFIG_MPTCP +MODULE_ALIAS ("nvme-mptcp" ); +#endif
Signature · 1 line
2.53.0
Geliang Tang
reviewerRFC v14 6/10 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.
These helpers set the values on all existing subflows of an MPTCP connection, except for set_reuseaddr which only applies to the first subflow. The values are 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 | 11 +++++++++++ net/mptcp/sockopt.c | 30 +++++++++++++++++++++++++++++- 3 files changed, 74 insertions(+), 1 deletion(-)
drivers/nvme/host/tcp.c +34 -0
@@ -2895,6 +2895,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) {
@@ -2923,6 +2941,18 @@ static const struct nvme_tcp_proto nvme_tcp_proto = { }; +#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) {
@@ -2989,6 +3019,10 @@ static struct nvme_tcp_ctrl *nvme_tcp_alloc_ctrl(struct device *dev,if (!strcmp (ctrl->ctrl.opts->transport,"tcp" )) { ctrl->proto = &nvme_tcp_proto; +#ifdef CONFIG_MPTCP + }else if (!strcmp (ctrl->ctrl.opts->transport,"mptcp" )) { + ctrl->proto = &nvme_mptcp_proto; +#endif }else { ret = -EINVAL ; goto out_free_ctrl;
include/net/mptcp.h +11 -0
@@ -246,7 +246,11 @@ 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); +void mptcp_sock_set_tos (struct sock *sk); + +int mptcp_sock_set_syncnt (struct sock *sk,int val);#else static inline void mptcp_init (void )
@@ -342,7 +346,14 @@ 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 void mptcp_sock_set_tos (struct sock *sk) { } + +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/sockopt.c +29 -1
@@ -1598,6 +1598,8 @@ static void sync_socket_options(struct mptcp_sock *msk, struct sock *ssk)WRITE_ONCE (inet_sk (ssk)->local_port_range,READ_ONCE (inet_sk (sk)->local_port_range)); ssk->sk_reuse = sk->sk_reuse; +if (inet_csk (sk)->icsk_syn_retries >0 ) +tcp_sock_set_syncnt (ssk,inet_csk (sk)->icsk_syn_retries); }void mptcp_sockopt_sync_locked (struct mptcp_sock *msk,struct sock *ssk)
@@ -1749,7 +1751,7 @@ void mptcp_sock_no_linger(struct sock *sk) }EXPORT_SYMBOL (mptcp_sock_no_linger); -static void __mptcp_sock_set_tos (struct sock *sk,int val) +void __mptcp_sock_set_tos (struct sock *sk,int val) {struct mptcp_sock *msk =mptcp_sk (sk);struct mptcp_subflow_context *subflow;
@@ -1768,6 +1770,7 @@ static void __mptcp_sock_set_tos(struct sock *sk, int val) }release_sock (sk); } +EXPORT_SYMBOL (__mptcp_sock_set_tos);void mptcp_sock_set_tos (struct sock *sk) {
@@ -1785,3 +1788,28 @@ void mptcp_sock_set_tos(struct sock *sk)__mptcp_sock_set_tos (sk, val); }EXPORT_SYMBOL (mptcp_sock_set_tos); + +int mptcp_sock_set_syncnt (struct sock *sk,int val) +{ +struct mptcp_sock *msk =mptcp_sk (sk); +struct mptcp_subflow_context *subflow; +struct sock *ssk; + +if (val <1 || val >MAX_TCP_SYNCNT ) +return -EINVAL ; + +lock_sock (sk); +sockopt_seq_inc (msk); +inet_csk (sk)->icsk_syn_retries = val; +mptcp_for_each_subflow (msk, subflow) { + ssk =mptcp_subflow_tcp_sock (subflow); +if (ssk) { +lock_sock_nested (ssk,SINGLE_DEPTH_NESTING ); +tcp_sock_set_syncnt (ssk, val); +release_sock (ssk); + } + } +release_sock (sk); +return 0 ; +} +EXPORT_SYMBOL (mptcp_sock_set_syncnt);
Signature · 1 line
2.53.0
Geliang Tang
reviewerRFC v14 7/10 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 discover and connect commands to establish NVMe over MPTCP connections. The test then evaluates read/write performance using fio, and ensures proper cleanup with nvme disconnect.
This script accepts two positional parameters:
trtype - Transport type (mptcp|tcp). Default: mptcp
path - Number of multipath (1-4). Default: 1
This test simulates four NICs on both target and host sides, each limited to 125MB/s. It shows that 'NVMe over MPTCP' delivered bandwidth up to four times that of standard TCP with a single NVMe multipath configuration:
# ./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
It reflects that MPTCP has the same multi-interface bandwidth aggregation capability as NVMe multipath.
--- tools/testing/selftests/net/mptcp/Makefile | 1 + tools/testing/selftests/net/mptcp/config | 8 + .../testing/selftests/net/mptcp/mptcp_lib.sh | 12 + .../testing/selftests/net/mptcp/mptcp_nvme.sh | 331 ++++++++++++++++++ 4 files changed, 352 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 +8 -0
@@ -34,3 +34,11 @@ CONFIG_NFT_SOCKET=m CONFIG_NFT_TPROXY=m CONFIG_SYN_COOKIES=y CONFIG_VETH=y +CONFIG_BLK_DEV_LOOP=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
@@ -530,6 +530,18 @@ mptcp_lib_check_tools() { exit ${KSFT_SKIP} fi ;; + "nvme") + if ! nvme --version &> /dev/null; then + mptcp_lib_pr_skip "nvme tool not found" + exit ${KSFT_SKIP} + fi + ;; + "fio") + if ! fio -h &> /dev/null; then + mptcp_lib_pr_skip "fio tool not found" + 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 +331 -0
331 lines not on this page · raw message
Signature · 1 line
2.53.0
Geliang Tang
reviewerRFC v14 8/10 selftests: mptcp: nvme: add iopolicy tests
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
Add NVMe iopolicy testing to mptcp_nvme.sh, with the default set to "numa". It can be set to "round-robin" or "queue-depth".
Test results with 4 NVMe multipath paths and round-robin iopolicy show that TCP and MPTCP achieve similar bandwidth:
# ./mptcp_nvme.sh tcp 4 round-robin READ: bw=455MiB/s (478MB/s), 455MiB/s-455MiB/s (478MB/s-478MB/s), io=4665MiB (4891MB), run=10242-10242msec WRITE: bw=455MiB/s (477MB/s), 455MiB/s-455MiB/s (477MB/s-477MB/s), io=4633MiB (4858MB), run=10184-10184msec
# ./mptcp_nvme.sh mptcp 4 round-robin READ: bw=445MiB/s (466MB/s), 445MiB/s-445MiB/s (466MB/s-466MB/s), io=4575MiB (4797MB), run=10287-10287msec WRITE: bw=445MiB/s (467MB/s), 445MiB/s-445MiB/s (467MB/s-467MB/s), io=4572MiB (4794MB), run=10267-10267msec
A "loss" argument is added to simulate network packet loss. When loss=1, each veth interface is configured with "delay 5ms loss 0.5%" using tc qdisc. Under this scenario, TCP performance is reduced by multiples compared to MPTCP:
# ./mptcp_nvme.sh tcp 4 round-robin 1 READ: bw=144MiB/s (151MB/s), 144MiB/s-144MiB/s (151MB/s-151MB/s), io=1909MiB (2001MB), run=13231-13231msec WRITE: bw=100.0MiB/s (105MB/s), 100.0MiB/s-100.0MiB/s (105MB/s-105MB/s), io=1397MiB (1465MB), run=13980-13980msec
# ./mptcp_nvme.sh mptcp 4 round-robin 1 READ: bw=428MiB/s (449MB/s), 428MiB/s-428MiB/s (449MB/s-449MB/s), io=4524MiB (4743MB), run=10564-10564msec WRITE: bw=431MiB/s (452MB/s), 431MiB/s-431MiB/s (452MB/s-452MB/s), io=4513MiB (4732MB), run=10481-10481msec
These results demonstrate that MPTCP has better resilience against packet loss compared to TCP, as it can leverage multiple subflows to mitigate network degradation.
--- .../testing/selftests/net/mptcp/mptcp_nvme.sh | 70 ++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-)
tools/testing/selftests/net/mptcp/mptcp_nvme.sh +69 -1
@@ -6,6 +6,8 @@ ret=0 trtype="${1:-mptcp}" path="${2:-1}" +iopolicy=${3:-"numa"} # round-robin, queue-depth +loss=${4:-0} nqn="nqn.2014-08.org.nvmexpress.${trtype}dev.$$.${RANDOM}" ns=1 port=$((RANDOM % 10000 + 20000))
@@ -17,6 +19,7 @@ loop_dev="" export trtype path nqn ns port trsvcid export loop_dev temp_file +export iopolicy loss usage() {
@@ -24,10 +27,12 @@ usage() Usage: - $(basename "$0") [trtype] [path] + $(basename "$0") [trtype] [path] [iopolicy] [loss] trtype Transport type (tcp|mptcp) - default: mptcp path Number of multipath (1-4) - default: 1 + iopolicy I/O policy (numa|round-robin|queue-depth) - default: numa + loss Enable packet loss (0|1) - default: 0 EOF exit ${KSFT_FAIL}
@@ -44,6 +49,16 @@ validate_params() echo "Invalid path count ${path}. Must be between 1 and 4" usage fi + + if [[ ! "${iopolicy}" =~ ^(numa|round-robin|queue-depth)$ ]]; then + echo "Invalid iopolicy ${iopolicy}." + usage + fi + + if [[ ! "${loss}" =~ ^[01]$ ]]; then + echo "Invalid loss value ${loss}. Must be 0 or 1" + usage + fi } # This function is invoked indirectly
@@ -106,6 +121,7 @@ cleanup() unset -v trtype path nqn ns port trsvcid unset -v loop_dev temp_file + unset -v iopolicy loss } # $tc_args needs word splitting to pass multiple arguments to netem
@@ -114,6 +130,10 @@ init() { local tc_args="rate 1000mbit" + if [ "${loss}" -eq 1 ]; then + tc_args+=" delay 5ms loss 0.5%" + fi + mptcp_lib_ns_init ns1 ns2 # ns1 ns2
@@ -194,6 +214,48 @@ run_target() done } +# This function is invoked indirectly +#shellcheck disable=SC2317,SC2329 +set_io_policy() +{ + local nqn="$1" + local iopolicy="$2" + local subname + local policy + local current + + subname=$(nvme list-subsys 2>/dev/null | grep "${nqn}" | + grep -o 'nvme-subsys[0-9]*' | head -1) + if [ -z "$subname" ]; then + return 1 + fi + + policy="/sys/class/nvme-subsystem/${subname}/iopolicy" + if [ ! -e "$policy" ]; then + # NVMe multipath not supported, skip iopolicy setting + return 0 + fi + + if [ ! -w "$policy" ]; then + return 1 + fi + + if ! echo "${iopolicy}" > "$policy" 2>/dev/null; then + return 1 + fi + + current=$(cat "$policy" 2>/dev/null) + if [ -z "$current" ]; then + return 1 + fi + + if [[ "$current" != *"${iopolicy}"* ]]; then + return 1 + fi + + return 0 +} + # This function is invoked indirectly #shellcheck disable=SC2317,SC2329 run_host()
@@ -243,6 +305,11 @@ run_host() return 1 fi + if ! set_io_policy "${nqn}" "${iopolicy}"; then + echo "Failed to set I/O policy to ${iopolicy}" + return 1 + fi + sleep 1 echo "fio randread /dev/${devname}"
@@ -308,6 +375,7 @@ run_test() fi if ! ip netns exec "$ns2" bash <<- EOF + $(declare -f set_io_policy) $(declare -f run_host) run_host exit \$?
Signature · 1 line
2.53.0
Geliang Tang
reviewerRFC v14 9/10 nvmet-tcp: check return value of set_queue_sock
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
The return value of nvmet_tcp_set_queue_sock() is currently ignored in nvmet_tcp_tls_handshake_done(). If it fails (e.g., due to concurrent port removal), the socket callbacks will not be properly set, leading to queue and socket leakage. Fix this by capturing the return value and calling nvmet_tcp_schedule_release_queue() on failure to ensure proper cleanup.
--- drivers/nvme/target/tcp.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/nvme/target/tcp.c +3 -2
@@ -1873,10 +1873,11 @@ static void nvmet_tcp_tls_handshake_done(void *data, int status,if (!status) status =nvmet_tcp_tls_key_lookup (queue, peerid); +if (!status) + status =nvmet_tcp_set_queue_sock (queue); +if (status)nvmet_tcp_schedule_release_queue (queue); -else -nvmet_tcp_set_queue_sock (queue);kref_put (&queue->kref, nvmet_tcp_release_queue); }
Signature · 1 line
2.53.0
Geliang Tang
reviewerRFC v14 10/10 nvme-tcp: add RCU protection for host_iface validation
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
When the host_iface option is specified, nvme_tcp_alloc_ctrl() calls __dev_get_by_name() to validate the network interface exists. However, __dev_get_by_name() requires RCU read lock protection as it traverses the RCU-protected device hash table.
Without RCU read lock, the thread can be preempted during traversal. If a concurrent device unregistration occurs, the hash node can be freed via kfree_rcu() and the RCU grace period could end before the thread resumes, leading to a use-after-free when the freed memory is dereferenced.
Fix this by using dev_get_by_name_rcu() instead of __dev_get_by_name() and wrapping the lookup with rcu_read_lock()/rcu_read_unlock().
--- drivers/nvme/host/tcp.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/nvme/host/tcp.c +5 -1
@@ -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>
@@ -3004,12 +3005,15 @@ static struct nvme_tcp_ctrl *nvme_tcp_alloc_ctrl(struct device *dev, }if (opts->mask &NVMF_OPT_HOST_IFACE ) { -if (!__dev_get_by_name (&init_net, opts->host_iface)) { +rcu_read_lock (); +if (!dev_get_by_name_rcu (&init_net, opts->host_iface)) { +rcu_read_unlock ();pr_err ("invalid interface passed: %s\n" , opts->host_iface); ret = -ENODEV ; goto out_free_ctrl; } +rcu_read_unlock (); }if (!opts->duplicate_connect &&nvme_tcp_existing_controller (opts)) {
Signature · 1 line
2.53.0
Geliang Tang
reviewerHi Matt,
Not sure why, but this version didn't trigger CI and sashiko. Could you help trigger them for me?
Sorry, the version has been iterated many times, since sashiko keeps complaining.
Thanks,
-Geliang
Quoted 312 lines · Geliang Tang
From: Geliang Tang <[email protected]>
v14:
- Patch 1:
- Add const structnvmet_fabrics_ops*ops back to structnvmet_tcp_proto,
instead of usingqueue->port->nport->tr_ops
- Add protocol validation"if (port->proto->protocol != newsock->sk->sk_protocol)"when allocating a new queue
- Addout_put_portlabel for error path cleanup
- Patch 3:
- Drop all "if (sk->sk_protocol!=IPPROTO_MPTCP)" checks in MPTCP helpers
- Patch 6:
- Drop all "if (sk->sk_protocol!=IPPROTO_MPTCP)" checks in MPTCP helpers
- Patch 7:
- Drop "/dev/nvme*cn1" from device discovery loop, only check "/dev/nvme*n1" to ensure fio tests multipath head device
- Per sashiko's comment, "../../../subsystems/${nqn}" does not work.
- Drop patch 12 in v13.v13:
- Patch 1
- adds kref reference counting to structnvmet_tcp_port
- Patch 2
- addnvmet_tcp_done_recv_pduto usetr_opsfrom nport structure instead of hardcodednvmet_tcp_ops(moved from v12 Patch 1)
- Patch 4
- splitmptcp_sock_set_tosinto__mptcp_sock_set_tos(internal) and
mptcp_sock_set_tos(getrcv_tosfrom first subflow)
- add protocol validation to all MPTCP helpers
- Patch 7
- export__mptcp_sock_set_tos
- add protocol validation tomptcp_sock_set_syncnt
- Patch 12 (new)
- fix module unload race with concurrent sysfs controller deletion Link:
https://patchwork.kernel.org/project/mptcp/cover/[email protected]/v12:
- Patch 1 (new):
- Addnvmet_tcp_done_recv_pduto usetr_opsfrom nport structure instead
of hardcodednvmet_tcp_ops
- Patch 2:
- Remove RCU protection for proto access
- Store proto pointer directly in structnvmet_tcp_queueinstead of
structnvmet_tcp_port
- Determine proto based onport->sock->sk->sk_protocolduring queue
allocation
- Deleteport->protofield from structnvmet_tcp_port
- Remove RCU annotations andrcu_dereference()for proto access
- Patch 3:
- Addnvmet_mptcp_registeredflag to track successful MPTCP transport
registration
- Only unregister MPTCP transport during module exit if registration
succeeded
- GuardMODULE_ALIAS("nvmet-transport-4")with #ifdefCONFIG_MPTCP
- Patch 4:
- Remove unnecessary sock_hold()/sock_put() pairs in MPTCP helpers
- Remove redundant priority >= 0 check insync_socket_options()
- Patch 8:
- Move trap cleanup EXIT beforeinit()to ensure cleanup runs on early
failure
- Export variables (nqn, path, port, etc.) immediately upon definition
- Patch 9:
- Skip iopolicy setting gracefully when iopolicy sysfs file does not
exist (kernel without NVMe multipath support)
Link:
https://patchwork.kernel.org/project/mptcp/cover/[email protected]/v11:
Patch 2 (new):
- Add RCU protection forhost_ifacevalidation to fix a pre-existing use-after-free issue when validating network interface names. Patch 3:
- Add RCU protection forqueue->portaccess innvmet_tcp_alloc_cmd(previously missing).
- Cache proto pointer innvmet_tcp_done_recv_pdubefore releasing RCU lock.
Patch 4:
- Removenvmet_unregister_transport(&nvmet_tcp_ops)on MPTCP registration
failure (MPTCP is optional, TCP continues to work). Patch 5:
- Update MPTCP helper functions to iterate over all subflows usingmptcp_for_each_subflow().
- Addsock_hold()with explanatory comment for concurrent subflow closure
protection.
- Fix priority synchronization insync_socket_options: change condition
from priority > 0 to priority >= 0 to allow priority 0. Patch 9:
- Simplifyvalidate_params: use regex ^[1-4]$ for path validation.
- Removetc_argsquotes ininit()to allow proper word splitting for netem
parameters.
Link:
https://patchwork.kernel.org/project/mptcp/cover/[email protected]/v10:
Patch 1 (new):
- Add Fixes tag to the commit that checks return value ofnvmet_tcp_set_queue_sock.
Patch 2:
- Fix RCU read lock release issue innvmet_tcp_done_recv_pdu:
movercu_read_unlock()afternvmet_req_init().
- Fix RCU read lock release issue innvmet_tcp_set_queue_sock:
cache proto pointer before releasing RCU lock.
- Add missing NULL checks forqueue->portinnvmet_tcp_alloc_cmd,nvmet_tcp_try_peek_pduandnvmet_tcp_tls_handshake.
- Add__rcuannotation toqueue->portin structnvmet_tcp_queue.
- Usercu_access_pointer()instead ofrcu_dereference()innvmet_tcp_destroy_port_queues.
- Remove redundantkfree_rcu()innvmet_tcp_remove_port, usekfree()sincesynchronize_rcu()already guarantees safety. Patch 4:
- Addlock_sock_nested(ssk, SINGLE_DEPTH_NESTING)to all MPTCP helpers
to avoid lockdep warnings.
- Fixmptcp_sock_no_lingerto properly set linger on subflow inside the
lock.
Patch 8:
- Move init before trap cleanup to prevent cleanup errors when early exit occurs.
- Fix usage text: change default path value from 4 to 1 to match actual
behavior.
- Fix break 2 to break (only one loop level).
Patch 9:
- Change grep -B 5 to grep (without -B) to avoid matching host NVMe devices.
Link:
https://patchwork.kernel.org/project/mptcp/cover/[email protected]/v9:
Patch 1:
- add NULL pointer checks for RCU dereference innvmet_tcp_done_recv_pdu
andnvmet_tcp_set_queue_sock.
- clearqueue->portusingrcu_assign_pointerand addsynchronize_rcuin
nvmet_tcp_destroy_port_queues.
- usekfree_rcufor port structure innvmet_tcp_remove_port. Patch 2:
- change module init order, make MPTCP registration optional to prevent
UAF.
Patch 3:
- fixmptcp_sock_set_priorityto save config on main socket first, use
READ_ONCEandsock_hold.
- fixmptcp_sock_no_lingerto useREAD_ONCEandsock_hold, callsock_no_lingeron ssk.
- fixmptcp_sock_set_tosto useREAD_ONCEandsock_hold. Patch 4:
- remove unnecessary RCU protection forctrl->proto(points to static
data).
- removercu_headfromnvme_tcp_ctrl, use kfree instead ofkfree_rcu.
Patch 6:
- addmsk->icsk_syn_retriescheck before callingtcp_sock_set_syncntin
sync_socket_options.
- fixmptcp_sock_set_syncntto always return 0 after saving config. Patch 7:
- split selftests into two patches.
- fix tool check order (callmptcp_lib_check_toolsbeforetemp_filecreation).
- add unshare -m in cleanup to prevent configfs mount leakage.
- improve device name parsing from nvme connect output. Patch 8:
- add iopolicy tests withset_io_policyfunction and error checking.
- add loss parameter for packet loss simulation (delay 5ms loss 0.5%).
Link:
https://patchwork.kernel.org/project/mptcp/cover/[email protected]/v8:
- address comments reported by ai-review for v7.
- add RCU protection forqueue->porton target side.
- add RCU protectionctrl->protoon host side.
- check !msk->first instead of "IS_ERR(msk->first)".
- fix return value ofmptcp_sock_set_syncnt.
- update selftest.
- fix CI error: "[SKIP] Could not run all tests without nvme".
- Link:
https://patchwork.kernel.org/project/mptcp/cover/[email protected]/v7:
- address comments reported by ai-review.
- change sockops innvmet_tcp_portandnvme_tcp_ctrlas a pointer.
- add null checks forqueue->port->sockopsinnvmet_tcp_set_queue_sock.
- add inline formptcp_sock_set_priorityandmptcp_sock_set_tosinmptcp.h
- use "ssk =msk->first" instead of "ssk =__mptcp_nmpc_sk(msk)" inmptcp_sock_set_priority,mptcp_sock_no_lingerandmptcp_sock_set_tos.
- dropsk_is_tcpinnvmet_tcp_done_recv_pdu
- movectrl->sockopssetting beforenvme_init_ctrlinnvme_tcp_alloc_ctrl
- definenvme_mptcp_ctrl_ops
- addMODULE_ALIAS("nvme-mptcp")
- add moreCONFIG_MPTCPchecks
- update selftest
- Link:
https://patchwork.kernel.org/project/mptcp/cover/[email protected]/v6:
- introducenvmet_tcp_sockopsandnvme_tcp_sockopsstructures
- fixset_reuseaddr,set_nodelayandset_syncnt, addsockopt_seq_inccalls, only set the first subflow, and synchronize to other subflows in
sync_socket_options
- Add implementations forno_linger,set_priorityandset_tos
- This version no longer depends on the "mptcp: fix stall because ofdata_ready" series of fixes
- Link:
https://patchwork.kernel.org/project/mptcp/cover/[email protected]/v5:
- address comments reported by ai-review: setmsk->nodelayto true in
mptcp_sock_set_nodelay, setsk->sk_reusetossk->sk_reuseinmptcp_sock_set_reuseaddr, addmptcp_nvme.shtoTEST_PROGS, and adjust
the order of patches.
- remove TLS-related options from .allowed_opts ofnvme_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 ofsock_set_nodelay: originally it only set
the first subflow, but now it sets every subflow.
- usesk_is_mskhelper 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-specificsock_set_syncnthelper.
- 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 mptcpread_sock" series to the main MPTCP repository, which has
been merged into net-next recently.Geliang Tang (10):
nvmet-tcp: define targettcp_protostruct
nvmet-tcp: register target mptcp transport
nvmet-tcp: implement target mptcp proto
nvme-tcp: define hosttcp_protostruct
nvme-tcp: register host mptcp transport
nvme-tcp: implement host mptcp proto
selftests: mptcp: add nvme over mptcp test
selftests: mptcp: nvme: add iopolicy tests
nvmet-tcp: check return value ofset_queue_sock
nvme-tcp: add RCU protection forhost_ifacevalidationdrivers/nvme/host/tcp.c | 107 ++++- drivers/nvme/target/configfs.c | 1 + drivers/nvme/target/tcp.c | 152 ++++++- include/linux/nvme.h | 1 + include/net/mptcp.h | 31 ++ net/mptcp/sockopt.c | 151 +++++++ tools/testing/selftests/net/mptcp/Makefile | 1 + tools/testing/selftests/net/mptcp/config | 8 + .../testing/selftests/net/mptcp/mptcp_lib.sh | 12 +
.../testing/selftests/net/mptcp/mptcp_nvme.sh| 399
++++++++++++++++++10 files changed, 840 insertions(+), 23 deletions(-)create mode 100755
tools/testing/selftests/net/mptcp/mptcp_nvme.sh
Matthieu Baerts
maintainerHi Geliang,
19 May 2026 17:43:06 Geliang Tang <[email protected]>:
Quoted 2 lines
Not sure why, but this version didn't trigger CI and sashiko. Could you help trigger them for me?
It looks like patchew is missing one patch:
https://patchew.org/MPTCP/[email protected]/
Not sure why, I received it.
But sashiko did a review:
https://sashiko.dev/#/patchset/cover.1779159524.git.tanggeliang%40kylinos.cn
I can force the CI to run when I'm back on my computer, if you still need the CI.
Quoted 2 lines
Sorry, the version has been iterated many times, since sashiko keeps complaining.
Are these complains often correct? If not, simply reply on the mailing list. Or add a note in the commit message.
Cheers,
Matt
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/26123437144
Initiator: Matthieu Baerts (NGI0)
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/c19be69b7661
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=1097007
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)