From patchwork Thu Oct 27 15:10:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 79741 Delivered-To: patch@linaro.org Received: by 10.80.142.83 with SMTP id 19csp722368edx; Thu, 27 Oct 2016 08:56:41 -0700 (PDT) X-Received: by 10.31.106.194 with SMTP id f185mr7012255vkc.118.1477583800307; Thu, 27 Oct 2016 08:56:40 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id q10si3617172uab.126.2016.10.27.08.56.40 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 27 Oct 2016 08:56:40 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42456 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bzn2l-00082a-Hs for patch@linaro.org; Thu, 27 Oct 2016 11:56:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45710) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bzmTX-0003yV-3s for qemu-devel@nongnu.org; Thu, 27 Oct 2016 11:20:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bzmTT-0004f3-3b for qemu-devel@nongnu.org; Thu, 27 Oct 2016 11:20:15 -0400 Received: from mail-wm0-x231.google.com ([2a00:1450:400c:c09::231]:37014) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1bzmTS-0004e0-SX for qemu-devel@nongnu.org; Thu, 27 Oct 2016 11:20:11 -0400 Received: by mail-wm0-x231.google.com with SMTP id 140so29778758wmv.0 for ; Thu, 27 Oct 2016 08:20:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hNhqvQIuVtoesY6NisQ27tk39k02+ps6YMmZEMF6YgI=; b=A8QcE14QeKYvJ7+lfltkXTlu060EFXHGx19D/p50aMlZiSMzhbnTxn0vVjX26RaeuF nRBp/3L6WwV1rj/rVV4L21fPrd6xh8O5QP4Q1M/hS1fJHDF8u3l/59uR0j0bvN7cVzk7 +vUYyhncsNqIeH7sRYlJM9jw5gsw5V97A0aG0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hNhqvQIuVtoesY6NisQ27tk39k02+ps6YMmZEMF6YgI=; b=D0GkdIErxafy1Z1JGo3YSjbWO+EvEzTSz1sO3FzMpZDW1fxRBRxDM/hfUcA8tnZqLb xt8bbL22cctvAuSJrXGyBRmEnSRjB9bq8bpvWW6gKyrE6z4klb5Iw55CkjXw5sNQSWEd sEzPE+Ci+INpJtcqz2nW09j8Eb2KNaQXN1MDNnwQBZJQsdg+1V/SDg5GBbWImcoJh6b/ 53U7e/9JzWS4ecmXug5iX9eIutBXi1Ypac5jnIAVub0AMILD5U+3KR6Uu0/wpmEyjcMm IV8306v9kR3oPooS+Y7o4yMDtPpWqSLowbB27qhJ/HABJCLp+mRlIWIO37qG32NYANDi 9fYQ== X-Gm-Message-State: ABUngvfWSwUzzXxFOWEptZPeHFLXNoTpLSmAYNjsARYfAV55kqgAqPVKe+vMNnmlIcCbFBYW X-Received: by 10.28.128.143 with SMTP id b137mr9033710wmd.95.1477581598912; Thu, 27 Oct 2016 08:19:58 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id 130sm3834441wmf.0.2016.10.27.08.19.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Oct 2016 08:19:56 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id A55853E03F5; Thu, 27 Oct 2016 16:11:00 +0100 (BST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: pbonzini@redhat.com Date: Thu, 27 Oct 2016 16:10:17 +0100 Message-Id: <20161027151030.20863-21-alex.bennee@linaro.org> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20161027151030.20863-1-alex.bennee@linaro.org> References: <20161027151030.20863-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::231 Subject: [Qemu-devel] [PATCH v5 20/33] tcg: enable tb_lock() for SoftMMU 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: mttcg@listserver.greensocs.com, peter.maydell@linaro.org, claudio.fontana@huawei.com, nikunj@linux.vnet.ibm.com, Peter Crosthwaite , jan.kiszka@siemens.com, mark.burton@greensocs.com, a.rigo@virtualopensystems.com, qemu-devel@nongnu.org, cota@braap.org, serge.fdrv@gmail.com, bobby.prani@gmail.com, rth@twiddle.net, =?UTF-8?q?Alex=20Benn=C3=A9e?= , fred.konrad@greensocs.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" tb_lock() has long been used for linux-user mode to protect code generation. By enabling it now we prepare for MTTCG and ensure all code generation is serialised by this lock. The other major structure that needs protecting is the l1_map and its PageDesc structures. For the SoftMMU case we also use tb_lock() to protect these structures instead of linux-user mmap_lock() which as the name suggests serialises updates to the structure as a result of guest mmap operations. Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson --- v4 - split from main tcg: enable thread-per-vCPU patch --- translate-all.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) -- 2.10.1 diff --git a/translate-all.c b/translate-all.c index 2dd240a..79b763d 100644 --- a/translate-all.c +++ b/translate-all.c @@ -82,7 +82,11 @@ #endif #ifdef CONFIG_SOFTMMU -#define assert_memory_lock() do { /* nothing */ } while (0) +#define assert_memory_lock() do { \ + if (DEBUG_MEM_LOCKS) { \ + g_assert(have_tb_lock); \ + } \ + } while (0) #else #define assert_memory_lock() do { \ if (DEBUG_MEM_LOCKS) { \ @@ -147,36 +151,28 @@ TCGContext tcg_ctx; bool parallel_cpus; /* translation block context */ -#ifdef CONFIG_USER_ONLY __thread int have_tb_lock; -#endif void tb_lock(void) { -#ifdef CONFIG_USER_ONLY assert(!have_tb_lock); qemu_mutex_lock(&tcg_ctx.tb_ctx.tb_lock); have_tb_lock++; -#endif } void tb_unlock(void) { -#ifdef CONFIG_USER_ONLY assert(have_tb_lock); have_tb_lock--; qemu_mutex_unlock(&tcg_ctx.tb_ctx.tb_lock); -#endif } void tb_lock_reset(void) { -#ifdef CONFIG_USER_ONLY if (have_tb_lock) { qemu_mutex_unlock(&tcg_ctx.tb_ctx.tb_lock); have_tb_lock = 0; } -#endif } #ifdef DEBUG_LOCKING @@ -185,15 +181,11 @@ void tb_lock_reset(void) #define DEBUG_TB_LOCKS 0 #endif -#ifdef CONFIG_SOFTMMU -#define assert_tb_lock() do { /* nothing */ } while (0) -#else #define assert_tb_lock() do { \ if (DEBUG_TB_LOCKS) { \ g_assert(have_tb_lock); \ } \ } while (0) -#endif static TranslationBlock *tb_find_pc(uintptr_t tc_ptr);