FAILED: patch "[PATCH] microblaze: restore the ABI argument home area below pt_regs (PTO)" failed to apply to 5.15-stable tree
Subsystems (2)
Sasha Levin
maintainerThe patch below does not apply to the 5.15-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.15.y
git checkout FETCH_HEAD
git cherry-pick -x c35d40a3efd2e575ef51a761e983f2bf7113be6c
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 5.15.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From c35d40a3efd2e575ef51a761e983f2bf7113be6c Mon Sep 17 00:00:00 2001
From: Ramin Moussavi <[email protected]>
Date: Fri, 21 Aug 2026 17:18:08 +0200
Subject: [PATCH] microblaze: restore the ABI argument home area below pt_regs
(PTO)
The MicroBlaze ABI has the caller reserve stack space for the arguments it passes in registers: REG_PARM_STACK_SPACE is 24 and OUTGOING_REG_PARM_STACK_SPACE is 1 in the gcc backend, so a callee may write to [caller_sp + 4, caller_sp + 28). The kernel calls C functions from entry.S with r1 pointing at pt_regs, handing the callee license to spill its incoming arguments over the saved registers -- the syscall dispatch is the worst case, where the first argument slot is PT_R1, the saved user stack pointer.
This was latent until GCC 15: since 3b9b8d6cfdf5 ("ira: Scale save/restore costs of callee save registers with block frequency") the allocator prefers spilling incoming arguments over copying them into callee-saved registers, and a kernel built with gcc >= 15 (without the TARGET_CALLEE_SAVE_COST workaround some distributions carry) corrupts PT_R1 on the first syscall: init takes SIGSEGV and the kernel panics.
The kernel had exactly this reservation until 2011:
commit 6e83557c38b4 ("microblaze: Remove r0_ram pointer and PTO alignment") removed STATE_SAVE_ARG_SPACE and with it the PTO offset, as part of cleaning up what was thought to be copied-from-v850 leftovers. Restore
it: the frame is STATE_SAVE_SIZE = PT_SIZE + PTO, r1 stays at the frame base through every asm-to-C call, and the saved registers are reached at r1 + PTO + PT_*. PTO is 28 rather than the historic 24, which was one word short: FIRST_PARM_OFFSET is 4 and REG_PARM_STACK_SPACE is 24, so the area spans [sp+4, sp+28) and needs 28 bytes. With 24 the last argument slot overlapped pt_regs' r0 -- harmless only because r0 is the constant-zero register. STACK_BOUNDARY is 32 bits, so 28 needs no further rounding.
Two places deliberately keep their mainline addressing. hw_exception_handler.S needs no offset change: its real-mode handler saves into the standalone pt_pool_space buffer rather than a stack frame, and _unaligned_data_exception works through a pointer to pt_regs in r7, where plain PT_* offsets are already right. And the user-SP reload after popping the frame keeps PT_R1 - PT_SIZE because PTO cancels there: (PTO + PT_R1) - (PT_SIZE + PTO) = PT_R1 - PT_SIZE. Both are exactly as the pre-2011 code had them.
The instruction count is unchanged -- the same instructions with different immediates, no per-call reservation and no trampolines. The cost is 28 bytes more kernel stack per saved frame.
--- arch/microblaze/include/asm/entry.h | 13 + arch/microblaze/include/asm/processor.h | 2 +- arch/microblaze/kernel/entry.S | 329 +++++++++--------- arch/microblaze/kernel/hw_exception_handler.S | 5 + arch/microblaze/kernel/process.c | 5 +- 5 files changed, 189 insertions(+), 165 deletions(-)
arch/microblaze/include/asm/entry.h +13 -0
@@ -21,6 +21,19 @@#define PER_CPU (var) var +/* +* The MicroBlaze ABI has the caller reserve an argument home area: +* REG_PARM_STACK_SPACE is 24 and OUTGOING_REG_PARM_STACK_SPACE is 1, so a +* callee may write to [caller_sp + 4, caller_sp + 28). The kernel calls C +* with r1 at the frame base, so reserve that area below pt_regs and reach +* the saved registers through PTO. This restores what 6e83557c38b4 +* ("microblaze: Remove r0_ram pointer and PTO alignment") removed; the old +* value of 24 was one word short and left the last argument slot +* overlapping pt_regs' r0. +*/ +#define PTO 28 +#define STATE_SAVE_SIZE (PT_SIZE + PTO) +# ifndef __ASSEMBLER__ DECLARE_PER_CPU(unsigned int, KSP); /* Saved kernel stack pointer */ DECLARE_PER_CPU(unsigned int, KM); /* Kernel/user mode */
arch/microblaze/include/asm/processor.h +1 -1
@@ -73,7 +73,7 @@ unsigned long __get_wchan(struct task_struct *p);# define task_regs (task) ((struct pt_regs *)task_tos(task) - 1)# define task_pt_regs_plus_args (tsk) \ - ((void *)task_pt_regs(tsk)) + (((void *)task_pt_regs(tsk)) - PTO)# define task_sp (task) (task_regs(task)->r1)# define task_pc (task) (task_regs(task)->pc)
arch/microblaze/kernel/entry.S +167 -162
675 lines not on this page · raw message
arch/microblaze/kernel/hw_exception_handler.S +5 -0
@@ -313,6 +313,11 @@ _MB_HW_ExceptionVectorTable: .align 4 .ent _hw_exception_handler _hw_exception_handler: + /* + * This handler saves into the static pt_pool_space buffer, not into a + * stack frame, so the plain PT_* offsets are right here -- do not add + * the PTO of entry.S's frames. + */ swi r1, r0, TOPHYS(pt_pool_space + PT_R1); /* GET_SP */ /* Save date to kernel memory. Here is the problem * when you came from user space */
arch/microblaze/kernel/process.c +3 -2
@@ -19,6 +19,7 @@#include <linux/bitops.h> #include <linux/ptrace.h> #include <asm/cacheflush.h> +#include <asm/entry.h> void show_regs (struct pt_regs *regs) {
@@ -65,7 +66,7 @@ int copy_thread(struct task_struct *p, const struct kernel_clone_args *args)* the registers. That's OK for a brand new thread.*/ memset (childregs,0 ,sizeof (struct pt_regs ));memset (&ti->cpu_context,0 ,sizeof (struct cpu_context )); - ti->cpu_context.r1 = (unsigned long )childregs; + ti->cpu_context.r1 = (unsigned long )childregs -PTO ; ti->cpu_context.r20 = (unsigned long )args->fn; ti->cpu_context.r19 = (unsigned long )args->fn_arg; childregs->pt_mode =1 ;
@@ -79,7 +80,7 @@ int copy_thread(struct task_struct *p, const struct kernel_clone_args *args) childregs->r1 = usp;memset (&ti->cpu_context,0 ,sizeof (struct cpu_context )); - ti->cpu_context.r1 = (unsigned long )childregs; + ti->cpu_context.r1 = (unsigned long )childregs -PTO ; childregs->msr |=MSR_UMS ;/* we should consider the fact that childregs is a copy of the parent
Signature · 1 line
2.53.0
PATCH 1/1 microblaze: restore the ABI argument home area below pt_regs (PTO)
commit c35d40a3efd2e575ef51a761e983f2bf7113be6c upstream.
The MicroBlaze ABI has the caller reserve stack space for the arguments it passes in registers: REG_PARM_STACK_SPACE is 24 and OUTGOING_REG_PARM_STACK_SPACE is 1 in the gcc backend, so a callee may write to [caller_sp + 4, caller_sp + 28). The kernel calls C functions from entry.S with r1 pointing at pt_regs, handing the callee license to spill its incoming arguments over the saved registers -- the syscall dispatch is the worst case, where the first argument slot is PT_R1, the saved user stack pointer.
This was latent until GCC 15: since 3b9b8d6cfdf5 ("ira: Scale save/restore costs of callee save registers with block frequency") the allocator prefers spilling incoming arguments over copying them into callee-saved registers, and a kernel built with gcc >= 15 (without the TARGET_CALLEE_SAVE_COST workaround some distributions carry) corrupts PT_R1 on the first syscall: init takes SIGSEGV and the kernel panics.
The kernel had exactly this reservation until 2011:
commit 6e83557c38b4 ("microblaze: Remove r0_ram pointer and PTO alignment") removed STATE_SAVE_ARG_SPACE and with it the PTO offset, as part of cleaning up what was thought to be copied-from-v850 leftovers. Restore
it: the frame is STATE_SAVE_SIZE = PT_SIZE + PTO, r1 stays at the frame base through every asm-to-C call, and the saved registers are reached at r1 + PTO + PT_*. PTO is 28 rather than the historic 24, which was one word short: FIRST_PARM_OFFSET is 4 and REG_PARM_STACK_SPACE is 24, so the area spans [sp+4, sp+28) and needs 28 bytes. With 24 the last argument slot overlapped pt_regs' r0 -- harmless only because r0 is the constant-zero register. STACK_BOUNDARY is 32 bits, so 28 needs no further rounding.
Two places deliberately keep their mainline addressing. hw_exception_handler.S needs no offset change: its real-mode handler saves into the standalone pt_pool_space buffer rather than a stack frame, and _unaligned_data_exception works through a pointer to pt_regs in r7, where plain PT_* offsets are already right. And the user-SP reload after popping the frame keeps PT_R1 - PT_SIZE because PTO cancels there: (PTO + PT_R1) - (PT_SIZE + PTO) = PT_R1 - PT_SIZE. Both are exactly as the pre-2011 code had them.
The instruction count is unchanged -- the same instructions with different immediates, no per-call reservation and no trampolines. The cost is 28 bytes more kernel stack per saved frame.
---
Prerequisites on this branch. Two are needed for this patch to apply:
c5947d28c209 ("microblaze: reserve the ABI argument-home area in the
signal frame")
da6829138a39 ("microblaze: don't clobber r3/r4 restored by rt_sigreturn")
in that order. Both are queued for this branch but not in it yet. With them applied entry.S needs no adjustment at all; without them the cherry-pick conflicts there, which is what the failure report was about.
Two more are needed before the result can be tested:
95fee37be45f ("microblaze: Do loop unrolling for optimized memset
implementation")
8f0f265e6cf5 ("microblaze: Use simple memset implementation from
lib/string.c")
Without them this branch does not boot at all when built with gcc 10 or later, so the result cannot be verified: the "while (n--)" loop left in arch/microblaze/lib/memset.c is turned into a call to memset by -ftree-loop-distribute-patterns, so memset calls itself and never returns -- no oops, no console output. Both are in v5.19-rc1 and cherry-pick cleanly.
Tested: built with gcc 16.2.0 and booted under qemu-system-microblaze 11.1.50 (-M petalogix-s3adsp1800,endianness=little); the kernel reaches userspace and the test suite runs to completion.
Backport changes: the asm/entry.h guard is still __ASSEMBLY__ here; three entry.S hunks are dropped because the code does not exist on this branch yet (mb_flush_dcache/mb_invalidate_icache, the CONFIG_MB_MANAGER block and xmb_inject_err); in process.c only the "- PTO" is taken, since copy_thread still has usp/arg instead of args->fn/args->fn_arg.
arch/microblaze/include/asm/entry.h | 13 + arch/microblaze/include/asm/processor.h | 2 +- arch/microblaze/kernel/entry.S | 277 +++++++++--------- arch/microblaze/kernel/hw_exception_handler.S | 5 + arch/microblaze/kernel/process.c | 5 +- 5 files changed, 163 insertions(+), 139 deletions(-)
arch/microblaze/include/asm/entry.h +13 -0
@@ -21,6 +21,19 @@#define PER_CPU (var) var +/* +* The MicroBlaze ABI has the caller reserve an argument home area: +* REG_PARM_STACK_SPACE is 24 and OUTGOING_REG_PARM_STACK_SPACE is 1, so a +* callee may write to [caller_sp + 4, caller_sp + 28). The kernel calls C +* with r1 at the frame base, so reserve that area below pt_regs and reach +* the saved registers through PTO. This restores what 6e83557c38b4 +* ("microblaze: Remove r0_ram pointer and PTO alignment") removed; the old +* value of 24 was one word short and left the last argument slot +* overlapping pt_regs' r0. +*/ +#define PTO 28 +#define STATE_SAVE_SIZE (PT_SIZE + PTO) +# ifndef __ASSEMBLY__ DECLARE_PER_CPU(unsigned int, KSP); /* Saved kernel stack pointer */ DECLARE_PER_CPU(unsigned int, KM); /* Kernel/user mode */
arch/microblaze/include/asm/processor.h +1 -1
@@ -78,7 +78,7 @@ unsigned long __get_wchan(struct task_struct *p);# define task_regs (task) ((struct pt_regs *)task_tos(task) - 1)# define task_pt_regs_plus_args (tsk) \ - ((void *)task_pt_regs(tsk)) + (((void *)task_pt_regs(tsk)) - PTO)# define task_sp (task) (task_regs(task)->r1)# define task_pc (task) (task_regs(task)->pc)
arch/microblaze/kernel/entry.S +141 -136
535 lines not on this page · raw message
arch/microblaze/kernel/hw_exception_handler.S +5 -0
@@ -313,6 +313,11 @@ _MB_HW_ExceptionVectorTable: .align 4 .ent _hw_exception_handler _hw_exception_handler: + /* + * This handler saves into the static pt_pool_space buffer, not into a + * stack frame, so the plain PT_* offsets are right here -- do not add + * the PTO of entry.S's frames. + */ swi r1, r0, TOPHYS(pt_pool_space + PT_R1); /* GET_SP */ /* Save date to kernel memory. Here is the problem * when you came from user space */
arch/microblaze/kernel/process.c +3 -2
@@ -20,6 +20,7 @@#include <linux/ptrace.h> #include <linux/uaccess.h> /* for USER_DS macros */ #include <asm/cacheflush.h> +#include <asm/entry.h> void show_regs (struct pt_regs *regs) {
@@ -64,7 +65,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp, unsigned long arg,* the registers. That's OK for a brand new thread.*/ memset (childregs,0 ,sizeof (struct pt_regs ));memset (&ti->cpu_context,0 ,sizeof (struct cpu_context )); - ti->cpu_context.r1 = (unsigned long )childregs; + ti->cpu_context.r1 = (unsigned long )childregs -PTO ; ti->cpu_context.r20 = (unsigned long )usp;/* fn */ ti->cpu_context.r19 = (unsigned long )arg; childregs->pt_mode =1 ;
@@ -78,7 +79,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp, unsigned long arg, childregs->r1 = usp;memset (&ti->cpu_context,0 ,sizeof (struct cpu_context )); - ti->cpu_context.r1 = (unsigned long )childregs; + ti->cpu_context.r1 = (unsigned long )childregs -PTO ; childregs->msr |=MSR_UMS ;/* we should consider the fact that childregs is a copy of the parent
Signature · 1 line
2.53.0
Re: [PATCH 5.15.y] microblaze: restore the ABI argument home area below pt_regs (PTO)
Quoted 1 line
microblaze: restore the ABI argument home area below
pt_regs(PTO)
Queued the two memset backports for 5.15 and 5.10 together with the PTO fix, thanks.
Signature · 2 lines
Thanks, Sasha