[PATCH v5 4/4] rust: Add warn_on macro
Greg KH
gregkh at linuxfoundation.org
Wed Apr 9 00:38:53 PDT 2025
On Wed, Apr 09, 2025 at 03:58:01PM +0900, FUJITA Tomonori wrote:
> Add warn_on macro, uses the BUG/WARN feature (lib/bug.c) via assembly
> for x86_64/arm64/riscv.
>
> The current Rust code simply wraps BUG() macro but doesn't provide the
> proper debug information. The BUG/WARN feature can only be used from
> assembly.
>
> This uses the assembly code exported by the C side via ARCH_WARN_ASM
> macro. To avoid duplicating the assembly code, this approach follows
> the same strategy as the static branch code: it generates the assembly
> code for Rust using the C preprocessor at compile time.
>
> Similarly, ARCH_WARN_REACHABLE is also used at compile time to
> generate the assembly code; objtool's reachable anotation code. It's
> used for only architectures that use objtool.
>
> For now, Loongarch and arm32 just use a wrapper for WARN macro.
>
> UML doesn't use the assembly BUG/WARN feature; just wrapping generic
> BUG/WARN functions implemented in C works.
>
> Signed-off-by: FUJITA Tomonori <fujita.tomonori at gmail.com>
I don't object to this change, but I would STRONGLY recommend never
using this in any driver if at all possible. Only use this if the
system is in such a state that the only way out is to reboot the kernel,
which is what both WARN() and BUG() will do.
Note, any way that a user can trigger either of these code paths will
result in a CVE, so don't do that either. Almost always just properly
handle the issue and propagate up the error to the caller.
thanks,
gre gk-h
More information about the linux-arm-kernel
mailing list