Commit 34be98f4 authored by Ard Biesheuvel's avatar Ard Biesheuvel Committed by Mark Rutland

arm64: kernel: remove {THREAD,IRQ_STACK}_START_SP

For historical reasons, we leave the top 16 bytes of our task and IRQ
stacks unused, a practice used to ensure that the SP can always be
masked to find the base of the current stack (historically, where
thread_info could be found).

However, this is not necessary, as:

* When an exception is taken from a task stack, we decrement the SP by
  S_FRAME_SIZE and stash the exception registers before we compare the
  SP against the task stack. In such cases, the SP must be at least
  S_FRAME_SIZE below the limit, and can be safely masked to determine
  whether the task stack is in use.

* When transitioning to an IRQ stack, we'll place a dummy frame onto the
  IRQ stack before enabling asynchronous exceptions, or executing code
  we expect to trigger faults. Thus, if an exception is taken from the
  IRQ stack, the SP must be at least 16 bytes below the limit.

* We no longer mask the SP to find the thread_info, which is now found
  via sp_el0. Note that historically, the offset was critical to ensure
  that cpu_switch_to() found the correct stack for new threads that
  hadn't yet executed ret_from_fork().

Given that, this initial offset serves no purpose, and can be removed.
This brings us in-line with other architectures (e.g. x86) which do not
rely on this masking.
Signed-off-by: default avatarArd Biesheuvel <ard.biesheuvel@linaro.org>
[Mark: rebase, kill THREAD_START_SP, commit msg additions]
Signed-off-by: default avatarMark Rutland <mark.rutland@arm.com>
Reviewed-by: default avatarWill Deacon <will.deacon@arm.com>
Tested-by: default avatarLaura Abbott <labbott@redhat.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: James Morse <james.morse@arm.com>
parent 48ac3c18
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
#define __ASM_IRQ_H #define __ASM_IRQ_H
#define IRQ_STACK_SIZE THREAD_SIZE #define IRQ_STACK_SIZE THREAD_SIZE
#define IRQ_STACK_START_SP THREAD_START_SP
#ifndef __ASSEMBLER__ #ifndef __ASSEMBLER__
...@@ -26,9 +25,9 @@ static inline int nr_legacy_irqs(void) ...@@ -26,9 +25,9 @@ static inline int nr_legacy_irqs(void)
static inline bool on_irq_stack(unsigned long sp) static inline bool on_irq_stack(unsigned long sp)
{ {
unsigned long low = (unsigned long)raw_cpu_ptr(irq_stack); unsigned long low = (unsigned long)raw_cpu_ptr(irq_stack);
unsigned long high = low + IRQ_STACK_START_SP; unsigned long high = low + IRQ_STACK_SIZE;
return (low <= sp && sp <= high); return (low <= sp && sp < high);
} }
static inline bool on_task_stack(struct task_struct *tsk, unsigned long sp) static inline bool on_task_stack(struct task_struct *tsk, unsigned long sp)
......
...@@ -159,7 +159,7 @@ extern struct task_struct *cpu_switch_to(struct task_struct *prev, ...@@ -159,7 +159,7 @@ extern struct task_struct *cpu_switch_to(struct task_struct *prev,
struct task_struct *next); struct task_struct *next);
#define task_pt_regs(p) \ #define task_pt_regs(p) \
((struct pt_regs *)(THREAD_START_SP + task_stack_page(p)) - 1) ((struct pt_regs *)(THREAD_SIZE + task_stack_page(p)) - 1)
#define KSTK_EIP(tsk) ((unsigned long)task_pt_regs(tsk)->pc) #define KSTK_EIP(tsk) ((unsigned long)task_pt_regs(tsk)->pc)
#define KSTK_ESP(tsk) user_stack_pointer(task_pt_regs(tsk)) #define KSTK_ESP(tsk) user_stack_pointer(task_pt_regs(tsk))
......
...@@ -30,7 +30,6 @@ ...@@ -30,7 +30,6 @@
#endif #endif
#define THREAD_SIZE 16384 #define THREAD_SIZE 16384
#define THREAD_START_SP (THREAD_SIZE - 16)
#ifndef __ASSEMBLY__ #ifndef __ASSEMBLY__
......
...@@ -272,7 +272,7 @@ alternative_else_nop_endif ...@@ -272,7 +272,7 @@ alternative_else_nop_endif
cbnz x25, 9998f cbnz x25, 9998f
adr_this_cpu x25, irq_stack, x26 adr_this_cpu x25, irq_stack, x26
mov x26, #IRQ_STACK_START_SP mov x26, #IRQ_STACK_SIZE
add x26, x25, x26 add x26, x25, x26
/* switch to the irq stack */ /* switch to the irq stack */
......
...@@ -154,7 +154,7 @@ int __cpu_up(unsigned int cpu, struct task_struct *idle) ...@@ -154,7 +154,7 @@ int __cpu_up(unsigned int cpu, struct task_struct *idle)
* page tables. * page tables.
*/ */
secondary_data.task = idle; secondary_data.task = idle;
secondary_data.stack = task_stack_page(idle) + THREAD_START_SP; secondary_data.stack = task_stack_page(idle) + THREAD_SIZE;
update_cpu_boot_status(CPU_MMU_OFF); update_cpu_boot_status(CPU_MMU_OFF);
__flush_dcache_area(&secondary_data, sizeof(secondary_data)); __flush_dcache_area(&secondary_data, sizeof(secondary_data));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment