s390: Enable Rust support and add required arch glue
Subsystems (4)
v6 cover s390: Enable Rust support and add required arch glue
Rust support on s390 requires a small set of architecture-specific pieces before the generic Rust kernel infrastructure can be used.
The series wires up s390 as a Rust-capable 64-bit architecture, adds the missing assembly interfaces needed by Rust for WARN/BUG reporting and for static branches, adjusts bindgen parameters to avoid repr layout conflicts caused by packed and aligned s390 structures, and fixes issues discovered during testing.
s390 currently requires rustc with support for -Zpacked-stack, and the minimum tool version gating is adjusted accordingly.
Tested against: rustc 1.96.0 (ac68faa20 2026-05-25)
Changes since v5:
- Fix indent in bug.h
- Add __rust_helper to rust_helper_memchr() (thanks Gary)
Changes since v4:
- Patch 4/6: Use kernel's memchr() instead of __builtin_memchr (Sashiko AI)
Changes since v3:
- Added patch 4/6: Add memchr wrapper preserving KASAN/FORTIFY_SOURCE (reported by Sashiko AI)
- Added patch 5/6: Fix KASAN stack-out-of-bounds in atomic helpers (reported by Miguel, suggested by Gary)
- Patch 6/6: Document CONFIG_EXPOLINE constraint in arch-support.rst (Sashiko AI feedback)
- Patch 6/6: Added Acked-by from Miguel Ojeda
Changes since v2:
- mflags: cleanup (thanks Gary)
Changes since v1:
- strip the -nightly suffix in min-tool-version.sh (thanks Miguel and Alice)
- ARCH_JUMP_TABLE_ENTRY() moved up to align comments properly (thanks Gary)
- removed MONCODE_BUG to prevent 0U in non-C context in assembler (noted by Sashiko - AI)
- prevent environment pollution by explicit initialization mflag := (noted by Sashiko - AI)
Jan Polensky (6):
s390/bug: Provide ARCH_WARN_ASM for Rust WARN/BUG support s390/jump_label: Implement ARCH_STATIC_BRANCH_JUMP_ASM and
ARCH_STATIC_BRANCH_ASM macros
rust/bindgen_parameters: Mark s390 types as opaque to prevent repr
conflicts
rust: helpers: Add memchr wrapper for string operations s390/cmpxchg: Fix KASAN stack-out-of-bounds in atomic helpers
s390: Enable Rust support
Documentation/rust/arch-support.rst | 1 + arch/s390/Kconfig | 1 + arch/s390/Makefile | 28 ++++++++++++++---------- arch/s390/include/asm/bug.h | 12 +++++++++++ arch/s390/include/asm/cmpxchg.h | 8 +++---- arch/s390/include/asm/jump_label.h | 33 +++++++++++++++++------------ rust/Makefile | 1 + rust/bindgen_parameters | 7 ++++++ rust/helpers/helpers.c | 1 + rust/helpers/string.c | 8 +++++++ scripts/generate_rust_target.rs | 2 ++ scripts/min-tool-version.sh | 6 +++++- 12 files changed, 78 insertions(+), 30 deletions(-) create mode 100644 rust/helpers/string.c
base-commit: 2d3090a8aeb596a26935db0955d46c9a5db5c6ce --
2.53.0
PATCH v6 1/6 s390/bug: Provide ARCH_WARN_ASM for Rust WARN/BUG support
Rust WARN and BUG support relies on ARCH_WARN_ASM to emit __bug_table entries. On s390 the macro is missing, so Rust code cannot generate proper WARN/BUG metadata for the kernel's bug reporting infrastructure.
Define ARCH_WARN_ASM to produce the same assembly sequence and __bug_table entry format as the existing s390 BUG handling, including the monitor call. Define ARCH_WARN_REACHABLE as empty since s390 does not provide reachability analysis for warning paths.
--- arch/s390/include/asm/bug.h | 12 ++++++++++++ 1 file changed, 12 insertions(+)
arch/s390/include/asm/bug.h +12 -0
@@ -4,6 +4,7 @@#include <linux/compiler.h> #include <linux/const.h> +#include <linux/stringify.h> #define MONCODE_BUG _AC(0, U)#define MONCODE_BUG_ARG _AC(1, U)
@@ -121,6 +122,17 @@ do { \#define HAVE_ARCH_BUG_FORMAT #define HAVE_ARCH_BUG_FORMAT_ARGS +#define ARCH_WARN_ASM (file, line, flags, size) \ + ".section .rodata.str,\"aMS\",@progbits,1\n" \ + "9:\n" \ + ".asciz \"\"\n"/* Empty string for compatibility */ \ +".previous\n" \ +"0:\n" \ + __stringify(mc 0(%r0),0) "\n" \ + __BUG_ENTRY("9b", file, line, flags, size) + +#define ARCH_WARN_REACHABLE +#endif /* CONFIG_BUG && CONFIG_CC_HAS_ASM_IMMEDIATE_STRINGS */ #endif /* __ASSEMBLER__ */
Signature · 1 line
2.53.0
PATCH v6 2/6 s390/jump_label: Implement ARCH_STATIC_BRANCH_JUMP_ASM and ARCH_STATIC_BRANCH_ASM macros
In reply to Jan PolenskyRust static branch support needs the s390 jump label instruction sequence and __jump_table emission in a reusable form. The current implementation embeds the sequence directly in the C asm goto blocks, which cannot be shared with Rust.
Introduce ARCH_STATIC_BRANCH_ASM and ARCH_STATIC_BRANCH_JUMP_ASM to describe the brcl sequences for the likely-false and likely-true cases and to emit the same __jump_table entries as before. Switch the existing C helpers to use the new macros to avoid duplication without changing the generated code.
--- arch/s390/include/asm/jump_label.h | 33 +++++++++++++++++------------- 1 file changed, 19 insertions(+), 14 deletions(-)
arch/s390/include/asm/jump_label.h +19 -14
@@ -19,19 +19,29 @@#define JUMP_LABEL_STATIC_KEY_CONSTRAINT "jdd"#endif +#define ARCH_JUMP_TABLE_ENTRY (key, label, local_label) \ + ".pushsection __jump_table,\"aw\"\n" \ + ".balign 8\n" \ + ".long " local_label "-.," label "-.\n" \ + ".quad " key "-.\n" \ + ".popsection\n" +/* * We use a brcl 0,<offset> instruction for jump labels so it * can be easily distinguished from a hotpatch generated instruction. */ +#define ARCH_STATIC_BRANCH_ASM (key, label) \ + "0: brcl 0," label "\n" \ + ARCH_JUMP_TABLE_ENTRY(key, label, "0b") + +#define ARCH_STATIC_BRANCH_JUMP_ASM (key, label) \ + "0: brcl 15," label "\n" \ + ARCH_JUMP_TABLE_ENTRY(key, label, "0b") + static __always_inline bool arch_static_branch(struct static_key *key, bool branch) { - asm goto("0: brcl 0,%l[label]\n" -".pushsection __jump_table,\"aw\"\n" -".balign 8\n" -".long 0b-.,%l[label]-.\n" -".quad %0+%1-.\n" -".popsection\n" - : : JUMP_LABEL_STATIC_KEY_CONSTRAINT (key), "i" (branch) : : label); + asm goto(ARCH_STATIC_BRANCH_ASM("%0+%1", "%l[label]") + : : JUMP_LABEL_STATIC_KEY_CONSTRAINT (key), "i" (branch) : : label);return false; label:return true;
@@ -39,13 +49,8 @@ static __always_inline bool arch_static_branch(struct static_key *key, bool bran static __always_inline bool arch_static_branch_jump(struct static_key *key, bool branch) { - asm goto("0: brcl 15,%l[label]\n" -".pushsection __jump_table,\"aw\"\n" -".balign 8\n" -".long 0b-.,%l[label]-.\n" -".quad %0+%1-.\n" -".popsection\n" - : : JUMP_LABEL_STATIC_KEY_CONSTRAINT (key), "i" (branch) : : label); + asm goto(ARCH_STATIC_BRANCH_JUMP_ASM("%0+%1", "%l[label]") + : : JUMP_LABEL_STATIC_KEY_CONSTRAINT (key), "i" (branch) : : label);return false; label:return true;
Signature · 1 line
2.53.0
PATCH v6 3/6 rust/bindgen_parameters: Mark s390 types as opaque to prevent repr conflicts
In reply to Jan PolenskyBindgen attempts to generate Rust layouts for a number of s390 structs that are packed but contain, or transitively contain, aligned fields. Rust rejects such layouts with E0588 ("packed type cannot transitively contain a #[repr(align)] type").
Add the affected s390 types to the opaque type list so bindgen emits opaque blob types instead of full representations. This matches existing workarounds for x86 types such as alt_instr and x86_msi_data.
--- rust/bindgen_parameters | 7 +++++++ 1 file changed, 7 insertions(+)
rust/bindgen_parameters +7 -0
@@ -14,6 +14,13 @@ --opaque-type alt_instr --opaque-type x86_msi_data --opaque-type x86_msi_addr_lo +# s390-only: same packed/align issue as above (E0588). +--opaque-type lowcore +--opaque-type tod_clock +--opaque-type tpi_info +--opaque-type uv_cb.* +--opaque-type uv_secret.* +--opaque-type zpci_fib # If SMP is disabled, `arch_spinlock_t` is defined as a ZST which triggers a Rust # warning. We don't need to peek into it anyway.
Signature · 1 line
2.53.0
PATCH v6 4/6 rust: helpers: Add memchr wrapper for string operations
In reply to Jan PolenskyAdd a dedicated string helper file with a memchr wrapper that uses the kernel's instrumented memchr() function to ensure KASAN and FORTIFY_SOURCE protections are preserved for Rust code.
--- rust/helpers/helpers.c | 1 + rust/helpers/string.c | 8 ++++++++ 2 files changed, 9 insertions(+) create mode 100644 rust/helpers/string.c
rust/helpers/helpers.c +1 -0
@@ -88,6 +88,7 @@#include "signal.c" #include "slab.c" #include "spinlock.c" +#include "string.c" #include "sync.c" #include "task.c" #include "time.c"
rust/helpers/string.c new file +8 -0
@@ -0,0 +1,8 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include <linux/string.h> + +__rust_helper void *rust_helper_memchr(const void *s, int c, size_t n) +{ +return memchr (s, c, n); +}
Signature · 1 line
2.53.0
PATCH v6 5/6 s390/cmpxchg: Fix KASAN stack-out-of-bounds in atomic helpers
In reply to Jan PolenskyThe __arch_cmpxchg1, __arch_cmpxchg2, __arch_xchg1, and __arch_xchg2 functions emulate 1-byte and 2-byte atomic operations using 4-byte cmpxchg instructions, since s390 lacks native 1/2-byte cmpxchg support.
When KASAN is enabled, the READ_ONCE() operations in these functions trigger stack-out-of-bounds warnings because they perform 4-byte reads when only 1 or 2 bytes should be accessed.
Mark these functions as __no_sanitize_or_inline to prevent KASAN instrumentation while maintaining correct functionality.
This resolves the following KASAN error during rust_atomics KUnit tests:
BUG: KASAN: stack-out-of-bounds in rust_helper_atomic_i8_xchg+0xb2/0xc0 Read of size 4 at addr 001bff7ffdbefcf0 by task kunit_try_catch/142
--- arch/s390/include/asm/cmpxchg.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
arch/s390/include/asm/cmpxchg.h +4 -4
@@ -35,7 +35,7 @@ static __always_inline u64 __csg_asm(u64 ptr, u64 old, u64 new)return old; } -static inline u8 __arch_cmpxchg1 (u64 ptr,u8 old,u8 new) +static __no_sanitize_or_inline u8 __arch_cmpxchg1(u64 ptr, u8 old, u8 new) {union {u8 b[4 ];
@@ -58,7 +58,7 @@ static inline u8 __arch_cmpxchg1(u64 ptr, u8 old, u8 new)return old; } -static inline u16 __arch_cmpxchg2 (u64 ptr,u16 old,u16 new) +static __no_sanitize_or_inline u16 __arch_cmpxchg2(u64 ptr, u16 old, u16 new) {union {u16 b[2 ];
@@ -173,7 +173,7 @@ static __always_inline u64 __arch_cmpxchg(u64 ptr, u64 old, u64 new, int size)void __xchg_called_with_bad_pointer (void ); -static inline u8 __arch_xchg1 (u64 ptr,u8 x) +static __no_sanitize_or_inline u8 __arch_xchg1(u64 ptr, u8 x) {int shift = (3 ^ (ptr &3 )) <<3 ;u32 mask, old, new;
@@ -188,7 +188,7 @@ static inline u8 __arch_xchg1(u64 ptr, u8 x)return old >> shift; } -static inline u16 __arch_xchg2 (u64 ptr,u16 x) +static __no_sanitize_or_inline u16 __arch_xchg2(u64 ptr, u16 x) {int shift = (2 ^ (ptr &2 )) <<3 ;u32 mask, old, new;
Signature · 1 line
2.53.0
PATCH v6 6/6 s390: Enable Rust support
In reply to Jan PolenskyEnable building Rust code on s390 by wiring the architecture into the kernel Rust infrastructure.
Add s390 to the Rust arch support documentation, provide the s390 Rust target and required compiler flags, and set the bindgen target for arch/s390. Adjust the Rust target generation and minimum rustc version gating so the s390 setup is handled explicitly.
The Rust toolchain uses the "s390x" triple naming for the 64 bit target.
Rust support is currently incompatible with CONFIG_EXPOLINE, which relies on compiler support for the -mindirect-branch= and -mfunction_return= options. Therefore, select HAVE_RUST only when EXPOLINE is disabled.
--- Documentation/rust/arch-support.rst | 1 + arch/s390/Kconfig | 1 + arch/s390/Makefile | 28 +++++++++++++++++----------- rust/Makefile | 1 + scripts/generate_rust_target.rs | 2 ++ scripts/min-tool-version.sh | 6 +++++- 6 files changed, 27 insertions(+), 12 deletions(-)
Documentation/rust/arch-support.rst +1 -0
@@ -19,6 +19,7 @@ Architecture Level of support Constraints ``arm64`` Maintained Little Endian only. ``loongarch`` Maintained \- ``riscv`` Maintained ``riscv64`` and LLVM/Clang only. +``s390`` Maintained ``CONFIG_EXPOLINE`` must be disabled. ``um`` Maintained \- ``x86`` Maintained ``x86_64`` only. ============= ================ ==============================================
arch/s390/Kconfig +1 -0
@@ -248,6 +248,7 @@ config S390 select HAVE_RELIABLE_STACKTRACE select HAVE_RETHOOK select HAVE_RSEQ + select HAVE_RUST if !EXPOLINE select HAVE_SAMPLE_FTRACE_DIRECT select HAVE_SAMPLE_FTRACE_DIRECT_MULTI select HAVE_SETUP_PER_CPU_AREA
arch/s390/Makefile +17 -11
@@ -35,25 +35,31 @@ KBUILD_CFLAGS_DECOMPRESSOR += $(if $(CONFIG_DEBUG_INFO),-g) KBUILD_CFLAGS_DECOMPRESSOR += $(if $(CONFIG_DEBUG_INFO_DWARF4), $(call cc-option, -gdwarf-4,)) KBUILD_CFLAGS_DECOMPRESSOR += $(if $(CONFIG_CC_NO_ARRAY_BOUNDS),-Wno-array-bounds) +KBUILD_RUSTFLAGS += --target=s390x-unknown-none-softfloat -Zpacked-stack -Ctarget-feature=+backchain + UTS_MACHINE := s390x STACK_SIZE := $(if $(CONFIG_KASAN),65536,$(if $(CONFIG_KMSAN),65536,16384)) CHECKFLAGS += -D__s390__ -D__s390x__ export LD_BFD -mflags-$(CONFIG_MARCH_Z10) := -march=z10 -mflags-$(CONFIG_MARCH_Z196) := -march=z196 -mflags-$(CONFIG_MARCH_ZEC12) := -march=zEC12 -mflags-$(CONFIG_MARCH_Z13) := -march=z13 -mflags-$(CONFIG_MARCH_Z14) := -march=z14 -mflags-$(CONFIG_MARCH_Z15) := -march=z15 -mflags-$(CONFIG_MARCH_Z16) := -march=z16 -mflags-$(CONFIG_MARCH_Z17) := -march=z17 +march-name-$(CONFIG_MARCH_Z10) := z10 +march-name-$(CONFIG_MARCH_Z196) := z196 +march-name-$(CONFIG_MARCH_ZEC12) := zEC12 +march-name-$(CONFIG_MARCH_Z13) := z13 +march-name-$(CONFIG_MARCH_Z14) := z14 +march-name-$(CONFIG_MARCH_Z15) := z15 +march-name-$(CONFIG_MARCH_Z16) := z16 +march-name-$(CONFIG_MARCH_Z17) := z17 -export CC_FLAGS_MARCH := $(mflags-y) +mflags := -march=$(march-name-y) -aflags-y += $(mflags-y) -cflags-y += $(mflags-y) +export CC_FLAGS_MARCH := $(mflags) + +aflags-y += $(mflags) +cflags-y += $(mflags) + +KBUILD_RUSTFLAGS += -Ctarget-cpu=$(march-name-y) cflags-$(CONFIG_MARCH_Z10_TUNE) += -mtune=z10 cflags-$(CONFIG_MARCH_Z196_TUNE) += -mtune=z196
rust/Makefile +1 -0
@@ -403,6 +403,7 @@ BINDGEN_TARGET_x86 := x86_64-linux-gnu BINDGEN_TARGET_arm64 := aarch64-linux-gnu BINDGEN_TARGET_arm := arm-linux-gnueabi BINDGEN_TARGET_loongarch := loongarch64-linux-gnusf +BINDGEN_TARGET_s390 := s390x-linux-gnu # This is only for i386 UM builds, which need the 32-bit target not -m32 BINDGEN_TARGET_i386 := i386-linux-gnu BINDGEN_TARGET_um := $(BINDGEN_TARGET_$(SUBARCH))
scripts/generate_rust_target.rs +2 -0
@@ -260,6 +260,8 @@ fn main() { } }else if cfg.has ("LOONGARCH" ) {panic! ("loongarch uses the builtin rustc loongarch64-unknown-none-softfloat target" ); + }else if cfg.has ("S390" ) { +panic! ("s390 uses the builtin rustc s390x-unknown-none-softfloat target" ); }else {panic! ("Unsupported architecture" ); }
scripts/min-tool-version.sh +5 -1
@@ -31,7 +31,11 @@ llvm) fi ;; rustc) - echo 1.85.0 + if [ "$SRCARCH" = "s390" ]; then + echo 1.96.0 + else + echo 1.85.0 + fi ;; bindgen) echo 0.71.1
Signature · 1 line
2.53.0
Gary Guo
reviewerRe: [PATCH v6 6/6] s390: Enable Rust support
Quoted 8 lines · Jan Polensky
Enable building Rust code on s390 by wiring the architecture into the kernel Rust infrastructure.
Add s390 to the Rust arch support documentation, provide the s390 Rust target and required compiler flags, and set the bindgen target for
arch/s390. Adjust the Rust target generation and minimum rustc version gating so the s390 setup is handled explicitly.
Quoted 6 lines
The Rust toolchain uses the "s390x" triple naming for the 64 bit target.
Rust support is currently incompatible with
CONFIG_EXPOLINE, which relies on compiler support for the -mindirect-branch= and -mfunction_return= options. Therefore, selectHAVE_RUSTonly when EXPOLINE is disabled.
Does -Zretpoline-external-thunk/-Zretpoline not work for s390? Rust will throw a warning saying that it doesn't recognize this for the target, but it looks like it does generate target features +retpoline-external-thunk,+retpoline-indirect-branches,+retpoline-indirect-calls in LLVM IR.
Best,
Gary
Quoted 126 lines
Acked-by Miguel Ojeda <[email protected]>Acked-by Heiko Carstens <[email protected]>Signed-off-by Jan Polensky <[email protected]>--- Documentation/rust/arch-support.rst | 1 + arch/s390/Kconfig | 1 + arch/s390/Makefile | 28 +++++++++++++++++----------- rust/Makefile | 1 + scripts/generate_rust_target.rs | 2 ++ scripts/min-tool-version.sh | 6 +++++- 6 files changed, 27 insertions(+), 12 deletions(-)Documentation/rust/arch-support.rst +1
-0@@ -19,6 +19,7 @@ Architecture Level of support Constraints ``arm64`` Maintained Little Endian only. ``loongarch`` Maintained \- ``riscv`` Maintained ``riscv64`` and LLVM/Clang only. +``s390`` Maintained ``CONFIG_EXPOLINE`` must be disabled. ``um`` Maintained \- ``x86`` Maintained ``x86_64`` only. ============= ================ ==============================================arch/s390/Kconfig +1
-0@@ -248,6 +248,7 @@ config S390 select HAVE_RELIABLE_STACKTRACE select HAVE_RETHOOK select HAVE_RSEQ + select HAVE_RUST if !EXPOLINE select HAVE_SAMPLE_FTRACE_DIRECT select HAVE_SAMPLE_FTRACE_DIRECT_MULTI select HAVE_SETUP_PER_CPU_AREAarch/s390/Makefile +17
-11@@ -35,25 +35,31 @@ KBUILD_CFLAGS_DECOMPRESSOR += $(if $(CONFIG_DEBUG_INFO),-g) KBUILD_CFLAGS_DECOMPRESSOR += $(if $(CONFIG_DEBUG_INFO_DWARF4), $(call cc-option, -gdwarf-4,)) KBUILD_CFLAGS_DECOMPRESSOR += $(if $(CONFIG_CC_NO_ARRAY_BOUNDS),-Wno-array-bounds) +KBUILD_RUSTFLAGS += --target=s390x-unknown-none-softfloat -Zpacked-stack -Ctarget-feature=+backchain + UTS_MACHINE := s390x STACK_SIZE := $(if $(CONFIG_KASAN),65536,$(if $(CONFIG_KMSAN),65536,16384)) CHECKFLAGS += -D__s390__ -D__s390x__ export LD_BFD -mflags-$(CONFIG_MARCH_Z10) := -march=z10 -mflags-$(CONFIG_MARCH_Z196) := -march=z196 -mflags-$(CONFIG_MARCH_ZEC12) := -march=zEC12 -mflags-$(CONFIG_MARCH_Z13) := -march=z13 -mflags-$(CONFIG_MARCH_Z14) := -march=z14 -mflags-$(CONFIG_MARCH_Z15) := -march=z15 -mflags-$(CONFIG_MARCH_Z16) := -march=z16 -mflags-$(CONFIG_MARCH_Z17) := -march=z17 +march-name-$(CONFIG_MARCH_Z10) := z10 +march-name-$(CONFIG_MARCH_Z196) := z196 +march-name-$(CONFIG_MARCH_ZEC12) := zEC12 +march-name-$(CONFIG_MARCH_Z13) := z13 +march-name-$(CONFIG_MARCH_Z14) := z14 +march-name-$(CONFIG_MARCH_Z15) := z15 +march-name-$(CONFIG_MARCH_Z16) := z16 +march-name-$(CONFIG_MARCH_Z17) := z17 -export CC_FLAGS_MARCH := $(mflags-y) +mflags := -march=$(march-name-y) -aflags-y += $(mflags-y) -cflags-y += $(mflags-y) +export CC_FLAGS_MARCH := $(mflags) + +aflags-y += $(mflags) +cflags-y += $(mflags) + +KBUILD_RUSTFLAGS += -Ctarget-cpu=$(march-name-y) cflags-$(CONFIG_MARCH_Z10_TUNE) += -mtune=z10 cflags-$(CONFIG_MARCH_Z196_TUNE) += -mtune=z196rust/Makefile +1
-0@@ -403,6 +403,7 @@ BINDGEN_TARGET_x86 := x86_64-linux-gnu BINDGEN_TARGET_arm64 := aarch64-linux-gnu BINDGEN_TARGET_arm := arm-linux-gnueabi BINDGEN_TARGET_loongarch := loongarch64-linux-gnusf +BINDGEN_TARGET_s390 := s390x-linux-gnu # This is only for i386 UM builds, which need the 32-bit target not -m32 BINDGEN_TARGET_i386 := i386-linux-gnu BINDGEN_TARGET_um := $(BINDGEN_TARGET_$(SUBARCH))scripts/generate_rust_target.rs +2
-0@@ -260,6 +260,8 @@ fn main() { } }else if cfg.has ("LOONGARCH" ) {panic! ("loongarch uses the builtin rustc loongarch64-unknown-none-softfloat target" ); + }else if cfg.has ("S390" ) { +panic! ("s390 uses the builtin rustc s390x-unknown-none-softfloat target" ); }else {panic! ("Unsupported architecture" ); }scripts/min-tool-version.sh +5
-1@@ -31,7 +31,11 @@ llvm) fi ;; rustc) - echo 1.85.0 + if [ "$SRCARCH" = "s390" ]; then + echo 1.96.0 + else + echo 1.85.0 + fi ;; bindgen) echo 0.71.1
Re: [PATCH v6 6/6] s390: Enable Rust support
Quoted 16 lines · Gary Guo
Quoted 8 lines · Jan Polensky
Enable building Rust code on s390 by wiring the architecture into the kernel Rust infrastructure.
Add s390 to the Rust arch support documentation, provide the s390 Rust target and required compiler flags, and set the bindgen target for
arch/s390. Adjust the Rust target generation and minimum rustc version gating so the s390 setup is handled explicitly.Quoted 6 lines
The Rust toolchain uses the "s390x" triple naming for the 64 bit target.
Rust support is currently incompatible with
CONFIG_EXPOLINE, which relies on compiler support for the -mindirect-branch= and -mfunction_return= options. Therefore, selectHAVE_RUSTonly when EXPOLINE is disabled.
Quoted 9 lines
Does
-Zretpoline-external-thunk/-Zretpolinenot work for s390? Rust will throw a warning saying that it doesn't recognize this for the target, but it looks like it does generate target features +retpoline-external-thunk,+retpoline-indirect-branches,+retpoline-indirect-calls in LLVM IR.Best,
Gary
Hi Gary,
thanks. The warning by itself does not prove the flags are ignored, since rustc may still forward unknown target features to the backend.
That said, s390 currently has no Rust/LLVM support for the EXPOLINE compiler support we rely on in C, and the kernel-side Rust retpoline handling is only wired up for x86/x86_64 today.
Backend support is planned, but has not been implemented yet. Until then, keeping Rust support gated behind !CONFIG_EXPOLINE is the intentional and conservative choice for this series.
Best,
Jan
Alexander Gordeev
maintainerRe: [PATCH v6 6/6] s390: Enable Rust support
On Mon, Jun 08, 2026 at 09:45:41PM +0200, Jan Polensky wrote:
Hi Gary!
...
Quoted 3 lines
Backend support is planned, but has not been implemented yet. Until then, keeping Rust support gated behind !CONFIG_EXPOLINE is the intentional and conservative choice for this series.
Is there anything in this series of concern to you?
Thanks!
Quoted 2 lines
Best,
Jan
Gary Guo
reviewerRe: [PATCH v6 6/6] s390: Enable Rust support
Quoted 6 lines · Alexander Gordeev
On Mon, Jun 08, 2026 at 09:45:41PM +0200, Jan Polensky wrote:
Hi Gary!
...
Quoted 7 lines
Quoted 3 lines
Backend support is planned, but has not been implemented yet. Until then, keeping Rust support gated behind !CONFIG_EXPOLINE is the intentional and conservative choice for this series.
Is there anything in this series of concern to you?
Thanks!
It looks okay to me. Feel free to add my acks for patches that don't have any yet.
Best,
Gary
Re: [PATCH v6 6/6] s390: Enable Rust support
In reply to Jan PolenskyHi all,
Quoted 18 lines · Jan Polensky
Enable building Rust code on s390 by wiring the architecture into the kernel Rust infrastructure.
Add s390 to the Rust arch support documentation, provide the s390 Rust target and required compiler flags, and set the bindgen target for
arch/s390. Adjust the Rust target generation and minimum rustc version gating so the s390 setup is handled explicitly.The Rust toolchain uses the "s390x" triple naming for the 64 bit target.
Rust support is currently incompatible with
CONFIG_EXPOLINE, which relies on compiler support for the -mindirect-branch= and -mfunction_return= options. Therefore, selectHAVE_RUSTonly when EXPOLINE is disabled.Acked-by Miguel Ojeda <[email protected]>Acked-by Heiko Carstens <[email protected]>Signed-off-by Jan Polensky <[email protected]>
...
arch/s390/Makefile KBUILD_CFLAGS_DECOMPRESSOR += $(if $(CONFIG_DEBUG_INFO),-g) · line 38
Quoted 9 lines
arch/s390/Makefile +1
-0@@ -35,25 +35,31 @@ KBUILD_CFLAGS_DECOMPRESSOR += $(if $(CONFIG_DEBUG_INFO),-g) KBUILD_CFLAGS_DECOMPRESSOR += $(if $(CONFIG_DEBUG_INFO_DWARF4), $(call cc-option, -gdwarf-4,)) KBUILD_CFLAGS_DECOMPRESSOR += $(if $(CONFIG_CC_NO_ARRAY_BOUNDS),-Wno-array-bounds) +KBUILD_RUSTFLAGS += --target=s390x-unknown-none-softfloat -Zpacked-stack -Ctarget-feature=+backchain
With Rust 1.96.0, I see the following warning several times when building Rust code in -next:
warning: unstable feature specified for -Ctarget-feature: backchain
|
= note: this feature is not stably supported; its behavior can change in the future
warning: 1 warning emitted
I assume this is expected? If so, is there a way to silence this warning?
Signature · 2 lines
Cheers, Nathan
Re: [PATCH v6 6/6] s390: Enable Rust support
Quoted 11 lines · Nathan Chancellor
With Rust 1.96.0, I see the following warning several times when building Rust code in -next:
warning: unstable feature specified for
-Ctarget-feature:backchain
|
= note: this feature is not stably supported; its behavior can change in the futurewarning: 1 warning emitted
I assume this is expected? If so, is there a way to silence this warning?
Yes, it seems so -- please see this thread:
If they are OK with it, then I guess it is fine, but it does mean CIs can suffer a bit from it.
I hope that helps.
Cheers,
Miguel
Re: [PATCH v6 6/6] s390: Enable Rust support
Quoted 13 lines · Miguel Ojeda
Quoted 11 lines · Nathan Chancellor
With Rust 1.96.0, I see the following warning several times when building Rust code in -next:
warning: unstable feature specified for
-Ctarget-feature:backchain
|
= note: this feature is not stably supported; its behavior can change in the futurewarning: 1 warning emitted
I assume this is expected? If so, is there a way to silence this warning?
Quoted 8 lines
Yes, it seems so -- please see this thread:
If they are OK with it, then I guess it is fine, but it does mean CIs can suffer a bit from it.
I hope that helps.
Ah, thanks for the pointer and sorry for the duplicate report. I have gone ahead and ignored this warning in my build reports for the time being.
Signature · 2 lines
Cheers, Nathan
Alice Ryhl
maintainerRe: [PATCH v6 6/6] s390: Enable Rust support
In reply to Miguel OjedaQuoted 11 lines · Miguel Ojeda
Quoted 10 lines · Nathan Chancellor
With Rust 1.96.0, I see the following warning several times when building Rust code in -next:
warning: unstable feature specified for
-Ctarget-feature:backchain
|
= note: this feature is not stably supported; its behavior can change in the futurewarning: 1 warning emitted
Quoted 8 lines
Quoted 1 line
I assume this is expected? If so, is there a way to silence this warning?
Yes, it seems so -- please see this thread:
If they are OK with it, then I guess it is fine, but it does mean CIs can suffer a bit from it.
Since fixing this requires a change in rustc to recognize the backchain target feature, has this work been started? I think that for stuff like this, we should make to at least start working on fixing the warning so that we don't emit a warning forever.
Alice
Re: [PATCH v6 6/6] s390: Enable Rust support
Quoted 5 lines · Alice Ryhl
Since fixing this requires a change in rustc to recognize the backchain target feature, has this work been started? I think that for stuff like this, we should make to at least start working on fixing the warning so that we don't emit a warning forever.
That is the expectation, yeah.
Jan et al.: for powerpc I have been accumulating the links etc. in
https://github.com/Rust-for-Linux/linux/issues/105 -- do you have similar links to the ongoing work for s390 so that I can fill the equivalent https://github.com/Rust-for-Linux/linux/issues/106?
Thanks!
Cheers,
Miguel
Re: [PATCH v6 6/6] s390: Enable Rust support
Quoted 14 lines · Miguel Ojeda
Quoted 5 lines · Alice Ryhl
Since fixing this requires a change in rustc to recognize the backchain target feature, has this work been started? I think that for stuff like this, we should make to at least start working on fixing the warning so that we don't emit a warning forever.
That is the expectation, yeah.
Jan et al.: for powerpc I have been accumulating the links etc. in
https://github.com/Rust-for-Linux/linux/issues/105 -- do you have similar links to the ongoing work for s390 so that I can fill the equivalent https://github.com/Rust-for-Linux/linux/issues/106?
Quoted 4 lines
Thanks!
Cheers,
Miguel
Hi Miguel,
thanks for raising this. We discussed the backchain warning today with the s390 compiler folks, and the plan is to move the backchain target feature into stable so we can support the kernel use case without carrying warnings indefinitely.
There is nothing public to point to just yet (no issue or tracking link yet), but the work is now owned on the IBM/s390 side. Eduard Stefens will take care of driving this forward from there.
So while we do not have a link to add today, the stabilization work is expected to happen.
Thanks,
Jan
Re: [PATCH v6 6/6] s390: Enable Rust support
Quoted 6 lines · Jan Polensky
thanks for raising this. We discussed the backchain warning today with the s390 compiler folks, and the plan is to move the backchain target feature into stable so we can support the kernel use case without carrying warnings indefinitely.
Quoted 6 lines
There is nothing public to point to just yet (no issue or tracking link yet), but the work is now owned on the IBM/s390 side. Eduard Stefens will take care of driving this forward from there.
So while we do not have a link to add today, the stabilization work is expected to happen.
Sounds good, thanks a lot!
Please let me know when you have something and I will update our usual live lists at https://github.com/Rust-for-Linux/linux/issues/2 etc.
I will mention it to the upstream Rust folks tomorrow in our regular call too so that they are aware.
Cheers,
Miguel