From patchwork Mon Oct 31 14:13:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 80176 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp140062qge; Mon, 31 Oct 2016 07:16:13 -0700 (PDT) X-Received: by 10.233.220.131 with SMTP id q125mr24662575qkf.43.1477923373178; Mon, 31 Oct 2016 07:16: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 d93si17697120qkh.92.2016.10.31.07.16.13 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 31 Oct 2016 07:16: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=@gmail.com; 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 Received: from localhost ([::1]:35907 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c1DNk-0001Me-Mb for patch@linaro.org; Mon, 31 Oct 2016 10:16:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33326) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c1DLP-00004s-PK for qemu-devel@nongnu.org; Mon, 31 Oct 2016 10:13:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c1DLO-0002qa-4r for qemu-devel@nongnu.org; Mon, 31 Oct 2016 10:13:47 -0400 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:35882) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1c1DLN-0002pc-Uj for qemu-devel@nongnu.org; Mon, 31 Oct 2016 10:13:46 -0400 Received: by mail-wm0-x241.google.com with SMTP id c17so18622453wmc.3 for ; Mon, 31 Oct 2016 07:13:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ypckkU0jD8WTaO9W7QLD73eAAa1HmjufX2gz6mYNGa8=; b=aEHTAi+57siJGdmpSdq6ijSCIthmVwuFN3xF86xgET+6Fnc126lTt1D8cY/8Fwl9mr DPf/f19N6ZAG9uCSZAfkGL6YfmG8KhtREhxhVEeIybQR8ds9pWjhQRVnGrcJxDDc5TQW +GvqkSnVBic5JDAapsUgKCVAffI0wwvSVxD9KrGnwdajI8of0YLRpauJY4/fKrIJtYzV xL1kVW0N+ahMZhdgNu9rDwKSc1R2Ap2zD7AbiWEKZS7Kp/MxrRL99v6kxPuWEbX4TRFI dCcnWbx4fQNfn3nWmCmoIakWuP034ODoOIIYD/W2eXgWbM80v4BfT9YYxsox7GGk/DXW DRrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=ypckkU0jD8WTaO9W7QLD73eAAa1HmjufX2gz6mYNGa8=; b=MA5sOyat3LJb2kr0nCpTvuBQ/WHYDcQAqBHQi/p5XkkBlUm3EUDpgI1QgPtTGRe/xz CVUjJlgfH0CbHXE2HFNp98UneW0I5Mg9JgzlWXrKk540R/0NWkb12hBWD64zkpPLjhd0 oDKAvPJWNfr2YM+++55ipfEfuiqWEPCROlAaZvdic2jNIVRzuGDsl16Y9WWvU/KSLVpx eZG/bGKGeKoWGsHSaxyBG3glbOcEsnB6ZcLVgAhRcFpRnU0a5Mym6Ya+qq6y1T4OZjOi BKZtg4zvNdEEv9EPA4s6ZYHRA0cBtZI/E0kFPn2QCdCMYnoCYQV2tk2mpLfdw0IbZKgD 9Wkw== X-Gm-Message-State: ABUngvd0O3ZK3Grzq9gM0dbBfZ5/DxLHiRbdZHXd4JkhKcIixq1AsJ/A+1q/LooNNYE2qg== X-Received: by 10.28.5.207 with SMTP id 198mr12223410wmf.22.1477923224772; Mon, 31 Oct 2016 07:13:44 -0700 (PDT) Received: from donizetti.lan (dynamic-adsl-78-12-246-178.clienti.tiscali.it. [78.12.246.178]) by smtp.gmail.com with ESMTPSA id p13sm25052133wmd.20.2016.10.31.07.13.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 31 Oct 2016 07:13:44 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 31 Oct 2016 15:13:24 +0100 Message-Id: <1477923215-30323-4-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1477923215-30323-1-git-send-email-pbonzini@redhat.com> References: <1477923215-30323-1-git-send-email-pbonzini@redhat.com> 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::241 Subject: [Qemu-devel] [PULL 03/14] 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: =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Alex Bennée 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 Message-Id: <20161027151030.20863-4-alex.bennee@linaro.org> Signed-off-by: Paolo Bonzini --- 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 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 cb624e4..4d36ee3 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, 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 ffd099d..61685bf 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -41,6 +41,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 f35522e..5aded3d 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 { @@ -173,6 +197,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)