From patchwork Tue Jul 15 09:52:23 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Shah X-Patchwork-Id: 369926 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id BDD5D140111 for ; Tue, 15 Jul 2014 19:53:28 +1000 (EST) Received: from localhost ([::1]:33777 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X6zQM-0001o2-Vo for incoming@patchwork.ozlabs.org; Tue, 15 Jul 2014 05:53:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45668) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X6zQ6-0001Wf-Go for qemu-devel@nongnu.org; Tue, 15 Jul 2014 05:53:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X6zQ5-0000CR-BH for qemu-devel@nongnu.org; Tue, 15 Jul 2014 05:53:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54341) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X6zQ5-0000BL-3s for qemu-devel@nongnu.org; Tue, 15 Jul 2014 05:53:09 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s6F9r6If027592 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 15 Jul 2014 05:53:07 -0400 Received: from localhost (ovpn-113-72.phx2.redhat.com [10.3.113.72]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s6F9r2sZ030968; Tue, 15 Jul 2014 05:53:03 -0400 From: Amit Shah To: qemu list Date: Tue, 15 Jul 2014 15:22:23 +0530 Message-Id: <339156532cdc68672d36d0aa0b1b85cf596b2135.1405417943.git.amit.shah@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Amit Shah , Paolo Bonzini , Amos Kong Subject: [Qemu-devel] [PATCH v2 for-2.1 1/1] virtio-serial-bus: keep port 0 reserved for virtconsole even on unplug X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 Signed-off-by: Amit Shah Reviewed-by: Paolo Bonzini --- 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); /*