From patchwork Thu Dec 12 20:48:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 849758 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:2c4:b0:385:e875:8a9e with SMTP id o4csp1152872wry; Thu, 12 Dec 2024 12:49:44 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCV8RO7+/TfZTQPOvlFEEGdDFi5sA684dsQ1pTFiGZDo42newd6pOzDUZOCyphZh7O402YVVxg==@linaro.org X-Google-Smtp-Source: AGHT+IHgTNBgR5rUrvIejTFos7a8f9Krt3LGdYjh7AeovBNePNEdd+BEu7kERtwKWjMyS6K9DJBA X-Received: by 2002:a05:622a:15c2:b0:467:5cfb:bd3c with SMTP id d75a77b69052e-467a14faa10mr28525411cf.20.1734036584615; Thu, 12 Dec 2024 12:49:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1734036584; cv=none; d=google.com; s=arc-20240605; b=bXLswm0K/rkaSSKtqoHq4+vaE2f4fEz++bZmY1HHN3kMQRNkK8bKNvAsDcwhNiQy0f S178ph+UysuGZswa0GfDSN7pn01l+lQ99Z3k9FIb5kqBqTB94HPGJADVIhgQKUG4QMIO Lww7hxUR/Xlhx60vn1clpAZiezNKISvlJwD9vDoav8W70iGZEE8izBIy8Dp+rdEIAeIe Ak10WtCVmh0QQz0SrR8/5FFtbzUB3YHp6u0q1D2IvDKiHzcFwgLImBX6HYrzi+ZyId3h CEiHy0rFfC81NklQRpXIJ19vTDaDj4OGysJJ0WGgynxT3M1wPSl+yY3AE0VTpNLzZpIs k3oA== 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:dkim-signature; bh=fg83bkK5yDHZA4CF6jEqCNLgZcxdUb+0IUzm0zJzq60=; fh=8RutQBzlcaWsmwfP8TvxyxVvuXre/9bJZ+VgDzur4BI=; b=GiMUygWgB9ASbfnso/dxkM2UBG8Ky+tFcR4s0LequqM5aUT45/p0uzIIshEZ8MDWsS S0/m6nBzBKicyFGp6ol0ql7gfj6yfSCxWDg9ETckaFNNLbqoAuGYTDVclIclMy8XtDAw P3jousYZhbaRT8BDlIjbxb6QpnD2SHgxujHic5XM1/vt7IY2ZVw9zDK8ImxDJ69qt+qB OvhDXLOETtS0rhSvG8yoHdhTk0w7SfXLNH0iPqICQXlgg1CaJC3QF9kKltlVpXSzfW+3 Ea0zvy6lBV7TDsWb8y2sbIplgX7BSjkovOGiSGCnpLfT+L09GMhtaLXXz0oxK/mH6xY5 PmhA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Wi/S21Ps"; 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; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-46792595f40si23559401cf.140.2024.12.12.12.49.44 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 12 Dec 2024 12:49:44 -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=pass header.i=@linaro.org header.s=google header.b="Wi/S21Ps"; 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; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLq6w-0003gw-Vw; Thu, 12 Dec 2024 15:48:39 -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 1tLq6o-0003en-V9 for qemu-devel@nongnu.org; Thu, 12 Dec 2024 15:48:32 -0500 Received: from mail-ot1-x32e.google.com ([2607:f8b0:4864:20::32e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tLq6l-0000w1-6y for qemu-devel@nongnu.org; Thu, 12 Dec 2024 15:48:30 -0500 Received: by mail-ot1-x32e.google.com with SMTP id 46e09a7af769-71e3284f963so413287a34.1 for ; Thu, 12 Dec 2024 12:48:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1734036502; x=1734641302; darn=nongnu.org; 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=fg83bkK5yDHZA4CF6jEqCNLgZcxdUb+0IUzm0zJzq60=; b=Wi/S21PsJjaRbkIyxd8x6B0bFcf8oraokP/GlkXAin1rSI5sw7cxH9x2hpLgpOtk3t c2GKFWo43x/WiqoFssKlu2vKHAlRqJyqzPzWnYztNx5+Mg2/t16hxK65LICONyXkdvYB lVZ7DkWvbJm/MmHhTqA06FAMBTUAUiIb6IPOKH5oDF0Xo3LvD5WZ0rbl3CFlT78C7YII 7meZjS/Jr5O5hU9W97s9Vy5aLsw0irE/eMG2jS4YUrBwF5zo7oNI8KKUKCo1w+2SgK6X YlsvdCI4bBLvxHi6GE1mpR3S3dEOJkarOxY1S/CXl+IhipSzbzUrhX41RiGRF0faZc+y 5exQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734036502; x=1734641302; 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=fg83bkK5yDHZA4CF6jEqCNLgZcxdUb+0IUzm0zJzq60=; b=VgmDh4nFosfWng07Rbvux5HMCHbG9QwOvBEbUk5cz1ddF0ZR5FWmYiXg21opNGWDp3 GZf+iItH2XoBCq8XxioeJLNHC228C8ZWgqReRnok5qAQ+cUeIvM1ufOkfkpf7KU77C3u SofYXYKcsinF4IwB9oM6kAMrsY54odE/SKM9YOvqFuD3wDj4JbAY4ySP4fD9v+834MFd Nbc53GRBBzN88JlhZHo93eWVnNNETlNawwSpy7DpghrZ2SC8mErhmjjkvZxGCkUiXRm3 RKKcqlZRBoOON1N9IbmGAqYwsy8xZnCfhea0Al4Qiicv3LndruAreTmtraPIDNYJz7+Y R7qw== X-Gm-Message-State: AOJu0YxkAiuyk7r/xA0Eo46vdI4DPqUrzqP+ny4Lx+bfdLp9tzfuFW56 lauurXkvmmts2EoK47MC3ROfMjCoDZ11ADxcSQslfaEpbsPCC+6iCoQkLecXbDmFZfMfIHNANIF oahp+QuMO X-Gm-Gg: ASbGncu8GhdrwrTX0keuRZiEuMRcOQ4aq11RDXG4PJrrvRtu3RlFCV6BzkXfgCVOQfB SG2TAi3pr/GBgKkf69MF2af1j+BJSgnTG+Dnmz3869RspeOg+hpxgI1pm1K/gVhj4AeKrQy03yV YD78P6AE7LxLkUBqRFOY8l3GUrsa1SCH6vc4Q11HEprSjSH/IDXZ9Oo1IVS3+rBE8wAtTVZP7Xa qqL7H2Aulg90iU7uB6Yf8UFFfNHofJr7Rwki3kMlE+tvVyJ8nGxk+gaE8paWt/E X-Received: by 2002:a05:6830:3116:b0:718:6cc:b5a2 with SMTP id 46e09a7af769-71e370bec7bmr1074023a34.20.1734036502447; Thu, 12 Dec 2024 12:48:22 -0800 (PST) Received: from stoup.. ([187.217.227.247]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5f2b8197b58sm2129758eaf.12.2024.12.12.12.48.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Dec 2024 12:48:21 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, wannacu , Pierrick Bouvier , =?utf-8?q?Philippe_Mathieu-?= =?utf-8?q?Daud=C3=A9?= Subject: [PULL 1/4] tcg: Reset free_temps before tcg_optimize Date: Thu, 12 Dec 2024 14:48:15 -0600 Message-ID: <20241212204818.2468583-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241212204818.2468583-1-richard.henderson@linaro.org> References: <20241212204818.2468583-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::32e; envelope-from=richard.henderson@linaro.org; helo=mail-ot1-x32e.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=unavailable 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 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é --- include/tcg/tcg-temp-internal.h | 6 ++++++ accel/tcg/plugin-gen.c | 2 +- tcg/tcg.c | 5 ++++- 3 files changed, 11 insertions(+), 2 deletions(-) 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/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/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);