Skip to content

Commit a45d575

Browse files
Robin GetzBryan Wu
authored andcommitted
Blackfin arch: Add basic irq stack checking for Blackfin
Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org> Signed-off-by: Bryan Wu <cooloney@kernel.org>
1 parent f768a0e commit a45d575

4 files changed

Lines changed: 40 additions & 1 deletion

File tree

‎arch/blackfin/Kconfig.debug‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@ menu "Kernel hacking"
22

33
source "lib/Kconfig.debug"
44

5+
config DEBUG_STACKOVERFLOW
6+
bool "Check for stack overflows"
7+
depends on DEBUG_KERNEL
8+
help
9+
This option will cause messages to be printed if free stack space
10+
drops below a certain limit.
11+
12+
config DEBUG_STACK_USAGE
13+
bool "Enable stack utilization instrumentation"
14+
depends on DEBUG_KERNEL
15+
help
16+
Enables the display of the minimum amount of free stack which each
17+
task has ever had available in the sysrq-T output.
18+
19+
This option will slow down process creation somewhat.
20+
521
config HAVE_ARCH_KGDB
622
def_bool y
723

‎arch/blackfin/include/asm/processor.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ static inline void wrusp(unsigned long usp)
2424
__asm__ __volatile__("usp = %0;\n\t"::"da"(usp));
2525
}
2626

27+
static inline unsigned long __get_SP(void)
28+
{
29+
unsigned long sp;
30+
31+
__asm__ __volatile__("%0 = sp;\n\t" : "=da"(sp));
32+
return sp;
33+
}
34+
2735
/*
2836
* User space process size: 1st byte beyond user address space.
2937
* Fairly meaningless on nommu. Parts of user programs can be scattered

‎arch/blackfin/include/asm/thread_info.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
*/
4545
#define THREAD_SIZE_ORDER 1
4646
#define THREAD_SIZE 8192 /* 2 pages */
47+
#define STACK_WARN (THREAD_SIZE/8)
4748

4849
#ifndef __ASSEMBLY__
4950

‎arch/blackfin/kernel/irqchip.c‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,21 @@ asmlinkage void asm_do_IRQ(unsigned int irq, struct pt_regs *regs)
120120
desc = &bad_irq_desc;
121121

122122
irq_enter();
123-
123+
#ifdef CONFIG_DEBUG_STACKOVERFLOW
124+
/* Debugging check for stack overflow: is there less than STACK_WARN free? */
125+
{
126+
long sp;
127+
128+
sp = __get_SP() & (THREAD_SIZE-1);
129+
130+
if (unlikely(sp < (sizeof(struct thread_info) + STACK_WARN))) {
131+
dump_stack();
132+
printk(KERN_EMERG "%s: possible stack overflow while handling irq %i "
133+
" only %ld bytes free\n",
134+
__func__, irq, sp - sizeof(struct thread_info));
135+
}
136+
}
137+
#endif
124138
generic_handle_irq(irq);
125139

126140
/* If we're the only interrupt running (ignoring IRQ15 which is for

0 commit comments

Comments
 (0)