Rust Support for powerpc
Subsystems (3)
v17 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
- pseries P11 hardware
- pseries(9, 10) qemu
- powernv(9, 10) qemu
- rustdoc on x86 and powerpc64le
- rusttest on x86 and powerpc64le
We are actively working with our LLVM team to get the target for ppc, ppc64 and ppc64le in the rust compiler.
[1] https://lore.kernel.org/all/[email protected]
[2] https://lore.kernel.org/all/[email protected]
Changelog:
V16 -> V17:
- Rebased to latest v7.2-rc2
V15 -> V16:
- Rebased to latest v7.1-rc4
V15: https://lore.kernel.org/all/[email protected]/
V14 -> V15:
- Fix an issue with rustdoc build on ppc64le
V14: https://lore.kernel.org/all/[email protected]/
V13 -> V14:
- 2nd patch is rewritten (Christian)
- Fixed a small typo in rust/Makefile (Sashiko)
- Fixed commit message in Patch 4 (Sashiko)
V13: https://lore.kernel.org/all/[email protected]/
V12 -> V13:
- Added a patch for fixing build issue on ppc32 by Link Mauve
- Added another patch to fix a build issue in dma-buf
- Added another patch to enforce minimum rustc version for powerpc
V12: https://lore.kernel.org/all/[email protected]/
V11 -> V12:
- Rebased to mainline (rust/Makefile conflict resolved)
V11: https://lore.kernel.org/all/[email protected]/
V10 -> V11:
- Updated rust/Makefile
- Not all libraries are move to rust/host directory now. Only proc_macro2, quote and syn are moved
- Special handling for pin init is added. Details in commit
- Removed mkdir for rust/host, this is now handled by toolchain.
V10: https://lore.kernel.org/all/[email protected]/
V9 -> V10:
- rust/Makefile updated with review comments from Miguel
- Patch 1/4 updated with commit message and subject
V9: https://lore.kernel.org/all/[email protected]/
V8 -> V9:
- rust/Makefile updated with a directory instead of abspath
V8: https://lore.kernel.org/all/[email protected]/
V7 -> V8:
- rust/Makefile updated to separate host libraries from target
V7: https://lore.kernel.org/all/[email protected]/
Changelog:
V6 -> V7:
- Documentation removed as powerpc is still under development
- Added a fix for race condition in rust/Makefile
V6: https://lore.kernel.org/all/[email protected]
V5 -> V6:
- Added a missing Tested by from Venkat which got missed since V3
- Support is marked as Maintained instead of experimental
V5: https://lore.kernel.org/all/[email protected]
V4 -> V5:
- Removed a nested ifdef from PPC64 for Little endian toolchain
V4: https://lore.kernel.org/all/[email protected]
V3 -> V4:
- Co-developed-by header added in patch 1
V3: https://lore.kernel.org/all/[email protected]
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
V1: https://lore.kernel.org/all/[email protected]
Link Mauve (2):
rust: Make __udivdi3() and __umoddi3() panic
rust: Add PowerPC support
Mukesh Kumar Chaurasiya (IBM) (6):
powerpc/syscall: Fix syscall skip handling for seccomp and ptrace
rust: Fix "multiple candidates for rmeta dependency core" error
dma-resv: Fix undefined symbol when CONFIG_DMA_SHARED_BUFFER is
disabled
powerpc/jump_label: adjust inline asm to be consistent rust/powerpc: Set min rustc version for powerpc
powerpc: Enable Rust for ppc64le
arch/powerpc/Kconfig | 2 + arch/powerpc/Makefile | 7 ++++ arch/powerpc/include/asm/jump_label.h | 23 ++++++----- arch/powerpc/include/asm/ptrace.h | 22 +++++++++- arch/powerpc/include/asm/syscall.h | 6 +++ arch/powerpc/include/uapi/asm/ptrace.h | 6 ++- arch/powerpc/kernel/ptrace/ptrace.c | 2 + arch/powerpc/kernel/syscall.c | 18 +++++++++ rust/Makefile | 56 +++++++++++++++++--------- rust/compiler_builtins.rs | 6 +++ rust/helpers/helpers.c | 2 + scripts/min-tool-version.sh | 2 + 12 files changed, 119 insertions(+), 33 deletions(-)
Signature · 1 line
2.55.0
PATCH v17 1/8 powerpc/syscall: Fix syscall skip handling for seccomp and ptrace
After enabling GENERIC_ENTRY on PowerPC, syscall_enter_from_user_mode() returns -1 as a sentinel to signal that seccomp or ptrace has intercepted the syscall and already set a return value via syscall_set_return_value(). system_call_exception() was not handling this sentinel, and since -1UL is >= NR_syscalls, the code fell into the out-of-range path and returned -ENOSYS, overwriting the errno already placed in regs->gpr[3].
The naive fix of checking r0 == -1L before the NR_syscalls bounds check is ambiguous: a user legitimately calling syscall(-1) also produces r0 == -1L, and a tracer intercepting such a call would have its injected return value silently discarded.
Fix this properly by introducing regs->entry_flags, a kernel-internal field in struct pt_regs (consuming one slot of the existing __pt_regs_pad so the ABI is preserved), with SYSCALL_ENTRY_RET_SET as an out-of-band flag. syscall_set_return_value() sets this flag whenever seccomp or ptrace injects a return value. system_call_exception() zeros entry_flags before calling syscall_enter_from_user_mode(), then checks and clears the flag
afterwards: if set, it returns regs->gpr[3] directly regardless of what syscall number the user originally requested.
This handles all seccomp actions correctly:
- SECCOMP_RET_ERRNO, SECCOMP_RET_TRACE (no tracer), SECCOMP_RET_USER_NOTIF:
all call syscall_set_return_value(), flag is set, injected value returned.
- SECCOMP_RET_TRAP, SECCOMP_RET_KILL: call syscall_rollback() and deliver a signal; flag is not set, but the process is dying so the return value is irrelevant.
The fix covers both ppc32 and ppc64 with no #ifdefs.
--- arch/powerpc/include/asm/ptrace.h | 22 +++++++++++++++++++++- arch/powerpc/include/asm/syscall.h | 6 ++++++ arch/powerpc/include/uapi/asm/ptrace.h | 6 ++++-- arch/powerpc/kernel/ptrace/ptrace.c | 2 ++ arch/powerpc/kernel/syscall.c | 18 ++++++++++++++++++ 5 files changed, 51 insertions(+), 3 deletions(-)
arch/powerpc/include/asm/ptrace.h +21 -1
@@ -54,8 +54,9 @@ struct pt_regs };unsigned long result;unsigned long exit_flags; +unsigned long entry_flags;/* Maintain 16 byte interrupt stack alignment */ -unsigned long __pt_regs_pad[3 ]; +unsigned long __pt_regs_pad[2 ]; }; };#if defined(CONFIG_PPC64 ) || defined(CONFIG_PPC_KUAP )
@@ -233,6 +234,25 @@ static inline unsigned long frame_pointer(struct pt_regs *regs)#define current_pt_regs () \ ((struct pt_regs *)((unsigned long)task_stack_page(current) + THREAD_SIZE) - 1) +/* +* SYSCALL_ENTRY_RET_SET: seccomp or ptrace called syscall_set_return_value() +* and wants the syscall skipped; regs->gpr[3] already holds the return value. +*/ +#define SYSCALL_ENTRY_RET_SET BIT(0) + +static inline void set_syscall_entry_ret (struct pt_regs *regs) +{ + regs->entry_flags |=SYSCALL_ENTRY_RET_SET ; +} + +static inline bool test_and_clear_syscall_entry_ret (struct pt_regs *regs) +{ +bool set = !!(regs->entry_flags &SYSCALL_ENTRY_RET_SET ); + + regs->entry_flags &= ~SYSCALL_ENTRY_RET_SET ; +return set; +} +/* * The 4 low bits (0xf) are available as flags to overload the trap word, * because interrupt vectors have minimum alignment of 0x10. TRAP_FLAGS_MASK
arch/powerpc/include/asm/syscall.h +6 -0
@@ -98,6 +98,12 @@ static inline void syscall_set_return_value(struct task_struct *task, regs->gpr[3 ] = val; } } +/* +* Mark that a return value has been explicitly set by seccomp or +* ptrace so that system_call_exception() can skip the syscall +* unconditionally, even when the user requested syscall(-1). +*/ +set_syscall_entry_ret (regs); } static inline void syscall_get_arguments(struct task_struct *task,
arch/powerpc/include/uapi/asm/ptrace.h +4 -2
@@ -56,7 +56,8 @@ struct pt_regsunsigned long dsisr;/* on 4xx/Book-E used for ESR */ unsigned long result;/* Result of a system call */ unsigned long exit_flags;/* System call exit flags */ - unsigned long __pt_regs_pad[3]; /* Maintain 16 byte interrupt stack alignment */ +unsigned long entry_flags;/* System call entry flags */ + unsigned long __pt_regs_pad[2]; /* Maintain 16 byte interrupt stack alignment */ };#endif /* __ASSEMBLER__ */
@@ -117,7 +118,8 @@ struct pt_regs#define PT_DSISR 42#define PT_RESULT 43#define PT_EXIT_FLAGS 44 -#define PT_PAD 47/* 3 times */ +#define PT_ENTRY_FLAGS 45 +#define PT_PAD 46/* 2 times */ #define PT_DSCR 48#define PT_REGS_COUNT 48
arch/powerpc/kernel/ptrace/ptrace.c +2 -0
@@ -235,6 +235,8 @@ void __init pt_regs_check(void) offsetof(struct user_pt_regs, dsisr));BUILD_BUG_ON (offsetof(struct pt_regs , result) != offsetof(struct user_pt_regs , result)); +BUILD_BUG_ON (offsetof(struct pt_regs , entry_flags) != + offsetof(struct user_pt_regs , entry_flags));BUILD_BUG_ON (sizeof (struct user_pt_regs ) >sizeof (struct pt_regs ));
arch/powerpc/kernel/syscall.c +18 -0
@@ -19,9 +19,27 @@ notrace long system_call_exception(struct pt_regs *regs, unsigned long r0)long ret;syscall_fn f; +/* +* Zero entry_flags before syscall_enter_from_user_mode() so that +* syscall_set_return_value() can set SYSCALL_ENTRY_RET_SET as an +* unambiguous out-of-band signal. The field is not initialised by +* the entry assembly. +*/ + regs->entry_flags =0 ;add_random_kstack_offset (); r0 =syscall_enter_from_user_mode (regs, r0); +/* +* Seccomp or ptrace may have set a return value and requested that +* the syscall be skipped. syscall_set_return_value() sets +* SYSCALL_ENTRY_RET_SET in regs->entry_flags as an +* unambiguous out-of-band signal. This avoids the ambiguity of +* using r0 == -1 as the skip sentinel when the user themselves +* called syscall(-1). +*/ +if (unlikely (test_and_clear_syscall_entry_ret (regs))) +return syscall_get_error (current, regs); +if (unlikely (r0 >= NR_syscalls)) {if (unlikely (trap_is_unsupported_scv (regs))) {/* Unsupported scv vector */
Signature · 1 line
2.55.0
Quoted 114 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
- pseries P11 hardware
-pseries(9, 10)qemu
-powernv(9, 10)qemu
- rustdoc on x86 and powerpc64le
- rusttest on x86 and powerpc64leWe are actively working with our LLVM team to get the target for ppc, ppc64 and ppc64le in the rust compiler.
[1] https://lore.kernel.org/all/[email protected]
[2] https://lore.kernel.org/all/[email protected]Changelog:
V16 -> V17:
- Rebased to latest v7.2-rc2V15 -> V16:
- Rebased to latest v7.1-rc4
V15: https://lore.kernel.org/all/[email protected]/V14 -> V15:
- Fix an issue with rustdoc build on ppc64le
V14: https://lore.kernel.org/all/[email protected]/V13 -> V14:
- 2nd patch is rewritten (Christian)
- Fixed a small typo inrust/Makefile(Sashiko)
- Fixed commit message in Patch 4 (Sashiko)
V13: https://lore.kernel.org/all/[email protected]/V12 -> V13:
- Added a patch for fixing build issue on ppc32 by Link Mauve
- Added another patch to fix a build issue in dma-buf
- Added another patch to enforce minimumrustcversion for powerpc
V12: https://lore.kernel.org/all/[email protected]/V11 -> V12:
- Rebased to mainline (rust/Makefileconflict resolved)
V11: https://lore.kernel.org/all/[email protected]/V10 -> V11:
- Updatedrust/Makefile
- Not all libraries are move torust/hostdirectory now. Onlyproc_macro2, quote and syn are moved
- Special handling for pin init is added. Details in commit
- Removed mkdir forrust/host, this is now handled by toolchain.
V10: https://lore.kernel.org/all/[email protected]/V9 -> V10:
-rust/Makefileupdated with review comments from Miguel
- Patch 1/4 updated with commit message and subject
V9: https://lore.kernel.org/all/[email protected]/V8 -> V9:
-rust/Makefileupdated with a directory instead of abspath
V8: https://lore.kernel.org/all/[email protected]/V7 -> V8:
-rust/Makefileupdated to separate host libraries from target
V7: https://lore.kernel.org/all/[email protected]/Changelog:
V6 -> V7:
- Documentation removed as powerpc is still under development
- Added a fix for race condition inrust/Makefile
V6: https://lore.kernel.org/all/[email protected]V5 -> V6:
- Added a missing Tested by from Venkat which got missed since V3
- Support is marked as Maintained instead of experimental
V5: https://lore.kernel.org/all/[email protected]V4 -> V5:
- Removed a nested ifdef from PPC64 for Little endian toolchain
V4: https://lore.kernel.org/all/[email protected]V3 -> V4:
- Co-developed-by header added in patch 1
V3: https://lore.kernel.org/all/[email protected]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 PPC64
V1: https://lore.kernel.org/all/[email protected]Link Mauve (2):
rust: Make__udivdi3()and__umoddi3()panic
rust: Add PowerPC supportMukesh Kumar Chaurasiya (IBM) (6):
powerpc/syscall: Fix syscall skip handling for seccomp and ptrace
rust: Fix "multiple candidates for rmeta dependency core" error
dma-resv: Fix undefined symbol whenCONFIG_DMA_SHARED_BUFFERis
disabled
powerpc/jump_label: adjust inline asm to be consistentrust/powerpc: Set min rustc version for powerpc
powerpc: Enable Rust for ppc64le
Quoted 17 lines
arch/powerpc/Kconfig | 2 + arch/powerpc/Makefile | 7 ++++ arch/powerpc/include/asm/jump_label.h | 23 ++++++----- arch/powerpc/include/asm/ptrace.h | 22 +++++++++- arch/powerpc/include/asm/syscall.h | 6 +++ arch/powerpc/include/uapi/asm/ptrace.h | 6 ++- arch/powerpc/kernel/ptrace/ptrace.c | 2 + arch/powerpc/kernel/syscall.c | 18 +++++++++ rust/Makefile | 56 +++++++++++++++++--------- rust/compiler_builtins.rs | 6 +++ rust/helpers/helpers.c | 2 + scripts/min-tool-version.sh | 2 + 12 files changed, 119 insertions(+), 33 deletions(-)Signature · 1 line
2.55.0
Please ignore this.
Regards,
Mukesh