Xuan Zhuo
2023-Oct-24 03:48 UTC
[PATCH vhost 0/2] virtio: set broken when re-enable vq fails
In vp_modern_enable_vq_after_reset, we will do some check to ensure that the vq is in reset status. If that fails, the vq is good. If the vq_active_vp() fails, that means the vq is broken. The driver will can not use that vq, this commit sets the vq to broken. Xuan Zhuo (2): virtio_ring: remove unused code virtio: set broken when re-enabling vq fails drivers/virtio/virtio_pci_modern.c | 6 +++--- drivers/virtio/virtio_ring.c | 15 ++++++++++----- include/linux/virtio_config.h | 2 ++ 3 files changed, 15 insertions(+), 8 deletions(-) -- 2.32.0.3.g01195cf9f
Remove the ignored return values; Signed-off-by: Xuan Zhuo <xuanzhuo at linux.alibaba.com> --- drivers/virtio/virtio_ring.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index 51d8f3299c10..af310418e66e 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -2755,9 +2755,9 @@ int virtqueue_resize(struct virtqueue *_vq, u32 num, return err; if (vq->packed_ring) - err = virtqueue_resize_packed(_vq, num); + virtqueue_resize_packed(_vq, num); else - err = virtqueue_resize_split(_vq, num); + virtqueue_resize_split(_vq, num); return virtqueue_enable_after_reset(_vq); } -- 2.32.0.3.g01195cf9f
Xuan Zhuo
2023-Oct-24 03:49 UTC
[PATCH vhost 2/2] virtio: set broken when re-enabling vq fails
In vp_modern_enable_vq_after_reset, we will do some checks to ensure that the vq is ready to re-enable. If that fails, the vq is good. If the vq_active_vp() fails, that means the vq is broken. The driver can not use that vq, this commit sets the vq to broken. Signed-off-by: Xuan Zhuo <xuanzhuo at linux.alibaba.com> --- drivers/virtio/virtio_pci_modern.c | 6 +++--- drivers/virtio/virtio_ring.c | 11 ++++++++--- include/linux/virtio_config.h | 2 ++ 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/drivers/virtio/virtio_pci_modern.c b/drivers/virtio/virtio_pci_modern.c index ee6a386d250b..56a4075ca5fb 100644 --- a/drivers/virtio/virtio_pci_modern.c +++ b/drivers/virtio/virtio_pci_modern.c @@ -286,16 +286,16 @@ static int vp_modern_enable_vq_after_reset(struct virtqueue *vq) int err; if (!vq->reset) - return -EBUSY; + return -EINVAL; index = vq->index; info = vp_dev->vqs[index]; if (vp_modern_get_queue_reset(mdev, index)) - return -EBUSY; + return -EINVAL; if (vp_modern_get_queue_enable(mdev, index)) - return -EBUSY; + return -EINVAL; err = vp_active_vq(vq, info->msix_vector); if (err) diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index af310418e66e..91e63c57c112 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -2183,11 +2183,16 @@ static int virtqueue_enable_after_reset(struct virtqueue *_vq) { struct vring_virtqueue *vq = to_vvq(_vq); struct virtio_device *vdev = vq->vq.vdev; + int err; + + err = vdev->config->enable_vq_after_reset(_vq); + if (err == -EINVAL || !err) + return err; - if (vdev->config->enable_vq_after_reset(_vq)) - return -EBUSY; + dev_warn(&vdev->dev, "Fail to re-enable the vq.%u error:%d\n", _vq->index, err); + __virtqueue_unbreak(_vq); - return 0; + return err; } /* diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h index 2b3438de2c4d..f96bebf9b632 100644 --- a/include/linux/virtio_config.h +++ b/include/linux/virtio_config.h @@ -91,6 +91,8 @@ typedef void vq_callback_t(struct virtqueue *); * @enable_vq_after_reset: enable a reset queue * vq: the virtqueue * Returns 0 on success or error status + * -EINVAL: the vq is not in the reset status or is not ready to enable. + * Other error: enabling vq fails. The vq is in broken status. * If disable_vq_and_reset is set, then enable_vq_after_reset must also be * set. */ -- 2.32.0.3.g01195cf9f