From 52c3f43ff671fcf031caaf0c37dd9e736710cf15 Mon Sep 17 00:00:00 2001 Message-Id: <52c3f43ff671fcf031caaf0c37dd9e736710cf15.1335950093.git.minovotn@redhat.com> From: Alon Levy Date: Tue, 1 May 2012 06:43:21 +0200 Subject: [PATCH 1/2] virtio-serial-bus: fix guest_connected init before driver init RH-Author: Alon Levy Message-id: <1335854602-16938-2-git-send-email-alevy@redhat.com> Patchwork-id: 39531 O-Subject: [PATCH 1/2] virtio-serial-bus: fix guest_connected init before driver init Bugzilla: 787974 RH-Acked-by: Hans de Goede RH-Acked-by: Michael S. Tsirkin RH-Acked-by: Amit Shah RHBZ: 787974 guest_connected should be false before guest driver initialization, and true after, both for multiport aware and non multiport aware drivers. Don't set it before the guest_features are available; instead use set_status which is called by io to VIRTIO_PCI_STATUS with VIRTIO_CONFIG_S_DRIVER_OK by even older non multiport drivers. [Amit: Add comment, tweak summary, only set guest_connected and not reset it as a side-effect.] Signed-off-by: Alon Levy Acked-by: Michael S. Tsirkin Signed-off-by: Amit Shah (cherry picked from commit 62a9fbf7fd022103c6b271abd7b7834b84ba7071) --- hw/virtio-serial-bus.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) Signed-off-by: Michal Novotny --- hw/virtio-serial-bus.c | 29 +++++++++++++++++++++-------- 1 files changed, 21 insertions(+), 8 deletions(-) diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c index 995a2d1..6a09401 100644 --- a/hw/virtio-serial-bus.c +++ b/hw/virtio-serial-bus.c @@ -553,6 +553,26 @@ static void set_config(VirtIODevice *vdev, const uint8_t *config_data) memcpy(&config, config_data, sizeof(config)); } +static void set_status(VirtIODevice *vdev, uint8_t status) +{ + VirtIOSerial *vser; + VirtIOSerialPort *port; + + vser = DO_UPCAST(VirtIOSerial, vdev, vdev); + port = find_port_by_id(vser, 0); + + if (port && !use_multiport(port->vser) + && (status & VIRTIO_CONFIG_S_DRIVER_OK)) { + /* + * Non-multiport guests won't be able to tell us guest + * open/close status. Such guests can only have a port at id + * 0, so set guest_connected for such ports as soon as guest + * is up. + */ + port->guest_connected = true; + } +} + static void virtio_serial_save(QEMUFile *f, void *opaque) { VirtIOSerial *s = opaque; @@ -841,14 +861,6 @@ static int virtser_port_qdev_init(DeviceState *qdev, DeviceInfo *base) return ret; } - if (!use_multiport(port->vser)) { - /* - * Allow writes to guest in this case; we have no way of - * knowing if a guest port is connected. - */ - port->guest_connected = true; - } - port->elem.out_num = 0; QTAILQ_INSERT_TAIL(&port->vser->ports, port, next); @@ -959,6 +971,7 @@ VirtIODevice *virtio_serial_init(DeviceState *dev, virtio_serial_conf *conf) vser->vdev.get_features = get_features; vser->vdev.get_config = get_config; vser->vdev.set_config = set_config; + vser->vdev.set_status = set_status; vser->qdev = dev; -- 1.7.7.6