RE: [PATCH] virtio_pci: Wait for legacy device to be reset

From: Angus Chen
Date: Mon Apr 10 2023 - 21:47:12 EST


Hi.

We got a legacy probe problem multitimes.
After reset the legacy device,and we probe the device quickly,
We often get the wrong status of device , especially use in vdpa with legacy moden.
It's often occurs in the set vq status ioctl.

If we use modern virtio device ,it is disappear.

Thanks.

> -----Original Message-----
> From: Angus Chen
> Sent: Tuesday, April 11, 2023 9:39 AM
> To: mst@xxxxxxxxxx; jasowang@xxxxxxxxxx
> Cc: virtualization@xxxxxxxxxxxxxxxxxxxxxxxxxx; linux-kernel@xxxxxxxxxxxxxxx;
> Angus Chen <angus.chen@xxxxxxxxxxxxxxx>
> Subject: [PATCH] virtio_pci: Wait for legacy device to be reset
>
> We read the status of device after reset,
> It is not guaranteed that the device be reseted successfully.
> We can use a while loop to make sure that,like the modern device did.
> The spec is not request it ,but it work.
>
> Signed-off-by: Angus Chen <angus.chen@xxxxxxxxxxxxxxx>
> ---
> drivers/virtio/virtio_pci_legacy.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/virtio/virtio_pci_legacy.c b/drivers/virtio/virtio_pci_legacy.c
> index 2257f1b3d8ae..f2d241563e4f 100644
> --- a/drivers/virtio/virtio_pci_legacy.c
> +++ b/drivers/virtio/virtio_pci_legacy.c
> @@ -14,6 +14,7 @@
> * Michael S. Tsirkin <mst@xxxxxxxxxx>
> */
>
> +#include <linux/delay.h>
> #include "linux/virtio_pci_legacy.h"
> #include "virtio_pci_common.h"
>
> @@ -97,7 +98,8 @@ static void vp_reset(struct virtio_device *vdev)
> vp_legacy_set_status(&vp_dev->ldev, 0);
> /* Flush out the status write, and flush in device writes,
> * including MSi-X interrupts, if any. */
> - vp_legacy_get_status(&vp_dev->ldev);
> + while (vp_legacy_get_status(&vp_dev->ldev))
> + msleep(1);
> /* Flush pending VQ/configuration callbacks. */
> vp_synchronize_vectors(vdev);
> }
> --
> 2.25.1