Skip to content

Commit bd4298c

Browse files
yeyunfeng-devwilldeacon
authored andcommitted
arm64: stacktrace: Factor out some common code into on_stack()
There are some common codes for stack checking, so factors it out into the function on_stack(). No functional change. Signed-off-by: Yunfeng Ye <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent b322c65 commit bd4298c

File tree

2 files changed

+16
-52
lines changed

2 files changed

+16
-52
lines changed

arch/arm64/include/asm/stacktrace.h

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,10 @@ extern void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk);
6868

6969
DECLARE_PER_CPU(unsigned long *, irq_stack_ptr);
7070

71-
static inline bool on_irq_stack(unsigned long sp,
71+
static inline bool on_stack(unsigned long sp, unsigned long low,
72+
unsigned long high, enum stack_type type,
7273
struct stack_info *info)
7374
{
74-
unsigned long low = (unsigned long)raw_cpu_read(irq_stack_ptr);
75-
unsigned long high = low + IRQ_STACK_SIZE;
76-
7775
if (!low)
7876
return false;
7977

@@ -83,29 +81,28 @@ static inline bool on_irq_stack(unsigned long sp,
8381
if (info) {
8482
info->low = low;
8583
info->high = high;
86-
info->type = STACK_TYPE_IRQ;
84+
info->type = type;
8785
}
88-
8986
return true;
9087
}
9188

89+
static inline bool on_irq_stack(unsigned long sp,
90+
struct stack_info *info)
91+
{
92+
unsigned long low = (unsigned long)raw_cpu_read(irq_stack_ptr);
93+
unsigned long high = low + IRQ_STACK_SIZE;
94+
95+
return on_stack(sp, low, high, STACK_TYPE_IRQ, info);
96+
}
97+
9298
static inline bool on_task_stack(const struct task_struct *tsk,
9399
unsigned long sp,
94100
struct stack_info *info)
95101
{
96102
unsigned long low = (unsigned long)task_stack_page(tsk);
97103
unsigned long high = low + THREAD_SIZE;
98104

99-
if (sp < low || sp >= high)
100-
return false;
101-
102-
if (info) {
103-
info->low = low;
104-
info->high = high;
105-
info->type = STACK_TYPE_TASK;
106-
}
107-
108-
return true;
105+
return on_stack(sp, low, high, STACK_TYPE_TASK, info);
109106
}
110107

111108
#ifdef CONFIG_VMAP_STACK
@@ -117,16 +114,7 @@ static inline bool on_overflow_stack(unsigned long sp,
117114
unsigned long low = (unsigned long)raw_cpu_ptr(overflow_stack);
118115
unsigned long high = low + OVERFLOW_STACK_SIZE;
119116

120-
if (sp < low || sp >= high)
121-
return false;
122-
123-
if (info) {
124-
info->low = low;
125-
info->high = high;
126-
info->type = STACK_TYPE_OVERFLOW;
127-
}
128-
129-
return true;
117+
return on_stack(sp, low, high, STACK_TYPE_OVERFLOW, info);
130118
}
131119
#else
132120
static inline bool on_overflow_stack(unsigned long sp,

arch/arm64/kernel/sdei.c

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -95,39 +95,15 @@ static bool on_sdei_normal_stack(unsigned long sp, struct stack_info *info)
9595
unsigned long low = (unsigned long)raw_cpu_read(sdei_stack_normal_ptr);
9696
unsigned long high = low + SDEI_STACK_SIZE;
9797

98-
if (!low)
99-
return false;
100-
101-
if (sp < low || sp >= high)
102-
return false;
103-
104-
if (info) {
105-
info->low = low;
106-
info->high = high;
107-
info->type = STACK_TYPE_SDEI_NORMAL;
108-
}
109-
110-
return true;
98+
return on_stack(sp, low, high, STACK_TYPE_SDEI_NORMAL, info);
11199
}
112100

113101
static bool on_sdei_critical_stack(unsigned long sp, struct stack_info *info)
114102
{
115103
unsigned long low = (unsigned long)raw_cpu_read(sdei_stack_critical_ptr);
116104
unsigned long high = low + SDEI_STACK_SIZE;
117105

118-
if (!low)
119-
return false;
120-
121-
if (sp < low || sp >= high)
122-
return false;
123-
124-
if (info) {
125-
info->low = low;
126-
info->high = high;
127-
info->type = STACK_TYPE_SDEI_CRITICAL;
128-
}
129-
130-
return true;
106+
return on_stack(sp, low, high, STACK_TYPE_SDEI_CRITICAL, info);
131107
}
132108

133109
bool _on_sdei_stack(unsigned long sp, struct stack_info *info)

0 commit comments

Comments
 (0)