From patchwork Thu Oct 8 20:37:40 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 35530 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id F163EB7B7C for ; Fri, 9 Oct 2009 07:46:18 +1100 (EST) Received: from localhost ([127.0.0.1]:38691 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MvzsN-0001J4-8L for incoming@patchwork.ozlabs.org; Thu, 08 Oct 2009 16:46:15 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MvzmQ-0006II-VS for qemu-devel@nongnu.org; Thu, 08 Oct 2009 16:40:07 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MvzmM-0006DM-Qi for qemu-devel@nongnu.org; Thu, 08 Oct 2009 16:40:06 -0400 Received: from [199.232.76.173] (port=43729 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MvzmM-0006D4-DW for qemu-devel@nongnu.org; Thu, 08 Oct 2009 16:40:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:13799) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MvzmK-0002v4-BR for qemu-devel@nongnu.org; Thu, 08 Oct 2009 16:40:01 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n98Kdipi013820; Thu, 8 Oct 2009 16:39:44 -0400 Received: from redhat.com (vpn-10-19.str.redhat.com [10.32.10.19]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id n98Kdfsb002091; Thu, 8 Oct 2009 16:39:42 -0400 Date: Thu, 8 Oct 2009 22:37:40 +0200 From: "Michael S. Tsirkin" To: malc , qemu-devel@nongnu.org, anthony@codemonkey.ws Message-ID: <20091008203740.GA20727@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.19 (2009-01-05) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Subject: [Qemu-devel] [PATCH] qemu: work around for "posix-aio-compat" X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org With commit ee3993069ff55fa6f1c64daf1e09963e340db8e4, "posix-aio-compat: avoid signal race when spawning a thread" winxp installation on a raw format file fails during disk format, with a message "your disk may be damaged". This commit moved signal mask from aio thread to creating thread. It turns out if we keep the mask in aio thread as well, the problem disappears. It should not be needed, but since this is harmless, let's keep it around until someone inclined to debug pthread library internals can check this issue. While we are at it, convert sigprocmask to pthread_sigmask as per posix. Signed-off-by: Michael S. Tsirkin For the benefit of whoever tries to debug this any deeper here's documentation on how to reproduce the issue to be saved in git logs (need to tweak paths obviously): The test was done on FC11, 32 bit userspace, 64 bit kernel 2.6.31. ./configure --prefix=/scm/qemu-kvm-debug --target-list=x86_64-softmmu \ --enable-kvm make -j 8 && make install rm /scm/images/winxp-bisect.raw /scm/qemu-kvm-debug/bin/qemu-img create -f raw \ /scm/images/winxp-bisect.raw 2G /scm/qemu-kvm-debug/bin/qemu-system-x86_64 -enable-kvm -cdrom \ /home/mst/en_windows_xp_professional_with_service_pack_3_x86_cd_x14-80428.iso \ /scm/images/winxp-bisect.raw Select format to NTFS. --- OK, I'm out of time with this issue, let's apply a work-around until someone interested comes around? posix-aio-compat.c | 14 ++++++++++++-- diff --git a/posix-aio-compat.c b/posix-aio-compat.c index 400d898..4abbe3a 100644 --- a/posix-aio-compat.c +++ b/posix-aio-compat.c @@ -301,6 +301,16 @@ static size_t handle_aiocb_rw(struct qemu_paiocb *aiocb) static void *aio_thread(void *unused) { pid_t pid; + sigset_t set; + + /* block all signals */ + /* Should not be necessary as we should inherit mask + * from creating thread. However, without this, + * on FC11, using raw file, WinXP installation fails during disk format + * saying disk was damaged. pthread library bug? + * */ + if (sigfillset(&set)) die("sigfillset"); + if (pthread_sigmask(SIG_BLOCK, &set, NULL)) die("pthread_sigmask"); pid = getpid(); @@ -371,11 +381,11 @@ static void spawn_thread(void) /* block all signals */ if (sigfillset(&set)) die("sigfillset"); - if (sigprocmask(SIG_SETMASK, &set, &oldset)) die("sigprocmask"); + if (pthread_sigmask(SIG_SETMASK, &set, &oldset)) die("pthread_sigmask"); thread_create(&thread_id, &attr, aio_thread, NULL); - if (sigprocmask(SIG_SETMASK, &oldset, NULL)) die("sigprocmask restore"); + if (pthread_sigmask(SIG_SETMASK, &oldset, NULL)) die("pthread_sigmask restore"); } static void qemu_paio_submit(struct qemu_paiocb *aiocb)