From 312cbe919b94565dc54c9c6189cea4d72797d514 Mon Sep 17 00:00:00 2001 From: guping Date: Tue, 26 Aug 2025 02:13:17 +0000 Subject: [PATCH] hw/nvme: cap MDTS value for internal limitation cherry-pick from 53493c1f836f4dda90a6b5f2fb3d9264918c6871 The emulated device had let the user set whatever max transfers size they wanted, including no limit. However the device does have an internal limit of 1024 segments. NVMe doesn't report max segments, though. This is implicitly inferred based on the MDTS and MPSMIN values. IOV_MAX is currently 1024 which 4k PRPs can exceed with 2MB transfers. Don't allow MDTS values that can exceed this, otherwise users risk seeing "internal error" status to their otherwise protocol compliant commands. Signed-off-by: Keith Busch Signed-off-by: Klaus Jensen Signed-off-by: guping --- hw/nvme/ctrl.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c index 6fc2a64b0e..e293496ac7 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -7816,6 +7816,11 @@ static bool nvme_check_params(NvmeCtrl *n, Error **errp) host_memory_backend_set_mapped(n->pmr.dev, true); } + if (!n->params.mdts || ((1 << n->params.mdts) + 1) > IOV_MAX) { + error_setg(errp, "mdts exceeds IOV_MAX"); + return false; + } + if (n->params.zasl > n->params.mdts) { error_setg(errp, "zoned.zasl (Zone Append Size Limit) must be less " "than or equal to mdts (Maximum Data Transfer Size)"); -- Gitee