All the callbacks below are always running in the main loop.
The callbacks are the following:
- start/stop_ioeventfd: these are the callbacks where
blk_set_aio_context(iothread) is done, so they are called in the main
loop.
- save and load: called during migration, when VM is stopped from the
main loop.
- reset: before calling this callback, stop_ioeventfd is invoked, so
it can only run in the main loop.
- set_status: going through all the callers we can see it is called
from a MemoryRegionOps callback, which always run in the main loop.
- realize: iothread is not even created yet.
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
---
hw/block/virtio-blk.c | 2 ++
hw/virtio/virtio-bus.c | 5 +++++
hw/virtio/virtio-pci.c | 2 ++
hw/virtio/virtio.c | 8 ++++++++
4 files changed, 17 insertions(+)
diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
index 29a9c53ebc..4e6421c35e 100644
--- a/hw/block/virtio-blk.c
+++ b/hw/block/virtio-blk.c
@@ -1032,6 +1032,8 @@ static void virtio_blk_set_status(VirtIODevice *vdev, uint8_t status)
{
VirtIOBlock *s = VIRTIO_BLK(vdev);
+ GLOBAL_STATE_CODE();
+
if (!(status & (VIRTIO_CONFIG_S_DRIVER | VIRTIO_CONFIG_S_DRIVER_OK))) {
assert(!s->dataplane_started);
}
diff --git a/hw/virtio/virtio-bus.c b/hw/virtio/virtio-bus.c
index d7ec023adf..0891ddb2ff 100644
--- a/hw/virtio/virtio-bus.c
+++ b/hw/virtio/virtio-bus.c
@@ -23,6 +23,7 @@
*/
#include "qemu/osdep.h"
+#include "qemu/main-loop.h"
#include "qemu/error-report.h"
#include "qemu/module.h"
#include "qapi/error.h"
@@ -223,6 +224,8 @@ int virtio_bus_start_ioeventfd(VirtioBusState *bus)
VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev);
int r;
+ GLOBAL_STATE_CODE();
+
if (!k->ioeventfd_assign || !k->ioeventfd_enabled(proxy)) {
return -ENOSYS;
}
@@ -247,6 +250,8 @@ void virtio_bus_stop_ioeventfd(VirtioBusState *bus)
VirtIODevice *vdev;
VirtioDeviceClass *vdc;
+ GLOBAL_STATE_CODE();
+
if (!bus->ioeventfd_started) {
return;
}
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index 0566ad7d00..6798039391 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -301,6 +301,8 @@ static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val)
VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
hwaddr pa;
+ GLOBAL_STATE_CODE();
+
switch (addr) {
case VIRTIO_PCI_GUEST_FEATURES:
/* Guest does not negotiate properly? We have to assume nothing. */
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 5d607aeaa0..2650504dd4 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -1977,6 +1977,8 @@ int virtio_set_status(VirtIODevice *vdev, uint8_t val)
VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
trace_virtio_set_status(vdev, val);
+ GLOBAL_STATE_CODE();
+
if (virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1)) {
if (!(vdev->status & VIRTIO_CONFIG_S_FEATURES_OK) &&
val & VIRTIO_CONFIG_S_FEATURES_OK) {
@@ -2025,6 +2027,8 @@ void virtio_reset(void *opaque)
VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
int i;
+ GLOBAL_STATE_CODE();
+
virtio_set_status(vdev, 0);
if (current_cpu) {
/* Guest initiated reset */
@@ -2882,6 +2886,8 @@ int virtio_save(VirtIODevice *vdev, QEMUFile *f)
uint32_t guest_features_lo = (vdev->guest_features & 0xffffffff);
int i;
+ GLOBAL_STATE_CODE();
+
if (k->save_config) {
k->save_config(qbus->parent, f);
}
@@ -3024,6 +3030,8 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id)
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev);
+ GLOBAL_STATE_CODE();
+
/*
* We poison the endianness to ensure it does not get used before
* subsections have been loaded.
--
2.31.1
On Thu, Jun 09, 2022 at 10:37:23AM -0400, Emanuele Giuseppe Esposito wrote: > All the callbacks below are always running in the main loop. > > The callbacks are the following: > - start/stop_ioeventfd: these are the callbacks where > blk_set_aio_context(iothread) is done, so they are called in the main > loop. > > - save and load: called during migration, when VM is stopped from the > main loop. > > - reset: before calling this callback, stop_ioeventfd is invoked, so > it can only run in the main loop. > > - set_status: going through all the callers we can see it is called > from a MemoryRegionOps callback, which always run in the main loop. > > - realize: iothread is not even created yet. > > Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com> > --- > hw/block/virtio-blk.c | 2 ++ > hw/virtio/virtio-bus.c | 5 +++++ > hw/virtio/virtio-pci.c | 2 ++ > hw/virtio/virtio.c | 8 ++++++++ > 4 files changed, 17 insertions(+) Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
On Thu, Jun 09, 2022 at 10:37:23AM -0400, Emanuele Giuseppe Esposito wrote:
> All the callbacks below are always running in the main loop.
>
> The callbacks are the following:
> - start/stop_ioeventfd: these are the callbacks where
> blk_set_aio_context(iothread) is done, so they are called in the main
> loop.
>
> - save and load: called during migration, when VM is stopped from the
> main loop.
>
> - reset: before calling this callback, stop_ioeventfd is invoked, so
> it can only run in the main loop.
>
> - set_status: going through all the callers we can see it is called
> from a MemoryRegionOps callback, which always run in the main loop.
>
> - realize: iothread is not even created yet.
>
> Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
> ---
> hw/block/virtio-blk.c | 2 ++
> hw/virtio/virtio-bus.c | 5 +++++
> hw/virtio/virtio-pci.c | 2 ++
> hw/virtio/virtio.c | 8 ++++++++
> 4 files changed, 17 insertions(+)
>
> diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
> index 29a9c53ebc..4e6421c35e 100644
> --- a/hw/block/virtio-blk.c
> +++ b/hw/block/virtio-blk.c
> @@ -1032,6 +1032,8 @@ static void virtio_blk_set_status(VirtIODevice *vdev, uint8_t status)
> {
> VirtIOBlock *s = VIRTIO_BLK(vdev);
>
> + GLOBAL_STATE_CODE();
> +
> if (!(status & (VIRTIO_CONFIG_S_DRIVER | VIRTIO_CONFIG_S_DRIVER_OK))) {
> assert(!s->dataplane_started);
> }
> diff --git a/hw/virtio/virtio-bus.c b/hw/virtio/virtio-bus.c
> index d7ec023adf..0891ddb2ff 100644
> --- a/hw/virtio/virtio-bus.c
> +++ b/hw/virtio/virtio-bus.c
> @@ -23,6 +23,7 @@
> */
>
> #include "qemu/osdep.h"
> +#include "qemu/main-loop.h"
> #include "qemu/error-report.h"
> #include "qemu/module.h"
> #include "qapi/error.h"
> @@ -223,6 +224,8 @@ int virtio_bus_start_ioeventfd(VirtioBusState *bus)
> VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev);
> int r;
>
> + GLOBAL_STATE_CODE();
> +
> if (!k->ioeventfd_assign || !k->ioeventfd_enabled(proxy)) {
> return -ENOSYS;
> }
> @@ -247,6 +250,8 @@ void virtio_bus_stop_ioeventfd(VirtioBusState *bus)
> VirtIODevice *vdev;
> VirtioDeviceClass *vdc;
>
> + GLOBAL_STATE_CODE();
> +
> if (!bus->ioeventfd_started) {
> return;
> }
> diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
> index 0566ad7d00..6798039391 100644
> --- a/hw/virtio/virtio-pci.c
> +++ b/hw/virtio/virtio-pci.c
> @@ -301,6 +301,8 @@ static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val)
> VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
> hwaddr pa;
>
> + GLOBAL_STATE_CODE();
> +
> switch (addr) {
> case VIRTIO_PCI_GUEST_FEATURES:
> /* Guest does not negotiate properly? We have to assume nothing. */
> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
> index 5d607aeaa0..2650504dd4 100644
> --- a/hw/virtio/virtio.c
> +++ b/hw/virtio/virtio.c
> @@ -1977,6 +1977,8 @@ int virtio_set_status(VirtIODevice *vdev, uint8_t val)
> VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
> trace_virtio_set_status(vdev, val);
>
> + GLOBAL_STATE_CODE();
> +
> if (virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1)) {
> if (!(vdev->status & VIRTIO_CONFIG_S_FEATURES_OK) &&
> val & VIRTIO_CONFIG_S_FEATURES_OK) {
> @@ -2025,6 +2027,8 @@ void virtio_reset(void *opaque)
> VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
> int i;
>
> + GLOBAL_STATE_CODE();
> +
> virtio_set_status(vdev, 0);
> if (current_cpu) {
> /* Guest initiated reset */
> @@ -2882,6 +2886,8 @@ int virtio_save(VirtIODevice *vdev, QEMUFile *f)
> uint32_t guest_features_lo = (vdev->guest_features & 0xffffffff);
> int i;
>
> + GLOBAL_STATE_CODE();
> +
> if (k->save_config) {
> k->save_config(qbus->parent, f);
> }
> @@ -3024,6 +3030,8 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id)
> VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
> VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev);
>
> + GLOBAL_STATE_CODE();
> +
> /*
> * We poison the endianness to ensure it does not get used before
> * subsections have been loaded.
> --
> 2.31.1
© 2016 - 2026 Red Hat, Inc.