From patchwork Sun Jan 24 18:11:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 369971 Delivered-To: patch@linaro.org Received: by 2002:a02:a60d:0:0:0:0:0 with SMTP id c13csp3343909jam; Sun, 24 Jan 2021 10:13:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJz1Ksw1B/epTDIOrjtbH1YAGsVk8kONvf2v8R+6Rb8+3najFQMfFLsSldLLIhZEKD7+NWsu X-Received: by 2002:a25:b7d1:: with SMTP id u17mr20520619ybj.227.1611512004336; Sun, 24 Jan 2021 10:13:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611512004; cv=none; d=google.com; s=arc-20160816; b=aKJQRIDnddxfnGSRmpgxorI2HocEHcsNPIOjkdovlBbHInJoYMp8fnEzxaGeD+0wvr V1NgobBL4yrZbYXYcwF65ebV8mpt4nJlPgDB9j6kfIF8ud5O6VIkV1FXT5uCp+3GAQ2O 7QbkfOlHMNWCzEi3xNtgU9w85qPVTN9H6P+FbYOYkv557ou4Xcj0MhWVJ/FmeQI/5eIW TEowtU8c6W1bQBbRGRfvXCz6s8Tz43V2ixn5sNWbbm8tzWR95SvmJjcjq9klzwDHpqi5 hlzCuyrcitR6Rx4zK3Nht4p9Zq00nOh4/0Ocf3FdvezdEo9xHbPgH7qlnReBgeUwoQbi dMPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc: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=dMC8pDMFrpkWp3tIhJXkAEfl2zqGr88OycytaS5rwLg=; b=NmC24aPKWCovYeuMW7gSu6Eg29frGZxnZvdgS4jBQL9cxaWkro77+1kQirkjtBtnkd JBzkSqKUACWpK5GU/ZqvOPER5OszyrZEvOBk62OMhBLmaS1vg8vGrAY1WaQwZEkXpuM/ eyW9qYYmIKxyHRPknolopw25y35yltyuqNr6NeYPEtIIJnsWg/SZQwZ8Y+FC9QcVY9vL /LvjX1ZGuyvRrxZf1v/hvTxCTHgJcX67fU2EnueiCIbZrzCBGgUs7F4k5YBIwtZDi+DK 68YRTb6TD+8Dp9zrzCJR38/uIVvsUWlD8jOXbVd+sJ9Mc3xzP6MDkYmNl6PVYYaoEqnP dwTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="hH/KXPxd"; 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=fail (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 z63si15894538ybf.99.2021.01.24.10.13.24 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 24 Jan 2021 10:13:24 -0800 (PST) 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=fail header.i=@linaro.org header.s=google header.b="hH/KXPxd"; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:37490 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l3jt5-0006hJ-Rd for patch@linaro.org; Sun, 24 Jan 2021 13:13:23 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47274) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l3jrH-0003xW-Mv for qemu-devel@nongnu.org; Sun, 24 Jan 2021 13:11:31 -0500 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]:38542) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l3jrE-0003V7-Tn for qemu-devel@nongnu.org; Sun, 24 Jan 2021 13:11:31 -0500 Received: by mail-pf1-x42f.google.com with SMTP id y205so7080126pfc.5 for ; Sun, 24 Jan 2021 10:11:28 -0800 (PST) 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=dMC8pDMFrpkWp3tIhJXkAEfl2zqGr88OycytaS5rwLg=; b=hH/KXPxdKSgAD/tYpJeXA0UWa8OV7d1F4bepKLOCftPs/c7QITLMeHDx7dLQIOtN14 2mraEeb6tdM/RaSFm68AwSBxzJrR+a1H++2V8wxHq0zXQ6dMrtoiDlsq/MIo6Ebe3uBN uCL077i6+h8qoEfFiboAZsOwwlx8nCX9yqhvg7jIgLtW31vJ/yzAAERWQL8DIKbvzipq 4EFiVv+6GM7i+sn0gVJKoWq7QJ/fiJC4HQ7hYe1eRyR/GSoknCliMQ09/8LPzMKXNf3+ EoDW/YSzWV8aBRbG3pXWrD0TMOx+aqERUAgoC8Eve6ULG/oAQ4fAx9KW5v4/K1A5RyG+ y99Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dMC8pDMFrpkWp3tIhJXkAEfl2zqGr88OycytaS5rwLg=; b=kxkz2e6JQlX/zOBghd1H7PcBObhff+qNPaSlT9p0MJ8mM9aBcZOm1gM4at/9pmRG9E 5z6KFHZsaDB7BFyYAta7PJCHXs4t0N2f6XHS+rXo1PsRxyTGlb3xfI7zIj+kQXub6ne5 IakRxKrtUn/9VgEe6p+k8lG64R/IC+LPjvL5V1hcTCVvALjGurTS48CZTnvr34Yyj9OE iaMZrwHknJj7+MPzdmj+95NRkhHv2fWQZ9UumjObKwuqXthDli8UdKJRc+9A8lqb7h9y RnczljrQgu7ALqgGU2oN6ZJpns5q/3LNP3j1DoAm/iPP0dTX64MUynFo7hD+XdRpmBjB /p4g== X-Gm-Message-State: AOAM532EexnXlNCmxjfgWJf4we7BbIbv7rP89kkz2oESoEhUhM+zmatn XpFaA4mbhlvuGsWysOFZfuX9kghBUkYvpw== X-Received: by 2002:a65:6450:: with SMTP id s16mr1246781pgv.71.1611511887571; Sun, 24 Jan 2021 10:11:27 -0800 (PST) Received: from localhost.localdomain (cpe-66-27-222-29.hawaii.res.rr.com. [66.27.222.29]) by smtp.gmail.com with ESMTPSA id 123sm14547629pgf.38.2021.01.24.10.11.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Jan 2021 10:11:27 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL v2 10/10] tcg: Restart code generation when we run out of temps Date: Sun, 24 Jan 2021 08:11:22 -1000 Message-Id: <20210124181122.5447-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210124181122.5447-1-richard.henderson@linaro.org> References: <20210124181122.5447-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42f; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42f.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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Some large translation blocks can generate so many unique constants that we run out of temps to hold them. In this case, longjmp back to the start of code generation and restart with a smaller translation block. Buglink: https://bugs.launchpad.net/bugs/1912065 Tested-by: BALATON Zoltan Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- include/tcg/tcg.h | 3 +++ accel/tcg/translate-all.c | 15 ++++++++++++++- tcg/tcg.c | 11 ++++++++--- 3 files changed, 25 insertions(+), 4 deletions(-) -- 2.25.1 Tested-by: Roman Bolshakov diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h index c5a9d65d5f..0f0695e90d 100644 --- a/include/tcg/tcg.h +++ b/include/tcg/tcg.h @@ -680,6 +680,9 @@ struct TCGContext { uint16_t gen_insn_end_off[TCG_MAX_INSNS]; target_ulong gen_insn_data[TCG_MAX_INSNS][TARGET_INSN_START_WORDS]; + + /* Exit to translator on overflow. */ + sigjmp_buf jmp_trans; }; static inline bool temp_readonly(TCGTemp *ts) diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index d09c187e0f..81d4c83f22 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1926,11 +1926,17 @@ TranslationBlock *tb_gen_code(CPUState *cpu, ti = profile_getclock(); #endif + gen_code_size = sigsetjmp(tcg_ctx->jmp_trans, 0); + if (unlikely(gen_code_size != 0)) { + goto error_return; + } + tcg_func_start(tcg_ctx); tcg_ctx->cpu = env_cpu(env); gen_intermediate_code(cpu, tb, max_insns); tcg_ctx->cpu = NULL; + max_insns = tb->icount; trace_translate_block(tb, tb->pc, tb->tc.ptr); @@ -1955,6 +1961,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu, gen_code_size = tcg_gen_code(tcg_ctx, tb); if (unlikely(gen_code_size < 0)) { + error_return: switch (gen_code_size) { case -1: /* @@ -1966,6 +1973,9 @@ TranslationBlock *tb_gen_code(CPUState *cpu, * flush the TBs, allocate a new TB, re-initialize it per * above, and re-do the actual code generation. */ + qemu_log_mask(CPU_LOG_TB_OP | CPU_LOG_TB_OP_OPT, + "Restarting code generation for " + "code_gen_buffer overflow\n"); goto buffer_overflow; case -2: @@ -1978,9 +1988,12 @@ TranslationBlock *tb_gen_code(CPUState *cpu, * Try again with half as many insns as we attempted this time. * If a single insn overflows, there's a bug somewhere... */ - max_insns = tb->icount; assert(max_insns > 1); max_insns /= 2; + qemu_log_mask(CPU_LOG_TB_OP | CPU_LOG_TB_OP_OPT, + "Restarting code generation with " + "smaller translation block (max %d insns)\n", + max_insns); goto tb_overflow; default: diff --git a/tcg/tcg.c b/tcg/tcg.c index 67b08f708d..9e1b0d73c7 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -1205,18 +1205,23 @@ void tcg_func_start(TCGContext *s) QSIMPLEQ_INIT(&s->labels); } -static inline TCGTemp *tcg_temp_alloc(TCGContext *s) +static TCGTemp *tcg_temp_alloc(TCGContext *s) { int n = s->nb_temps++; - tcg_debug_assert(n < TCG_MAX_TEMPS); + + if (n >= TCG_MAX_TEMPS) { + /* Signal overflow, starting over with fewer guest insns. */ + siglongjmp(s->jmp_trans, -2); + } return memset(&s->temps[n], 0, sizeof(TCGTemp)); } -static inline TCGTemp *tcg_global_alloc(TCGContext *s) +static TCGTemp *tcg_global_alloc(TCGContext *s) { TCGTemp *ts; tcg_debug_assert(s->nb_globals == s->nb_temps); + tcg_debug_assert(s->nb_globals < TCG_MAX_TEMPS); s->nb_globals++; ts = tcg_temp_alloc(s); ts->kind = TEMP_GLOBAL;