Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1CFD1F01806 for ; Fri, 6 Mar 2026 07:35:19 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vyPiE-000896-Fm; Fri, 06 Mar 2026 02:35:07 -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 1vyPiB-00088m-RG; Fri, 06 Mar 2026 02:35:04 -0500 Received: from layka.disroot.org ([178.21.23.139]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vyPiA-0002RN-BG; Fri, 06 Mar 2026 02:35:03 -0500 Received: from [127.0.0.1] (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id BE31726447; Fri, 6 Mar 2026 08:34:59 +0100 (CET) X-Virus-Scanned: SPAM Filter at disroot.org Received: from layka.disroot.org ([127.0.0.1]) by localhost (disroot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id 6Itk8Bop84qD; Fri, 6 Mar 2026 08:34:59 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rail5.org; s=mail; t=1772782499; bh=ja/0Z9HoHiNmwkKbJ2QWZx/TxCXaz60qngIDtf7ujwI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=dXAi61K4N2DXJhwpf2BGkuS1lAHO0uF1LQgog9ZIc922qBDsXobwVCUzmpNL+/ue/ JsLVc+HB9L8TAhM63jLYuih3KufAZ2ygE+xoZmesghmxx4U0WWwmwa6H9f78YZtCCe CRFI3R3c84a7Ngp4mSRrK7XXjG8ZqDUNSGlZzLb/zhzFX+1Je8lGorZ6L8Kf9u99WM fKhQpwMe5U095bPAWYDUIFgveQH/Yb8ZsnlW+iEpCeNbuUy3F8P3LrbhLVk4RJw+OZ 1rTdEjkBsr6DK2REejB7xI2goQHZc+luKqxTDD48n6Ujq2VCEhxdHRdBPYidhpDgzs 8h5HHRC7qWXLg== To: qemu-devel@nongnu.org Cc: gaosong@loongson.cn, maobibo@loongson.cn, qemu-stable@nongnu.org, rail5 Subject: [PATCH v2 2/2] target/loongarch: Avoid recursive PNX exception on CSR_BADI fetch Date: Fri, 6 Mar 2026 15:33:37 +0800 Message-ID: <20260306073355.899858-3-andrew@rail5.org> In-Reply-To: <20260306073355.899858-1-andrew@rail5.org> References: <20260306073355.899858-1-andrew@rail5.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=178.21.23.139; envelope-from=andrew@rail5.org; helo=layka.disroot.org X-Spam_score_int: -1 X-Spam_score: -0.2 X-Spam_bar: / X-Spam_report: (-0.2 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.892, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.622, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: "Andrew S. Rightenburg" From: "Andrew S. Rightenburg" via qemu development Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: rail5 loongarch_cpu_do_interrupt() updates CSR_BADI by fetching the faulting instruction with cpu_ldl_code_mmu(). For a PNX exception (instruction fetch prohibited by NX), fetching the instruction at env->pc will fault with PNX again. This can lead to an infinite exception loop. Treat PNX like other instruction-fetch exceptions (PIF/ADEF) and do not update CSR_BADI for it. Fixes: 410dfbf620a ("target/loongarch: Move TCG specified functions to tcg_cpu.c") Cc: qemu-stable@nongnu.org Signed-off-by: rail5 (Andrew S. Rightenburg) Reviewed-by: Bibo Mao --- target/loongarch/tcg/tcg_cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/loongarch/tcg/tcg_cpu.c b/target/loongarch/tcg/tcg_cpu.c index af92277669..31d3db6e8e 100644 --- a/target/loongarch/tcg/tcg_cpu.c +++ b/target/loongarch/tcg/tcg_cpu.c @@ -109,6 +109,7 @@ static void loongarch_cpu_do_interrupt(CPUState *cs) } QEMU_FALLTHROUGH; case EXCCODE_PIF: + case EXCCODE_PNX: case EXCCODE_ADEF: cause = cs->exception_index; update_badinstr = 0; @@ -129,7 +130,6 @@ static void loongarch_cpu_do_interrupt(CPUState *cs) case EXCCODE_PIS: case EXCCODE_PME: case EXCCODE_PNR: - case EXCCODE_PNX: case EXCCODE_PPI: cause = cs->exception_index; break; -- 2.47.3