From patchwork Tue Dec 6 20:56:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pranith Kumar X-Patchwork-Id: 9463271 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 5E9CD6022E for ; Tue, 6 Dec 2016 20:58:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4FE51284AC for ; Tue, 6 Dec 2016 20:58:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 42665284C3; Tue, 6 Dec 2016 20:58:33 +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_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, 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 5FC92284AC for ; Tue, 6 Dec 2016 20:58:31 +0000 (UTC) Received: from localhost ([::1]:34773 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cEMoo-0003LC-Gg for patchwork-qemu-devel@patchwork.kernel.org; Tue, 06 Dec 2016 15:58:30 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58998) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cEMoF-0003Hh-GQ for qemu-devel@nongnu.org; Tue, 06 Dec 2016 15:57:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cEMoC-0006R5-Cp for qemu-devel@nongnu.org; Tue, 06 Dec 2016 15:57:55 -0500 Received: from mail-yw0-f193.google.com ([209.85.161.193]:35317) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cEMoC-0006Ns-8u for qemu-devel@nongnu.org; Tue, 06 Dec 2016 15:57:52 -0500 Received: by mail-yw0-f193.google.com with SMTP id b66so29935695ywh.2 for ; Tue, 06 Dec 2016 12:57:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=H53UGoeEMBiXzPqaRjb73A5l7kgNT/kgMJpYuBRmRIM=; b=dTrhSCX08DeQNtt9yL43cEUnOF5b1GvEx+pfb5afQl1xld2+Lb8qDyD0ZJoG7NhlJM 9r8qXi3MtO+4YGlXqRWtJDkaHxjkXNkHzekw0g3oTs8hwCkCSL/b6m9qx98+r/X2R9qi 40Rr6ZoF951CuSoWG5orL+49bCWi7mABnwoqkFvUZaC0tqvA3bzEE+DDtOOwv84HzbRa 4P9rZ8ajcqA+4B7nv2cETvrWfr8aiEKXejRJd2+yaLupejTbQnp7Vr1/4cUFpkaEj9bX 8pes82Y6VqKN5mmULrAXh50T6/ZGu+p8SR9ikU2w5sNYL721ORJbevLO+ZXFXttNrrDz sPWg== 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; bh=H53UGoeEMBiXzPqaRjb73A5l7kgNT/kgMJpYuBRmRIM=; b=DP+q97dnCS5XBkpGmklT1Kvv3ZsoGSGPsUThjLhqGZHzfQbW8EqQm9lY72AAUyW9Ae TbRgK2+/nAyUkGgSBtPLE2mvsS6YEAtChO1+hqHDm+/wIGXgX+lBTpexrpn82wVg6wGl IQtDkAHHmLn+7YdFStkQSWW9VAlHzK7KRJPq1dM1QOkujjSx/1K+TyBK4MnXpsG1FW8o y4lBTF2y3uXzijKMgtlT437HG4EfqE1Ql3jj/strX9FjR4l5EVGYjv7Gg3tcJsyaXZ7J DA+NyM7c6wSV5uiNwvD9N/K+YoYRS5m8KbDX8jaH2C8DjMWAtBHzO+cu/5/kDgkKXIvH jl8w== X-Gm-Message-State: AKaTC01JTr4mPRuOtB8Uhzud36uJl5r4nOl0fu+rTpdWjnldCXz27+sOc5DcW4p2LiEoew== X-Received: by 10.129.105.4 with SMTP id e4mr65111997ywc.292.1481057790319; Tue, 06 Dec 2016 12:56:30 -0800 (PST) Received: from localhost.localdomain (c-73-207-178-95.hsd1.ga.comcast.net. [73.207.178.95]) by smtp.gmail.com with ESMTPSA id u1sm9012647ywc.15.2016.12.06.12.56.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 06 Dec 2016 12:56:29 -0800 (PST) From: Pranith Kumar To: alex.bennee@linaro.org Date: Tue, 6 Dec 2016 15:56:25 -0500 Message-Id: <20161206205627.8443-2-bobby.prani@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20161206205627.8443-1-bobby.prani@gmail.com> References: <20161206205627.8443-1-bobby.prani@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.161.193 Subject: [Qemu-devel] [RFC PATCH 1/3] tcg: Release tb_lock in the order acquired 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: mst@redhat.com, cota@braap.org, qemu-devel@nongnu.org, rth@twiddle.net Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP We acquire mmap lock and tb lock in one order and release them in a different order. This does not need to be that way. This patch was inspired by a previous patch by Emilio G. Cota (https://lists.gnu.org/archive/html/qemu-devel/2016-08/msg03785.html). Signed-off-by: Pranith Kumar --- cpu-exec.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/cpu-exec.c b/cpu-exec.c index aa8318d864..f4a00f5047 100644 --- a/cpu-exec.c +++ b/cpu-exec.c @@ -318,7 +318,6 @@ static inline TranslationBlock *tb_find(CPUState *cpu, TranslationBlock *tb; target_ulong cs_base, pc; uint32_t flags; - bool have_tb_lock = false; /* we record a subset of the CPU state. It will always be the same before a given translated block @@ -336,7 +335,6 @@ static inline TranslationBlock *tb_find(CPUState *cpu, */ mmap_lock(); tb_lock(); - have_tb_lock = true; /* There's a chance that our desired tb has been translated while * taking the locks so we check again inside the lock. @@ -347,6 +345,7 @@ static inline TranslationBlock *tb_find(CPUState *cpu, tb = tb_gen_code(cpu, pc, cs_base, flags, 0); } + tb_unlock(); mmap_unlock(); } @@ -364,17 +363,12 @@ static inline TranslationBlock *tb_find(CPUState *cpu, #endif /* See if we can patch the calling TB. */ if (last_tb && !qemu_loglevel_mask(CPU_LOG_TB_NOCHAIN)) { - if (!have_tb_lock) { - tb_lock(); - have_tb_lock = true; - } if (!tb->invalid) { + tb_lock(); tb_add_jump(last_tb, tb_exit, tb); + tb_unlock(); } } - if (have_tb_lock) { - tb_unlock(); - } return tb; }