Patchwork virtio-serial-bus: fix guest_connected pre-driver

login
register
mail settings
Submitter Alon Levy
Date April 23, 2012, 3:23 p.m.
Message ID <1335194590-15080-1-git-send-email-alevy@redhat.com>
Download mbox | patch
Permalink /patch/154470/
State New
Headers show

Comments

Alon Levy - April 23, 2012, 3:23 p.m.
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.

Signed-off-by: Alon Levy <alevy@redhat.com>
---
 hw/virtio-serial-bus.c |   21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)
Michael S. Tsirkin - April 23, 2012, 3:53 p.m.
On Mon, Apr 23, 2012 at 06:23:10PM +0300, Alon Levy wrote:
> 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.
> 
> Signed-off-by: Alon Levy <alevy@redhat.com>

Acked-by: Michael S. Tsirkin <mst@redhat.com>

> ---
>  hw/virtio-serial-bus.c |   21 +++++++++++++--------
>  1 file changed, 13 insertions(+), 8 deletions(-)
> 
> diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c
> index e22940e..8788da2 100644
> --- a/hw/virtio-serial-bus.c
> +++ b/hw/virtio-serial-bus.c
> @@ -528,6 +528,18 @@ 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)) {
> +        port->guest_connected = status & VIRTIO_CONFIG_S_DRIVER_OK;
> +    }
> +}
> +
>  static void virtio_serial_save(QEMUFile *f, void *opaque)
>  {
>      VirtIOSerial *s = opaque;
> @@ -798,14 +810,6 @@ static int virtser_port_qdev_init(DeviceState *qdev)
>          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);
> @@ -905,6 +909,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.10

Patch

diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c
index e22940e..8788da2 100644
--- a/hw/virtio-serial-bus.c
+++ b/hw/virtio-serial-bus.c
@@ -528,6 +528,18 @@  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)) {
+        port->guest_connected = status & VIRTIO_CONFIG_S_DRIVER_OK;
+    }
+}
+
 static void virtio_serial_save(QEMUFile *f, void *opaque)
 {
     VirtIOSerial *s = opaque;
@@ -798,14 +810,6 @@  static int virtser_port_qdev_init(DeviceState *qdev)
         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);
@@ -905,6 +909,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;