2a929aa7e1c0bc24d3087c5e188fbfd791631ab7
[lede.git] / target / linux / generic / patches-4.4 / 062-01-MIPS-Introduce-irq_stack.patch
1 From: Matt Redfearn <matt.redfearn@imgtec.com>
2 Date: Mon, 19 Dec 2016 14:20:56 +0000
3 Subject: [PATCH] MIPS: Introduce irq_stack
4
5 Allocate a per-cpu irq stack for use within interrupt handlers.
6
7 Also add a utility function on_irq_stack to determine if a given stack
8 pointer is within the irq stack for that cpu.
9
10 Signed-off-by: Matt Redfearn <matt.redfearn@imgtec.com>
11 ---
12
13 --- a/arch/mips/include/asm/irq.h
14 +++ b/arch/mips/include/asm/irq.h
15 @@ -17,6 +17,18 @@
16  
17  #include <irq.h>
18  
19 +#define IRQ_STACK_SIZE                 THREAD_SIZE
20 +
21 +extern void *irq_stack[NR_CPUS];
22 +
23 +static inline bool on_irq_stack(int cpu, unsigned long sp)
24 +{
25 +       unsigned long low = (unsigned long)irq_stack[cpu];
26 +       unsigned long high = low + IRQ_STACK_SIZE;
27 +
28 +       return (low <= sp && sp <= high);
29 +}
30 +
31  #ifdef CONFIG_I8259
32  static inline int irq_canonicalize(int irq)
33  {
34 --- a/arch/mips/kernel/asm-offsets.c
35 +++ b/arch/mips/kernel/asm-offsets.c
36 @@ -101,6 +101,7 @@ void output_thread_info_defines(void)
37         OFFSET(TI_REGS, thread_info, regs);
38         DEFINE(_THREAD_SIZE, THREAD_SIZE);
39         DEFINE(_THREAD_MASK, THREAD_MASK);
40 +       DEFINE(_IRQ_STACK_SIZE, IRQ_STACK_SIZE);
41         BLANK();
42  }
43  
44 --- a/arch/mips/kernel/irq.c
45 +++ b/arch/mips/kernel/irq.c
46 @@ -25,6 +25,8 @@
47  #include <linux/atomic.h>
48  #include <asm/uaccess.h>
49  
50 +void *irq_stack[NR_CPUS];
51 +
52  /*
53   * 'what should we do if we get a hw irq event on an illegal vector'.
54   * each architecture has to answer this themselves.
55 @@ -55,6 +57,15 @@ void __init init_IRQ(void)
56                 irq_set_noprobe(i);
57  
58         arch_init_irq();
59 +
60 +       for_each_possible_cpu(i) {
61 +               int irq_pages = IRQ_STACK_SIZE / PAGE_SIZE;
62 +               void *s = (void *)__get_free_pages(GFP_KERNEL, irq_pages);
63 +
64 +               irq_stack[i] = s;
65 +               pr_debug("CPU%d IRQ stack at 0x%p - 0x%p\n", i,
66 +                       irq_stack[i], irq_stack[i] + IRQ_STACK_SIZE);
67 +       }
68  }
69  
70  #ifdef CONFIG_DEBUG_STACKOVERFLOW