From nobody Sun Feb 8 17:21:55 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=bupt.edu.cn Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1625409238714663.2345280954968; Sun, 4 Jul 2021 07:33:58 -0700 (PDT) Received: from localhost ([::1]:42226 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m03C1-0008Gm-Nt for importer@patchew.org; Sun, 04 Jul 2021 10:33:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39142) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m03Ao-0006Bk-VT for qemu-devel@nongnu.org; Sun, 04 Jul 2021 10:32:43 -0400 Received: from smtpbgjp3.qq.com ([54.92.39.34]:59027) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m03Al-0008UR-CG for qemu-devel@nongnu.org; Sun, 04 Jul 2021 10:32:42 -0400 Received: from Wei.localdomain (unknown [223.72.88.167]) by esmtp6.qq.com (ESMTP) with id ; Sun, 04 Jul 2021 22:31:30 +0800 (CST) X-QQ-mid: bizesmtp54t1625409091tknzzoxm X-QQ-SSF: 0140000000200080X000000B0000000 X-QQ-FEAT: g9nl15ZGxljvewZdWj6FQFzWCm4Pl6WDlpwqL4gpWE2YfJor5fUESGng+FQ97 wU0hxUsDCYD2xTdap4PZpBivqkC97+uwf8Dc/n/hOe/FIo2qx9d5W8E3vyhquQKbWRPGs3z GGryo6qJbaGwC9RKEMxvZpAYe7JPKCQI9v2SJ+jREZwyL2Q0nly5v3BLG9BH/oUfTNgxrQU d/suYdsb8scd6IMhaGCKITuLRsGCa+tVuip+qw3oIDI4w3ieNXgHxI4K39CVOTkaC2TEyjk LyvivdH7qAjaaMbS8Oablu4aItFlpmCgAfvHG20aZSFze9yNFabYI9fEE/FCRONWdcEMwKZ u+5BLEKe9uhv4QX4r1iT3RI7Vk7t78OAG1YqdtKUWCYrAzN5Iw= X-QQ-GoodBg: 2 From: Liren Wei To: qemu-devel@nongnu.org Subject: [PATCH 1/2] accel/tcg: Hoist tcg_tb_insert() up above tb_link_page() Date: Sun, 4 Jul 2021 22:31:26 +0800 Message-Id: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:bupt.edu.cn:qybgforeign:qybgforeign7 X-QQ-Bgrelay: 1 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=54.92.39.34; envelope-from=lrwei@bupt.edu.cn; helo=smtpbgjp3.qq.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_PASS=-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: pbonzini@redhat.com, richard.henderson@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1625409240602100001 Content-Type: text/plain; charset="utf-8" TranslationBlocks not inserted into the corresponding region tree shall be regarded as partially initialized objects, and needs to be finalized first before inserting into QHT. Signed-off-by: Liren Wei --- accel/tcg/translate-all.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 7929a7e320..75e4d06557 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1657,6 +1657,13 @@ TranslationBlock *tb_gen_code(CPUState *cpu, return tb; } =20 + /* + * Insert TB into the corresponding region tree before publishing it + * through QHT. Otherwise rewinding happened in the TB might fail to + * lookup itself using host PC. + */ + tcg_tb_insert(tb); + /* check next page if needed */ virt_page2 =3D (pc + tb->size - 1) & TARGET_PAGE_MASK; phys_page2 =3D -1; @@ -1675,9 +1682,9 @@ TranslationBlock *tb_gen_code(CPUState *cpu, orig_aligned -=3D ROUND_UP(sizeof(*tb), qemu_icache_linesize); qatomic_set(&tcg_ctx->code_gen_ptr, (void *)orig_aligned); tb_destroy(tb); + tcg_tb_remove(tb); return existing_tb; } - tcg_tb_insert(tb); return tb; } =20 --=20 2.32.0 From nobody Sun Feb 8 17:21:55 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=bupt.edu.cn Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1625409179115903.1752330643797; Sun, 4 Jul 2021 07:32:59 -0700 (PDT) Received: from localhost ([::1]:38946 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m03B4-00066j-5O for importer@patchew.org; Sun, 04 Jul 2021 10:32:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39008) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m039z-0004jK-I3 for qemu-devel@nongnu.org; Sun, 04 Jul 2021 10:31:51 -0400 Received: from smtpbg501.qq.com ([203.205.250.101]:51185) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m039u-0007wN-OB for qemu-devel@nongnu.org; Sun, 04 Jul 2021 10:31:51 -0400 Received: from Wei.localdomain (unknown [223.72.88.167]) by esmtp6.qq.com (ESMTP) with id ; Sun, 04 Jul 2021 22:31:32 +0800 (CST) X-QQ-mid: bizesmtp54t1625409093t92jabvk X-QQ-SSF: 0140000000200080X000000B0000000 X-QQ-FEAT: XIEqvPtYnoGcaq8NZPcWIxqtaNsepyhiy3cxxd0rKvKSPUWdTTOWK4IWpZaWN E1+1URnBPZHB3dXaVH7jgtafKPqnopOb+SZIVRiXJwk6yd1FdQs0T0jZCvEbCEgxJL2kvxi Pob11GWSOlDBGFN/OfxPq44kqEhIZHaZkXKSjnZXO3juR+NR6rK5tYQcu1kmKTN+X7+AlYf Lj/S66w1fRRxFIstTUWK1LseNwYEk0NN7Yy3kjYhwPW5lR83km6VpzJ/n0M4XdjlWXTEs2a gODVBjhWlG/q53ydp3XXJoHU7rxaKhw9JwAQlS0b6xpyjkCjZq8SrypaOEQpe9MR5z2LL4C 0PXiK5KhznNCw77MHjnGGGPVN54fRowtkU4UHcs1SDnqwH09x4= X-QQ-GoodBg: 2 From: Liren Wei To: qemu-devel@nongnu.org Subject: [PATCH 2/2] tcg: Bake tb_destroy() into tcg_region_tree Date: Sun, 4 Jul 2021 22:31:27 +0800 Message-Id: <8dc352f08d038c4e7a1f5f56962398cdc700c3aa.1625404483.git.lrwei@bupt.edu.cn> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:bupt.edu.cn:qybgforeign:qybgforeign6 X-QQ-Bgrelay: 1 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=203.205.250.101; envelope-from=lrwei@bupt.edu.cn; helo=smtpbg501.qq.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, 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: pbonzini@redhat.com, richard.henderson@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1625409180694100003 Content-Type: text/plain; charset="utf-8" The function is called only at tcg_gen_code() when duplicated TBs are translated by different threads, and when the tcg_region_tree is reset. Bake it into the underlying GTree as its value destroy function to unite these situations. Also remove tcg_region_tree_traverse() which now becomes useless. Signed-off-by: Liren Wei --- accel/tcg/translate-all.c | 6 ------ include/tcg/tcg.h | 1 - tcg/region.c | 18 +++++++----------- 3 files changed, 7 insertions(+), 18 deletions(-) diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 75e4d06557..57455d8639 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -378,11 +378,6 @@ static int cpu_restore_state_from_tb(CPUState *cpu, Tr= anslationBlock *tb, return 0; } =20 -void tb_destroy(TranslationBlock *tb) -{ - qemu_spin_destroy(&tb->jmp_lock); -} - bool cpu_restore_state(CPUState *cpu, uintptr_t host_pc, bool will_exit) { /* @@ -1681,7 +1676,6 @@ TranslationBlock *tb_gen_code(CPUState *cpu, =20 orig_aligned -=3D ROUND_UP(sizeof(*tb), qemu_icache_linesize); qatomic_set(&tcg_ctx->code_gen_ptr, (void *)orig_aligned); - tb_destroy(tb); tcg_tb_remove(tb); return existing_tb; } diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h index 899493701c..dedb86939a 100644 --- a/include/tcg/tcg.h +++ b/include/tcg/tcg.h @@ -808,7 +808,6 @@ void *tcg_malloc_internal(TCGContext *s, int size); void tcg_pool_reset(TCGContext *s); TranslationBlock *tcg_tb_alloc(TCGContext *s); =20 -void tb_destroy(TranslationBlock *tb); void tcg_region_reset_all(void); =20 size_t tcg_code_size(void); diff --git a/tcg/region.c b/tcg/region.c index 00b0c3b091..956a5ae483 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -112,7 +112,7 @@ static int ptr_cmp_tb_tc(const void *ptr, const struct = tb_tc *s) return 0; } =20 -static gint tb_tc_cmp(gconstpointer ap, gconstpointer bp) +static gint tb_tc_cmp(gconstpointer ap, gconstpointer bp, gpointer _) { const struct tb_tc *a =3D ap; const struct tb_tc *b =3D bp; @@ -143,6 +143,11 @@ static gint tb_tc_cmp(gconstpointer ap, gconstpointer = bp) return ptr_cmp_tb_tc(b->ptr, a); } =20 +static void tb_destroy(gpointer tb) +{ + qemu_spin_destroy(&((TranslationBlock *) tb)->jmp_lock); +} + static void tcg_region_trees_init(void) { size_t i; @@ -153,7 +158,7 @@ static void tcg_region_trees_init(void) struct tcg_region_tree *rt =3D region_trees + i * tree_size; =20 qemu_mutex_init(&rt->lock); - rt->tree =3D g_tree_new(tb_tc_cmp); + rt->tree =3D g_tree_new_full(tb_tc_cmp, NULL, NULL, tb_destroy); } } =20 @@ -277,14 +282,6 @@ size_t tcg_nb_tbs(void) return nb_tbs; } =20 -static gboolean tcg_region_tree_traverse(gpointer k, gpointer v, gpointer = data) -{ - TranslationBlock *tb =3D v; - - tb_destroy(tb); - return FALSE; -} - static void tcg_region_tree_reset_all(void) { size_t i; @@ -293,7 +290,6 @@ static void tcg_region_tree_reset_all(void) for (i =3D 0; i < region.n; i++) { struct tcg_region_tree *rt =3D region_trees + i * tree_size; =20 - g_tree_foreach(rt->tree, tcg_region_tree_traverse, NULL); /* Increment the refcount first so that destroy acts as a reset */ g_tree_ref(rt->tree); g_tree_destroy(rt->tree); --=20 2.32.0