From patchwork Mon Jan 27 14:17:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 860264 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:18c8:b0:385:e875:8a9e with SMTP id w8csp2044602wrq; Mon, 27 Jan 2025 06:26:48 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVk+mG5qgDaSpsX7768T9JiAgAwZM4S2oOVPOMzNvS4lUldbbJhVmj3IPAd/uSW3AzejcAGxA==@linaro.org X-Google-Smtp-Source: AGHT+IHgBSW0hpD8zhPD6gxUBja/3TV0/vlF3r7tYsbVOH1foHN0CnaFzx7ez+LGb7HelXrzbL1O X-Received: by 2002:a05:6214:ca9:b0:6d8:ad28:adbf with SMTP id 6a1803df08f44-6e1b21a0c5fmr604311586d6.20.1737988007837; Mon, 27 Jan 2025 06:26:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1737988007; cv=none; d=google.com; s=arc-20240605; b=QWdJZ48DFpdCMH35Hcn16lsBH/OAdtaH6B4Jr0TY4c0/UmxT7Sylyupqh24ZdrlmOG T1c/Yo7tG7PUy8y2rBi89sfHQ7Y5P23TpKZ3SNGTNBF33HQjAUqIp2sEz1j8letU6Bwz rtdOU0mtImyFIplZXQ7Zb7SwdpJ+BH9XfIkT9iDMiz+YXjTorjpznWvdOSUg2dNjANFy ooptkJ4qVrpYvbJJIs89Cgm7GSXC3nuuzhtqxI38G2lVh7VO6dYUo6hcgEdOVfHoEJGF H4/TeUvyq/DFtk9pJvxLA9Jq+pMI9/bwFMBeZ4xhfD/+/ZvE2pc63Aprb6PoU05L4pHy tfjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to: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; bh=XCEFpe4Ue760/IPZuqwjqpZVx5VdQa70mRKgKJi6lxQ=; fh=pf+ec3LEfrqMT+5gdCXHweMh6LzvAi5DC66/0Pko6EE=; b=BC/LWusSN/1YZ+Jd3p9G1XJZXQVIC26sAvdZULdoeypq8H9oF5YkaRt2O6KgzzdJe3 g9Nw49fZiN/+hYg5d6ylwOaThkhQS4wsEmD9Y6p3YQLiulsCk8A6J72HoNJyl1MSSv7Z iHsSIwXFcMnglcpnFxQTUe6mFL9uC0u6yW/BMaVrG1z1XlmTmj58KbnbEtwQfJ/RjZA7 1tSFZ04pRMQtZNM0duV8S1nv68V4bX9z+x6Xy3o6x5nzEoK6RpAFRB++AxnfcOYbHxC6 RM2sF7D76VrNINT1mcJXXBDD339RvczvH4NgrEF00mwrMyhd/6TOzeobjglegZMUHSN1 yfng==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; 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" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 6a1803df08f44-6e20525e381si99810636d6.82.2025.01.27.06.26.47 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Jan 2025 06:26:47 -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; 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" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tcQ2y-00047F-Ku; Mon, 27 Jan 2025 09:25:10 -0500 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 1tcQ2d-0003S8-J6; Mon, 27 Jan 2025 09:24:43 -0500 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tcQ2b-00031S-MW; Mon, 27 Jan 2025 09:24:43 -0500 Received: from localhost.tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by isrv.corpit.ru (Postfix) with ESMTP id 5269AE0F71; Mon, 27 Jan 2025 17:24:11 +0300 (MSK) Received: by localhost.tls.msk.ru (Postfix, from userid 1000) id 5E85951D61; Mon, 27 Jan 2025 17:18:03 +0300 (MSK) From: Michael Tokarev To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Richard Henderson , wannacu , Pierrick Bouvier , =?utf-8?q?Philippe_Mathieu-?= =?utf-8?q?Daud=C3=A9?= , Michael Tokarev Subject: [Stable-9.2.1 02/41] tcg: Reset free_temps before tcg_optimize Date: Mon, 27 Jan 2025 17:17:16 +0300 Message-Id: <20250127141803.3514882-2-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.5 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Richard Henderson When allocating new temps during tcg_optmize, do not re-use any EBB temps that were used within the TB. We do not have any idea what span of the TB in which the temp was live. Introduce tcg_temp_ebb_reset_freed and use before tcg_optimize, as well as replacing the equivalent in plugin_gen_inject and tcg_func_start. Cc: qemu-stable@nongnu.org Fixes: fb04ab7ddd8 ("tcg/optimize: Lower TCG_COND_TST{EQ,NE} if unsupported") Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2711 Reported-by: wannacu Signed-off-by: Richard Henderson Reviewed-by: Pierrick Bouvier Reviewed-by: Philippe Mathieu-Daudé (cherry picked from commit 04e006ab36a8565b92d4e21dd346367fbade7d74) Signed-off-by: Michael Tokarev diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c index 0f47bfbb48..1ef075552c 100644 --- a/accel/tcg/plugin-gen.c +++ b/accel/tcg/plugin-gen.c @@ -275,7 +275,7 @@ static void plugin_gen_inject(struct qemu_plugin_tb *plugin_tb) * that might be live within the existing opcode stream. * The simplest solution is to release them all and create new. */ - memset(tcg_ctx->free_temps, 0, sizeof(tcg_ctx->free_temps)); + tcg_temp_ebb_reset_freed(tcg_ctx); QTAILQ_FOREACH_SAFE(op, &tcg_ctx->ops, link, next) { switch (op->opc) { diff --git a/include/tcg/tcg-temp-internal.h b/include/tcg/tcg-temp-internal.h index 44192c55a9..98f91e68b7 100644 --- a/include/tcg/tcg-temp-internal.h +++ b/include/tcg/tcg-temp-internal.h @@ -42,4 +42,10 @@ TCGv_i64 tcg_temp_ebb_new_i64(void); TCGv_ptr tcg_temp_ebb_new_ptr(void); TCGv_i128 tcg_temp_ebb_new_i128(void); +/* Forget all freed EBB temps, so that new allocations produce new temps. */ +static inline void tcg_temp_ebb_reset_freed(TCGContext *s) +{ + memset(s->free_temps, 0, sizeof(s->free_temps)); +} + #endif /* TCG_TEMP_FREE_H */ diff --git a/tcg/tcg.c b/tcg/tcg.c index 0babae1b88..4578b185be 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -1489,7 +1489,7 @@ void tcg_func_start(TCGContext *s) s->nb_temps = s->nb_globals; /* No temps have been previously allocated for size or locality. */ - memset(s->free_temps, 0, sizeof(s->free_temps)); + tcg_temp_ebb_reset_freed(s); /* No constant temps have been previously allocated. */ for (int i = 0; i < TCG_TYPE_COUNT; ++i) { @@ -6120,6 +6120,9 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb, uint64_t pc_start) } #endif + /* Do not reuse any EBB that may be allocated within the TB. */ + tcg_temp_ebb_reset_freed(s); + tcg_optimize(s); reachable_code_pass(s);