From nobody Sat Sep 6 14:41:22 2025 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1756889403922631.0995151760899; Wed, 3 Sep 2025 01:50:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1utjAV-0003IS-N8; Wed, 03 Sep 2025 04:48:39 -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 1utjAT-0003Hu-9k for qemu-devel@nongnu.org; Wed, 03 Sep 2025 04:48:37 -0400 Received: from mail.loongson.cn ([114.242.206.163]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1utjAR-0007Mj-6S for qemu-devel@nongnu.org; Wed, 03 Sep 2025 04:48:36 -0400 Received: from loongson.cn (unknown [10.2.5.213]) by gateway (Coremail) with SMTP id _____8DxudHdALhoHCcGAA--.12861S3; Wed, 03 Sep 2025 16:48:29 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.213]) by front1 (Coremail) with SMTP id qMiowJDxbMHcALhoc916AA--.5293S3; Wed, 03 Sep 2025 16:48:29 +0800 (CST) From: Bibo Mao To: Song Gao , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: Jiaxun Yang , qemu-devel@nongnu.org Subject: [PATCH v3 01/12] target/loongarch: Use mmu idx bitmap method when flush TLB Date: Wed, 3 Sep 2025 16:48:16 +0800 Message-Id: <20250903084827.3085911-2-maobibo@loongson.cn> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20250903084827.3085911-1-maobibo@loongson.cn> References: <20250903084827.3085911-1-maobibo@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: qMiowJDxbMHcALhoc916AA--.5293S3 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== 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=114.242.206.163; envelope-from=maobibo@loongson.cn; helo=mail.loongson.cn 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_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1756889406911124100 Content-Type: text/plain; charset="utf-8" With API tlb_flush_range_by_mmuidx(), bitmap of mmu idx should be used rather than itself. Also MMU_KERNEL_IDX and MMU_USER_IDX are used rather than current running mmu idx when flush TLB. Signed-off-by: Bibo Mao Reviewed-by: Richard Henderson --- target/loongarch/tcg/tlb_helper.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/target/loongarch/tcg/tlb_helper.c b/target/loongarch/tcg/tlb_h= elper.c index 9365860c8c..d58f447555 100644 --- a/target/loongarch/tcg/tlb_helper.c +++ b/target/loongarch/tcg/tlb_helper.c @@ -101,8 +101,7 @@ static void invalidate_tlb_entry(CPULoongArchState *env= , int index) target_ulong addr, mask, pagesize; uint8_t tlb_ps; LoongArchTLB *tlb =3D &env->tlb[index]; - - int mmu_idx =3D cpu_mmu_index(env_cpu(env), false); + int mmu_idx =3D BIT(MMU_KERNEL_IDX) | BIT(MMU_USER_IDX); uint8_t tlb_v0 =3D FIELD_EX64(tlb->tlb_entry0, TLBENTRY, V); uint8_t tlb_v1 =3D FIELD_EX64(tlb->tlb_entry1, TLBENTRY, V); uint64_t tlb_vppn =3D FIELD_EX64(tlb->tlb_misc, TLB_MISC, VPPN); --=20 2.39.3 From nobody Sat Sep 6 14:41:22 2025 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1756889404939114.91945980141611; Wed, 3 Sep 2025 01:50:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1utjAX-0003Jr-CH; Wed, 03 Sep 2025 04:48:41 -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 1utjAV-0003IZ-9d for qemu-devel@nongnu.org; Wed, 03 Sep 2025 04:48:39 -0400 Received: from mail.loongson.cn ([114.242.206.163]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1utjAT-0007Mv-9X for qemu-devel@nongnu.org; Wed, 03 Sep 2025 04:48:39 -0400 Received: from loongson.cn (unknown [10.2.5.213]) by gateway (Coremail) with SMTP id _____8AxSNHjALhoIScGAA--.12960S3; Wed, 03 Sep 2025 16:48:35 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.213]) by front1 (Coremail) with SMTP id qMiowJDxbMHcALhoc916AA--.5293S4; Wed, 03 Sep 2025 16:48:34 +0800 (CST) From: Bibo Mao To: Song Gao , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: Jiaxun Yang , qemu-devel@nongnu.org Subject: [PATCH v3 02/12] target/loongarch: Add parameter tlb pointer with fill_tlb_entry Date: Wed, 3 Sep 2025 16:48:17 +0800 Message-Id: <20250903084827.3085911-3-maobibo@loongson.cn> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20250903084827.3085911-1-maobibo@loongson.cn> References: <20250903084827.3085911-1-maobibo@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: qMiowJDxbMHcALhoc916AA--.5293S4 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== 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=114.242.206.163; envelope-from=maobibo@loongson.cn; helo=mail.loongson.cn 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_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1756889406003116600 Content-Type: text/plain; charset="utf-8" With function fill_tlb_entry(), it will update LoongArch emulated TLB information. Here parameter tlb pointer is added so that TLB entry will be updated based on relative TLB CSR registers. Signed-off-by: Bibo Mao Reviewed-by: Richard Henderson --- target/loongarch/tcg/tlb_helper.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/target/loongarch/tcg/tlb_helper.c b/target/loongarch/tcg/tlb_h= elper.c index d58f447555..fcd03ca320 100644 --- a/target/loongarch/tcg/tlb_helper.c +++ b/target/loongarch/tcg/tlb_helper.c @@ -143,9 +143,8 @@ static void invalidate_tlb(CPULoongArchState *env, int = index) invalidate_tlb_entry(env, index); } =20 -static void fill_tlb_entry(CPULoongArchState *env, int index) +static void fill_tlb_entry(CPULoongArchState *env, LoongArchTLB *tlb) { - LoongArchTLB *tlb =3D &env->tlb[index]; uint64_t lo0, lo1, csr_vppn; uint16_t csr_asid; uint8_t csr_ps; @@ -312,7 +311,7 @@ void helper_tlbwr(CPULoongArchState *env) return; } =20 - fill_tlb_entry(env, index); + fill_tlb_entry(env, env->tlb + index); } =20 void helper_tlbfill(CPULoongArchState *env) @@ -350,7 +349,7 @@ void helper_tlbfill(CPULoongArchState *env) } =20 invalidate_tlb(env, index); - fill_tlb_entry(env, index); + fill_tlb_entry(env, env->tlb + index); } =20 void helper_tlbclr(CPULoongArchState *env) --=20 2.39.3 From nobody Sat Sep 6 14:41:22 2025 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 175688939340515.013997355158267; Wed, 3 Sep 2025 01:49:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1utjAY-0003Kr-C1; Wed, 03 Sep 2025 04:48:42 -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 1utjAW-0003J9-IE for qemu-devel@nongnu.org; Wed, 03 Sep 2025 04:48:40 -0400 Received: from mail.loongson.cn ([114.242.206.163]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1utjAT-0007N6-V8 for qemu-devel@nongnu.org; Wed, 03 Sep 2025 04:48:40 -0400 Received: from loongson.cn (unknown [10.2.5.213]) by gateway (Coremail) with SMTP id _____8Bx1tDjALhoJCcGAA--.12852S3; Wed, 03 Sep 2025 16:48:35 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.213]) by front1 (Coremail) with SMTP id qMiowJDxbMHcALhoc916AA--.5293S5; Wed, 03 Sep 2025 16:48:34 +0800 (CST) From: Bibo Mao To: Song Gao , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: Jiaxun Yang , qemu-devel@nongnu.org Subject: [PATCH v3 03/12] target/loongarch: Reduce TLB flush with helper_tlbwr Date: Wed, 3 Sep 2025 16:48:18 +0800 Message-Id: <20250903084827.3085911-4-maobibo@loongson.cn> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20250903084827.3085911-1-maobibo@loongson.cn> References: <20250903084827.3085911-1-maobibo@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: qMiowJDxbMHcALhoc916AA--.5293S5 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== 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=114.242.206.163; envelope-from=maobibo@loongson.cn; helo=mail.loongson.cn 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_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1756889394050116600 Content-Type: text/plain; charset="utf-8" With function helper_tlbwr(), specified LoongArch TLB entry will be updated. There are two PTE pages in one TLB entry called even/odd pages. Supposing even/odd page is normal/none state, when odd page is added, TLB entry is changed as normal/normal state and even page keeps unchanged. In this situation, it is not necessary to flush QEMU TLB since even page keep unchanged and odd page is newly changed. Here check whether PTE page is the same or not, TLB flush can be skipped if both are the same or newly added. Signed-off-by: Bibo Mao Reviewed-by: Richard Henderson --- target/loongarch/tcg/tlb_helper.c | 33 ++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/target/loongarch/tcg/tlb_helper.c b/target/loongarch/tcg/tlb_h= elper.c index fcd03ca320..331b485b1a 100644 --- a/target/loongarch/tcg/tlb_helper.c +++ b/target/loongarch/tcg/tlb_helper.c @@ -302,16 +302,39 @@ void helper_tlbrd(CPULoongArchState *env) void helper_tlbwr(CPULoongArchState *env) { int index =3D FIELD_EX64(env->CSR_TLBIDX, CSR_TLBIDX, INDEX); + LoongArchTLB *old, new; + bool skip_inv =3D false; + uint8_t tlb_v0, tlb_v1; =20 - invalidate_tlb(env, index); - + old =3D env->tlb + index; if (FIELD_EX64(env->CSR_TLBIDX, CSR_TLBIDX, NE)) { - env->tlb[index].tlb_misc =3D FIELD_DP64(env->tlb[index].tlb_misc, - TLB_MISC, E, 0); + invalidate_tlb(env, index); + old->tlb_misc =3D FIELD_DP64(old->tlb_misc, TLB_MISC, E, 0); return; } =20 - fill_tlb_entry(env, env->tlb + index); + new.tlb_misc =3D 0; + new.tlb_entry0 =3D 0; + new.tlb_entry1 =3D 0; + fill_tlb_entry(env, &new); + /* Check whether ASID/VPPN is the same */ + if (old->tlb_misc =3D=3D new.tlb_misc) { + /* Check whether both even/odd pages is the same or invalid */ + tlb_v0 =3D FIELD_EX64(old->tlb_entry0, TLBENTRY, V); + tlb_v1 =3D FIELD_EX64(old->tlb_entry1, TLBENTRY, V); + if ((!tlb_v0 || new.tlb_entry0 =3D=3D old->tlb_entry0) && + (!tlb_v1 || new.tlb_entry1 =3D=3D old->tlb_entry1)) { + skip_inv =3D true; + } + } + + /* flush tlb before updating the entry */ + if (!skip_inv) { + invalidate_tlb(env, index); + } + old->tlb_misc =3D new.tlb_misc; + old->tlb_entry0 =3D new.tlb_entry0; + old->tlb_entry1 =3D new.tlb_entry1; } =20 void helper_tlbfill(CPULoongArchState *env) --=20 2.39.3 From nobody Sat Sep 6 14:41:22 2025 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17568893358691015.0023391424218; Wed, 3 Sep 2025 01:48:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1utjAY-0003LK-NU; Wed, 03 Sep 2025 04:48:42 -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 1utjAX-0003Jk-8B for qemu-devel@nongnu.org; Wed, 03 Sep 2025 04:48:41 -0400 Received: from mail.loongson.cn ([114.242.206.163]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1utjAU-0007NB-3S for qemu-devel@nongnu.org; Wed, 03 Sep 2025 04:48:40 -0400 Received: from loongson.cn (unknown [10.2.5.213]) by gateway (Coremail) with SMTP id _____8CxaNHjALhoJycGAA--.12926S3; Wed, 03 Sep 2025 16:48:35 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.213]) by front1 (Coremail) with SMTP id qMiowJDxbMHcALhoc916AA--.5293S6; Wed, 03 Sep 2025 16:48:35 +0800 (CST) From: Bibo Mao To: Song Gao , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: Jiaxun Yang , qemu-devel@nongnu.org Subject: [PATCH v3 04/12] target/loongarch: Update TLB index selection method Date: Wed, 3 Sep 2025 16:48:19 +0800 Message-Id: <20250903084827.3085911-5-maobibo@loongson.cn> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20250903084827.3085911-1-maobibo@loongson.cn> References: <20250903084827.3085911-1-maobibo@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: qMiowJDxbMHcALhoc916AA--.5293S6 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== 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=114.242.206.163; envelope-from=maobibo@loongson.cn; helo=mail.loongson.cn 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_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1756889338684116600 Content-Type: text/plain; charset="utf-8" With function helper_tlbfill(), since there is no suitable TLB entry, new TLB will be added and invalidate one old TLB entry. The old TLB entry index is selected randomly, instead it can be optimized as following: 1. invalid TLB entry can be selected at first. 2. TLB entry with other ASID can be selected secondly 3. random method is used by last. Signed-off-by: Bibo Mao Reviewed-by: Richard Henderson --- target/loongarch/tcg/tlb_helper.c | 49 ++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/target/loongarch/tcg/tlb_helper.c b/target/loongarch/tcg/tlb_h= elper.c index 331b485b1a..00422f259d 100644 --- a/target/loongarch/tcg/tlb_helper.c +++ b/target/loongarch/tcg/tlb_helper.c @@ -340,8 +340,11 @@ void helper_tlbwr(CPULoongArchState *env) void helper_tlbfill(CPULoongArchState *env) { uint64_t address, entryhi; - int index, set, stlb_idx; + int index, set, i, stlb_idx; uint16_t pagesize, stlb_ps; + uint16_t asid, tlb_asid; + LoongArchTLB *tlb; + uint8_t tlb_e; =20 if (FIELD_EX64(env->CSR_TLBRERA, CSR_TLBRERA, ISTLBR)) { entryhi =3D env->CSR_TLBREHI; @@ -355,20 +358,52 @@ void helper_tlbfill(CPULoongArchState *env) =20 /* Validity of stlb_ps is checked in helper_csrwr_stlbps() */ stlb_ps =3D FIELD_EX64(env->CSR_STLBPS, CSR_STLBPS, PS); + asid =3D FIELD_EX64(env->CSR_ASID, CSR_ASID, ASID); if (pagesize =3D=3D stlb_ps) { /* Only write into STLB bits [47:13] */ address =3D entryhi & ~MAKE_64BIT_MASK(0, R_CSR_TLBEHI_64_VPPN_SHI= FT); - - /* Choose one set ramdomly */ - set =3D get_random_tlb(0, 7); - - /* Index in one set */ + set =3D -1; stlb_idx =3D (address >> (stlb_ps + 1)) & 0xff; /* [0,255] */ + for (i =3D 0; i < 8; ++i) { + tlb =3D &env->tlb[i * 256 + stlb_idx]; + tlb_e =3D FIELD_EX64(tlb->tlb_misc, TLB_MISC, E); + if (!tlb_e) { + set =3D i; + break; + } + + tlb_asid =3D FIELD_EX64(tlb->tlb_misc, TLB_MISC, ASID); + if (asid !=3D tlb_asid) { + set =3D i; + } + } =20 + /* Choose one set randomly */ + if (set < 0) { + set =3D get_random_tlb(0, 7); + } index =3D set * 256 + stlb_idx; } else { /* Only write into MTLB */ - index =3D get_random_tlb(LOONGARCH_STLB, LOONGARCH_TLB_MAX - 1); + index =3D -1; + for (i =3D LOONGARCH_STLB; i < LOONGARCH_TLB_MAX; i++) { + tlb =3D &env->tlb[i]; + tlb_e =3D FIELD_EX64(tlb->tlb_misc, TLB_MISC, E); + + if (!tlb_e) { + index =3D i; + break; + } + + tlb_asid =3D FIELD_EX64(tlb->tlb_misc, TLB_MISC, ASID); + if (asid !=3D tlb_asid) { + index =3D i; + } + } + + if (index < 0) { + index =3D get_random_tlb(LOONGARCH_STLB, LOONGARCH_TLB_MAX - 1= ); + } } =20 invalidate_tlb(env, index); --=20 2.39.3 From nobody Sat Sep 6 14:41:22 2025 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1756889407163117.81299462924153; Wed, 3 Sep 2025 01:50:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1utjAZ-0003Ld-GH; Wed, 03 Sep 2025 04:48:43 -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 1utjAW-0003Ja-VL for qemu-devel@nongnu.org; Wed, 03 Sep 2025 04:48:41 -0400 Received: from mail.loongson.cn ([114.242.206.163]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1utjAU-0007NQ-RJ for qemu-devel@nongnu.org; Wed, 03 Sep 2025 04:48:40 -0400 Received: from loongson.cn (unknown [10.2.5.213]) by gateway (Coremail) with SMTP id _____8BxH9PkALhoKycGAA--.12671S3; Wed, 03 Sep 2025 16:48:36 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.213]) by front1 (Coremail) with SMTP id qMiowJDxbMHcALhoc916AA--.5293S7; Wed, 03 Sep 2025 16:48:35 +0800 (CST) From: Bibo Mao To: Song Gao , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: Jiaxun Yang , qemu-devel@nongnu.org Subject: [PATCH v3 05/12] target/loongarch: Fix page size set issue with CSR_STLBPS Date: Wed, 3 Sep 2025 16:48:20 +0800 Message-Id: <20250903084827.3085911-6-maobibo@loongson.cn> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20250903084827.3085911-1-maobibo@loongson.cn> References: <20250903084827.3085911-1-maobibo@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: qMiowJDxbMHcALhoc916AA--.5293S7 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== 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=114.242.206.163; envelope-from=maobibo@loongson.cn; helo=mail.loongson.cn 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_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1756889408952124100 Content-Type: text/plain; charset="utf-8" When modify register CSR_STLBPS, the page size should come from input parameter rather than old value. Signed-off-by: Bibo Mao --- target/loongarch/cpu-csr.h | 1 + target/loongarch/tcg/csr_helper.c | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/target/loongarch/cpu-csr.h b/target/loongarch/cpu-csr.h index 0834e91f30..1a311bf06a 100644 --- a/target/loongarch/cpu-csr.h +++ b/target/loongarch/cpu-csr.h @@ -106,6 +106,7 @@ FIELD(CSR_PWCH, DIR4_WIDTH, 18, 6) =20 #define LOONGARCH_CSR_STLBPS 0x1e /* Stlb page size */ FIELD(CSR_STLBPS, PS, 0, 5) +FIELD(CSR_STLBPS, RESERVE, 5, 27) =20 #define LOONGARCH_CSR_RVACFG 0x1f /* Reduced virtual address confi= g */ FIELD(CSR_RVACFG, RBITS, 0, 4) diff --git a/target/loongarch/tcg/csr_helper.c b/target/loongarch/tcg/csr_h= elper.c index 0d99e2c92b..eb60fefa82 100644 --- a/target/loongarch/tcg/csr_helper.c +++ b/target/loongarch/tcg/csr_helper.c @@ -26,13 +26,14 @@ target_ulong helper_csrwr_stlbps(CPULoongArchState *env= , target_ulong val) * The real hardware only supports the min tlb_ps is 12 * tlb_ps=3D0 may cause undefined-behavior. */ - uint8_t tlb_ps =3D FIELD_EX64(env->CSR_STLBPS, CSR_STLBPS, PS); + uint8_t tlb_ps =3D FIELD_EX64(val, CSR_STLBPS, PS); if (!check_ps(env, tlb_ps)) { qemu_log_mask(LOG_GUEST_ERROR, "Attempted set ps %d\n", tlb_ps); } else { /* Only update PS field, reserved bit keeps zero */ - env->CSR_STLBPS =3D FIELD_DP64(old_v, CSR_STLBPS, PS, tlb_ps); + val =3D FIELD_DP64(val, CSR_STLBPS, RESERVE, 0); + env->CSR_STLBPS =3D val; } =20 return old_v; --=20 2.39.3 From nobody Sat Sep 6 14:41:22 2025 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1756889358292128.29254110192005; Wed, 3 Sep 2025 01:49:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1utjAd-0003Ma-1M; Wed, 03 Sep 2025 04:48:48 -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 1utjAX-0003KX-U2 for qemu-devel@nongnu.org; Wed, 03 Sep 2025 04:48:41 -0400 Received: from mail.loongson.cn ([114.242.206.163]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1utjAV-0007NZ-Pp for qemu-devel@nongnu.org; Wed, 03 Sep 2025 04:48:41 -0400 Received: from loongson.cn (unknown [10.2.5.213]) by gateway (Coremail) with SMTP id _____8Axz7_kALhoLicGAA--.11659S3; Wed, 03 Sep 2025 16:48:37 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.213]) by front1 (Coremail) with SMTP id qMiowJDxbMHcALhoc916AA--.5293S8; Wed, 03 Sep 2025 16:48:36 +0800 (CST) From: Bibo Mao To: Song Gao , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: Jiaxun Yang , qemu-devel@nongnu.org Subject: [PATCH v3 06/12] target/loongarch: Add tlb search callback in loongarch_tlb_search() Date: Wed, 3 Sep 2025 16:48:21 +0800 Message-Id: <20250903084827.3085911-7-maobibo@loongson.cn> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20250903084827.3085911-1-maobibo@loongson.cn> References: <20250903084827.3085911-1-maobibo@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: qMiowJDxbMHcALhoc916AA--.5293S8 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== 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=114.242.206.163; envelope-from=maobibo@loongson.cn; helo=mail.loongson.cn 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_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1756889362982124100 Content-Type: text/plain; charset="utf-8" With function loongarch_tlb_search(), it is to search TLB entry with speficied virtual address, the difference is selection with asid and global bit. Here add selection callback with asid and global bit. Signed-off-by: Bibo Mao Reviewed-by: Richard Henderson --- target/loongarch/tcg/tlb_helper.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/target/loongarch/tcg/tlb_helper.c b/target/loongarch/tcg/tlb_h= elper.c index 00422f259d..006fe1b207 100644 --- a/target/loongarch/tcg/tlb_helper.c +++ b/target/loongarch/tcg/tlb_helper.c @@ -21,6 +21,17 @@ #include "cpu-csr.h" #include "tcg/tcg_loongarch.h" =20 +typedef bool (*tlb_match)(int global, int asid, int tlb_asid); + +static bool tlb_match_any(int global, int asid, int tlb_asid) +{ + if (global =3D=3D 1 || tlb_asid =3D=3D asid) { + return true; + } + + return false; +} + bool check_ps(CPULoongArchState *env, uint8_t tlb_ps) { if (tlb_ps >=3D 64) { @@ -204,9 +215,11 @@ static bool loongarch_tlb_search(CPULoongArchState *en= v, vaddr vaddr, uint8_t tlb_e, tlb_ps, tlb_g, stlb_ps; int i, compare_shift; uint64_t vpn, tlb_vppn; + tlb_match func; =20 + func =3D tlb_match_any; csr_asid =3D FIELD_EX64(env->CSR_ASID, CSR_ASID, ASID); - stlb_ps =3D FIELD_EX64(env->CSR_STLBPS, CSR_STLBPS, PS); + stlb_ps =3D FIELD_EX64(env->CSR_STLBPS, CSR_STLBPS, PS); vpn =3D (vaddr & TARGET_VIRT_MASK) >> (stlb_ps + 1); stlb_idx =3D vpn & 0xff; /* VA[25:15] <=3D=3D> TLBIDX.index for 16KiB = Page */ compare_shift =3D stlb_ps + 1 - R_TLB_MISC_VPPN_SHIFT; @@ -220,7 +233,7 @@ static bool loongarch_tlb_search(CPULoongArchState *env= , vaddr vaddr, tlb_asid =3D FIELD_EX64(tlb->tlb_misc, TLB_MISC, ASID); tlb_g =3D FIELD_EX64(tlb->tlb_entry0, TLBENTRY, G); =20 - if ((tlb_g =3D=3D 1 || tlb_asid =3D=3D csr_asid) && + if (func(tlb_g, csr_asid, tlb_asid) && (vpn =3D=3D (tlb_vppn >> compare_shift))) { *index =3D i * 256 + stlb_idx; return true; @@ -239,7 +252,7 @@ static bool loongarch_tlb_search(CPULoongArchState *env= , vaddr vaddr, tlb_g =3D FIELD_EX64(tlb->tlb_entry0, TLBENTRY, G); compare_shift =3D tlb_ps + 1 - R_TLB_MISC_VPPN_SHIFT; vpn =3D (vaddr & TARGET_VIRT_MASK) >> (tlb_ps + 1); - if ((tlb_g =3D=3D 1 || tlb_asid =3D=3D csr_asid) && + if (func(tlb_g, csr_asid, tlb_asid) && (vpn =3D=3D (tlb_vppn >> compare_shift))) { *index =3D i; return true; --=20 2.39.3 From nobody Sat Sep 6 14:41:22 2025 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1756889397850614.1221449228478; Wed, 3 Sep 2025 01:49:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1utjAl-0003SP-Fz; Wed, 03 Sep 2025 04:48:55 -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 1utjAY-0003LE-Ef for qemu-devel@nongnu.org; Wed, 03 Sep 2025 04:48:42 -0400 Received: from mail.loongson.cn ([114.242.206.163]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1utjAW-0007Nc-Ab for qemu-devel@nongnu.org; Wed, 03 Sep 2025 04:48:42 -0400 Received: from loongson.cn (unknown [10.2.5.213]) by gateway (Coremail) with SMTP id _____8AxztLlALhoMScGAA--.12811S3; Wed, 03 Sep 2025 16:48:37 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.213]) by front1 (Coremail) with SMTP id qMiowJDxbMHcALhoc916AA--.5293S9; Wed, 03 Sep 2025 16:48:36 +0800 (CST) From: Bibo Mao To: Song Gao , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: Jiaxun Yang , qemu-devel@nongnu.org Subject: [PATCH v3 07/12] target/loongarch: Add common API loongarch_tlb_search_cb() Date: Wed, 3 Sep 2025 16:48:22 +0800 Message-Id: <20250903084827.3085911-8-maobibo@loongson.cn> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20250903084827.3085911-1-maobibo@loongson.cn> References: <20250903084827.3085911-1-maobibo@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: qMiowJDxbMHcALhoc916AA--.5293S9 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== 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=114.242.206.163; envelope-from=maobibo@loongson.cn; helo=mail.loongson.cn 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_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1756889400984124100 Content-Type: text/plain; charset="utf-8" Common API loongarch_tlb_search_cb() is added here to search TLB entry with specified address. Signed-off-by: Bibo Mao Reviewed-by: Richard Henderson --- target/loongarch/tcg/tlb_helper.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/target/loongarch/tcg/tlb_helper.c b/target/loongarch/tcg/tlb_h= elper.c index 006fe1b207..fc853f6e80 100644 --- a/target/loongarch/tcg/tlb_helper.c +++ b/target/loongarch/tcg/tlb_helper.c @@ -207,18 +207,16 @@ static uint32_t get_random_tlb(uint32_t low, uint32_t= high) * field in tlb entry contains bit[47:13], so need adjust. * virt_vpn =3D vaddr[47:13] */ -static bool loongarch_tlb_search(CPULoongArchState *env, vaddr vaddr, - int *index) +static bool loongarch_tlb_search_cb(CPULoongArchState *env, vaddr vaddr, + int *index, int asid, tlb_match func) { LoongArchTLB *tlb; uint16_t csr_asid, tlb_asid, stlb_idx; uint8_t tlb_e, tlb_ps, tlb_g, stlb_ps; int i, compare_shift; uint64_t vpn, tlb_vppn; - tlb_match func; =20 - func =3D tlb_match_any; - csr_asid =3D FIELD_EX64(env->CSR_ASID, CSR_ASID, ASID); + csr_asid =3D asid; stlb_ps =3D FIELD_EX64(env->CSR_STLBPS, CSR_STLBPS, PS); vpn =3D (vaddr & TARGET_VIRT_MASK) >> (stlb_ps + 1); stlb_idx =3D vpn & 0xff; /* VA[25:15] <=3D=3D> TLBIDX.index for 16KiB = Page */ @@ -262,6 +260,17 @@ static bool loongarch_tlb_search(CPULoongArchState *en= v, vaddr vaddr, return false; } =20 +static bool loongarch_tlb_search(CPULoongArchState *env, vaddr vaddr, + int *index) +{ + int asid; + tlb_match func; + + func =3D tlb_match_any; + asid =3D FIELD_EX64(env->CSR_ASID, CSR_ASID, ASID); + return loongarch_tlb_search_cb(env, vaddr, index, asid, func); +} + void helper_tlbsrch(CPULoongArchState *env) { int index, match; --=20 2.39.3 From nobody Sat Sep 6 14:41:22 2025 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 175688934528579.68702724018453; Wed, 3 Sep 2025 01:49:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1utjAb-0003M7-09; Wed, 03 Sep 2025 04:48:45 -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 1utjAY-0003Kt-Bx for qemu-devel@nongnu.org; Wed, 03 Sep 2025 04:48:42 -0400 Received: from mail.loongson.cn ([114.242.206.163]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1utjAW-0007Nf-Ay for qemu-devel@nongnu.org; Wed, 03 Sep 2025 04:48:42 -0400 Received: from loongson.cn (unknown [10.2.5.213]) by gateway (Coremail) with SMTP id _____8Dx_7_lALhoNCcGAA--.12294S3; Wed, 03 Sep 2025 16:48:37 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.213]) by front1 (Coremail) with SMTP id qMiowJDxbMHcALhoc916AA--.5293S10; Wed, 03 Sep 2025 16:48:37 +0800 (CST) From: Bibo Mao To: Song Gao , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: Jiaxun Yang , qemu-devel@nongnu.org Subject: [PATCH v3 08/12] target/loongarch: Use loongarch_tlb_search_cb in helper_invtlb_page_asid_or_g Date: Wed, 3 Sep 2025 16:48:23 +0800 Message-Id: <20250903084827.3085911-9-maobibo@loongson.cn> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20250903084827.3085911-1-maobibo@loongson.cn> References: <20250903084827.3085911-1-maobibo@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: qMiowJDxbMHcALhoc916AA--.5293S10 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== 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=114.242.206.163; envelope-from=maobibo@loongson.cn; helo=mail.loongson.cn 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_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1756889347352116600 Content-Type: text/plain; charset="utf-8" With function helper_invtlb_page_asid_or_g(), currently it is to search TLB entry one by one. Instead STLB can be searched at first with hash method, and then search MTLB with one by one method. Here common API loongarch_tlb_search_cb() is used in function helper_invtlb_page_asid_or_g(). Signed-off-by: Bibo Mao Reviewed-by: Richard Henderson --- target/loongarch/tcg/tlb_helper.c | 33 +++++++++++-------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/target/loongarch/tcg/tlb_helper.c b/target/loongarch/tcg/tlb_h= elper.c index fc853f6e80..620de85a3a 100644 --- a/target/loongarch/tcg/tlb_helper.c +++ b/target/loongarch/tcg/tlb_helper.c @@ -561,30 +561,19 @@ void helper_invtlb_page_asid(CPULoongArchState *env, = target_ulong info, void helper_invtlb_page_asid_or_g(CPULoongArchState *env, target_ulong info, target_ulong addr) { - uint16_t asid =3D info & 0x3ff; - - for (int i =3D 0; i < LOONGARCH_TLB_MAX; i++) { - LoongArchTLB *tlb =3D &env->tlb[i]; - uint8_t tlb_g =3D FIELD_EX64(tlb->tlb_entry0, TLBENTRY, G); - uint16_t tlb_asid =3D FIELD_EX64(tlb->tlb_misc, TLB_MISC, ASID); - uint64_t vpn, tlb_vppn; - uint8_t tlb_ps, compare_shift; - uint8_t tlb_e =3D FIELD_EX64(tlb->tlb_misc, TLB_MISC, E); - - if (!tlb_e) { - continue; - } - - tlb_ps =3D FIELD_EX64(tlb->tlb_misc, TLB_MISC, PS); - tlb_vppn =3D FIELD_EX64(tlb->tlb_misc, TLB_MISC, VPPN); - vpn =3D (addr & TARGET_VIRT_MASK) >> (tlb_ps + 1); - compare_shift =3D tlb_ps + 1 - R_TLB_MISC_VPPN_SHIFT; + int index, asid =3D info & 0x3ff; + LoongArchTLB *tlb; + tlb_match func; + bool ret; =20 - if ((tlb_g || (tlb_asid =3D=3D asid)) && - (vpn =3D=3D (tlb_vppn >> compare_shift))) { - tlb->tlb_misc =3D FIELD_DP64(tlb->tlb_misc, TLB_MISC, E, 0); - } + func =3D tlb_match_any; + ret =3D loongarch_tlb_search_cb(env, addr, &index, asid, func); + if (!ret) { + return; } + + tlb =3D &env->tlb[index]; + tlb->tlb_misc =3D FIELD_DP64(tlb->tlb_misc, TLB_MISC, E, 0); tlb_flush(env_cpu(env)); } =20 --=20 2.39.3 From nobody Sat Sep 6 14:41:22 2025 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1756889383688995.4291743554498; Wed, 3 Sep 2025 01:49:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1utjAk-0003Q5-TJ; Wed, 03 Sep 2025 04:48:54 -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 1utjAY-0003LG-Iv for qemu-devel@nongnu.org; Wed, 03 Sep 2025 04:48:42 -0400 Received: from mail.loongson.cn ([114.242.206.163]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1utjAW-0007No-JJ for qemu-devel@nongnu.org; Wed, 03 Sep 2025 04:48:42 -0400 Received: from loongson.cn (unknown [10.2.5.213]) by gateway (Coremail) with SMTP id _____8AxRNDlALhoNycGAA--.12421S3; Wed, 03 Sep 2025 16:48:37 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.213]) by front1 (Coremail) with SMTP id qMiowJDxbMHcALhoc916AA--.5293S11; Wed, 03 Sep 2025 16:48:37 +0800 (CST) From: Bibo Mao To: Song Gao , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: Jiaxun Yang , qemu-devel@nongnu.org Subject: [PATCH v3 09/12] target/loongarch: Use loongarch_tlb_search_cb in helper_invtlb_page_asid Date: Wed, 3 Sep 2025 16:48:24 +0800 Message-Id: <20250903084827.3085911-10-maobibo@loongson.cn> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20250903084827.3085911-1-maobibo@loongson.cn> References: <20250903084827.3085911-1-maobibo@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: qMiowJDxbMHcALhoc916AA--.5293S11 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== 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=114.242.206.163; envelope-from=maobibo@loongson.cn; helo=mail.loongson.cn 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_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1756889385997116600 Content-Type: text/plain; charset="utf-8" With function helper_invtlb_page_asid(), currently it is to search TLB entry one by one. Instead STLB can be searched at first with hash method, and then search MTLB with one by one method Here common API loongarch_tlb_search_cb() is used in function helper_invtlb_page_asid() Signed-off-by: Bibo Mao Reviewed-by: Richard Henderson --- target/loongarch/tcg/tlb_helper.c | 42 +++++++++++++++---------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/target/loongarch/tcg/tlb_helper.c b/target/loongarch/tcg/tlb_h= elper.c index 620de85a3a..c074c956a2 100644 --- a/target/loongarch/tcg/tlb_helper.c +++ b/target/loongarch/tcg/tlb_helper.c @@ -32,6 +32,15 @@ static bool tlb_match_any(int global, int asid, int tlb_= asid) return false; } =20 +static bool tlb_match_asid(int global, int asid, int tlb_asid) +{ + if (!global && tlb_asid =3D=3D asid) { + return true; + } + + return false; +} + bool check_ps(CPULoongArchState *env, uint8_t tlb_ps) { if (tlb_ps >=3D 64) { @@ -531,30 +540,19 @@ void helper_invtlb_all_asid(CPULoongArchState *env, t= arget_ulong info) void helper_invtlb_page_asid(CPULoongArchState *env, target_ulong info, target_ulong addr) { - uint16_t asid =3D info & 0x3ff; - - for (int i =3D 0; i < LOONGARCH_TLB_MAX; i++) { - LoongArchTLB *tlb =3D &env->tlb[i]; - uint8_t tlb_g =3D FIELD_EX64(tlb->tlb_entry0, TLBENTRY, G); - uint16_t tlb_asid =3D FIELD_EX64(tlb->tlb_misc, TLB_MISC, ASID); - uint64_t vpn, tlb_vppn; - uint8_t tlb_ps, compare_shift; - uint8_t tlb_e =3D FIELD_EX64(tlb->tlb_misc, TLB_MISC, E); - - if (!tlb_e) { - continue; - } - - tlb_ps =3D FIELD_EX64(tlb->tlb_misc, TLB_MISC, PS); - tlb_vppn =3D FIELD_EX64(tlb->tlb_misc, TLB_MISC, VPPN); - vpn =3D (addr & TARGET_VIRT_MASK) >> (tlb_ps + 1); - compare_shift =3D tlb_ps + 1 - R_TLB_MISC_VPPN_SHIFT; + int index, asid =3D info & 0x3ff; + LoongArchTLB *tlb; + tlb_match func; + bool ret; =20 - if (!tlb_g && (tlb_asid =3D=3D asid) && - (vpn =3D=3D (tlb_vppn >> compare_shift))) { - tlb->tlb_misc =3D FIELD_DP64(tlb->tlb_misc, TLB_MISC, E, 0); - } + func =3D tlb_match_asid; + ret =3D loongarch_tlb_search_cb(env, addr, &index, asid, func); + if (!ret) { + return; } + + tlb =3D &env->tlb[index]; + tlb->tlb_misc =3D FIELD_DP64(tlb->tlb_misc, TLB_MISC, E, 0); tlb_flush(env_cpu(env)); } =20 --=20 2.39.3 From nobody Sat Sep 6 14:41:22 2025 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1756889425841174.14912083236743; Wed, 3 Sep 2025 01:50:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1utjAm-0003UC-7x; Wed, 03 Sep 2025 04:48:56 -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 1utjAj-0003PT-J8 for qemu-devel@nongnu.org; Wed, 03 Sep 2025 04:48:54 -0400 Received: from mail.loongson.cn ([114.242.206.163]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1utjAh-0007Nr-1U for qemu-devel@nongnu.org; Wed, 03 Sep 2025 04:48:53 -0400 Received: from loongson.cn (unknown [10.2.5.213]) by gateway (Coremail) with SMTP id _____8Dx+tHlALhoOicGAA--.12984S3; Wed, 03 Sep 2025 16:48:37 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.213]) by front1 (Coremail) with SMTP id qMiowJDxbMHcALhoc916AA--.5293S12; Wed, 03 Sep 2025 16:48:37 +0800 (CST) From: Bibo Mao To: Song Gao , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: Jiaxun Yang , qemu-devel@nongnu.org Subject: [PATCH v3 10/12] target/loongarch: Invalid tlb entry in invalidate_tlb() Date: Wed, 3 Sep 2025 16:48:25 +0800 Message-Id: <20250903084827.3085911-11-maobibo@loongson.cn> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20250903084827.3085911-1-maobibo@loongson.cn> References: <20250903084827.3085911-1-maobibo@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: qMiowJDxbMHcALhoc916AA--.5293S12 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== 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=114.242.206.163; envelope-from=maobibo@loongson.cn; helo=mail.loongson.cn 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_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1756889428371116600 Content-Type: text/plain; charset="utf-8" Invalid tlb entry in function invalidate_tlb(), and its usage is simple and easy to use. Signed-off-by: Bibo Mao --- target/loongarch/tcg/tlb_helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/loongarch/tcg/tlb_helper.c b/target/loongarch/tcg/tlb_h= elper.c index c074c956a2..ee40684a18 100644 --- a/target/loongarch/tcg/tlb_helper.c +++ b/target/loongarch/tcg/tlb_helper.c @@ -161,6 +161,7 @@ static void invalidate_tlb(CPULoongArchState *env, int = index) return; } invalidate_tlb_entry(env, index); + tlb->tlb_misc =3D FIELD_DP64(tlb->tlb_misc, TLB_MISC, E, 0); } =20 static void fill_tlb_entry(CPULoongArchState *env, LoongArchTLB *tlb) @@ -340,7 +341,6 @@ void helper_tlbwr(CPULoongArchState *env) old =3D env->tlb + index; if (FIELD_EX64(env->CSR_TLBIDX, CSR_TLBIDX, NE)) { invalidate_tlb(env, index); - old->tlb_misc =3D FIELD_DP64(old->tlb_misc, TLB_MISC, E, 0); return; } =20 --=20 2.39.3 From nobody Sat Sep 6 14:41:22 2025 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1756889666661896.86074747722; Wed, 3 Sep 2025 01:54:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1utjFm-0002gE-S2; Wed, 03 Sep 2025 04:54:10 -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 1utjFT-0002bD-Aq for qemu-devel@nongnu.org; Wed, 03 Sep 2025 04:53:49 -0400 Received: from mail.loongson.cn ([114.242.206.163]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1utjFR-00086q-EQ for qemu-devel@nongnu.org; Wed, 03 Sep 2025 04:53:47 -0400 Received: from loongson.cn (unknown [10.2.5.213]) by gateway (Coremail) with SMTP id _____8DxN9ETArho9icGAA--.12913S3; Wed, 03 Sep 2025 16:53:39 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.213]) by front1 (Coremail) with SMTP id qMiowJBxzsESArhoB+B6AA--.32715S2; Wed, 03 Sep 2025 16:53:39 +0800 (CST) From: Bibo Mao To: Song Gao , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: Jiaxun Yang , qemu-devel@nongnu.org Subject: [PATCH v3 11/12] target/loongarch: Only flush one TLB entry in helper_invtlb_page_asid_or_g() Date: Wed, 3 Sep 2025 16:53:38 +0800 Message-Id: <20250903085338.3086081-1-maobibo@loongson.cn> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20250903084827.3085911-1-maobibo@loongson.cn> References: <20250903084827.3085911-1-maobibo@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: qMiowJBxzsESArhoB+B6AA--.32715S2 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== 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=114.242.206.163; envelope-from=maobibo@loongson.cn; helo=mail.loongson.cn 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_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1756889668853116600 Content-Type: text/plain; charset="utf-8" With function helper_invtlb_page_asid_or_g(), only one TLB entry in LoongArch emulated TLB is invalidated. so with QEMU TLB, it is not necessary to flush all QEMU TLB, only flush address range specified LoongArch emulated TLB is ok. Here invalidate_tlb_entry() is called so that only QEMU TLB entry with specified address range is flushed. Signed-off-by: Bibo Mao Reviewed-by: Richard Henderson --- target/loongarch/tcg/tlb_helper.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/target/loongarch/tcg/tlb_helper.c b/target/loongarch/tcg/tlb_h= elper.c index ee40684a18..017c0d2f5b 100644 --- a/target/loongarch/tcg/tlb_helper.c +++ b/target/loongarch/tcg/tlb_helper.c @@ -560,7 +560,6 @@ void helper_invtlb_page_asid_or_g(CPULoongArchState *en= v, target_ulong info, target_ulong addr) { int index, asid =3D info & 0x3ff; - LoongArchTLB *tlb; tlb_match func; bool ret; =20 @@ -570,9 +569,7 @@ void helper_invtlb_page_asid_or_g(CPULoongArchState *en= v, return; } =20 - tlb =3D &env->tlb[index]; - tlb->tlb_misc =3D FIELD_DP64(tlb->tlb_misc, TLB_MISC, E, 0); - tlb_flush(env_cpu(env)); + invalidate_tlb(env, index); } =20 bool loongarch_cpu_tlb_fill(CPUState *cs, vaddr address, int size, --=20 2.39.3 From nobody Sat Sep 6 14:41:22 2025 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1756889683933179.78159619011979; Wed, 3 Sep 2025 01:54:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1utjG7-0002um-WB; Wed, 03 Sep 2025 04:54:28 -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 1utjFp-0002lA-7Q for qemu-devel@nongnu.org; Wed, 03 Sep 2025 04:54:10 -0400 Received: from mail.loongson.cn ([114.242.206.163]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1utjFn-00089Q-A3 for qemu-devel@nongnu.org; Wed, 03 Sep 2025 04:54:08 -0400 Received: from loongson.cn (unknown [10.2.5.213]) by gateway (Coremail) with SMTP id _____8Cx778pArhoCCgGAA--.11611S3; Wed, 03 Sep 2025 16:54:01 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.213]) by front1 (Coremail) with SMTP id qMiowJAxQMIpArhoNeB6AA--.53375S2; Wed, 03 Sep 2025 16:54:01 +0800 (CST) From: Bibo Mao To: Song Gao , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: Jiaxun Yang , qemu-devel@nongnu.org Subject: [PATCH v3 12/12] target/loongarch: Only flush one TLB entry in helper_invtlb_page_asid() Date: Wed, 3 Sep 2025 16:54:01 +0800 Message-Id: <20250903085401.3086110-1-maobibo@loongson.cn> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20250903084827.3085911-1-maobibo@loongson.cn> References: <20250903084827.3085911-1-maobibo@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: qMiowJAxQMIpArhoNeB6AA--.53375S2 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== 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=114.242.206.163; envelope-from=maobibo@loongson.cn; helo=mail.loongson.cn 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_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1756889685118116600 Content-Type: text/plain; charset="utf-8" With function helper_invtlb_page_asid(), only one TLB entry in LoongArch emulated TLB is invalidated. so with QEMU TLB, it is not necessary to flush all QEMU TLB, only flush address range specified LoongArch emulated TLB is ok. Here invalidate_tlb_entry() is called so that only QEMU TLB entry with specified address range is flushed. Signed-off-by: Bibo Mao Reviewed-by: Richard Henderson --- target/loongarch/tcg/tlb_helper.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/target/loongarch/tcg/tlb_helper.c b/target/loongarch/tcg/tlb_h= elper.c index 017c0d2f5b..de0bbbb6b1 100644 --- a/target/loongarch/tcg/tlb_helper.c +++ b/target/loongarch/tcg/tlb_helper.c @@ -541,7 +541,6 @@ void helper_invtlb_page_asid(CPULoongArchState *env, ta= rget_ulong info, target_ulong addr) { int index, asid =3D info & 0x3ff; - LoongArchTLB *tlb; tlb_match func; bool ret; =20 @@ -551,9 +550,7 @@ void helper_invtlb_page_asid(CPULoongArchState *env, ta= rget_ulong info, return; } =20 - tlb =3D &env->tlb[index]; - tlb->tlb_misc =3D FIELD_DP64(tlb->tlb_misc, TLB_MISC, E, 0); - tlb_flush(env_cpu(env)); + invalidate_tlb(env, index); } =20 void helper_invtlb_page_asid_or_g(CPULoongArchState *env, --=20 2.39.3