Re: [RFC] rust: kernel: Add KUnit tests for ARCH_WARN_ASM bug table emission
flat view
From: Peter Zijlstra <peterz@infradead.org>
Date: 2026-09-24 12:53:18
Also in:
linux-riscv, linux-s390, lkml, llvm, rust-for-linux
On Thu, Sep 24, 2026 at 01:46:59PM +0100, Mark Rutland wrote:
quoted
diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c index 914282016069..3d8a969eab5f 100644 --- a/arch/arm64/kernel/traps.c +++ b/arch/arm64/kernel/traps.c@@ -987,14 +987,13 @@ void do_serror(struct pt_regs *regs, unsigned long esr) #ifdef CONFIG_GENERIC_BUG int is_valid_bugaddr(unsigned long addr) { - /* - * bug_brk_handler() only called for BRK #BUG_BRK_IMM. - * So the answer is trivial -- any spurious instances with no - * bug table entry will be rejected by report_bug() and passed - * back to the debug-monitors code and handled as a fatal - * unexpected debug exception. - */ - return 1; + u32 insn; + + if (aarch64_insn_read((u32 *)addr, &insn)) + return 0; + + /* Match ASM_BUG_FLAGS() / BUG() instructions. */ + return insn == (0xd4200000 | (BUG_BRK_IMM << 5)); } #endifWhat problem is this trying to solve? Mukesh's original patch seems to be trying to check whether we compiled things correctly (such that the bug_table entry points at the expected insturction), and I don't think that warrants a runtime check, but (as per my reply to him) I don't understand why that's a thing to check in the first place. On arm64 we only call is_valid_bugaddr() under do_el1_brk64() -> call_el1_break_hook() -> bug_brk_handler(). We only call bug_brk_handler() when HW has taken a BRK exception with the BUG_BRK_IMM immediate, and that can only be triggered by executing the right instruction (BRK #BUG_BRK_IMM), which we ONLY use for BUG(). and WARN(). So I don't see why any change is necessary here. If the HW has somehow taken a BRK exception from any other instruction (which would presumably be a HW bug), there won't be a bug_table entry, and so __report_bug() will fail to find an entry, and will return BUG_TRAP_TYPE_NONE, same as for the !is_valid_bugaddr() case.
Right, so I wasn't at all sure what he was doing, Rust is still mostly unreadable garbage to me. But I figured I'd much rather see him use is_valid_bugaddr() to do runtime checks than whatever dodgy games he was playing with that label. So *if* doing runtime checks is what is wanted, then is_valid_bugaddr() needs to actually work, because then it grows a user outside of the BRK handler. Lots of IFs etc, but since I am having a head-ache and am mostly useless, I figured I'd distract myself doing whatever :-)