virtio: fix some issues of "started" and "start_on_kick" flag
cover virtio: fix some issues of "started" and "start_on_kick" flag
From: Xie Yongji <[email protected]>
We introduced two flags "started" and "start_on_kick" to indicate virtio device's state before. But there still are some problems with them. So we try to fixup them in this patchset.
The patch 1 fixes a regression bug that old guest is not able to boot with vhost-user-blk device.
The patch 2,3,4 fix some problems with "started" and "start_on_kick" flag.
The patch 5 introduces a "use-started" property to avoid a migration issue under Greg Kurz's suggestion [1].
[1] https://lists.gnu.org/archive/html/qemu-devel/2019-05/msg06247.html
Xie Yongji (5):
virtio: Set "start_on_kick" on virtio_set_features()
virtio: Migrate the "start_on_kick" flag
virtio: Make sure we get correct state of device on
handle_aio_output()
virtio: Don't change "started" flag on virtio_vmstate_change()
virtio: add "use-started" property
hw/block/vhost-user-blk.c | 8 +++-- hw/core/machine.c | 4 ++- hw/virtio/virtio.c | 67 +++++++++++++++++++++++++++----------- include/hw/virtio/virtio.h | 10 ++++++ 4 files changed, 67 insertions(+), 22 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/5 virtio: Set "start_on_kick" on virtio_set_features()
From: Xie Yongji <[email protected]>
The guest feature is not set correctly on virtio_reset() and virtio_init(). So we should not use it to set "start_on_kick" at that point. This patch set "start_on_kick" on virtio_set_features() instead.
--- hw/virtio/virtio.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-)
hw/virtio/virtio.c +15 -10
@@ -1214,8 +1214,7 @@ void virtio_reset(void *opaque) k->reset (vdev); } - vdev->start_on_kick = (virtio_host_has_feature (vdev,VIRTIO_F_VERSION_1 ) && - !virtio_vdev_has_feature (vdev,VIRTIO_F_VERSION_1 )); + vdev->start_on_kick = false; vdev->started = false; vdev->broken = false; vdev->guest_features =0 ;
@@ -2069,14 +2068,21 @@ int virtio_set_features(VirtIODevice *vdev, uint64_t val)return -EINVAL ; } ret =virtio_set_features_nocheck (vdev, val); -if (!ret &&virtio_vdev_has_feature (vdev,VIRTIO_RING_F_EVENT_IDX )) { -/* VIRTIO_RING_F_EVENT_IDX changes the size of the caches. */ -int i; -for (i =0 ; i <VIRTIO_QUEUE_MAX ; i++) { -if (vdev->vq[i].vring.num !=0 ) { -virtio_init_region_cache (vdev, i); +if (!ret) { +if (virtio_vdev_has_feature (vdev,VIRTIO_RING_F_EVENT_IDX )) { +/* VIRTIO_RING_F_EVENT_IDX changes the size of the caches. */ +int i; +for (i =0 ; i <VIRTIO_QUEUE_MAX ; i++) { +if (vdev->vq[i].vring.num !=0 ) { +virtio_init_region_cache (vdev, i); + } } } + +if (virtio_host_has_feature (vdev,VIRTIO_F_VERSION_1 ) && + !virtio_vdev_has_feature (vdev,VIRTIO_F_VERSION_1 )) { + vdev->start_on_kick = true; + } }return ret; }
@@ -2331,8 +2337,7 @@ void virtio_init(VirtIODevice *vdev, const char *name,g_malloc0 (sizeof (*vdev->vector_queues) * nvectors); } - vdev->start_on_kick = (virtio_host_has_feature (vdev,VIRTIO_F_VERSION_1 ) && - !virtio_vdev_has_feature (vdev,VIRTIO_F_VERSION_1 )); + vdev->start_on_kick = false; vdev->started = false; vdev->device_id = device_id; vdev->status =0 ;
Signature · 1 line
2.17.1
Re: [Qemu-devel] [PATCH 1/5] virtio: Set "start_on_kick" on virtio_set_features()
Quoted 8 lines · On Wed, 29 May 2019 15:09:51 +0800 [email protected] wrote:
From: Xie Yongji <[email protected]>
The guest feature is not set correctly on
virtio_reset()andvirtio_init(). So we should not use it to set "start_on_kick" at that point. This patch set "start_on_kick" onvirtio_set_features()instead.Signed-off-by Xie Yongji <[email protected]>---
Maybe add a Fixes: badaf79cfdbd3 ?
Quoted 46 lines
hw/virtio/virtio.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-)hw/virtio/virtio.c +14
-8@@ -1214,8 +1214,7 @@ void virtio_reset(void *opaque) k->reset (vdev); } - vdev->start_on_kick = (virtio_host_has_feature (vdev,VIRTIO_F_VERSION_1 ) && - !virtio_vdev_has_feature (vdev,VIRTIO_F_VERSION_1 )); + vdev->start_on_kick = false; vdev->started = false; vdev->broken = false; vdev->guest_features =0 ;@@ -2069,14 +2068,21 @@ int virtio_set_features(VirtIODevice *vdev, uint64_t val)return -EINVAL ; } ret =virtio_set_features_nocheck (vdev, val); -if (!ret &&virtio_vdev_has_feature (vdev,VIRTIO_RING_F_EVENT_IDX )) { -/* VIRTIO_RING_F_EVENT_IDX changes the size of the caches. */ -int i; -for (i =0 ; i <VIRTIO_QUEUE_MAX ; i++) { -if (vdev->vq[i].vring.num !=0 ) { -virtio_init_region_cache (vdev, i); +if (!ret) { +if (virtio_vdev_has_feature (vdev,VIRTIO_RING_F_EVENT_IDX )) { +/* VIRTIO_RING_F_EVENT_IDX changes the size of the caches. */ +int i; +for (i =0 ; i <VIRTIO_QUEUE_MAX ; i++) { +if (vdev->vq[i].vring.num !=0 ) { +virtio_init_region_cache (vdev, i); + } } } + +if (virtio_host_has_feature (vdev,VIRTIO_F_VERSION_1 ) && + !virtio_vdev_has_feature (vdev,VIRTIO_F_VERSION_1 )) { + vdev->start_on_kick = true; + } }return ret; }
hw/virtio/virtio.c void virtio_init(VirtIODevice *vdev, const char *name, · line 2340
Quoted 6 lines
hw/virtio/virtio.c +1
-2@@ -2331,8 +2337,7 @@ void virtio_init(VirtIODevice *vdev, const char *name,g_malloc0 (sizeof (*vdev->vector_queues) * nvectors); } - vdev->start_on_kick = (virtio_host_has_feature (vdev,VIRTIO_F_VERSION_1 ) && - !virtio_vdev_has_feature (vdev,VIRTIO_F_VERSION_1 )); + vdev->start_on_kick = false;
virtio_init() is called at realize on an object that was just allocated with g_malloc0(). You shouldn't need to set anything to 0 or false... or I'm missing something ?
Anyway, I guess this doesn't hurt, so:
Quoted 3 lines
hw/virtio/virtio.c +0
-0vdev->started = false; vdev->device_id = device_id; vdev->status =0 ;
Re: [Qemu-devel] [PATCH 1/5] virtio: Set "start_on_kick" on virtio_set_features()
Quoted 6 lines · Greg Kurz
Quoted 2 lines · On Wed, 29 May 2019 15:09:51 +0800 [email protected] wrote:
From: Xie Yongji <[email protected]>
Quoted 9 lines
Quoted 6 lines
The guest feature is not set correctly on
virtio_reset()andvirtio_init(). So we should not use it to set "start_on_kick" at that point. This patch set "start_on_kick" onvirtio_set_features()instead.Signed-off-by Xie Yongji <[email protected]>---
Maybe add a Fixes:
badaf79cfdbd3?
Will add it in v2. Thanks for review.
Thanks,
Yongji
PATCH 2/5 virtio: Migrate the "start_on_kick" flag
In reply to [email protected]From: Xie Yongji <[email protected]>
We should migrate the "start_on_kick" flag so that we would not miss starting device on kicking at startup after migration.
--- hw/virtio/virtio.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
hw/virtio/virtio.c +19 -0
@@ -1802,6 +1802,13 @@ static bool virtio_started_needed(void *opaque)return vdev->started; } +static bool virtio_start_on_kick_needed (void *opaque) +{ +VirtIODevice *vdev = opaque; + +return vdev->start_on_kick; +} +static const VMStateDescription vmstate_virtqueue = { .name ="virtqueue_state" , .version_id =1 ,
@@ -1941,6 +1948,17 @@ static const VMStateDescription vmstate_virtio_started = { } }; +static const VMStateDescription vmstate_virtio_start_on_kick = { + .name ="virtio/start_on_kick" , + .version_id =1 , + .minimum_version_id =1 , + .needed = &virtio_start_on_kick_needed, + .fields = (VMStateField []) { +VMSTATE_BOOL (start_on_kick, VirtIODevice), +VMSTATE_END_OF_LIST () + } +}; +static const VMStateDescription vmstate_virtio = { .name ="virtio" , .version_id =1 ,
@@ -1957,6 +1975,7 @@ static const VMStateDescription vmstate_virtio = { &vmstate_virtio_broken, &vmstate_virtio_extra_state, &vmstate_virtio_started, + &vmstate_virtio_start_on_kick, NULL } };
Signature · 1 line
2.17.1
Re: [Qemu-devel] [PATCH 2/5] virtio: Migrate the "start_on_kick" flag
Quoted 6 lines · On Wed, 29 May 2019 15:09:52 +0800 [email protected] wrote:
From: Xie Yongji <[email protected]>
We should migrate the "
start_on_kick" flag so that we would not miss starting device on kicking at startup after migration.
Hmm... IIUC "start_on_kick" means "virtio 1.0 transitional device that has not been started yet", ie:
!vdev->started && (virtio_host_has_feature(vdev, VIRTIO_F_VERSION_1) &&
!virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1))
If so, not sure why you need this extra field in the first place, but you probably don't need to migrate it. Just recalculate in a post load callback.
Quoted 49 lines
Signed-off-by Xie Yongji <[email protected]>--- hw/virtio/virtio.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)hw/virtio/virtio.c +19
-0@@ -1802,6 +1802,13 @@ static bool virtio_started_needed(void *opaque)return vdev->started; } +static bool virtio_start_on_kick_needed (void *opaque) +{ +VirtIODevice *vdev = opaque; + +return vdev->start_on_kick; +} +static const VMStateDescription vmstate_virtqueue = { .name ="virtqueue_state" , .version_id =1 ,@@ -1941,6 +1948,17 @@ static const VMStateDescription vmstate_virtio_started = { } }; +static const VMStateDescription vmstate_virtio_start_on_kick = { + .name ="virtio/start_on_kick" , + .version_id =1 , + .minimum_version_id =1 , + .needed = &virtio_start_on_kick_needed, + .fields = (VMStateField []) { +VMSTATE_BOOL (start_on_kick, VirtIODevice), +VMSTATE_END_OF_LIST () + } +}; +static const VMStateDescription vmstate_virtio = { .name ="virtio" , .version_id =1 ,@@ -1957,6 +1975,7 @@ static const VMStateDescription vmstate_virtio = { &vmstate_virtio_broken, &vmstate_virtio_extra_state, &vmstate_virtio_started, + &vmstate_virtio_start_on_kick, NULL } };
Re: [Qemu-devel] [PATCH 2/5] virtio: Migrate the "start_on_kick" flag
Quoted 10 lines · Greg Kurz
Quoted 6 lines · On Wed, 29 May 2019 15:09:52 +0800 [email protected] wrote:
From: Xie Yongji <[email protected]>
We should migrate the "
start_on_kick" flag so that we would not miss starting device on kicking at startup after migration.
Quoted 6 lines
Hmm... IIUC "
start_on_kick" means "virtio 1.0 transitional device that has not been started yet", ie:!vdev->started && (
virtio_host_has_feature(vdev, VIRTIO_F_VERSION_1)&&
!virtio_vdev_has_feature(vdev,VIRTIO_F_VERSION_1))
Or a legacy device I guess?
Quoted 53 lines
If so, not sure why you need this extra field in the first place, but you probably don't need to migrate it. Just recalculate in a post load callback.
Quoted 49 lines
Signed-off-by Xie Yongji <[email protected]>--- hw/virtio/virtio.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)hw/virtio/virtio.c +19
-0@@ -1802,6 +1802,13 @@ static bool virtio_started_needed(void *opaque)return vdev->started; } +static bool virtio_start_on_kick_needed (void *opaque) +{ +VirtIODevice *vdev = opaque; + +return vdev->start_on_kick; +} +static const VMStateDescription vmstate_virtqueue = { .name ="virtqueue_state" , .version_id =1 ,@@ -1941,6 +1948,17 @@ static const VMStateDescription vmstate_virtio_started = { } }; +static const VMStateDescription vmstate_virtio_start_on_kick = { + .name ="virtio/start_on_kick" , + .version_id =1 , + .minimum_version_id =1 , + .needed = &virtio_start_on_kick_needed, + .fields = (VMStateField []) { +VMSTATE_BOOL (start_on_kick, VirtIODevice), +VMSTATE_END_OF_LIST () + } +}; +static const VMStateDescription vmstate_virtio = { .name ="virtio" , .version_id =1 ,@@ -1957,6 +1975,7 @@ static const VMStateDescription vmstate_virtio = { &vmstate_virtio_broken, &vmstate_virtio_extra_state, &vmstate_virtio_started, + &vmstate_virtio_start_on_kick, NULL } };
Re: [Qemu-devel] [PATCH 2/5] virtio: Migrate the "start_on_kick" flag
Quoted 11 lines · On Mon, 3 Jun 2019 17:03:06 -0400 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 10 lines · Greg Kurz
Quoted 6 lines · On Wed, 29 May 2019 15:09:52 +0800 [email protected] wrote:
From: Xie Yongji <[email protected]>
We should migrate the "
start_on_kick" flag so that we would not miss starting device on kicking at startup after migration.
Quoted 9 lines
Quoted 6 lines
Hmm... IIUC "
start_on_kick" means "virtio 1.0 transitional device that has not been started yet", ie:!vdev->started && (
virtio_host_has_feature(vdev, VIRTIO_F_VERSION_1)&&
!virtio_vdev_has_feature(vdev,VIRTIO_F_VERSION_1))Or a legacy device I guess?
Do you mean "start_on_kick" should be set for both legacy and virtio 1.0 transitional devices ?
Quoted 53 lines
Quoted 53 lines
If so, not sure why you need this extra field in the first place, but you probably don't need to migrate it. Just recalculate in a post load callback.
Quoted 49 lines
Signed-off-by Xie Yongji <[email protected]>--- hw/virtio/virtio.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)hw/virtio/virtio.c +19
-0@@ -1802,6 +1802,13 @@ static bool virtio_started_needed(void *opaque)return vdev->started; } +static bool virtio_start_on_kick_needed (void *opaque) +{ +VirtIODevice *vdev = opaque; + +return vdev->start_on_kick; +} +static const VMStateDescription vmstate_virtqueue = { .name ="virtqueue_state" , .version_id =1 ,@@ -1941,6 +1948,17 @@ static const VMStateDescription vmstate_virtio_started = { } }; +static const VMStateDescription vmstate_virtio_start_on_kick = { + .name ="virtio/start_on_kick" , + .version_id =1 , + .minimum_version_id =1 , + .needed = &virtio_start_on_kick_needed, + .fields = (VMStateField []) { +VMSTATE_BOOL (start_on_kick, VirtIODevice), +VMSTATE_END_OF_LIST () + } +}; +static const VMStateDescription vmstate_virtio = { .name ="virtio" , .version_id =1 ,@@ -1957,6 +1975,7 @@ static const VMStateDescription vmstate_virtio = { &vmstate_virtio_broken, &vmstate_virtio_extra_state, &vmstate_virtio_started, + &vmstate_virtio_start_on_kick, NULL } };
Re: [Qemu-devel] [PATCH 2/5] virtio: Migrate the "start_on_kick" flag
Quoted 21 lines · Greg Kurz
Quoted 18 lines · On Mon, 3 Jun 2019 17:03:06 -0400 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 16 lines · Greg Kurz
Quoted 6 lines · On Wed, 29 May 2019 15:09:52 +0800 [email protected] wrote:
From: Xie Yongji <[email protected]>
We should migrate the "
start_on_kick" flag so that we would not miss starting device on kicking at startup after migration.Hmm... IIUC "
start_on_kick" means "virtio 1.0 transitional device that has not been started yet", ie:!vdev->started && (
virtio_host_has_feature(vdev, VIRTIO_F_VERSION_1)&&
!virtio_vdev_has_feature(vdev,VIRTIO_F_VERSION_1))
Quoted 5 lines
Quoted 2 lines
Or a legacy device I guess?
Do you mean "
start_on_kick" should be set for both legacy and virtio 1.0 transitional devices ?
Yes - generally when virtio 1 feature has not
been negotiated.
Quoted 53 lines
Quoted 53 lines
Quoted 53 lines
If so, not sure why you need this extra field in the first place, but you probably don't need to migrate it. Just recalculate in a post load callback.
Quoted 49 lines
Signed-off-by Xie Yongji <[email protected]>--- hw/virtio/virtio.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)hw/virtio/virtio.c +19
-0@@ -1802,6 +1802,13 @@ static bool virtio_started_needed(void *opaque)return vdev->started; } +static bool virtio_start_on_kick_needed (void *opaque) +{ +VirtIODevice *vdev = opaque; + +return vdev->start_on_kick; +} +static const VMStateDescription vmstate_virtqueue = { .name ="virtqueue_state" , .version_id =1 ,@@ -1941,6 +1948,17 @@ static const VMStateDescription vmstate_virtio_started = { } }; +static const VMStateDescription vmstate_virtio_start_on_kick = { + .name ="virtio/start_on_kick" , + .version_id =1 , + .minimum_version_id =1 , + .needed = &virtio_start_on_kick_needed, + .fields = (VMStateField []) { +VMSTATE_BOOL (start_on_kick, VirtIODevice), +VMSTATE_END_OF_LIST () + } +}; +static const VMStateDescription vmstate_virtio = { .name ="virtio" , .version_id =1 ,@@ -1957,6 +1975,7 @@ static const VMStateDescription vmstate_virtio = { &vmstate_virtio_broken, &vmstate_virtio_extra_state, &vmstate_virtio_started, + &vmstate_virtio_start_on_kick, NULL } };
Re: [Qemu-devel] [PATCH 2/5] virtio: Migrate the "start_on_kick" flag
In reply to Greg KurzQuoted 14 lines · Greg Kurz
Quoted 6 lines · On Wed, 29 May 2019 15:09:52 +0800 [email protected] wrote:
From: Xie Yongji <[email protected]>
We should migrate the "
start_on_kick" flag so that we would not miss starting device on kicking at startup after migration.Hmm... IIUC "
start_on_kick" means "virtio 1.0 transitional device that has not been started yet", ie:
Quoted 8 lines
!vdev->started && (
virtio_host_has_feature(vdev, VIRTIO_F_VERSION_1)&&
!virtio_vdev_has_feature(vdev,VIRTIO_F_VERSION_1))If so, not sure why you need this extra field in the first place, but you probably don't need to migrate it. Just recalculate in a post load callback.
Good idea! Will recalculate this in virtio_load() in v2. Thank you.
Thanks,
Yongji
PATCH 3/5 virtio: Make sure we get correct state of device on handle_aio_output()
In reply to [email protected]From: Xie Yongji <[email protected]>
We should set the flags: "start_on_kick" and "started" after we call the kick functions (handle_aio_output() and handle_output()).
--- hw/virtio/virtio.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
hw/virtio/virtio.c +4 -4
@@ -1575,11 +1575,11 @@ void virtio_queue_notify(VirtIODevice *vdev, int n)event_notifier_set (&vq->host_notifier); }else if (vq->handle_output) { vq->handle_output (vdev, vq); - } -if (unlikely (vdev->start_on_kick)) { - vdev->started = true; - vdev->start_on_kick = false; +if (unlikely (vdev->start_on_kick)) { + vdev->started = true; + vdev->start_on_kick = false; + } } }
Signature · 1 line
2.17.1
PATCH 4/5 virtio: Don't change "started" flag on virtio_vmstate_change()
In reply to [email protected]From: Xie Yongji <[email protected]>
We will call virtio_set_status() on virtio_vmstate_change(). The "started" flag should not be changed in this case. Otherwise, we may get an incorrect value when we set "started" flag but not set DRIVER_OK in source VM.
--- hw/virtio/virtio.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
hw/virtio/virtio.c +7 -3
@@ -1162,9 +1162,13 @@ int virtio_set_status(VirtIODevice *vdev, uint8_t val) } } } - vdev->started = val &VIRTIO_CONFIG_S_DRIVER_OK ; -if (unlikely (vdev->start_on_kick && vdev->started)) { - vdev->start_on_kick = false; + +if ((vdev->status &VIRTIO_CONFIG_S_DRIVER_OK ) != + (val &VIRTIO_CONFIG_S_DRIVER_OK )) { + vdev->started = val &VIRTIO_CONFIG_S_DRIVER_OK ; +if (unlikely (vdev->start_on_kick && vdev->started)) { + vdev->start_on_kick = false; + } }if (k->set_status) {
Signature · 1 line
2.17.1
PATCH 5/5 virtio: add "use-started" property
In reply to [email protected]From: Xie Yongji <[email protected]>
In order to avoid migration issues, we introduce a "use-started" property to the base virtio device to indicate whether "started" and "start_on_kick" flag could be used. This property will be true by default and set to false when machine type <= 4.0.
--- hw/block/vhost-user-blk.c | 8 ++++++-- hw/core/machine.c | 4 +++- hw/virtio/virtio.c | 7 ++++--- include/hw/virtio/virtio.h | 10 ++++++++++ 4 files changed, 23 insertions(+), 6 deletions(-)
hw/block/vhost-user-blk.c +6 -2
@@ -191,9 +191,13 @@ static void vhost_user_blk_stop(VirtIODevice *vdev)static void vhost_user_blk_set_status (VirtIODevice *vdev,uint8_t status) {VHostUserBlk *s =VHOST_USER_BLK (vdev); -bool should_start = vdev->started; +bool should_start = status &VIRTIO_CONFIG_S_DRIVER_OK ;int ret; +if (virtio_device_started (vdev)) { + should_start = true; + } +if (!vdev->vm_running) { should_start = false; }
@@ -317,7 +321,7 @@ static int vhost_user_blk_connect(DeviceState *dev) }/* restore vhost state */ -if (vdev->started) { +if (virtio_device_started (vdev)) { ret =vhost_user_blk_start (vdev);if (ret <0 ) { error_report("vhost-user-blk: vhost start failed: %s",
hw/core/machine.c +3 -1
@@ -24,7 +24,9 @@#include "hw/pci/pci.h" #include "hw/mem/nvdimm.h" -GlobalProperty hw_compat_4_0[] = {}; +GlobalProperty hw_compat_4_0[] = { + {"virtio-device" ,"use-started" ,"false" }, +};const size_t hw_compat_4_0_len =G_N_ELEMENTS (hw_compat_4_0);GlobalProperty hw_compat_3_1[] = {
hw/virtio/virtio.c +4 -3
@@ -1803,14 +1803,14 @@ static bool virtio_started_needed(void *opaque) {VirtIODevice *vdev = opaque; -return vdev->started; +return vdev->started && vdev->use_started; }static bool virtio_start_on_kick_needed (void *opaque) {VirtIODevice *vdev = opaque; -return vdev->start_on_kick; +return vdev->start_on_kick && vdev->use_started; }static const VMStateDescription vmstate_virtqueue = {
@@ -2320,7 +2320,7 @@ static void virtio_vmstate_change(void *opaque, int running, RunState state)VirtIODevice *vdev = opaque;BusState *qbus =qdev_get_parent_bus (DEVICE (vdev));VirtioBusClass *k =VIRTIO_BUS_GET_CLASS (qbus); -bool backend_run = running && vdev->started; +bool backend_run = running &&virtio_device_started (vdev); vdev->vm_running = running;if (backend_run) {
@@ -2698,6 +2698,7 @@ static void virtio_device_instance_finalize(Object *obj)static Property virtio_properties[] = {DEFINE_VIRTIO_COMMON_FEATURES (VirtIODevice, host_features), +DEFINE_PROP_BOOL ("use-started" , VirtIODevice, use_started, true),DEFINE_PROP_END_OF_LIST (), };
include/hw/virtio/virtio.h +10 -0
@@ -105,6 +105,7 @@ struct VirtIODeviceuint16_t device_id;bool vm_running;bool broken;/* device in invalid state, needs reset */ +bool use_started;bool started;bool start_on_kick;/* virtio 1.0 transitional devices support that */ VMChangeStateEntry *vmstate;
@@ -351,4 +352,13 @@ static inline bool virtio_is_big_endian(VirtIODevice *vdev)/* Devices conforming to VIRTIO 1.0 or later are always LE. */ return false; } + +static inline bool virtio_device_started (VirtIODevice *vdev) +{ +if (vdev->use_started) { +return vdev->started; + } + +return vdev->status &VIRTIO_CONFIG_S_DRIVER_OK ; +}#endif
Signature · 1 line
2.17.1
Re: [Qemu-devel] [PATCH 5/5] virtio: add "use-started" property
Quoted 21 lines · On Wed, 29 May 2019 15:09:55 +0800 [email protected] wrote:
From: Xie Yongji <[email protected]>
In order to avoid migration issues, we introduce a "use-started" property to the base virtio device to indicate whether "started" and "
start_on_kick" flag could be used. This property will be true by default and set to false when machine type <= 4.0.Suggested-by Greg Kurz <[email protected]>Signed-off-by Xie Yongji <[email protected]>--- hw/block/vhost-user-blk.c | 8 ++++++-- hw/core/machine.c | 4 +++- hw/virtio/virtio.c | 7 ++++--- include/hw/virtio/virtio.h | 10 ++++++++++ 4 files changed, 23 insertions(+), 6 deletions(-)hw/block/vhost-user-blk.c +0
-0
hw/block/vhost-user-blk.c static void vhost_user_blk_stop(VirtIODevice *vdev) · line 194
Quoted 5 lines
hw/block/vhost-user-blk.c +1
-1@@ -191,9 +191,13 @@ static void vhost_user_blk_stop(VirtIODevice *vdev)static void vhost_user_blk_set_status (VirtIODevice *vdev,uint8_t status) {VHostUserBlk *s =VHOST_USER_BLK (vdev); -bool should_start = vdev->started; +bool should_start = status &VIRTIO_CONFIG_S_DRIVER_OK ;
I guess you need the above because the set_status callback is called before setting vdev->status, and virtio_device_started() thus doesn't return the expected result for older machine types ?
What about adding a status argument to virtio_device_started() ?
bool should_start = virtio_device_started(vdev, status);
Quoted 10 lines
hw/block/vhost-user-blk.c +4
-0int ret; +if (virtio_device_started (vdev)) { + should_start = true; + } +if (!vdev->vm_running) { should_start = false; }
hw/block/vhost-user-blk.c static int vhost_user_blk_connect(DeviceState *dev) · line 324
Quoted 5 lines
hw/block/vhost-user-blk.c +1
-1@@ -317,7 +321,7 @@ static int vhost_user_blk_connect(DeviceState *dev) }/* restore vhost state */ -if (vdev->started) { +if (virtio_device_started (vdev)) {
if (virtio_device_started(vdev, vdev->status)) {and so on...
Quoted 23 lines
hw/block/vhost-user-blk.c +0
-0ret =vhost_user_blk_start (vdev);if (ret <0 ) { error_report("vhost-user-blk: vhost start failed: %s",hw/core/machine.c +3
-1@@ -24,7 +24,9 @@#include "hw/pci/pci.h" #include "hw/mem/nvdimm.h" -GlobalProperty hw_compat_4_0[] = {}; +GlobalProperty hw_compat_4_0[] = { + {"virtio-device" ,"use-started" ,"false" }, +};const size_t hw_compat_4_0_len =G_N_ELEMENTS (hw_compat_4_0);GlobalProperty hw_compat_3_1[] = {hw/virtio/virtio.c +0
-0
hw/virtio/virtio.c static bool virtio_started_needed(void *opaque) · line 1806
Quoted 5 lines
hw/virtio/virtio.c +1
-1@@ -1803,14 +1803,14 @@ static bool virtio_started_needed(void *opaque) {VirtIODevice *vdev = opaque; -return vdev->started; +return vdev->started && vdev->use_started;
Hmm... the idea is that vdev->started should never be set when "use-started" is "off". Instead of checking vdev->use_started here, you should rather assign it to vdev->started everywhere you currently assign true.
Quoted 54 lines
hw/virtio/virtio.c +3
-2}static bool virtio_start_on_kick_needed (void *opaque) {VirtIODevice *vdev = opaque; -return vdev->start_on_kick; +return vdev->start_on_kick && vdev->use_started; }static const VMStateDescription vmstate_virtqueue = {@@ -2320,7 +2320,7 @@ static void virtio_vmstate_change(void *opaque, int running, RunState state)VirtIODevice *vdev = opaque;BusState *qbus =qdev_get_parent_bus (DEVICE (vdev));VirtioBusClass *k =VIRTIO_BUS_GET_CLASS (qbus); -bool backend_run = running && vdev->started; +bool backend_run = running &&virtio_device_started (vdev); vdev->vm_running = running;if (backend_run) {@@ -2698,6 +2698,7 @@ static void virtio_device_instance_finalize(Object *obj)static Property virtio_properties[] = {DEFINE_VIRTIO_COMMON_FEATURES (VirtIODevice, host_features), +DEFINE_PROP_BOOL ("use-started" , VirtIODevice, use_started, true),DEFINE_PROP_END_OF_LIST (), };include/hw/virtio/virtio.h +10
-0@@ -105,6 +105,7 @@ struct VirtIODeviceuint16_t device_id;bool vm_running;bool broken;/* device in invalid state, needs reset */ +bool use_started;bool started;bool start_on_kick;/* virtio 1.0 transitional devices support that */ VMChangeStateEntry *vmstate;@@ -351,4 +352,13 @@ static inline bool virtio_is_big_endian(VirtIODevice *vdev)/* Devices conforming to VIRTIO 1.0 or later are always LE. */ return false; } + +static inline bool virtio_device_started (VirtIODevice *vdev) +{ +if (vdev->use_started) { +return vdev->started; + } + +return vdev->status &VIRTIO_CONFIG_S_DRIVER_OK ; +}#endif
Re: [Qemu-devel] [PATCH 5/5] virtio: add "use-started" property
Quoted 20 lines · Greg Kurz
Quoted 16 lines · On Wed, 29 May 2019 15:09:55 +0800 [email protected] wrote:
From: Xie Yongji <[email protected]>
In order to avoid migration issues, we introduce a "use-started" property to the base virtio device to indicate whether "started" and "
start_on_kick" flag could be used. This property will be true by default and set to false when machine type <= 4.0.Suggested-by Greg Kurz <[email protected]>Signed-off-by Xie Yongji <[email protected]>--- hw/block/vhost-user-blk.c | 8 ++++++-- hw/core/machine.c | 4 +++- hw/virtio/virtio.c | 7 ++++--- include/hw/virtio/virtio.h | 10 ++++++++++ 4 files changed, 23 insertions(+), 6 deletions(-)
Quoted 15 lines
hw/block/vhost-user-blk.c static void vhost_user_blk_stop(VirtIODevice *vdev) · line 194
Quoted 10 lines
hw/block/vhost-user-blk.c +1
-1@@ -191,9 +191,13 @@ static void vhost_user_blk_stop(VirtIODevice *vdev)static void vhost_user_blk_set_status (VirtIODevice *vdev,uint8_t status) {VHostUserBlk *s =VHOST_USER_BLK (vdev); -bool should_start = vdev->started; +bool should_start = status &VIRTIO_CONFIG_S_DRIVER_OK ;I guess you need the above because the
set_statuscallback is called before settingvdev->status, andvirtio_device_started()thus doesn't return the expected result for older machine types ?
Yes, that's case.
Quoted 4 lines
What about adding a status argument to
virtio_device_started()?bool should_start = virtio_device_started(vdev, status);
Looks fine to me.
Quoted 46 lines
Quoted 10 lines
hw/block/vhost-user-blk.c +4
-0int ret; +if (virtio_device_started (vdev)) { + should_start = true; + } +if (!vdev->vm_running) { should_start = false; }hw/block/vhost-user-blk.c static int vhost_user_blk_connect(DeviceState *dev) · line 324
Quoted 5 lines
hw/block/vhost-user-blk.c +1
-1@@ -317,7 +321,7 @@ static int vhost_user_blk_connect(DeviceState *dev) }/* restore vhost state */ -if (vdev->started) { +if (virtio_device_started (vdev)) {if (virtio_device_started(vdev, vdev->status)) {and so on...
Quoted 26 lines
hw/block/vhost-user-blk.c +0
-0ret =vhost_user_blk_start (vdev);if (ret <0 ) { error_report("vhost-user-blk: vhost start failed: %s",hw/core/machine.c +3
-1@@ -24,7 +24,9 @@#include "hw/pci/pci.h" #include "hw/mem/nvdimm.h" -GlobalProperty hw_compat_4_0[] = {}; +GlobalProperty hw_compat_4_0[] = { + {"virtio-device" ,"use-started" ,"false" }, +};const size_t hw_compat_4_0_len =G_N_ELEMENTS (hw_compat_4_0);GlobalProperty hw_compat_3_1[] = {hw/virtio/virtio.c +0
-0@@ -1803,14 +1803,14 @@ static bool virtio_started_needed(void *opaque) {VirtIODevice *vdev = opaque;
Quoted 8 lines
hw/virtio/virtio.c static bool virtio_started_needed(void *opaque) · line 1806
Quoted 2 lines
hw/virtio/virtio.c +1
-1-return vdev->started; +return vdev->started && vdev->use_started;Hmm... the idea is that
vdev->startedshould never be set when "use-started" is "off". Instead of checkingvdev->use_startedhere, you should rather assign it tovdev->startedeverywhere you currently assign true.
Will do it in v2.
Thanks,
Yongji