[PATCH 2/2] nvmet-tcp: advertise a 4 MiB MDTS limit
Kenta Akagi
kenta.akagi at linecorp.com
Thu Dec 3 02:32:24 PST 2026
Commit 4a3f00262a04 ("nvmet-tcp: bound SGL data length before allocating
command buffers") added a command-wide SGL length check before buffer
allocation. The check rejects lengths above NVMET_TCP_MAXH2CDATA,
currently 4 MiB. ICResp MAXH2CDATA only limits the data in each H2CData
PDU; it does not advertise a maximum command transfer size.
However, nvmet-tcp does not provide get_mdts, so Identify Controller
reports MDTS=0 (no maximum transfer size) by default. An initiator can
therefore submit commands transferring more than 4 MiB, which the target
rejects with NVME_SC_SGL_INVALID_DATA | NVME_STATUS_DNR.
Provide an nvmet-tcp get_mdts callback returning NVMET_TCP_MAX_MDTS,
set to 10. With the current CAP.MPSMIN of zero, this advertises 4 MiB.
The existing allocation protection and per-PDU limits are unchanged.
MDTS and MAXH2CDATA describe different limits, but nvmet_tcp_map_data()
also uses NVMET_TCP_MAXH2CDATA as a command-wide allocation limit.
Match the advertised MDTS to this existing limit so initiators avoid
submitting commands that the target rejects.
MDTS enforcement remains a follow-up. Passthrough is unchanged:
nvmet_passthru_override_id_ctrl() may report MDTS > 10, but no failure
has been reproduced.
Fixes: 4a3f00262a04 ("nvmet-tcp: bound SGL data length before
allocating command buffers")
Reported-by: Alfonso Kuen <gerencia at idkmanager.com>
Link: https://lore.kernel.org/linux-nvme/20260829013900.10392-1-gerencia@idkmanager.com/
Cc: stable at vger.kernel.org
Signed-off-by: Kenta Akagi <kenta.akagi at linecorp.com>
---
drivers/nvme/target/tcp.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/nvme/target/tcp.c b/drivers/nvme/target/tcp.c
index c70804efb853..6507ebc3b5ac 100644
--- a/drivers/nvme/target/tcp.c
+++ b/drivers/nvme/target/tcp.c
@@ -24,6 +24,7 @@
#include "nvmet.h"
#define NVMET_TCP_DEF_INLINE_DATA_SIZE (4 * PAGE_SIZE)
+#define NVMET_TCP_MAX_MDTS 10 /* 4 MiB with CAP.MPSMIN == 0 */
#define NVMET_TCP_MAXH2CDATA 0x400000 /* 4 MiB arbitrary limit */
#define NVMET_TCP_BACKLOG 128
@@ -2301,6 +2302,11 @@ static ssize_t nvmet_tcp_host_port_addr(struct
nvmet_ctrl *ctrl,
(struct sockaddr *)&queue->sockaddr_peer);
}
+static u8 nvmet_tcp_get_mdts(const struct nvmet_ctrl *ctrl)
+{
+ return NVMET_TCP_MAX_MDTS;
+}
+
static const struct nvmet_fabrics_ops nvmet_tcp_ops = {
.owner = THIS_MODULE,
.type = NVMF_TRTYPE_TCP,
@@ -2312,6 +2318,7 @@ static const struct nvmet_fabrics_ops nvmet_tcp_ops = {
.install_queue = nvmet_tcp_install_queue,
.disc_traddr = nvmet_tcp_disc_port_addr,
.host_traddr = nvmet_tcp_host_port_addr,
+ .get_mdts = nvmet_tcp_get_mdts,
};
static int __init nvmet_tcp_init(void)
--
2.51.2
More information about the Linux-nvme
mailing list