Skip to content

Commit

Permalink
hw/virtio: Introduce virtio_bh_new_guarded() helper
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Gerd Hoffmann <[email protected]>
Acked-by: Michael S. Tsirkin <[email protected]>
Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
Reviewed-by: Michael S. Tsirkin <[email protected]>
Message-Id: <[email protected]>
  • Loading branch information
philmd committed Apr 10, 2024
1 parent 927284d commit ec0504b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
10 changes: 10 additions & 0 deletions hw/virtio/virtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -4145,3 +4145,13 @@ static void virtio_register_types(void)
}

type_init(virtio_register_types)

QEMUBH *virtio_bh_new_guarded_full(DeviceState *dev,
QEMUBHFunc *cb, void *opaque,
const char *name)
{
DeviceState *transport = qdev_get_parent_bus(dev)->parent;

return qemu_bh_new_full(cb, opaque, name,
&transport->mem_reentrancy_guard);
}
7 changes: 7 additions & 0 deletions include/hw/virtio/virtio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -508,4 +509,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(DeviceState *dev,
QEMUBHFunc *cb, void *opaque,
const char *name);
#define virtio_bh_new_guarded(dev, cb, opaque) \
virtio_bh_new_guarded_full((dev), (cb), (opaque), (stringify(cb)))

#endif

0 comments on commit ec0504b

Please sign in to comment.