]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
s390: Enable Rust support
authorJan Polensky <japo@linux.ibm.com>
Mon, 1 Jun 2026 17:46:25 +0000 (19:46 +0200)
committerAlexander Gordeev <agordeev@linux.ibm.com>
Wed, 10 Jun 2026 14:25:13 +0000 (16:25 +0200)
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, select HAVE_RUST only when
EXPOLINE is disabled.

Acked-by: Miguel Ojeda <ojeda@kernel.org>
Acked-by: Gary Guo <gary@garyguo.net>
Acked-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Jan Polensky <japo@linux.ibm.com>
Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
Documentation/rust/arch-support.rst
arch/s390/Kconfig
arch/s390/Makefile
rust/Makefile
scripts/generate_rust_target.rs
scripts/min-tool-version.sh

index 6e6a515d08991a130a8e79dc4ad7ad09da244020..4f980815e92a001f8d4de140277b7efebcedac1d 100644 (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.
 =============  ================  ==============================================
index ecbcbb781e40aa8cf3b0ef160b447bcb51eafde2..26951781d74dbb16ea65faa4dfca7f77125653be 100644 (file)
@@ -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
index 297976b4108864bada24e505b078404b9e58789e..8b712cd85fcd3c14ee0c821548ec469e0bbfc451 100644 (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
+
+mflags := -march=$(march-name-y)
+
+export CC_FLAGS_MARCH := $(mflags)
 
-export CC_FLAGS_MARCH := $(mflags-y)
+aflags-y += $(mflags)
+cflags-y += $(mflags)
 
-aflags-y += $(mflags-y)
-cflags-y += $(mflags-y)
+KBUILD_RUSTFLAGS += -Ctarget-cpu=$(march-name-y)
 
 cflags-$(CONFIG_MARCH_Z10_TUNE)                += -mtune=z10
 cflags-$(CONFIG_MARCH_Z196_TUNE)       += -mtune=z196
index b9e9f512cec3143a9ed69cbb4fbb286ebaab5a3f..77460502f5764a3b402fcacb351dd0b747d74d66 100644 (file)
@@ -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))
index 38b3416bb9799e201b7cdc666a801f4494ecbcb1..8f1df6819d0b17b2380550ac11fdb96d0b13d13c 100644 (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");
     }
index b96ec2d379b6322f1c08a232e23ec3fcc3f36d47..296acf8f71aa8374e842f575bf31a30a5f3a9217 100755 (executable)
@@ -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