From: FUJITA Tomonori <tomo@flapping.org>
To: mkchauras@gmail.com
Cc: maddy@linux.ibm.com, mpe@ellerman.id.au, npiggin@gmail.com,
chleroy@kernel.org, ojeda@kernel.org, boqun@kernel.org,
gary@garyguo.net, bjorn3_gh@protonmail.com, lossin@kernel.org,
a.hindborg@kernel.org, aliceryhl@google.com, tmgross@umich.edu,
dakr@kernel.org, daniel.almeida@collabora.com, tamird@kernel.org,
acourbot@nvidia.com, work@onurozkan.dev, pjw@kernel.org,
palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr,
nathan@kernel.org, ndesaulniers@google.com, morbo@google.com,
justinstitt@google.com, ynorov@nvidia.com, david@davidgow.net,
joelagnelf@nvidia.com, fujita.tomonori@gmail.com,
linkmauve@linkmauve.fr, linuxppc-dev@lists.ozlabs.org,
linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
linux-riscv@lists.infradead.org, llvm@lists.linux.dev
Subject: Re: [PATCH V5 2/2] rust: kernel: Add KUnit tests for powerpc ARCH_WARN_ASM bug table emission
Date: Wed, 16 Sep 2026 23:06:58 +0900 (JST) [thread overview]
Message-ID: <20260916.230658.2266384286281034372.tomo@flapping.org> (raw)
In-Reply-To: <20260915090453.1227034-3-mkchauras@gmail.com>
On Tue, 15 Sep 2026 14:34:53 +0530
"Mukesh Kumar Chaurasiya (IBM)" <mkchauras@gmail.com> wrote:
> Verify that the __bug_table entry emitted by ARCH_WARN_ASM has a correct
> bug_addr displacement ― i.e. the '1b' label reference in _EMIT_BUG_ENTRY
> resolves to the trap instruction ― by calling find_bug() with the exact
> virtual address of the twi instruction, mirroring what the real powerpc
> trap handler does.
>
> The trap address is captured at link time via a .dc.a 1b relocation placed
> in .data by the global_asm! block. global_asm! is used instead of asm!
> because LLVM eliminates asm! blocks in dead branches; global_asm! is
> file-scope and always emitted. BUG_KUNIT_TRAP_ADDR is defined as a .global
> symbol directly on the .dc.a word so the linker relocation lands on it ―
> a Rust static initialized to zero would end up in BSS where relocations are
> not applied.
>
> .dc.a emits a pointer-width word (4 bytes on ppc32, 8 bytes on ppc64),
> so BUG_KUNIT_TRAP_ADDR is declared as usize on the Rust side, making the
> tests correct on both ppc32 and ppc64. The global_asm! block is split into
> two cfg-gated variants (CONFIG_PPC64 / !CONFIG_PPC64) to select the right
> .balign since concat!() only accepts literals.
>
> Five tests are included in the rust_kernel_bug_powerpc suite:
>
> bug_entry_found - find_bug() returns non-NULL for the trap address,
> proving the bug_addr displacement is correct
> bug_entry_is_warning - the emitted entry has BUGFLAG_WARNING set
> bug_entry_file - bug_get_file_line() returns the correct source
> file (requires CONFIG_DEBUG_BUGVERBOSE)
> bug_entry_line - the recorded line number is non-zero, confirming
> the {line} operand was substituted correctly
> (requires CONFIG_DEBUG_BUGVERBOSE)
> bug_entry_addr_is_in_text - kernel_text_address() confirms the trap address
> lies in kernel text, not data or zero
>
> The suite is named rust_kernel_bug_powerpc and the Kconfig option
> CONFIG_RUST_BUG_POWERPC_KUNIT_TEST depends on PPC && GENERIC_BUG,
> covering both ppc32 and ppc64.
>
> Tested on ppc64le (ltcfujiaac-lp3, 7.3.0-rc1+): pass:5 fail:0 skip:0.
> Tested on ppc32 Book3S (QEMU mac99 G4, chrp32_defconfig): pass:5 fail:0 skip:0.
> Tested on ppc64le (QEMU pseries, pseries_le_defconfig): pass:5 fail:0 skip:0.
>
> Signed-off-by: Mukesh Kumar Chaurasiya (IBM) <mkchauras@gmail.com>
> ---
> rust/kernel/Kconfig.test | 13 +++
> rust/kernel/bug.rs | 209 +++++++++++++++++++++++++++++++++++++++
> 2 files changed, 222 insertions(+)
I think that testing warn_on!, in particular that the right address is
put in the bug entry, is a good idea.
I'd prefer such a test to work on every architecture. This one depends on
details of powerpc's ARCH_WARN_ASM, such as the '1b' label. KUnit has a
warning suppression API. A test can call warn_on! inside a suppression
block and check that one warning was counted. The counter is only
incremented after find_bug() found the entry, so a wrong address is caught
too.
I'll send a patch for that shortly.
next prev parent reply other threads:[~2026-09-16 14:07 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-15 9:04 [PATCH v5 0/2] powerpc: Add ARCH_WARN_ASM and KUnit tests for Rust WARN() support Mukesh Kumar Chaurasiya (IBM)
2026-09-15 9:04 ` [PATCH V5 1/2] powerpc/bug: Add ARCH_WARN_ASM and refactor _EMIT_BUG_ENTRY for Rust support Mukesh Kumar Chaurasiya (IBM)
2026-09-15 9:04 ` [PATCH V5 2/2] rust: kernel: Add KUnit tests for powerpc ARCH_WARN_ASM bug table emission Mukesh Kumar Chaurasiya (IBM)
2026-09-16 14:06 ` FUJITA Tomonori [this message]
2026-09-16 14:17 ` Mukesh Kumar Chaurasiya
2026-09-16 14:21 ` David Gow
2026-09-16 14:46 ` Mukesh Kumar Chaurasiya
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260916.230658.2266384286281034372.tomo@flapping.org \
--to=tomo@flapping.org \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=alex@ghiti.fr \
--cc=aliceryhl@google.com \
--cc=aou@eecs.berkeley.edu \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=chleroy@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=david@davidgow.net \
--cc=fujita.tomonori@gmail.com \
--cc=gary@garyguo.net \
--cc=joelagnelf@nvidia.com \
--cc=justinstitt@google.com \
--cc=linkmauve@linkmauve.fr \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=llvm@lists.linux.dev \
--cc=lossin@kernel.org \
--cc=maddy@linux.ibm.com \
--cc=mkchauras@gmail.com \
--cc=morbo@google.com \
--cc=mpe@ellerman.id.au \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=npiggin@gmail.com \
--cc=ojeda@kernel.org \
--cc=palmer@dabbelt.com \
--cc=pjw@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
--cc=ynorov@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®