From patchwork Fri May 13 00:13:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 9087071 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id BBD7EBF29F for ; Fri, 13 May 2016 00:21:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DA58B20204 for ; Fri, 13 May 2016 00:21:47 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 212C0200D0 for ; Fri, 13 May 2016 00:21:47 +0000 (UTC) Received: from localhost ([::1]:60363 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b10rS-0004VT-3n for patchwork-qemu-devel@patchwork.kernel.org; Thu, 12 May 2016 20:21:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38606) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b10lA-0001aF-7k for qemu-devel@nongnu.org; Thu, 12 May 2016 20:15:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b10l3-0002w4-IX for qemu-devel@nongnu.org; Thu, 12 May 2016 20:15:15 -0400 Received: from mail-qg0-x242.google.com ([2607:f8b0:400d:c04::242]:35186) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b10l3-0002vx-Dn for qemu-devel@nongnu.org; Thu, 12 May 2016 20:15:09 -0400 Received: by mail-qg0-x242.google.com with SMTP id b14so6075086qge.2 for ; Thu, 12 May 2016 17:15:09 -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=fBHBceDwPSbPKDQCp0QCmlKRZNPirqkENx4XVbIrjNo=; b=P9ldIm9nA4es9gGiewSNIiF5TrSDhlV4IAXbgNVB6mIODvwgqXPKeAvhmgjuiUDDlz SFaBQulLRi+hLuC1kNGCaiVzXtbKzz5CfjVHSBXylVVUKJT7zY0TYgQn2eDVl52QCA+m VucbpHWuKSSSeTVs52wblLcxUj1l8UN2HY6VDy8q7DkwOw2qfpGcbn3q/7zz2UasMEDP pO/3eldllXVeKELuvw+WffcJsTxxNm2op2QEH5qKS9ff/7O7l6gE/jmCofxyKv/heSkM ZQo6OzgWA7TgS7vLvaXQMqx0FEpHHqAS2jj1mH39APZNDCnJkCH5yAzEMSC/Frjel+MW ziug== 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=fBHBceDwPSbPKDQCp0QCmlKRZNPirqkENx4XVbIrjNo=; b=BM9El/3AEwzkOkl7JX3VK/HfrIb2w3FKP1plQ9te7VfQMs1zTIA505t7l8YB821HXe 5ERC4ORXmE0KjIuFjQgY86VoU2o1ug+p1Lb0wS1SgnUA8OgpuVXT5PoZKdcqhAfRoYIQ Ix/7kukJGmuA0jyG7Pa9aypIbF3MsEVGf34GKx3LHUDq72r64Wl4aW/1Pztjoc5oH6Tp MX9uYuddSgUBHkzpvIwh4bLT91b2SQnqamAqYSJMAGgUdWlf8pdYVmUZPIW2UVr8lG7x fFp89wt0jMwZsnjJtB6YNpcLm/YCSFWVppVgx4uhR3E+aHELM+3OQm3E/hhNIODobOzt moJw== X-Gm-Message-State: AOPr4FVkkWNFzmdmYPRngfuRPyN8Z5yhqyfA6ZkyfAB7BC74dOZZrJUuinWR3OFkIrKx3Q== X-Received: by 10.140.98.147 with SMTP id o19mr12619796qge.8.1463098509182; Thu, 12 May 2016 17:15:09 -0700 (PDT) Received: from bigtime.com ([172.56.44.137]) by smtp.gmail.com with ESMTPSA id w16sm7171321qka.35.2016.05.12.17.15.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 May 2016 17:15:08 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 12 May 2016 14:13:20 -1000 Message-Id: <1463098420-29113-20-git-send-email-rth@twiddle.net> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1463098420-29113-1-git-send-email-rth@twiddle.net> References: <1463098420-29113-1-git-send-email-rth@twiddle.net> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400d:c04::242 Subject: [Qemu-devel] [PULL 19/39] tcg: Init TB's direct jumps before making it visible 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, Sergey Fedorov , Sergey Fedorov Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Sergey Fedorov Initialize TB's direct jump list data fields and reset the jumps before tb_link_page() puts it into the physical hash table and the physical page list. So TB is completely initialized before it becomes visible. This is pure rearrangement of code to a more suitable place, though it could be a preparation for relaxing the locking scheme in future. Signed-off-by: Sergey Fedorov Signed-off-by: Sergey Fedorov Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson --- translate-all.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/translate-all.c b/translate-all.c index 4a58af4..1dc1a73 100644 --- a/translate-all.c +++ b/translate-all.c @@ -1134,19 +1134,6 @@ static void tb_link_page(TranslationBlock *tb, tb_page_addr_t phys_pc, tb->page_addr[1] = -1; } - assert(((uintptr_t)tb & 3) == 0); - tb->jmp_list_first = (uintptr_t)tb | 2; - tb->jmp_list_next[0] = (uintptr_t)NULL; - tb->jmp_list_next[1] = (uintptr_t)NULL; - - /* init original jump addresses */ - if (tb->jmp_reset_offset[0] != TB_JMP_RESET_OFFSET_INVALID) { - tb_reset_jump(tb, 0); - } - if (tb->jmp_reset_offset[1] != TB_JMP_RESET_OFFSET_INVALID) { - tb_reset_jump(tb, 1); - } - #ifdef DEBUG_TB_CHECK tb_page_check(); #endif @@ -1255,12 +1242,31 @@ TranslationBlock *tb_gen_code(CPUState *cpu, ROUND_UP((uintptr_t)gen_code_buf + gen_code_size + search_size, CODE_GEN_ALIGN); + /* init jump list */ + assert(((uintptr_t)tb & 3) == 0); + tb->jmp_list_first = (uintptr_t)tb | 2; + tb->jmp_list_next[0] = (uintptr_t)NULL; + tb->jmp_list_next[1] = (uintptr_t)NULL; + + /* init original jump addresses wich has been set during tcg_gen_code() */ + if (tb->jmp_reset_offset[0] != TB_JMP_RESET_OFFSET_INVALID) { + tb_reset_jump(tb, 0); + } + if (tb->jmp_reset_offset[1] != TB_JMP_RESET_OFFSET_INVALID) { + tb_reset_jump(tb, 1); + } + /* check next page if needed */ virt_page2 = (pc + tb->size - 1) & TARGET_PAGE_MASK; phys_page2 = -1; if ((pc & TARGET_PAGE_MASK) != virt_page2) { phys_page2 = get_page_addr_code(env, virt_page2); } + /* As long as consistency of the TB stuff is provided by tb_lock in user + * mode and is implicit in single-threaded softmmu emulation, no explicit + * memory barrier is required before tb_link_page() makes the TB visible + * through the physical hash table and physical page list. + */ tb_link_page(tb, phys_pc, phys_page2); return tb; }