All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] vdpa/vp_vdpa: Wait for device reset to complete
@ 2026-12-03 15:24 Yuho Choi
  2026-12-03 15:40 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages 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] 2+ messages in thread

* Re: [PATCH v3] vdpa/vp_vdpa: Wait for device reset to complete
  2026-12-03 15:24 [PATCH v3] vdpa/vp_vdpa: Wait for device reset to complete Yuho Choi
@ 2026-12-03 15:40 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-03 15:40 UTC (permalink / raw)
  To: Yuho Choi; +Cc: virtualization, Michael S. Tsirkin, Eugenio Perez

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] vdpa/vp_vdpa: unbounded loop in vp_vdpa_reset() hangs on PCI
  surprise removal
--

commit 70fcb12db8da3c2444a449999ffa84aee5127406
Author: Yuho Choi <oss.patchbox@gmail.com>

vdpa/vp_vdpa: Wait for device reset to complete

This commit adds a polling loop in vp_vdpa_reset() to wait until
device_status reads back 0 after writing 0.

> diff --git a/drivers/vdpa/virtio_pci/vp_vdpa.c b/drivers/vdpa/virtio_pci/vp_vdpa.c
> index 646efd9384fba..eba82ff253ea3 100644
> --- a/drivers/vdpa/virtio_pci/vp_vdpa.c
> +++ b/drivers/vdpa/virtio_pci/vp_vdpa.c

[ ... ]

> @@ -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);

[Severity: High]
Can this loop hang indefinitely when the PCI device is surprise-removed?

After surprise removal, MMIO reads in vp_modern_get_status() return 0xff,
which never satisfies the exit condition.  The uninterruptible loop then
spins forever without reaching vp_vdpa_free_irq().

Because PCI hot-unplug reaches vp_vdpa_reset() through vp_vdpa_remove() ->
vdpa_mgmtdev_unregister() -> vdpa_reset() while holding the global
vdpa_dev_lock and vdev->cf_lock for write, this hang permanently deadlocks
host-wide vDPA management and PCI removal, and skips the rest of teardown.

Unlike vp_reset(), vdpa_config_ops.reset returns an int.  Checking for
0xff or !pci_device_is_present(mdev->pci_dev) and bounding the wait with a
timeout while still calling vp_vdpa_free_irq() would avoid this deadlock.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203152530.1953781-2-oss.patchbox@gmail.com?part=1

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

end of thread, other threads:[~2026-12-03 15:40 UTC | newest]

Thread overview: 2+ messages (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
2026-12-03 15:40 ` sashiko-bot

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.