From fecef4fdd15d54dc0e8cef8b635622f6e2570075 Mon Sep 17 00:00:00 2001 Message-Id: In-Reply-To: <1265c14a6676be3cbc003c219326a60813dc29d5.1343041017.git.minovotn@redhat.com> References: <1265c14a6676be3cbc003c219326a60813dc29d5.1343041017.git.minovotn@redhat.com> From: Amit Shah Date: Wed, 11 Jul 2012 06:45:09 +0200 Subject: [PATCH 3/9] virtio-console: Fix failure on unconnected pty RH-Author: Amit Shah Message-id: <776b96ae67f306ce4ac8820230e9a45e47089fe4.1341989107.git.amit.shah@redhat.com> Patchwork-id: 40266 O-Subject: [RHEL6.4 qemu-kvm PATCH 1/1] virtio-console: Fix failure on unconnected pty Bugzilla: 839156 RH-Acked-by: Gerd Hoffmann RH-Acked-by: Alon Levy RH-Acked-by: Markus Armbruster From: Christian Borntraeger when I tried qemu with -virtio-console pty the guest hangs and attaching on /dev/pts/ does not return anything if the attachment is too late. This results in pty_chr_write() returning 0, which causes the port to get throttled. This results in the guest getting frozen as the guest->host virtio_console writes don't return until the host releases the vq element back to the guest. For the virtio-serial use case we don't want to lose data but for the console case we better drop data instead of "killing" the guest console. If we get chardev->frontend notification and a better behaving virtio-console we can revert this fix. Signed-off-by: Christian Borntraeger Signed-off-by: Amit Shah (cherry picked from commit ed8e5a85a1741147ce06932b478a509ce3407061) Bugzilla: 839156 Hilighting a behaviour change: without the fix, if a guest writes to a console port, and if the host-side unix or tcp chardev isn't connected, the output will be buffered till the host is connected, or till the guest vq becomes full. After the fix is applied, the guest output will be discarded till the host chardev gets connected. The previous behaviour isn't important for console ports, as console output getting discarded is normal if no one is listening. The guest will get frozen only for 'pty' type of chardev associated with a virtio-console port before the fix. Signed-off-by: Amit Shah --- hw/virtio-serial-bus.c | 14 +++++++++++++- 1 files changed, 13 insertions(+), 1 deletions(-) Signed-off-by: Michal Novotny --- hw/virtio-serial-bus.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c index bf839d7..d598fb5 100644 --- a/hw/virtio-serial-bus.c +++ b/hw/virtio-serial-bus.c @@ -199,7 +199,19 @@ static void do_flush_queued_data(VirtIOSerialPort *port, VirtQueue *vq, abort(); } if (ret == -EAGAIN || (ret >= 0 && ret < buf_size)) { - virtio_serial_throttle_port(port, true); + /* + * this is a temporary check until chardevs can signal to + * frontends that they are writable again. This prevents + * the console from going into throttled mode (forever) + * if virtio-console is connected to a pty without a + * listener. Otherwise the guest spins forever. + * We can revert this if + * 1: chardevs can notify frondends + * 2: the guest driver does not spin in these cases + */ + if (!info->is_console) { + virtio_serial_throttle_port(port, true); + } port->iov_idx = i; if (ret > 0) { port->iov_offset += ret; -- 1.7.10.4