* [PATCH v3] vdpa/vp_vdpa: Wait for device reset to complete
@ 2026-12-03 15:24 Yuho Choi
0 siblings, 0 replies; only message in thread
From: Yuho Choi @ 2026-12-03 15:24 UTC (permalink / raw)
To: Michael S. Tsirkin, Jason Wang
Cc: Eugenio Pérez, Xuan Zhuo, virtualization, linux-kernel,
Yuho Choi
vp_vdpa_reset() writes 0 to device_status and returns at once, but the
virtio spec requires the driver to wait until device_status reads back
0. With a device that takes time to reset, the vDPA bus driver can set
the device up again before the reset is done, and the late reset then
wipes that setup; the device may also still use the old rings. Wait for
the read-back, as vp_reset() does.
Fixes: 64b9f64f80a6 ("vdpa: introduce virtio pci driver")
Signed-off-by: Yuho Choi <oss.patchbox@gmail.com>
---
I used an LLM to write and run the test below.
v3:
- Tested in QEMU/KVM, including a QEMU that completes the reset 1 to
100 ms late, which shows the bug (see below).
- Shorter changelog that describes what the test shows. No code change.
v2: https://lore.kernel.org/r/20261116030152.1704527-2-oss.patchbox@gmail.com
v1: https://lore.kernel.org/r/20260926211507.1330179-1-oss.patchbox@gmail.com
Tested on d06ce6f1eb5e with KASAN guests in QEMU/KVM (q35, intel-iommu)
and a modern-only virtio-net-pci device bound to vp_vdpa, using it
through virtio_vdpa (vdpa dev add, traffic, vdpa dev del) and through
vhost_vdpa (VHOST_VDPA_SET_STATUS 0, then read the status back):
1. Stock QEMU 6.2 completes a reset at once, so device_status reads 0 at
the first poll. Both kernels pass 20 cycles of each.
2. A QEMU v11.2.0-rc1 with a test-only change completes the reset 1, 2,
5, 10, 20 or 100 ms after the write of 0, as a slower device might.
Without this patch every boot failed, 3 of 3 at each delay: the late
reset wipes the setup that follows it. Depending on the delay, the
virtio_net probe fails with -95, no packets are received, vdpa dev
del never returns, or vhost_vdpa reads the old status right after
SET_STATUS 0 or fails its next setup with -EINVAL. At 100 ms:
WARNING: drivers/pci/msi/msi.c:816 at __pci_enable_msix_range+0xb3d/0xdc0
WARNING: drivers/vdpa/virtio_pci/vp_vdpa.c:224 at vp_vdpa_set_status+0x412/0x630
WARNING: drivers/virtio/virtio.c:380 at virtio_dev_remove+0x182/0x1e0
With this patch: 10 of 10 cycles of each at every delay, no warnings,
3 of 3 boots each.
Like vp_reset(), the loop has no bound, so a surprise-removed device
that reads back all ones keeps it spinning (pointed out on v1). I kept
it the same as vp_reset().
drivers/vdpa/virtio_pci/vp_vdpa.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/vdpa/virtio_pci/vp_vdpa.c b/drivers/vdpa/virtio_pci/vp_vdpa.c
index 646efd9384fb..eba82ff253ea 100644
--- a/drivers/vdpa/virtio_pci/vp_vdpa.c
+++ b/drivers/vdpa/virtio_pci/vp_vdpa.c
@@ -8,6 +8,7 @@
* Based on virtio_pci_modern.c.
*/
+#include <linux/delay.h>
#include <linux/interrupt.h>
#include <linux/module.h>
#include <linux/pci.h>
@@ -236,6 +237,9 @@ static int vp_vdpa_reset(struct vdpa_device *vdpa)
u8 s = vp_vdpa_get_status(vdpa);
vp_modern_set_status(mdev, 0);
+ /* Wait for the reset to complete */
+ while (vp_modern_get_status(mdev))
+ fsleep(1000);
if (s & VIRTIO_CONFIG_S_DRIVER_OK)
vp_vdpa_free_irq(vp_vdpa);
base-commit: d06ce6f1eb5eeffd4ebcfde345dc34a98131d106
--
2.56.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-12-03 15:25 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 15:24 [PATCH v3] vdpa/vp_vdpa: Wait for device reset to complete Yuho Choi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox