Skip to contentSkip to conversation

virtio-console: Move to qdev, multiple devices, generic ports

RFC PATCH In review Amit Shah 4 participants 11 messages Dec 22, 2009 – Jan 4, 2010 7 messages not in the archive Kbuild

lore
Share & tools
lore

Amit Shah

author
#0 lore raw

cover virtio-console: Move to qdev, multiple devices, generic ports

Hello,

Here's the latest patch series for enabling support for generic serial ports over the virtio-console device.

This series converts virtio-console to the qdev infrastructure, creates a new virtio-serial bus on which console and generic ports are put and adds support for multiple devices, each of which can have multiple ports.

I've tried converting the s390 bits but acks from the maintainers would be good.

The vl.c bits have to be changed to accomodate s390 -- what I'm currently doing is when an old-style

-virtioconsole

argument is found, a virtio-serial-pci bus is created and a virtioconsole device is put on top of that. That needs to change to check for either virtio-serial-pci or virtio-serial-s390 and use the appropriate one.

Other than that, this series passes my tests which ensures that the console and the other functionality works fine on old as well as new guests.

The major change from the last time this patch series was sent is that each port now has its own IO vqs instead of a common pair for all the ports.

Please review,
Amit.

Amit Shah (3):
virtio: Remove duplicate macro definition for max. virtqueues, bump
up the max
virtio-console: Add a virtio-serial bus, support for multiple devices
and ports
virtio-serial: Add a new virtserialport device for generic serial
port support

 Makefile.target        |    2 +-
 hw/pc.c                |    9 -
 hw/ppc440_bamboo.c     |    7 -
 hw/qdev.c              |    8 +-
 hw/s390-virtio-bus.c   |   16 +-
 hw/s390-virtio-bus.h   |    1 +
 hw/virtio-console.c    |  213 ++++++-----
 hw/virtio-console.h    |   19 -
 hw/virtio-pci.c        |   11 +-
 hw/virtio-serial-bus.c |  964 ++++++++++++++++++++++++++++++++++++++++++++++++
 hw/virtio-serial.h     |  230 ++++++++++++
 hw/virtio.c            |    2 -
 hw/virtio.h            |    4 +-
 qemu-options.hx        |    4 +
 sysemu.h               |    6 -
 vl.c                   |   18 +-
 16 files changed, 1350 insertions(+), 164 deletions(-)
 delete mode 100644 hw/virtio-console.h
 create mode 100644 hw/virtio-serial-bus.c
 create mode 100644 hw/virtio-serial.h
author
#1 lore raw

PATCH 1/3 virtio: Remove duplicate macro definition for max. virtqueues, bump up the max

VIRTIO_PCI_QUEUE_MAX is redefined in hw/virtio.c. Let's just keep it in hw/virtio.h.

Also, bump up the value of the maximum allowed virtqueues to 32. This is in preparation to allow multiple ports per virtio-console device.

---
 hw/virtio.c |    2 --
 hw/virtio.h |    2 +-
 2 files changed, 1 insertions(+), 3 deletions(-)
hw/virtio.c +0 -2
index cecd0dc..88f4e78 100644
@@ -75,8 +75,6 @@ struct VirtQueue
     void (*handle_output)(VirtIODevice *vdev, VirtQueue *vq);
 };
 
-#define VIRTIO_PCI_QUEUE_MAX        16
-
 /* virt queue functions */
 static void virtqueue_init(VirtQueue *vq)
 {
hw/virtio.h +1 -1
index 35532a6..769f540 100644
@@ -90,7 +90,7 @@ typedef struct {
     unsigned (*get_features)(void * opaque);
 } VirtIOBindings;
 
-#define VIRTIO_PCI_QUEUE_MAX 16
+#define VIRTIO_PCI_QUEUE_MAX 32
 
 #define VIRTIO_NO_VECTOR 0xffff
 
Signature · 1 line
1.6.2.5
author
#2 lore raw

PATCH 2/3 virtio-console: Add a virtio-serial bus, support for multiple devices and ports

This patch migrates virtio-console to the qdev infrastructure and creates a new virtio-serial bus on which multiple ports are exposed as devices. The bulk of the code now resides in a new file with virtio-console.c being just a simple qdev device.

This interface enables spawning of multiple virtio consoles as well as generic serial ports.

The older -virtconsole argument still works, but when using the new functionality, it is recommended to use

-device virtio-serial-pci -device virtconsole,...

The virtconsole device type accepts a chardev as an argument and a 'name' argument to identify the corresponding consoles on the host as well as the guest. The name, if given, is exposed via the 'name' sysfs attribute in the guest.

Care has been taken to ensure compatibility with kernels that do not support multiple ports as well as accepting incoming migrations from older qemu versions.

---
 Makefile.target        |    2 +-
 hw/pc.c                |    9 -
 hw/ppc440_bamboo.c     |    7 -
 hw/qdev.c              |    8 +-
 hw/s390-virtio-bus.c   |   16 +-
 hw/s390-virtio-bus.h   |    1 +
 hw/virtio-console.c    |  186 ++++------
 hw/virtio-console.h    |   19 -
 hw/virtio-pci.c        |   11 +-
 hw/virtio-serial-bus.c |  964 ++++++++++++++++++++++++++++++++++++++++++++++++
 hw/virtio-serial.h     |  230 ++++++++++++
 hw/virtio.h            |    2 +-
 qemu-options.hx        |    4 +
 sysemu.h               |    6 -
 vl.c                   |   18 +-
 15 files changed, 1317 insertions(+), 166 deletions(-)
 delete mode 100644 hw/virtio-console.h
 create mode 100644 hw/virtio-serial-bus.c
 create mode 100644 hw/virtio-serial.h
Makefile.target +1 -1
index 7c1f30c..74bb548 100644
@@ -156,7 +156,7 @@ ifdef CONFIG_SOFTMMU
 obj-y = vl.o async.o monitor.o pci.o pci_host.o pcie_host.o machine.o gdbstub.o
 # virtio has to be here due to weird dependency between PCI and virtio-net.
 # need to fix this properly
-obj-y += virtio-blk.o virtio-balloon.o virtio-net.o virtio-console.o virtio-pci.o
+obj-y += virtio-blk.o virtio-balloon.o virtio-net.o virtio-serial-bus.o virtio-console.o virtio-pci.o
 obj-$(CONFIG_KVM) += kvm.o kvm-all.o
 obj-$(CONFIG_ISA_MMIO) += isa_mmio.o
 LIBS+=-lz
hw/pc.c +0 -9
index db7d58e..5e742bf 100644
@@ -1242,15 +1242,6 @@ static void pc_init1(ram_addr_t ram_size,
         }
     }
 
-    /* Add virtio console devices */
-    if (pci_enabled) {
-        for(i = 0; i < MAX_VIRTIO_CONSOLES; i++) {
-            if (virtcon_hds[i]) {
-                pci_create_simple(pci_bus, -1, "virtio-console-pci");
-            }
-        }
-    }
-
     rom_load_fw(fw_cfg);
 }
 
hw/ppc440_bamboo.c +0 -7
index a488240..1ab9872 100644
@@ -108,13 +108,6 @@ static void bamboo_init(ram_addr_t ram_size,
     env = ppc440ep_init(&ram_size, &pcibus, pci_irq_nrs, 1, cpu_model);
 
     if (pcibus) {
-        /* Add virtio console devices */
-        for(i = 0; i < MAX_VIRTIO_CONSOLES; i++) {
-            if (virtcon_hds[i]) {
-                pci_create_simple(pcibus, -1, "virtio-console-pci");
-            }
-        }
-
         /* Register network interfaces. */
         for (i = 0; i < nb_nics; i++) {
             /* There are no PCI NICs on the Bamboo board, but there are
hw/qdev.c +2 -6
index b6bd4ae..38c6e15 100644
@@ -321,13 +321,9 @@ void qdev_machine_creation_done(void)
 CharDriverState *qdev_init_chardev(DeviceState *dev)
 {
     static int next_serial;
-    static int next_virtconsole;
+
     /* FIXME: This is a nasty hack that needs to go away.  */
-    if (strncmp(dev->info->name, "virtio", 6) == 0) {
-        return virtcon_hds[next_virtconsole++];
-    } else {
-        return serial_hds[next_serial++];
-    }
+    return serial_hds[next_serial++];
 }
 
 BusState *qdev_get_parent_bus(DeviceState *dev)
hw/s390-virtio-bus.c +9 -7
index dc154ed..79ba9fc 100644
@@ -26,7 +26,7 @@
 #include "loader.h"
 #include "elf.h"
 #include "hw/virtio.h"
-#include "hw/virtio-console.h"
+#include "hw/virtio-serial.h"
 #include "hw/sysbus.h"
 #include "kvm.h"
 
@@ -130,7 +130,7 @@ static int s390_virtio_blk_init(VirtIOS390Device *dev)
     return s390_virtio_device_init(dev, vdev);
 }
 
-static int s390_virtio_console_init(VirtIOS390Device *dev)
+static int s390_virtio_serial_init(VirtIOS390Device *dev)
 {
     VirtIOS390Bus *bus;
     VirtIODevice *vdev;
@@ -138,7 +138,7 @@ static int s390_virtio_console_init(VirtIOS390Device *dev)
 
     bus = DO_UPCAST(VirtIOS390Bus, bus, dev->qdev.parent_bus);
 
-    vdev = virtio_console_init((DeviceState *)dev);
+    vdev = virtio_serial_init((DeviceState *)dev, dev->max_virtserial_ports);
     if (!vdev) {
         return -1;
     }
@@ -336,11 +336,13 @@ static VirtIOS390DeviceInfo s390_virtio_blk = {
     },
 };
 
-static VirtIOS390DeviceInfo s390_virtio_console = {
-    .init = s390_virtio_console_init,
-    .qdev.name = "virtio-console-s390",
+static VirtIOS390DeviceInfo s390_virtio_serial = {
+    .init = s390_virtio_serial_init,
+    .qdev.name = "virtio-serial-s390",
     .qdev.size = sizeof(VirtIOS390Device),
     .qdev.props = (Property[]) {
+        DEFINE_PROP_UINT32("max_ports", VirtIOS390Device, max_virtserial_ports,
+                           15),
         DEFINE_PROP_END_OF_LIST(),
     },
 };
@@ -364,7 +366,7 @@ static void s390_virtio_bus_register_withprop(VirtIOS390DeviceInfo *info)
 
 static void s390_virtio_register(void)
 {
-    s390_virtio_bus_register_withprop(&s390_virtio_console);
+    s390_virtio_bus_register_withprop(&s390_virtio_serial);
     s390_virtio_bus_register_withprop(&s390_virtio_blk);
     s390_virtio_bus_register_withprop(&s390_virtio_net);
 }
hw/s390-virtio-bus.h +1 -0
index ef36714..42e56ce 100644
@@ -40,6 +40,7 @@ typedef struct VirtIOS390Device {
     VirtIODevice *vdev;
     DriveInfo *dinfo;
     NICConf nic;
+    uint32_t max_virtserial_ports;
 } VirtIOS390Device;
 
 typedef struct VirtIOS390Bus {
hw/virtio-console.c +82 -104

225 lines not on this page · raw message

hw/virtio-console.h deleted +0 -19
deleted file mode 100644
index 84d0717..0000000
@@ -1,19 +0,0 @@
-/*
- * Virtio Console Support
- *
- * Copyright IBM, Corp. 2008
- *
- * Authors:
- *  Christian Ehrhardt <[email protected]>
- *
- * This work is licensed under the terms of the GNU GPL, version 2.  See
- * the COPYING file in the top-level directory.
- *
- */
-#ifndef _QEMU_VIRTIO_CONSOLE_H
-#define _QEMU_VIRTIO_CONSOLE_H
-
-/* The ID for virtio console */
-#define VIRTIO_ID_CONSOLE 3
-
-#endif
hw/virtio-pci.c +7 -4
index 62b46bd..1baca0d 100644
@@ -92,6 +92,7 @@ typedef struct {
     uint32_t nvectors;
     DriveInfo *dinfo;
     NICConf nic;
+    uint32_t max_virtserial_ports;
 } VirtIOPCIProxy;
 
 /* virtio device */
@@ -481,7 +482,7 @@ static int virtio_blk_exit_pci(PCIDevice *pci_dev)
     return virtio_exit_pci(pci_dev);
 }
 
-static int virtio_console_init_pci(PCIDevice *pci_dev)
+static int virtio_serial_init_pci(PCIDevice *pci_dev)
 {
     VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
     VirtIODevice *vdev;
@@ -491,7 +492,7 @@ static int virtio_console_init_pci(PCIDevice *pci_dev)
         proxy->class_code != PCI_CLASS_OTHERS)          /* qemu-kvm  */
         proxy->class_code = PCI_CLASS_COMMUNICATION_OTHER;
 
-    vdev = virtio_console_init(&pci_dev->qdev);
+    vdev = virtio_serial_init(&pci_dev->qdev, proxy->max_virtserial_ports);
     if (!vdev) {
         return -1;
     }
@@ -569,12 +570,14 @@ static PCIDeviceInfo virtio_info[] = {
         },
         .qdev.reset = virtio_pci_reset,
     },{
-        .qdev.name = "virtio-console-pci",
+        .qdev.name = "virtio-serial-pci",
         .qdev.size = sizeof(VirtIOPCIProxy),
-        .init      = virtio_console_init_pci,
+        .init      = virtio_serial_init_pci,
         .exit      = virtio_exit_pci,
         .qdev.props = (Property[]) {
             DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0),
+            DEFINE_PROP_UINT32("max_ports", VirtIOPCIProxy, max_virtserial_ports,
+                               15),
             DEFINE_PROP_END_OF_LIST(),
         },
         .qdev.reset = virtio_pci_reset,
hw/virtio-serial-bus.c new file +964 -0

964 lines not on this page · raw message

hw/virtio-serial.h new file +230 -0

230 lines not on this page · raw message

hw/virtio.h +1 -1
index 769f540..a5d3147 100644
@@ -171,7 +171,7 @@ void virtio_bind_device(VirtIODevice *vdev, const VirtIOBindings *binding,
 /* Base devices.  */
 VirtIODevice *virtio_blk_init(DeviceState *dev, DriveInfo *dinfo);
 VirtIODevice *virtio_net_init(DeviceState *dev, NICConf *conf);
-VirtIODevice *virtio_console_init(DeviceState *dev);
+VirtIODevice *virtio_serial_init(DeviceState *dev, uint32_t max_nr_ports);
 VirtIODevice *virtio_balloon_init(DeviceState *dev);
 
 void virtio_net_exit(VirtIODevice *vdev);
qemu-options.hx +4 -0
index b8cc375..183b616 100644
@@ -1873,6 +1873,10 @@ DEF("virtioconsole", HAS_ARG, QEMU_OPTION_virtiocon, \
 STEXI
 @item -virtioconsole @var{c}
 Set virtio console.
+
+This option is maintained for backward compatibility.
+
+Please use @code{-device virtconsole} for the new way of invocation.
 ETEXI
 
 DEF("show-cursor", 0, QEMU_OPTION_show_cursor, \
sysemu.h +0 -6
index 9d80bb2..9c3b281 100644
@@ -231,12 +231,6 @@ extern CharDriverState *serial_hds[MAX_SERIAL_PORTS];
 
 extern CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
 
-/* virtio consoles */
-
-#define MAX_VIRTIO_CONSOLES 1
-
-extern CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES];
-
 #define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR)
 
 #ifdef HAS_AUDIO
vl.c +16 -2
index e606903..523022b 100644
@@ -173,6 +173,8 @@ int main(int argc, char **argv)
 
 #define DEFAULT_RAM_SIZE 128
 
+#define MAX_VIRTIO_CONSOLES 1
+
 static const char *data_dir;
 const char *bios_name = NULL;
 /* Note: drives_table[MAX_DRIVES] is a dummy block driver if none available
@@ -4816,6 +4818,7 @@ static int virtcon_parse(const char *devname)
 {
     static int index = 0;
     char label[32];
+    QemuOpts *opts;
 
     if (strcmp(devname, "none") == 0)
         return 0;
@@ -4823,6 +4826,13 @@ static int virtcon_parse(const char *devname)
         fprintf(stderr, "qemu: too many virtio consoles\n");
         exit(1);
     }
+
+    opts = qemu_opts_create(&qemu_device_opts, NULL, 0);
+    qemu_opt_set(opts, "driver", "virtio-serial-pci");
+    qdev_device_add(opts);
+
+    qemu_opt_set(opts, "driver", "virtconsole");
+
     snprintf(label, sizeof(label), "virtcon%d", index);
     virtcon_hds[index] = qemu_chr_open(label, devname, NULL);
     if (!virtcon_hds[index]) {
@@ -4830,6 +4840,9 @@ static int virtcon_parse(const char *devname)
                 devname, strerror(errno));
         return -1;
     }
+    qemu_opt_set(opts, "chardev", label);
+    qdev_device_add(opts);
+
     index++;
     return 0;
 }
@@ -5914,8 +5927,6 @@ int main(int argc, char **argv, char **envp)
         exit(1);
     if (foreach_device_config(DEV_PARALLEL, parallel_parse) < 0)
         exit(1);
-    if (foreach_device_config(DEV_VIRTCON, virtcon_parse) < 0)
-        exit(1);
 
     module_call_init(MODULE_INIT_DEVICE);
 
@@ -5959,6 +5970,9 @@ int main(int argc, char **argv, char **envp)
     if (qemu_opts_foreach(&qemu_device_opts, device_init_func, NULL, 1) != 0)
         exit(1);
 
+    if (foreach_device_config(DEV_VIRTCON, virtcon_parse) < 0)
+        exit(1);
+
     if (!display_state)
         dumb_display_init();
     /* just use the first displaystate for the moment */
Signature · 1 line
1.6.2.5
author
#3 lore raw

PATCH 3/3 virtio-serial: Add a new virtserialport device for generic serial port support

This patch adds generic serial ports over the virtio serial bus. These ports have a few more options that are not relevant for virtio console ports: the ability to cache buffers that are received for a port while it's disconnected, setting of limits to the bytes that are cached so as to prevent OOM conditions, etc.

Sample uses for such a device can be obtaining info from the guest like the file systems used, apps installed, etc. for offline usage and logged-in users, clipboard copy-paste, etc. for online usage.

For requirements, use-cases, test cases and some history see

http://www.linux-kvm.org/page/VMchannel_Requirements

---
 hw/virtio-console.c |   37 +++++++++++++++++++++++++++++++++++++
 1 files changed, 37 insertions(+), 0 deletions(-)
hw/virtio-console.c +37 -0
index b2e4eb1..fc0c239 100644
@@ -119,3 +119,40 @@ static void virtcon_register(void)
     virtio_serial_port_qdev_register(&virtcon_info);
 }
 device_init(virtcon_register)
+
+
+/* Generic Virtio Serial Ports */
+static int virtserial_port_initfn(VirtIOSerialDevice *dev)
+{
+    VirtIOSerialPort *port = DO_UPCAST(VirtIOSerialPort, dev, &dev->qdev);
+    VirtConsole *vcon = DO_UPCAST(VirtConsole, port, port);
+
+    port->info = dev->info;
+
+    if (vcon->chr) {
+        qemu_chr_add_handlers(vcon->chr, chr_can_read, chr_read, chr_event,
+                              vcon);
+    }
+    return 0;
+}
+
+static VirtIOSerialPortInfo virtserial_port_info = {
+    .qdev.name     = "virtserialport",
+    .qdev.size     = sizeof(VirtConsole),
+    .init          = virtserial_port_initfn,
+    .exit          = vcon_exitfn,
+    .have_data     = flush_buf,
+    .qdev.props = (Property[]) {
+        DEFINE_PROP_CHR("chardev", VirtConsole, chr),
+        DEFINE_PROP_STRING("name", VirtConsole, port.name),
+        DEFINE_PROP_INT32("cache_buffers", VirtConsole, port.cache_buffers, 1),
+        DEFINE_PROP_UINT64("byte_limit", VirtConsole, port.byte_limit, 0),
+        DEFINE_PROP_END_OF_LIST(),
+    },
+};
+
+static void virtserial_port_register(void)
+{
+    virtio_serial_port_qdev_register(&virtserial_port_info);
+}
+device_init(virtserial_port_register)
Signature · 1 line
1.6.2.5
#4 lore raw

[Qemu-devel] Re: [PATCH 2/3] virtio-console: Add a virtio-serial bus, support for multiple devices and ports

In reply to Amit Shah
Quoted 18 lines · Amit Shah

This patch migrates virtio-console to the qdev infrastructure and creates a new virtio-serial bus on which multiple ports are exposed as devices. The bulk of the code now resides in a new file with virtio-console.c being just a simple qdev device.

This interface enables spawning of multiple virtio consoles as well as generic serial ports.

The older -virtconsole argument still works, but when using the new functionality, it is recommended to use

-device virtio-serial-pci -device virtconsole,...

The virtconsole device type accepts a chardev as an argument and a 'name' argument to identify the corresponding consoles on the host as well as the guest. The name, if given, is exposed via the 'name' sysfs attribute in the guest.

Quoted 6 lines

Care has been taken to ensure compatibility with kernels that do not support multiple ports as well as accepting incoming migrations from older qemu versions.

Please split this patch. I got dizzy after only reading 1/4th of it :-).

Alex

author
#5 lore raw

[Qemu-devel] Re: [PATCH 2/3] virtio-console: Add a virtio-serial bus, support for multiple devices and ports

Quoted 19 lines · Alexander Graf
Quoted 18 lines · Amit Shah

This patch migrates virtio-console to the qdev infrastructure and creates a new virtio-serial bus on which multiple ports are exposed as devices. The bulk of the code now resides in a new file with virtio-console.c being just a simple qdev device.

This interface enables spawning of multiple virtio consoles as well as generic serial ports.

The older -virtconsole argument still works, but when using the new functionality, it is recommended to use

-device virtio-serial-pci -device virtconsole,...

The virtconsole device type accepts a chardev as an argument and a 'name' argument to identify the corresponding consoles on the host as well as the guest. The name, if given, is exposed via the 'name' sysfs attribute in the guest.

Quoted 8 lines
Quoted 6 lines

Care has been taken to ensure compatibility with kernels that do not support multiple ports as well as accepting incoming migrations from older qemu versions.

Please split this patch. I got dizzy after only reading 1/4th of it :-).

Ah, sooner the better I guess. I'll do that soon.

The interesting bits for you are in hw/s390-* and vl.c though.

Amit

#6 lore raw

[Qemu-devel] Re: [PATCH 2/3] virtio-console: Add a virtio-serial bus, support for multiple devices and ports

In reply to Amit Shah
Quoted 65 lines · Amit Shah

This patch migrates virtio-console to the qdev infrastructure and creates a new virtio-serial bus on which multiple ports are exposed as devices. The bulk of the code now resides in a new file with virtio-console.c being just a simple qdev device.

This interface enables spawning of multiple virtio consoles as well as generic serial ports.

The older -virtconsole argument still works, but when using the new functionality, it is recommended to use

-device virtio-serial-pci -device virtconsole,...

The virtconsole device type accepts a chardev as an argument and a 'name' argument to identify the corresponding consoles on the host as well as the guest. The name, if given, is exposed via the 'name' sysfs attribute in the guest.

Care has been taken to ensure compatibility with kernels that do not support multiple ports as well as accepting incoming migrations from older qemu versions.

---
 Makefile.target        |    2 +-
 hw/pc.c                |    9 -
 hw/ppc440_bamboo.c     |    7 -
 hw/qdev.c              |    8 +-
 hw/s390-virtio-bus.c   |   16 +-
 hw/s390-virtio-bus.h   |    1 +
 hw/virtio-console.c    |  186 ++++------
 hw/virtio-console.h    |   19 -
 hw/virtio-pci.c        |   11 +-
 hw/virtio-serial-bus.c |  964 ++++++++++++++++++++++++++++++++++++++++++++++++
 hw/virtio-serial.h     |  230 ++++++++++++
 hw/virtio.h            |    2 +-
 qemu-options.hx        |    4 +
 sysemu.h               |    6 -
 vl.c                   |   18 +-
 15 files changed, 1317 insertions(+), 166 deletions(-)
 delete mode 100644 hw/virtio-console.h
 create mode 100644 hw/virtio-serial-bus.c
 create mode 100644 hw/virtio-serial.h
Makefile.target +1 -1
index 7c1f30c..74bb548 100644
@@ -156,7 +156,7 @@ ifdef CONFIG_SOFTMMU
 obj-y = vl.o async.o monitor.o pci.o pci_host.o pcie_host.o machine.o gdbstub.o
 # virtio has to be here due to weird dependency between PCI and virtio-net.
 # need to fix this properly
-obj-y += virtio-blk.o virtio-balloon.o virtio-net.o virtio-console.o virtio-pci.o
+obj-y += virtio-blk.o virtio-balloon.o virtio-net.o virtio-serial-bus.o virtio-console.o virtio-pci.o
 obj-$(CONFIG_KVM) += kvm.o kvm-all.o
 obj-$(CONFIG_ISA_MMIO) += isa_mmio.o
 LIBS+=-lz
hw/pc.c +0 -0
index db7d58e..5e742bf 100644
@@ -1242,15 +1242,6 @@ static void pc_init1(ram_addr_t ram_size,
         }
     }
 

hw/pc.c static void pc_init1(ram_addr_t ram_size, · line 1245

Quoted 10 lines
hw/pc.c +0 -9
-    /* Add virtio console devices */
-    if (pci_enabled) {
-        for(i = 0; i < MAX_VIRTIO_CONSOLES; i++) {
-            if (virtcon_hds[i]) {
-                pci_create_simple(pci_bus, -1, "virtio-console-pci");
-            }
-        }
-    }
-
 

We have something pretty similar in s390-virtio.c. I suppose that needs to be changed too?

Quoted 73 lines
hw/pc.c +0 -0
     rom_load_fw(fw_cfg);
 }
hw/ppc440_bamboo.c +0 -7
index a488240..1ab9872 100644
@@ -108,13 +108,6 @@ static void bamboo_init(ram_addr_t ram_size,
     env = ppc440ep_init(&ram_size, &pcibus, pci_irq_nrs, 1, cpu_model);
 
     if (pcibus) {
-        /* Add virtio console devices */
-        for(i = 0; i < MAX_VIRTIO_CONSOLES; i++) {
-            if (virtcon_hds[i]) {
-                pci_create_simple(pcibus, -1, "virtio-console-pci");
-            }
-        }
-
         /* Register network interfaces. */
         for (i = 0; i < nb_nics; i++) {
             /* There are no PCI NICs on the Bamboo board, but there are
hw/qdev.c +2 -6
index b6bd4ae..38c6e15 100644
@@ -321,13 +321,9 @@ void qdev_machine_creation_done(void)
 CharDriverState *qdev_init_chardev(DeviceState *dev)
 {
     static int next_serial;
-    static int next_virtconsole;
+
     /* FIXME: This is a nasty hack that needs to go away.  */
-    if (strncmp(dev->info->name, "virtio", 6) == 0) {
-        return virtcon_hds[next_virtconsole++];
-    } else {
-        return serial_hds[next_serial++];
-    }
+    return serial_hds[next_serial++];
 }
 
 BusState *qdev_get_parent_bus(DeviceState *dev)
hw/s390-virtio-bus.c +3 -3
index dc154ed..79ba9fc 100644
@@ -26,7 +26,7 @@
 #include "loader.h"
 #include "elf.h"
 #include "hw/virtio.h"
-#include "hw/virtio-console.h"
+#include "hw/virtio-serial.h"
 #include "hw/sysbus.h"
 #include "kvm.h"
 
@@ -130,7 +130,7 @@ static int s390_virtio_blk_init(VirtIOS390Device *dev)
     return s390_virtio_device_init(dev, vdev);
 }
 
-static int s390_virtio_console_init(VirtIOS390Device *dev)
+static int s390_virtio_serial_init(VirtIOS390Device *dev)
 {
     VirtIOS390Bus *bus;
     VirtIODevice *vdev;
@@ -138,7 +138,7 @@ static int s390_virtio_console_init(VirtIOS390Device *dev)
 
     bus = DO_UPCAST(VirtIOS390Bus, bus, dev->qdev.parent_bus);
 
-    vdev = virtio_console_init((DeviceState *)dev);
+    vdev = virtio_serial_init((DeviceState *)dev, dev->max_virtserial_ports);
     if (!vdev) {
         return -1;
     }

hw/s390-virtio-bus.c static VirtIOS390DeviceInfo s390_virtio_blk = { · line 342

Quoted 10 lines
hw/s390-virtio-bus.c +3 -3
@@ -336,11 +336,13 @@ static VirtIOS390DeviceInfo s390_virtio_blk = {
     },
 };
 
-static VirtIOS390DeviceInfo s390_virtio_console = {
-    .init = s390_virtio_console_init,
-    .qdev.name = "virtio-console-s390",
+static VirtIOS390DeviceInfo s390_virtio_serial = {
+    .init = s390_virtio_serial_init,
+    .qdev.name = "virtio-serial-s390",
 

Are you sure you changed all users of the old name too?

Quoted 34 lines
hw/s390-virtio-bus.c +2 -0
     .qdev.size = sizeof(VirtIOS390Device),
     .qdev.props = (Property[]) {
+        DEFINE_PROP_UINT32("max_ports", VirtIOS390Device, max_virtserial_ports,
+                           15),
         DEFINE_PROP_END_OF_LIST(),
     },

};

hw/s390-virtio-bus.c +1 -1
@@ -364,7 +366,7 @@ static void s390_virtio_bus_register_withprop(VirtIOS390DeviceInfo *info)
 
 static void s390_virtio_register(void)
 {
-    s390_virtio_bus_register_withprop(&s390_virtio_console);
+    s390_virtio_bus_register_withprop(&s390_virtio_serial);
     s390_virtio_bus_register_withprop(&s390_virtio_blk);
     s390_virtio_bus_register_withprop(&s390_virtio_net);
 }
hw/s390-virtio-bus.h +1 -0
index ef36714..42e56ce 100644
@@ -40,6 +40,7 @@ typedef struct VirtIOS390Device {
     VirtIODevice *vdev;
     DriveInfo *dinfo;
     NICConf nic;
+    uint32_t max_virtserial_ports;
 } VirtIOS390Device;
 
 typedef struct VirtIOS390Bus {
hw/virtio-console.c +0 -0
index 57f8f89..b2e4eb1 100644
@@ -1,143 +1,121 @@
 /*

hw/virtio-console.c line 8

Quoted 10 lines
hw/virtio-console.c +3 -3
- * Virtio Console Device
+ * Virtio Console and Generic Port Devices
  *
- * Copyright IBM, Corp. 2008
+ * Copyright Red Hat, Inc. 2009
  *
  * Authors:
- *  Christian Ehrhardt <[email protected]>
+ *  Amit Shah <[email protected]>
 

Please don't remove copyrights.

hw/virtio-console.c static int virtcon_parse(const char *devname) · line 4832

Quoted 8 lines
hw/virtio-console.c +3 -0
@@ -4823,6 +4826,13 @@ static int virtcon_parse(const char *devname)
         fprintf(stderr, "qemu: too many virtio consoles\n");
         exit(1);
     }
+
+    opts = qemu_opts_create(&qemu_device_opts, NULL, 0);
+    qemu_opt_set(opts, "driver", "virtio-serial-pci");
 

As you stated in your comment, this breaks. Maybe something as simple as

#ifdef TARGET_S390X
qemu_opt_set(opts, "driver", "virtio-serial-pci"); #else
qemu_opt_set(opts, "driver", "virtio-serial-s390"); #endif

is enough here?

Alex

author
#7 lore raw

[Qemu-devel] Re: [PATCH 2/3] virtio-console: Add a virtio-serial bus, support for multiple devices and ports

Quoted 12 lines · Alexander Graf

hw/pc.c static void pc_init1(ram_addr_t ram_size, · line 1253

Quoted 11 lines
hw/pc.c +0 -9
-    /* Add virtio console devices */
-    if (pci_enabled) {
-        for(i = 0; i < MAX_VIRTIO_CONSOLES; i++) {
-            if (virtcon_hds[i]) {
-                pci_create_simple(pci_bus, -1, "virtio-console-pci");
-            }
-        }
-    }
-
Quoted 2 lines

We have something pretty similar in s390-virtio.c. I suppose that needs to be changed too?

Yes, it'll have to be changed as well then; done in my tree.

Quoted 9 lines

hw/s390-virtio-bus.c static VirtIOS390DeviceInfo s390_virtio_blk = { · line 341

Quoted 7 lines
hw/s390-virtio-bus.c +3 -3
-static VirtIOS390DeviceInfo s390_virtio_console = {
-    .init = s390_virtio_console_init,
-    .qdev.name = "virtio-console-s390",
+static VirtIOS390DeviceInfo s390_virtio_serial = {
+    .init = s390_virtio_serial_init,
+    .qdev.name = "virtio-serial-s390",

Are you sure you changed all users of the old name too?

There's only virtio-serial-pci and virtio-serial-s390. Is there something I missed?

The new changes in vl.c, on the other hand, I've not yet fully studied so there might be something missing there.

Quoted 8 lines
Quoted 8 lines
hw/virtio-console.c +1 -2
@@ -1,143 +1,121 @@
 /*
- * Virtio Console Device
+ * Virtio Console and Generic Port Devices
  *
- * Copyright IBM, Corp. 2008
Quoted 8 lines

hw/virtio-console.c line 12

Quoted 6 lines
hw/virtio-console.c +2 -1
+ * Copyright Red Hat, Inc. 2009
  *
  * Authors:
- *  Christian Ehrhardt <[email protected]>
+ *  Amit Shah <[email protected]>
 

Please don't remove copyrights.

It seems that way due to file name changes. This is actually a new file that has nothing in common with the old one. Whatever is left of the old content is now in virtio-serial-bus.c.

Quoted 11 lines

hw/virtio-console.c static int virtcon_parse(const char *devname) · line 4832

Quoted 8 lines
hw/virtio-console.c +3 -0
@@ -4823,6 +4826,13 @@ static int virtcon_parse(const char *devname)
         fprintf(stderr, "qemu: too many virtio consoles\n");
         exit(1);
     }
+
+    opts = qemu_opts_create(&qemu_device_opts, NULL, 0);
+    qemu_opt_set(opts, "driver", "virtio-serial-pci");
 

As you stated in your comment, this breaks. Maybe something as simple as

Quoted 7 lines

#ifdef TARGET_S390X
qemu_opt_set(opts, "driver", "virtio-serial-pci"); #else
qemu_opt_set(opts, "driver", "virtio-serial-s390"); #endif

is enough here?

But it's ugly; Markus said we could do something better but I didn't fully understand it. On the lines of creating default devices or setting virtio-console's preferred bus type.

Thanks for looking at this,

Amit

#8 lore raw

Re: [Qemu-devel] [PATCH 2/3] virtio-console: Add a virtio-serial bus, support for multiple devices and ports

In reply to Amit Shah
Quoted 18 lines · Amit Shah

This patch migrates virtio-console to the qdev infrastructure and creates a new virtio-serial bus on which multiple ports are exposed as devices. The bulk of the code now resides in a new file with virtio-console.c being just a simple qdev device.

This interface enables spawning of multiple virtio consoles as well as generic serial ports.

The older -virtconsole argument still works, but when using the new functionality, it is recommended to use

-device virtio-serial-pci -device virtconsole,...

The virtconsole device type accepts a chardev as an argument and a 'name' argument to identify the corresponding consoles on the host as well as the guest. The name, if given, is exposed via the 'name' sysfs attribute in the guest.

Quoted 5 lines

Care has been taken to ensure compatibility with kernels that do not support multiple ports as well as accepting incoming migrations from older qemu versions.

This is really difficult to review. If you're introducing a completely new file, why don't you just call it virtio-serial.c and delete virtio-console.c It will save quite a bit of reviewing head ache.

Regards,

Anthony Liguori

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#12 lore raw

Re: [Qemu-devel] [PATCH 2/3] virtio-console: Add a virtio-serial bus, support for multiple devices and ports

Hi,

Quoted 18 lines
Quoted 18 lines
Quoted 17 lines
Quoted 4 lines
hw/qdev.c +0 -0
@@ -321,13 +321,9 @@ void qdev_machine_creation_done(void)
  CharDriverState *qdev_init_chardev(DeviceState *dev)
  {
      static int next_serial;

hw/qdev.c void qdev_machine_creation_done(void) · line 327

Quoted 10 lines
hw/qdev.c +2 -6
-    static int next_virtconsole;
+
      /* FIXME: This is a nasty hack that needs to go away.  */
-    if (strncmp(dev->info->name, "virtio", 6) == 0) {
-        return virtcon_hds[next_virtconsole++];
-    } else {
-        return serial_hds[next_serial++];
-    }
+    return serial_hds[next_serial++];
  }

I believe the FIXME is about the nasty special case for "virtio". Since you fix that, better remove the FIXME.

Quoted 4 lines
Quoted 2 lines

I did that in a previous submission and Gerd asked me to keep it. Even the serial init can be changed, I guess.

Okay, Gerd's the authority on this.

Yes, serial drivers should use a chardev property instead of qdev_init_chardev(). You can try to zap this function altogether, but I think there are still serial drivers using this so this would break the (full, all archs) build.

cheers,
Gerd

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#17 lore raw

Re: [Qemu-devel] [PATCH 2/3] virtio-console: Add a virtio-serial bus, support for multiple devices and ports

Quoted 3 lines · Markus Armbruster

We could declare that -virtioconsole always creates a bus a feature, but I can do that in good conscience only if the console created along with it always gets attached to it, even when other suitable buses exist.

I'd just discourage mixing -virtioconsole and -device virtio-serial-$bus

The whole point of -virtioconsole is backward compatibility for management apps / start scripts and the like and it should create a device which can be used by the guest like the qemu 0.11 virtioconsole.

If you are using device virtio-serial-$bus you are obviously not needing the backward compatibility stuff ;)

cheers,
Gerd