From patchwork Thu Sep 13 17:02:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: KONRAD Frederic X-Patchwork-Id: 10599833 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7F17214DB for ; Thu, 13 Sep 2018 17:04:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 683692B179 for ; Thu, 13 Sep 2018 17:04:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5957F2B2B7; Thu, 13 Sep 2018 17:04:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C11BB2B179 for ; Thu, 13 Sep 2018 17:04:17 +0000 (UTC) Received: from localhost ([::1]:43534 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g0V2P-0002S1-3x for patchwork-qemu-devel@patchwork.kernel.org; Thu, 13 Sep 2018 13:04:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36073) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g0V1D-0001nf-Ge for qemu-devel@nongnu.org; Thu, 13 Sep 2018 13:03:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g0V1A-000213-At for qemu-devel@nongnu.org; Thu, 13 Sep 2018 13:03:03 -0400 Received: from mel.act-europe.fr ([194.98.77.210]:60415 helo=smtp.eu.adacore.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g0V19-00020J-Ug for qemu-devel@nongnu.org; Thu, 13 Sep 2018 13:03:00 -0400 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id A2ED3822BB; Thu, 13 Sep 2018 19:02:58 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at eu.adacore.com Received: from smtp.eu.adacore.com ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id FY0XpMdTBlIx; Thu, 13 Sep 2018 19:02:58 +0200 (CEST) Received: from localhost.localdomain (unknown [IPv6:2a02:2ab8:224:100::100c]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.eu.adacore.com (Postfix) with ESMTPSA id 5B29A822B3; Thu, 13 Sep 2018 19:02:58 +0200 (CEST) From: KONRAD Frederic To: ashedel@microsoft.com Message-ID: <5aae1837-f6b9-a48b-7401-3aa623a084b2@adacore.com> Date: Thu, 13 Sep 2018 19:02:56 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 Content-Language: fr X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 194.98.77.210 Subject: [Qemu-devel] crashes with win2008 host X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , QEMU Developers , Andrew.Baumann@microsoft.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Hi Andrey, I've strange crashes since this commit: (yes its old) commit 12f8def0e02232d7c6416ad9b66640f973c531d1 Author: Andrey Shedel Date: Fri Mar 24 15:01:41 2017 -0700 win32: replace custom mutex and condition variable with native primitives Basically it just crashes.. (exception 0xc0000135) like this: (gdb) run Starting program: C:\home\konrad\temp\qemu-system-sparc --version [New Thread 5324.0xdf8] gdb: unknown target exception 0xc0000135 at 0x77636698 gdb: unknown target exception 0xc0000135 at 0x77636698 Program received signal ?, Unknown signal. 0x0000000077636698 in ntdll!RtlRaiseStatus () from C:\Windows\system32\ntdll.dll (gdb) bt #0 0x0000000077636698 in ntdll!RtlRaiseStatus () from C:\Windows\system32\ntdll.dll #1 0x00000000775dcbf7 in ntdll!LdrGetProcedureAddress () from C:\Windows\system32\ntdll.dll #2 0x00000000775a536e in ntdll!LdrInitializeThunk () from C:\Windows\system32\ntdll.dll #3 0x0000000000000000 in ?? () Backtrace stopped: previous frame inner to this frame (corrupt stack?) (gdb) Sorry the backtrace is not really helpful.. I can reproduce the same behavior with v3.0.0.. and only with the Windows 2008 server host.. If I partially revert the patch, eg: using CriticalSection instead of SRWL it seems to work.. But I don't understand why because SRWL should be supported on 2008 Server.. Here is the change I did (which is wrongly making qemu_mutex recursive for now): @@ -69,7 +69,7 @@ int qemu_mutex_trylock_impl(QemuMutex *mutex, const char *file, const int line) int owned; assert(mutex->initialized); - owned = TryAcquireSRWLockExclusive(&mutex->lock); + owned = TryEnterCriticalSection(&mutex->lock);there if (owned) { qemu_mutex_post_lock(mutex, file, line); return 0; @@ -81,7 +81,7 @@ void qemu_mutex_unlock_impl(QemuMutex *mutex, const char *file, const int line) { assert(mutex->initialized); qemu_mutex_pre_unlock(mutex, file, line); - ReleaseSRWLockExclusive(&mutex->lock); + LeaveCriticalSection(&mutex->lock); } void qemu_rec_mutex_init(QemuRecMutex *mutex) @@ -141,11 +141,12 @@ void qemu_cond_broadcast(QemuCond *cond) WakeAllConditionVariable(&cond->var); } -void qemu_cond_wait_impl(QemuCond *cond, QemuMutex *mutex, const char *file, const int line) +void qemu_cond_wait_impl(QemuCond *cond, QemuMutex *mutex, const char *file, + const int line) { assert(cond->initialized); qemu_mutex_pre_unlock(mutex, file, line); - SleepConditionVariableSRW(&cond->var, &mutex->lock, INFINITE, 0); + SleepConditionVariableCS(&cond->var, &mutex->lock, INFINITE); qemu_mutex_post_lock(mutex, file, line); } diff --git a/include/qemu/thread-win32.h b/include/qemu/thread-win32.h index d668d789b4..b335687604 100644 --- a/include/qemu/thread-win32.h +++ b/include/qemu/thread-win32.h @@ -4,7 +4,8 @@ #include struct QemuMutex { - SRWLOCK lock; + CRITICAL_SECTION lock; + LONG owner; #ifdef CONFIG_DEBUG_MUTEX const char *file; int line; diff --git a/util/qemu-thread-win32.c b/util/qemu-thread-win32.c index b303188a36..09ce4fd957 100644 --- a/util/qemu-thread-win32.c +++ b/util/qemu-thread-win32.c @@ -45,7 +45,7 @@ static void error_exit(int err, const char *msg) void qemu_mutex_init(QemuMutex *mutex) { - InitializeSRWLock(&mutex->lock); + InitializeCriticalSection(&mutex->lock); qemu_mutex_post_init(mutex); } @@ -53,14 +53,14 @@ void qemu_mutex_destroy(QemuMutex *mutex) { assert(mutex->initialized); mutex->initialized = false; - InitializeSRWLock(&mutex->lock); + DeleteCriticalSection(&mutex->lock); } void qemu_mutex_lock_impl(QemuMutex *mutex, const char *file, const int line) { assert(mutex->initialized); qemu_mutex_pre_lock(mutex, file, line); - AcquireSRWLockExclusive(&mutex->lock); + EnterCriticalSection(&mutex->lock); qemu_mutex_post_lock(mutex, file, line); }