From: Klaus Jensen <its@irrelevant.dk>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
Klaus Jensen <k.jensen@samsung.com>,
qemu-stable@nongnu.org,
Jesper Wendel Devantier <foss@defmacro.it>,
Keith Busch <kbusch@kernel.org>, Klaus Jensen <its@irrelevant.dk>,
qemu-block@nongnu.org
Subject: [PULL 1/5] hw/nvme: report data transfer error on failed dma
Date: Fri, 20 Nov 2026 13:29:45 +0100 [thread overview]
Message-ID: <20261120122949.1044-2-its@irrelevant.dk> (raw)
In-Reply-To: <20261120122949.1044-1-its@irrelevant.dk>
From: Klaus Jensen <k.jensen@samsung.com>
nvme_tx discards the MemTxResult returned by dma_buf_read/write and only
inspects the residual. dma_buf_rw already accounts failed transactions
against the residual, so a full-length transfer to or from unmapped
memory results in a zero residual and an apparently successful transfer.
Check the memory transaction result instead and complete the command
with a Data Transfer Error on error and add a new trace event that
actually describe the event correctly.
Cc: qemu-stable@nongnu.org
Fixes: f02b664aad8f ("hw/dma: Let dma_buf_read() / dma_buf_write() propagate MemTxResult")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4700
Reported-by: Karl Mehltretter
Reviewed-by: Jesper Wendel Devantier <foss@defmacro.it>
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
---
hw/nvme/ctrl.c | 10 ++++++++--
hw/nvme/trace-events | 1 +
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c
index 71c24dc02b67..5e8788a257da 100644
--- a/hw/nvme/ctrl.c
+++ b/hw/nvme/ctrl.c
@@ -1380,11 +1380,17 @@ static uint16_t nvme_tx(NvmeCtrl *n, NvmeSg *sg, void *ptr, uint32_t len,
if (sg->flags & NVME_SG_DMA) {
const MemTxAttrs attrs = MEMTXATTRS_UNSPECIFIED;
dma_addr_t residual;
+ MemTxResult res;
if (dir == NVME_TX_DIRECTION_TO_DEVICE) {
- dma_buf_write(ptr, len, &residual, &sg->qsg, attrs);
+ res = dma_buf_write(ptr, len, &residual, &sg->qsg, attrs);
} else {
- dma_buf_read(ptr, len, &residual, &sg->qsg, attrs);
+ res = dma_buf_read(ptr, len, &residual, &sg->qsg, attrs);
+ }
+
+ if (unlikely(res != MEMTX_OK)) {
+ trace_pci_nvme_err_data_transfer(res);
+ return NVME_DATA_TRAS_ERROR;
}
if (unlikely(residual)) {
diff --git a/hw/nvme/trace-events b/hw/nvme/trace-events
index f97a6a11f360..7cc4d1975afb 100644
--- a/hw/nvme/trace-events
+++ b/hw/nvme/trace-events
@@ -139,6 +139,7 @@ pci_nvme_err_addr_write(uint64_t addr) "addr 0x%"PRIx64""
pci_nvme_err_cfs(void) "controller fatal status"
pci_nvme_err_aio(uint16_t cid, const char *errname, uint16_t status) "cid %"PRIu16" err '%s' status 0x%"PRIx16""
pci_nvme_err_copy_invalid_format(uint8_t format) "format 0x%"PRIx8""
+pci_nvme_err_data_transfer(int result) "result %d"
pci_nvme_err_invalid_sgld(uint16_t cid, uint8_t typ) "cid %"PRIu16" type 0x%"PRIx8""
pci_nvme_err_invalid_num_sgld(uint16_t cid, uint8_t typ) "cid %"PRIu16" type 0x%"PRIx8""
pci_nvme_err_invalid_sgl_excess_length(uint32_t residual) "residual %"PRIu32""
--
2.53.0
next prev parent reply other threads:[~2026-11-20 12:30 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 12:29 [PULL 0/5] hw/nvme fixes Klaus Jensen
2026-11-20 12:29 ` Klaus Jensen [this message]
2026-11-20 12:29 ` [PULL 2/5] hw/nvme: fix zone descriptor extension allocation overflow Klaus Jensen
2026-11-20 12:29 ` [PULL 3/5] hw/nvme: fix open zone zrwa allocation Klaus Jensen
2026-11-20 12:29 ` [PULL 4/5] hw/nvme: bound zrwa flush by the write area and zone write boundary Klaus Jensen
2026-11-20 12:29 ` [PULL 5/5] hw/nvme: advance zone write pointer only once the write is committed Klaus Jensen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261120122949.1044-2-its@irrelevant.dk \
--to=its@irrelevant.dk \
--cc=foss@defmacro.it \
--cc=k.jensen@samsung.com \
--cc=kbusch@kernel.org \
--cc=peter.maydell@linaro.org \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-stable@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.