From patchwork Fri Jun 3 20:40:12 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: 69279 Delivered-To: patch@linaro.org Received: by 10.140.106.246 with SMTP id e109csp449091qgf; Fri, 3 Jun 2016 13:47:13 -0700 (PDT) X-Received: by 10.55.78.4 with SMTP id c4mr5327944qkb.71.1464986833343; Fri, 03 Jun 2016 13:47:13 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id v128si3491537qki.61.2016.06.03.13.47.13 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 03 Jun 2016 13:47:13 -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]:57652 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8vzs-0005Jh-SC for patch@linaro.org; Fri, 03 Jun 2016 16:47:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37331) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8vtT-0008Pl-A8 for qemu-devel@nongnu.org; Fri, 03 Jun 2016 16:40:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b8vtR-0000Pm-UQ for qemu-devel@nongnu.org; Fri, 03 Jun 2016 16:40:35 -0400 Received: from mail-wm0-x233.google.com ([2a00:1450:400c:c09::233]:36622) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8vtR-0000PT-Ak for qemu-devel@nongnu.org; Fri, 03 Jun 2016 16:40:33 -0400 Received: by mail-wm0-x233.google.com with SMTP id n184so11942557wmn.1 for ; Fri, 03 Jun 2016 13:40:33 -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=ASGDlSrX9KBH/7BB/iIhkt0eomSmm4QOEIkRqJ4dv3w=; b=JKgO+BhZ1uXlehWdMg+Rwrcq/u0KS+iqT6fzk/aiQCprQTD8VgIXGnKFhiYJ/M4yJC lYF6MiF4Pxi4WK+9iXFFceNL1ZMvqmxpyOjMjrllTNOonyb3CDU/fp117uPP8LsxNLZj I8IJGSsVlxRrJxHRxFnHKDwyHC2i55+Z9hkWA= 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=ASGDlSrX9KBH/7BB/iIhkt0eomSmm4QOEIkRqJ4dv3w=; b=jh/e7mqUOcvfYuxxAM+vIgu/FJD5K8MRTSvaDWcm31KYbACZX52qE9em0j8VEPvX2Q 5S6XDubHyyYN16uvSow+jczNe7Seq4FkWm02ejP9Mi91GcsJ5psxe+L6kJ20qEC2CDUP THHZNus8HPH+hZeodRICQfs3ErSFz9tCBCZqIm/lSqAq57fJTVNQ75h5I4p4DBfKet2N vlZHhR03MfVlHDg2HtFWkd8wZ+WZkwr1JgV/HxRbse6aNOGvKSgtn83QrW/+RV8mLDxJ VpRHrJo8qLDHudvgKsKrqLmkImQReGnY86AvMHC/8X82CfLMFleUenX+3VfxcGKLrcb0 2yQQ== X-Gm-Message-State: ALyK8tJy54kS01UVM+DPV5bRhF1z/oTNf2M6AxAkzq7LAEUrWmPP8xnI2OmYqIuaBl2SatRn X-Received: by 10.194.141.238 with SMTP id rr14mr4988570wjb.58.1464986432594; Fri, 03 Jun 2016 13:40:32 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id m5sm3940978wji.16.2016.06.03.13.40.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Jun 2016 13:40:30 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 7BE4D3E2CDE; Fri, 3 Jun 2016 21:40:39 +0100 (BST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: mttcg@listserver.greensocs.com, qemu-devel@nongnu.org, fred.konrad@greensocs.com, a.rigo@virtualopensystems.com, serge.fdrv@gmail.com, cota@braap.org, bobby.prani@gmail.com Date: Fri, 3 Jun 2016 21:40:12 +0100 Message-Id: <1464986428-6739-4-git-send-email-alex.bennee@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1464986428-6739-1-git-send-email-alex.bennee@linaro.org> References: <1464986428-6739-1-git-send-email-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::233 Subject: [Qemu-devel] [RFC v3 03/19] 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: peter.maydell@linaro.org, Peter Crosthwaite , claudio.fontana@huawei.com, Riku Voipio , mark.burton@greensocs.com, Blue Swirl , jan.kiszka@siemens.com, pbonzini@redhat.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= , rth@twiddle.net 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 --- 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.7.4 diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index 6ab5334..4a61ad0 100644 --- a/bsd-user/mmap.c +++ b/bsd-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/include/exec/exec-all.h b/include/exec/exec-all.h index 70ab361..ea1c925 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -369,6 +369,7 @@ void tlb_fill(CPUState *cpu, target_ulong addr, int is_write, int mmu_idx, #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 3519147..fd68249 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -44,6 +44,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 ec6fdbb..e3f44d9 100644 --- a/translate-all.c +++ b/translate-all.c @@ -33,6 +33,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 @@ -60,6 +61,7 @@ /* #define DEBUG_TB_INVALIDATE */ /* #define DEBUG_TB_FLUSH */ +/* #define DEBUG_LOCKING */ /* make various TB consistency checks */ /* #define DEBUG_TB_CHECK */ @@ -68,6 +70,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 { @@ -155,6 +179,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)