From patchwork Thu Oct 27 10:02:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 619177 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp175377pvb; Thu, 27 Oct 2022 03:05:50 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4dlLoNeDaAMUGpQgkxZoHO5mS0bEdd+VN4ymU4Nx3wquQ8O8iZwWcPXy/z0PexCYf+nt5V X-Received: by 2002:a05:620a:2685:b0:6f5:a85f:7c50 with SMTP id c5-20020a05620a268500b006f5a85f7c50mr13726561qkp.75.1666865150626; Thu, 27 Oct 2022 03:05:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666865150; cv=none; d=google.com; s=arc-20160816; b=UXEhfOPdItN/0LNzEaFvVUqelJ3SJtksXioPa8DFLqMGb0qk81EgqFfqIXBzXMfy/t he/Laddz1rVt/omCB1GivMsx0PNRzJMPpbTb8N0AxLqtsQJBkM3kRJmTx5Hy3UBKOToR NWa+iACyj1ihJnBTi+ywnKFKcW0xyr67zwSs4XRoS9xUgQdjdUEb+CgobpKmp7G00wJR HW5rWcsnvP2o8Jr6e+J0q/TqfbS6RB2WjG3Mo78rGpIMICmpzodbmTjF2abAgwcxaZZE qNHYjWwkFFU/5bMBOMHPdqKPMzjuG+elA1JkvjAOHL0yxc6mk4qnhI2/NQtqCSwom5Ud W6BA== 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:cc:to :from:dkim-signature; bh=nSG/K4mlF2KPY6JS4R2kh3NiVBne+gqPMQQ357pKXcA=; b=07slk48b8Ne9oqPk8lftLqXWX2QcNgzt8v8H6J/0xwg64AJxgCvtsbeL3oVdfLv/7o gmI3du+XZDKnSD0BjBeTkrExt2shzR2dmqX9Lb5xSZtcvqqch6mxW87PXAU4ZvSnQEDO 8JzCP5fWKZyaBCSW86Rc8Hy56Nj13v5asr5JF2nqgcbDrjHHIC7DS99+qXcjEKI+CtMT smdNaFUF/X1wioF/IBxE8vFigHW1VSqw96z9QPBMgelUTnpT8g9QHUlnlMSZANrp3F1g nCPsnM5hf2D+nStsdfQl1GlpRq6aiY+RPYyUom6ff1os4RofnURq1+dWSwSkGDa13gxh RtAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=u1ktNpJ4; 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 og10-20020a056214428a00b004b31dec5686si572947qvb.46.2022.10.27.03.05.50 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 27 Oct 2022 03:05:50 -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=u1ktNpJ4; 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 1onzjZ-0007VX-Gk; Thu, 27 Oct 2022 06:03:33 -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 1onzjA-0006sZ-Tl for qemu-devel@nongnu.org; Thu, 27 Oct 2022 06:03:09 -0400 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1onzj8-0004Ef-Iz for qemu-devel@nongnu.org; Thu, 27 Oct 2022 06:03:08 -0400 Received: by mail-pf1-x434.google.com with SMTP id g62so974409pfb.10 for ; Thu, 27 Oct 2022 03:03:05 -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:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nSG/K4mlF2KPY6JS4R2kh3NiVBne+gqPMQQ357pKXcA=; b=u1ktNpJ4RM7TK79E1Gk+5LixuoKLqNpIzJkYHsMmmgwwyZqxT//d/yia5tYUPc8kMF gSOiSoo+WLL5LqdV20bc5l3dG00tRJzZ1uGXji76eCqcHX14m06GOg+brRFUsdyNYR93 ellQuaw78vTNGkkXrRMmPwEPkZ1pq/8BcCYbb7/QVU1QBfCPkvvyAX1kCrQYoYIa68b8 L1UBhv8mpyCDhwnD7j4dPFyid5nk1u8uj2goczv0UYTamVnme92pxIwFqVI1U5qDM81b WmHXLTos8e73saRJ3/2587qPq/uO9xzem/IskCSN2XbAj1FkoGlQIl+xLS2IuT/cS32T tEyw== 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:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nSG/K4mlF2KPY6JS4R2kh3NiVBne+gqPMQQ357pKXcA=; b=PMD5+4R+ioo22/jlGdcTLA7lbBbX6tHw2d0N8y+9JbFs1W0kMWhqfVHgEnqTVAmGDe pQnme0NrBjoL1XsLR40d9vF4Me1vMYxkqsgXi5RTYw26aC1C1s8GYYo3jzNK+WbWqDnO L1XvLOtpWJ5fG0d+yiIhsXK0KGB0NuAykb8HmagVs6OL2j2gcdhuGrWsnOVgUNOGxfbb iuo3n32POcWfW5ZH9cMQqmbXEii7g14sxHTv2XDjow40CocJZbuUKiGtyxLn2C9aT1uO LbEQSJ3cc05vos1dQKy4yXBc2bJRsIa8kzCtRyzrn20NOFimTAneLMDC0VnTqaBVFhTf PQlw== X-Gm-Message-State: ACrzQf0nX0ZIJxS9H1IemF+7Px7HFDIiOuBNv6j7UeyTgKCedgPYMVM2 QFpOQAfnq1pKl8RlmGqh0k/FYku2uAg4B/9E X-Received: by 2002:a65:6158:0:b0:46f:55fe:9be6 with SMTP id o24-20020a656158000000b0046f55fe9be6mr1078594pgv.301.1666864984528; Thu, 27 Oct 2022 03:03:04 -0700 (PDT) Received: from localhost.localdomain ([2001:8003:501a:d301:3a91:9408:3918:55a]) by smtp.gmail.com with ESMTPSA id n13-20020a17090a2bcd00b0020a825fc912sm2354631pje.45.2022.10.27.03.03.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Oct 2022 03:03:03 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: cfontana@suse.de Subject: [PATCH v2 1/6] accel/tcg: Introduce cpu_unwind_state_data Date: Thu, 27 Oct 2022 21:02:49 +1100 Message-Id: <20221027100254.215253-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221027100254.215253-1-richard.henderson@linaro.org> References: <20221027100254.215253-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::434; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x434.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 way to examine the unwind data without actually restoring the data back into env. Signed-off-by: Richard Henderson Reviewed-by: Claudio Fontana --- accel/tcg/internal.h | 4 +-- include/exec/exec-all.h | 21 ++++++++--- accel/tcg/translate-all.c | 74 ++++++++++++++++++++++++++------------- 3 files changed, 68 insertions(+), 31 deletions(-) diff --git a/accel/tcg/internal.h b/accel/tcg/internal.h index 1227bb69bd..9c06b320b7 100644 --- a/accel/tcg/internal.h +++ b/accel/tcg/internal.h @@ -106,8 +106,8 @@ void tb_reset_jump(TranslationBlock *tb, int n); TranslationBlock *tb_link_page(TranslationBlock *tb, tb_page_addr_t phys_pc, tb_page_addr_t phys_page2); bool tb_invalidate_phys_page_unwind(tb_page_addr_t addr, uintptr_t pc); -int cpu_restore_state_from_tb(CPUState *cpu, TranslationBlock *tb, - uintptr_t searched_pc, bool reset_icount); +void cpu_restore_state_from_tb(CPUState *cpu, TranslationBlock *tb, + uintptr_t host_pc, bool reset_icount); /* Return the current PC from CPU, which may be cached in TB. */ static inline target_ulong log_pc(CPUState *cpu, const TranslationBlock *tb) diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index e948992a80..7d851f5907 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -39,20 +39,33 @@ typedef ram_addr_t tb_page_addr_t; #define TB_PAGE_ADDR_FMT RAM_ADDR_FMT #endif +/** + * cpu_unwind_state_data: + * @cpu: the cpu context + * @host_pc: the host pc within the translation + * @data: output data + * + * Attempt to load the the unwind state for a host pc occurring in + * translated code. If @host_pc is not in translated code, the + * function returns false; otherwise @data is loaded. + * This is the same unwind info as given to restore_state_to_opc. + */ +bool cpu_unwind_state_data(CPUState *cpu, uintptr_t host_pc, uint64_t *data); + /** * cpu_restore_state: - * @cpu: the vCPU state is to be restore to - * @searched_pc: the host PC the fault occurred at + * @cpu: the cpu context + * @host_pc: the host pc within the translation * @will_exit: true if the TB executed will be interrupted after some cpu adjustments. Required for maintaining the correct icount valus * @return: true if state was restored, false otherwise * * Attempt to restore the state for a fault occurring in translated - * code. If the searched_pc is not in translated code no state is + * code. If @host_pc is not in translated code no state is * restored and the function returns false. */ -bool cpu_restore_state(CPUState *cpu, uintptr_t searched_pc, bool will_exit); +bool cpu_restore_state(CPUState *cpu, uintptr_t host_pc, bool will_exit); G_NORETURN void cpu_loop_exit_noexc(CPUState *cpu); G_NORETURN void cpu_loop_exit(CPUState *cpu); diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index f185356a36..319becb698 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -247,52 +247,66 @@ static int encode_search(TranslationBlock *tb, uint8_t *block) return p - block; } -/* The cpu state corresponding to 'searched_pc' is restored. - * When reset_icount is true, current TB will be interrupted and - * icount should be recalculated. - */ -int cpu_restore_state_from_tb(CPUState *cpu, TranslationBlock *tb, - uintptr_t searched_pc, bool reset_icount) +static int cpu_unwind_data_from_tb(TranslationBlock *tb, uintptr_t host_pc, + uint64_t *data) { - uint64_t data[TARGET_INSN_START_WORDS]; - uintptr_t host_pc = (uintptr_t)tb->tc.ptr; + uintptr_t iter_pc = (uintptr_t)tb->tc.ptr; const uint8_t *p = tb->tc.ptr + tb->tc.size; int i, j, num_insns = tb->icount; -#ifdef CONFIG_PROFILER - TCGProfile *prof = &tcg_ctx->prof; - int64_t ti = profile_getclock(); -#endif - searched_pc -= GETPC_ADJ; + host_pc -= GETPC_ADJ; - if (searched_pc < host_pc) { + if (host_pc < iter_pc) { return -1; } - memset(data, 0, sizeof(data)); + memset(data, 0, sizeof(uint64_t) * TARGET_INSN_START_WORDS); if (!TARGET_TB_PCREL) { data[0] = tb_pc(tb); } - /* Reconstruct the stored insn data while looking for the point at - which the end of the insn exceeds the searched_pc. */ + /* + * Reconstruct the stored insn data while looking for the point + * at which the end of the insn exceeds host_pc. + */ for (i = 0; i < num_insns; ++i) { for (j = 0; j < TARGET_INSN_START_WORDS; ++j) { data[j] += decode_sleb128(&p); } - host_pc += decode_sleb128(&p); - if (host_pc > searched_pc) { - goto found; + iter_pc += decode_sleb128(&p); + if (iter_pc > host_pc) { + return num_insns - i; } } return -1; +} + +/* + * The cpu state corresponding to 'host_pc' is restored. + * When reset_icount is true, current TB will be interrupted and + * icount should be recalculated. + */ +void cpu_restore_state_from_tb(CPUState *cpu, TranslationBlock *tb, + uintptr_t host_pc, bool reset_icount) +{ + uint64_t data[TARGET_INSN_START_WORDS]; +#ifdef CONFIG_PROFILER + TCGProfile *prof = &tcg_ctx->prof; + int64_t ti = profile_getclock(); +#endif + int insns_left = cpu_unwind_data_from_tb(tb, host_pc, data); + + if (insns_left < 0) { + return; + } - found: if (reset_icount && (tb_cflags(tb) & CF_USE_ICOUNT)) { assert(icount_enabled()); - /* Reset the cycle counter to the start of the block - and shift if to the number of actually executed instructions */ - cpu_neg(cpu)->icount_decr.u16.low += num_insns - i; + /* + * Reset the cycle counter to the start of the block and + * shift if to the number of actually executed instructions. + */ + cpu_neg(cpu)->icount_decr.u16.low += insns_left; } cpu->cc->tcg_ops->restore_state_to_opc(cpu, tb, data); @@ -302,7 +316,6 @@ int cpu_restore_state_from_tb(CPUState *cpu, TranslationBlock *tb, prof->restore_time + profile_getclock() - ti); qatomic_set(&prof->restore_count, prof->restore_count + 1); #endif - return 0; } bool cpu_restore_state(CPUState *cpu, uintptr_t host_pc, bool will_exit) @@ -335,6 +348,17 @@ bool cpu_restore_state(CPUState *cpu, uintptr_t host_pc, bool will_exit) return false; } +bool cpu_unwind_state_data(CPUState *cpu, uintptr_t host_pc, uint64_t *data) +{ + if (in_code_gen_buffer((const void *)(host_pc - tcg_splitwx_diff))) { + TranslationBlock *tb = tcg_tb_lookup(host_pc); + if (tb) { + return cpu_unwind_data_from_tb(tb, host_pc, data) >= 0; + } + } + return false; +} + void page_init(void) { page_size_init();