* [PATCH] LoongArch: kgdb: Use larch_insn_read() for the step target instruction
@ 2026-12-06 5:57 Tao Cui
0 siblings, 0 replies; only message in thread
From: Tao Cui @ 2026-12-06 5:57 UTC (permalink / raw)
To: chenhuacai
Cc: kernel, jianghaoran, clopez, zhangqing, zhoubinbin, lihui,
rdunlap, loongarch, kgdb-bugreport, cui.tao, Tao Cui
From: Tao Cui <cuitao@kylinos.cn>
Stepping to an address whose instruction page is not readable kills
the whole debugging session on LoongArch: the kernel faults on the
read, the fault re-enters the debugger, and the re-entry guard kills
all breakpoints and panics with "Recursive entry to debugger":
KGDB: re-enter exception: ALL breakpoints killed
CPU: 1 UID: 0 PID: 72 Comm: mount Not tainted 7.4.0-rc5-next-20261204
Call Trace:
[<90000000003dab14>] kgdb_reenter_check+0x138/0x144
[<90000000003dabb8>] kgdb_handle_exception+0x98/0x104
[<9000000000249a20>] kgdb_loongarch_notify+0x7c/0xf4
get_step_address() decodes the instruction at the step target by
dereferencing the instruction pointer directly, so an unreadable
target faults inside the debugger itself. Read the instruction with
the fault-tolerant larch_insn_read() instead and reject unreadable
targets: the same step is then answered with an error reply and the
session survives.
Tested on qemu-system-loongarch64 -M virt (TCG) with kgdboc=ttyS0:
breakpoints and single steps work normally, a step to an unmapped
address gets an error reply.
Fixes: e14dd076964e ("LoongArch: Add basic KGDB & KDB support")
Signed-off-by: Tao Cui <cuitao@kylinos.cn>
---
arch/loongarch/kernel/kgdb.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/arch/loongarch/kernel/kgdb.c b/arch/loongarch/kernel/kgdb.c
index e7b59f8a4b05..160cd16a354c 100644
--- a/arch/loongarch/kernel/kgdb.c
+++ b/arch/loongarch/kernel/kgdb.c
@@ -298,13 +298,18 @@ static int get_step_address(struct pt_regs *regs, unsigned long *next_addr)
char cj_val;
unsigned int si, si_l, si_h, rd, rj, cj;
unsigned long pc = instruction_pointer(regs);
- union loongarch_instruction *ip = (union loongarch_instruction *)pc;
+ union loongarch_instruction insn, *ip = &insn;
if (pc & 3) {
pr_warn("%s: invalid pc 0x%lx\n", __func__, pc);
return -EINVAL;
}
+ if (larch_insn_read((void *)pc, &insn.word)) {
+ pr_warn_ratelimited("%s: failed to read pc 0x%lx\n", __func__, pc);
+ return -EINVAL;
+ }
+
*next_addr = pc + LOONGARCH_INSN_SIZE;
si_h = ip->reg0i26_format.immediate_h;
--
2.43.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-12-06 5:57 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-06 5:57 [PATCH] LoongArch: kgdb: Use larch_insn_read() for the step target instruction Tao Cui
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.