powerpc currently has no ARCH_WARN_ASM or ARCH_WARN_REACHABLE definitions, which causes Rust kernel builds on powerpc to fail with a macro expansion error when the generic Rust WARN() infrastructure tries to call ARCH_WARN_ASM() through generated_arch_warn_asm.rs.S. Every other architecture that supports Rust (x86, arm64, s390, riscv) already provides these definitions. This series brings powerpc into line.
Patch 1 refactors _EMIT_BUG_ENTRY in arch/powerpc/include/asm/bug.h. The old macro was a positional-operand template that hardcoded the 1b label reference and embedded .org/.previous directives, making it impossible to compose as a free string outside an asm operand context. The refactored version takes explicit (label, file, line, flags) arguments via string concatenation; .org/.previous are moved to each call site so BUG_ENTRY() can continue to pass sizeof(struct bug_entry) as an asm operand while ARCH_WARN_ASM supplies its own size string. With _EMIT_BUG_ENTRY composable as a plain string, adding ARCH_WARN_ASM and ARCH_WARN_REACHABLE is then straightforward. Patch 2 adds five KUnit tests under CONFIG_RUST_BUG_POWERPC_KUNIT_TEST (depends on PPC && GENERIC_BUG, covering both ppc32 and ppc64) that verify the __bug_table entry emitted by ARCH_WARN_ASM is correctly formed. find_bug() is called with the exact virtual address of the twi instruction, captured at link time via a .dc.a relocation in a global_asm! block. .dc.a emits a pointer-width word (4 bytes on ppc32, 8 bytes on ppc64); BUG_KUNIT_TRAP_ADDR is declared as usize on the Rust side so the same test code is correct on both. The five tests check that the entry is found, carries BUGFLAG_WARNING, records the right source file and a non-zero line number, and that the trap address lies in kernel text. Changelog: V3 -> V4: - Fix Label with appending b at end - Add KUnit test patch. - Tested on ppc64le pseries: pass:5 fail:0 skip:0. - Tested on ppc32 QEMU mac99 G4: pass:5 fail:0 skip:0. - Tested on ppc64le QEMU pseries: pass:5 fail:0 skip:0. V3: https://lore.kernel.org/all/[email protected] V2 -> V3: - Add label argument in _EMIT_BUG_ENTRY V2: https://lore.kernel.org/all/[email protected] V1 -> V2: - commit message now has error, fixes tag and closes tag V1: https://lore.kernel.org/all/[email protected] Mukesh Kumar Chaurasiya (IBM) (2): powerpc/bug: Add ARCH_WARN_ASM and refactor _EMIT_BUG_ENTRY for Rust support rust: kernel: Add KUnit tests for powerpc ARCH_WARN_ASM bug table emission arch/powerpc/include/asm/bug.h | 36 ++++--- rust/kernel/Kconfig.test | 13 +++ rust/kernel/bug.rs | 171 +++++++++++++++++++++++++++++++++ 3 files changed, 204 insertions(+), 16 deletions(-) -- 2.55.0
