[RFC PATCH] virtio: Change order of appling runstate to device and bus

Anton Kuchin posted 1 patch 4 years, 4 months ago
Test asan failed
Test checkpatch failed
Test FreeBSD failed
Test docker-mingw@fedora failed
Test docker-clang@ubuntu failed
Test docker-quick@centos7 failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20191220125245.7679-1-antonkuchin@yandex-team.ru
Maintainers: "Michael S. Tsirkin" <mst@redhat.com>
hw/virtio/virtio.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[RFC PATCH] virtio: Change order of appling runstate to device and bus
Posted by Anton Kuchin 4 years, 4 months ago
On transition to running first apply state to bus and then to device
so device can access bus functions correctly. When going to stopped
notify device first and then the bus.

Signed-off-by: Anton Kuchin <antonkuchin@yandex-team.ru>
---
 hw/virtio/virtio.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 04716b5f6c..2ea2edba10 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -3096,7 +3096,7 @@ static void virtio_vmstate_change(void *opaque, int running, RunState state)
     bool backend_run = running && virtio_device_started(vdev, vdev->status);
     vdev->vm_running = running;
 
-    if (backend_run) {
+    if (!backend_run) {
         virtio_set_status(vdev, vdev->status);
     }
 
@@ -3104,7 +3104,7 @@ static void virtio_vmstate_change(void *opaque, int running, RunState state)
         k->vmstate_change(qbus->parent, backend_run);
     }
 
-    if (!backend_run) {
+    if (backend_run) {
         virtio_set_status(vdev, vdev->status);
     }
 }
-- 
2.20.1


Re: [RFC PATCH] virtio: Change order of appling runstate to device and bus
Posted by Michael S. Tsirkin 4 years, 3 months ago
On Fri, Dec 20, 2019 at 03:52:45PM +0300, Anton Kuchin wrote:
> On transition to running first apply state to bus and then to device
> so device can access bus functions correctly. When going to stopped
> notify device first and then the bus.
> 
> Signed-off-by: Anton Kuchin <antonkuchin@yandex-team.ru>

I kind of like this but this has the potential to break lots of things.
How was this tested?

> ---
>  hw/virtio/virtio.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
> index 04716b5f6c..2ea2edba10 100644
> --- a/hw/virtio/virtio.c
> +++ b/hw/virtio/virtio.c
> @@ -3096,7 +3096,7 @@ static void virtio_vmstate_change(void *opaque, int running, RunState state)
>      bool backend_run = running && virtio_device_started(vdev, vdev->status);
>      vdev->vm_running = running;
>  
> -    if (backend_run) {
> +    if (!backend_run) {
>          virtio_set_status(vdev, vdev->status);
>      }
>  
> @@ -3104,7 +3104,7 @@ static void virtio_vmstate_change(void *opaque, int running, RunState state)
>          k->vmstate_change(qbus->parent, backend_run);
>      }
>  
> -    if (!backend_run) {
> +    if (backend_run) {
>          virtio_set_status(vdev, vdev->status);
>      }
>  }
> -- 
> 2.20.1