Skip to content

Commit

Permalink
powerpc: allow minimum sized kernel stack frames
Browse files Browse the repository at this point in the history
This affects only 64-bit ELFv2 kernels, and reduces the minimum
asm-created stack frame size from 112 to 32 byte on those kernels.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20221127124942.1665522-16-npiggin@gmail.com
  • Loading branch information
Nicholas Piggin authored and Michael Ellerman committed Dec 2, 2022
1 parent 4cefb0f commit 90f1b43
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion arch/powerpc/kernel/head_40x.S
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ start_here:
lis r1,init_thread_union@ha
addi r1,r1,init_thread_union@l
li r0,0
stwu r0,THREAD_SIZE-STACK_FRAME_OVERHEAD(r1)
stwu r0,THREAD_SIZE-STACK_FRAME_MIN_SIZE(r1)

bl early_init /* We have to do this with MMU on */

Expand Down
6 changes: 3 additions & 3 deletions arch/powerpc/kernel/head_44x.S
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ _GLOBAL(_start);
lis r1,init_thread_union@h
ori r1,r1,init_thread_union@l
li r0,0
stwu r0,THREAD_SIZE-STACK_FRAME_OVERHEAD(r1)
stwu r0,THREAD_SIZE-STACK_FRAME_MIN_SIZE(r1)

bl early_init

Expand Down Expand Up @@ -1012,7 +1012,7 @@ _GLOBAL(start_secondary_47x)
*/
lis r1,temp_boot_stack@h
ori r1,r1,temp_boot_stack@l
addi r1,r1,1024-STACK_FRAME_OVERHEAD
addi r1,r1,1024-STACK_FRAME_MIN_SIZE
li r0,0
stw r0,0(r1)
bl mmu_init_secondary
Expand All @@ -1025,7 +1025,7 @@ _GLOBAL(start_secondary_47x)
lwz r1,TASK_STACK(r2)

/* Current stack pointer */
addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
addi r1,r1,THREAD_SIZE-STACK_FRAME_MIN_SIZE
li r0,0
stw r0,0(r1)

Expand Down
6 changes: 3 additions & 3 deletions arch/powerpc/kernel/head_64.S
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ generic_secondary_common_init:

/* Create a temp kernel stack for use before relocation is on. */
ld r1,PACAEMERGSP(r13)
subi r1,r1,STACK_FRAME_OVERHEAD
subi r1,r1,STACK_FRAME_MIN_SIZE

/* See if we need to call a cpu state restore handler */
LOAD_REG_ADDR(r23, cur_cpu_spec)
Expand Down Expand Up @@ -780,7 +780,7 @@ _GLOBAL(pmac_secondary_start)

/* Create a temp kernel stack for use before relocation is on. */
ld r1,PACAEMERGSP(r13)
subi r1,r1,STACK_FRAME_OVERHEAD
subi r1,r1,STACK_FRAME_MIN_SIZE

b __secondary_start

Expand Down Expand Up @@ -958,7 +958,7 @@ start_here_multiplatform:
LOAD_REG_IMMEDIATE(r1,THREAD_SIZE)
add r1,r3,r1
li r0,0
stdu r0,-STACK_FRAME_OVERHEAD(r1)
stdu r0,-STACK_FRAME_MIN_SIZE(r1)

/*
* Do very early kernel initializations, including initial hash table
Expand Down
4 changes: 2 additions & 2 deletions arch/powerpc/kernel/head_85xx.S
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ set_ivor:
lis r1,init_thread_union@h
ori r1,r1,init_thread_union@l
li r0,0
stwu r0,THREAD_SIZE-STACK_FRAME_OVERHEAD(r1)
stwu r0,THREAD_SIZE-STACK_FRAME_MIN_SIZE(r1)

#ifdef CONFIG_SMP
stw r24, TASK_CPU(r2)
Expand Down Expand Up @@ -1044,7 +1044,7 @@ __secondary_start:
lwz r1,TASK_STACK(r2)

/* stack */
addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
addi r1,r1,THREAD_SIZE-STACK_FRAME_MIN_SIZE
li r0,0
stw r0,0(r1)

Expand Down
2 changes: 1 addition & 1 deletion arch/powerpc/kernel/head_8xx.S
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ start_here:
ori r0, r0, STACK_END_MAGIC@l
stw r0, 0(r1)
li r0,0
stwu r0,THREAD_SIZE-STACK_FRAME_OVERHEAD(r1)
stwu r0,THREAD_SIZE-STACK_FRAME_MIN_SIZE(r1)

lis r6, swapper_pg_dir@ha
tophys(r6,r6)
Expand Down
4 changes: 2 additions & 2 deletions arch/powerpc/kernel/head_book3s_32.S
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ __secondary_start:
lwz r1,TASK_STACK(r1)

/* stack */
addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
addi r1,r1,THREAD_SIZE-STACK_FRAME_MIN_SIZE
li r0,0
tophys(r3,r1)
stw r0,0(r3)
Expand Down Expand Up @@ -966,7 +966,7 @@ END_MMU_FTR_SECTION_IFCLR(MMU_FTR_HPTE_TABLE)
lis r1,init_thread_union@ha
addi r1,r1,init_thread_union@l
li r0,0
stwu r0,THREAD_SIZE-STACK_FRAME_OVERHEAD(r1)
stwu r0,THREAD_SIZE-STACK_FRAME_MIN_SIZE(r1)
/*
* Do early platform-specific initialization,
* and set up the MMU.
Expand Down
4 changes: 2 additions & 2 deletions arch/powerpc/kernel/irq.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ static __always_inline void call_do_softirq(const void *sp)
PPC_LL " %%r1, 0(%%r1) ;"
: // Outputs
: // Inputs
[sp] "b" (sp), [offset] "i" (THREAD_SIZE - STACK_FRAME_OVERHEAD),
[sp] "b" (sp), [offset] "i" (THREAD_SIZE - STACK_FRAME_MIN_SIZE),
[callee] "i" (__do_softirq)
: // Clobbers
"lr", "xer", "ctr", "memory", "cr0", "cr1", "cr5", "cr6",
Expand Down Expand Up @@ -264,7 +264,7 @@ static __always_inline void call_do_irq(struct pt_regs *regs, void *sp)
: // Outputs
"+r" (r3)
: // Inputs
[sp] "b" (sp), [offset] "i" (THREAD_SIZE - STACK_FRAME_OVERHEAD),
[sp] "b" (sp), [offset] "i" (THREAD_SIZE - STACK_FRAME_MIN_SIZE),
[callee] "i" (__do_irq)
: // Clobbers
"lr", "xer", "ctr", "memory", "cr0", "cr1", "cr5", "cr6",
Expand Down
2 changes: 1 addition & 1 deletion arch/powerpc/kernel/misc_32.S
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ EXPORT_SYMBOL(__bswapdi2)
_GLOBAL(start_secondary_resume)
/* Reset stack */
rlwinm r1, r1, 0, 0, 31 - THREAD_SHIFT
addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
addi r1,r1,THREAD_SIZE-STACK_FRAME_MIN_SIZE
li r3,0
stw r3,0(r1) /* Zero the stack frame pointer */
bl start_secondary
Expand Down
4 changes: 2 additions & 2 deletions arch/powerpc/kernel/misc_64.S
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ _GLOBAL(kexec_sequence)
std r0,16(r1)

/* switch stacks to newstack -- &kexec_stack.stack */
stdu r1,THREAD_SIZE-STACK_FRAME_OVERHEAD(r3)
stdu r1,THREAD_SIZE-STACK_FRAME_MIN_SIZE(r3)
mr r1,r3

li r0,0
Expand All @@ -401,7 +401,7 @@ _GLOBAL(kexec_sequence)
std r26,-48(r1)
std r25,-56(r1)

stdu r1,-STACK_FRAME_OVERHEAD-64(r1)
stdu r1,-STACK_FRAME_MIN_SIZE-64(r1)

/* save args into preserved regs */
mr r31,r3 /* newstack (both) */
Expand Down
2 changes: 1 addition & 1 deletion arch/powerpc/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -2180,7 +2180,7 @@ int validate_sp_size(unsigned long sp, struct task_struct *p,

int validate_sp(unsigned long sp, struct task_struct *p)
{
return validate_sp_size(sp, p, STACK_FRAME_OVERHEAD);
return validate_sp_size(sp, p, STACK_FRAME_MIN_SIZE);
}

static unsigned long ___get_wchan(struct task_struct *p)
Expand Down
2 changes: 1 addition & 1 deletion arch/powerpc/kernel/smp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1249,7 +1249,7 @@ static void cpu_idle_thread_init(unsigned int cpu, struct task_struct *idle)
#ifdef CONFIG_PPC64
paca_ptrs[cpu]->__current = idle;
paca_ptrs[cpu]->kstack = (unsigned long)task_stack_page(idle) +
THREAD_SIZE - STACK_FRAME_OVERHEAD;
THREAD_SIZE - STACK_FRAME_MIN_SIZE;
#endif
task_thread_info(idle)->cpu = cpu;
secondary_current = current_set[cpu] = idle;
Expand Down
2 changes: 1 addition & 1 deletion arch/powerpc/kernel/stacktrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ int __no_sanitize_address arch_stack_walk_reliable(stack_trace_consume_fn consum
* idle tasks have a custom stack layout,
* c.f. cpu_idle_thread_init().
*/
stack_end -= STACK_FRAME_OVERHEAD;
stack_end -= STACK_FRAME_MIN_SIZE;
}

if (task == current)
Expand Down

0 comments on commit 90f1b43

Please sign in to comment.