From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.60 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796536672; b=P24SAL0MwTSwQqt4z5VNSHz/Y4KCrJDkaocFqB+XyFF802FEc2LUbVqeZrLbVL/LQGLg 4/wb6xzOyWpLDQad+6Vu22fP2ML+z7jLG+VWW3eyJBWkDHlypVjQfyBASZoXTd8pD9YTg NvInMsgkVnldkt0+VozazQNkLRwV/bcWWK42L1NRa/8O/IyDN5CBxdUlWIG3b6MfgkqX4 LYWz9tquYj0QnrWgLehdHAABvppb+uY8N4WN0D3jiWpjqP/RglwkDwmCVWDK/xNa6q0CX y7NYFr8vkpgELK7WYySdgwYSB1KLRkUWwpyy3PC3xr4gM4+qj2XHl6aLNRFpQJYkqew== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796536672; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc:Subject:Date:Message-ID: X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=gn/YRg4tBJ4ufvi7tY1KJo35YLX5jqu7OBr0PTA8Kc0=; b=pIRE7WDQJKwkTm0pKK1G1r5RHxUDHIHfbZ0+9hM9S3MiZX/2HxgnxYO3fu1wI8bLXlI5 k8skT5UIFHJ8KfY6b7Zy1dm995CCxh5yAmO1qhbuWEqaaVj4R19DQH+46asPluTULJryG Hzw+Z26lzfzko+BaNIcpWK7JFgFq4hf49dPoFv663k7yRDjoso5JQQdqmvmLJG6A49yBl 9OjvEEETvoUn3qKHoDE0l9Bcqa7h8Fm4/rxoq4M86iWKsX5DBMbNkMs0rOGpM0YA0xm8a GAOoKh3+sSNHTjMs298Q+cYVm3mwyDpX5doK6pFRRxSAJXA24AGkWl4p44bBSgwIvgw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=pijfsvDy; arc=none smtp.remote-ip=95.215.58.60 Received: from mta1.migadu.com (out-60.mta1.migadu.com [95.215.58.60]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7F10560A381F for ; Sun, 6 Dec 2026 05:57:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7F10560A381F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=pijfsvDy X-Envelope-To: loongarch@lists.linux.dev DKIM-Signature: a=rsa-sha256; bh=NqAbwFekshgVEV8hw6I1nCjLEkAlhkCTfxJcDqwJ1GQ=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796536669; v=1; x=1797141469; b=pijfsvDyOOZTE6+WejNKnjAg0JVHCSK4FGI7CgkWZSyQ/5e3PEWY+ViVf9TOWdxCNm5xn/RX o/Ii0fQ17Ie+EOzSVKQcBxID1HBF8EQdOJUR9rCepnTKobeUZtDo7rYYxSv53ZRrzyoBUZZvSFR vp8flcBZ5lGzMhOAJaKz4Y6k= X-Envelope-To: loongarch@lists.linux.dev Received: by smtp.migadu.com with ESMTPS id 080a543b8be72ed1; Sun, 06 Dec 2026 05:57:49 +0000 X-Mizu-Trace-ID: 080a543b8be72ed1 X-Migadu-Flow: FLOW_OUT From: Tao Cui To: chenhuacai@kernel.org Cc: kernel@xen0n.name, jianghaoran@kylinos.cn, clopez@suse.de, zhangqing@loongson.cn, zhoubinbin@loongson.cn, lihui@loongson.cn, rdunlap@infradead.org, loongarch@lists.linux.dev, kgdb-bugreport@lists.sourceforge.net, cui.tao@linux.dev, Tao Cui Subject: [PATCH] LoongArch: kgdb: Use larch_insn_read() for the step target instruction Date: Sun, 6 Dec 2026 13:57:34 +0800 Message-ID: <20261206055734.304756-1-cui.tao@linux.dev> X-Mailer: git-send-email 2.53.0 X-Mailing-List: loongarch@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Tao Cui 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 --- 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