public inbox for linux-riscv@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH v2 0/5] rust: Add bug/warn abstractions
@ 2024-12-18  6:20 FUJITA Tomonori
  2024-12-18  6:20 ` [PATCH v2 1/5] x86/bug: Add ARCH_WARN_ASM macro for BUG/WARN asm code sharing with Rust FUJITA Tomonori
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: FUJITA Tomonori @ 2024-12-18  6:20 UTC (permalink / raw)
  To: linux-kernel, rust-for-linux
  Cc: x86, linux-riscv, linux-arm-kernel, loongarch, tglx, mingo, bp,
	dave.hansen, peterz, hpa, paul.walmsley, palmer, aou,
	catalin.marinas, will, chenhuacai, kernel, tangyouling, hejinyang,
	yangtiezhu, ojeda, alex.gaynor, boqun.feng, gary, bjorn3_gh,
	benno.lossin, a.hindborg, aliceryhl, tmgross

This patchset adds warn_on and warn_on_once macros with the bug/warn
abstraction.

Wrapping C's BUG/WARN macros does not work the same way on
architectures that support Rust (x86, RISC-V, ARM64, 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 dynamically generates the
assembly code for Rust using the C preprocessor.

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.

v2:
- 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              |  31 +++++-
 arch/loongarch/include/asm/bug.h              |  31 +++++-
 arch/riscv/include/asm/bug.h                  |  35 +++---
 arch/x86/include/asm/bug.h                    |  51 +++++----
 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, 224 insertions(+), 49 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: 517743c4e303252cd8c1a1fb1bed28e7d94d4678
-- 
2.43.0


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-12-18 12:10 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-18  6:20 [PATCH v2 0/5] rust: Add bug/warn abstractions FUJITA Tomonori
2024-12-18  6:20 ` [PATCH v2 1/5] x86/bug: Add ARCH_WARN_ASM macro for BUG/WARN asm code sharing with Rust FUJITA Tomonori
2024-12-18 11:04   ` Peter Zijlstra
2024-12-18  6:20 ` [PATCH v2 2/5] riscv/bug: " FUJITA Tomonori
2024-12-18  6:20 ` [PATCH v2 3/5] arm64/bug: " FUJITA Tomonori
2024-12-18  6:20 ` [PATCH v2 4/5] loongarch/bug: " FUJITA Tomonori
2024-12-18  6:20 ` [PATCH v2 5/5] rust: Add warn_on and warn_on_once FUJITA Tomonori

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox