Received: from eggs.gnu.org ([2001:4830:134:3::10]:45417) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X4z3u-0000pq-CM for qemu-devel@nongnu.org; Wed, 09 Jul 2014 17:06:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X4z3p-00021l-HR for qemu-devel@nongnu.org; Wed, 09 Jul 2014 17:05:58 -0400 Received: from indium.canonical.com ([91.189.90.7]:35560) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X4z3p-00021h-A7 for qemu-devel@nongnu.org; Wed, 09 Jul 2014 17:05:53 -0400 Received: from loganberry.canonical.com ([91.189.90.37]) by indium.canonical.com with esmtp (Exim 4.76 #1 (Debian)) id 1X4z3o-0006mi-QX for ; Wed, 09 Jul 2014 21:05:52 +0000 Received: from loganberry.canonical.com (localhost [127.0.0.1]) by loganberry.canonical.com (Postfix) with ESMTP id B80622E80BF for ; Wed, 9 Jul 2014 21:05:52 +0000 (UTC) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Date: Wed, 09 Jul 2014 20:57:09 -0000 From: Andreas Gustafsson Sender: bounces@canonical.com References: <20140628145046.26094.20783.malonedeb@wampee.canonical.com> Message-Id: <20140709205709.368.81378.malone@chaenomeles.canonical.com> Errors-To: bounces@canonical.com Subject: [Qemu-devel] [Bug 1335444] Re: qemu loses serial console data on EAGAIN Reply-To: Bug 1335444 <1335444@bugs.launchpad.net> List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Kirill - thank you for looking into the problem. I reran the test of "Meth= od 1" with your patch, and it is still failing, but the blocks of missing data seem to be smaller than before. Here is an extract from the output of the "Method 1" test without your patc= h. In this case, the test failed because360 consecutive lines of output were m= issing: <00001071> <00001072> <00001433> <00001434> With your patch, it still failed, but only a single character was missing: <00001073> 0001074> <00001075> -- = You received this bug notification because you are a member of qemu- devel-ml, which is subscribed to QEMU. https://bugs.launchpad.net/bugs/1335444 Title: qemu loses serial console data on EAGAIN Status in QEMU: New Bug description: When running a guest OS with a serial console under "qemu-system-i386 -nographic", parts of the serial console output are sometimes lost. This happens when a write() to standard output by qemu returns EAGAIN, as may be the case when the guest is generating console output faster than the tty (or pty/pipe/socket, etc.) connected to qemu's standard output accepts it. The bug affects all releases of qemu since 1.5, which was the first version to set stdout to O_NONBLOCK mode. Version 1.4.2 and earlier work correctly. To reproduce the bug, you will need a guest OS configured with a serial console, and a host with a slow tty. Two different methods of setting this up are outlined below. = Method 1 This fully automated test uses the "pexpect" Python module to run qemu under a pty, with an Aboriginal Linux guest. A "seq" command is sent to the guest to generate 100,000 lines of output containing sequential integers, and the output is checked for gaps. The script limits the tty output rate by occasionally sleeping for 1/10 of a second. Run the following commands in a Bourne shell: wget http://landley.net/aboriginal/downloads/binaries/system-image-i686.t= ar.bz2 bunzip2 test.py #!/usr/bin/python import sys import time import pexpect n =3D 100000 child =3D pexpect.spawn('./run-emulator.sh', logfile =3D sys.stderr) child.expect("/home #") child.send("seq -f '<%%08.0f>' 0 %d\r" % (n - 1)) for i in range(n): child.expect("<([0-9]+)>", timeout =3D 5) got =3D int(child.match.group(1)) if got !=3D i: print >>sys.stderr, "\nFAIL: expected %d, got %d" % (i, got) sys.exit(1) if i % 100 =3D=3D 0: time.sleep(0.1) child.send("exit") print >>sys.stderr, "\nPASS" sys.exit(0) END python test.py This will output PASS if the console output contains the 100,000 sequential integers as expected, or FAIL if parts of the output are missing due to the bug. = Method 2 This method does not require Python or pexpect. Instead, the qemu source is modified to simulate a simulate a slow tty by forcing an EAGAIN return from every other write(). If qemu were working correctly, this change would not cause any data loss, because the writes would be retried, but in actuality, they are not retried, and the end result is that every other character in the guest output will be missing. Apply the following patch to the qemu source (this is against 2.0.0): --- ../qemu-2.0.0.orig/qemu-char.c 2014-04-17 16:44:45.000000000 +03= 00 +++ ./qemu-char.c 2014-06-20 16:47:18.000000000 +0300 @@ -779,6 +779,17 @@ size_t offset =3D 0; GIOStatus status =3D G_IO_STATUS_NORMAL; + /* + * Simulate a tty with a limited output buffer by returning + * EAGAIN on every second call. + */ + static unsigned int toggle =3D 0; + toggle++; + if (toggle & 1) { + errno =3D EAGAIN; + return -1; + } + while (offset < len && status =3D=3D G_IO_STATUS_NORMAL) { gsize bytes_written =3D 0; Build and install qemu. Run any serial console guest. You could use the same Aboriginal Linux im= age as in Method 1, or for example the PLD RescueCD: wget http://rescuecd.pld-linux.org/download/2011-02-12/x86/RCDx86_11_02= .iso qemu-system-i386 -nographic -cdrom RCDx86_11_02.iso If this command is run with an unmodified qemu, a set of boot messages will appear, starting with: ISOLINUX 4.03 2010-10-22 Copyright (C) 1994-2010 H. Peter Anvin et al When qemu has been patched to simulate EAGAIN returns, every other character in the boot messages will be missing, so that the first line of output will instead read: SLNX40 001-2 oyih C 9421 .PtrAvne l To manage notifications about this bug go to: https://bugs.launchpad.net/qemu/+bug/1335444/+subscriptions