提交 8e93cef1 编写于 作者: P Paolo Bonzini 提交者: Michael S. Tsirkin

virtio: introduce virtio_device_ioeventfd_enabled

This will be used to forbid iothread configuration when the
proxy does not allow using ioeventfd.  To simplify the implementation,
change the direction of the ioeventfd_disabled callback too.
Reviewed-by: NStefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: NCornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
Reviewed-by: NMichael S. Tsirkin <mst@redhat.com>
Signed-off-by: NMichael S. Tsirkin <mst@redhat.com>
上级 ff4c07df
...@@ -59,11 +59,11 @@ static void virtio_ccw_stop_ioeventfd(VirtioCcwDevice *dev) ...@@ -59,11 +59,11 @@ static void virtio_ccw_stop_ioeventfd(VirtioCcwDevice *dev)
virtio_bus_stop_ioeventfd(&dev->bus); virtio_bus_stop_ioeventfd(&dev->bus);
} }
static bool virtio_ccw_ioeventfd_disabled(DeviceState *d) static bool virtio_ccw_ioeventfd_enabled(DeviceState *d)
{ {
VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d); VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
return !(dev->flags & VIRTIO_CCW_FLAG_USE_IOEVENTFD); return (dev->flags & VIRTIO_CCW_FLAG_USE_IOEVENTFD) != 0;
} }
static int virtio_ccw_ioeventfd_assign(DeviceState *d, EventNotifier *notifier, static int virtio_ccw_ioeventfd_assign(DeviceState *d, EventNotifier *notifier,
...@@ -1589,7 +1589,7 @@ static void virtio_ccw_bus_class_init(ObjectClass *klass, void *data) ...@@ -1589,7 +1589,7 @@ static void virtio_ccw_bus_class_init(ObjectClass *klass, void *data)
k->pre_plugged = virtio_ccw_pre_plugged; k->pre_plugged = virtio_ccw_pre_plugged;
k->device_plugged = virtio_ccw_device_plugged; k->device_plugged = virtio_ccw_device_plugged;
k->device_unplugged = virtio_ccw_device_unplugged; k->device_unplugged = virtio_ccw_device_unplugged;
k->ioeventfd_disabled = virtio_ccw_ioeventfd_disabled; k->ioeventfd_enabled = virtio_ccw_ioeventfd_enabled;
k->ioeventfd_assign = virtio_ccw_ioeventfd_assign; k->ioeventfd_assign = virtio_ccw_ioeventfd_assign;
} }
......
...@@ -193,7 +193,7 @@ int virtio_bus_start_ioeventfd(VirtioBusState *bus) ...@@ -193,7 +193,7 @@ int virtio_bus_start_ioeventfd(VirtioBusState *bus)
VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev); VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev);
int r; int r;
if (!k->ioeventfd_assign || k->ioeventfd_disabled(proxy)) { if (!k->ioeventfd_assign || !k->ioeventfd_enabled(proxy)) {
return -ENOSYS; return -ENOSYS;
} }
if (bus->ioeventfd_started || bus->ioeventfd_disabled) { if (bus->ioeventfd_started || bus->ioeventfd_disabled) {
...@@ -223,6 +223,14 @@ void virtio_bus_stop_ioeventfd(VirtioBusState *bus) ...@@ -223,6 +223,14 @@ void virtio_bus_stop_ioeventfd(VirtioBusState *bus)
bus->ioeventfd_started = false; bus->ioeventfd_started = false;
} }
bool virtio_bus_ioeventfd_enabled(VirtioBusState *bus)
{
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(bus);
DeviceState *proxy = DEVICE(BUS(bus)->parent);
return k->ioeventfd_assign && k->ioeventfd_enabled(proxy);
}
/* /*
* This function switches from/to the generic ioeventfd handler. * This function switches from/to the generic ioeventfd handler.
* assign==false means 'use generic ioeventfd handler'. * assign==false means 'use generic ioeventfd handler'.
......
...@@ -92,9 +92,9 @@ typedef struct { ...@@ -92,9 +92,9 @@ typedef struct {
bool format_transport_address; bool format_transport_address;
} VirtIOMMIOProxy; } VirtIOMMIOProxy;
static bool virtio_mmio_ioeventfd_disabled(DeviceState *d) static bool virtio_mmio_ioeventfd_enabled(DeviceState *d)
{ {
return !kvm_eventfds_enabled(); return kvm_eventfds_enabled();
} }
static int virtio_mmio_ioeventfd_assign(DeviceState *d, static int virtio_mmio_ioeventfd_assign(DeviceState *d,
...@@ -531,7 +531,7 @@ static void virtio_mmio_bus_class_init(ObjectClass *klass, void *data) ...@@ -531,7 +531,7 @@ static void virtio_mmio_bus_class_init(ObjectClass *klass, void *data)
k->save_config = virtio_mmio_save_config; k->save_config = virtio_mmio_save_config;
k->load_config = virtio_mmio_load_config; k->load_config = virtio_mmio_load_config;
k->set_guest_notifiers = virtio_mmio_set_guest_notifiers; k->set_guest_notifiers = virtio_mmio_set_guest_notifiers;
k->ioeventfd_disabled = virtio_mmio_ioeventfd_disabled; k->ioeventfd_enabled = virtio_mmio_ioeventfd_enabled;
k->ioeventfd_assign = virtio_mmio_ioeventfd_assign; k->ioeventfd_assign = virtio_mmio_ioeventfd_assign;
k->has_variable_vring_alignment = true; k->has_variable_vring_alignment = true;
bus_class->max_dev = 1; bus_class->max_dev = 1;
......
...@@ -262,11 +262,11 @@ static int virtio_pci_load_queue(DeviceState *d, int n, QEMUFile *f) ...@@ -262,11 +262,11 @@ static int virtio_pci_load_queue(DeviceState *d, int n, QEMUFile *f)
return 0; return 0;
} }
static bool virtio_pci_ioeventfd_disabled(DeviceState *d) static bool virtio_pci_ioeventfd_enabled(DeviceState *d)
{ {
VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d); VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
return !(proxy->flags & VIRTIO_PCI_FLAG_USE_IOEVENTFD); return (proxy->flags & VIRTIO_PCI_FLAG_USE_IOEVENTFD) != 0;
} }
#define QEMU_VIRTIO_PCI_QUEUE_MEM_MULT 0x1000 #define QEMU_VIRTIO_PCI_QUEUE_MEM_MULT 0x1000
...@@ -2516,7 +2516,7 @@ static void virtio_pci_bus_class_init(ObjectClass *klass, void *data) ...@@ -2516,7 +2516,7 @@ static void virtio_pci_bus_class_init(ObjectClass *klass, void *data)
k->device_plugged = virtio_pci_device_plugged; k->device_plugged = virtio_pci_device_plugged;
k->device_unplugged = virtio_pci_device_unplugged; k->device_unplugged = virtio_pci_device_unplugged;
k->query_nvectors = virtio_pci_query_nvectors; k->query_nvectors = virtio_pci_query_nvectors;
k->ioeventfd_disabled = virtio_pci_ioeventfd_disabled; k->ioeventfd_enabled = virtio_pci_ioeventfd_enabled;
k->ioeventfd_assign = virtio_pci_ioeventfd_assign; k->ioeventfd_assign = virtio_pci_ioeventfd_assign;
} }
......
...@@ -2247,6 +2247,14 @@ static void virtio_device_class_init(ObjectClass *klass, void *data) ...@@ -2247,6 +2247,14 @@ static void virtio_device_class_init(ObjectClass *klass, void *data)
vdc->stop_ioeventfd = virtio_device_stop_ioeventfd_impl; vdc->stop_ioeventfd = virtio_device_stop_ioeventfd_impl;
} }
bool virtio_device_ioeventfd_enabled(VirtIODevice *vdev)
{
BusState *qbus = qdev_get_parent_bus(DEVICE(vdev));
VirtioBusState *vbus = VIRTIO_BUS(qbus);
return virtio_bus_ioeventfd_enabled(vbus);
}
static const TypeInfo virtio_device_info = { static const TypeInfo virtio_device_info = {
.name = TYPE_VIRTIO_DEVICE, .name = TYPE_VIRTIO_DEVICE,
.parent = TYPE_DEVICE, .parent = TYPE_DEVICE,
......
...@@ -71,10 +71,10 @@ typedef struct VirtioBusClass { ...@@ -71,10 +71,10 @@ typedef struct VirtioBusClass {
int (*query_nvectors)(DeviceState *d); int (*query_nvectors)(DeviceState *d);
/* /*
* ioeventfd handling: if the transport implements ioeventfd_assign, * ioeventfd handling: if the transport implements ioeventfd_assign,
* it must implement ioeventfd_disabled as well. * it must implement ioeventfd_enabled as well.
*/ */
/* Returns true if the ioeventfd has been disabled for the device. */ /* Returns true if the ioeventfd is enabled for the device. */
bool (*ioeventfd_disabled)(DeviceState *d); bool (*ioeventfd_enabled)(DeviceState *d);
/* /*
* Assigns/deassigns the ioeventfd backing for the transport on * Assigns/deassigns the ioeventfd backing for the transport on
* the device for queue number n. Returns an error value on * the device for queue number n. Returns an error value on
...@@ -131,6 +131,8 @@ static inline VirtIODevice *virtio_bus_get_device(VirtioBusState *bus) ...@@ -131,6 +131,8 @@ static inline VirtIODevice *virtio_bus_get_device(VirtioBusState *bus)
return (VirtIODevice *)qdev; return (VirtIODevice *)qdev;
} }
/* Return whether the proxy allows ioeventfd. */
bool virtio_bus_ioeventfd_enabled(VirtioBusState *bus);
/* Start the ioeventfd. */ /* Start the ioeventfd. */
int virtio_bus_start_ioeventfd(VirtioBusState *bus); int virtio_bus_start_ioeventfd(VirtioBusState *bus);
/* Stop the ioeventfd. */ /* Stop the ioeventfd. */
......
...@@ -273,6 +273,7 @@ void virtio_queue_set_guest_notifier_fd_handler(VirtQueue *vq, bool assign, ...@@ -273,6 +273,7 @@ void virtio_queue_set_guest_notifier_fd_handler(VirtQueue *vq, bool assign,
bool with_irqfd); bool with_irqfd);
int virtio_device_start_ioeventfd(VirtIODevice *vdev); int virtio_device_start_ioeventfd(VirtIODevice *vdev);
void virtio_device_stop_ioeventfd(VirtIODevice *vdev); void virtio_device_stop_ioeventfd(VirtIODevice *vdev);
bool virtio_device_ioeventfd_enabled(VirtIODevice *vdev);
EventNotifier *virtio_queue_get_host_notifier(VirtQueue *vq); EventNotifier *virtio_queue_get_host_notifier(VirtQueue *vq);
void virtio_queue_set_host_notifier_fd_handler(VirtQueue *vq, bool assign, void virtio_queue_set_host_notifier_fd_handler(VirtQueue *vq, bool assign,
bool set_handler); bool set_handler);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册