Rust support for powerpc
Subsystems (4)
v3 cover Rust support for powerpc
Enable experimental rust support for ppc64le and ppc32be. The patch for ppc32 has been provided by Link Mauve[1] and ppc64le support[2] has been merged over it. ppc32 needs some toolchain fixes mentioned in the patch rust: Add PowerPC support and the discussion for that is done here[1].
This has been tested on powernv9 hardware and power10 pseries qemu. I I request Link to test the ppc32 part as i don't have a hardware to test it out.
[1] https://lore.kernel.org/all/[email protected]
[2] https://lore.kernel.org/all/[email protected]
Changelog:
V2 -> V3:
- Splited HAVE_RUST in 2 lines
- BINDGEN_TARGET_powerpc initialized before assigning the same to BINDGEN_TARGET
V2: https://lore.kernel.org/all/[email protected]
V1 -> V2:
- jump label fix for rust has been moved to a separate patch
- PPC32 support has been taken
- rust support has been marked experimental
- target.json dependency has been removed
- HAVE_RUST now depends on CPU_LITTLE_ENDIAN for PPC64
Link Mauve (1):
rust: Add PowerPC support
Mukesh Kumar Chaurasiya (IBM) (2):
powerpc/jump_label: adjust inline asm to be consistent
powerpc: Enable Rust for ppc64le
Documentation/rust/arch-support.rst | 1 + arch/powerpc/Kconfig | 2 ++ arch/powerpc/Makefile | 9 +++++++++ arch/powerpc/include/asm/jump_label.h | 23 +++++++++++++---------- rust/Makefile | 12 +++++++++++- 5 files changed, 36 insertions(+), 11 deletions(-)
Signature · 1 line
2.52.0
PATCH v3 1/3 powerpc/jump_label: adjust inline asm to be consistent
Added support for a new macro ARCH_STATIC_BRANCH_ASM in powerpc
to avoid duplication of inline asm between C and Rust. This is
inline with commit aecaf181651c '("jump_label: adjust inline asm to be consistent")'
--- arch/powerpc/include/asm/jump_label.h | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-)
arch/powerpc/include/asm/jump_label.h +13 -10
@@ -15,14 +15,20 @@#define JUMP_ENTRY_TYPE stringify_in_c(FTR_ENTRY_LONG)#define JUMP_LABEL_NOP_SIZE 4 +#define JUMP_TABLE_ENTRY (key, label) \ + ".pushsection __jump_table, \"aw\" \n\t" \ + ".long 1b - ., " label " - . \n\t" \ + JUMP_ENTRY_TYPE key " - . \n\t" \ + ".popsection \n\t" + +#define ARCH_STATIC_BRANCH_ASM (key, label) \ + "1: nop \n\t" \ + JUMP_TABLE_ENTRY(key,label) + static __always_inline bool arch_static_branch(struct static_key *key, bool branch) { - asm goto("1:\n\t" -"nop # arch_static_branch\n\t" -".pushsection __jump_table, \"aw\"\n\t" -".long 1b - ., %l[l_yes] - .\n\t" -JUMP_ENTRY_TYPE "%c0 - .\n\t" -".popsection \n\t" + asm goto( + ARCH_STATIC_BRANCH_ASM("%c0", "%l[l_yes]") : : "i" (&((char *)key)[branch]) : : l_yes);return false;
@@ -34,10 +40,7 @@ static __always_inline bool arch_static_branch_jump(struct static_key *key, bool { asm goto("1:\n\t" "b %l[l_yes] # arch_static_branch_jump\n\t" -".pushsection __jump_table, \"aw\"\n\t" -".long 1b - ., %l[l_yes] - .\n\t" -JUMP_ENTRY_TYPE "%c0 - .\n\t" -".popsection \n\t" + JUMP_TABLE_ENTRY("%c0", "%l[l_yes]") : : "i" (&((char *)key)[branch]) : : l_yes);return false;
Signature · 1 line
2.52.0
PATCH v3 2/3 rust: Add PowerPC support
In reply to Mukesh Kumar Chaurasiya (IBM)From: Link Mauve <[email protected]>
For now only Big Endian 32-bit PowerPC is supported, as that is the only hardware I have. This has been tested on the Nintendo Wii so far, but I plan on also using it on the GameCube, Wii U and Apple G4.
These changes aren’t the only ones required to get the kernel to compile and link on PowerPC, libcore will also have to be changed to not use integer division to format u64, u128 and core::time::Duration, otherwise __udivdi3() and __umoddi3() will have to be added. I have tested this change by replacing the three implementations with unimplemented!() and it linked just fine.
--- Documentation/rust/arch-support.rst | 1 + arch/powerpc/Kconfig | 1 + arch/powerpc/Makefile | 2 ++ rust/Makefile | 4 +++- 4 files changed, 7 insertions(+), 1 deletion(-)
Documentation/rust/arch-support.rst +1 -0
@@ -18,6 +18,7 @@ Architecture Level of support Constraints ``arm`` Maintained ARMv7 Little Endian only. ``arm64`` Maintained Little Endian only. ``loongarch`` Maintained \- +``powerpc`` Experimental 32-bit Big Endian only. ``riscv`` Maintained ``riscv64`` and LLVM/Clang only. ``um`` Maintained \- ``x86`` Maintained ``x86_64`` only.
arch/powerpc/Kconfig +1 -0
@@ -283,6 +283,7 @@ config PPC select HAVE_REGS_AND_STACK_ACCESS_API select HAVE_RELIABLE_STACKTRACE select HAVE_RSEQ + select HAVE_RUST if PPC32 select HAVE_SAMPLE_FTRACE_DIRECT if HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS select HAVE_SAMPLE_FTRACE_DIRECT_MULTI if HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS select HAVE_SETUP_PER_CPU_AREA if PPC64
arch/powerpc/Makefile +2 -0
@@ -61,6 +61,8 @@ else KBUILD_LDFLAGS_MODULE += $(objtree)/arch/powerpc/lib/crtsavres.o endif +KBUILD_RUSTFLAGS += --target=powerpc-unknown-linux-gnu + ifdef CONFIG_CPU_LITTLE_ENDIAN KBUILD_CPPFLAGS += -mlittle-endian KBUILD_LDFLAGS += -EL
rust/Makefile +3 -1
@@ -384,13 +384,15 @@ bindgen_skip_c_flags := -mno-fp-ret-in-387 -mpreferred-stack-boundary=% \ -fstrict-flex-arrays=% -fmin-function-alignment=% \ -fzero-init-padding-bits=% -mno-fdpic \ -fdiagnostics-show-context -fdiagnostics-show-context=% \ - --param=% --param asan-% -fno-isolate-erroneous-paths-dereference + --param=% --param asan-% -fno-isolate-erroneous-paths-dereference \ + -ffixed-r2 -mmultiple -mno-readonly-in-sdata # Derived from `scripts/Makefile.clang`. 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_powerpc := powerpc-linux-gnu BINDGEN_TARGET_um := $(BINDGEN_TARGET_$(SUBARCH)) BINDGEN_TARGET := $(BINDGEN_TARGET_$(SRCARCH))
Signature · 1 line
2.52.0
PATCH v3 3/3 powerpc: Enable Rust for ppc64le
In reply to Mukesh Kumar Chaurasiya (IBM)Enabling rust support for ppc64le only.
Tested on powernv9:
$ uname -rm 6.19.0-rc8+ ppc64le
$ sudo modprobe rust_minimal [ 632.890850] rust_minimal: Rust minimal sample (init) [ 632.890881] rust_minimal: Am I built-in? false [ 632.890898] rust_minimal: test_parameter: 1
$ sudo rmmod rust_minimal [ 648.272832] rust_minimal: My numbers are [72, 108, 200] [ 648.272873] rust_minimal: Rust minimal sample (exit)
$ sudo modprobe rust_print [ 843.410391] rust_print: Rust printing macros sample (init) [ 843.410424] rust_print: Emergency message (level 0) without args [ 843.410451] rust_print: Alert message (level 1) without args [ 843.410477] rust_print: Critical message (level 2) without args [ 843.410503] rust_print: Error message (level 3) without args [ 843.410530] rust_print: Warning message (level 4) without args [ 843.410557] rust_print: Notice message (level 5) without args [ 843.410594] rust_print: Info message (level 6) without args [ 843.410617] rust_print: A line that is continued without args [ 843.410646] rust_print: Emergency message (level 0) with args [ 843.410675] rust_print: Alert message (level 1) with args [ 843.410691] rust_print: Critical message (level 2) with args [ 843.410727] rust_print: Error message (level 3) with args [ 843.410761] rust_print: Warning message (level 4) with args [ 843.410796] rust_print: Notice message (level 5) with args [ 843.410821] rust_print: Info message (level 6) with args [ 843.410854] rust_print: A line that is continued with args [ 843.410892] rust_print: 1 [ 843.410895] rust_print: "hello, world" [ 843.410924] rust_print: [samples/rust/rust_print_main.rs:35:5] c = "hello, world" [ 843.410977] rust_print: Arc<dyn Display> says 42 [ 843.410979] rust_print: Arc<dyn Display> says hello, world
$ sudo rmmod rust_print [ 843.411003] rust_print: "hello, world" [ 888.499935] rust_print: Rust printing macros sample (exit)
--- Documentation/rust/arch-support.rst | 2 +- arch/powerpc/Kconfig | 1 + arch/powerpc/Makefile | 9 ++++++++- rust/Makefile | 8 ++++++++ 4 files changed, 18 insertions(+), 2 deletions(-)
Documentation/rust/arch-support.rst +1 -1
@@ -18,7 +18,7 @@ Architecture Level of support Constraints ``arm`` Maintained ARMv7 Little Endian only. ``arm64`` Maintained Little Endian only. ``loongarch`` Maintained \- -``powerpc`` Experimental 32-bit Big Endian only. +``powerpc`` Experimental 64-bit Little Endian. 32-bit Big Endian. ``riscv`` Maintained ``riscv64`` and LLVM/Clang only. ``um`` Maintained \- ``x86`` Maintained ``x86_64`` only.
arch/powerpc/Kconfig +1 -0
@@ -284,6 +284,7 @@ config PPC select HAVE_RELIABLE_STACKTRACE select HAVE_RSEQ select HAVE_RUST if PPC32 + select HAVE_RUST if PPC64 && CPU_LITTLE_ENDIAN select HAVE_SAMPLE_FTRACE_DIRECT if HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS select HAVE_SAMPLE_FTRACE_DIRECT_MULTI if HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS select HAVE_SETUP_PER_CPU_AREA if PPC64
arch/powerpc/Makefile +8 -1
@@ -61,7 +61,14 @@ else KBUILD_LDFLAGS_MODULE += $(objtree)/arch/powerpc/lib/crtsavres.o endif -KBUILD_RUSTFLAGS += --target=powerpc-unknown-linux-gnu +ifdef CONFIG_PPC64 +ifdef CONFIG_CPU_LITTLE_ENDIAN +KBUILD_RUSTFLAGS += --target=powerpc64le-unknown-linux-gnu +endif +KBUILD_RUSTFLAGS += -Ctarget-feature=-mma,-vsx,-hard-float,-altivec +else +KBUILD_RUSTFLAGS += --target=powerpc-unknown-linux-gnu +endif ifdef CONFIG_CPU_LITTLE_ENDIAN KBUILD_CPPFLAGS += -mlittle-endian
rust/Makefile +8 -0
@@ -392,7 +392,15 @@ 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 + +ifdef CONFIG_PPC64 +ifdef CONFIG_CPU_LITTLE_ENDIAN +BINDGEN_TARGET_powerpc := powerpc64le-linux-gnu +endif +else BINDGEN_TARGET_powerpc := powerpc-linux-gnu +endif + BINDGEN_TARGET_um := $(BINDGEN_TARGET_$(SUBARCH)) BINDGEN_TARGET := $(BINDGEN_TARGET_$(SRCARCH))
Signature · 1 line
2.52.0
Quoted 37 lines · Mukesh Kumar Chaurasiya (IBM)
Enable experimental rust support for ppc64le and ppc32be. The patch for ppc32 has been provided by Link Mauve[1] and ppc64le support[2] has been merged over it. ppc32 needs some toolchain fixes mentioned in the patch
rust: Add PowerPC supportand the discussion for that is done here[1].This has been tested on powernv9 hardware and power10 pseries qemu. I I request Link to test the ppc32 part as i don't have a hardware to test it out.
[1] https://lore.kernel.org/all/[email protected]
[2] https://lore.kernel.org/all/[email protected]Changelog:
V2 -> V3:
- SplitedHAVE_RUSTin 2 lines
-BINDGEN_TARGET_powerpcinitialized before assigning the same toBINDGEN_TARGET
V2: https://lore.kernel.org/all/[email protected]V1 -> V2:
- jump label fix for rust has been moved to a separate patch
- PPC32 support has been taken
- rust support has been marked experimental
- target.json dependency has been removed
-HAVE_RUSTnow depends onCPU_LITTLE_ENDIANfor PPC64Link Mauve (1):
rust: Add PowerPC supportMukesh Kumar Chaurasiya (IBM) (2):
powerpc/jump_label: adjust inline asm to be consistent
powerpc: Enable Rust for ppc64le
Quoted 10 lines
Documentation/rust/arch-support.rst | 1 + arch/powerpc/Kconfig | 2 ++ arch/powerpc/Makefile | 9 +++++++++ arch/powerpc/include/asm/jump_label.h | 23 +++++++++++++---------- rust/Makefile | 12 +++++++++++- 5 files changed, 36 insertions(+), 11 deletions(-)Signature · 1 line
2.52.0
Tested this patch set, by applying on mainline kernel. Attached is the .config file used.
Please add below tag.
Logs:
rustc --version
rustc 1.95.0-nightly (e96bb7e44 2026-01-27)
llvm-18.1.8-3.el9.ppc64le
sudo insmod samples/rust/rust_minimal.ko
[ 39.532119] rust_minimal: loading out-of-tree module taints kernel. [ 39.532132] rust_minimal: module verification failed: signature and/or required key missing - tainting kernel [ 39.532856] rust_minimal: Rust minimal sample (init) [ 39.532860] rust_minimal: Am I built-in? false [ 39.532864] rust_minimal: test_parameter: 1 # dmesg | tail -n 30 [ 3.418850] systemd[1]: Mounted Kernel Trace File System. [ 3.419194] systemd[1]: Finished Create List of Static Device Nodes. [ 3.419482] systemd[1]: [email protected]: Deactivated successfully. [ 3.419647] systemd[1]: Finished Load Kernel Module configfs. [ 3.419913] systemd[1]: [email protected]: Deactivated successfully. [ 3.420056] systemd[1]: Finished Load Kernel Module drm. [ 3.420405] systemd[1]: Finished Read and set NIS domainname from /etc/sysconfig/network. [ 3.420694] systemd[1]: Finished Generate network units from Kernel command line. [ 3.422214] systemd[1]: Mounting Kernel Configuration File System... [ 3.423543] systemd[1]: Finished Apply Kernel Variables. [ 3.424011] systemd[1]: Mounted Kernel Configuration File System. [ 3.430589] systemd[1]: Started Journal Service. [ 3.477706] fuse: init (API version 7.45) [ 3.548678] EXT4-fs (sda3): re-mounted 78691517-64fe-451b-9009-14359b774643 r/w. [ 3.556791] systemd-journald[640]: Received client request to flush runtime journal. [ 3.681167] Adding 10485696k swap on /dev/sda2. Priority:-1 extents:1 across:10485696k SS [ 3.693490] pseries_rng: Registering IBM pSeries RNG driver [ 3.693904] cryptd: max_cpu_qlen set to 1000 [ 4.702590] RPC: Registered named UNIX socket transport module. [ 4.702604] RPC: Registered udp transport module. [ 4.702607] RPC: Registered tcp transport module. [ 4.702609] RPC: Registered tcp-with-tls transport module. [ 4.702612] RPC: Registered tcp NFSv4.1 backchannel transport module. [ 6.701147] block sda: the capability attribute has been deprecated. [ 10.150485] fbcon: Taking over console [ 39.532119] rust_minimal: loading out-of-tree module taints kernel. [ 39.532132] rust_minimal: module verification failed: signature and/or required key missing - tainting kernel [ 39.532856] rust_minimal: Rust minimal sample (init) [ 39.532860] rust_minimal: Am I built-in? false [ 39.532864] rust_minimal: test_parameter: 1 # sudo rmmod rust_minimal [ 4125.461822] rust_minimal: My numbers are [72, 108, 200] [ 4125.461839] rust_minimal: Rust minimal sample (exit) # sudo insmod samples/rust/rust_print.ko [ 4142.492146] rust_print: Rust printing macros sample (init) [ 4142.492158] rust_print: Emergency message (level 0) without args [ 4142.492161] rust_print: Alert message (level 1) without args [ 4142.492163] rust_print: Critical message (level 2) without args [ 4142.492166] rust_print: Error message (level 3) without args [ 4142.492169] rust_print: Warning message (level 4) without args [ 4142.492171] rust_print: Notice message (level 5) without args [ 4142.492174] rust_print: Info message (level 6) without args [ 4142.492176] rust_print: A line that is continued without args [ 4142.492181] rust_print: Emergency message (level 0) with args [ 4142.492185] rust_print: Alert message (level 1) with args [ 4142.492188] rust_print: Critical message (level 2) with args [ 4142.492190] rust_print: Error message (level 3) with args [ 4142.492193] rust_print: Warning message (level 4) with args [ 4142.492195] rust_print: Notice message (level 5) with args [ 4142.492197] rust_print: Info message (level 6) with args [ 4142.492200] rust_print: A line that is continued with args [ 4142.492205] rust_print: 1 [ 4142.492206] rust_print: "hello, world" [ 4142.492208] rust_print: [rust_print_main.rs:35:5] c = "hello, world" [ 4142.492213] rust_print: Arc<dyn Display> says 42 [ 4142.492214] rust_print: Arc<dyn Display> says hello, world # dmesg | tail -n 50 [ 3.419913] systemd[1]: [email protected]: Deactivated successfully. [ 3.420056] systemd[1]: Finished Load Kernel Module drm. [ 3.420405] systemd[1]: Finished Read and set NIS domainname from /etc/sysconfig/network. [ 3.420694] systemd[1]: Finished Generate network units from Kernel command line. [ 3.422214] systemd[1]: Mounting Kernel Configuration File System... [ 3.423543] systemd[1]: Finished Apply Kernel Variables. [ 3.424011] systemd[1]: Mounted Kernel Configuration File System. [ 3.430589] systemd[1]: Started Journal Service. [ 3.477706] fuse: init (API version 7.45) [ 3.548678] EXT4-fs (sda3): re-mounted 78691517-64fe-451b-9009-14359b774643 r/w. [ 3.556791] systemd-journald[640]: Received client request to flush runtime journal. [ 3.681167] Adding 10485696k swap on /dev/sda2. Priority:-1 extents:1 across:10485696k SS [ 3.693490] pseries_rng: Registering IBM pSeries RNG driver [ 3.693904] cryptd: max_cpu_qlen set to 1000 [ 4.702590] RPC: Registered named UNIX socket transport module. [ 4.702604] RPC: Registered udp transport module. [ 4.702607] RPC: Registered tcp transport module. [ 4.702609] RPC: Registered tcp-with-tls transport module. [ 4.702612] RPC: Registered tcp NFSv4.1 backchannel transport module. [ 6.701147] block sda: the capability attribute has been deprecated. [ 10.150485] fbcon: Taking over console [ 39.532119] rust_minimal: loading out-of-tree module taints kernel. [ 39.532132] rust_minimal: module verification failed: signature and/or required key missing - tainting kernel [ 39.532856] rust_minimal: Rust minimal sample (init) [ 39.532860] rust_minimal: Am I built-in? false [ 39.532864] rust_minimal: test_parameter: 1 [ 4125.461822] rust_minimal: My numbers are [72, 108, 200] [ 4125.461839] rust_minimal: Rust minimal sample (exit) [ 4142.492146] rust_print: Rust printing macros sample (init) [ 4142.492158] rust_print: Emergency message (level 0) without args [ 4142.492161] rust_print: Alert message (level 1) without args [ 4142.492163] rust_print: Critical message (level 2) without args [ 4142.492166] rust_print: Error message (level 3) without args [ 4142.492169] rust_print: Warning message (level 4) without args [ 4142.492171] rust_print: Notice message (level 5) without args [ 4142.492174] rust_print: Info message (level 6) without args [ 4142.492176] rust_print: A line that is continued without args [ 4142.492181] rust_print: Emergency message (level 0) with args [ 4142.492185] rust_print: Alert message (level 1) with args [ 4142.492188] rust_print: Critical message (level 2) with args [ 4142.492190] rust_print: Error message (level 3) with args [ 4142.492193] rust_print: Warning message (level 4) with args [ 4142.492195] rust_print: Notice message (level 5) with args [ 4142.492197] rust_print: Info message (level 6) with args [ 4142.492200] rust_print: A line that is continued with args [ 4142.492205] rust_print: 1 [ 4142.492206] rust_print: "hello, world" [ 4142.492208] rust_print: [rust_print_main.rs:35:5] c = "hello, world" [ 4142.492213] rust_print: Arc<dyn Display> says 42 [ 4142.492214] rust_print: Arc<dyn Display> says hello, world # sudo rmmod rust_print [ 4142.492217] rust_print: "hello, world" [ 4153.334714] rust_print: Rust printing macros sample (exit)
# sudo rmmod rust_debugfs
Regards,
Venkat.