From nobody Mon May 25 18:05:05 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D1F9C36AF6 for ; Sun, 17 May 2026 06:06:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778997976; cv=none; b=vEoGvzko5RSb5lcYNPmlwZO9sN+/QKBEYTCGnJGIUGFzdBgIZkkwUxOJr3QoAtNl5PQ/fFYd81O0KsdMmoQpVF8Y+UPfzuEyaHp6MUd0iWg+NKTevQQV+n0tcNtJfS3VAwFCUWwJ6BmqJHqEnn/5loVdEwy4fTb7zbq7a1C7qBw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778997976; c=relaxed/simple; bh=UMbv0kJDGb4DqzP57rJf1RO7F6wW9TMuOGWKszzTj/o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Wttfz6bdxHXCUAEJKNAR8KwC3RNqOnUOQJ5igOYHTM4aPY/VasWxkcfiipELt+W/sKcd4C+EffGdgsEDol2a9dMYE3xXYT6pAu7tfkRQ6EyA+kI7rDANG+wZI/frHOgF2gMQ9G2mBWOGppGPhE6BzdBAaix1s2PRZHLMJ8r/snc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qMJtl8mL; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="qMJtl8mL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B8523C2BCB0; Sun, 17 May 2026 06:06:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778997976; bh=UMbv0kJDGb4DqzP57rJf1RO7F6wW9TMuOGWKszzTj/o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qMJtl8mLv7l0O6+20+5RivbCxRAY9IIhukn0WmQnfQjseyVXW1hasnuhIGYr3N6Ro TiXufoXeb9R5Z5VyLM8hR/PnTLmY+yCuCPjoa4n8Lf9vszlDNGJ/FFbIAt218I9J29 9OYd7JH5yJuaJGNosF+9G6W6RKXFQXSu9xkLZlm5GKWR5in9hyDznMtBWf+2vUIG72 HWMxCgWPdKKXfVxQMLVIzm0bhiGTIDBEfi3yxB1SEPX17GWkGc4sGsSMocckuxRteQ er+pKdXe1451GDAevYbZxsUblZ8QAYKwx41sDXn2Pr82fsKHb9zZ5SaexKOPtu4PRL FC7tw8u0Nsu3Q== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Hannes Reinecke , zhenwei pi , Hui Zhu , Gang Yan Subject: [RFC mptcp-next v11 01/10] nvmet-tcp: check return value of set_queue_sock Date: Sun, 17 May 2026 14:05:05 +0800 Message-ID: <6fe186acd68e1083e32fda1037f710f42539e660.1778997507.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang 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. Cc: Hannes Reinecke Cc: zhenwei pi Cc: Hui Zhu Cc: Gang Yan Fixes: 675b453e0241 ("nvmet-tcp: enable TLS handshake upcall") Signed-off-by: Geliang Tang --- drivers/nvme/target/tcp.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/nvme/target/tcp.c b/drivers/nvme/target/tcp.c index 164a564ba3b4..8a243d22a511 100644 --- a/drivers/nvme/target/tcp.c +++ b/drivers/nvme/target/tcp.c @@ -1842,10 +1842,11 @@ static void nvmet_tcp_tls_handshake_done(void *data= , int status, if (!status) status =3D nvmet_tcp_tls_key_lookup(queue, peerid); =20 + if (!status) + status =3D 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); } =20 --=20 2.53.0 From nobody Mon May 25 18:05:05 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EC14C30DD2F for ; Sun, 17 May 2026 06:06:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778997979; cv=none; b=fqDaeDqhPtuh+IjKmzbebo8UXiHaE1OiT3+Gsbg68bppQQbW8Lq5WzPMZevJI/17VhhGxNB/VQ1KuecV0PvKCODtBaTrDr2U0qA8nGkzsTGMwgwTMnyFnSnl4WK0SQeDbDpROQSkuiIpon9EOXHKJ/faxTEXhW2nnlMoRIFWv24= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778997979; c=relaxed/simple; bh=0/1qDpnrEASKTyamgrZq3hiktwpNCegwlvl5LllEwVY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y66W2iBO73Q+8Y7ezP+APBGrrKtaOUq7qIv0pz+M4uUDTR1gCawz4WFv/WWTvB5oFCHQSsbTj7tKbSBZhcVDTy9nPjC6rxu8O9673RabFaM1/RKhK2VeK9TLA/STNe5BPREbLP5Ng5bjqiRPHkG3KDVbauX/mf9NyD4GXW2JBnA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AOnh59CI; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="AOnh59CI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 20A7BC2BCB3; Sun, 17 May 2026 06:06:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778997978; bh=0/1qDpnrEASKTyamgrZq3hiktwpNCegwlvl5LllEwVY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AOnh59CILpr7Akcfzk7nJz0jMoqtBZq0Zxn9zWjQ+XwMX/Mwtw7UbgcWa6FfgfbP/ c0+pXRNX0rCD1bFZV2nUPJt10R0Yp7HWqdcuoqOiBf1nLZlYXEjorPvCuZ2nQQ3KaN b2+DTWa73/QAEN0VL5ZQC6eckvk4WYDBtlTHpfDxUzyANo+yZAFUFuJ8lftswIbRt6 4Ma6Cvu/JBbXgdKAoAdCl5IzEp9iAEblNZGStOCY8PQw32pTWGhNPJ+ZOCRsaKwXpW YeyNS0nS9hKtfLcJJpi8iF32oAdqMDS/0uukU6Fi6HYBOFb4el2NO+XAaxClTXeTPv PyoKmuByUYmzQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Hannes Reinecke , zhenwei pi , Hui Zhu , Gang Yan Subject: [RFC mptcp-next v11 02/10] nvme-tcp: add RCU protection for host_iface validation Date: Sun, 17 May 2026 14:05:06 +0800 Message-ID: X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang 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(). Cc: Hannes Reinecke Cc: zhenwei pi Cc: Hui Zhu Cc: Gang Yan Fixes: 3ede8f72a9a2 ("nvme-tcp: allow selecting the network interface for c= onnections") Signed-off-by: Geliang Tang --- drivers/nvme/host/tcp.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c index 15d36d6a728e..d1654a630897 100644 --- a/drivers/nvme/host/tcp.c +++ b/drivers/nvme/host/tcp.c @@ -2951,12 +2951,15 @@ static struct nvme_tcp_ctrl *nvme_tcp_alloc_ctrl(st= ruct device *dev, } =20 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 =3D -ENODEV; goto out_free_ctrl; } + rcu_read_unlock(); } =20 if (!opts->duplicate_connect && nvme_tcp_existing_controller(opts)) { --=20 2.53.0 From nobody Mon May 25 18:05:05 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3FF0536AF6 for ; Sun, 17 May 2026 06:06:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778997981; cv=none; b=RkvscHSCSEr3ILEZ6A6lHN9/5Md0DPLoNSIJpkPD1YTb7ePLmyDhhGAZ9gKwVNamZHK7NoRpGkIemWOCJvKJFZV84e6qfww1WyJ+h2EKSsLj1VVvqKrIm+6A9F1ITrLInEDz/OfuK2F8YqURfitXe3FCTL3Y0iKVWjYOAOfk3lk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778997981; c=relaxed/simple; bh=psEx0nb4bCMLmQGIAUSIXx9YeRyZNf2fNRG/If0FBwE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YW/gIeXrPP81LV21FEI1W2tssfQjoP9PPp0D4TqAT/3FdPkbsM9emOhbNMfNg4N6Li7MtXyqtBw9J0YZTVLs35xt0WwmSDEE1D0papfKGXnlDVfSuRkTJsstdg8Fdmg5FNCn+mk9H4Nk7iDrJxU9KYtD6DPeZ2cSqyGf6wfE6aE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lIASKMR8; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lIASKMR8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3BD46C2BCF6; Sun, 17 May 2026 06:06:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778997980; bh=psEx0nb4bCMLmQGIAUSIXx9YeRyZNf2fNRG/If0FBwE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lIASKMR8VmLyHsKLYzvP6ju9DFBnlWIB5VI8BWsCzEiytwhxKcZmjzgjpjSR4A8on zLxgClO1xtarjoXpuYKdWFJUkNzuxMwHO3Wpdg/DR9wXYAL9HMk244H3bkb5BfTAck YCvWQtCvaJPvmutC+/eBfaudnJwvrCknRtf2XP/Wggcwb4BZF3PPnWQQ3QSGA8q/Sv MwE5Rt5VI5CiUF/bqJwlX+ZbV8Pn4rw51VoAw7DC23k/nlRPhRzv0DWeC815a5CW6r ZIqUy5jYsg5sCUW+ppHymUcrRwdJ4uS0OOxyope3+rXHw3OjEazBoYHahFMGiSB2cf NzK2VVkmHWGAw== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Hannes Reinecke , zhenwei pi , Hui Zhu , Gang Yan Subject: [RFC mptcp-next v11 03/10] nvmet-tcp: define target tcp_proto struct Date: Sun, 17 May 2026 14:05:07 +0800 Message-ID: <51260b7724246471d5147c05ec8e620094561ec8.1778997507.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang 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 to prevent use-after-free when a port is removed while asynchronous operations are pending. The queue->port pointer is cleared using RCU assignment and synchronized with RCU grace period, and the port structure is then released after all RCU readers have completed. Note: This is not a bug fix; it is a preparatory change for MPTCP support. The RCU conversion makes the code consistent with the __rcu annotation introduced here, and does not address any existing issue. Cc: Hannes Reinecke Co-developed-by: zhenwei pi Signed-off-by: zhenwei pi Co-developed-by: Hui Zhu Signed-off-by: Hui Zhu Co-developed-by: Gang Yan Signed-off-by: Gang Yan Signed-off-by: Geliang Tang --- drivers/nvme/target/tcp.c | 114 +++++++++++++++++++++++++++++++++----- 1 file changed, 100 insertions(+), 14 deletions(-) diff --git a/drivers/nvme/target/tcp.c b/drivers/nvme/target/tcp.c index 8a243d22a511..20b7b5447cfc 100644 --- a/drivers/nvme/target/tcp.c +++ b/drivers/nvme/target/tcp.c @@ -18,6 +18,7 @@ #include #include #include +#include #include =20 #include "nvmet.h" @@ -147,7 +148,7 @@ enum nvmet_tcp_queue_state { =20 struct nvmet_tcp_queue { struct socket *sock; - struct nvmet_tcp_port *port; + struct nvmet_tcp_port __rcu *port; struct work_struct io_work; struct nvmet_cq nvme_cq; struct nvmet_sq nvme_sq; @@ -198,12 +199,23 @@ struct nvmet_tcp_queue { void (*write_space)(struct sock *); }; =20 +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 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; }; =20 static DEFINE_IDA(nvmet_tcp_queue_ida); @@ -1044,6 +1056,8 @@ static int nvmet_tcp_done_recv_pdu(struct nvmet_tcp_q= ueue *queue) { struct nvme_tcp_hdr *hdr =3D &queue->pdu.cmd.hdr; struct nvme_command *nvme_cmd =3D &queue->pdu.cmd.cmd; + const struct nvmet_tcp_proto *proto; + struct nvmet_tcp_port *port; struct nvmet_req *req; int ret; =20 @@ -1081,7 +1095,16 @@ static int nvmet_tcp_done_recv_pdu(struct nvmet_tcp_= queue *queue) req =3D &queue->cmd->req; memcpy(req->cmd, nvme_cmd, sizeof(*nvme_cmd)); =20 - if (unlikely(!nvmet_req_init(req, &queue->nvme_sq, &nvmet_tcp_ops))) { + rcu_read_lock(); + port =3D rcu_dereference(queue->port); + if (!port || !port->proto) { + rcu_read_unlock(); + return -EINVAL; + } + proto =3D port->proto; + rcu_read_unlock(); + + if (unlikely(!nvmet_req_init(req, &queue->nvme_sq, 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, @@ -1466,9 +1489,17 @@ static int nvmet_tcp_alloc_cmd(struct nvmet_tcp_queu= e *queue, struct nvmet_tcp_cmd *c) { u8 hdgst =3D nvmet_tcp_hdgst_len(queue); + struct nvmet_tcp_port *port; =20 c->queue =3D queue; - c->req.port =3D queue->port->nport; + rcu_read_lock(); + port =3D rcu_dereference(queue->port); + if (!port || !port->nport) { + rcu_read_unlock(); + return -EINVAL; + } + c->req.port =3D port->nport; + rcu_read_unlock(); =20 c->cmd_pdu =3D page_frag_alloc(&queue->pf_cache, sizeof(*c->cmd_pdu) + hdgst, GFP_KERNEL | __GFP_ZERO); @@ -1697,6 +1728,8 @@ static int nvmet_tcp_set_queue_sock(struct nvmet_tcp_= queue *queue) { struct socket *sock =3D queue->sock; struct inet_sock *inet =3D inet_sk(sock->sk); + const struct nvmet_tcp_proto *proto; + struct nvmet_tcp_port *port; int ret; =20 ret =3D kernel_getsockname(sock, @@ -1709,19 +1742,29 @@ static int nvmet_tcp_set_queue_sock(struct nvmet_tc= p_queue *queue) if (ret < 0) return ret; =20 + rcu_read_lock(); + port =3D rcu_dereference(queue->port); + if (!port || !port->proto || + port->proto->protocol !=3D sock->sk->sk_protocol) { + rcu_read_unlock(); + return -EINVAL; + } + proto =3D 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); =20 if (so_priority > 0) - sock_set_priority(sock->sk, so_priority); + proto->set_priority(sock->sk, so_priority); =20 /* 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); =20 ret =3D 0; write_lock_bh(&sock->sk->sk_callback_lock); @@ -1752,6 +1795,7 @@ static int nvmet_tcp_set_queue_sock(struct nvmet_tcp_= queue *queue) static int nvmet_tcp_try_peek_pdu(struct nvmet_tcp_queue *queue) { struct nvme_tcp_hdr *hdr =3D &queue->pdu.cmd.hdr; + struct nvmet_tcp_port *port; int len, ret; struct kvec iov =3D { .iov_base =3D (u8 *)&queue->pdu + queue->offset, @@ -1764,8 +1808,18 @@ static int nvmet_tcp_try_peek_pdu(struct nvmet_tcp_q= ueue *queue) .msg_flags =3D MSG_PEEK, }; =20 - if (nvmet_port_secure_channel_required(queue->port->nport)) + rcu_read_lock(); + port =3D rcu_dereference(queue->port); + if (!port || !port->nport) { + rcu_read_unlock(); + return 0; + } + + if (nvmet_port_secure_channel_required(port->nport)) { + rcu_read_unlock(); return 0; + } + rcu_read_unlock(); =20 len =3D kernel_recvmsg(queue->sock, &msg, &iov, 1, iov.iov_len, msg.msg_flags); @@ -1876,19 +1930,30 @@ static int nvmet_tcp_tls_handshake(struct nvmet_tcp= _queue *queue) { int ret =3D -EOPNOTSUPP; struct tls_handshake_args args; + struct nvmet_tcp_port *port; + key_serial_t keyring; =20 if (queue->state !=3D NVMET_TCP_Q_TLS_HANDSHAKE) { pr_warn("cannot start TLS in state %d\n", queue->state); return -EINVAL; } =20 + rcu_read_lock(); + port =3D rcu_dereference(queue->port); + if (!port || !port->nport || !port->nport->keyring) { + rcu_read_unlock(); + return -EINVAL; + } + keyring =3D key_serial(port->nport->keyring); + rcu_read_unlock(); + kref_get(&queue->kref); pr_debug("queue %d: TLS ServerHello\n", queue->idx); memset(&args, 0, sizeof(args)); args.ta_sock =3D queue->sock; args.ta_done =3D nvmet_tcp_tls_handshake_done; args.ta_data =3D queue; - args.ta_keyring =3D key_serial(queue->port->nport->keyring); + args.ta_keyring =3D keyring; args.ta_timeout_ms =3D tls_handshake_timeout * 1000; =20 ret =3D tls_server_hello_psk(&args, GFP_KERNEL); @@ -2042,6 +2107,16 @@ static void nvmet_tcp_listen_data_ready(struct sock = *sk) read_unlock_bh(&sk->sk_callback_lock); } =20 +static const struct nvmet_tcp_proto nvmet_tcp_proto =3D { + .protocol =3D IPPROTO_TCP, + .set_reuseaddr =3D sock_set_reuseaddr, + .set_nodelay =3D tcp_sock_set_nodelay, + .set_priority =3D sock_set_priority, + .no_linger =3D sock_no_linger, + .set_tos =3D ip_sock_set_tos, + .ops =3D &nvmet_tcp_ops, +}; + static int nvmet_tcp_add_port(struct nvmet_port *nport) { struct nvmet_tcp_port *port; @@ -2066,6 +2141,13 @@ static int nvmet_tcp_add_port(struct nvmet_port *npo= rt) goto err_port; } =20 + if (nport->disc_addr.trtype =3D=3D NVMF_TRTYPE_TCP) { + port->proto =3D &nvmet_tcp_proto; + } else { + ret =3D -EINVAL; + goto err_port; + } + ret =3D inet_pton_with_scope(&init_net, af, nport->disc_addr.traddr, nport->disc_addr.trsvcid, &port->addr); if (ret) { @@ -2080,7 +2162,7 @@ static int nvmet_tcp_add_port(struct nvmet_port *npor= t) port->nport->inline_data_size =3D NVMET_TCP_DEF_INLINE_DATA_SIZE; =20 ret =3D 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; @@ -2089,10 +2171,10 @@ static int nvmet_tcp_add_port(struct nvmet_port *np= ort) port->sock->sk->sk_user_data =3D port; port->data_ready =3D port->sock->sk->sk_data_ready; port->sock->sk->sk_data_ready =3D 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); =20 ret =3D kernel_bind(port->sock, (struct sockaddr_unsized *)&port->addr, sizeof(port->addr)); @@ -2125,10 +2207,14 @@ static void nvmet_tcp_destroy_port_queues(struct nv= met_tcp_port *port) struct nvmet_tcp_queue *queue; =20 mutex_lock(&nvmet_tcp_queue_mutex); - list_for_each_entry(queue, &nvmet_tcp_queue_list, queue_list) - if (queue->port =3D=3D port) + list_for_each_entry(queue, &nvmet_tcp_queue_list, queue_list) { + if (rcu_access_pointer(queue->port) =3D=3D port) { + rcu_assign_pointer(queue->port, NULL); kernel_sock_shutdown(queue->sock, SHUT_RDWR); + } + } mutex_unlock(&nvmet_tcp_queue_mutex); + synchronize_rcu(); } =20 static void nvmet_tcp_remove_port(struct nvmet_port *nport) --=20 2.53.0 From nobody Mon May 25 18:05:05 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 36B992E1EFC for ; Sun, 17 May 2026 06:06:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778997983; cv=none; b=ejUMLetsyS3Y81F4JTLLW2O3f4lOF+gP6c09TI4LQ59Vb+1Z1UiFAc0pfaFiDfUnrVwm6+UTV7M/mLY8vvx+y0pwLGjQoZUuhWyXgSptrnIvzQUKBOlpoyB72nYVbTzwTmbByN+3O4vRcbA3r6uIEzteF4XqLyUNjUjDzl5txs8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778997983; c=relaxed/simple; bh=U6rCXeywXBBtjwzxOPtOmwBbkEGM5kP0MytkDdnsvKw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=muqkTZUcJrQLnyICtiPJr58ypbuL9bBinxdFWwyetHV72mfCBC8V7sYahNcI0F2aiUe9pezVjRButsxQIlFQ9SwJM9wJuuVQbN06qTT74ij/XDuj1SBSXme3pa3LH1pbcL2uAo7J5z/jPp9iJWoRGUIZsuGsuFtbtH7MlCB6ec0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=O/6UobvK; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="O/6UobvK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 65D8EC2BCB0; Sun, 17 May 2026 06:06:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778997983; bh=U6rCXeywXBBtjwzxOPtOmwBbkEGM5kP0MytkDdnsvKw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O/6UobvKypTtA1oJ+c36M4DkqNF4RKUAPeC5IPLaiyELvbvTIeR/j4GnLcg3/cRvW dAiclCtq3ZxU8IpZOnM7Y2XQaeOSm9h7ZZ/nAsn6wSdZIWpDwoq9lcNY9CaZjAU1qj /y0JjzQc/tTeGOavdfIu3nwLzOBTXO4/Sg6rNziDGuy4YhKt/GkQAEgKIdgWRtrm01 t8kbI11yAxcd+p0tddqTR/qGdc/j2Wx0MPkcrHMCf6/ChTEmUV0Q2+C8gxItohasDn EfgfTr8TWmwQeX+7Mns1cLHcnszmHMjL05x0/tFk2HCHVSLmBdBnqP6saao/WBJ+SH 6Ml39W5nWvoLQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Hannes Reinecke , zhenwei pi , Hui Zhu , Gang Yan Subject: [RFC mptcp-next v11 04/10] nvmet-tcp: register target mptcp transport Date: Sun, 17 May 2026 14:05:08 +0800 Message-ID: <5a5c6763cbe82f0cc29258390486105e03b45c8b.1778997507.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang 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. Cc: Hannes Reinecke Co-developed-by: zhenwei pi Signed-off-by: zhenwei pi Co-developed-by: Hui Zhu Signed-off-by: Hui Zhu Co-developed-by: Gang Yan Signed-off-by: Gang Yan Signed-off-by: Geliang Tang --- drivers/nvme/target/configfs.c | 1 + drivers/nvme/target/tcp.c | 24 ++++++++++++++++++++++++ include/linux/nvme.h | 1 + 3 files changed, 26 insertions(+) diff --git a/drivers/nvme/target/configfs.c b/drivers/nvme/target/configfs.c index b88f897f06e2..51fc0f4d0c32 100644 --- a/drivers/nvme/target/configfs.c +++ b/drivers/nvme/target/configfs.c @@ -37,6 +37,7 @@ static struct nvmet_type_name_map nvmet_transport[] =3D { { NVMF_TRTYPE_RDMA, "rdma" }, { NVMF_TRTYPE_FC, "fc" }, { NVMF_TRTYPE_TCP, "tcp" }, + { NVMF_TRTYPE_MPTCP, "mptcp" }, { NVMF_TRTYPE_PCI, "pci" }, { NVMF_TRTYPE_LOOP, "loop" }, }; diff --git a/drivers/nvme/target/tcp.c b/drivers/nvme/target/tcp.c index 20b7b5447cfc..3ff5deac6779 100644 --- a/drivers/nvme/target/tcp.c +++ b/drivers/nvme/target/tcp.c @@ -2318,6 +2318,21 @@ static const struct nvmet_fabrics_ops nvmet_tcp_ops = =3D { .host_traddr =3D nvmet_tcp_host_port_addr, }; =20 +#ifdef CONFIG_MPTCP +static const struct nvmet_fabrics_ops nvmet_mptcp_ops =3D { + .owner =3D THIS_MODULE, + .type =3D NVMF_TRTYPE_MPTCP, + .msdbd =3D 1, + .add_port =3D nvmet_tcp_add_port, + .remove_port =3D nvmet_tcp_remove_port, + .queue_response =3D nvmet_tcp_queue_response, + .delete_ctrl =3D nvmet_tcp_delete_ctrl, + .install_queue =3D nvmet_tcp_install_queue, + .disc_traddr =3D nvmet_tcp_disc_port_addr, + .host_traddr =3D nvmet_tcp_host_port_addr, +}; +#endif + static int __init nvmet_tcp_init(void) { int ret; @@ -2331,6 +2346,11 @@ static int __init nvmet_tcp_init(void) if (ret) goto err; =20 +#ifdef CONFIG_MPTCP + if (nvmet_register_transport(&nvmet_mptcp_ops)) + pr_warn("MPTCP transport not available (TCP only)\n"); +#endif + return 0; err: destroy_workqueue(nvmet_tcp_wq); @@ -2341,6 +2361,9 @@ static void __exit nvmet_tcp_exit(void) { struct nvmet_tcp_queue *queue; =20 +#ifdef CONFIG_MPTCP + nvmet_unregister_transport(&nvmet_mptcp_ops); +#endif nvmet_unregister_transport(&nvmet_tcp_ops); =20 flush_workqueue(nvmet_wq); @@ -2360,3 +2383,4 @@ module_exit(nvmet_tcp_exit); MODULE_DESCRIPTION("NVMe target TCP transport driver"); MODULE_LICENSE("GPL v2"); MODULE_ALIAS("nvmet-transport-3"); /* 3 =3D=3D NVMF_TRTYPE_TCP */ +MODULE_ALIAS("nvmet-transport-4"); /* 4 =3D=3D NVMF_TRTYPE_MPTCP */ diff --git a/include/linux/nvme.h b/include/linux/nvme.h index 041f30931a90..0eada1e0c652 100644 --- a/include/linux/nvme.h +++ b/include/linux/nvme.h @@ -68,6 +68,7 @@ enum { NVMF_TRTYPE_RDMA =3D 1, /* RDMA */ NVMF_TRTYPE_FC =3D 2, /* Fibre Channel */ NVMF_TRTYPE_TCP =3D 3, /* TCP/IP */ + NVMF_TRTYPE_MPTCP =3D 4, /* Multipath TCP */ NVMF_TRTYPE_LOOP =3D 254, /* Reserved for host usage */ NVMF_TRTYPE_MAX, }; --=20 2.53.0 From nobody Mon May 25 18:05:05 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 637B630F53C for ; Sun, 17 May 2026 06:06:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778997985; cv=none; b=W2u33n/zjf9FnZW2tHods/sr0s/Z1KLnsiiPMkPtuXAD9ng7MneXRnDaSlOr6OrEOiuAucQoGTiUaYMmFJZB1L5dOErSwokH+ZNzxjMWiMN3sDl8bRqN/7n4YOPz4z+SyeX5vokzs+PvyupeAn51oip3P5jFxdB8q7QQnwDPiLk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778997985; c=relaxed/simple; bh=NANwvxTErmry8dk3Xd3VQYsWQrDkX/ywYJHByWbhowc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PYCi5uyDvlf7GsaStX2R2xpDOvD6OH+MP7p26FWKUbTOVkzwWxRENN5pTXpKN7uZOGkh6X++6O8y5iRPuvfCMHOEaoGHmkGXPvU3KS3z//h9SheJg3q9kPDhJylzN/O+dkOSEB2eItgUQIRb4pfDXS5HRntV/CbgNLtt14VQn7U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sIj7BLmH; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="sIj7BLmH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A1D5BC2BCB3; Sun, 17 May 2026 06:06:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778997985; bh=NANwvxTErmry8dk3Xd3VQYsWQrDkX/ywYJHByWbhowc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sIj7BLmHuZgjSoaCge0fw8eyJspIFfsoC47vjthG4U3YOFoZuqCUwsRKIUBbl0SM7 /KWse9W0w/rVWK7TLy8Ui7XUNrvFR8TcwKUhwEjr/imb5RRa1b23ChhqJTuqDPExWv 0gkSPwkTMV17Qw5NAG5szxs/ydXDmwkLzlclAEcN9x/Y07k9kWLWcrTBJ7h627K6dD uCPf4iEE+DZfBk+qA8TVG4hsKP49cKvelJgZzRNGogmYTECaSiQhEMAHQ+DU3hEwLS aqKB0XRJlchrHpRUGDYv6eEn1tjlOGQTmtzp2fCcXjeaL9IyN95dck2En4RkBlOweq UQx+Cs79Cj9LA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Hannes Reinecke , zhenwei pi , Hui Zhu , Gang Yan Subject: [RFC mptcp-next v11 05/10] nvmet-tcp: implement target mptcp proto Date: Sun, 17 May 2026 14:05:09 +0800 Message-ID: X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang 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(). Cc: Hannes Reinecke Co-developed-by: zhenwei pi Signed-off-by: zhenwei pi Co-developed-by: Hui Zhu Signed-off-by: Hui Zhu Co-developed-by: Gang Yan Signed-off-by: Gang Yan Signed-off-by: Geliang Tang --- drivers/nvme/target/tcp.c | 19 ++++++ include/net/mptcp.h | 20 ++++++ net/mptcp/sockopt.c | 125 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 164 insertions(+) diff --git a/drivers/nvme/target/tcp.c b/drivers/nvme/target/tcp.c index 3ff5deac6779..eff713ba5338 100644 --- a/drivers/nvme/target/tcp.c +++ b/drivers/nvme/target/tcp.c @@ -224,6 +224,9 @@ static DEFINE_MUTEX(nvmet_tcp_queue_mutex); =20 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); =20 @@ -2117,6 +2120,18 @@ static const struct nvmet_tcp_proto nvmet_tcp_proto = =3D { .ops =3D &nvmet_tcp_ops, }; =20 +#ifdef CONFIG_MPTCP +static const struct nvmet_tcp_proto nvmet_mptcp_proto =3D { + .protocol =3D IPPROTO_MPTCP, + .set_reuseaddr =3D mptcp_sock_set_reuseaddr, + .set_nodelay =3D mptcp_sock_set_nodelay, + .set_priority =3D mptcp_sock_set_priority, + .no_linger =3D mptcp_sock_no_linger, + .set_tos =3D mptcp_sock_set_tos, + .ops =3D &nvmet_mptcp_ops, +}; +#endif + static int nvmet_tcp_add_port(struct nvmet_port *nport) { struct nvmet_tcp_port *port; @@ -2143,6 +2158,10 @@ static int nvmet_tcp_add_port(struct nvmet_port *npo= rt) =20 if (nport->disc_addr.trtype =3D=3D NVMF_TRTYPE_TCP) { port->proto =3D &nvmet_tcp_proto; +#ifdef CONFIG_MPTCP + } else if (nport->disc_addr.trtype =3D=3D NVMF_TRTYPE_MPTCP) { + port->proto =3D &nvmet_mptcp_proto; +#endif } else { ret =3D -EINVAL; goto err_port; diff --git a/include/net/mptcp.h b/include/net/mptcp.h index 4cf59e83c1c5..91ce7b9b639d 100644 --- a/include/net/mptcp.h +++ b/include/net/mptcp.h @@ -237,6 +237,16 @@ static inline __be32 mptcp_reset_option(const struct s= k_buff *skb) } =20 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 =20 static inline void mptcp_init(void) @@ -323,6 +333,16 @@ static inline struct request_sock *mptcp_subflow_reqsk= _alloc(const struct reques static inline __be32 mptcp_reset_option(const struct sk_buff *skb) { retu= rn htonl(0u); } =20 static inline void mptcp_active_detect_blackhole(struct sock *sk, bool exp= ired) { } + +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 */ =20 #if IS_ENABLED(CONFIG_MPTCP_IPV6) diff --git a/net/mptcp/sockopt.c b/net/mptcp/sockopt.c index 87b5796d0135..08c8aafa73b7 100644 --- a/net/mptcp/sockopt.c +++ b/net/mptcp/sockopt.c @@ -1547,6 +1547,7 @@ static void sync_socket_options(struct mptcp_sock *ms= k, struct sock *ssk) static const unsigned int tx_rx_locks =3D SOCK_RCVBUF_LOCK | SOCK_SNDBUF_= LOCK; struct sock *sk =3D (struct sock *)msk; bool keep_open; + u32 priority; =20 keep_open =3D sock_flag(sk, SOCK_KEEPOPEN); if (ssk->sk_prot->keepalive) @@ -1596,6 +1597,11 @@ static void sync_socket_options(struct mptcp_sock *m= sk, struct sock *ssk) inet_assign_bit(FREEBIND, ssk, inet_test_bit(FREEBIND, sk)); inet_assign_bit(BIND_ADDRESS_NO_PORT, ssk, inet_test_bit(BIND_ADDRESS_NO_= PORT, sk)); WRITE_ONCE(inet_sk(ssk)->local_port_range, READ_ONCE(inet_sk(sk)->local_p= ort_range)); + + ssk->sk_reuse =3D sk->sk_reuse; + priority =3D READ_ONCE(sk->sk_priority); + if (priority >=3D 0) + sock_set_priority(ssk, priority); } =20 void mptcp_sockopt_sync_locked(struct mptcp_sock *msk, struct sock *ssk) @@ -1662,3 +1668,122 @@ int mptcp_set_rcvlowat(struct sock *sk, int val) } return 0; } + +void mptcp_sock_set_reuseaddr(struct sock *sk) +{ + struct mptcp_sock *msk =3D mptcp_sk(sk); + struct sock *ssk; + + lock_sock(sk); + sockopt_seq_inc(msk); + sk->sk_reuse =3D SK_CAN_REUSE; + ssk =3D __mptcp_nmpc_sk(msk); + if (IS_ERR(ssk)) + goto unlock; + lock_sock_nested(ssk, SINGLE_DEPTH_NESTING); + ssk->sk_reuse =3D SK_CAN_REUSE; + release_sock(ssk); +unlock: + release_sock(sk); +} +EXPORT_SYMBOL(mptcp_sock_set_reuseaddr); + +void mptcp_sock_set_nodelay(struct sock *sk) +{ + struct mptcp_sock *msk =3D mptcp_sk(sk); + struct mptcp_subflow_context *subflow; + struct sock *ssk; + + lock_sock(sk); + sockopt_seq_inc(msk); + msk->nodelay =3D true; + mptcp_for_each_subflow(msk, subflow) { + ssk =3D mptcp_subflow_tcp_sock(subflow); + if (ssk) { + /* + * sock_hold is required here because the subflow + * socket could be closed concurrently by another + * thread, and lock_sock(sk) only protects the + * subflow list, not the subflow socket itself. + */ + sock_hold(ssk); + lock_sock_nested(ssk, SINGLE_DEPTH_NESTING); + __tcp_sock_set_nodelay(ssk, true); + release_sock(ssk); + sock_put(ssk); + } + } + release_sock(sk); +} +EXPORT_SYMBOL(mptcp_sock_set_nodelay); + +void mptcp_sock_set_priority(struct sock *sk, u32 priority) +{ + struct mptcp_sock *msk =3D mptcp_sk(sk); + struct mptcp_subflow_context *subflow; + struct sock *ssk; + + lock_sock(sk); + sockopt_seq_inc(msk); + sock_set_priority(sk, priority); + mptcp_for_each_subflow(msk, subflow) { + ssk =3D mptcp_subflow_tcp_sock(subflow); + if (ssk) { + sock_hold(ssk); + lock_sock_nested(ssk, SINGLE_DEPTH_NESTING); + sock_set_priority(ssk, priority); + release_sock(ssk); + sock_put(ssk); + } + } + release_sock(sk); +} +EXPORT_SYMBOL(mptcp_sock_set_priority); + +void mptcp_sock_no_linger(struct sock *sk) +{ + struct mptcp_sock *msk =3D mptcp_sk(sk); + struct mptcp_subflow_context *subflow; + struct sock *ssk; + + lock_sock(sk); + sockopt_seq_inc(msk); + WRITE_ONCE(sk->sk_lingertime, 0); + sock_set_flag(sk, SOCK_LINGER); + mptcp_for_each_subflow(msk, subflow) { + ssk =3D mptcp_subflow_tcp_sock(subflow); + if (ssk) { + sock_hold(ssk); + lock_sock_nested(ssk, SINGLE_DEPTH_NESTING); + WRITE_ONCE(ssk->sk_lingertime, 0); + sock_set_flag(ssk, SOCK_LINGER); + release_sock(ssk); + sock_put(ssk); + } + } + release_sock(sk); +} +EXPORT_SYMBOL(mptcp_sock_no_linger); + +void mptcp_sock_set_tos(struct sock *sk, int val) +{ + struct mptcp_sock *msk =3D mptcp_sk(sk); + struct mptcp_subflow_context *subflow; + struct sock *ssk; + + lock_sock(sk); + sockopt_seq_inc(msk); + __ip_sock_set_tos(sk, val); + mptcp_for_each_subflow(msk, subflow) { + ssk =3D mptcp_subflow_tcp_sock(subflow); + if (ssk) { + sock_hold(ssk); + lock_sock_nested(ssk, SINGLE_DEPTH_NESTING); + __ip_sock_set_tos(ssk, val); + release_sock(ssk); + sock_put(ssk); + } + } + release_sock(sk); +} +EXPORT_SYMBOL(mptcp_sock_set_tos); --=20 2.53.0 From nobody Mon May 25 18:05:05 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8123E173 for ; Sun, 17 May 2026 06:06:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778997987; cv=none; b=JJUTCMn7c2pZQlYX+fVN/eqfymGxsMJjkQYu7t2LsZRMkDC/kediuB/1RFHKEa6ATKg031lLBybMDOtNO3VViCC4ncnP1gwxDnjebHTrHN/IvBpoZOaVuGgVGaG1AkoJLbpW464nSjJOYYMJoSJQ5pI3i+8sbogFDRUN5wJJkO8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778997987; c=relaxed/simple; bh=04rPn26LCwGPgJq5Oemeud/NXl/pz8o+vxwZAzixVZk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZLqvfrpaZ2zbCXlSNWpgV0Aw5aBluVEaNAgbHQQweOmfizlCtMVOFYcVTrd94k2jWB81Hd6++T0x/sBRhN0ZV6ZhmFACitBIVbYJKx1TrPPVDXnGdXftU50l6y9A7CzExMrJ/o7xSqu+h9VsIoREwYpZsZiWfFAKF3rMO9TYLxg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AFozvIx2; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="AFozvIx2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C12EAC2BCB3; Sun, 17 May 2026 06:06:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778997987; bh=04rPn26LCwGPgJq5Oemeud/NXl/pz8o+vxwZAzixVZk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AFozvIx2tCRzfmDsiGBkYzGd3aaiWuShkxRiIg/mswt3i1EaIA6hCtnuk7cjZvuvE d/SjN/zDTytv+U3hkbvlcdOS2LWSQ8xA+j001xmKfDR6g1AgFMBuTLZn1OlRs8YuF9 8eKZ+D5CT5bKq3m0YDQsUCbIjribMeDjmc6zvqylcRsyxifT7tLJh+vG6MZfCL2xIS 3tdqcoLB23flNMBOPWeHYFO/XV/7ab9iXw4Dsg/YZAeCaUlVlvlFXrIdg7KzXDTZwL uUYLCqc7ttUcT1xC7QxM3u+zlMF+6Yu0tGkossqCuQ7trGWLoxx5W9XzReWO1D5bGi HKtRVoRfCUwWg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Hannes Reinecke , zhenwei pi , Hui Zhu , Gang Yan Subject: [RFC mptcp-next v11 06/10] nvme-tcp: define host tcp_proto struct Date: Sun, 17 May 2026 14:05:10 +0800 Message-ID: <9a10ce9f59923239cdcf671a5bc9a2ccc9afd9d0.1778997507.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang 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 proto field points to a statically allocated nvme_tcp_proto structure that is never freed, so no RCU protection is needed. The controller's proto pointer is set during initialization and remains valid throughout the controller's lifetime. Cc: Hannes Reinecke Co-developed-by: zhenwei pi Signed-off-by: zhenwei pi Co-developed-by: Hui Zhu Signed-off-by: Hui Zhu Co-developed-by: Gang Yan Signed-off-by: Gang Yan Signed-off-by: Geliang Tang --- drivers/nvme/host/tcp.c | 44 ++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c index d1654a630897..a5aa91c65174 100644 --- a/drivers/nvme/host/tcp.c +++ b/drivers/nvme/host/tcp.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -182,6 +183,16 @@ struct nvme_tcp_queue { void (*write_space)(struct sock *); }; =20 +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 +209,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; }; =20 static LIST_HEAD(nvme_tcp_ctrl_list); @@ -1799,7 +1812,7 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nct= rl, int qid, =20 ret =3D 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 +1829,24 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *n= ctrl, int qid, nvme_tcp_reclassify_socket(queue->sock); =20 /* Single syn retry */ - tcp_sock_set_syncnt(queue->sock->sk, 1); + ctrl->proto->set_syncnt(queue->sock->sk, 1); =20 /* Set TCP no delay */ - tcp_sock_set_nodelay(queue->sock->sk); + ctrl->proto->set_nodelay(queue->sock->sk); =20 /* * 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); =20 if (so_priority > 0) - sock_set_priority(queue->sock->sk, so_priority); + ctrl->proto->set_priority(queue->sock->sk, so_priority); =20 /* Set socket type of service */ if (nctrl->opts->tos >=3D 0) - ip_sock_set_tos(queue->sock->sk, nctrl->opts->tos); + ctrl->proto->set_tos(queue->sock->sk, nctrl->opts->tos); =20 /* Set 10 seconds timeout for icresp recvmsg */ queue->sock->sk->sk_rcvtimeo =3D 10 * HZ; @@ -2900,6 +2913,16 @@ nvme_tcp_existing_controller(struct nvmf_ctrl_option= s *opts) return found; } =20 +static const struct nvme_tcp_proto nvme_tcp_proto =3D { + .protocol =3D IPPROTO_TCP, + .set_syncnt =3D tcp_sock_set_syncnt, + .set_nodelay =3D tcp_sock_set_nodelay, + .no_linger =3D sock_no_linger, + .set_priority =3D sock_set_priority, + .set_tos =3D ip_sock_set_tos, + .ops =3D &nvme_tcp_ctrl_ops, +}; + static struct nvme_tcp_ctrl *nvme_tcp_alloc_ctrl(struct device *dev, struct nvmf_ctrl_options *opts) { @@ -2967,13 +2990,20 @@ static struct nvme_tcp_ctrl *nvme_tcp_alloc_ctrl(st= ruct device *dev, goto out_free_ctrl; } =20 + if (!strcmp(ctrl->ctrl.opts->transport, "tcp")) { + ctrl->proto =3D &nvme_tcp_proto; + } else { + ret =3D -EINVAL; + goto out_free_ctrl; + } + ctrl->queues =3D kzalloc_objs(*ctrl->queues, ctrl->ctrl.queue_count); if (!ctrl->queues) { ret =3D -ENOMEM; goto out_free_ctrl; } =20 - ret =3D nvme_init_ctrl(&ctrl->ctrl, dev, &nvme_tcp_ctrl_ops, 0); + ret =3D nvme_init_ctrl(&ctrl->ctrl, dev, ctrl->proto->ops, 0); if (ret) goto out_kfree_queues; =20 --=20 2.53.0 From nobody Mon May 25 18:05:05 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ACF3E1EB1AA for ; Sun, 17 May 2026 06:06:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778997989; cv=none; b=Mku64PbFS2aU6Vr77Qk2Ly1rXuzyn/+znv5dppvtw7M9qQtFW+3v3jgdm3LzBO7JIxX9gkzXMxFpugkAh6SJTpFlAHqSlHVmj7wUP1aTPvh0BtGifSrJogixTAig3BfA8X3wteuX3kQIblAI/67LjNlCAzW8SNwzmNdQRjArJ0M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778997989; c=relaxed/simple; bh=r43wLVJ/gv12FotweD8iof8f2uIKaHxZa9t8YfpUblA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LSfpCAj5eLfp+W4UUSBpoDVUO8OjqjzB14E/5I45Mb1lEW8C190G2rAEdcFXN611BFyhy/MO5Mw582f0hmR4tKP1HVgjo3LM9FsAwBZ+yKRjqZrGZ8JelMtHHEZph51pzzcBcTgiIV4BfpXDGZWzJ91TV+7LWL7RqQjrL06ajiM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iC+z7dT2; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="iC+z7dT2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EC413C2BCB0; Sun, 17 May 2026 06:06:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778997989; bh=r43wLVJ/gv12FotweD8iof8f2uIKaHxZa9t8YfpUblA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iC+z7dT2iYNZmiDXr5Fo0In8sJeTAmQ0dtw9IzhG8dafK6utLPvLcdMlpo33G6O6r nZax7D/+ryOPHV86+Ds/o+1wz1rE0gRYVS+Kjm1PQuv5CyPzUOlqYux5ezumnMuOOW Vx+oJu2P0hpyY11kqxD48+I3iB2OBgoVu8NICwtmgKoDcly1shEVd7CoGC/Co1y/PE RFAvOVgtUdiOuyKOErt2OCLGuziI48RALMjh8qHk3vZDNPOrStSwwHVNevAfgN9kh2 01dW9QPnrfTIBuEEhsXVBdblGP1TB/0rbCCd5Jn9Za2FkAET9WOHOrOi9/RxPjsBZt ZVGoZAkYOxc4w== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Hannes Reinecke , zhenwei pi , Hui Zhu , Gang Yan Subject: [RFC mptcp-next v11 07/10] nvme-tcp: register host mptcp transport Date: Sun, 17 May 2026 14:05:11 +0800 Message-ID: <40c20921f3d63dcf8cc6583e3ec56b6bd9865b00.1778997507.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang 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 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. Cc: Hannes Reinecke Co-developed-by: zhenwei pi Signed-off-by: zhenwei pi Co-developed-by: Hui Zhu Signed-off-by: Hui Zhu Co-developed-by: Gang Yan Signed-off-by: Gang Yan Signed-off-by: Geliang Tang --- drivers/nvme/host/tcp.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c index a5aa91c65174..544ac321c20e 100644 --- a/drivers/nvme/host/tcp.c +++ b/drivers/nvme/host/tcp.c @@ -3070,6 +3070,20 @@ static struct nvmf_transport_ops nvme_tcp_transport = =3D { .create_ctrl =3D nvme_tcp_create_ctrl, }; =20 +#ifdef CONFIG_MPTCP +static struct nvmf_transport_ops nvme_mptcp_transport =3D { + .name =3D "mptcp", + .module =3D THIS_MODULE, + .required_opts =3D NVMF_OPT_TRADDR, + .allowed_opts =3D 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 =3D nvme_tcp_create_ctrl, +}; +#endif + static int __init nvme_tcp_init_module(void) { unsigned int wq_flags =3D WQ_MEM_RECLAIM | WQ_HIGHPRI | WQ_SYSFS; @@ -3095,6 +3109,9 @@ static int __init nvme_tcp_init_module(void) atomic_set(&nvme_tcp_cpu_queues[cpu], 0); =20 nvmf_register_transport(&nvme_tcp_transport); +#ifdef CONFIG_MPTCP + nvmf_register_transport(&nvme_mptcp_transport); +#endif return 0; } =20 @@ -3102,6 +3119,9 @@ static void __exit nvme_tcp_cleanup_module(void) { struct nvme_tcp_ctrl *ctrl; =20 +#ifdef CONFIG_MPTCP + nvmf_unregister_transport(&nvme_mptcp_transport); +#endif nvmf_unregister_transport(&nvme_tcp_transport); =20 mutex_lock(&nvme_tcp_ctrl_mutex); @@ -3119,3 +3139,4 @@ module_exit(nvme_tcp_cleanup_module); MODULE_DESCRIPTION("NVMe host TCP transport driver"); MODULE_LICENSE("GPL v2"); MODULE_ALIAS("nvme-tcp"); +MODULE_ALIAS("nvme-mptcp"); --=20 2.53.0 From nobody Mon May 25 18:05:05 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0CA0130DD2F for ; Sun, 17 May 2026 06:06:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778997992; cv=none; b=fDjvkXt6ElRa/8rpXWTlk37Ch0MbjAoBo+ILoi7nJqQxGOVLXuGMwpwY4wAoZ8JL2y3DPvgyeNuh1UrbbCcQxzq1gdUUzmeGEwu7cTYYMpt3CQiOj7tneLj51lPRHn5jfwynMVZPcIQQUD2c2MzJ8ZplVT+oDIlI+N0jvPIB05M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778997992; c=relaxed/simple; bh=OU9631tJ0A5r9fBcaOp9ok6bbKi74uI0yzGduWBRvqQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aluPyq4DuwQ7AaAQ1Jf+uJhRXDCkGu9ApfelrowFmoqLjGRhq+t8IpcOkNwy/qJ+Bs7eOMCZJbXJR2FkiPxTECrUPVJiuFBiEsVDtKtpdFKqYFZ1CV/8QnNozLVRkOxAS7Oz3G9y7r3pYODNSoFAbK2qQHnp3tnvXgtVTBypCBE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QDve1z85; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="QDve1z85" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1C795C2BCB0; Sun, 17 May 2026 06:06:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778997991; bh=OU9631tJ0A5r9fBcaOp9ok6bbKi74uI0yzGduWBRvqQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QDve1z85q61HGwBbyt5mTRbSNWPy+mwmGkv6FK+KokoBInNcwdXBTgX/DsvbKKgA1 gSCkF+Lw7v1SxVO/NaexfIywOnzfdwOJ1NoVVknL8dAKeReStnucltpbvVMoFcpYSV eqyacE+bBOCS8gPglri60lSVSb0CoIjIUQ4EcvFogbT0/parP6fFLV4VLUfq0gowc6 vouv75eROHh2bQKq5dGZFryAADWLQRJQiYcnhSEdl64QFg+eyQ81MKXNg7/4i1Itfp 01DFpQsVSc9B/mPRXK9lKSYnVK0K99PXg4AkkFR6n2QKZ9exEwGO5XuKZeYP0TpAxZ lXiPV3QlB/Pww== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Hannes Reinecke , zhenwei pi , Hui Zhu , Gang Yan Subject: [RFC mptcp-next v11 08/10] nvme-tcp: implement host mptcp proto Date: Sun, 17 May 2026 14:05:12 +0800 Message-ID: X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang 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 =3D "mptcp" is defined and used for MPTCP controllers. Cc: Hannes Reinecke Co-developed-by: zhenwei pi Signed-off-by: zhenwei pi Co-developed-by: Hui Zhu Signed-off-by: Hui Zhu Co-developed-by: Gang Yan Signed-off-by: Gang Yan Signed-off-by: Geliang Tang --- drivers/nvme/host/tcp.c | 34 ++++++++++++++++++++++++++++++++++ include/net/mptcp.h | 7 +++++++ net/mptcp/protocol.h | 1 + net/mptcp/sockopt.c | 21 +++++++++++++++++++++ 4 files changed, 63 insertions(+) diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c index 544ac321c20e..4e5e31578fbd 100644 --- a/drivers/nvme/host/tcp.c +++ b/drivers/nvme/host/tcp.c @@ -2896,6 +2896,24 @@ static const struct nvme_ctrl_ops nvme_tcp_ctrl_ops = =3D { .get_virt_boundary =3D nvmf_get_virt_boundary, }; =20 +#ifdef CONFIG_MPTCP +static const struct nvme_ctrl_ops nvme_mptcp_ctrl_ops =3D { + .name =3D "mptcp", + .module =3D THIS_MODULE, + .flags =3D NVME_F_FABRICS | NVME_F_BLOCKING, + .reg_read32 =3D nvmf_reg_read32, + .reg_read64 =3D nvmf_reg_read64, + .reg_write32 =3D nvmf_reg_write32, + .subsystem_reset =3D nvmf_subsystem_reset, + .free_ctrl =3D nvme_tcp_free_ctrl, + .submit_async_event =3D nvme_tcp_submit_async_event, + .delete_ctrl =3D nvme_tcp_delete_ctrl, + .get_address =3D nvme_tcp_get_address, + .stop_ctrl =3D nvme_tcp_stop_ctrl, + .get_virt_boundary =3D 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 = =3D { .ops =3D &nvme_tcp_ctrl_ops, }; =20 +#ifdef CONFIG_MPTCP +static const struct nvme_tcp_proto nvme_mptcp_proto =3D { + .protocol =3D IPPROTO_MPTCP, + .set_syncnt =3D mptcp_sock_set_syncnt, + .set_nodelay =3D mptcp_sock_set_nodelay, + .no_linger =3D mptcp_sock_no_linger, + .set_priority =3D mptcp_sock_set_priority, + .set_tos =3D mptcp_sock_set_tos, + .ops =3D &nvme_mptcp_ctrl_ops, +}; +#endif + static struct nvme_tcp_ctrl *nvme_tcp_alloc_ctrl(struct device *dev, struct nvmf_ctrl_options *opts) { @@ -2992,6 +3022,10 @@ static struct nvme_tcp_ctrl *nvme_tcp_alloc_ctrl(str= uct device *dev, =20 if (!strcmp(ctrl->ctrl.opts->transport, "tcp")) { ctrl->proto =3D &nvme_tcp_proto; +#ifdef CONFIG_MPTCP + } else if (!strcmp(ctrl->ctrl.opts->transport, "mptcp")) { + ctrl->proto =3D &nvme_mptcp_proto; +#endif } else { ret =3D -EINVAL; goto out_free_ctrl; diff --git a/include/net/mptcp.h b/include/net/mptcp.h index 91ce7b9b639d..49031a111e69 100644 --- a/include/net/mptcp.h +++ b/include/net/mptcp.h @@ -247,6 +247,8 @@ void mptcp_sock_set_priority(struct sock *sk, u32 prior= ity); void mptcp_sock_no_linger(struct sock *sk); =20 void mptcp_sock_set_tos(struct sock *sk, int val); + +int mptcp_sock_set_syncnt(struct sock *sk, int val); #else =20 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) { } =20 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 */ =20 #if IS_ENABLED(CONFIG_MPTCP_IPV6) diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 661600f8b573..0096cabdccd2 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -336,6 +336,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; diff --git a/net/mptcp/sockopt.c b/net/mptcp/sockopt.c index 08c8aafa73b7..d1dd2eae38d2 100644 --- a/net/mptcp/sockopt.c +++ b/net/mptcp/sockopt.c @@ -1602,6 +1602,8 @@ static void sync_socket_options(struct mptcp_sock *ms= k, struct sock *ssk) priority =3D READ_ONCE(sk->sk_priority); if (priority >=3D 0) sock_set_priority(ssk, priority); + if (msk->icsk_syn_retries > 0) + tcp_sock_set_syncnt(ssk, msk->icsk_syn_retries); } =20 void mptcp_sockopt_sync_locked(struct mptcp_sock *msk, struct sock *ssk) @@ -1787,3 +1789,22 @@ 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 =3D mptcp_sk(sk); + struct sock *ssk; + + if (val < 1 || val > MAX_TCP_SYNCNT) + return -EINVAL; + + lock_sock(sk); + sockopt_seq_inc(msk); + msk->icsk_syn_retries =3D val; + ssk =3D __mptcp_nmpc_sk(msk); + if (!IS_ERR(ssk)) + tcp_sock_set_syncnt(ssk, val); + release_sock(sk); + return 0; +} +EXPORT_SYMBOL(mptcp_sock_set_syncnt); --=20 2.53.0 From nobody Mon May 25 18:05:05 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B884836AF6 for ; Sun, 17 May 2026 06:06:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778997994; cv=none; b=rfRTjcD0Lvh0UY2W4WN8gySaGrdq9BM7FE9rwXQeqlrDiDo+ePFXpLSFFERdTwU93YSUIt7pqTmKtrPEff8MkFgSVqkrKqfV7Cfu1FzNrXzvPnLY7p2HLn312CwRbiXqp79EANCDClWATE9EVVm5ddjTLtbMiOOI6tYkTxhTLcc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778997994; c=relaxed/simple; bh=leQP0rwosxaacKd2yJEfaBPkQz3MT4FzwyqvsHD0wlA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ufY4KScv2RdJDjjiHi1V+IDRtprxAw4iB9e4XsI//ELKAPOdP4G3b13qhqM/JFqqkxqwzl/I2PGUO4czs96fUgjKUqWdR+W/zvzL5sDbpS6uRsntv+cOqa5IxpHMEJTgdfnFEVr3U3ywHH1JGD3qE6CQ/i0yCoQmUoI3sL0ppWo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AqK6p/Lx; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="AqK6p/Lx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1BDFDC2BCB3; Sun, 17 May 2026 06:06:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778997994; bh=leQP0rwosxaacKd2yJEfaBPkQz3MT4FzwyqvsHD0wlA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AqK6p/LxS91NAX3eFWQwhKrdcrG2I4E7KnqFJWfute3ki+9tqUbNlD1H4NStqtu9U JKwOZbcK9l0C10IoE1Fp/TBkVvvGbQgo8x1mq6a6CEdKOpukIylQCRVkTjeAWcoEfD rvJ03v/obJeQCPeZMQ12RlOm6HMhccVZaKX6njFiR2g7PYjIJd5uQS7iQN9IjNXhM0 +rn7GrBjqh9s4GctNBOrUoqPdMh+4jGaCMWfhY/VdIF8zJLBW9z7dAj0ts5kzduGEx JKJzT8JzF3gJE8RVWutUuiZVFtATPy1pAGqOrSMg/CnFNY50AT8D4k33mngXZs4AKR Lr0dxtyOoIsLA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Hannes Reinecke , zhenwei pi , Hui Zhu , Gang Yan Subject: [RFC mptcp-next v11 09/10] selftests: mptcp: add nvme over mptcp test Date: Sun, 17 May 2026 14:05:13 +0800 Message-ID: <0a927979938bd8ab34c8686a0071b772f4e062fa.1778997507.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang 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=3D112MiB/s (118MB/s), 112MiB/s-112MiB/s (118MB/s-118MB/s), io=3D1123MiB (1177MB), run=3D10018-10018msec WRITE: bw=3D112MiB/s (117MB/s), 112MiB/s-112MiB/s (117MB/s-117MB/s), io=3D1118MiB (1173MB), run=3D10018-10018msec # ./mptcp_nvme.sh mptcp READ: bw=3D427MiB/s (448MB/s), 427MiB/s-427MiB/s (448MB/s-448MB/s), io=3D4286MiB (4494MB), run=3D10039-10039msec WRITE: bw=3D387MiB/s (406MB/s), 387MiB/s-387MiB/s (406MB/s-406MB/s), io=3D3885MiB (4073MB), run=3D10043-10043msec It reflects that MPTCP has the same multi-interface bandwidth aggregation capability as NVMe multipath. Cc: Hannes Reinecke Co-developed-by: zhenwei pi Signed-off-by: zhenwei pi Co-developed-by: Hui Zhu Signed-off-by: Hui Zhu Co-developed-by: Gang Yan Signed-off-by: Gang Yan Signed-off-by: Geliang Tang --- 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 | 339 ++++++++++++++++++ 4 files changed, 359 insertions(+) create mode 100755 tools/testing/selftests/net/mptcp/mptcp_nvme.sh diff --git a/tools/testing/selftests/net/mptcp/Makefile b/tools/testing/sel= ftests/net/mptcp/Makefile index 22ba0da2adb8..7b308447a58b 100644 --- a/tools/testing/selftests/net/mptcp/Makefile +++ b/tools/testing/selftests/net/mptcp/Makefile @@ -13,6 +13,7 @@ TEST_PROGS :=3D \ mptcp_connect_sendfile.sh \ mptcp_connect_splice.sh \ mptcp_join.sh \ + mptcp_nvme.sh \ mptcp_sockopt.sh \ pm_netlink.sh \ simult_flows.sh \ diff --git a/tools/testing/selftests/net/mptcp/config b/tools/testing/selft= ests/net/mptcp/config index 59051ee2a986..0eee348eff8b 100644 --- a/tools/testing/selftests/net/mptcp/config +++ b/tools/testing/selftests/net/mptcp/config @@ -34,3 +34,10 @@ CONFIG_NFT_SOCKET=3Dm CONFIG_NFT_TPROXY=3Dm CONFIG_SYN_COOKIES=3Dy CONFIG_VETH=3Dy +CONFIG_CONFIGFS_FS=3Dy +CONFIG_NVME_CORE=3Dy +CONFIG_NVME_FABRICS=3Dy +CONFIG_NVME_TCP=3Dy +CONFIG_NVME_TARGET=3Dy +CONFIG_NVME_TARGET_TCP=3Dy +CONFIG_NVME_MULTIPATH=3Dy diff --git a/tools/testing/selftests/net/mptcp/mptcp_lib.sh b/tools/testing= /selftests/net/mptcp/mptcp_lib.sh index 5ef6033775c8..e08854ba42bd 100644 --- a/tools/testing/selftests/net/mptcp/mptcp_lib.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_lib.sh @@ -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} diff --git a/tools/testing/selftests/net/mptcp/mptcp_nvme.sh b/tools/testin= g/selftests/net/mptcp/mptcp_nvme.sh new file mode 100755 index 000000000000..6c43c8727174 --- /dev/null +++ b/tools/testing/selftests/net/mptcp/mptcp_nvme.sh @@ -0,0 +1,339 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 + +. "$(dirname "$0")/mptcp_lib.sh" + +ret=3D0 +trtype=3D"${1:-mptcp}" +path=3D"${2:-1}" +nqn=3D"nqn.2014-08.org.nvmexpress.${trtype}dev.$$.${RANDOM}" +ns=3D1 +port=3D$((RANDOM % 10000 + 20000)) +trsvcid=3D$((RANDOM % 64512 + 1024)) +ns1=3D"" +ns2=3D"" +temp_file=3D"" +loop_dev=3D"" + +usage() +{ + cat << EOF + +Usage: + + $(basename "$0") [trtype] [path] + + trtype Transport type (tcp|mptcp) - default: mptcp + path Number of multipath (1-4) - default: 1 + +EOF +exit 0 +} + +validate_params() +{ + if [[ ! "${trtype}" =3D~ ^(tcp|mptcp)$ ]]; then + echo "Invalid trtype ${trtype}. Must be tcp or mptcp" + usage + fi + + if [[ ! "${path}" =3D~ ^[1-4]$ ]]; then + echo "Invalid path count ${path}. Must be between 1 and 4" + usage + fi +} + +# This function is invoked indirectly +#shellcheck disable=3DSC2317,SC2329 +ns1_cleanup() +{ + pushd /sys/kernel/config/nvmet || exit 1 + + for i in $(seq 1 "${path}"); do + local portdir=3D$((port + i)) + + rm -rf "ports/${portdir}/subsystems/${nqn}" + rmdir "ports/${portdir}" + done + + echo 0 > "subsystems/${nqn}/namespaces/${ns}/enable" + echo -n 0 > "subsystems/${nqn}/namespaces/${ns}/device_path" + rmdir "subsystems/${nqn}/namespaces/${ns}" + rmdir "subsystems/${nqn}" + + popd || exit 1 +} + +# This function is invoked indirectly +#shellcheck disable=3DSC2317,SC2329 +ns2_cleanup() +{ + nvme disconnect -n "${nqn}" || true +} + +# This function is used in the cleanup trap +#shellcheck disable=3DSC2317,SC2329 +cleanup() +{ + if ! ip netns exec "$ns2" bash <<- EOF + $(declare -f ns2_cleanup) + ns2_cleanup + EOF + then + echo "ns2_cleanup failed" >&2 + fi + + sleep 1 + + if ! ip netns exec "$ns1" unshare -m bash <<- EOF + mount -t configfs none /sys/kernel/config + $(declare -f ns1_cleanup) + ns1_cleanup + EOF + then + echo "ns1_cleanup failed" >&2 + fi + + if [ -n "${loop_dev}" ] && [ -b "${loop_dev}" ]; then + losetup -d "${loop_dev}" 2>/dev/null || true + fi + rm -rf "${temp_file}" + + mptcp_lib_ns_exit "$ns1" "$ns2" + + kill "$monitor_pid_ns1" 2>/dev/null + wait "$monitor_pid_ns1" 2>/dev/null + + kill "$monitor_pid_ns2" 2>/dev/null + wait "$monitor_pid_ns2" 2>/dev/null + + unset -v trtype path nqn ns port trsvcid +} + +init() +{ + local tc_args=3D"rate 1000mbit" + + mptcp_lib_ns_init ns1 ns2 + + # ns1 ns2 + # 10.1.1.1 10.1.1.2 + # 10.1.2.1 10.1.2.2 + # 10.1.3.1 10.1.3.2 + # 10.1.4.1 10.1.4.2 + for i in {1..4}; do + ip link add ns1eth"$i" netns "$ns1" type veth peer \ + name ns2eth"$i" netns "$ns2" + ip -net "$ns1" addr add 10.1."$i".1/24 dev ns1eth"$i" + ip -net "$ns1" addr add dead:beef:"$i"::1/64 \ + dev ns1eth"$i" nodad + ip -net "$ns1" link set ns1eth"$i" up + ip -net "$ns2" addr add 10.1."$i".2/24 dev ns2eth"$i" + ip -net "$ns2" addr add dead:beef:"$i"::2/64 \ + dev ns2eth"$i" nodad + ip -net "$ns2" link set ns2eth"$i" up + ip -net "$ns2" route add default via 10.1."$i".1 \ + dev ns2eth"$i" metric 10"$i" + ip -net "$ns2" route add default via dead:beef:"$i"::1 \ + dev ns2eth"$i" metric 10"$i" + + # Add tc qdisc to both namespaces for bandwidth limiting + tc -n "$ns1" qdisc add dev ns1eth"$i" root netem $tc_args + tc -n "$ns2" qdisc add dev ns2eth"$i" root netem $tc_args + + tc -n "$ns1" qdisc show dev ns1eth"$i" + tc -n "$ns2" qdisc show dev ns2eth"$i" + done + + mptcp_lib_pm_nl_set_limits "${ns1}" 8 8 + + mptcp_lib_pm_nl_add_endpoint "$ns1" 10.1.1.1 flags signal + mptcp_lib_pm_nl_add_endpoint "$ns1" 10.1.2.1 flags signal + mptcp_lib_pm_nl_add_endpoint "$ns1" 10.1.3.1 flags signal + mptcp_lib_pm_nl_add_endpoint "$ns1" 10.1.4.1 flags signal + + mptcp_lib_pm_nl_set_limits "${ns2}" 8 8 + + mptcp_lib_pm_nl_add_endpoint "$ns2" 10.1.1.2 flags subflow + mptcp_lib_pm_nl_add_endpoint "$ns2" 10.1.2.2 flags subflow + mptcp_lib_pm_nl_add_endpoint "$ns2" 10.1.3.2 flags subflow + mptcp_lib_pm_nl_add_endpoint "$ns2" 10.1.4.2 flags subflow + + ip -n "${ns1}" mptcp monitor & + monitor_pid_ns1=3D$! + ip -n "${ns2}" mptcp monitor & + monitor_pid_ns2=3D$! +} + +# This function is invoked indirectly +#shellcheck disable=3DSC2317,SC2329 +run_target() +{ + cd /sys/kernel/config/nvmet/subsystems || exit + mkdir -p "${nqn}" + cd "${nqn}" || exit + echo 1 > attr_allow_any_host + mkdir -p namespaces/"${ns}" + echo "${loop_dev}" > namespaces/"${ns}"/device_path + echo 1 > namespaces/"${ns}"/enable + + # Create 4 ports, each on a different IP address + for i in $(seq 1 "${path}"); do + local portdir=3D$((port + i)) + + cd /sys/kernel/config/nvmet/ports || exit + mkdir -p "${portdir}" + cd "${portdir}" || exit 1 + echo "${trtype}" > addr_trtype + echo ipv4 > addr_adrfam + if [ "${path}" -eq 1 ]; then + echo "0.0.0.0" > addr_traddr + else + echo "10.1.${i}.1" > addr_traddr + fi + echo "${trsvcid}" > addr_trsvcid + + mkdir -p subsystems + ln -sf "../../subsystems/${nqn}" "subsystems/${nqn}" + cd - >/dev/null || exit + done +} + +# This function is invoked indirectly +#shellcheck disable=3DSC2317,SC2329 +run_host() +{ + local traddr=3D10.1.1.1 + local devname + + echo "nvme discover -a ${traddr}" + if ! nvme discover -t "${trtype}" -a "${traddr}" \ + -s "${trsvcid}"; then + echo "Failed to discover ${traddr}" + return 1 + fi + + for i in $(seq 1 "${path}"); do + traddr=3D10.1.${i}.1 + echo "Connecting to ${traddr}:${trsvcid}" + if ! nvme connect -t "${trtype}" -a "${traddr}" \ + -s "${trsvcid}" -n "${nqn}"; then + echo "Failed to connect to ${traddr}" + return 1 + fi + done + + for i in $(seq 1 10); do + for dev in /dev/nvme*n1 /dev/nvme*cn1; do + if [ -b "$dev" ] 2>/dev/null; then + if nvme id-ctrl "$dev" 2>/dev/null | + grep -q "${nqn}"; then + devname=3D$(basename "$dev") + break 2 + fi + fi + done 2>/dev/null + [ -n "$devname" ] && break + sleep 1 + done + + if [ -z "$devname" ]; then + echo "No block device found for NQN ${nqn}" >&2 + return 1 + fi + + echo "nvme list" + if ! nvme list; then + echo "nvme list failed" >&2 + return 1 + fi + + sleep 1 + + echo "fio randread /dev/${devname}" + if ! fio --name=3Dglobal --direct=3D1 --norandommap --randrepeat=3D0 \ + --ioengine=3Dlibaio --thread=3D1 --blocksize=3D128k --runtime=3D10 \ + --time_based --rw=3Drandread --numjobs=3D4 --iodepth=3D256 \ + --group_reporting --size=3D100% \ + --name=3Dlibaio_4_256_128k_randread \ + --filename=3D"/dev/${devname}"; then + echo "fio randread failed" + return 1 + fi + + sleep 1 + + echo "fio randwrite /dev/${devname}" + if ! fio --name=3Dglobal --direct=3D1 --norandommap --randrepeat=3D0 \ + --ioengine=3Dlibaio --thread=3D1 --blocksize=3D128k --runtime=3D10 \ + --time_based --rw=3Drandwrite --numjobs=3D4 --iodepth=3D256 \ + --group_reporting --size=3D100% \ + --name=3Dlibaio_4_256_128k_randwrite \ + --filename=3D"/dev/${devname}"; then + echo "fio randwrite failed" + return 1 + fi + + nvme flush "/dev/${devname}" +} + +mptcp_lib_check_tools nvme fio +validate_params + +if ! temp_file=3D$(mktemp /tmp/nvme_test.XXXXXX.raw); then + echo "Failed to create temp file" + exit 1 +fi + +if ! dd if=3D/dev/zero of=3D"${temp_file}" bs=3D1M count=3D0 seek=3D512; t= hen + echo "Failed to create backing file" >&2 + rm -f "${temp_file}" + exit 1 +fi + +if ! loop_dev=3D$(losetup -f --show "${temp_file}"); then + echo "Failed to create loop device" >&2 + rm -f "${temp_file}" + exit 1 +fi + +init +trap cleanup EXIT + +run_test() +{ + export trtype path nqn ns port trsvcid + export loop_dev temp_file + + if ! ip netns exec "$ns1" unshare -m bash <<- EOF + mount -t configfs none /sys/kernel/config + $(declare -f run_target) + run_target + exit \$? + EOF + then + ret=3D"${KSFT_FAIL}" + fi + + if ! ip netns exec "$ns2" bash <<- EOF + $(declare -f run_host) + run_host + exit \$? + EOF + then + ret=3D"${KSFT_FAIL}" + fi + + sleep 1 +} + +run_test "$@" + +if [ ${ret} -eq 0 ]; then + mptcp_lib_result_pass "nvme over ${trtype} test" +else + mptcp_lib_result_fail "nvme over ${trtype} test" +fi + +mptcp_lib_result_print_all_tap +exit "$ret" --=20 2.53.0 From nobody Mon May 25 18:05:05 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 93DC44502F for ; Sun, 17 May 2026 06:06:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778997996; cv=none; b=MdvH6aT/2pACYm+f1fqga9zwFr//L4h+/LGoo/2sLsSCJKTC+/bvnWPiGH9xRBNS1moNJbGerBJxghXzMVWSHSW0VxJ8pUCwHG/EDMb1ATuesf770GaU3pdxdDqWul+y5UDTLMjnFif2fj6yf19u0HbSuZtocP26UgA69SVwjLM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778997996; c=relaxed/simple; bh=H/9rvH8SPnV89KrWr5EDDV7ePngQ/W+Nw6YFuzkmqYw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iNBKCZ4rsJlnL42wzWZEaor6zq4UJsPwli8eSYA+/cxxfLlqad4osQ2HWehYFabP0ZOydMNrg1afxg0h/KHhEeKnq1D2W/a7RUQin81ZH1/Wv7NcMIgPn6yvXkOCcejUk2EPUswU1zXCaN/JmU++HRdTRuTWN5iLp6VL7S2WNZM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MZoQWOJ5; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MZoQWOJ5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E27E8C2BCB3; Sun, 17 May 2026 06:06:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778997996; bh=H/9rvH8SPnV89KrWr5EDDV7ePngQ/W+Nw6YFuzkmqYw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MZoQWOJ5oFOgqTUa8InZ4m+DoD55jWtF6ZJGPDlO0f4ZuAS+xcchxQKOO2+YOq+ou QoS4EfjqDz+cNpoSujoYZKNOHYT3T20NYuDkdFsB4z5dGXmSA7Q3wFmk6nBV/X9IXr 0g72G5GtdxD8cRsLji5ixIyrr6MXbJFoyKHIa6S1XvpZRMMkwD1MvEdq+cqAZBJw2r SOAPtee6ktiVrg4lq40NwI3Et+WE36mlL6Lvn4e9iZNTif+ttuVjYK34NTbrwf1Ydz rdRX+WuNIq84R2kcl4eoRRl8wcYkiSNiUJqa75yIWpRN71/FgR/aZBr4MwmX/uCTJU rzIoMDb0U9kOA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Hannes Reinecke , zhenwei pi , Hui Zhu , Gang Yan Subject: [RFC mptcp-next v11 10/10] selftests: mptcp: nvme: add iopolicy tests Date: Sun, 17 May 2026 14:05:14 +0800 Message-ID: X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang 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=3D455MiB/s (478MB/s), 455MiB/s-455MiB/s (478MB/s-478MB/s), io=3D4665MiB (4891MB), run=3D10242-10242msec WRITE: bw=3D455MiB/s (477MB/s), 455MiB/s-455MiB/s (477MB/s-477MB/s), io=3D4633MiB (4858MB), run=3D10184-10184msec # ./mptcp_nvme.sh mptcp 4 round-robin READ: bw=3D445MiB/s (466MB/s), 445MiB/s-445MiB/s (466MB/s-466MB/s), io=3D4575MiB (4797MB), run=3D10287-10287msec WRITE: bw=3D445MiB/s (467MB/s), 445MiB/s-445MiB/s (467MB/s-467MB/s), io=3D4572MiB (4794MB), run=3D10267-10267msec A "loss" argument is added to simulate network packet loss. When loss=3D1, 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=3D144MiB/s (151MB/s), 144MiB/s-144MiB/s (151MB/s-151MB/s), io=3D1909MiB (2001MB), run=3D13231-13231msec WRITE: bw=3D100.0MiB/s (105MB/s), 100.0MiB/s-100.0MiB/s (105MB/s-105MB/s), io=3D1397MiB (1465MB), run=3D13980-13980msec # ./mptcp_nvme.sh mptcp 4 round-robin 1 READ: bw=3D428MiB/s (449MB/s), 428MiB/s-428MiB/s (449MB/s-449MB/s), io=3D4524MiB (4743MB), run=3D10564-10564msec WRITE: bw=3D431MiB/s (452MB/s), 431MiB/s-431MiB/s (452MB/s-452MB/s), io=3D4513MiB (4732MB), run=3D10481-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. Cc: Hannes Reinecke Co-developed-by: zhenwei pi Signed-off-by: zhenwei pi Co-developed-by: Hui Zhu Signed-off-by: Hui Zhu Co-developed-by: Gang Yan Signed-off-by: Gang Yan Signed-off-by: Geliang Tang --- .../testing/selftests/net/mptcp/mptcp_nvme.sh | 65 ++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/net/mptcp/mptcp_nvme.sh b/tools/testin= g/selftests/net/mptcp/mptcp_nvme.sh index 6c43c8727174..e823947c89a6 100755 --- a/tools/testing/selftests/net/mptcp/mptcp_nvme.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_nvme.sh @@ -6,6 +6,8 @@ ret=3D0 trtype=3D"${1:-mptcp}" path=3D"${2:-1}" +iopolicy=3D${3:-"numa"} # round-robin, queue-depth +loss=3D${4:-0} nqn=3D"nqn.2014-08.org.nvmexpress.${trtype}dev.$$.${RANDOM}" ns=3D1 port=3D$((RANDOM % 10000 + 20000)) @@ -21,10 +23,12 @@ usage() =20 Usage: =20 - $(basename "$0") [trtype] [path] + $(basename "$0") [trtype] [path] [iopolicy] [loss] =20 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 =20 EOF exit 0 @@ -41,6 +45,16 @@ validate_params() echo "Invalid path count ${path}. Must be between 1 and 4" usage fi + + if [[ ! "${iopolicy}" =3D~ ^(numa|round-robin|queue-depth)$ ]]; then + echo "Invalid iopolicy ${iopolicy}." + usage + fi + + if [[ ! "${loss}" =3D~ ^[01]$ ]]; then + echo "Invalid loss value ${loss}. Must be 0 or 1" + usage + fi } =20 # This function is invoked indirectly @@ -108,12 +122,17 @@ cleanup() wait "$monitor_pid_ns2" 2>/dev/null =20 unset -v trtype path nqn ns port trsvcid + unset iopolicy loss } =20 init() { local tc_args=3D"rate 1000mbit" =20 + if [ "${loss}" -eq 1 ]; then + tc_args+=3D" delay 5ms loss 0.5%" + fi + mptcp_lib_ns_init ns1 ns2 =20 # ns1 ns2 @@ -199,6 +218,43 @@ run_target() done } =20 +# This function is invoked indirectly +#shellcheck disable=3DSC2317,SC2329 +set_io_policy() +{ + local nqn=3D"$1" + local iopolicy=3D"$2" + local subname + local policy + local current + + subname=3D$(nvme list-subsys 2>/dev/null | grep "${nqn}" | + grep -o 'nvme-subsys[0-9]*' | head -1) + if [ -z "$subname" ]; then + return 1 + fi + + policy=3D"/sys/class/nvme-subsystem/${subname}/iopolicy" + if [ ! -w "$policy" ]; then + return 1 + fi + + if ! echo "${iopolicy}" > "$policy" 2>/dev/null; then + return 1 + fi + + current=3D$(cat "$policy" 2>/dev/null) + if [ -z "$current" ]; then + return 1 + fi + + if [[ "$current" !=3D *"${iopolicy}"* ]]; then + return 1 + fi + + return 0 +} + # This function is invoked indirectly #shellcheck disable=3DSC2317,SC2329 run_host() @@ -248,6 +304,11 @@ run_host() return 1 fi =20 + if ! set_io_policy "${nqn}" "${iopolicy}"; then + echo "Failed to set I/O policy to ${iopolicy}" + return 1 + fi + sleep 1 =20 echo "fio randread /dev/${devname}" @@ -304,6 +365,7 @@ run_test() { export trtype path nqn ns port trsvcid export loop_dev temp_file + export iopolicy loss =20 if ! ip netns exec "$ns1" unshare -m bash <<- EOF mount -t configfs none /sys/kernel/config @@ -316,6 +378,7 @@ run_test() fi =20 if ! ip netns exec "$ns2" bash <<- EOF + $(declare -f set_io_policy) $(declare -f run_host) run_host exit \$? --=20 2.53.0