[PATCH] hw/nvme: fix pin-based irq assertion

Klaus Jensen posted 1 patch 1 day, 16 hours ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20261126-fix-4520-intx-assert-v1-1-bd20dd253365@samsung.com
Maintainers: Keith Busch <kbusch@kernel.org>, Klaus Jensen <its@irrelevant.dk>, Jesper Devantier <foss@defmacro.it>
hw/nvme/ctrl.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
[PATCH] hw/nvme: fix pin-based irq assertion
Posted by Klaus Jensen 1 day, 16 hours ago
From: Klaus Jensen <k.jensen@samsung.com>

If an existing queue uses a vector larger than 31 (MSI-X) and the host
then disables MSI-X, the next completion on that queue hits the
pin-based interrupt path and an assert on the vector number fires.

Only intentionally bad-behaving guests would hit this, but replace the
asserts with a check and fix potential undefined behavior in the
following shift too.

Cc: qemu-stable@nongnu.org
Fixes: ca247d35098d ("hw/block/nvme: fix pin-based interrupt behavior")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4077
Link: https://gitlab.com/qemu-project/qemu/-/work_items/4520
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
---
 hw/nvme/ctrl.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c
index 5755aad1fa72..4858bd41552c 100644
--- a/hw/nvme/ctrl.c
+++ b/hw/nvme/ctrl.c
@@ -688,8 +688,9 @@ static void nvme_irq_assert(NvmeCtrl *n, NvmeCQueue *cq)
             msix_notify(pci, cq->vector);
         } else {
             trace_pci_nvme_irq_pin();
-            assert(cq->vector < 32);
-            n->irq_status |= 1 << cq->vector;
+            if (cq->vector < 32) {
+                n->irq_status |= 1U << cq->vector;
+            }
             nvme_irq_check(n);
         }
     } else {
@@ -703,9 +704,8 @@ static void nvme_irq_deassert(NvmeCtrl *n, NvmeCQueue *cq)
         if (msix_enabled(PCI_DEVICE(n))) {
             return;
         } else {
-            assert(cq->vector < 32);
-            if (!n->cq_pending) {
-                n->irq_status &= ~(1 << cq->vector);
+            if (!n->cq_pending && cq->vector < 32) {
+                n->irq_status &= ~(1U << cq->vector);
             }
             nvme_irq_check(n);
         }

---
base-commit: 9751c62358073580cbf330a4df22077a7c6a407c
change-id: 20261126-fix-4520-intx-assert-1583241f813d

Best regards,
--  
Klaus Jensen <k.jensen@samsung.com>