From nobody Sat Apr 11 23:04:08 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1772782519; cv=none; d=zohomail.com; s=zohoarc; b=TWbVn3/twXb7xqsLAgmxI6xfAQi9OijrSQG8QQGQm5q748/0WC0NYG2ncuZywo564fOwoaAu8zswy7lXxVuB06bw5tZhWXSc3Hfm38rE1PC/yF6Ud1npq99IOFeeXkufhSAFh8rZXBNdNFPo1/t0qWK+hQsPhFNQfLHfVERdMnU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772782519; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=SCpJQphqfZ1AK5J0yMYMd/d/izV0d2E9+tUBA9YiWGU=; b=JdGI8GStMAE22l67vsljGRDv8XYru0Kp03dnHFsW4btg+s4w+MqqqxvPhkliuGHycXcRDsKo6teRSEyfVx2J06Ex4v8dH+L/5hOrJS+QHBH9K1khx7wlghn5JCWV62n+7epAcrfQhS2CslXriXFUdCIQ+R+Y21X36WJPadmdk4M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1772782519446436.7989229069541; Thu, 5 Mar 2026 23:35:19 -0800 (PST) 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) 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) X-Virus-Scanned: SPAM Filter at disroot.org 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: quoted-printable 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=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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Invalid Public Key: Invalid key spec: java.security.InvalidKeyException: IOException: null) X-ZM-MESSAGEID: 1772782521084158500 Content-Type: text/plain; charset="utf-8" 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 =3D cs->exception_index; update_badinstr =3D 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 =3D cs->exception_index; break; --=20 2.47.3