From: Klaus Jensen <its@irrelevant.dk>
To: qemu-devel@nongnu.org
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
"Markku Ahvenjärvi" <mankku@gmail.com>,
qemu-stable@nongnu.org, "Klaus Jensen" <k.jensen@samsung.com>,
"Keith Busch" <kbusch@kernel.org>,
"Klaus Jensen" <its@irrelevant.dk>,
"Jesper Devantier" <foss@defmacro.it>,
qemu-block@nongnu.org
Subject: [PULL 1/7] hw/nvme: prevent cq_pending underflow
Date: Mon, 16 Nov 2026 22:50:07 +0100 [thread overview]
Message-ID: <20261116215014.59993-2-its@irrelevant.dk> (raw)
In-Reply-To: <20261116215014.59993-1-its@irrelevant.dk>
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
next prev parent reply other threads:[~2026-11-16 21:51 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 21:50 [PULL 0/7] hw/nvme fixes Klaus Jensen
2026-11-16 21:50 ` Klaus Jensen [this message]
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
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=20261116215014.59993-2-its@irrelevant.dk \
--to=its@irrelevant.dk \
--cc=foss@defmacro.it \
--cc=k.jensen@samsung.com \
--cc=kbusch@kernel.org \
--cc=mankku@gmail.com \
--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.