Thread (5 messages) flat view 5 messages, 2 authors, 9d ago
COOLING9d

[PATCH] virtio_pci: do not mutate caller irq_affinity.pre_vectors

From: Xiong Weimin <hidden>
Date: 2026-08-05 03:29:40
Also in: lkml, stable
Subsystem: the rest, virtio core · Maintainers: Linus Torvalds, "Michael S. Tsirkin", Jason Wang

vp_request_msix_vectors() bumps desc->pre_vectors in place to reserve
the virtio config vector. vp_find_vqs() may call it more than once while
retrying MSI-X with different per-vq policies, so the caller's
irq_affinity keeps accumulating and later attempts get the wrong
affinity layout.

Copy the descriptor to a stack local, adjust pre_vectors there, and
pass that to pci_alloc_irq_vectors_affinity().

Fixes: ba74b6f7fcc0 ("virtio_pci: fix cpu affinity support")
Cc: stable@vger.kernel.org
Signed-off-by: Xiong Weimin <redacted>
---
 drivers/virtio/virtio_pci_common.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c
index 164f480b1..9e75fd03e 100644
--- a/drivers/virtio/virtio_pci_common.c
+++ b/drivers/virtio/virtio_pci_common.c
@@ -128,6 +128,7 @@ static int vp_request_msix_vectors(struct virtio_device *vdev, int nvectors,
 {
 	struct virtio_pci_device *vp_dev = to_vp_device(vdev);
 	const char *name = dev_name(&vp_dev->vdev.dev);
+	struct irq_affinity tmp_aff, *aff = NULL;
 	unsigned int flags = PCI_IRQ_MSIX;
 	unsigned int i, v;
 	int err = -ENOMEM;
@@ -146,16 +147,19 @@ static int vp_request_msix_vectors(struct virtio_device *vdev, int nvectors,
 					GFP_KERNEL))
 			goto error;
 
-	if (!per_vq_vectors)
-		desc = NULL;
-
-	if (desc) {
+	if (per_vq_vectors && desc) {
+		/*
+		 * Do not mutate the caller's irq_affinity across MSI-X
+		 * fallback retries in vp_find_vqs().
+		 */
+		tmp_aff = *desc;
+		tmp_aff.pre_vectors++; /* virtio config vector */
+		aff = &tmp_aff;
 		flags |= PCI_IRQ_AFFINITY;
-		desc->pre_vectors++; /* virtio config vector */
 	}
 
 	err = pci_alloc_irq_vectors_affinity(vp_dev->pci_dev, nvectors,
-					     nvectors, flags, desc);
+					     nvectors, flags, aff);
 	if (err < 0)
 		goto error;
 	vp_dev->msix_enabled = 1;
-- 
2.43.0
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help