Introduce virtio_bh_new_guarded(), similar to qemu_bh_new_guarded() but using the transport memory guard, instead of the device one (there can only be one virtio device per virtio bus).
Inspired-by: Gerd Hoffmann <kra...@redhat.com> Signed-off-by: Philippe Mathieu-Daudé <phi...@linaro.org> --- include/hw/virtio/virtio.h | 7 +++++++ hw/virtio/virtio.c | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index b3c74a1bca..12419d6355 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -22,6 +22,7 @@ #include "standard-headers/linux/virtio_config.h" #include "standard-headers/linux/virtio_ring.h" #include "qom/object.h" +#include "block/aio.h" /* * A guest should never accept this. It implies negotiation is broken @@ -527,4 +528,10 @@ static inline bool virtio_device_disabled(VirtIODevice *vdev) bool virtio_legacy_allowed(VirtIODevice *vdev); bool virtio_legacy_check_disabled(VirtIODevice *vdev); +QEMUBH *virtio_bh_new_guarded_full(VirtIODevice *vdev, + QEMUBHFunc *cb, void *opaque, + const char *name); +#define virtio_bh_new_guarded(vdev, cb, opaque) \ + virtio_bh_new_guarded_full((vdev), (cb), (opaque), (stringify(cb))) + #endif diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index fb6b4ccd83..e1735cf7fd 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -4176,3 +4176,13 @@ static void virtio_register_types(void) } type_init(virtio_register_types) + +QEMUBH *virtio_bh_new_guarded_full(VirtIODevice *vdev, + QEMUBHFunc *cb, void *opaque, + const char *name) +{ + BusState *virtio_bus = qdev_get_parent_bus(DEVICE(vdev)); + DeviceState *transport = virtio_bus->parent; + + return qemu_bh_new_full(cb, opaque, name, &transport->mem_reentrancy_guard); +} -- 2.41.0