diff mbox

[v2,for-2.1,1/1] virtio-serial-bus: keep port 0 reserved for virtconsole even on unplug

Message ID 339156532cdc68672d36d0aa0b1b85cf596b2135.1405417943.git.amit.shah@redhat.com
State New
Headers show

Commit Message

Amit Shah July 15, 2014, 9:52 a.m. UTC
We keep port 0 reserved for compat with older guests, where only
virtio-console was expected.  Even if a system is started without a
virtio-console port, port #0 is kept aside.  However, after a
virtconsole port is unplugged, port id 0 became available, and the next
hotplug of a virtserialport caused failure due to it not being a console
port.

Steps to reproduce:

$ ./x86_64-softmmu/qemu-system-x86_64 -m 512 -cpu host -enable-kvm -device virtio-serial-pci -monitor stdio  -vnc :1
QEMU 2.0.91 monitor - type 'help' for more information
(qemu) device_add virtconsole,id=p1
(qemu) device_del p1
(qemu) device_add virtserialport,id=p1
Port number 0 on virtio-serial devices reserved for virtconsole devices for backward compatibility.
Device 'virtserialport' could not be initialized
(qemu) quit

Reported-by: dengmin <mdeng@redhat.com>
Signed-off-by: Amit Shah <amit.shah@redhat.com>

---
v2:
 - move calculation of 'i' inside if stmt too (Paolo)
 - re-word comment
---
 hw/char/virtio-serial-bus.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

Comments

Paolo Bonzini July 15, 2014, 9:55 a.m. UTC | #1
Il 15/07/2014 11:52, Amit Shah ha scritto:
> We keep port 0 reserved for compat with older guests, where only
> virtio-console was expected.  Even if a system is started without a
> virtio-console port, port #0 is kept aside.  However, after a
> virtconsole port is unplugged, port id 0 became available, and the next
> hotplug of a virtserialport caused failure due to it not being a console
> port.
>
> Steps to reproduce:
>
> $ ./x86_64-softmmu/qemu-system-x86_64 -m 512 -cpu host -enable-kvm -device virtio-serial-pci -monitor stdio  -vnc :1
> QEMU 2.0.91 monitor - type 'help' for more information
> (qemu) device_add virtconsole,id=p1
> (qemu) device_del p1
> (qemu) device_add virtserialport,id=p1
> Port number 0 on virtio-serial devices reserved for virtconsole devices for backward compatibility.
> Device 'virtserialport' could not be initialized
> (qemu) quit
>
> Reported-by: dengmin <mdeng@redhat.com>
> Signed-off-by: Amit Shah <amit.shah@redhat.com>
>
> ---
> v2:
>  - move calculation of 'i' inside if stmt too (Paolo)
>  - re-word comment
> ---
>  hw/char/virtio-serial-bus.c | 14 +++++++++++---
>  1 file changed, 11 insertions(+), 3 deletions(-)
>
> diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c
> index 07bebc0..917e93e 100644
> --- a/hw/char/virtio-serial-bus.c
> +++ b/hw/char/virtio-serial-bus.c
> @@ -797,10 +797,18 @@ static void add_port(VirtIOSerial *vser, uint32_t port_id)
>  static void remove_port(VirtIOSerial *vser, uint32_t port_id)
>  {
>      VirtIOSerialPort *port;
> -    unsigned int i;
>
> -    i = port_id / 32;
> -    vser->ports_map[i] &= ~(1U << (port_id % 32));
> +    /*
> +     * Don't mark port 0 removed -- we explicitly reserve it for
> +     * backward compat with older guests, ensure a virtconsole device
> +     * unplug virtconsole retains the reservation.
> +     */
> +    if (port_id) {
> +        unsigned int i;
> +
> +        i = port_id / 32;
> +        vser->ports_map[i] &= ~(1U << (port_id % 32));
> +    }
>
>      port = find_port_by_id(vser, port_id);
>      /*
>

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Amit Shah July 15, 2014, 10 a.m. UTC | #2
On (Tue) 15 Jul 2014 [15:22:23], Amit Shah wrote:

> v2:
>  - move calculation of 'i' inside if stmt too (Paolo)
>  - re-word comment

> +    /*
> +     * Don't mark port 0 removed -- we explicitly reserve it for
> +     * backward compat with older guests, ensure a virtconsole device
> +     * unplug virtconsole retains the reservation.

oops, extra 'virtconsole'


		Amit
diff mbox

Patch

diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c
index 07bebc0..917e93e 100644
--- a/hw/char/virtio-serial-bus.c
+++ b/hw/char/virtio-serial-bus.c
@@ -797,10 +797,18 @@  static void add_port(VirtIOSerial *vser, uint32_t port_id)
 static void remove_port(VirtIOSerial *vser, uint32_t port_id)
 {
     VirtIOSerialPort *port;
-    unsigned int i;
 
-    i = port_id / 32;
-    vser->ports_map[i] &= ~(1U << (port_id % 32));
+    /*
+     * Don't mark port 0 removed -- we explicitly reserve it for
+     * backward compat with older guests, ensure a virtconsole device
+     * unplug virtconsole retains the reservation.
+     */
+    if (port_id) {
+        unsigned int i;
+
+        i = port_id / 32;
+        vser->ports_map[i] &= ~(1U << (port_id % 32));
+    }
 
     port = find_port_by_id(vser, port_id);
     /*