From patchwork Tue Jul 5 16:18:14 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: 71396 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp436503qgy; Tue, 5 Jul 2016 10:58:48 -0700 (PDT) X-Received: by 10.55.181.1 with SMTP id e1mr23279886qkf.99.1467741528884; Tue, 05 Jul 2016 10:58:48 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id d19si804280qke.214.2016.07.05.10.58.48 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 05 Jul 2016 10:58:48 -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]:56853 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKUcS-0004FO-36 for patch@linaro.org; Tue, 05 Jul 2016 13:58:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56600) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKT3F-00078w-6q for qemu-devel@nongnu.org; Tue, 05 Jul 2016 12:18:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bKT3D-0001x9-3P for qemu-devel@nongnu.org; Tue, 05 Jul 2016 12:18:20 -0400 Received: from mail-wm0-x22d.google.com ([2a00:1450:400c:c09::22d]:34881) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKT3C-0001wx-P5 for qemu-devel@nongnu.org; Tue, 05 Jul 2016 12:18:19 -0400 Received: by mail-wm0-x22d.google.com with SMTP id z126so81886837wme.0 for ; Tue, 05 Jul 2016 09:18:18 -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=Zb5xHr86N0JPZ+ucvmaC9//jH8QRL58sj2GErhFTgbI=; b=jUHBXWaql7iLfFKrrL8KgZcM43m5BtZPm0JBdQZhQ+g59KtQXL5o6Zyu0CNn517TZr yN9eX21Cwk+XMXeSZQiih0HqLDLdumiP0UxyRQsBlu5Jjk7/mp6w22MTvQWfU29nR928 RE3TTmEYGCf+cdrY939m+1SDiK/21mBn7Ejtc= 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=Zb5xHr86N0JPZ+ucvmaC9//jH8QRL58sj2GErhFTgbI=; b=Q2hHNMWl3Cy07bMmfJq1znQZYDcR6K91XRu40BbaiQnvqwHFNw7dcUpmOGDNQMD4iy gKVq84zbCjD+jspgbUvvjmKv5TJ7JFB4H40pfdV/fqnM7jFIQlU9RgxlWjt/73ZZQVsM jTZHfkQIOeClZpaRfZr3s2YvFMfJklmXl+77t5fMVKEtJTh09cwp+eUrVSrA+sbMq4Ue AVKCIBd8ShXa9zZEVIj0g7r62yBKiOTgJWag4i59kewUPLzKE8QjKB1aDFgtmOBpVtQa 2lMrfDQH7JUwzElmXk+257XEZ2jdbMXL3zbAC8xu+HTQpH7OGoykvx3Lsn1jxbS7KR0Q iVqg== X-Gm-Message-State: ALyK8tIcewRfl/S1IyTdhKciSFFPAJBFjFDeJ7+yN+I53OUCBAzddUsOFSBg+WnRy2UCFxvg X-Received: by 10.194.157.162 with SMTP id wn2mr17909360wjb.103.1467735498107; Tue, 05 Jul 2016 09:18:18 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id f140sm4853565wmf.22.2016.07.05.09.18.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Jul 2016 09:18:13 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id ABC1B3E0519; Tue, 5 Jul 2016 17:18:17 +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, rth@twiddle.net Date: Tue, 5 Jul 2016 17:18:14 +0100 Message-Id: <1467735496-16256-5-git-send-email-alex.bennee@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1467735496-16256-1-git-send-email-alex.bennee@linaro.org> References: <1467735496-16256-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::22d Subject: [Qemu-devel] [PATCH v2 4/6] tcg: cpu-exec: factor out TB patching code 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, mark.burton@greensocs.com, jan.kiszka@siemens.com, pbonzini@redhat.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This is going to be useful in the next patch when rolling up the locking on the slow path into the TB patching. Signed-off-by: Alex Bennée --- cpu-exec.c | 59 +++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 22 deletions(-) -- 2.7.4 diff --git a/cpu-exec.c b/cpu-exec.c index dd0bd50..59c2ec5 100644 --- a/cpu-exec.c +++ b/cpu-exec.c @@ -278,6 +278,40 @@ static TranslationBlock *tb_find_physical(CPUState *cpu, return qht_lookup(&tcg_ctx.tb_ctx.htable, tb_cmp, &desc, h); } +/* + * Patch the last TB with a jump to the current TB. + * + * Modification of the TB has to be protected with tb_lock. + */ +static inline void maybe_patch_last_tb(CPUState *cpu, + TranslationBlock *tb, + TranslationBlock **last_tb, + int tb_exit) +{ + if (cpu->tb_flushed) { + /* Ensure that no TB jump will be modified as the + * translation buffer has been flushed. + */ + *last_tb = NULL; + cpu->tb_flushed = false; + } +#ifndef CONFIG_USER_ONLY + /* We don't take care of direct jumps when address mapping changes in + * system emulation. So it's not safe to make a direct jump to a TB + * spanning two pages because the mapping for the second page can change. + */ + if (tb->page_addr[1] != -1) { + *last_tb = NULL; + } +#endif + /* See if we can patch the calling TB. */ + if (*last_tb && !qemu_loglevel_mask(CPU_LOG_TB_NOCHAIN)) { + tb_lock(); + tb_add_jump(*last_tb, tb_exit, tb); + tb_unlock(); + } +} + static TranslationBlock *tb_find_slow(CPUState *cpu, target_ulong pc, target_ulong cs_base, @@ -336,28 +370,9 @@ static inline TranslationBlock *tb_find_fast(CPUState *cpu, tb->flags != flags)) { tb = tb_find_slow(cpu, pc, cs_base, flags); } - if (cpu->tb_flushed) { - /* Ensure that no TB jump will be modified as the - * translation buffer has been flushed. - */ - *last_tb = NULL; - cpu->tb_flushed = false; - } -#ifndef CONFIG_USER_ONLY - /* We don't take care of direct jumps when address mapping changes in - * system emulation. So it's not safe to make a direct jump to a TB - * spanning two pages because the mapping for the second page can change. - */ - if (tb->page_addr[1] != -1) { - *last_tb = NULL; - } -#endif - /* See if we can patch the calling TB. */ - if (*last_tb && !qemu_loglevel_mask(CPU_LOG_TB_NOCHAIN)) { - tb_lock(); - tb_add_jump(*last_tb, tb_exit, tb); - tb_unlock(); - } + + maybe_patch_last_tb(cpu, tb, last_tb, tb_exit); + return tb; }