[Qemu-devel] [PATCH v2] clean up callback when del virtqueue

liujunjie posted 1 patch 7 years, 1 month ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20180917134845.12908-1-liujunjie23@huawei.com
Test docker-clang@ubuntu failed
Test checkpatch passed
hw/virtio/virtio.c | 2 ++
1 file changed, 2 insertions(+)
[Qemu-devel] [PATCH v2] clean up callback when del virtqueue
Posted by liujunjie 7 years, 1 month ago
Before, we did not clear callback like handle_output when delete
the virtqueue which may result be segmentfault.
The scene is as follows:
1. Start a vm with multiqueue vhost-net,
2. then we write VIRTIO_PCI_GUEST_FEATURES in PCI configuration to
triger multiqueue disable in this vm which will delete the virtqueue.
In this step, the tx_bh is deleted but the callback virtio_net_handle_tx_bh
still exist.
3. Finally, we write VIRTIO_PCI_QUEUE_NOTIFY in PCI configuration to
notify the deleted virtqueue. In this way, virtio_net_handle_tx_bh
will be called and qemu will be crashed.

Although the way described above is uncommon, we had better reinforce it.

Signed-off-by: liujunjie <liujunjie23@huawei.com>
---
 hw/virtio/virtio.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index d4e4d98..dc8dcf8 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -1604,6 +1604,8 @@ void virtio_del_queue(VirtIODevice *vdev, int n)
 
     vdev->vq[n].vring.num = 0;
     vdev->vq[n].vring.num_default = 0;
+    vdev->vq[n].handle_output = NULL;
+    vdev->vq[n].handle_aio_output = NULL;
 }
 
 static void virtio_set_isr(VirtIODevice *vdev, int value)
-- 
1.8.3.1



Re: [Qemu-devel] [PATCH v2] clean up callback when del virtqueue
Posted by Jason Wang 7 years, 1 month ago

On 2018年09月17日 21:48, liujunjie wrote:
> Before, we did not clear callback like handle_output when delete
> the virtqueue which may result be segmentfault.
> The scene is as follows:
> 1. Start a vm with multiqueue vhost-net,
> 2. then we write VIRTIO_PCI_GUEST_FEATURES in PCI configuration to
> triger multiqueue disable in this vm which will delete the virtqueue.
> In this step, the tx_bh is deleted but the callback virtio_net_handle_tx_bh
> still exist.
> 3. Finally, we write VIRTIO_PCI_QUEUE_NOTIFY in PCI configuration to
> notify the deleted virtqueue. In this way, virtio_net_handle_tx_bh
> will be called and qemu will be crashed.
>
> Although the way described above is uncommon, we had better reinforce it.
>
> Signed-off-by: liujunjie <liujunjie23@huawei.com>
> ---
>   hw/virtio/virtio.c | 2 ++
>   1 file changed, 2 insertions(+)
>
> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
> index d4e4d98..dc8dcf8 100644
> --- a/hw/virtio/virtio.c
> +++ b/hw/virtio/virtio.c
> @@ -1604,6 +1604,8 @@ void virtio_del_queue(VirtIODevice *vdev, int n)
>   
>       vdev->vq[n].vring.num = 0;
>       vdev->vq[n].vring.num_default = 0;
> +    vdev->vq[n].handle_output = NULL;
> +    vdev->vq[n].handle_aio_output = NULL;
>   }
>   
>   static void virtio_set_isr(VirtIODevice *vdev, int value)

Applied and queued for -stable.

Thanks