@samitouri / QOSamiQemu / commits / db2325f794

target/loongarch: Avoid recursive PNX exception on CSR_BADI fetch

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) <andrew@rail5.org> Reviewed-by: Bibo Mao <maobibo@loongson.cn> Reviewed-by: Song Gao <gaosong@loongson.cn> Signed-off-by: Song Gao <gaosong@loongson.cn>

rail5 committed Mar 6, 2026 at 15:33 UTC db2325f79481fab87211e5a287580d753f582cb8
1 file changed +1 -1
target/loongarch/tcg/tcg_cpu.c
+1 -1
@@ -109,6 +109,7 @@ static void loongarch_cpu_do_interrupt(CPUState *cs)
109 }
110 QEMU_FALLTHROUGH;
111 case EXCCODE_PIF:
112 + case EXCCODE_PNX:
113 case EXCCODE_ADEF:
114 cause = cs->exception_index;
115 update_badinstr = 0;
@@ -129,7 +130,6 @@ static void loongarch_cpu_do_interrupt(CPUState *cs)
130 case EXCCODE_PIS:
131 case EXCCODE_PME:
132 case EXCCODE_PNR:
132 - case EXCCODE_PNX:
133 case EXCCODE_PPI:
134 cause = cs->exception_index;
135 break;