Merge branch 'rust-for-s390' into features

Jan Polensky says:

===================
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.

Link: https://github.com/Rust-for-Linux/linux/issues/2

Tested against: rustc 1.96.0 (ac68faa20 2026-05-25)
===================

Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
This commit is contained in:
Alexander Gordeev committed 2026-06-10 16:53:23 +02:00
commit 982c89c9b9
12 files changed
+80 -30

No files matched your search

+1
View File
@@ -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.
============= ================ ==============================================
+1
View File
@@ -249,6 +249,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
+17 -11
View File
@@ -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
+12
View File
@@ -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__ */
+4 -4
View File
@@ -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;
+19 -14
View File
@@ -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 @@ label:
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;
+3
View File
@@ -403,6 +403,9 @@ 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))
BINDGEN_TARGET := $(BINDGEN_TARGET_$(SRCARCH))
+7
View File
@@ -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.
+1
View File
@@ -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"
+8
View File
@@ -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);
}
+2
View File
@@ -256,6 +256,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");
}
+5 -1
View File
@@ -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