[Qemu-devel] [PATCH v2] vhost-user-blk: start vhost when guest kicks

Yongji Xie posted 1 patch 5 years, 10 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/1528291488-2586-1-git-send-email-xieyongji@baidu.com
Test checkpatch passed
Test docker-mingw@fedora passed
Test docker-quick@centos7 passed
Test s390x passed
hw/block/vhost-user-blk.c |   25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
[Qemu-devel] [PATCH v2] vhost-user-blk: start vhost when guest kicks
Posted by Yongji Xie 5 years, 10 months ago
Some old guests (before commit 7a11370e5: "virtio_blk: enable VQs early")
kick virtqueue before setting VIRTIO_CONFIG_S_DRIVER_OK. This violates
the virtio spec. But virtio 1.0 transitional devices support this behaviour.
So we should start vhost when guest kicks in this case.

Signed-off-by: Yongji Xie <xieyongji@baidu.com>
Signed-off-by: Chai Wen <chaiwen@baidu.com>
Signed-off-by: Ni Xun <nixun@baidu.com>
---
 hw/block/vhost-user-blk.c |   25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c
index d755223..1451940 100644
--- a/hw/block/vhost-user-blk.c
+++ b/hw/block/vhost-user-blk.c
@@ -217,7 +217,32 @@ static uint64_t vhost_user_blk_get_features(VirtIODevice *vdev,
 
 static void vhost_user_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq)
 {
+    VHostUserBlk *s = VHOST_USER_BLK(vdev);
+    int i;
+
+    if (!(virtio_host_has_feature(vdev, VIRTIO_F_VERSION_1) &&
+        !virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1))) {
+        return;
+    }
+
+    if (s->dev.started) {
+        return;
+    }
+
+    /* Some guests kick before setting VIRTIO_CONFIG_S_DRIVER_OK so start
+     * vhost here instead of waiting for .set_status().
+     */
+    vhost_user_blk_start(vdev);
 
+    /* Kick right away to begin processing requests already in vring */
+    for (i = 0; i < s->dev.nvqs; i++) {
+        VirtQueue *kick_vq = virtio_get_queue(vdev, i);
+
+        if (!virtio_queue_get_desc_addr(vdev, i)) {
+            continue;
+        }
+        event_notifier_set(virtio_queue_get_host_notifier(kick_vq));
+    }
 }
 
 static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp)
-- 
1.7.9.5


Re: [Qemu-devel] [PATCH v2] vhost-user-blk: start vhost when guest kicks
Posted by Stefan Hajnoczi 5 years, 10 months ago
On Wed, Jun 06, 2018 at 09:24:48PM +0800, Yongji Xie wrote:
> Some old guests (before commit 7a11370e5: "virtio_blk: enable VQs early")
> kick virtqueue before setting VIRTIO_CONFIG_S_DRIVER_OK. This violates
> the virtio spec. But virtio 1.0 transitional devices support this behaviour.
> So we should start vhost when guest kicks in this case.
> 
> Signed-off-by: Yongji Xie <xieyongji@baidu.com>
> Signed-off-by: Chai Wen <chaiwen@baidu.com>
> Signed-off-by: Ni Xun <nixun@baidu.com>
> ---
>  hw/block/vhost-user-blk.c |   25 +++++++++++++++++++++++++
>  1 file changed, 25 insertions(+)

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Re: [Qemu-devel] [PATCH v2] vhost-user-blk: start vhost when guest kicks
Posted by Yongji Xie 5 years, 7 months ago
Kindly ping...

On Thu, 7 Jun 2018 at 20:50, Stefan Hajnoczi <stefanha@gmail.com> wrote:
>
> On Wed, Jun 06, 2018 at 09:24:48PM +0800, Yongji Xie wrote:
> > Some old guests (before commit 7a11370e5: "virtio_blk: enable VQs early")
> > kick virtqueue before setting VIRTIO_CONFIG_S_DRIVER_OK. This violates
> > the virtio spec. But virtio 1.0 transitional devices support this behaviour.
> > So we should start vhost when guest kicks in this case.
> >
> > Signed-off-by: Yongji Xie <xieyongji@baidu.com>
> > Signed-off-by: Chai Wen <chaiwen@baidu.com>
> > Signed-off-by: Ni Xun <nixun@baidu.com>
> > ---
> >  hw/block/vhost-user-blk.c |   25 +++++++++++++++++++++++++
> >  1 file changed, 25 insertions(+)
>
> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>