From nobody Sun Mar 22 09:51:35 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 65799336881 for ; Thu, 5 Mar 2026 04:05:48 +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=1772683548; cv=none; b=OtZvEv92p2W8JROFBKrNuI58jpZyFklm4h+a3emCfWaDCv4FNG0ayecWEYmVc1smCOUsGYVm9RHxqdGcg+PXYHtZbLQ38XYzAs8eC5TDZVJ/UAziSYE9AUKKWqZSWqt2sFuFshsALbIWpqUR04cS4tCSEq98KKgUhbiyoMQLKCo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772683548; c=relaxed/simple; bh=tcONdptBQn2Ep/oyzZEhEW5gqHIf/pgAo4zgOelzXX8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RiVcUSWphc7LDPYRpxojwVfNVQJ6WNiSICKx/urL/gYXm/tJXe1Rgh2MSgsyEm7//QjB/yjXMwb74RqFhw6g4LEJgNn+vKLThkV9mQB5MRArY6L0/sywkZBwh2R2SZvxnd9CszZULGRp9MClq4nppypQjNrPloRnUUHi1vgHQr0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jUYun7th; 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="jUYun7th" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1B5BAC19422; Thu, 5 Mar 2026 04:05:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1772683548; bh=tcONdptBQn2Ep/oyzZEhEW5gqHIf/pgAo4zgOelzXX8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jUYun7thyUvwrEy3wIy3APPJQsGISctTTHqvAwZQfejxcMNGpY4fvG0pD8fbpuEBv q8FzHjVwcVEZElquR3z2mvyLkRp8ezaWgqokbfGy8DArdM5pLsjvMoAdI+cDu0PBOs ctLJcsq215iTEKl6t53uc8AxdGSxUIUa5MCvWOKm9rTA/7QwnnKFko/gb5td4ww6Q4 xD7TjVCtKrrnAAlEhXLeTDLYpQu4Gtne3aSdV5m0rYno26oq8Eu7ajBMmtTkmF6cVH 7fhwDHLz3z0qf+QYAC4BpRKCl22QQxJpI15IsikfZqt1TvpmZb6yqihKCbfNGzmKP7 2TNZVS9L4uIWA== From: Geliang Tang To: mptcp@lists.linux.dev, nilay@linux.ibm.com, ming.lei@redhat.com, hare@suse.de Cc: Geliang Tang , zhenwei pi , Hui Zhu , Gang Yan Subject: [RFC mptcp-next v4 2/8] nvmet-tcp: add mptcp support Date: Thu, 5 Mar 2026 12:05:20 +0800 Message-ID: <06a0c9133bf17e4d7544c92c0d4ffb469c97734f.1772683110.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. Check if disc_addr.trtype is NVMF_TRTYPE_MPTCP in nvmet_tcp_add_port() to decide whether to pass IPPROTO_MPTCP to sock_create() to create a MPTCP socket instead of a TCP one. This new nvmet_fabrics_ops can be switched in nvmet_tcp_done_recv_pdu() according to different protocol. 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 | 34 ++++++++++++++++++++++++++++++++-- include/linux/nvme.h | 1 + 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/drivers/nvme/target/configfs.c b/drivers/nvme/target/configfs.c index 3088e044dbcb..4b7498ffb102 100644 --- a/drivers/nvme/target/configfs.c +++ b/drivers/nvme/target/configfs.c @@ -38,6 +38,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 acc71a26733f..5a58b544f258 100644 --- a/drivers/nvme/target/tcp.c +++ b/drivers/nvme/target/tcp.c @@ -212,6 +212,7 @@ static DEFINE_MUTEX(nvmet_tcp_queue_mutex); =20 static struct workqueue_struct *nvmet_tcp_wq; static const struct nvmet_fabrics_ops nvmet_tcp_ops; +static const struct nvmet_fabrics_ops nvmet_mptcp_ops; static void nvmet_tcp_free_cmd(struct nvmet_tcp_cmd *c); static void nvmet_tcp_free_cmd_buffers(struct nvmet_tcp_cmd *cmd); =20 @@ -1067,7 +1068,9 @@ static int nvmet_tcp_done_recv_pdu(struct nvmet_tcp_q= ueue *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))) { + if (unlikely(!nvmet_req_init(req, &queue->nvme_sq, + sk_is_msk(queue->sock->sk) ? + &nvmet_mptcp_ops : &nvmet_tcp_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, @@ -2034,6 +2037,7 @@ static int nvmet_tcp_add_port(struct nvmet_port *npor= t) { struct nvmet_tcp_port *port; __kernel_sa_family_t af; + int proto =3D IPPROTO_TCP; int ret; =20 port =3D kzalloc_obj(*port); @@ -2054,6 +2058,11 @@ static int nvmet_tcp_add_port(struct nvmet_port *npo= rt) goto err_port; } =20 +#ifdef CONFIG_MPTCP + if (nport->disc_addr.trtype =3D=3D NVMF_TRTYPE_MPTCP) + proto =3D IPPROTO_MPTCP; +#endif + ret =3D inet_pton_with_scope(&init_net, af, nport->disc_addr.traddr, nport->disc_addr.trsvcid, &port->addr); if (ret) { @@ -2068,7 +2077,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); + proto, &port->sock); if (ret) { pr_err("failed to create a socket\n"); goto err_port; @@ -2220,6 +2229,19 @@ static const struct nvmet_fabrics_ops nvmet_tcp_ops = =3D { .host_traddr =3D nvmet_tcp_host_port_addr, }; =20 +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, +}; + static int __init nvmet_tcp_init(void) { int ret; @@ -2233,6 +2255,12 @@ static int __init nvmet_tcp_init(void) if (ret) goto err; =20 + ret =3D nvmet_register_transport(&nvmet_mptcp_ops); + if (ret) { + nvmet_unregister_transport(&nvmet_tcp_ops); + goto err; + } + return 0; err: destroy_workqueue(nvmet_tcp_wq); @@ -2243,6 +2271,7 @@ static void __exit nvmet_tcp_exit(void) { struct nvmet_tcp_queue *queue; =20 + nvmet_unregister_transport(&nvmet_mptcp_ops); nvmet_unregister_transport(&nvmet_tcp_ops); =20 flush_workqueue(nvmet_wq); @@ -2262,3 +2291,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 655d194f8e72..8069667ad47e 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