All of lore.kernel.org
 help / color / mirror / Atom feed
* [PULL 0/7] hw/nvme fixes
@ 2026-11-16 21:50 Klaus Jensen
  2026-11-16 21:50 ` [PULL 1/7] hw/nvme: prevent cq_pending underflow Klaus Jensen
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: Klaus Jensen @ 2026-11-16 21:50 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Klaus Jensen

From: Klaus Jensen <k.jensen@samsung.com>

Hi,

The following changes since commit 573577bff0138681ddd4ee2410c51bead7b53e74:

  Merge tag 'pull-target-arm-20261116' of https://gitlab.com/pm215/qemu into staging (2026-11-16 12:09:43 -0800)

are available in the Git repository at:

  https://gitlab.com/birkelund/qemu.git tags/pull-nvme-20261116

for you to fetch changes up to c0080f56036249df4a3f56e07e90cb0e56b3fd34:

  hw/nvme: fix broadcast fdp events handling (2026-11-16 22:41:27 +0100)

----------------------------------------------------------------
nvme queue

----------------------------------------------------------------
Klaus Jensen (4):
      hw/nvme: verify source and destination lba size for copy
      hw/nvme: reject fdp.runs smaller than the lba data size
      hw/nvme: fix fdp reclaim unit accounting
      hw/nvme: fix broadcast fdp events handling

Markku Ahvenjärvi (3):
      hw/nvme: prevent cq_pending underflow
      hw/nvme: fix missed CQ updates
      hw/nvme: clear interrupts on controller reset

 hw/nvme/ctrl.c | 24 +++++++++++++++++++++---
 hw/nvme/ns.c   |  6 ++++++
 2 files changed, 27 insertions(+), 3 deletions(-)


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PULL 1/7] hw/nvme: prevent cq_pending underflow
  2026-11-16 21:50 [PULL 0/7] hw/nvme fixes Klaus Jensen
@ 2026-11-16 21:50 ` Klaus Jensen
  2026-11-16 21:50 ` [PULL 2/7] hw/nvme: fix missed CQ updates Klaus Jensen
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Klaus Jensen @ 2026-11-16 21:50 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Markku Ahvenjärvi, qemu-stable, Klaus Jensen,
	Keith Busch, Klaus Jensen, Jesper Devantier, qemu-block

From: Markku Ahvenjärvi <mankku@gmail.com>

cq_pending counts interrupt-enabled completion queues with unconsumed
entries. nvme_cq_notifier() and nvme_process_db() decrement it whenever
a CQ becomes empty, but they may also process a notification or doorbell
write for a CQ that was already empty.

Decrement cq_pending only when the CQ contained pending completions
before its head update. Otherwise cq_pending may underflow and
prevent legacy INTx from being deasserted.

Cc: qemu-stable@nongnu.org
Fixes: 83d7ed5c570d ("hw/nvme: fix pin-based interrupt behavior (again)")
Fixes: 2e53b0b45024 ("hw/nvme: Use ioeventfd to handle doorbell updates")
Signed-off-by: Markku Ahvenjärvi <mankku@gmail.com>
Reviewed-by: Klaus Jensen <k.jensen@samsung.com>
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
---
 hw/nvme/ctrl.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c
index 10e5d976a84b..e591842a4a33 100644
--- a/hw/nvme/ctrl.c
+++ b/hw/nvme/ctrl.c
@@ -4783,6 +4783,7 @@ static void nvme_cq_notifier(EventNotifier *e)
 {
     NvmeCQueue *cq = container_of(e, NvmeCQueue, notifier);
     NvmeCtrl *n = cq->ctrl;
+    bool pending = cq->tail != cq->head;
 
     if (!event_notifier_test_and_clear(e)) {
         return;
@@ -4791,7 +4792,7 @@ static void nvme_cq_notifier(EventNotifier *e)
     nvme_update_cq_head(cq);
 
     if (cq->tail == cq->head) {
-        if (cq->irq_enabled) {
+        if (cq->irq_enabled && pending) {
             n->cq_pending--;
         }
 
@@ -8565,6 +8566,7 @@ static void nvme_process_db(NvmeCtrl *n, hwaddr addr, int val)
 
         uint16_t new_head = val & 0xffff;
         NvmeCQueue *cq;
+        bool pending;
 
         qid = (addr - (0x1000 + (1 << 2))) >> 3;
         if (unlikely(nvme_check_cqid(n, qid))) {
@@ -8619,13 +8621,14 @@ static void nvme_process_db(NvmeCtrl *n, hwaddr addr, int val)
             qemu_bh_schedule(cq->bh);
         }
 
+        pending = cq->tail != cq->head;
         cq->head = new_head;
         if (!qid && n->dbbuf_enabled) {
             stl_le_pci_dma(pci, cq->db_addr, cq->head, MEMTXATTRS_UNSPECIFIED);
         }
 
         if (cq->tail == cq->head) {
-            if (cq->irq_enabled) {
+            if (cq->irq_enabled && pending) {
                 n->cq_pending--;
             }
 
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PULL 2/7] hw/nvme: fix missed CQ updates
  2026-11-16 21:50 [PULL 0/7] hw/nvme fixes Klaus Jensen
  2026-11-16 21:50 ` [PULL 1/7] hw/nvme: prevent cq_pending underflow Klaus Jensen
@ 2026-11-16 21:50 ` Klaus Jensen
  2026-11-16 21:50 ` [PULL 3/7] hw/nvme: clear interrupts on controller reset Klaus Jensen
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Klaus Jensen @ 2026-11-16 21:50 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Markku Ahvenjärvi, qemu-stable, Klaus Jensen,
	Keith Busch, Klaus Jensen, Jesper Devantier, qemu-block

From: Markku Ahvenjärvi <mankku@gmail.com>

When doorbell buffers are enabled, CQ head updates may race with
completion posting. When a CQ doorbell leaves pending completions, the
event index may become stale and cause the guest to suppress the next
MMIO doorbell write. QEMU may then fail to observe that the CQ has
been drained. With legacy INTx, this can leave the interrupt asserted
indefinitely and cause an interrupt storm.

Update the CQ event index as part of doorbell processing to ensure that
subsequent head updates notify QEMU.

Cc: qemu-stable@nongnu.org
Fixes: 3f7fe8de3d49 ("hw/nvme: Implement shadow doorbell buffer support")
Fixes: 2e53b0b45024 ("hw/nvme: Use ioeventfd to handle doorbell updates")
Signed-off-by: Markku Ahvenjärvi <mankku@gmail.com>
Reviewed-by: Klaus Jensen <k.jensen@samsung.com>
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
---
 hw/nvme/ctrl.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c
index e591842a4a33..52fa4b327c1f 100644
--- a/hw/nvme/ctrl.c
+++ b/hw/nvme/ctrl.c
@@ -4789,6 +4789,7 @@ static void nvme_cq_notifier(EventNotifier *e)
         return;
     }
 
+    nvme_update_cq_eventidx(cq);
     nvme_update_cq_head(cq);
 
     if (cq->tail == cq->head) {
@@ -8633,6 +8634,8 @@ static void nvme_process_db(NvmeCtrl *n, hwaddr addr, int val)
             }
 
             nvme_irq_deassert(n, cq);
+        } else if (n->dbbuf_enabled) {
+            nvme_update_cq_eventidx(cq);
         }
     } else {
         /* Submission queue doorbell write */
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PULL 3/7] hw/nvme: clear interrupts on controller reset
  2026-11-16 21:50 [PULL 0/7] hw/nvme fixes Klaus Jensen
  2026-11-16 21:50 ` [PULL 1/7] hw/nvme: prevent cq_pending underflow Klaus Jensen
  2026-11-16 21:50 ` [PULL 2/7] hw/nvme: fix missed CQ updates Klaus Jensen
@ 2026-11-16 21:50 ` Klaus Jensen
  2026-11-16 21:50 ` [PULL 4/7] hw/nvme: verify source and destination lba size for copy Klaus Jensen
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Klaus Jensen @ 2026-11-16 21:50 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Markku Ahvenjärvi, qemu-stable, Klaus Jensen,
	Keith Busch, Klaus Jensen, Jesper Devantier, qemu-block

From: Markku Ahvenjärvi <mankku@gmail.com>

Clear stale CQ interrupt state and ensure the interrupt line is
deasserted when resetting an NVMe controller.

Cc: qemu-stable@nongnu.org
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4142
Fixes: 83d7ed5c570d ("hw/nvme: fix pin-based interrupt behavior (again)")
Signed-off-by: Markku Ahvenjärvi <mankku@gmail.com>
Reviewed-by: Klaus Jensen <k.jensen@samsung.com>
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
---
 hw/nvme/ctrl.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c
index 52fa4b327c1f..4a626203cad8 100644
--- a/hw/nvme/ctrl.c
+++ b/hw/nvme/ctrl.c
@@ -8136,6 +8136,10 @@ static void nvme_ctrl_reset(NvmeCtrl *n, NvmeResetType rst)
     stl_le_p(&n->bar.intmc, 0);
     stl_le_p(&n->bar.cc, 0);
 
+    n->cq_pending = 0;
+    n->irq_status = 0;
+    nvme_irq_check(n);
+
     n->dbbuf_dbs = 0;
     n->dbbuf_eis = 0;
     n->dbbuf_enabled = false;
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PULL 4/7] hw/nvme: verify source and destination lba size for copy
  2026-11-16 21:50 [PULL 0/7] hw/nvme fixes Klaus Jensen
                   ` (2 preceding siblings ...)
  2026-11-16 21:50 ` [PULL 3/7] hw/nvme: clear interrupts on controller reset Klaus Jensen
@ 2026-11-16 21:50 ` Klaus Jensen
  2026-11-16 21:50 ` [PULL 5/7] hw/nvme: reject fdp.runs smaller than the lba data size Klaus Jensen
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Klaus Jensen @ 2026-11-16 21:50 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Klaus Jensen, qemu-stable, Jesper Wendel Devantier,
	Keith Busch, Klaus Jensen, qemu-block

From: Klaus Jensen <k.jensen@samsung.com>

Cross-namespace copy requires the source and destination namespace to
have the same logical block size. This is not verified, causing a heap
out-of-bounds write.

Fix by correctly identifying the invalid operation.

Cc: qemu-stable@nongnu.org
Reported-by: Feng Xue and XGPT of ThreatBook
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4173
Fixes: d522aef88d42 ("hw/nvme: add cross namespace copy support")
Reviewed-by: Jesper Wendel Devantier <foss@defmacro.it>
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
---
 hw/nvme/ctrl.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c
index 4a626203cad8..685cbc2f340c 100644
--- a/hw/nvme/ctrl.c
+++ b/hw/nvme/ctrl.c
@@ -3278,6 +3278,11 @@ static void nvme_do_copy(NvmeCopyAIOCB *iocb)
         status = NVME_INVALID_FIELD | NVME_DNR;
         goto invalid;
     } else if (snsid != dnsid) {
+        if (sns->lbaf.ds != dns->lbaf.ds) {
+            status = NVME_CMD_INCOMP_NS_OR_FMT | NVME_DNR;
+            goto invalid;
+        }
+
         if (!NVME_ID_NS_DPS_TYPE(sns->id_ns.dps) &&
             !NVME_ID_NS_DPS_TYPE(dns->id_ns.dps)) {
             if (!nvme_copy_matching_ns_format(sns, dns, false)) {
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PULL 5/7] hw/nvme: reject fdp.runs smaller than the lba data size
  2026-11-16 21:50 [PULL 0/7] hw/nvme fixes Klaus Jensen
                   ` (3 preceding siblings ...)
  2026-11-16 21:50 ` [PULL 4/7] hw/nvme: verify source and destination lba size for copy Klaus Jensen
@ 2026-11-16 21:50 ` Klaus Jensen
  2026-11-16 21:50 ` [PULL 6/7] hw/nvme: fix fdp reclaim unit accounting Klaus Jensen
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Klaus Jensen @ 2026-11-16 21:50 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Klaus Jensen, qemu-stable, Jesper Wendel Devantier,
	Keith Busch, Klaus Jensen, qemu-block

From: Klaus Jensen <k.jensen@samsung.com>

The reclaim unit accounting in nvme_do_write_fdp spins forever if RUNS
is configured to be smaller than LBADS.

Reject such an invalid configuration upfront.

Cc: qemu-stable@nongnu.org
Link: https://gitlab.com/qemu-project/qemu/-/work_items/4520
Fixes: 73064edfb864 ("hw/nvme: flexible data placement emulation")
Reviewed-by: Jesper Wendel Devantier <foss@defmacro.it>
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
---
 hw/nvme/ns.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/hw/nvme/ns.c b/hw/nvme/ns.c
index 2ae26a9acbd0..37d45bb4d533 100644
--- a/hw/nvme/ns.c
+++ b/hw/nvme/ns.c
@@ -485,6 +485,12 @@ static bool nvme_ns_init_fdp(NvmeNamespace *ns, Error **errp)
     char *r, *p;
     uint16_t *ph;
 
+    if (endgrp->fdp.runs < nvme_l2b(ns, 1)) {
+        error_setg(errp, "fdp.runs must be greater than or equal to the "
+                   "lba data size of the namespace");
+        return false;
+    }
+
     if (!ns->params.fdp.ruhs) {
         ns->fdp.nphs = 1;
         ph = ns->fdp.phs = g_new(uint16_t, 1);
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PULL 6/7] hw/nvme: fix fdp reclaim unit accounting
  2026-11-16 21:50 [PULL 0/7] hw/nvme fixes Klaus Jensen
                   ` (4 preceding siblings ...)
  2026-11-16 21:50 ` [PULL 5/7] hw/nvme: reject fdp.runs smaller than the lba data size Klaus Jensen
@ 2026-11-16 21:50 ` Klaus Jensen
  2026-11-16 21:50 ` [PULL 7/7] hw/nvme: fix broadcast fdp events handling Klaus Jensen
  2026-11-16 23:47 ` [PULL 0/7] hw/nvme fixes Richard Henderson
  7 siblings, 0 replies; 9+ messages in thread
From: Klaus Jensen @ 2026-11-16 21:50 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Klaus Jensen, qemu-stable, Jesper Wendel Devantier,
	Keith Busch, Klaus Jensen, qemu-block

From: Klaus Jensen <k.jensen@samsung.com>

nvme_do_write_fdp falls back to placement handle zero for a write that
has no Data Placement directive or where the placement identifier is
invalid. However, it then passes the invalid placement identifier to
nvme_update_ruh which results in no update to RUAMW for placement handle
zero.

Reset the placement identifier along with the handle in the fallback.

Cc: qemu-stable@nongnu.org
Link: https://gitlab.com/qemu-project/qemu/-/work_items/4520
Fixes: 73064edfb864 ("hw/nvme: flexible data placement emulation")
Reviewed-by: Jesper Wendel Devantier <foss@defmacro.it>
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
---
 hw/nvme/ctrl.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c
index 685cbc2f340c..a0d22dacedfa 100644
--- a/hw/nvme/ctrl.c
+++ b/hw/nvme/ctrl.c
@@ -3754,6 +3754,7 @@ static void nvme_do_write_fdp(NvmeCtrl *n, NvmeRequest *req, uint64_t slba,
         !nvme_parse_pid(ns, pid, &ph, &rg)) {
         ph = 0;
         rg = 0;
+        pid = 0;
     }
 
     ruhid = ns->fdp.phs[ph];
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PULL 7/7] hw/nvme: fix broadcast fdp events handling
  2026-11-16 21:50 [PULL 0/7] hw/nvme fixes Klaus Jensen
                   ` (5 preceding siblings ...)
  2026-11-16 21:50 ` [PULL 6/7] hw/nvme: fix fdp reclaim unit accounting Klaus Jensen
@ 2026-11-16 21:50 ` Klaus Jensen
  2026-11-16 23:47 ` [PULL 0/7] hw/nvme fixes Richard Henderson
  7 siblings, 0 replies; 9+ messages in thread
From: Klaus Jensen @ 2026-11-16 21:50 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Klaus Jensen, qemu-stable, Jesper Wendel Devantier,
	Keith Busch, Klaus Jensen, qemu-block

From: Klaus Jensen <k.jensen@samsung.com>

The Set Features handler for the FDP Events feature asserts that a
namespace is passed in the command because the feature is
namespace-specific. An invalid namespace is rejected prior to reaching
the handler, but the "broadcast nsid" (0xFFFFFFFF) is considered valid
and causes the assert to abort QEMU.

Reject it with Invalid Field in Command instead as per the
specification.

Cc: qemu-stable@nongnu.org
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4792
Fixes: 73064edfb864 ("hw/nvme: flexible data placement emulation")
Reviewed-by: Jesper Wendel Devantier <foss@defmacro.it>
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
---
 hw/nvme/ctrl.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c
index a0d22dacedfa..71c24dc02b67 100644
--- a/hw/nvme/ctrl.c
+++ b/hw/nvme/ctrl.c
@@ -6636,7 +6636,9 @@ static uint16_t nvme_set_feature_fdp_events(NvmeCtrl *n, NvmeNamespace *ns,
     g_autofree uint8_t *events = NULL;
     NvmeRuHandle *ruh = NULL;
 
-    assert(ns);
+    if (!ns) {
+        return NVME_INVALID_FIELD | NVME_DNR;
+    }
 
     if (!n->subsys || !n->subsys->endgrp.fdp.enabled) {
         return NVME_FDP_DISABLED | NVME_DNR;
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PULL 0/7] hw/nvme fixes
  2026-11-16 21:50 [PULL 0/7] hw/nvme fixes Klaus Jensen
                   ` (6 preceding siblings ...)
  2026-11-16 21:50 ` [PULL 7/7] hw/nvme: fix broadcast fdp events handling Klaus Jensen
@ 2026-11-16 23:47 ` Richard Henderson
  7 siblings, 0 replies; 9+ messages in thread
From: Richard Henderson @ 2026-11-16 23:47 UTC (permalink / raw)
  To: Klaus Jensen, qemu-devel; +Cc: Peter Maydell, Klaus Jensen

On 11/16/26 13:50, Klaus Jensen wrote:
> From: Klaus Jensen<k.jensen@samsung.com>
> 
> Hi,
> 
> The following changes since commit 573577bff0138681ddd4ee2410c51bead7b53e74:
> 
>    Merge tag 'pull-target-arm-20261116' ofhttps://gitlab.com/pm215/qemu into staging (2026-11-16 12:09:43 -0800)
> 
> are available in the Git repository at:
> 
>    https://gitlab.com/birkelund/qemu.git tags/pull-nvme-20261116
> 
> for you to fetch changes up to c0080f56036249df4a3f56e07e90cb0e56b3fd34:
> 
>    hw/nvme: fix broadcast fdp events handling (2026-11-16 22:41:27 +0100)
> 
> ----------------------------------------------------------------
> nvme queue

Applied, thanks.

r~


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-11-16 23:48 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-16 21:50 [PULL 0/7] hw/nvme fixes Klaus Jensen
2026-11-16 21:50 ` [PULL 1/7] hw/nvme: prevent cq_pending underflow Klaus Jensen
2026-11-16 21:50 ` [PULL 2/7] hw/nvme: fix missed CQ updates Klaus Jensen
2026-11-16 21:50 ` [PULL 3/7] hw/nvme: clear interrupts on controller reset Klaus Jensen
2026-11-16 21:50 ` [PULL 4/7] hw/nvme: verify source and destination lba size for copy Klaus Jensen
2026-11-16 21:50 ` [PULL 5/7] hw/nvme: reject fdp.runs smaller than the lba data size Klaus Jensen
2026-11-16 21:50 ` [PULL 6/7] hw/nvme: fix fdp reclaim unit accounting Klaus Jensen
2026-11-16 21:50 ` [PULL 7/7] hw/nvme: fix broadcast fdp events handling Klaus Jensen
2026-11-16 23:47 ` [PULL 0/7] hw/nvme fixes Richard Henderson

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.