From patchwork Thu Oct 27 15:10:00 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: 79720 Delivered-To: patch@linaro.org Received: by 10.80.142.83 with SMTP id 19csp707707edx; Thu, 27 Oct 2016 08:28:22 -0700 (PDT) X-Received: by 10.31.82.129 with SMTP id g123mr6676210vkb.55.1477582102776; Thu, 27 Oct 2016 08:28:22 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id f4si3545033uab.54.2016.10.27.08.28.22 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 27 Oct 2016 08:28:22 -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]:42288 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bzmbO-0001Rv-3p for patch@linaro.org; Thu, 27 Oct 2016 11:28:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42480) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bzmKi-0004ak-Gu for qemu-devel@nongnu.org; Thu, 27 Oct 2016 11:11:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bzmKe-0007by-EY for qemu-devel@nongnu.org; Thu, 27 Oct 2016 11:11:08 -0400 Received: from mail-wm0-x234.google.com ([2a00:1450:400c:c09::234]:35941) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1bzmKe-0007bF-6q for qemu-devel@nongnu.org; Thu, 27 Oct 2016 11:11:04 -0400 Received: by mail-wm0-x234.google.com with SMTP id b80so40024417wme.1 for ; Thu, 27 Oct 2016 08:11:04 -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=cLTzR3N5q+36aR8r5/DRqXZPa5M9mBpBYIxhXG36QJY=; b=juhGHml2XumTS7ket1fmp/h2kdpmvdAj4GFEwFvgswapkhD8EI3gsffzfeu8yOO6Tm S3dL1djjX4c1hz40XogqO9WHKJ4Ryd5AF5LhxqWDOUq1Ovu4b2g85L8BXR0z1FpyZVGS HoOQF3qniKgztpBZa92ARcpbU84+P1DyQL0v0= 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=cLTzR3N5q+36aR8r5/DRqXZPa5M9mBpBYIxhXG36QJY=; b=Ef6s7IFiRT5PqugBfRPHlOJLl9O+kfGX30cjHHu5qSw/bieTDlMzux+lui40wKW7WB XL+0crw65/W9rcQQ/bgeY7B5PLSXp4DGQt+o3rwNq69WJ9mUNj0ObJDBlyEzAZ0xn/gc 4QT23cNgtEL1s0DJpeh2LKIh94xgdV7KU3PKxNgqQYK1y7T5WCpHUu3mcAAaRUI5gZ/y YPHxqxDnmo+YcrqRKSENb7SQdqiXktfXPEs1qVGo923qNLUcQvhe3rg/9u5xliaohGSd 5ZSMp4IYRVrUOO1k6Q6BnT/05Af5DsfIvr2rngkhcAXbShCCrjAvjt+X83hG3zPmR6DD LmEA== X-Gm-Message-State: ABUngvdBKCvATbIcASVUm7N3q96+f+WY6Dfsu/LEcZraGAFM/u55NivYB26NDNBc5NDFgagq X-Received: by 10.28.23.199 with SMTP id 190mr7980000wmx.107.1477581062676; Thu, 27 Oct 2016 08:11:02 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id v3sm9024066wjm.4.2016.10.27.08.10.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Oct 2016 08:11:01 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 4F65E3E0297; Thu, 27 Oct 2016 16:10:59 +0100 (BST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: pbonzini@redhat.com Date: Thu, 27 Oct 2016 16:10:00 +0100 Message-Id: <20161027151030.20863-4-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::234 Subject: [Qemu-devel] [PATCH v5 03/33] translate-all: add DEBUG_LOCKING asserts 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, Riku Voipio , 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" This adds asserts to check the locking on the various translation engines structures. There are two sets of structures that are protected by locks. The first the l1map and PageDesc structures used to track which translation blocks are associated with which physical addresses. In user-mode this is covered by the mmap_lock. The second case are TB context related structures which are protected by tb_lock which is also user-mode only. Currently the asserts do nothing in SoftMMU mode but this will change for MTTCG. Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson --- bsd-user/mmap.c | 5 +++++ include/exec/exec-all.h | 1 + linux-user/mmap.c | 5 +++++ translate-all.c | 41 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+) -- 2.10.1 diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index 610f91b..ee59073 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -42,6 +42,11 @@ void mmap_unlock(void) } } +bool have_mmap_lock(void) +{ + return mmap_lock_count > 0 ? true : false; +} + /* Grab lock to make sure things are in a consistent state after fork(). */ void mmap_fork_start(void) { diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index 13633a2..84fecc8 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -370,6 +370,7 @@ void tlb_fill(CPUState *cpu, target_ulong addr, MMUAccessType access_type, #if defined(CONFIG_USER_ONLY) void mmap_lock(void); void mmap_unlock(void); +bool have_mmap_lock(void); static inline tb_page_addr_t get_page_addr_code(CPUArchState *env1, target_ulong addr) { diff --git a/linux-user/mmap.c b/linux-user/mmap.c index c4371d9..19aeec5 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -43,6 +43,11 @@ void mmap_unlock(void) } } +bool have_mmap_lock(void) +{ + return mmap_lock_count > 0 ? true : false; +} + /* Grab lock to make sure things are in a consistent state after fork(). */ void mmap_fork_start(void) { diff --git a/translate-all.c b/translate-all.c index 8907302..758f654 100644 --- a/translate-all.c +++ b/translate-all.c @@ -31,6 +31,7 @@ #include "tcg.h" #if defined(CONFIG_USER_ONLY) #include "qemu.h" +#include "exec/exec-all.h" #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) #include #if __FreeBSD_version >= 700104 @@ -58,6 +59,7 @@ /* #define DEBUG_TB_INVALIDATE */ /* #define DEBUG_TB_FLUSH */ +/* #define DEBUG_LOCKING */ /* make various TB consistency checks */ /* #define DEBUG_TB_CHECK */ @@ -66,6 +68,28 @@ #undef DEBUG_TB_CHECK #endif +/* Access to the various translations structures need to be serialised via locks + * for consistency. This is automatic for SoftMMU based system + * emulation due to its single threaded nature. In user-mode emulation + * access to the memory related structures are protected with the + * mmap_lock. + */ +#ifdef DEBUG_LOCKING +#define DEBUG_MEM_LOCKS 1 +#else +#define DEBUG_MEM_LOCKS 0 +#endif + +#ifdef CONFIG_SOFTMMU +#define assert_memory_lock() do { /* nothing */ } while (0) +#else +#define assert_memory_lock() do { \ + if (DEBUG_MEM_LOCKS) { \ + g_assert(have_mmap_lock()); \ + } \ + } while (0) +#endif + #define SMC_BITMAP_USE_THRESHOLD 10 typedef struct PageDesc { @@ -154,6 +178,23 @@ void tb_lock_reset(void) #endif } +#ifdef DEBUG_LOCKING +#define DEBUG_TB_LOCKS 1 +#else +#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); void cpu_gen_init(void)