Skip to contentSkip to conversation

Virtio refactoring.

RFC PATCH Superseded [email protected] 5 participants 43 messages Dec 7, 2012 – Jan 8, 2013

v6 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

v6 cover Virtio refactoring.

From: KONRAD Frederic <[email protected]>

You can clone that from here :
git.greensocs.com/home/greensocs/git/qemu_virtio.git virtio_refactoring_v6

The problem with the last RFC v5 was that virtio-blk refactoring broke virtio-blk-pci device ( SEGFAULT ). So I modify this last step to fix that issue.

In order to not break anything, I think we have to refactor virtio-pci-blk in a next step then add a supplementary step which clean virtio-blk
( eg : fix the cast ).

Does it make sense ?

This patch-set is :
* Introducing a virtio-bus which extends bus-state.
* Implementing a virtio-pci-bus which extends virtio-bus.
* Implementing a virtio-pci device which has a virtio-pci-bus.
* Implementing virtio-device which extends device-states.
* Implementing a virtio-blk which extends virtio-device.

The first patch is a modification of qdev-monitor.c, it forces the function qbus_find_recursive(..) to return a non-full bus, and return an error if the desired bus ( with "bus=" option ) is full. It add a max_dev field to the bus_state structure. If max_dev=0 it has no limitation, if not the maximum amount of device connected to the bus is max_dev.

Changes v5 -> v6:
* Renamed virtio_common_init_ to virtio_init, modify virtio_common_init to allocate and call virtio_init. Drop the unused structure size parameters.
* Renamed init/exit callback in VirtioBusClass.
* Renamed virtio_blk_init virtio_blk_common_init.
* Modified virtio_blk_init to call virtio_blk_common_init.

Changes v4 -> v5:
* use ERROR_CLASS_GENERIC_ERROR in place of creating a new error type for the maximum device limitation. ( Peter )
* Removed bus_in_use function. We assume that the virtio-bus is not in use, when plugin in. ( Peter )
* Added virtio_bus_destroy_device().
* Implemented the exit function of virtio-pci.
* Implemented the init callback for virtio-pci ( must be modified, it still access vdev directly. ).
* Implemented the exit callback for virtio-pci.
* Started virtio-device refactoring.
* Started virtio-blk refactoring.

Changes v3 -> v4:
* Added virtio-bus.o in Makefile.objs ( accidentally dropped from v3 ).
* *const* TypeInfo in virtio-bus.
* Introduced virtio-pci-bus.
* Reintroduced virtio-pci.
* Introduced virtio-device.
* Started virtio-blk refactoring.
* Added an error type in qerror.h for the "bus full" error.

Changes v2 -> v3:
* Added VirtioBusClass.
* Renamed VirtioBus -> VirtioBusState.
* Renamed qbus -> parent_obj.
* Plug the device only in a non-full bus.

Changes v1 -> v2:
* All the little fix you suggest ( License, Debug printf, naming convention, ...)
* Added get_virtio_device_id(), and remove the pci_id* from the VirtioBus structure.
* Added virtio_bus_reset().
* Added cast macros VIRTIO_BUS.
* Added virtio_bus_plug_device.
* Replaced the old-style "bus->qbus" by BUS() macro.

Fred.

KONRAD Frederic (6):
qdev : add a maximum device allowed field for the bus. virtio-bus : Introduce virtio-bus virtio-pci-bus : Introduce virtio-pci-bus. virtio-pci : Refactor virtio-pci device. virtio-device : Refactor virtio-device. virtio-blk : Add the virtio-blk device.

 hw/Makefile.objs  |   1 +
 hw/qdev-core.h    |   2 +
 hw/qdev-monitor.c |  11 ++++
 hw/virtio-blk.c   | 101 ++++++++++++++++++++++++++++++++----
 hw/virtio-blk.h   |   4 ++
 hw/virtio-bus.c   | 111 ++++++++++++++++++++++++++++++++++++++++
 hw/virtio-bus.h   |  82 ++++++++++++++++++++++++++++++
 hw/virtio-pci.c   | 149 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/virtio-pci.h   |  33 +++++++++++-
 hw/virtio.c       |  50 ++++++++++++++----
 hw/virtio.h       |  28 ++++++++++
 11 files changed, 550 insertions(+), 22 deletions(-)
 create mode 100644 hw/virtio-bus.c
 create mode 100644 hw/virtio-bus.h
Signature · 1 line
1.7.11.7
#1 lore raw

RFC PATCH v6 1/6 qdev : add a maximum device allowed field for the bus.

From: KONRAD Frederic <[email protected]>

Add a max_dev field to BusState to specify the maximum amount of devices allowed on the bus ( have no effect if max_dev=0 )

---
 hw/qdev-core.h    |  2 ++
 hw/qdev-monitor.c | 11 +++++++++++
 2 files changed, 13 insertions(+)
hw/qdev-core.h +2 -0
index fff7f0f..ee4becd 100644
@@ -113,6 +113,8 @@ struct BusState {
     const char *name;
     int allow_hotplug;
     int max_index;
+    /* maximum devices allowed on the bus, 0 : no limit. */
+    int max_dev;
     QTAILQ_HEAD(ChildrenHead, BusChild) children;
     QLIST_ENTRY(BusState) sibling;
 };
hw/qdev-monitor.c +11 -0
index a1b4d6a..7a9d275 100644
@@ -292,6 +292,17 @@ static BusState *qbus_find_recursive(BusState *bus, const char *name,
     if (bus_typename && !object_dynamic_cast(OBJECT(bus), bus_typename)) {
         match = 0;
     }
+    if ((bus->max_dev != 0) && (bus->max_dev <= bus->max_index)) {
+        if (name != NULL) {
+            /* bus was explicitly specified : return an error. */
+            qerror_report(ERROR_CLASS_GENERIC_ERROR, "Bus '%s' is full",
+                          bus->name);
+            return NULL;
+        } else {
+            /* bus was not specified : try to find another one. */
+            match = 0;
+        }
+    }
     if (match) {
         return bus;
     }
Signature · 1 line
1.7.11.7
#2 lore raw

RFC PATCH v6 2/6 virtio-bus : Introduce virtio-bus

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

Introduce virtio-bus. Refactored transport device will create a bus which extends virtio-bus.

---
 hw/Makefile.objs |   1 +
 hw/virtio-bus.c  | 111 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/virtio-bus.h  |  82 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 194 insertions(+)
 create mode 100644 hw/virtio-bus.c
 create mode 100644 hw/virtio-bus.h
hw/Makefile.objs +1 -0
index d581d8d..6fa4de4 100644
@@ -3,6 +3,7 @@ common-obj-y += loader.o
 common-obj-$(CONFIG_VIRTIO) += virtio-console.o
 common-obj-$(CONFIG_VIRTIO) += virtio-rng.o
 common-obj-$(CONFIG_VIRTIO_PCI) += virtio-pci.o
+common-obj-$(CONFIG_VIRTIO) += virtio-bus.o
 common-obj-y += fw_cfg.o
 common-obj-$(CONFIG_PCI) += pci.o pci_bridge.o pci_bridge_dev.o
 common-obj-$(CONFIG_PCI) += msix.o msi.o
hw/virtio-bus.c new file +111 -0

111 lines not on this page · raw message

hw/virtio-bus.h new file +82 -0

82 lines not on this page · raw message

Signature · 1 line
1.7.11.7
#3 lore raw

RFC PATCH v6 3/6 virtio-pci-bus : Introduce virtio-pci-bus.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

Introduce virtio-pci-bus, which extends virtio-bus. It is used with virtio-pci transport device.

---
 hw/virtio-pci.c | 37 +++++++++++++++++++++++++++++++++++++
 hw/virtio-pci.h | 19 +++++++++++++++++--
 2 files changed, 54 insertions(+), 2 deletions(-)
hw/virtio-pci.c +37 -0
index 71f4fb5..5ac8d0d 100644
@@ -32,6 +32,7 @@
 #include "blockdev.h"
 #include "virtio-pci.h"
 #include "range.h"
+#include "virtio-bus.h"
 
 /* from Linux's linux/virtio_pci.h */
 
@@ -1118,6 +1119,41 @@ static TypeInfo virtio_scsi_info = {
     .class_init    = virtio_scsi_class_init,
 };
 
+/* virtio-pci-bus */
+
+VirtioBusState *virtio_pci_bus_new(VirtIOPCIProxy *dev)
+{
+    DeviceState *qdev = DEVICE(dev);
+    BusState *qbus = qbus_create(TYPE_VIRTIO_PCI_BUS, qdev, NULL);
+    VirtioBusState *bus = VIRTIO_BUS(qbus);
+    qbus->allow_hotplug = 0;
+    /* Only one virtio-device allowed for virtio-pci. */
+    qbus->max_dev = 1;
+    return bus;
+}
+
+static void virtio_pci_bus_class_init(ObjectClass *klass, void *data)
+{
+    VirtioBusClass *k = VIRTIO_BUS_CLASS(klass);
+    k->notify = virtio_pci_notify;
+    k->save_config = virtio_pci_save_config;
+    k->load_config = virtio_pci_load_config;
+    k->save_queue = virtio_pci_save_queue;
+    k->load_queue = virtio_pci_load_queue;
+    k->get_features = virtio_pci_get_features;
+    k->query_guest_notifiers = virtio_pci_query_guest_notifiers;
+    k->set_host_notifier = virtio_pci_set_host_notifier;
+    k->set_guest_notifiers = virtio_pci_set_guest_notifiers;
+    k->vmstate_change = virtio_pci_vmstate_change;
+}
+
+static const TypeInfo virtio_pci_bus_info = {
+    .name          = TYPE_VIRTIO_PCI_BUS,
+    .parent        = TYPE_VIRTIO_BUS,
+    .instance_size = sizeof(VirtioBusState),
+    .class_init    = virtio_pci_bus_class_init,
+};
+
 static void virtio_pci_register_types(void)
 {
     type_register_static(&virtio_blk_info);
@@ -1126,6 +1162,7 @@ static void virtio_pci_register_types(void)
     type_register_static(&virtio_balloon_info);
     type_register_static(&virtio_scsi_info);
     type_register_static(&virtio_rng_info);
+    type_register_static(&virtio_pci_bus_info);
 }
 
 type_init(virtio_pci_register_types)
hw/virtio-pci.h +17 -2
index b58d9a2..0e3288e 100644
@@ -20,6 +20,21 @@
 #include "virtio-rng.h"
 #include "virtio-serial.h"
 #include "virtio-scsi.h"
+#include "virtio-bus.h"
+
+/* VirtIOPCIProxy will be renammed VirtioPCIState at the end. */
+typedef struct VirtIOPCIProxy VirtIOPCIProxy;
+
+/* virtio-pci-bus */
+#define TYPE_VIRTIO_PCI_BUS "virtio-pci-bus"
+#define VIRTIO_PCI_BUS_GET_CLASS(obj) \
+        OBJECT_GET_CLASS(VirtioBusClass, obj, TYPE_VIRTIO_PCI_BUS)
+#define VIRTIO_PCI_BUS_CLASS(klass) \
+        OBJECT_CLASS_CHECK(VirtioBusClass, klass, TYPE_VIRTIO_PCI_BUS)
+#define VIRTIO_PCI_BUS(obj) \
+        OBJECT_CHECK(VirtioBusState, (obj), TYPE_VIRTIO_PCI_BUS)
+
+VirtioBusState *virtio_pci_bus_new(VirtIOPCIProxy *dev);
 
 /* Performance improves when virtqueue kick processing is decoupled from the
  * vcpu thread using ioeventfd for some devices. */
@@ -31,7 +46,7 @@ typedef struct {
     unsigned int users;
 } VirtIOIRQFD;
 
-typedef struct {
+struct VirtIOPCIProxy {
     PCIDevice pci_dev;
     VirtIODevice *vdev;
     MemoryRegion bar;
@@ -51,7 +66,7 @@ typedef struct {
     bool ioeventfd_disabled;
     bool ioeventfd_started;
     VirtIOIRQFD *vector_irqfd;
-} VirtIOPCIProxy;
+};
 
 void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev);
 void virtio_pci_reset(DeviceState *d);
Signature · 1 line
1.7.11.7
#4 lore raw

RFC PATCH v6 4/6 virtio-pci : Refactor virtio-pci device.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

Create the virtio-pci device. This transport device will create a virtio-pci-bus, so one VirtIODevice can be connected.

---
 hw/virtio-pci.c | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/virtio-pci.h |  14 +++++++
 2 files changed, 126 insertions(+)
hw/virtio-pci.c +112 -0
index 5ac8d0d..ff0b5f1 100644
@@ -1119,6 +1119,115 @@ static TypeInfo virtio_scsi_info = {
     .class_init    = virtio_scsi_class_init,
 };
 
+/*
+ * virtio-pci : This is the PCIDevice which have a virtio-pci-bus.
+ */
+
+/* This is called by virtio-bus just after the device is plugged. */
+static void virtio_pci_device_plugged(void *opaque)
+{
+    VirtIOPCIProxy *proxy = VIRTIO_PCI(opaque);
+    uint8_t *config;
+    uint32_t size;
+
+    /* Put the PCI IDs */
+    switch (get_virtio_device_id(proxy->bus)) {
+
+    case VIRTIO_ID_BLOCK:
+        pci_config_set_device_id(proxy->pci_dev.config,
+                                 PCI_DEVICE_ID_VIRTIO_BLOCK);
+        pci_config_set_class(proxy->pci_dev.config, PCI_CLASS_STORAGE_SCSI);
+    break;
+    default:
+        error_report("unknown device id\n");
+    break;
+
+    }
+
+    /* TODO: vdev should be accessed through virtio-bus functions. */
+    proxy->vdev = proxy->bus->vdev;
+    config = proxy->pci_dev.config;
+
+    if (proxy->class_code) {
+        pci_config_set_class(config, proxy->class_code);
+    }
+    pci_set_word(config + PCI_SUBSYSTEM_VENDOR_ID,
+                 pci_get_word(config + PCI_VENDOR_ID));
+    pci_set_word(config + PCI_SUBSYSTEM_ID, get_virtio_device_id(proxy->bus));
+    config[PCI_INTERRUPT_PIN] = 1;
+
+    if (proxy->bus->vdev->nvectors &&
+        msix_init_exclusive_bar(&proxy->pci_dev, proxy->bus->vdev->nvectors,
+                                1)) {
+        proxy->bus->vdev->nvectors = 0;
+    }
+
+    proxy->pci_dev.config_write = virtio_write_config;
+
+    size = VIRTIO_PCI_REGION_SIZE(&proxy->pci_dev)
+         + proxy->bus->vdev->config_len;
+    if (size & (size-1)) {
+        size = 1 << qemu_fls(size);
+    }
+
+    memory_region_init_io(&proxy->bar, &virtio_pci_config_ops, proxy,
+                          "virtio-pci", size);
+    pci_register_bar(&proxy->pci_dev, 0, PCI_BASE_ADDRESS_SPACE_IO,
+                     &proxy->bar);
+
+    if (!kvm_has_many_ioeventfds()) {
+        proxy->flags &= ~VIRTIO_PCI_FLAG_USE_IOEVENTFD;
+    }
+
+    proxy->host_features |= 0x1 << VIRTIO_F_NOTIFY_ON_EMPTY;
+    proxy->host_features |= 0x1 << VIRTIO_F_BAD_FEATURE;
+    proxy->host_features = proxy->bus->vdev->get_features(proxy->bus->vdev,
+                                                          proxy->host_features);
+}
+
+/* This is called by virtio-bus just before the device is unplugged. */
+static void virtio_pci_device_unplug(void *opaque)
+{
+    VirtIOPCIProxy *dev = VIRTIO_PCI(opaque);
+    virtio_pci_stop_ioeventfd(dev);
+}
+
+static int virtio_pci_init(PCIDevice *pci_dev)
+{
+    VirtIOPCIProxy *dev = VIRTIO_PCI(pci_dev);
+    dev->bus = virtio_pci_bus_new(dev);
+    return 0;
+}
+
+static void virtio_pci_exit(PCIDevice *pci_dev)
+{
+    DeviceState *qdev = DEVICE(pci_dev);
+    BusState *qbus = BUS(qdev_get_parent_bus(qdev));
+    VirtioBusState *bus = VIRTIO_BUS(qbus);
+    virtio_bus_destroy_device(bus);
+    qbus_free(qbus);
+}
+
+static void virtio_pci_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+    k->init = virtio_pci_init;
+    k->exit = virtio_pci_exit;
+    k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
+    k->revision = VIRTIO_PCI_ABI_VERSION;
+    k->class_id = PCI_CLASS_OTHERS;
+    dc->reset = virtio_pci_reset;
+}
+
+static const TypeInfo virtio_pci_info = {
+    .name          = TYPE_VIRTIO_PCI,
+    .parent        = TYPE_PCI_DEVICE,
+    .instance_size = sizeof(VirtIOPCIProxy),
+    .class_init    = virtio_pci_class_init,
+};
+
 /* virtio-pci-bus */
 
 VirtioBusState *virtio_pci_bus_new(VirtIOPCIProxy *dev)
@@ -1145,6 +1254,8 @@ static void virtio_pci_bus_class_init(ObjectClass *klass, void *data)
     k->set_host_notifier = virtio_pci_set_host_notifier;
     k->set_guest_notifiers = virtio_pci_set_guest_notifiers;
     k->vmstate_change = virtio_pci_vmstate_change;
+    k->device_plugged = virtio_pci_device_plugged;
+    k->device_unplug = virtio_pci_device_unplug;
 }
 
 static const TypeInfo virtio_pci_bus_info = {
@@ -1163,6 +1274,7 @@ static void virtio_pci_register_types(void)
     type_register_static(&virtio_scsi_info);
     type_register_static(&virtio_rng_info);
     type_register_static(&virtio_pci_bus_info);
+    type_register_static(&virtio_pci_info);
 }
 
 type_init(virtio_pci_register_types)
hw/virtio-pci.h +14 -0
index 0e3288e..2c31b7a 100644
@@ -46,6 +46,17 @@ typedef struct {
     unsigned int users;
 } VirtIOIRQFD;
 
+/*
+ * virtio-pci : This is the PCIDevice which have a virtio-pci-bus.
+ */
+#define TYPE_VIRTIO_PCI "virtio-pci"
+#define VIRTIO_PCI_GET_CLASS(obj) \
+        OBJECT_GET_CLASS(VirtioPCIClass, obj, TYPE_VIRTIO_PCI)
+#define VIRTIO_PCI_CLASS(klass) \
+        OBJECT_CLASS_CHECK(VirtioPCIClass, klass, TYPE_VIRTIO_PCI)
+#define VIRTIO_PCI(obj) \
+        OBJECT_CHECK(VirtIOPCIProxy, (obj), TYPE_VIRTIO_PCI)
+
 struct VirtIOPCIProxy {
     PCIDevice pci_dev;
     VirtIODevice *vdev;
@@ -66,6 +77,9 @@ struct VirtIOPCIProxy {
     bool ioeventfd_disabled;
     bool ioeventfd_started;
     VirtIOIRQFD *vector_irqfd;
+    /* That's the virtio-bus on which VirtioDevice will be connected. */
+    VirtioBusState *bus;
+    /* Nothing more for the moment. */
 };
 
 void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev);
Signature · 1 line
1.7.11.7
#5 lore raw

RFC PATCH v6 5/6 virtio-device : Refactor virtio-device.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

Create the virtio-device which is abstract. All the virtio-device can extend this class.

---
 hw/virtio.c | 50 +++++++++++++++++++++++++++++++++++++++-----------
 hw/virtio.h | 28 ++++++++++++++++++++++++++++
 2 files changed, 67 insertions(+), 11 deletions(-)
hw/virtio.c +39 -11
index f40a8c5..2541ea8 100644
@@ -16,6 +16,7 @@
 #include "trace.h"
 #include "qemu-error.h"
 #include "virtio.h"
+#include "virtio-bus.h"
 #include "qemu-barrier.h"
 
 /* The alignment to use between consumer and producer parts of vring.
@@ -902,14 +903,10 @@ static void virtio_vmstate_change(void *opaque, int running, RunState state)
     }
 }
 
-VirtIODevice *virtio_common_init(const char *name, uint16_t device_id,
-                                 size_t config_size, size_t struct_size)
+void virtio_init(VirtIODevice *vdev, const char *name,
+                 uint16_t device_id, size_t config_size)
 {
-    VirtIODevice *vdev;
     int i;
-
-    vdev = g_malloc0(struct_size);
-
     vdev->device_id = device_id;
     vdev->status = 0;
     vdev->isr = 0;
@@ -917,20 +914,28 @@ VirtIODevice *virtio_common_init(const char *name, uint16_t device_id,
     vdev->config_vector = VIRTIO_NO_VECTOR;
     vdev->vq = g_malloc0(sizeof(VirtQueue) * VIRTIO_PCI_QUEUE_MAX);
     vdev->vm_running = runstate_is_running();
-    for(i = 0; i < VIRTIO_PCI_QUEUE_MAX; i++) {
+    for (i = 0; i < VIRTIO_PCI_QUEUE_MAX; i++) {
         vdev->vq[i].vector = VIRTIO_NO_VECTOR;
         vdev->vq[i].vdev = vdev;
     }
 
     vdev->name = name;
     vdev->config_len = config_size;
-    if (vdev->config_len)
+    if (vdev->config_len) {
         vdev->config = g_malloc0(config_size);
-    else
+    } else {
         vdev->config = NULL;
+    }
+    vdev->vmstate = qemu_add_vm_change_state_handler(virtio_vmstate_change,
+                                                     vdev);
+}
 
-    vdev->vmstate = qemu_add_vm_change_state_handler(virtio_vmstate_change, vdev);
-
+VirtIODevice *virtio_common_init(const char *name, uint16_t device_id,
+                                 size_t config_size, size_t struct_size)
+{
+    VirtIODevice *vdev;
+    vdev = g_malloc0(struct_size);
+    virtio_init(vdev, name, device_id, config_size);
     return vdev;
 }
 
@@ -1056,3 +1061,26 @@ EventNotifier *virtio_queue_get_host_notifier(VirtQueue *vq)
 {
     return &vq->host_notifier;
 }
+
+static void virtio_device_class_init(ObjectClass *klass, void *data)
+{
+    /* Set the default value here. */
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    dc->bus_type = TYPE_VIRTIO_BUS;
+}
+
+static const TypeInfo virtio_device_info = {
+    .name = TYPE_VIRTIO_DEVICE,
+    .parent = TYPE_DEVICE,
+    .instance_size = sizeof(VirtIODevice),
+    .class_init = virtio_device_class_init,
+    .abstract = true,
+    .class_size = sizeof(VirtioDeviceClass),
+};
+
+static void virtio_register_types(void)
+{
+    type_register_static(&virtio_device_info);
+}
+
+type_init(virtio_register_types)
hw/virtio.h +28 -0
index 7c17f7b..79d2b91 100644
@@ -108,8 +108,17 @@ typedef struct {
 
 #define VIRTIO_NO_VECTOR 0xffff
 
+#define TYPE_VIRTIO_DEVICE "virtio-device"
+#define VIRTIO_DEVICE_GET_CLASS(obj) \
+        OBJECT_GET_CLASS(VirtioDeviceClass, obj, TYPE_VIRTIO_DEVICE)
+#define VIRTIO_DEVICE_CLASS(klass) \
+        OBJECT_CLASS_CHECK(VirtioDeviceClass, klass, TYPE_VIRTIO_DEVICE)
+#define VIRTIO_DEVICE(obj) \
+        OBJECT_CHECK(VirtIODevice, (obj), TYPE_VIRTIO_DEVICE)
+
 struct VirtIODevice
 {
+    DeviceState parent_obj;
     const char *name;
     uint8_t status;
     uint8_t isr;
@@ -119,6 +128,9 @@ struct VirtIODevice
     void *config;
     uint16_t config_vector;
     int nvectors;
+    /*
+     * Must be removed as we have it in VirtioDeviceClass.
+     */
     uint32_t (*get_features)(VirtIODevice *vdev, uint32_t requested_features);
     uint32_t (*bad_features)(VirtIODevice *vdev);
     void (*set_features)(VirtIODevice *vdev, uint32_t val);
@@ -126,6 +138,7 @@ struct VirtIODevice
     void (*set_config)(VirtIODevice *vdev, const uint8_t *config);
     void (*reset)(VirtIODevice *vdev);
     void (*set_status)(VirtIODevice *vdev, uint8_t val);
+    /***/
     VirtQueue *vq;
     const VirtIOBindings *binding;
     void *binding_opaque;
@@ -134,6 +147,21 @@ struct VirtIODevice
     VMChangeStateEntry *vmstate;
 };
 
+typedef struct {
+    /* This is what a VirtioDevice must implement */
+    DeviceClass parent;
+    uint32_t (*get_features)(VirtIODevice *vdev, uint32_t requested_features);
+    uint32_t (*bad_features)(VirtIODevice *vdev);
+    void (*set_features)(VirtIODevice *vdev, uint32_t val);
+    void (*get_config)(VirtIODevice *vdev, uint8_t *config);
+    void (*set_config)(VirtIODevice *vdev, const uint8_t *config);
+    void (*reset)(VirtIODevice *vdev);
+    void (*set_status)(VirtIODevice *vdev, uint8_t val);
+} VirtioDeviceClass;
+
+void virtio_init(VirtIODevice *vdev, const char *name,
+                         uint16_t device_id, size_t config_size);
+
 VirtQueue *virtio_add_queue(VirtIODevice *vdev, int queue_size,
                             void (*handle_output)(VirtIODevice *,
                                                   VirtQueue *));
Signature · 1 line
1.7.11.7
#6 lore raw

RFC PATCH v6 6/6 virtio-blk : Add the virtio-blk device.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

Create virtio-blk which extends virtio-device, so it can be connected on virtio-bus. I suggest one step to refactor virtio-blk-pci, and one more to clean virtio-blk.

---
 hw/virtio-blk.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++-----
 hw/virtio-blk.h |   4 +++
 2 files changed, 96 insertions(+), 9 deletions(-)
hw/virtio-blk.c +92 -9
index e25cc96..9b6a8f5 100644
@@ -21,6 +21,7 @@
 #ifdef __linux__
 # include <scsi/sg.h>
 #endif
+#include "virtio-bus.h"
 
 typedef struct VirtIOBlock
 {
@@ -30,11 +31,14 @@ typedef struct VirtIOBlock
     void *rq;
     QEMUBH *bh;
     BlockConf *conf;
-    VirtIOBlkConf *blk;
+    VirtIOBlkConf blk;
     unsigned short sector_mask;
     DeviceState *qdev;
 } VirtIOBlock;
 
+/*
+ * Moving to QOM later in this series.
+ */
 static VirtIOBlock *to_virtio_blk(VirtIODevice *vdev)
 {
     return (VirtIOBlock *)vdev;
@@ -164,7 +168,7 @@ static void virtio_blk_handle_scsi(VirtIOBlockReq *req)
      */
     req->scsi = (void *)req->elem.in_sg[req->elem.in_num - 2].iov_base;
 
-    if (!req->dev->blk->scsi) {
+    if (!req->dev->blk.scsi) {
         status = VIRTIO_BLK_S_UNSUPP;
         goto fail;
     }
@@ -384,7 +388,7 @@ static void virtio_blk_handle_request(VirtIOBlockReq *req,
          * terminated by '\0' only when shorter than buffer.
          */
         strncpy(req->elem.in_sg[0].iov_base,
-                s->blk->serial ? s->blk->serial : "",
+                s->blk.serial ? s->blk.serial : "",
                 MIN(req->elem.in_sg[0].iov_len, VIRTIO_BLK_ID_BYTES));
         virtio_blk_req_complete(req, VIRTIO_BLK_S_OK);
         g_free(req);
@@ -600,9 +604,10 @@ static const BlockDevOps virtio_block_ops = {
     .resize_cb = virtio_blk_resize,
 };
 
-VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk)
+static VirtIODevice *virtio_blk_common_init(DeviceState *dev,
+                                          VirtIOBlkConf *blk, VirtIOBlock **ps)
 {
-    VirtIOBlock *s;
+    VirtIOBlock *s = *ps;
     static int virtio_blk_id;
 
     if (!blk->conf.bs) {
@@ -619,9 +624,20 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk)
         return NULL;
     }
 
-    s = (VirtIOBlock *)virtio_common_init("virtio-blk", VIRTIO_ID_BLOCK,
-                                          sizeof(struct virtio_blk_config),
-                                          sizeof(VirtIOBlock));
+    /*
+     * We have two cases here : the old virtio-blk-pci device, and the
+     * refactored virtio-blk.
+     */
+    if (s == NULL) {
+        /* virtio-blk-pci */
+        s = (VirtIOBlock *)virtio_common_init("virtio-blk", VIRTIO_ID_BLOCK,
+                                              sizeof(struct virtio_blk_config),
+                                              sizeof(VirtIOBlock));
+    } else {
+        /* virtio-blk */
+        virtio_init(VIRTIO_DEVICE(s), "virtio-blk", VIRTIO_ID_BLOCK,
+                    sizeof(struct virtio_blk_config));
+    }
 
     s->vdev.get_config = virtio_blk_update_config;
     s->vdev.set_config = virtio_blk_set_config;
@@ -630,7 +646,7 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk)
     s->vdev.reset = virtio_blk_reset;
     s->bs = blk->conf.bs;
     s->conf = &blk->conf;
-    s->blk = blk;
+    memcpy(&(s->blk), blk, sizeof(struct VirtIOBlkConf));
     s->rq = NULL;
     s->sector_mask = (s->conf->logical_block_size / BDRV_SECTOR_SIZE) - 1;
 
@@ -649,6 +665,12 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk)
     return &s->vdev;
 }
 
+VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk)
+{
+    VirtIOBlock *s = NULL;
+    return virtio_blk_common_init(dev, blk, &s);
+}
+
 void virtio_blk_exit(VirtIODevice *vdev)
 {
     VirtIOBlock *s = to_virtio_blk(vdev);
@@ -656,3 +678,64 @@ void virtio_blk_exit(VirtIODevice *vdev)
     blockdev_mark_auto_del(s->bs);
     virtio_cleanup(vdev);
 }
+
+
+static int virtio_device_init(DeviceState *qdev)
+{
+    VirtIODevice *vdev = VIRTIO_DEVICE(qdev);
+    VirtIOBlock *s = VIRTIO_BLK(qdev);
+
+    VirtIOBlkConf *blk = &(s->blk);
+
+    virtio_blk_common_init(qdev, blk, &s);
+
+    virtio_bus_plug_device(vdev);
+
+    return 0;
+}
+
+static int virtio_device_exit(DeviceState *dev)
+{
+    VirtIODevice *vdev = VIRTIO_DEVICE(dev);
+    virtio_blk_exit(vdev);
+    return 0;
+}
+
+static Property virtio_blk_properties[] = {
+    DEFINE_BLOCK_PROPERTIES(VirtIOBlock, blk.conf),
+    DEFINE_BLOCK_CHS_PROPERTIES(VirtIOBlock, blk.conf),
+    DEFINE_PROP_STRING("serial", VirtIOBlock, blk.serial),
+#ifdef __linux__
+    DEFINE_PROP_BIT("scsi", VirtIOBlock, blk.scsi, 0, true),
+#endif
+    DEFINE_PROP_BIT("config-wce", VirtIOBlock, blk.config_wce, 0, true),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void virtio_blk_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
+    dc->init = virtio_device_init;
+    dc->exit = virtio_device_exit;
+    dc->props = virtio_blk_properties;
+    vdc->get_config = virtio_blk_update_config;
+    vdc->set_config = virtio_blk_set_config;
+    vdc->get_features = virtio_blk_get_features;
+    vdc->set_status = virtio_blk_set_status;
+    vdc->reset = virtio_blk_reset;
+}
+
+static const TypeInfo virtio_device_info = {
+    .name = TYPE_VIRTIO_BLK,
+    .parent = TYPE_VIRTIO_DEVICE,
+    .instance_size = sizeof(VirtIOBlock),
+    .class_init = virtio_blk_class_init,
+};
+
+static void virtio_register_types(void)
+{
+    type_register_static(&virtio_device_info);
+}
+
+type_init(virtio_register_types)
hw/virtio-blk.h +4 -0
index f0740d0..97adaf2 100644
@@ -17,6 +17,10 @@
 #include "virtio.h"
 #include "hw/block-common.h"
 
+#define TYPE_VIRTIO_BLK "virtio-blk"
+#define VIRTIO_BLK(obj) \
+        OBJECT_CHECK(VirtIOBlock, (obj), TYPE_VIRTIO_BLK)
+
 /* from Linux's linux/virtio_blk.h */
 
 /* The ID for virtio_block */
Signature · 1 line
1.7.11.7
#7 lore raw

Re: [Qemu-devel] [RFC PATCH v6 6/6] virtio-blk : Add the virtio-blk device.

Quoted 5 lines · On 7 December 2012 13:32, <[email protected]> wrote:

From: KONRAD Frederic <[email protected]>

Create virtio-blk which extends virtio-device, so it can be connected on virtio-bus. I suggest one step to refactor virtio-blk-pci, and one more to clean virtio-blk.

Yes; I think you need to take this patchseries another step forward. There doesn't seem to be anything particularly obviously wrong here but it's hard to tell without seeing what happens to virtio-blk-pci and what the final virtio-blk looks like.

-- PMM

#8 lore raw
In reply to [email protected]
Quoted 9 lines · On Fri, Dec 07, 2012 at 02:32:29PM +0100, [email protected] wrote:

From: KONRAD Frederic <[email protected]>

You can clone that from here :
git.greensocs.com/home/greensocs/git/qemu_virtio.git virtio_refactoring_v6

The problem with the last RFC v5 was that virtio-blk refactoring broke virtio-blk-pci device ( SEGFAULT ). So I modify this last step to fix that issue.

Quoted 5 lines

In order to not break anything, I think we have to refactor virtio-pci-blk in a next step then add a supplementary step which clean virtio-blk
( eg : fix the cast ).

Does it make sense ?

I am yet to go over the patches but I did try to read previous discussion and I am still puzzled about the motivation. One of the previous messages mentioned this is to allow virtio-mmio.

Is the point to allow virtio-mmio? Why can't virtio-mmio be just another bus, like a pci bus, and another binding, like the virtio-pci binding?

Is the issue that bindings are not devices?
I'm sending a patchset to use DeviceState as binding pointer - will this address the issue?

If this was covered but I missed this I'll be thankful for pointers if any.
Thanks,

Signature · 1 line
MST
#9 lore raw
Quoted 10 lines · Michael S. Tsirkin
Quoted 9 lines · On Fri, Dec 07, 2012 at 02:32:29PM +0100, [email protected] wrote:

From: KONRAD Frederic <[email protected]>

You can clone that from here :
git.greensocs.com/home/greensocs/git/qemu_virtio.git virtio_refactoring_v6

The problem with the last RFC v5 was that virtio-blk refactoring broke virtio-blk-pci device ( SEGFAULT ). So I modify this last step to fix that issue.

Quoted 8 lines
Quoted 5 lines

In order to not break anything, I think we have to refactor virtio-pci-blk in a next step then add a supplementary step which clean virtio-blk
( eg : fix the cast ).

Does it make sense ?

I am yet to go over the patches but I did try to read previous discussion and I am still puzzled about the motivation. One of the previous messages mentioned this is to allow virtio-mmio.

Yes, the main goal is to have the choice of the transport device.

eg :

-device virtio-pci,id=transport1 -device virtio-scsi,bus=transport1

or

-device virtio-mmio,id=transport1 -device virtio-scsi,bus=transport1

That's why anthony suggest to create a virtio-bus to connect transport to device.

so all virtio-x devices must be created. And virtio-pci must have a virtio-bus.

Then to keep compability with the older version virtio-x-pci must create virtio-pci and virtio-x.

Quoted 4 lines

Is the point to allow virtio-mmio? Why can't virtio-mmio be just another bus, like a pci bus, and another binding, like the virtio-pci binding?

Do you mean something like creating all virtio device like virtio-mmio-x ?

Quoted 4 lines

Is the issue that bindings are not devices?
I'm sending a patchset to use DeviceState as binding pointer - will this address the issue?

The issue is that all is linked, and here the virtio-blk refactoring breaks virtio-blk-pci and virtio-blk-s390 devices as they didn't use QOM. But the newer version ( V7 ) didn't break anything.

Quoted 5 lines

If this was covered but I missed this I'll be thankful for pointers if any.
Thanks,

#10 lore raw
Quoted 23 lines · KONRAD Frédéric
Quoted 10 lines · Michael S. Tsirkin
Quoted 9 lines · On Fri, Dec 07, 2012 at 02:32:29PM +0100, [email protected] wrote:

From: KONRAD Frederic <[email protected]>

You can clone that from here :
git.greensocs.com/home/greensocs/git/qemu_virtio.git virtio_refactoring_v6

The problem with the last RFC v5 was that virtio-blk refactoring broke virtio-blk-pci device ( SEGFAULT ). So I modify this last step to fix that issue.

Quoted 8 lines
Quoted 5 lines

In order to not break anything, I think we have to refactor virtio-pci-blk in a next step then add a supplementary step which clean virtio-blk
( eg : fix the cast ).

Does it make sense ?

I am yet to go over the patches but I did try to read previous discussion and I am still puzzled about the motivation. One of the previous messages mentioned this is to allow virtio-mmio.

Yes, the main goal is to have the choice of the transport device.

eg :

Quoted 7 lines

-device virtio-pci,id=transport1 -device virtio-scsi,bus=transport1

or

-device virtio-mmio,id=transport1 -device virtio-scsi,bus=transport1 That's why anthony suggest to create a virtio-bus to connect transport to device.

If it's an implementation detail, fine. If it's user-visible, I think it's a bad idea.

Quoted 10 lines

so all virtio-x devices must be created. And virtio-pci must have a virtio-bus.

Then to keep compability with the older version virtio-x-pci must create virtio-pci and virtio-x.

Quoted 4 lines

Is the point to allow virtio-mmio? Why can't virtio-mmio be just another bus, like a pci bus, and another binding, like the virtio-pci binding?

Do you mean something like creating all virtio device like virtio-mmio-x ?

Yes or to be closer to what we do with pci, virtio-x-mmio.

Quoted 7 lines
Quoted 4 lines

Is the issue that bindings are not devices?
I'm sending a patchset to use DeviceState as binding pointer - will this address the issue?

The issue is that all is linked, and here the virtio-blk refactoring breaks virtio-blk-pci and virtio-blk-s390 devices as they didn't use QOM. But the newer version ( V7 ) didn't break anything.

No, my question was why is all this useful?

Quoted 5 lines
Quoted 5 lines

If this was covered but I missed this I'll be thankful for pointers if any.
Thanks,

#11 lore raw
In reply to Michael S. Tsirkin
Quoted 3 lines · Michael S. Tsirkin

Is the point to allow virtio-mmio? Why can't virtio-mmio be just another bus, like a pci bus, and another binding, like the virtio-pci binding?

(a) the current code is really not very nice because it's not actually a proper set of QOM/qdev devices
(b) unlike PCI, you can't create sysbus devices on the command line, because they don't correspond to a user pluggable bit of hardware. We don't want users to have to know an address and IRQ number for each virtio-mmio device (especially since these are board specific); instead the board can create and wire up transport devices wherever is suitable, and the user just creates the backend (which is plugged into the virtio bus).

-- PMM

#12 lore raw
Quoted 15 lines · Peter Maydell
Quoted 3 lines · Michael S. Tsirkin

Is the point to allow virtio-mmio? Why can't virtio-mmio be just another bus, like a pci bus, and another binding, like the virtio-pci binding?

(a) the current code is really not very nice because it's not actually a proper set of QOM/qdev devices
(b) unlike PCI, you can't create sysbus devices on the command line, because they don't correspond to a user pluggable bit of hardware. We don't want users to have to know an address and IRQ number for each virtio-mmio device (especially since these are board specific); instead the board can create and wire up transport devices wherever is suitable, and the user just creates the backend (which is plugged into the virtio bus).

Quoted 1 line

-- PMM

This is what I am saying: create your own bus and put your devices there. Allocate resources when you init a device.

Instead you seem to want to expose a virtio device as two devices to user - if true this is not reasonable.

Signature · 1 line
MST
#13 lore raw
Quoted 2 lines · Michael S. Tsirkin

This is what I am saying: create your own bus and put your devices there.

What bus?

-- PMM

#14 lore raw

Il 18/12/2012 12:26, Peter Maydell ha scritto:

Quoted 5 lines · Michael S. Tsirkin
Quoted 2 lines

This is what I am saying: create your own bus and put your devices there.

What bus?

A virtio bus like the one in these patches. But mst is suggesting to leave virtio.c aside, and only use the virtio bus in the virtio-x-mmio devices, to connect to the virtio-mmio device provided by the board.

Either way is fine for me.

Paolo

#15 lore raw
Quoted 10 lines · Paolo Bonzini

Il 18/12/2012 12:26, Peter Maydell ha scritto:

Quoted 5 lines · Michael S. Tsirkin
Quoted 2 lines

This is what I am saying: create your own bus and put your devices there.

What bus?

A virtio bus like the one in these patches. But mst is suggesting to leave virtio.c aside, and only use the virtio bus in the virtio-x-mmio devices, to connect to the virtio-mmio device provided by the board.

That doesn't make any sense to me -- why would you want to make mmio be randomly different from the other virtio transports? The code as it stands is a mess which ought to be cleaned up anyway...

To the extent that it's painful for users to manipulate qdev devices on the command line, that's a problem we ought to address at some point anyhow.

-- PMM

#16 lore raw
Quoted 6 lines · Peter Maydell
Quoted 5 lines · Paolo Bonzini

Il 18/12/2012 12:26, Peter Maydell ha scritto:

Quoted 4 lines · Michael S. Tsirkin
Quoted 2 lines

This is what I am saying: create your own bus and put your devices there.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

What bus?

A virtio bus like the one in these patches. But mst is suggesting to leave virtio.c aside, and only use the virtio bus in the virtio-x-mmio devices, to connect to the virtio-mmio device provided by the board.

That doesn't make any sense to me -- why would you want to make mmio be randomly different from the other virtio transports?

Not different at all. virtio-pci uses the pci bus. It's you who's saying mmio is different and can not work with existing bindings.

Quoted 2 lines

The code
as it stands is a mess which ought to be cleaned up anyway...

My experience is all working code is somewhat messy. This is working code.

I'm sure we shouldnot add more ways to create devices, we have two for each device already, that's too much. You can't seriously add yet another way, keep the two existing ones around as legacy and claim it's a cleanup. You are single-handedly making the testing matrix bigger by 1/3.

And what makes virtio so special anyway? e1000 can be used without exposing users to internal buses and all kind of nastiness like this. People just want to install a driver and have a faster IO.

Quoted 5 lines

To the extent that it's painful for users to manipulate qdev devices on the command line, that's a problem we ought to address at some point anyhow.

-- PMM

It's pretty painful, yes, but adding yet another way to do it is not addressing the problem.

Signature · 1 line
MST
#17 lore raw
Quoted 2 lines · Michael S. Tsirkin

And what makes virtio so special anyway? e1000 can be used without exposing users to internal buses and all kind of nastiness like this.

Congratulations, you're using an architecture that has a pluggable discoverable bus implemented by just about all machines using that architecture. That makes things much easier for you.

-- PMM

#18 lore raw

Il 18/12/2012 15:00, Peter Maydell ha scritto:

Quoted 6 lines · Michael S. Tsirkin
Quoted 2 lines
Quoted 2 lines

And what makes virtio so special anyway? e1000 can be used without exposing users to internal buses and all kind of nastiness like this.

Congratulations, you're using an architecture that has a pluggable discoverable bus implemented by just about all machines using that architecture. That makes things much easier for you.

Yes, that's true. And you're basically using virtio as the pluggable discoverable bus, which is actually a pretty good idea.

However, what you are doing is very similar to what virtio-s390 does, and it manages to do it just fine with the existing virtio.c infrastructure. The only difference is that you have a 1:1 relationship between virtio-mmio "slots" described by the board and virtio-mmio devices added by the user.

True, it is not pure qdev, but it is much simpler and doesn't require convincing grumpy maintainers. :)

Paolo

#19 lore raw
Quoted 8 lines · Paolo Bonzini

Yes, that's true. And you're basically using virtio as the pluggable discoverable bus, which is actually a pretty good idea.

However, what you are doing is very similar to what virtio-s390 does, and it manages to do it just fine with the existing virtio.c infrastructure. The only difference is that you have a 1:1 relationship between virtio-mmio "slots" described by the board and virtio-mmio devices added by the user.

Also it looks like the board model and the 'bridge' and the transport implementation are all collaborating to get the virtio memory sorted out, rather than it just being "instantiate a bridge here"...

Quoted 2 lines

True, it is not pure qdev, but it is much simpler and doesn't require convincing grumpy maintainers. :)

I'm not actually personally all that attached to this design -- it's just trying to implement a suggestion by Anthony.

It does seem frankly bizarre that adding a new transport requires knowing about all the backends (notice how s390-virtio-bus.c has to register types for each backend). The kernel gets the transport vs backend separation much cleaner and it was much easier to add the virtio support there.

-- PMM

#20 lore raw
Quoted 9 lines · Peter Maydell
Quoted 2 lines

True, it is not pure qdev, but it is much simpler and doesn't require convincing grumpy maintainers. :)

I'm not actually personally all that attached to this design -- it's just trying to implement a suggestion by Anthony.

It does seem frankly bizarre that adding a new transport requires knowing about all the backends (notice how s390-virtio-bus.c has to register types for each backend).

I agree it's not pretty. The issue is that things like e.g. PCI class need per-device handling. We could invent our own class system but that seems like overkill:
it's rare enough to add new devices.

Quoted 5 lines

The kernel gets the transport
vs backend separation much cleaner and it was much easier to add the virtio support there.

-- PMM

By the way even there the separation does confuse users sometimes. Things like autoloading are broken
and some tools poking at sysfs get confused.

At this point it's probably not worth changing though.

Signature · 1 line
MST
#21 lore raw
In reply to Peter Maydell

Il 18/12/2012 15:56, Peter Maydell ha scritto:

Quoted 10 lines · Paolo Bonzini
Quoted 8 lines

Yes, that's true. And you're basically using virtio as the pluggable discoverable bus, which is actually a pretty good idea.

However, what you are doing is very similar to what virtio-s390 does, and it manages to do it just fine with the existing virtio.c infrastructure. The only difference is that you have a 1:1 relationship between virtio-mmio "slots" described by the board and virtio-mmio devices added by the user.

Quoted 3 lines

Also it looks like the board model and the 'bridge' and the transport implementation are all collaborating to get the virtio memory sorted out, rather than it just being "instantiate a bridge here"...

But s390 is weird. :)

Quoted 5 lines
Quoted 2 lines

True, it is not pure qdev, but it is much simpler and doesn't require convincing grumpy maintainers. :)

I'm not actually personally all that attached to this design -- it's just trying to implement a suggestion by Anthony.

Yes, and I agree FWIW.

Quoted 5 lines

It does seem frankly bizarre that adding a new transport requires knowing about all the backends (notice how s390-virtio-bus.c has to register types for each backend). The kernel gets the transport vs backend separation much cleaner and it was much easier to add the virtio support there.

Yes, I agree. However, to some extent it's unavoidable. For example, the PCI transport needs to know the class id for each backend. You may have a single virtio-pci device types, or separate types for virtio-blk/net/scsi-pci, but it's true anyway.

Paolo

#22 lore raw
Quoted 8 lines · Paolo Bonzini
Quoted 5 lines

It does seem frankly bizarre that adding a new transport requires knowing about all the backends (notice how s390-virtio-bus.c has to register types for each backend). The kernel gets the transport vs backend separation much cleaner and it was much easier to add the virtio support there.

Yes, I agree. However, to some extent it's unavoidable. For example, the PCI transport needs to know the class id for each backend.

PCI device ID too (they don't match virtio IDs).

Signature · 1 line
MST
#23 lore raw
In reply to Peter Maydell
Quoted 9 lines · Peter Maydell
Quoted 2 lines · Michael S. Tsirkin

And what makes virtio so special anyway? e1000 can be used without exposing users to internal buses and all kind of nastiness like this.

Congratulations, you're using an architecture that has a pluggable discoverable bus implemented by just about all machines using that architecture. That makes things much easier for you.

-- PMM

That's on the guest side. Yes, drivers are a problem but they are not qemu problem as such.
But on the user/qemu side I dont' yes see why it's so different.

#24 lore raw
In reply to Michael S. Tsirkin
Quoted 15 lines · Michael S. Tsirkin
Quoted 14 lines · Peter Maydell
Quoted 3 lines · Michael S. Tsirkin

Is the point to allow virtio-mmio? Why can't virtio-mmio be just another bus, like a pci bus, and another binding, like the virtio-pci binding?

(a) the current code is really not very nice because it's not actually a proper set of QOM/qdev devices
(b) unlike PCI, you can't create sysbus devices on the command line, because they don't correspond to a user pluggable bit of hardware. We don't want users to have to know an address and IRQ number for each virtio-mmio device (especially since these are board specific); instead the board can create and wire up transport devices wherever is suitable, and the user just creates the backend (which is plugged into the virtio bus).

Quoted 8 lines
Quoted 1 line

-- PMM

This is what I am saying: create your own bus and put your devices there. Allocate resources when you init a device.

Instead you seem to want to expose a virtio device as two devices to user - if true this is not reasonable.

The modifications will be transparent to the user, as we will keep virtio-x-pci devices.

#25 lore raw
Quoted 21 lines · KONRAD Frédéric
Quoted 20 lines · Michael S. Tsirkin
Quoted 14 lines · Peter Maydell
Quoted 3 lines · Michael S. Tsirkin

Is the point to allow virtio-mmio? Why can't virtio-mmio be just another bus, like a pci bus, and another binding, like the virtio-pci binding?

(a) the current code is really not very nice because it's not actually a proper set of QOM/qdev devices
(b) unlike PCI, you can't create sysbus devices on the command line, because they don't correspond to a user pluggable bit of hardware. We don't want users to have to know an address and IRQ number for each virtio-mmio device (especially since these are board specific); instead the board can create and wire up transport devices wherever is suitable, and the user just creates the backend (which is plugged into the virtio bus).

Quoted 1 line

-- PMM

This is what I am saying: create your own bus and put your devices there. Allocate resources when you init a device.

Quoted 5 lines
Quoted 3 lines

Instead you seem to want to expose a virtio device as two devices to user - if true this is not reasonable.

The modifications will be transparent to the user, as we will keep virtio-x-pci devices.

So there are three ways to add virtio pci devices now. Legacy -device virtio-net-pci, legacy legacy -net nic.model=virtio and the new one with two devices.
If yes it's not transparent, it's user visible.
Or did I misunderstand?

Look we can have a virtio network device on a PCI bus. A very similar device can be created on XXX bus, and we can and do share a lot of code.
This makes it two devices? Why not 4?
One for TX one for RX one for control one for PCI. I hope I'm not giving anyone ideas ...

Signature · 1 line
MST
#26 lore raw
Quoted 34 lines · Michael S. Tsirkin
Quoted 21 lines · KONRAD Frédéric
Quoted 20 lines · Michael S. Tsirkin
Quoted 14 lines · Peter Maydell
Quoted 3 lines · Michael S. Tsirkin

Is the point to allow virtio-mmio? Why can't virtio-mmio be just another bus, like a pci bus, and another binding, like the virtio-pci binding?

(a) the current code is really not very nice because it's not actually a proper set of QOM/qdev devices
(b) unlike PCI, you can't create sysbus devices on the command line, because they don't correspond to a user pluggable bit of hardware. We don't want users to have to know an address and IRQ number for each virtio-mmio device (especially since these are board specific); instead the board can create and wire up transport devices wherever is suitable, and the user just creates the backend (which is plugged into the virtio bus).

Quoted 1 line

-- PMM

This is what I am saying: create your own bus and put your devices there. Allocate resources when you init a device.

Quoted 5 lines
Quoted 3 lines

Instead you seem to want to expose a virtio device as two devices to user - if true this is not reasonable.

The modifications will be transparent to the user, as we will keep virtio-x-pci devices.

So there are three ways to add virtio pci devices now. Legacy -device virtio-net-pci, legacy legacy -net nic.model=virtio and the new one with two devices.
If yes it's not transparent, it's user visible.
Or did I misunderstand?

Quoted 6 lines

Look we can have a virtio network device on a PCI bus. A very similar device can be created on XXX bus, and we can and do share a lot of code.
This makes it two devices? Why not 4?
One for TX one for RX one for control one for PCI. I hope I'm not giving anyone ideas ...

Devices != things users need to worry about.

The documented way to create network devices is completely different than any possible syntax you can conjure up with -device.

Really, -device is not something users should have to deal with--ever. It's a low level API, not a UI.

Regards,

Anthony Liguori

Quoted 3 lines
Signature · 2 lines
-- 
MST
#27 lore raw
Quoted 48 lines · Anthony Liguori
Quoted 34 lines · Michael S. Tsirkin
Quoted 21 lines · KONRAD Frédéric
Quoted 20 lines · Michael S. Tsirkin
Quoted 14 lines · Peter Maydell
Quoted 3 lines · Michael S. Tsirkin

Is the point to allow virtio-mmio? Why can't virtio-mmio be just another bus, like a pci bus, and another binding, like the virtio-pci binding?

(a) the current code is really not very nice because it's not actually a proper set of QOM/qdev devices
(b) unlike PCI, you can't create sysbus devices on the command line, because they don't correspond to a user pluggable bit of hardware. We don't want users to have to know an address and IRQ number for each virtio-mmio device (especially since these are board specific); instead the board can create and wire up transport devices wherever is suitable, and the user just creates the backend (which is plugged into the virtio bus).

Quoted 1 line

-- PMM

This is what I am saying: create your own bus and put your devices there. Allocate resources when you init a device.

Quoted 5 lines
Quoted 3 lines

Instead you seem to want to expose a virtio device as two devices to user - if true this is not reasonable.

The modifications will be transparent to the user, as we will keep virtio-x-pci devices.

So there are three ways to add virtio pci devices now. Legacy -device virtio-net-pci, legacy legacy -net nic.model=virtio and the new one with two devices.
If yes it's not transparent, it's user visible.
Or did I misunderstand?

Quoted 6 lines

Look we can have a virtio network device on a PCI bus. A very similar device can be created on XXX bus, and we can and do share a lot of code.
This makes it two devices? Why not 4?
One for TX one for RX one for control one for PCI. I hope I'm not giving anyone ideas ...

Devices != things users need to worry about.

The documented way to create network devices is completely different than any possible syntax you can conjure up with -device.

Quoted 6 lines

Really, -device is not something users should have to deal with--ever. It's a low level API, not a UI.

Regards,

Anthony Liguori

Interesting.
Let's assume I want to put a device behind a pci bridge (for example I want more than 32 of these). It's impossible without -device, isn't it?

Quoted 3 lines
Quoted 3 lines
Signature · 2 lines
-- 
MST
#28 lore raw
Quoted 52 lines · Michael S. Tsirkin
Quoted 51 lines · Anthony Liguori
Quoted 34 lines · Michael S. Tsirkin
Quoted 21 lines · KONRAD Frédéric
Quoted 20 lines · Michael S. Tsirkin
Quoted 14 lines · Peter Maydell
Quoted 3 lines · Michael S. Tsirkin

Is the point to allow virtio-mmio? Why can't virtio-mmio be just another bus, like a pci bus, and another binding, like the virtio-pci binding?

(a) the current code is really not very nice because it's not actually a proper set of QOM/qdev devices
(b) unlike PCI, you can't create sysbus devices on the command line, because they don't correspond to a user pluggable bit of hardware. We don't want users to have to know an address and IRQ number for each virtio-mmio device (especially since these are board specific); instead the board can create and wire up transport devices wherever is suitable, and the user just creates the backend (which is plugged into the virtio bus).

Quoted 1 line

-- PMM

This is what I am saying: create your own bus and put your devices there. Allocate resources when you init a device.

Quoted 5 lines
Quoted 3 lines

Instead you seem to want to expose a virtio device as two devices to user - if true this is not reasonable.

The modifications will be transparent to the user, as we will keep virtio-x-pci devices.

So there are three ways to add virtio pci devices now. Legacy -device virtio-net-pci, legacy legacy -net nic.model=virtio and the new one with two devices.
If yes it's not transparent, it's user visible.
Or did I misunderstand?

Quoted 6 lines

Look we can have a virtio network device on a PCI bus. A very similar device can be created on XXX bus, and we can and do share a lot of code.
This makes it two devices? Why not 4?
One for TX one for RX one for control one for PCI. I hope I'm not giving anyone ideas ...

Devices != things users need to worry about.

The documented way to create network devices is completely different than any possible syntax you can conjure up with -device.

Really, -device is not something users should have to deal with--ever. It's a low level API, not a UI.

Quoted 7 lines
Quoted 3 lines

Regards,

Anthony Liguori

Interesting.
Let's assume I want to put a device behind a pci bridge (for example I want more than 32 of these).

You don't want to put a device behind a PCI bridge, you want to have more than 32 devices.

'-net nic' should do the Right Thing when presented with more than 32 devices.

Quoted 1 line

It's impossible without -device, isn't it?

Think of -device like an API and -net as our UI. Management tools want to use an API, because it provides low level control and generally has limited side effects.

Users want a UI that makes sense. Trying to make both things satisfy both audiences will almost certainly fail.

If a common use case cannot be done without resorting to using our API, then we ought to improve our UI.

Regards,

Anthony Liguori

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Signature · 2 lines
-- 
MST
#29 lore raw
Quoted 76 lines · Anthony Liguori
Quoted 52 lines · Michael S. Tsirkin
Quoted 51 lines · Anthony Liguori
Quoted 34 lines · Michael S. Tsirkin
Quoted 21 lines · KONRAD Frédéric
Quoted 20 lines · Michael S. Tsirkin
Quoted 14 lines · Peter Maydell
Quoted 3 lines · Michael S. Tsirkin

Is the point to allow virtio-mmio? Why can't virtio-mmio be just another bus, like a pci bus, and another binding, like the virtio-pci binding?

(a) the current code is really not very nice because it's not actually a proper set of QOM/qdev devices
(b) unlike PCI, you can't create sysbus devices on the command line, because they don't correspond to a user pluggable bit of hardware. We don't want users to have to know an address and IRQ number for each virtio-mmio device (especially since these are board specific); instead the board can create and wire up transport devices wherever is suitable, and the user just creates the backend (which is plugged into the virtio bus).

Quoted 1 line

-- PMM

This is what I am saying: create your own bus and put your devices there. Allocate resources when you init a device.

Quoted 5 lines
Quoted 3 lines

Instead you seem to want to expose a virtio device as two devices to user - if true this is not reasonable.

The modifications will be transparent to the user, as we will keep virtio-x-pci devices.

So there are three ways to add virtio pci devices now. Legacy -device virtio-net-pci, legacy legacy -net nic.model=virtio and the new one with two devices.
If yes it's not transparent, it's user visible.
Or did I misunderstand?

Quoted 6 lines

Look we can have a virtio network device on a PCI bus. A very similar device can be created on XXX bus, and we can and do share a lot of code.
This makes it two devices? Why not 4?
One for TX one for RX one for control one for PCI. I hope I'm not giving anyone ideas ...

Devices != things users need to worry about.

The documented way to create network devices is completely different than any possible syntax you can conjure up with -device.

Really, -device is not something users should have to deal with--ever. It's a low level API, not a UI.

Quoted 7 lines
Quoted 3 lines

Regards,

Anthony Liguori

Interesting.
Let's assume I want to put a device behind a pci bridge (for example I want more than 32 of these).

You don't want to put a device behind a PCI bridge, you want to have more than 32 devices.

'-net nic' should do the Right Thing when presented with more than 32 devices.

Quoted 1 line

It's impossible without -device, isn't it?

Think of -device like an API and -net as our UI. Management tools want to use an API, because it provides low level control and generally has limited side effects.

Users want a UI that makes sense. Trying to make both things satisfy both audiences will almost certainly fail.

Quoted 6 lines

If a common use case cannot be done without resorting to using our API, then we ought to improve our UI.

Regards,

Anthony Liguori

I guess you are saying we want to add bus= option to -net nic?

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Signature · 2 lines
-- 
MST
#30 lore raw
Quoted 1 line · Michael S. Tsirkin

I guess you are saying we want to add bus= option to -net nic?

I absolutely wouldn't object to that.

But I can think of better solutions too. Like:

    -virtio-net ...

Regards,

Anthony Liguori

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Signature · 2 lines
-- 
MST
#31 lore raw
Quoted 6 lines · Anthony Liguori
Quoted 1 line · Michael S. Tsirkin

I guess you are saying we want to add bus= option to -net nic?

I absolutely wouldn't object to that.

Quoted 7 lines

But I can think of better solutions too. Like:

    -virtio-net ...

Regards,

Anthony Liguori

for most people I think virtio is an implementation detail really. no?

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Signature · 2 lines
-- 
MST
#32 lore raw
Quoted 9 lines · Michael S. Tsirkin
Quoted 8 lines · Anthony Liguori
Quoted 1 line · Michael S. Tsirkin

I guess you are saying we want to add bus= option to -net nic?

I absolutely wouldn't object to that.

But I can think of better solutions too. Like:

Quoted 7 lines
Quoted 5 lines
    -virtio-net ...

Regards,

Anthony Liguori

for most people I think virtio is an implementation detail really. no?

So what is it that people really want to do?

Is tap an implementation detail? Should we just do -nics 4 and call it a day? I'm not being facetious, I really think we should approach it like this.

We don't need to design our internal interfaces/abstractions such that they map 1-1 with command line arguments meant for normal users.

Regards,

Anthony Liguori

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Signature · 2 lines
-- 
MST
#33 lore raw
Quoted 13 lines · Anthony Liguori
Quoted 11 lines · Michael S. Tsirkin
Quoted 10 lines · Anthony Liguori
Quoted 1 line · Michael S. Tsirkin

I guess you are saying we want to add bus= option to -net nic?

I absolutely wouldn't object to that.

But I can think of better solutions too. Like:

    -virtio-net ...
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Regards,

Anthony Liguori

for most people I think virtio is an implementation detail really. no?

So what is it that people really want to do?

With virtio? They want to install a driver and have networking go faster.

Quoted 3 lines

Is tap an implementation detail? Should we just do -nics 4 and call it a day? I'm not being facetious, I really think we should approach it like this.

How would you make it work well?

Quoted 2 lines

We don't need to design our internal interfaces/abstractions such that they map 1-1 with command line arguments meant for normal users.

Of course.

Quoted 10 lines

Regards,

Anthony Liguori

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Signature · 2 lines
-- 
MST
#34 lore raw
In reply to Anthony Liguori
Quoted 65 lines · Anthony Liguori
Quoted 52 lines · Michael S. Tsirkin
Quoted 51 lines · Anthony Liguori
Quoted 34 lines · Michael S. Tsirkin
Quoted 21 lines · KONRAD Frédéric
Quoted 20 lines · Michael S. Tsirkin
Quoted 14 lines · Peter Maydell
Quoted 3 lines · Michael S. Tsirkin

Is the point to allow virtio-mmio? Why can't virtio-mmio be just another bus, like a pci bus, and another binding, like the virtio-pci binding?

(a) the current code is really not very nice because it's not actually a proper set of QOM/qdev devices
(b) unlike PCI, you can't create sysbus devices on the command line, because they don't correspond to a user pluggable bit of hardware. We don't want users to have to know an address and IRQ number for each virtio-mmio device (especially since these are board specific); instead the board can create and wire up transport devices wherever is suitable, and the user just creates the backend (which is plugged into the virtio bus).

Quoted 1 line

-- PMM

This is what I am saying: create your own bus and put your devices there. Allocate resources when you init a device.

Quoted 5 lines
Quoted 3 lines

Instead you seem to want to expose a virtio device as two devices to user - if true this is not reasonable.

The modifications will be transparent to the user, as we will keep virtio-x-pci devices.

So there are three ways to add virtio pci devices now. Legacy -device virtio-net-pci, legacy legacy -net nic.model=virtio and the new one with two devices.
If yes it's not transparent, it's user visible.
Or did I misunderstand?

Quoted 6 lines

Look we can have a virtio network device on a PCI bus. A very similar device can be created on XXX bus, and we can and do share a lot of code.
This makes it two devices? Why not 4?
One for TX one for RX one for control one for PCI. I hope I'm not giving anyone ideas ...

Devices != things users need to worry about.

The documented way to create network devices is completely different than any possible syntax you can conjure up with -device.

Really, -device is not something users should have to deal with--ever. It's a low level API, not a UI.

Quoted 7 lines
Quoted 3 lines

Regards,

Anthony Liguori

Interesting.
Let's assume I want to put a device behind a pci bridge (for example I want more than 32 of these).

You don't want to put a device behind a PCI bridge, you want to have more than 32 devices.

Quoted 6 lines

'-net nic' should do the Right Thing when presented with more than 32 devices.

Quoted 1 line

It's impossible without -device, isn't it?

Think of -device like an API and -net as our UI.

Wait a second, -net implies vlans no? And this means no offloads so performance suffers ...

Quoted 18 lines

Management tools want
to use an API, because it provides low level control and generally has limited side effects.

Users want a UI that makes sense. Trying to make both things satisfy both audiences will almost certainly fail.

If a common use case cannot be done without resorting to using our API, then we ought to improve our UI.

Regards,

Anthony Liguori

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Signature · 2 lines
-- 
MST
#35 lore raw
In reply to KONRAD Frédéric
Quoted 21 lines · KONRAD Frédéric
Quoted 20 lines · Michael S. Tsirkin
Quoted 14 lines · Peter Maydell
Quoted 3 lines · Michael S. Tsirkin

Is the point to allow virtio-mmio? Why can't virtio-mmio be just another bus, like a pci bus, and another binding, like the virtio-pci binding?

(a) the current code is really not very nice because it's not actually a proper set of QOM/qdev devices
(b) unlike PCI, you can't create sysbus devices on the command line, because they don't correspond to a user pluggable bit of hardware. We don't want users to have to know an address and IRQ number for each virtio-mmio device (especially since these are board specific); instead the board can create and wire up transport devices wherever is suitable, and the user just creates the backend (which is plugged into the virtio bus).

Quoted 1 line

-- PMM

This is what I am saying: create your own bus and put your devices there. Allocate resources when you init a device.

Quoted 5 lines
Quoted 3 lines

Instead you seem to want to expose a virtio device as two devices to user - if true this is not reasonable.

The modifications will be transparent to the user, as we will keep virtio-x-pci devices.

Then what's the point of all this?

-device virtio-pci,id=transport1 -device virtio-net,bus=transport1

or

-device virtio-mmio,id=transport1 -device virtio-net,bus=transport1

Is simply an insane way to create a network device.

Signature · 1 line
MST
#36 lore raw
Quoted 6 lines · Michael S. Tsirkin
Quoted 2 lines · KONRAD Frédéric

The modifications will be transparent to the user, as we will keep virtio-x-pci devices.

Then what's the point of all this?

Quoted 7 lines

-device virtio-pci,id=transport1 -device virtio-net,bus=transport1

or

-device virtio-mmio,id=transport1 -device virtio-net,bus=transport1

Is simply an insane way to create a network device.

1. You wouldn't create the virtio-mmio transport on the command line, the machine model does it (it has to because it's a sysbus device and it needs the address/irq lines wiring up properly), so it's just "-device virtio-net" (and let qemu find the bus automatically)
2. We shouldn't be making command line simplicity drive how we model devices inside QEMU. If we wanted to do that we should have stuck with the old -net command line arguments which are rather more userfriendly IMHO. If commandline confusion is getting to be a problem with all the -device foo stuff then we should probably fix that at the UI level.

-- PMM

#37 lore raw
Quoted 11 lines · Peter Maydell
Quoted 10 lines · Michael S. Tsirkin
Quoted 2 lines · KONRAD Frédéric

The modifications will be transparent to the user, as we will keep virtio-x-pci devices.

Then what's the point of all this?

-device virtio-pci,id=transport1 -device virtio-net,bus=transport1

or

Quoted 8 lines
Quoted 3 lines

-device virtio-mmio,id=transport1 -device virtio-net,bus=transport1

Is simply an insane way to create a network device.

1. You wouldn't create the virtio-mmio transport on the command line, the machine model does it (it has to because it's a sysbus device and it needs the address/irq lines wiring up properly), so it's just "-device virtio-net" (and let qemu find the bus automatically)

Bus auto-detection sounds good and would be nice for pci too. We had things like model=virtio originally which is pretty close. But the issue is, how then do you pass bus specific arguments like pci slot? This is what caused us to go the virtio-net-pci route to begin with.

Quoted 2 lines

2. We shouldn't be making command line simplicity drive how we model devices inside QEMU.

Confused. I was told that enabling
-device virtio-pci,id=transport1 -device virtio-net,bus=transport1
is the reason we have this patchset.

Quoted 3 lines

If we wanted to do that we should have
stuck with the old -net command line arguments which are rather more userfriendly IMHO.

The main thing that confused people with -net was the vlans and the need to specify -net twice.
A good UI would have been e.g. -nic model=virtio,net=user.

But one bad UI does not justify another one.

Quoted 5 lines

If commandline confusion is getting to
be a problem with all the -device foo stuff then we should probably fix that at the UI level.

-- PMM

I'd like to see a proposal about how we are going to do this.

Signature · 1 line
MST
#38 lore raw
Quoted 21 lines · Michael S. Tsirkin
Quoted 11 lines · Peter Maydell
Quoted 10 lines · Michael S. Tsirkin
Quoted 2 lines · KONRAD Frédéric

The modifications will be transparent to the user, as we will keep virtio-x-pci devices.

Then what's the point of all this?

-device virtio-pci,id=transport1 -device virtio-net,bus=transport1

or

Quoted 8 lines
Quoted 3 lines

-device virtio-mmio,id=transport1 -device virtio-net,bus=transport1

Is simply an insane way to create a network device.

1. You wouldn't create the virtio-mmio transport on the command line, the machine model does it (it has to because it's a sysbus device and it needs the address/irq lines wiring up properly), so it's just "-device virtio-net" (and let qemu find the bus automatically)

Quoted 5 lines

Bus auto-detection sounds good and would be nice for pci too. We had things like model=virtio originally which is pretty close. But the issue is, how then do you pass bus specific arguments like pci slot? This is what caused us to go the virtio-net-pci route to begin with.

PCI is not the same as MMIO here.

virtio-mmio devices are not pluggable. It makes a lot more sense to have a virtio-net-pci device. But it doesn't make much sense to have a virtio-net-mmio device.

Quoted 7 lines
Quoted 3 lines

2. We shouldn't be making command line simplicity drive how we model devices inside QEMU.

Confused. I was told that enabling
-device virtio-pci,id=transport1 -device virtio-net,bus=transport1
is the reason we have this patchset.

You were misinformed.

Quoted 7 lines
Quoted 3 lines

If we wanted to do that we should have
stuck with the old -net command line arguments which are rather more userfriendly IMHO.

The main thing that confused people with -net was the vlans and the need to specify -net twice.
A good UI would have been e.g. -nic model=virtio,net=user.

That was the original UI. It was even called -nics. See 7c9d8e if you're curious. I was never a fan of the -net syntax.

Quoted 9 lines

But one bad UI does not justify another one.

Quoted 5 lines

If commandline confusion is getting to
be a problem with all the -device foo stuff then we should probably fix that at the UI level.

-- PMM

I'd like to see a proposal about how we are going to do this.

(1) Stop conflating internal modeling with UI

(2) Add UI interfaces as appropriate

It's really that simple.

Regards,

Anthony Liguori

Quoted 3 lines
Signature · 2 lines
-- 
MST
#39 lore raw
In reply to Michael S. Tsirkin
Quoted 30 lines · Michael S. Tsirkin
Quoted 21 lines · KONRAD Frédéric
Quoted 20 lines · Michael S. Tsirkin
Quoted 14 lines · Peter Maydell
Quoted 3 lines · Michael S. Tsirkin

Is the point to allow virtio-mmio? Why can't virtio-mmio be just another bus, like a pci bus, and another binding, like the virtio-pci binding?

(a) the current code is really not very nice because it's not actually a proper set of QOM/qdev devices
(b) unlike PCI, you can't create sysbus devices on the command line, because they don't correspond to a user pluggable bit of hardware. We don't want users to have to know an address and IRQ number for each virtio-mmio device (especially since these are board specific); instead the board can create and wire up transport devices wherever is suitable, and the user just creates the backend (which is plugged into the virtio bus).

Quoted 1 line

-- PMM

This is what I am saying: create your own bus and put your devices there. Allocate resources when you init a device.

Quoted 5 lines
Quoted 3 lines

Instead you seem to want to expose a virtio device as two devices to user - if true this is not reasonable.

The modifications will be transparent to the user, as we will keep virtio-x-pci devices.

Then what's the point of all this?

Quoted 7 lines

-device virtio-pci,id=transport1 -device virtio-net,bus=transport1

or

-device virtio-mmio,id=transport1 -device virtio-net,bus=transport1

Is simply an insane way to create a network device.

virtio-pci is pluggable into a bus, virtio-mmio is not. There is a fixed number of them for a specific board and you have the option to add virtio devices to the ones that already exist.

virtio is a mess in its current state. Large swaths are not qdev'ified and we jump through hoops to try to set properties.

I can't imagine how you can look at this cleanup and not understand why it's nicer...

Regards,

Anthony Liguori

Quoted 3 lines
Signature · 2 lines
-- 
MST
#40 lore raw
In reply to Michael S. Tsirkin
Quoted 29 lines · Michael S. Tsirkin
Quoted 21 lines · KONRAD Frédéric
Quoted 20 lines · Michael S. Tsirkin
Quoted 14 lines · Peter Maydell
Quoted 3 lines · Michael S. Tsirkin

Is the point to allow virtio-mmio? Why can't virtio-mmio be just another bus, like a pci bus, and another binding, like the virtio-pci binding?

(a) the current code is really not very nice because it's not actually a proper set of QOM/qdev devices
(b) unlike PCI, you can't create sysbus devices on the command line, because they don't correspond to a user pluggable bit of hardware. We don't want users to have to know an address and IRQ number for each virtio-mmio device (especially since these are board specific); instead the board can create and wire up transport devices wherever is suitable, and the user just creates the backend (which is plugged into the virtio bus).

Quoted 1 line

-- PMM

This is what I am saying: create your own bus and put your devices there. Allocate resources when you init a device.

Quoted 5 lines
Quoted 3 lines

Instead you seem to want to expose a virtio device as two devices to user - if true this is not reasonable.

The modifications will be transparent to the user, as we will keep virtio-x-pci devices.

Then what's the point of all this?

Quoted 8 lines

-device virtio-pci,id=transport1 -device virtio-net,bus=transport1

or

-device virtio-mmio,id=transport1 -device virtio-net,bus=transport1

Is simply an insane way to create a network device.

To recap :

The idea is to have a virtio-bus between the transport device (like pci, mmio,... ).

Then we can have a platform with several virtio-mmio and then virtio-bus slot.

At the end user can add a virtio-device in the command line with -device parameter without recompiling the platform. That is not possible with just creating the virtio-x-mmio devices. The bus= option can be used to select the bus slot, but I'm not sure it is usefull.

The series keep the virtio-x-pci devices :
eg : step 11/61 for virtio-blk
So -device virtio-blk-pci or -device virtio-blk-s390 works as before.

Of course -device virtio-pci,id=transport1 -device virtio-net,bus=transport1 is possible but why using this command line when we could simply do :
-device virtio-net-pci ?

Fred

#41 lore raw
Quoted 43 lines · KONRAD Frédéric
Quoted 29 lines · Michael S. Tsirkin
Quoted 21 lines · KONRAD Frédéric
Quoted 20 lines · Michael S. Tsirkin
Quoted 14 lines · Peter Maydell
Quoted 3 lines · Michael S. Tsirkin

Is the point to allow virtio-mmio? Why can't virtio-mmio be just another bus, like a pci bus, and another binding, like the virtio-pci binding?

(a) the current code is really not very nice because it's not actually a proper set of QOM/qdev devices
(b) unlike PCI, you can't create sysbus devices on the command line, because they don't correspond to a user pluggable bit of hardware. We don't want users to have to know an address and IRQ number for each virtio-mmio device (especially since these are board specific); instead the board can create and wire up transport devices wherever is suitable, and the user just creates the backend (which is plugged into the virtio bus).

Quoted 1 line

-- PMM

This is what I am saying: create your own bus and put your devices there. Allocate resources when you init a device.

Quoted 5 lines
Quoted 3 lines

Instead you seem to want to expose a virtio device as two devices to user - if true this is not reasonable.

The modifications will be transparent to the user, as we will keep virtio-x-pci devices.

Then what's the point of all this?

Quoted 8 lines

-device virtio-pci,id=transport1 -device virtio-net,bus=transport1

or

-device virtio-mmio,id=transport1 -device virtio-net,bus=transport1

Is simply an insane way to create a network device.

To recap :

The idea is to have a virtio-bus between the transport device (like pci, mmio,... ).

Quoted 7 lines

Then we can have a platform with several virtio-mmio and then virtio-bus slot.

At the end user can add a virtio-device in the command line with -device parameter without recompiling the platform. That is not possible with just creating the virtio-x-mmio devices. The bus= option can be used to select the bus slot, but I'm not sure it is usefull.

pci uses addr option for this, I am guessing mmio can do the same.

Quoted 10 lines

The series keep the virtio-x-pci devices :
eg : step 11/61 for virtio-blk
So -device virtio-blk-pci or -device virtio-blk-s390 works as before.

Of course -device virtio-pci,id=transport1 -device virtio-net,bus=transport1 is
possible but why using this command line when we could simply do :
-device virtio-net-pci ?

Fred

Adding multiple ways to do one thing is a bad idea. I'm fine with modeling virtio by multiple devices internally, but exposing this to user is a mistake, we might rework this even more and command line has to be supported indefinitely.

#42 lore raw
Quoted 62 lines · Michael S. Tsirkin
Quoted 43 lines · KONRAD Frédéric
Quoted 29 lines · Michael S. Tsirkin
Quoted 21 lines · KONRAD Frédéric
Quoted 20 lines · Michael S. Tsirkin
Quoted 14 lines · Peter Maydell
Quoted 3 lines · Michael S. Tsirkin

Is the point to allow virtio-mmio? Why can't virtio-mmio be just another bus, like a pci bus, and another binding, like the virtio-pci binding?

(a) the current code is really not very nice because it's not actually a proper set of QOM/qdev devices
(b) unlike PCI, you can't create sysbus devices on the command line, because they don't correspond to a user pluggable bit of hardware. We don't want users to have to know an address and IRQ number for each virtio-mmio device (especially since these are board specific); instead the board can create and wire up transport devices wherever is suitable, and the user just creates the backend (which is plugged into the virtio bus).

Quoted 1 line

-- PMM

This is what I am saying: create your own bus and put your devices there. Allocate resources when you init a device.

Quoted 5 lines
Quoted 3 lines

Instead you seem to want to expose a virtio device as two devices to user - if true this is not reasonable.

The modifications will be transparent to the user, as we will keep virtio-x-pci devices.

Then what's the point of all this?

Quoted 8 lines

-device virtio-pci,id=transport1 -device virtio-net,bus=transport1

or

-device virtio-mmio,id=transport1 -device virtio-net,bus=transport1

Is simply an insane way to create a network device.

To recap :

The idea is to have a virtio-bus between the transport device (like pci, mmio,... ).

Quoted 7 lines

Then we can have a platform with several virtio-mmio and then virtio-bus slot.

At the end user can add a virtio-device in the command line with -device parameter without recompiling the platform. That is not possible with just creating the virtio-x-mmio devices. The bus= option can be used to select the bus slot, but I'm not sure it is usefull.

pci uses addr option for this, I am guessing mmio can do the same.

Quoted 9 lines

The series keep the virtio-x-pci devices :
eg : step 11/61 for virtio-blk
So -device virtio-blk-pci or -device virtio-blk-s390 works as before.

Of course -device virtio-pci,id=transport1 -device virtio-net,bus=transport1 is
possible but why using this command line when we could simply do :
-device virtio-net-pci ?

Quoted 7 lines
Quoted 1 line

Fred

Adding multiple ways to do one thing is a bad idea. I'm fine with modeling virtio by multiple devices internally, but exposing this to user is a mistake, we might rework this even more and command line has to be supported indefinitely.

for the moment all virtio-x-pci devices extend virtio-pci. So why not abstracting virtio-pci ?
Then there is only one way to add a virtio-x-pci device.