From patchwork Tue Oct 10 00:55:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 9994735 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 96CED60230 for ; Tue, 10 Oct 2017 01:10:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 87DCE28860 for ; Tue, 10 Oct 2017 01:10:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7CC702886E; Tue, 10 Oct 2017 01:10:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 14AE728876 for ; Tue, 10 Oct 2017 01:10:01 +0000 (UTC) Received: from localhost ([::1]:60540 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1j3Y-0003o7-8O for patchwork-qemu-devel@patchwork.kernel.org; Mon, 09 Oct 2017 21:10:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60551) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1iqQ-0002Oi-C9 for qemu-devel@nongnu.org; Mon, 09 Oct 2017 20:56:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1iqM-0004WM-NR for qemu-devel@nongnu.org; Mon, 09 Oct 2017 20:56:25 -0400 Received: from mail-pf0-x22f.google.com ([2607:f8b0:400e:c00::22f]:53905) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e1iqM-0004Vt-Hf for qemu-devel@nongnu.org; Mon, 09 Oct 2017 20:56:22 -0400 Received: by mail-pf0-x22f.google.com with SMTP id n73so8794306pfg.10 for ; Mon, 09 Oct 2017 17:56:22 -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=BlqfHrkOPjLzLqDyXBqDW01UXizdoh9zUOpMpGA3NFk=; b=fzdaXHJ7h6JggUSh3mrKhmMOD/zifn3H4DfWBKl4Fj/MdIDvNiHPVoo2rY2W8aATXs Y9zjCadomyufXbPgVs6FjCg8BXmiB/aPTJWbI0V4NkPtPVlxVzxYDhqFhxKipjAxB1Ta kPEY6cTjoN0xC7HpNyIn5KAAmJKxkMZdnSmO4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BlqfHrkOPjLzLqDyXBqDW01UXizdoh9zUOpMpGA3NFk=; b=hUlGhtKZ0HdWxKeGt4OORPaJ20a/SSCWp0EmmoxRvX04+4y30pFkxjsAAQo6bzKoHZ MOomDPgKraSt93y+5BDHEUoEbC6HAglBlmf2EL2CYN2nBU27YSR+cFdAEFUCJenHIIJl a1TEa25J5/1inBVEZXOZKZ8ErgMUZ9y592L0MmxmnTbl2X+1rY5bykZ0kztAZkK/Kn1g rhuE9YIfhoCxjX7S8Z4mNzkdASUMfO/S+jOqn4B0bpRnCcCgKgohPQb7idWTB2p8meSC vVnDLug06nDu5KRbkovHeJZNy8Ye1EnTGBrl+efGpbFNl0D1wHtF+YeS4o2d60NLOWzW qDsw== X-Gm-Message-State: AMCzsaWhIeTK+FbUBEY9ncknYw2tkIAlL6o9ZQq8AuLGRYG7i2W8lCwQ Zod/DUJQsHleVU8PRP+Ntr2bLgytevg= X-Google-Smtp-Source: AOwi7QA+QRTRemwpfS0Y8/okSk8nZgIMDZ3PJYuq70vuyjSHnR5yo1WW69JAnKoqG2tbO2P/g0NzOA== X-Received: by 10.98.30.66 with SMTP id e63mr11701437pfe.176.1507596981173; Mon, 09 Oct 2017 17:56:21 -0700 (PDT) Received: from bigtime.twiddle.net (97-126-104-76.tukw.qwest.net. [97.126.104.76]) by smtp.gmail.com with ESMTPSA id n19sm17121368pfj.52.2017.10.09.17.56.20 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 09 Oct 2017 17:56:20 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 9 Oct 2017 17:55:51 -0700 Message-Id: <20171010005600.28735-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171010005600.28735-1-richard.henderson@linaro.org> References: <20171010005600.28735-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::22f Subject: [Qemu-devel] [PULL 14/23] translate-all: define and use DEBUG_TB_CHECK_GATE 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, "Emilio G. Cota" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: "Emilio G. Cota" This prevents bit rot by ensuring the debug code is compiled when building a user-mode target. Unfortunately the helpers are user-mode-only so we cannot fully get rid of the ifdef checks. Add a comment to explain this. Suggested-by: Alex Bennée Reviewed-by: Richard Henderson Signed-off-by: Emilio G. Cota Signed-off-by: Richard Henderson --- accel/tcg/translate-all.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 6b853b329c..26efad302d 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -82,6 +82,12 @@ #undef DEBUG_TB_CHECK #endif +#ifdef DEBUG_TB_CHECK +#define DEBUG_TB_CHECK_GATE 1 +#else +#define DEBUG_TB_CHECK_GATE 0 +#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 @@ -950,7 +956,13 @@ void tb_flush(CPUState *cpu) } } -#ifdef DEBUG_TB_CHECK +/* + * Formerly ifdef DEBUG_TB_CHECK. These debug functions are user-mode-only, + * so in order to prevent bit rot we compile them unconditionally in user-mode, + * and let the optimizer get rid of them by wrapping their user-only callers + * with if (DEBUG_TB_CHECK_GATE). + */ +#ifdef CONFIG_USER_ONLY static void do_tb_invalidate_check(struct qht *ht, void *p, uint32_t hash, void *userp) @@ -994,7 +1006,7 @@ static void tb_page_check(void) qht_iter(&tcg_ctx.tb_ctx.htable, do_tb_page_check, NULL); } -#endif +#endif /* CONFIG_USER_ONLY */ static inline void tb_page_remove(TranslationBlock **ptb, TranslationBlock *tb) { @@ -1236,8 +1248,10 @@ static void tb_link_page(TranslationBlock *tb, tb_page_addr_t phys_pc, h = tb_hash_func(phys_pc, tb->pc, tb->flags, tb->trace_vcpu_dstate); qht_insert(&tcg_ctx.tb_ctx.htable, tb, h); -#ifdef DEBUG_TB_CHECK - tb_page_check(); +#ifdef CONFIG_USER_ONLY + if (DEBUG_TB_CHECK_GATE) { + tb_page_check(); + } #endif } @@ -2223,8 +2237,10 @@ int page_unprotect(target_ulong address, uintptr_t pc) /* and since the content will be modified, we must invalidate the corresponding translated code. */ current_tb_invalidated |= tb_invalidate_phys_page(addr, pc); -#ifdef DEBUG_TB_CHECK - tb_invalidate_check(addr); +#ifdef CONFIG_USER_ONLY + if (DEBUG_TB_CHECK_GATE) { + tb_invalidate_check(addr); + } #endif } mprotect((void *)g2h(host_start), qemu_host_page_size,