| 1 |
/* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 |
/* |
| 3 |
* Copyright (C) 2012 ARM Ltd. |
| 4 |
*/ |
| 5 |
#ifndef __ASM_STACKTRACE_H |
| 6 |
#define __ASM_STACKTRACE_H |
| 7 |
|
| 8 |
#include <linux/percpu.h> |
| 9 |
#include <linux/sched.h> |
| 10 |
#include <linux/sched/task_stack.h> |
| 11 |
#include <linux/llist.h> |
| 12 |
|
| 13 |
#include <asm/memory.h> |
| 14 |
#include <asm/pointer_auth.h> |
| 15 |
#include <asm/ptrace.h> |
| 16 |
#include <asm/sdei.h> |
| 17 |
|
| 18 |
#include <asm/stacktrace/common.h> |
| 19 |
|
| 20 |
extern void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk, |
| 21 |
const char *loglvl); |
| 22 |
|
| 23 |
DECLARE_PER_CPU(unsigned long *, irq_stack_ptr); |
| 24 |
|
| 25 |
static inline struct stack_info stackinfo_get_irq(void) |
| 26 |
{ |
| 27 |
unsigned long low = (unsigned long)raw_cpu_read(irq_stack_ptr); |
| 28 |
unsigned long high = low + IRQ_STACK_SIZE; |
| 29 |
|
| 30 |
return (struct stack_info) { |
| 31 |
.low = low, |
| 32 |
.high = high, |
| 33 |
}; |
| 34 |
} |
| 35 |
|
| 36 |
static inline bool on_irq_stack(unsigned long sp, unsigned long size) |
| 37 |
{ |
| 38 |
struct stack_info info = stackinfo_get_irq(); |
| 39 |
return stackinfo_on_stack(&info, sp, size); |
| 40 |
} |
| 41 |
|
| 42 |
static inline struct stack_info stackinfo_get_task(const struct task_struct *tsk) |
| 43 |
{ |
| 44 |
unsigned long low = (unsigned long)task_stack_page(tsk); |
| 45 |
unsigned long high = low + THREAD_SIZE; |
| 46 |
|
| 47 |
return (struct stack_info) { |
| 48 |
.low = low, |
| 49 |
.high = high, |
| 50 |
}; |
| 51 |
} |
| 52 |
|
| 53 |
static inline bool on_task_stack(const struct task_struct *tsk, |
| 54 |
unsigned long sp, unsigned long size) |
| 55 |
{ |
| 56 |
struct stack_info info = stackinfo_get_task(tsk); |
| 57 |
return stackinfo_on_stack(&info, sp, size); |
| 58 |
} |
| 59 |
|
| 60 |
#define on_thread_stack() (on_task_stack(current, current_stack_pointer, 1)) |
| 61 |
|
| 62 |
DECLARE_PER_CPU(unsigned long [OVERFLOW_STACK_SIZE/sizeof(long)], overflow_stack); |
| 63 |
|
| 64 |
static inline struct stack_info stackinfo_get_overflow(void) |
| 65 |
{ |
| 66 |
unsigned long low = (unsigned long)raw_cpu_ptr(overflow_stack); |
| 67 |
unsigned long high = low + OVERFLOW_STACK_SIZE; |
| 68 |
|
| 69 |
return (struct stack_info) { |
| 70 |
.low = low, |
| 71 |
.high = high, |
| 72 |
}; |
| 73 |
} |
| 74 |
|
| 75 |
#if defined(CONFIG_ARM_SDE_INTERFACE) |
| 76 |
DECLARE_PER_CPU(unsigned long *, sdei_stack_normal_ptr); |
| 77 |
DECLARE_PER_CPU(unsigned long *, sdei_stack_critical_ptr); |
| 78 |
|
| 79 |
static inline struct stack_info stackinfo_get_sdei_normal(void) |
| 80 |
{ |
| 81 |
unsigned long low = (unsigned long)raw_cpu_read(sdei_stack_normal_ptr); |
| 82 |
unsigned long high = low + SDEI_STACK_SIZE; |
| 83 |
|
| 84 |
return (struct stack_info) { |
| 85 |
.low = low, |
| 86 |
.high = high, |
| 87 |
}; |
| 88 |
} |
| 89 |
|
| 90 |
static inline struct stack_info stackinfo_get_sdei_critical(void) |
| 91 |
{ |
| 92 |
unsigned long low = (unsigned long)raw_cpu_read(sdei_stack_critical_ptr); |
| 93 |
unsigned long high = low + SDEI_STACK_SIZE; |
| 94 |
|
| 95 |
return (struct stack_info) { |
| 96 |
.low = low, |
| 97 |
.high = high, |
| 98 |
}; |
| 99 |
} |
| 100 |
#else |
| 101 |
#define stackinfo_get_sdei_normal() stackinfo_get_unknown() |
| 102 |
#define stackinfo_get_sdei_critical() stackinfo_get_unknown() |
| 103 |
#endif |
| 104 |
|
| 105 |
#ifdef CONFIG_EFI |
| 106 |
extern u64 *efi_rt_stack_top; |
| 107 |
|
| 108 |
static inline struct stack_info stackinfo_get_efi(void) |
| 109 |
{ |
| 110 |
unsigned long high = (u64)efi_rt_stack_top; |
| 111 |
unsigned long low = high - THREAD_SIZE; |
| 112 |
|
| 113 |
return (struct stack_info) { |
| 114 |
.low = low, |
| 115 |
.high = high, |
| 116 |
}; |
| 117 |
} |
| 118 |
#endif |
| 119 |
|
| 120 |
#endif /* __ASM_STACKTRACE_H */ |