All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] vhost-user-blk: start vhost when guest kicks
@ 2018-06-05 13:56 Yongji Xie
  2018-06-05 14:23 ` Michael S. Tsirkin
  0 siblings, 1 reply; 3+ messages in thread
From: Yongji Xie @ 2018-06-05 13:56 UTC (permalink / raw)
  To: mst, stefanha, changpeng.liu; +Cc: qemu-devel, chaiwen, nixun, elohimes

Some old guests (before commit 7a11370e5: "virtio_blk: enable VQs early")
kick virtqueue before setting VIRTIO_CONFIG_S_DRIVER_OK. This would cause
that those old guests fail to boot with vhost-user-blk device.

To fix it, start vhost when guest kicks instead of waiting for .set_status().

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 |   20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c
index d755223..8fd0e6f 100644
--- a/hw/block/vhost-user-blk.c
+++ b/hw/block/vhost-user-blk.c
@@ -217,7 +217,27 @@ 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 (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

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

* Re: [Qemu-devel] [PATCH] vhost-user-blk: start vhost when guest kicks
  2018-06-05 13:56 [Qemu-devel] [PATCH] vhost-user-blk: start vhost when guest kicks Yongji Xie
@ 2018-06-05 14:23 ` Michael S. Tsirkin
  2018-06-06  3:43   ` Yongji Xie
  0 siblings, 1 reply; 3+ messages in thread
From: Michael S. Tsirkin @ 2018-06-05 14:23 UTC (permalink / raw)
  To: Yongji Xie; +Cc: stefanha, changpeng.liu, qemu-devel, chaiwen, nixun

On Tue, Jun 05, 2018 at 09:56:10PM +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 would cause
> that those old guests fail to boot with vhost-user-blk device.
> 
> To fix it, start vhost when guest kicks instead of waiting for .set_status().
> 
> Signed-off-by: Yongji Xie <xieyongji@baidu.com>
> Signed-off-by: Chai Wen <chaiwen@baidu.com>
> Signed-off-by: Ni Xun <nixun@baidu.com>

Can we at least limit this to when virtio 1.0 has not
been negotiated?

> ---
>  hw/block/vhost-user-blk.c |   20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
> 
> diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c
> index d755223..8fd0e6f 100644
> --- a/hw/block/vhost-user-blk.c
> +++ b/hw/block/vhost-user-blk.c
> @@ -217,7 +217,27 @@ 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 (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

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

* Re: [Qemu-devel] [PATCH] vhost-user-blk: start vhost when guest kicks
  2018-06-05 14:23 ` Michael S. Tsirkin
@ 2018-06-06  3:43   ` Yongji Xie
  0 siblings, 0 replies; 3+ messages in thread
From: Yongji Xie @ 2018-06-06  3:43 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: stefanha, changpeng.liu, qemu-devel, chaiwen, nixun

On 5 June 2018 at 22:23, Michael S. Tsirkin <mst@redhat.com> wrote:
> On Tue, Jun 05, 2018 at 09:56:10PM +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 would cause
>> that those old guests fail to boot with vhost-user-blk device.
>>
>> To fix it, start vhost when guest kicks instead of waiting for .set_status().
>>
>> Signed-off-by: Yongji Xie <xieyongji@baidu.com>
>> Signed-off-by: Chai Wen <chaiwen@baidu.com>
>> Signed-off-by: Ni Xun <nixun@baidu.com>
>
> Can we at least limit this to when virtio 1.0 has not
> been negotiated?
>

OK, I will limit this to when driver is v0.9.x and device is v1.0 so
we don't violate the spec.

Thanks,
Yongji

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

end of thread, other threads:[~2018-06-06  3:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-05 13:56 [Qemu-devel] [PATCH] vhost-user-blk: start vhost when guest kicks Yongji Xie
2018-06-05 14:23 ` Michael S. Tsirkin
2018-06-06  3:43   ` Yongji Xie

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.