From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=40591 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OTv4K-0001dZ-1Z for qemu-devel@nongnu.org; Wed, 30 Jun 2010 07:03:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OTv3O-0000Jz-WF for qemu-devel@nongnu.org; Wed, 30 Jun 2010 07:03:03 -0400 Received: from e23smtp04.au.ibm.com ([202.81.31.146]:39700) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OTv3O-0000JX-Bp for qemu-devel@nongnu.org; Wed, 30 Jun 2010 07:02:06 -0400 Received: from d23relay04.au.ibm.com (d23relay04.au.ibm.com [202.81.31.246]) by e23smtp04.au.ibm.com (8.14.4/8.13.1) with ESMTP id o5UAvlEg014057 for ; Wed, 30 Jun 2010 20:57:47 +1000 Received: from d23av04.au.ibm.com (d23av04.au.ibm.com [9.190.235.139]) by d23relay04.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o5UB22TN983250 for ; Wed, 30 Jun 2010 21:02:02 +1000 Received: from d23av04.au.ibm.com (loopback [127.0.0.1]) by d23av04.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id o5UB21Oo010663 for ; Wed, 30 Jun 2010 21:02:02 +1000 From: Sripathi Kodi Date: Wed, 30 Jun 2010 16:32:00 +0530 Message-ID: <20100630110200.18277.71637.stgit@localhost.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [PATCH] virtio-9p: Avoid SEGV when log file couldn't be opened List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Sripathi Kodi While running in debug mode if 9P server is unable to open the log file it results in a SEGV deep down in glibc: Program received signal SIGSEGV, Segmentation fault. 0x008fca8c in fwrite () from /lib/libc.so.6 (gdb) bt #0 0x008fca8c in fwrite () from /lib/libc.so.6 #1 0x081eb87e in pprint_pdu (pdu=0x89a52e1c) at /data/sripathi/code/qemu/new/qemu-next-upstream/hw/virtio-9p-debug.c:380 #2 0x0806dad8 in submit_pdu (s=0x897dc008, pdu=0x89a52e1c) at /data/sripathi/code/qemu/new/qemu-next-upstream/hw/virtio-9p.c:3092 #3 0x0806dc63 in handle_9p_output (vdev=0x897dc008, vq=0x86d8218) at /data/sripathi/code/qemu/new/qemu-next-upstream/hw/virtio-9p.c:3122 #4 0x081ac728 in virtio_queue_notify (vdev=0x897dc008, n=0) at /data/sripathi/code/qemu/new/qemu-next-upstream/hw/virtio.c:563 #5 0x08063876 in virtio_ioport_write (opaque=0x86d7b98, addr=16, val=0) at /data/sripathi/code/qemu/new/qemu-next-upstream/hw/virtio-pci.c:222 #6 0x08063e26 in virtio_pci_config_writew (opaque=0x86d7b98, addr=16, val=0) at /data/sripathi/code/qemu/new/qemu-next-upstream/hw/virtio-pci.c:357 #7 0x080c881a in ioport_write (index=1, address=49296, data=0) at ioport.c:80 #8 0x080c8d4c in cpu_outw (addr=49296, val=0) at ioport.c:204 #9 0x08073010 in kvm_handle_io (port=49296, data=0xab393000, direction=1, size=2, count=1) at /data/sripathi/code/qemu/new/qemu-next-upstream/kvm-all.c:735 ... ... This is ugly and misleading. The following patch adds a BUG_ON to catch this error. With this patch we get an abort message like the following, which makes it easier to analyze: f12-kvm login: qemu: /data/sripathi/code/qemu/new/qemu-next-upstream/hw/virtio-9p-debug.c:353: pprint_pdu: Assertion `!(!llogfile)' failed. Signed-off-by: Sripathi Kodi --- hw/virtio-9p-debug.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/hw/virtio-9p-debug.c b/hw/virtio-9p-debug.c index e4ab4bc..c1b0e6f 100644 --- a/hw/virtio-9p-debug.c +++ b/hw/virtio-9p-debug.c @@ -327,6 +327,8 @@ void pprint_pdu(V9fsPDU *pdu) llogfile = fopen("/tmp/pdu.log", "w"); } + BUG_ON(!llogfile); + switch (pdu->id) { case P9_TVERSION: fprintf(llogfile, "TVERSION: (");