Commit 7e20372641 for qemu.org
commit 7e203726411b7a28b2d020339d6267c7c7d4134e
Author: Klaus Jensen <k.jensen@samsung.com>
Date: Wed Nov 18 13:45:36 2026 +0100
hw/nvme: advance zone write pointer only once the write is committed
nvme_do_write stages the updated zone write pointer before data is
mapped. If that fails, the write pointer update is already staged and
subsequent writes will be rejected if attempted at the original
position.
Move the staging down.
Cc: qemu-stable@nongnu.org
Link: https://gitlab.com/qemu-project/qemu/-/work_items/4520
Fixes: 975b64665048 ("hw/block/nvme: refactor zone resource management")
Reviewed-by: Jesper Wendel Devantier <foss@defmacro.it>
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c
index 35e2c57851..5755aad1fa 100644
--- a/hw/nvme/ctrl.c
+++ b/hw/nvme/ctrl.c
@@ -3800,7 +3800,7 @@ static uint16_t nvme_do_write(NvmeCtrl *n, NvmeRequest *req, bool append,
uint64_t data_size = nvme_l2b(ns, nlb);
uint64_t mapped_size = data_size;
uint64_t data_offset;
- NvmeZone *zone;
+ NvmeZone *zone = NULL;
NvmeZonedResult *res = (NvmeZonedResult *)&req->cqe;
BlockBackend *blk = ns->blkconf.blk;
uint16_t status;
@@ -3893,10 +3893,6 @@ static uint16_t nvme_do_write(NvmeCtrl *n, NvmeRequest *req, bool append,
if (status) {
goto invalid;
}
-
- if (!(zone->d.za & NVME_ZA_ZRWA_VALID)) {
- zone->w_ptr += nlb;
- }
} else if (ns->endgrp && ns->endgrp->fdp.enabled) {
nvme_do_write_fdp(n, req, slba, nlb);
}
@@ -3904,7 +3900,13 @@ static uint16_t nvme_do_write(NvmeCtrl *n, NvmeRequest *req, bool append,
data_offset = nvme_l2b(ns, slba);
if (NVME_ID_NS_DPS_TYPE(ns->id_ns.dps)) {
- return nvme_dif_rw(n, req);
+ status = nvme_dif_rw(n, req);
+
+ if (status != NVME_NO_COMPLETE) {
+ return status;
+ }
+
+ goto out;
}
if (!wrz) {
@@ -3922,6 +3924,11 @@ static uint16_t nvme_do_write(NvmeCtrl *n, NvmeRequest *req, bool append,
req);
}
+out:
+ if (ns->params.zoned && !(zone->d.za & NVME_ZA_ZRWA_VALID)) {
+ zone->w_ptr += nlb;
+ }
+
return NVME_NO_COMPLETE;
invalid: