]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
hw/nvme: cap MDTS value for internal limitation
authorKeith Busch <kbusch@kernel.org>
Fri, 1 Aug 2025 14:24:57 +0000 (07:24 -0700)
committerKlaus Jensen <k.jensen@samsung.com>
Mon, 11 Aug 2025 07:17:38 +0000 (00:17 -0700)
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 <kbusch@kernel.org>
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
hw/nvme/ctrl.c

index fa48412ef48e060da6e2d8b2adb49a271e3fc6ae..f5ee6bf260f159249204571a366472f3e0d16dea 100644 (file)
@@ -8339,6 +8339,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)");