From patchwork Mon Oct 24 13:24:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 617872 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2738743pvb; Mon, 24 Oct 2022 06:57:51 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7F1GpHVuD6G5xL6EZ4HLC0bugzikaIsu1Kp96T1C3G1cEj5ldKxoeX0jh4rgUUkk9CwFbF X-Received: by 2002:a05:620a:c99:b0:6ed:5fdd:2717 with SMTP id q25-20020a05620a0c9900b006ed5fdd2717mr22609921qki.665.1666619860530; Mon, 24 Oct 2022 06:57:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666619860; cv=none; d=google.com; s=arc-20160816; b=j0sulDDsQr75MpyXhtn7iVaT8BUO4tKO0Eg7FyZzHHXxS4HzcVjuQnpg4HdCKlOl3y vBuAiD6EANlbLwuc2Y8Apx4N5plFc1XRMqUXIzVoVxgXU8gDjbY0TuYFopg8Rav4JKG3 9MjgB8d5biaAO8o7UaGjGW21lYOXz1ZztxY55jaEdboqXkJoxV68X5Y1Qf69GCecSo+J fZ2z3tOwIBfwh6jA0YMKLbFIn6I7EQ0pKDfYpZ0BeLTqRye0bl4teuaCIbklbhvaksVU JPdDoTXIfRSLrmX3H0IZcSlVcs8Ufg2+Rl6W/WTiCBg5NEJJYHyeuv5SkUHGIwNOl/7I TmlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=7hCgNQMpOajbfDDqbMwdSH+6jBKQutGWCbpGwjxiCrc=; b=GrdNhem0AkzOFvcl3Em/VBfpWuai2pqfRvkKuXqOvh+dODJSqX7Ba6ceSg1O6rnBIU a+l1LFRMBVSf56/Hag7PEVXdzqu4CeM7su70s2q0GkySvVPCQRx+lLGaeJFFOVoqohV8 Lo9UtQLlpMz6J7+GyQt1mqBxfZWceLRx3K3yxvtpWFLAQ75EFOECmDtkpabh1rU0n4cr 418pV/Dr9L1mB7hFCtFzvYB9/JIA5rZAK/jL5Vu5MCifcPwYFqc32mSAj2CxMhxFHlfu Xvmwvwj0zuL06V/1ZJJCSqL1OHnXnVVJMX/y0zCEV6hPyfBRIaNCtAo3f6oJx/rfmya6 6edA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DQCAEQB4; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id bm8-20020a05620a198800b006eecf02d618si18046qkb.132.2022.10.24.06.57.40 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 24 Oct 2022 06:57:40 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DQCAEQB4; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1omxSR-0003Gs-Oa; Mon, 24 Oct 2022 09:25:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1omxSK-0003FK-5X for qemu-devel@nongnu.org; Mon, 24 Oct 2022 09:25:28 -0400 Received: from mail-oa1-x36.google.com ([2001:4860:4864:20::36]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1omxSG-0003x6-Ji for qemu-devel@nongnu.org; Mon, 24 Oct 2022 09:25:27 -0400 Received: by mail-oa1-x36.google.com with SMTP id 586e51a60fabf-13b103a3e5dso11838394fac.2 for ; Mon, 24 Oct 2022 06:25:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=7hCgNQMpOajbfDDqbMwdSH+6jBKQutGWCbpGwjxiCrc=; b=DQCAEQB4oD2ss2MfDt/18sj2dPTsvmBXZG6nyCQ70XO9N/pP4gA+gx0X6dFG9DQIkQ NLrRH+S7daPY2yeLCIE4He/TdLg3w5qg40q5f4rpTiHPumxXsGZtffSXIj7+woweY41F kvuXEnq+yRGT/P5vDScEQAopcDxIl7d6wLeuvDHlcQElWJP7T7uBgVnh0JoKbgtWNkMh 4PPnR+RnfTad6ptc/1ObI+//9q0W2aMf2dJXFPtDhtD9SWncKL5+n4GcNIPLce8XmpBG JjCTsQhRiGYSZ1J8pa6Q/ARyQUr8Moq2CrQaXXLXQC2+m3yra7Tw1Fs+h/cR2k7P8GOY W2eA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7hCgNQMpOajbfDDqbMwdSH+6jBKQutGWCbpGwjxiCrc=; b=ndYuOgrbXdlbLWZECQjc3j58s/Y+adxWQB4n7vmfuWT2HFVlbJqo/PM7h2V1SGA37P IshW/OvTp+oIyNGFXUC9s4QB21iv6VoY4tlJ0y9mZFATSy8yPBW1eWnxN0yTh46H+RZc xfZ/VMRzEiRYYrjkXdvDgtCXOagIjZuHPf4L0GLRAN4mVz0JvXP5aoX4SQ8tPey6XgMJ rwY/6JWHX8Eh7tLjvL81bwJ7aQtuoWdEcBudnl1g7yERf9dCs2+M+Ht6B0nE1HGWb2Pn ORQNszSG+q6b6YxSBEJpCp3eRuivJpwubHIBOxoAOB977llnsJhKIqi1kykDB84Y8pc6 kyFg== X-Gm-Message-State: ACrzQf0L+9RXQoFjHVZvQqWIfPy9HMkjJ2zQ7AWG6dfCeLFYu6UYQHEz on7D2qQm4WXn4agK3uOrpqQ13yRPixXsnQ== X-Received: by 2002:a17:90b:3a8b:b0:20d:b254:e30e with SMTP id om11-20020a17090b3a8b00b0020db254e30emr38796571pjb.206.1666617911987; Mon, 24 Oct 2022 06:25:11 -0700 (PDT) Received: from stoup.. ([103.100.225.182]) by smtp.gmail.com with ESMTPSA id b12-20020a1709027e0c00b00178ab008364sm17009216plm.37.2022.10.24.06.25.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Oct 2022 06:25:11 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 01/29] accel/tcg: Add restore_state_to_opc to TCGCPUOps Date: Mon, 24 Oct 2022 23:24:30 +1000 Message-Id: <20221024132459.3229709-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221024132459.3229709-1-richard.henderson@linaro.org> References: <20221024132459.3229709-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2001:4860:4864:20::36; envelope-from=richard.henderson@linaro.org; helo=mail-oa1-x36.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Add a tcg_ops hook to replace the restore_state_to_opc function call. Because these generic hooks cannot depend on target-specific types, temporarily, copy the current target_ulong data[] into uint64_t d64[]. Signed-off-by: Richard Henderson Reviewed-by: Claudio Fontana --- include/exec/exec-all.h | 2 +- include/hw/core/tcg-cpu-ops.h | 11 +++++++++++ accel/tcg/translate-all.c | 24 ++++++++++++++++++++++-- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index e5f8b224a5..a772e8cbdc 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -40,7 +40,7 @@ typedef ram_addr_t tb_page_addr_t; #endif void restore_state_to_opc(CPUArchState *env, TranslationBlock *tb, - target_ulong *data); + target_ulong *data) __attribute__((weak)); /** * cpu_restore_state: diff --git a/include/hw/core/tcg-cpu-ops.h b/include/hw/core/tcg-cpu-ops.h index 78c6c6635d..20e3c0ffbb 100644 --- a/include/hw/core/tcg-cpu-ops.h +++ b/include/hw/core/tcg-cpu-ops.h @@ -31,6 +31,17 @@ struct TCGCPUOps { * function to restore all the state, and register it here. */ void (*synchronize_from_tb)(CPUState *cpu, const TranslationBlock *tb); + /** + * @restore_state_to_opc: Synchronize state from INDEX_op_start_insn + * + * This is called when we unwind state in the middle of a TB, + * usually before raising an exception. Set all part of the CPU + * state which are tracked insn-by-insn in the target-specific + * arguments to start_insn, passed as @data. + */ + void (*restore_state_to_opc)(CPUState *cpu, const TranslationBlock *tb, + const uint64_t *data); + /** @cpu_exec_enter: Callback for cpu_exec preparation */ void (*cpu_exec_enter)(CPUState *cpu); /** @cpu_exec_exit: Callback for cpu_exec cleanup */ diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 4ed75a13e1..19cd23e9a0 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -329,7 +329,6 @@ static int cpu_restore_state_from_tb(CPUState *cpu, TranslationBlock *tb, { target_ulong data[TARGET_INSN_START_WORDS]; uintptr_t host_pc = (uintptr_t)tb->tc.ptr; - CPUArchState *env = cpu->env_ptr; const uint8_t *p = tb->tc.ptr + tb->tc.size; int i, j, num_insns = tb->icount; #ifdef CONFIG_PROFILER @@ -368,7 +367,20 @@ static int cpu_restore_state_from_tb(CPUState *cpu, TranslationBlock *tb, and shift if to the number of actually executed instructions */ cpu_neg(cpu)->icount_decr.u16.low += num_insns - i; } - restore_state_to_opc(env, tb, data); + + { + const struct TCGCPUOps *ops = cpu->cc->tcg_ops; + __typeof(ops->restore_state_to_opc) restore = ops->restore_state_to_opc; + if (restore) { + uint64_t d64[TARGET_INSN_START_WORDS]; + for (i = 0; i < TARGET_INSN_START_WORDS; ++i) { + d64[i] = data[i]; + } + restore(cpu, tb, d64); + } else { + restore_state_to_opc(cpu->env_ptr, tb, data); + } + } #ifdef CONFIG_PROFILER qatomic_set(&prof->restore_time, @@ -380,6 +392,14 @@ static int cpu_restore_state_from_tb(CPUState *cpu, TranslationBlock *tb, bool cpu_restore_state(CPUState *cpu, uintptr_t host_pc, bool will_exit) { + /* + * The pc update associated with restore without exit will + * break the relative pc adjustments performed by TARGET_TB_PCREL. + */ + if (TARGET_TB_PCREL) { + assert(will_exit); + } + /* * The host_pc has to be in the rx region of the code buffer. * If it is not we will not be able to resolve it here.