From patchwork Thu Sep 3 19:24:26 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?QW7DrWJhbCBMaW3Ds24=?= X-Patchwork-Id: 514291 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 615FA140216 for ; Fri, 4 Sep 2015 09:30:21 +1000 (AEST) Received: from localhost ([::1]:52634 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZXdxT-0007L4-Ct for incoming@patchwork.ozlabs.org; Thu, 03 Sep 2015 19:30:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57476) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZXa7e-00057V-Os for qemu-devel@nongnu.org; Thu, 03 Sep 2015 15:24:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZXa7b-0006fj-MN for qemu-devel@nongnu.org; Thu, 03 Sep 2015 15:24:34 -0400 Received: from mga02.intel.com ([134.134.136.20]:14815) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZXa7b-0006fC-H2 for qemu-devel@nongnu.org; Thu, 03 Sep 2015 15:24:31 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP; 03 Sep 2015 12:24:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,463,1437462000"; d="scan'208";a="782161481" Received: from alimonb-mobl1.zpn.intel.com ([10.219.5.31]) by fmsmga001.fm.intel.com with ESMTP; 03 Sep 2015 12:24:17 -0700 From: =?UTF-8?q?An=C3=ADbal=20Lim=C3=B3n?= To: qemu-devel@nongnu.org Date: Thu, 3 Sep 2015 14:24:26 -0500 Message-Id: <1441308266-20801-1-git-send-email-anibal.limon@linux.intel.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.20 X-Mailman-Approved-At: Thu, 03 Sep 2015 19:29:47 -0400 Cc: richard.purdie@linuxfoundation.org, =?UTF-8?q?An=C3=ADbal=20Lim=C3=B3n?= Subject: [Qemu-devel] [PATCH] cpus.c: qemu_mutex_lock_iothread fix race condition at cpu thread init X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org When QEMU starts the RCU thread executes qemu_mutex_lock_thread causing error "qemu:qemu_cpu_kick_thread: No such process" and exits. This isn't occur frequently but in glibc the thread id can exist and this not guarantee that the thread is on active/running state. If is inserted a sleep(1) after newthread assignment [1] the issue appears. So not make assumption that thread exist if first_cpu->thread is set then change the validation of cpu to created that is set into cpu threads (kvm, tcg, dummy). [1] https://sourceware.org/git/?p=glibc.git;a=blob;f=nptl/pthread_create.c;h=d10f4ea8004e1d8f3a268b95cc0f8d93b8d89867;hb=HEAD#l621 Signed-off-by: Aníbal Limón --- cpus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpus.c b/cpus.c index 7e4786e..05e5400 100644 --- a/cpus.c +++ b/cpus.c @@ -1171,7 +1171,7 @@ void qemu_mutex_lock_iothread(void) * TCG code execution. */ if (!tcg_enabled() || qemu_in_vcpu_thread() || - !first_cpu || !first_cpu->thread) { + !first_cpu || !first_cpu->created) { qemu_mutex_lock(&qemu_global_mutex); atomic_dec(&iothread_requesting_mutex); } else {