From patchwork Wed Nov 9 14:57:36 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: 81520 Delivered-To: patch@linaro.org Received: by 10.140.97.165 with SMTP id m34csp245347qge; Wed, 9 Nov 2016 07:10:21 -0800 (PST) X-Received: by 10.129.52.133 with SMTP id b127mr85247ywa.332.1478704221819; Wed, 09 Nov 2016 07:10:21 -0800 (PST) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id e123si5494ybc.165.2016.11.09.07.10.21 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 09 Nov 2016 07:10:21 -0800 (PST) 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]:40481 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c4UW5-000211-34 for patch@linaro.org; Wed, 09 Nov 2016 10:10:21 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41189) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c4UKJ-0000gC-M7 for qemu-devel@nongnu.org; Wed, 09 Nov 2016 09:58:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c4UKE-0002JC-Up for qemu-devel@nongnu.org; Wed, 09 Nov 2016 09:58:11 -0500 Received: from mail-wm0-x234.google.com ([2a00:1450:400c:c09::234]:37069) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1c4UKE-0002IY-O7 for qemu-devel@nongnu.org; Wed, 09 Nov 2016 09:58:06 -0500 Received: by mail-wm0-x234.google.com with SMTP id t79so305617040wmt.0 for ; Wed, 09 Nov 2016 06:58:06 -0800 (PST) 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=pm3BhGB1hSogW9jLxkjrm4U0WduXZmNIvToexOw7mAw=; b=I5g8MUOgYSBzGSJFqmZW1AjrdDElZlmPSKbshOS9U3FiryTFbDINNsOLYe82Vy2jDZ SRoW0CZBOD3bqCSt6kosVvEwDC35PyWRNa1xkJQlo/qYfvvcBhbWBxfqyQVdcKpwe2FM 0evUP5OikMkc0aykjaDUTkXoRrqbLTHRHPNf8= 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=pm3BhGB1hSogW9jLxkjrm4U0WduXZmNIvToexOw7mAw=; b=Rj2cvhj3Ng3lT0PyQsdo50jUJUV6bnrShf+otAEoz3j8HEPGEP479+JZ1pUolDVFtR KBMVK4sn8FtYdGK3ohsY1v8hRYEbhdCqWAhs4Uil4g6EA0geJr4ZzxZ8OHjhQ7fDmlT1 uR5bK1qH82qIzX56tSFxWyMDrrS8QJdFnfs6VjklzS6pWYfbdaXSi7b3sd13fVx9wrav fbkDLpTXQdBPlLMuQFne67QPn4nD0SjJ4fRgEKYaTiqoC5DJ+fF0l5JItgxZM+ak95zM DlgUW0Sb3gHyBh+7779y/Yfu6oifEAqZY8CDY+AaUnzRhwPH/0QLG+AeJVtm9HD5V0RW IYhQ== X-Gm-Message-State: ABUngvfCexSLeXoRDsNJ/GQKFZheu/LuiklBkJlddv8K0oT8JS32+zZg6W6t3JBfThewUTQS X-Received: by 10.194.82.163 with SMTP id j3mr29730wjy.56.1478703485500; Wed, 09 Nov 2016 06:58:05 -0800 (PST) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id l67sm16777851wmf.0.2016.11.09.06.57.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Nov 2016 06:58:02 -0800 (PST) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 5812A3E0407; Wed, 9 Nov 2016 14:57:57 +0000 (GMT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: pbonzini@redhat.com Date: Wed, 9 Nov 2016 14:57:36 +0000 Message-Id: <20161109145748.27282-8-alex.bennee@linaro.org> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20161109145748.27282-1-alex.bennee@linaro.org> References: <20161109145748.27282-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::234 Subject: [Qemu-devel] [PATCH v6 07/19] 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 2c8baf5..cf828aa 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) { \ @@ -146,9 +150,7 @@ TCGContext tcg_ctx; bool parallel_cpus; /* translation block context */ -#ifdef CONFIG_USER_ONLY __thread int have_tb_lock; -#endif static void page_table_config_init(void) { @@ -172,30 +174,24 @@ static void page_table_config_init(void) 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 @@ -204,15 +200,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);