[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250213135759.190006-1-fujita.tomonori@gmail.com>
Date: Thu, 13 Feb 2025 22:57:54 +0900
From: FUJITA Tomonori <fujita.tomonori@...il.com>
To: linux-kernel@...r.kernel.org,
rust-for-linux@...r.kernel.org
Cc: x86@...nel.org,
linux-riscv@...ts.infradead.org,
linux-arm-kernel@...ts.infradead.org,
loongarch@...ts.linux.dev,
tglx@...utronix.de,
mingo@...hat.com,
bp@...en8.de,
dave.hansen@...ux.intel.com,
peterz@...radead.org,
hpa@...or.com,
paul.walmsley@...ive.com,
palmer@...belt.com,
aou@...s.berkeley.edu,
catalin.marinas@....com,
will@...nel.org,
chenhuacai@...nel.org,
kernel@...0n.name,
tangyouling@...ngson.cn,
hejinyang@...ngson.cn,
yangtiezhu@...ngson.cn,
ojeda@...nel.org,
alex.gaynor@...il.com,
boqun.feng@...il.com,
gary@...yguo.net,
bjorn3_gh@...tonmail.com,
benno.lossin@...ton.me,
a.hindborg@...nel.org,
aliceryhl@...gle.com,
tmgross@...ch.edu
Subject: [PATCH v3 0/5] rust: Add bug/warn abstractions
This patchset adds warn_on and warn_on_once macros with the bug/warn
abstraction.
Wrapping C's BUG/WARN macros does not work well for x86, RISC-V,
ARM64, and LoongArch. Rust code needs to directly execute the same
assembly code used on the C side. To avoid duplicating the assembly
code, this approach mirrors what the static branch code does: it
generates the assembly code for Rust using the C preprocessor at
compile time.
The 1st to 4th patches export the BUG/WARN assembly code for Rust on
each architecture, with no functional changes on the C side. The
changes for x86 and RISC-V are straightforward. However, the ARM64 and
LoongArch assembly code are designed differently; they are used by
both C inline assembly and assembly code. As a result, sharing this
code with Rust is complicated.
The last patch adds the bug abstraction with warn_on and warn_on_once
implementations.
This has been tested on x86, ARM64, and RISC-V (QEMU), with only a
compile test performed for LoongArch.
The assembly code can be used for both BUG and WARN, but currently
only supports warn_on and warn_on_once. I will work on the remaining
functionality after this abstraction is merged.
v3:
- rebased on rust-next
- use ANNOTATE_REACHABLE macro (replaced ASM_REACHABLE)
- added Acked-by tag to the x86 change
v2: https://lore.kernel.org/linux-arm-kernel/20241218062009.2402650-1-fujita.tomonori@gmail.com/
- remove target_arch cfg by using asm comment
- clean up the changes to loongarch asm
v1: https://lore.kernel.org/linux-arm-kernel/20241210001802.228725-1-fujita.tomonori@gmail.com/
FUJITA Tomonori (5):
x86/bug: Add ARCH_WARN_ASM macro for BUG/WARN asm code sharing with
Rust
riscv/bug: Add ARCH_WARN_ASM macro for BUG/WARN asm code sharing with
Rust
arm64/bug: Add ARCH_WARN_ASM macro for BUG/WARN asm code sharing with
Rust
loongarch/bug: Add ARCH_WARN_ASM macro for BUG/WARN asm code sharing
with Rust
rust: Add warn_on and warn_on_once
arch/arm64/include/asm/asm-bug.h | 33 +++++-
arch/loongarch/include/asm/bug.h | 35 +++++-
arch/riscv/include/asm/bug.h | 37 ++++---
arch/x86/include/asm/bug.h | 56 +++++-----
rust/Makefile | 8 ++
rust/kernel/.gitignore | 2 +
rust/kernel/bug.rs | 100 ++++++++++++++++++
rust/kernel/generated_arch_reachable_asm.rs.S | 7 ++
rust/kernel/generated_arch_warn_asm.rs.S | 7 ++
rust/kernel/lib.rs | 1 +
10 files changed, 235 insertions(+), 51 deletions(-)
create mode 100644 rust/kernel/bug.rs
create mode 100644 rust/kernel/generated_arch_reachable_asm.rs.S
create mode 100644 rust/kernel/generated_arch_warn_asm.rs.S
base-commit: beeb78d46249cab8b2b8359a2ce8fa5376b5ad2d
--
2.43.0
Powered by blists - more mailing lists