All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] vdpa/vp_vdpa: Wait for device reset to complete
@ 2026-11-16  3:01 Yuho Choi
  2026-11-16  3:11 ` sashiko-bot
  2026-11-16  8:18 ` Michael S. Tsirkin
  0 siblings, 2 replies; 3+ messages in thread
From: Yuho Choi @ 2026-11-16  3:01 UTC (permalink / raw)
  To: Michael S. Tsirkin, Jason Wang, Eugenio Pérez
  Cc: Xuan Zhuo, virtualization, linux-kernel, Yuho Choi

vp_vdpa_reset() writes 0 to device_status and returns success right
away. The virtio specification requires the driver to wait until a read
of device_status returns 0 before reinitializing the device, and
virtio_pci_modern's vp_reset() does exactly that: the read-back flushes
the posted status write and any in-flight device writes, including
MSI-X messages.

Without it, vhost-vdpa (or virtio-vdpa) can go on to tear down the
IOTLB/IOMMU mappings or reprogram the queues while the device has not
yet finished its reset, and may still be DMAing to the old virtqueue
addresses. The MSI-X vectors are also freed while an interrupt from
the old configuration may still be in flight.

Poll device_status after writing 0, in the same way as vp_reset(),
before freeing the IRQs and returning.

Fixes: 64b9f64f80a6 ("vdpa: introduce virtio pci driver")
Signed-off-by: Yuho Choi <oss.patchbox@gmail.com>
---
v2:
- Drop Cc: stable, as this has not been reproduced.
- Rebased on current mainline. No code change.

v1: https://lore.kernel.org/r/20260926211507.1330179-1-oss.patchbox@gmail.com

Like vp_reset(), the new loop has no bound, so a surprise-removed
device that reads back all ones would keep it spinning (the Sashiko
review of v1 pointed this out). I kept it the same as vp_reset()
rather than handling that case only here.

Compile-tested only (x86_64 defconfig + VP_VDPA, W=1).

 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: 067c5c24cef23d913b67eaaf71ae67e7169a6620
-- 
2.43.0


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

* Re: [PATCH v2] vdpa/vp_vdpa: Wait for device reset to complete
  2026-11-16  3:01 [PATCH v2] vdpa/vp_vdpa: Wait for device reset to complete Yuho Choi
@ 2026-11-16  3:11 ` sashiko-bot
  2026-11-16  8:18 ` Michael S. Tsirkin
  1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-11-16  3:11 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: infinite loop in vp_vdpa_reset() on surprise
  removal or fault
--

commit 877ae67f265800ae2b653bd6932dd2f6fa55c959
Author: Yuho Choi <oss.patchbox@gmail.com>

vdpa/vp_vdpa: Wait for device reset to complete

This commit polls device_status in vp_vdpa_reset() until it reads back 0
before freeing the MSI-X IRQs and returning.

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

[Severity: High]
Can this loop sleep forever if the PCI device is surprise-removed or
fails to reset?

On PCI hot-unplug, vp_vdpa_remove() unregisters the vDPA device, which
triggers vdpa_reset() -> vp_vdpa_reset() while MMIO reads from
cfg->device_status return 0xff on every iteration.  Without a timeout or
a check for pci_device_is_present(mdev->pci_dev), vp_vdpa_reset() hangs
indefinitely while holding vdpa->cf_lock and blocks vp_vdpa_free_irq()
and device teardown.

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

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

* Re: [PATCH v2] vdpa/vp_vdpa: Wait for device reset to complete
  2026-11-16  3:01 [PATCH v2] vdpa/vp_vdpa: Wait for device reset to complete Yuho Choi
  2026-11-16  3:11 ` sashiko-bot
@ 2026-11-16  8:18 ` Michael S. Tsirkin
  1 sibling, 0 replies; 3+ messages in thread
From: Michael S. Tsirkin @ 2026-11-16  8:18 UTC (permalink / raw)
  To: Yuho Choi
  Cc: Jason Wang, Eugenio Pérez, Xuan Zhuo, virtualization,
	linux-kernel

On Sun, Nov 15, 2026 at 10:01:44PM -0500, Yuho Choi wrote:
> vp_vdpa_reset() writes 0 to device_status and returns success right
> away. The virtio specification requires the driver to wait until a read
> of device_status returns 0 before reinitializing the device, and
> virtio_pci_modern's vp_reset() does exactly that: the read-back flushes
> the posted status write and any in-flight device writes, including
> MSI-X messages.
> 
> Without it, vhost-vdpa (or virtio-vdpa) can go on to tear down the
> IOTLB/IOMMU mappings or reprogram the queues while the device has not
> yet finished its reset, and may still be DMAing to the old virtqueue
> addresses. The MSI-X vectors are also freed while an interrupt from
> the old configuration may still be in flight.
> 
> Poll device_status after writing 0, in the same way as vp_reset(),
> before freeing the IRQs and returning.
> 
> Fixes: 64b9f64f80a6 ("vdpa: introduce virtio pci driver")
> Signed-off-by: Yuho Choi <oss.patchbox@gmail.com>
> ---
> v2:
> - Drop Cc: stable, as this has not been reproduced.
> - Rebased on current mainline. No code change.
> 
> v1: https://lore.kernel.org/r/20260926211507.1330179-1-oss.patchbox@gmail.com
> 
> Like vp_reset(), the new loop has no bound, so a surprise-removed
> device that reads back all ones would keep it spinning (the Sashiko
> review of v1 pointed this out). I kept it the same as vp_reset()
> rather than handling that case only here.
> 
> Compile-tested only (x86_64 defconfig + VP_VDPA, W=1).

If you can't bother testing, why should I bother merging?

>  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: 067c5c24cef23d913b67eaaf71ae67e7169a6620
> -- 
> 2.43.0


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

end of thread, other threads:[~2026-11-16  8:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-16  3:01 [PATCH v2] vdpa/vp_vdpa: Wait for device reset to complete Yuho Choi
2026-11-16  3:11 ` sashiko-bot
2026-11-16  8:18 ` Michael S. Tsirkin

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.