diff options
-rw-r--r-- | arch/mips/include/asm/irq.h | 15 | ||||
-rw-r--r-- | arch/mips/kernel/asm-offsets.c | 1 | ||||
-rw-r--r-- | arch/mips/kernel/genex.S | 8 | ||||
-rw-r--r-- | arch/mips/kernel/process.c | 56 |
4 files changed, 60 insertions, 20 deletions
diff --git a/arch/mips/include/asm/irq.h b/arch/mips/include/asm/irq.h index 956db6e201d1..ddd1c918103b 100644 --- a/arch/mips/include/asm/irq.h +++ b/arch/mips/include/asm/irq.h | |||
@@ -18,9 +18,24 @@ | |||
18 | #include <irq.h> | 18 | #include <irq.h> |
19 | 19 | ||
20 | #define IRQ_STACK_SIZE THREAD_SIZE | 20 | #define IRQ_STACK_SIZE THREAD_SIZE |
21 | #define IRQ_STACK_START (IRQ_STACK_SIZE - sizeof(unsigned long)) | ||
21 | 22 | ||
22 | extern void *irq_stack[NR_CPUS]; | 23 | extern void *irq_stack[NR_CPUS]; |
23 | 24 | ||
25 | /* | ||
26 | * The highest address on the IRQ stack contains a dummy frame put down in | ||
27 | * genex.S (handle_int & except_vec_vi_handler) which is structured as follows: | ||
28 | * | ||
29 | * top ------------ | ||
30 | * | task sp | <- irq_stack[cpu] + IRQ_STACK_START | ||
31 | * ------------ | ||
32 | * | | <- First frame of IRQ context | ||
33 | * ------------ | ||
34 | * | ||
35 | * task sp holds a copy of the task stack pointer where the struct pt_regs | ||
36 | * from exception entry can be found. | ||
37 | */ | ||
38 | |||
24 | static inline bool on_irq_stack(int cpu, unsigned long sp) | 39 | static inline bool on_irq_stack(int cpu, unsigned long sp) |
25 | { | 40 | { |
26 | unsigned long low = (unsigned long)irq_stack[cpu]; | 41 | unsigned long low = (unsigned long)irq_stack[cpu]; |
diff --git a/arch/mips/kernel/asm-offsets.c b/arch/mips/kernel/asm-offsets.c index bb5c5d34ba81..a670c0c11875 100644 --- a/arch/mips/kernel/asm-offsets.c +++ b/arch/mips/kernel/asm-offsets.c | |||
@@ -102,6 +102,7 @@ void output_thread_info_defines(void) | |||
102 | DEFINE(_THREAD_SIZE, THREAD_SIZE); | 102 | DEFINE(_THREAD_SIZE, THREAD_SIZE); |
103 | DEFINE(_THREAD_MASK, THREAD_MASK); | 103 | DEFINE(_THREAD_MASK, THREAD_MASK); |
104 | DEFINE(_IRQ_STACK_SIZE, IRQ_STACK_SIZE); | 104 | DEFINE(_IRQ_STACK_SIZE, IRQ_STACK_SIZE); |
105 | DEFINE(_IRQ_STACK_START, IRQ_STACK_START); | ||
105 | BLANK(); | 106 | BLANK(); |
106 | } | 107 | } |
107 | 108 | ||
diff --git a/arch/mips/kernel/genex.S b/arch/mips/kernel/genex.S index 2ac6c2625c13..ae810da4d499 100644 --- a/arch/mips/kernel/genex.S +++ b/arch/mips/kernel/genex.S | |||
@@ -215,9 +215,11 @@ NESTED(handle_int, PT_SIZE, sp) | |||
215 | beq t0, t1, 2f | 215 | beq t0, t1, 2f |
216 | 216 | ||
217 | /* Switch to IRQ stack */ | 217 | /* Switch to IRQ stack */ |
218 | li t1, _IRQ_STACK_SIZE | 218 | li t1, _IRQ_STACK_START |
219 | PTR_ADD sp, t0, t1 | 219 | PTR_ADD sp, t0, t1 |
220 | 220 | ||
221 | /* Save task's sp on IRQ stack so that unwinding can follow it */ | ||
222 | LONG_S s1, 0(sp) | ||
221 | 2: | 223 | 2: |
222 | jal plat_irq_dispatch | 224 | jal plat_irq_dispatch |
223 | 225 | ||
@@ -325,9 +327,11 @@ NESTED(except_vec_vi_handler, 0, sp) | |||
325 | beq t0, t1, 2f | 327 | beq t0, t1, 2f |
326 | 328 | ||
327 | /* Switch to IRQ stack */ | 329 | /* Switch to IRQ stack */ |
328 | li t1, _IRQ_STACK_SIZE | 330 | li t1, _IRQ_STACK_START |
329 | PTR_ADD sp, t0, t1 | 331 | PTR_ADD sp, t0, t1 |
330 | 332 | ||
333 | /* Save task's sp on IRQ stack so that unwinding can follow it */ | ||
334 | LONG_S s1, 0(sp) | ||
331 | 2: | 335 | 2: |
332 | jalr v0 | 336 | jalr v0 |
333 | 337 | ||
diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c index fb6b6b650719..b68e10fc453d 100644 --- a/arch/mips/kernel/process.c +++ b/arch/mips/kernel/process.c | |||
@@ -488,31 +488,52 @@ unsigned long notrace unwind_stack_by_address(unsigned long stack_page, | |||
488 | unsigned long pc, | 488 | unsigned long pc, |
489 | unsigned long *ra) | 489 | unsigned long *ra) |
490 | { | 490 | { |
491 | unsigned long low, high, irq_stack_high; | ||
491 | struct mips_frame_info info; | 492 | struct mips_frame_info info; |
492 | unsigned long size, ofs; | 493 | unsigned long size, ofs; |
494 | struct pt_regs *regs; | ||
493 | int leaf; | 495 | int leaf; |
494 | extern void ret_from_irq(void); | ||
495 | extern void ret_from_exception(void); | ||
496 | 496 | ||
497 | if (!stack_page) | 497 | if (!stack_page) |
498 | return 0; | 498 | return 0; |
499 | 499 | ||
500 | /* | 500 | /* |
501 | * If we reached the bottom of interrupt context, | 501 | * IRQ stacks start at IRQ_STACK_START |
502 | * return saved pc in pt_regs. | 502 | * task stacks at THREAD_SIZE - 32 |
503 | */ | 503 | */ |
504 | if (pc == (unsigned long)ret_from_irq || | 504 | low = stack_page; |
505 | pc == (unsigned long)ret_from_exception) { | 505 | if (!preemptible() && on_irq_stack(raw_smp_processor_id(), *sp)) { |
506 | struct pt_regs *regs; | 506 | high = stack_page + IRQ_STACK_START; |
507 | if (*sp >= stack_page && | 507 | irq_stack_high = high; |
508 | *sp + sizeof(*regs) <= stack_page + THREAD_SIZE - 32) { | 508 | } else { |
509 | regs = (struct pt_regs *)*sp; | 509 | high = stack_page + THREAD_SIZE - 32; |
510 | pc = regs->cp0_epc; | 510 | irq_stack_high = 0; |
511 | if (!user_mode(regs) && __kernel_text_address(pc)) { | 511 | } |
512 | *sp = regs->regs[29]; | 512 | |
513 | *ra = regs->regs[31]; | 513 | /* |
514 | return pc; | 514 | * If we reached the top of the interrupt stack, start unwinding |
515 | } | 515 | * the interrupted task stack. |
516 | */ | ||
517 | if (unlikely(*sp == irq_stack_high)) { | ||
518 | unsigned long task_sp = *(unsigned long *)*sp; | ||
519 | |||
520 | /* | ||
521 | * Check that the pointer saved in the IRQ stack head points to | ||
522 | * something within the stack of the current task | ||
523 | */ | ||
524 | if (!object_is_on_stack((void *)task_sp)) | ||
525 | return 0; | ||
526 | |||
527 | /* | ||
528 | * Follow pointer to tasks kernel stack frame where interrupted | ||
529 | * state was saved. | ||
530 | */ | ||
531 | regs = (struct pt_regs *)task_sp; | ||
532 | pc = regs->cp0_epc; | ||
533 | if (!user_mode(regs) && __kernel_text_address(pc)) { | ||
534 | *sp = regs->regs[29]; | ||
535 | *ra = regs->regs[31]; | ||
536 | return pc; | ||
516 | } | 537 | } |
517 | return 0; | 538 | return 0; |
518 | } | 539 | } |
@@ -533,8 +554,7 @@ unsigned long notrace unwind_stack_by_address(unsigned long stack_page, | |||
533 | if (leaf < 0) | 554 | if (leaf < 0) |
534 | return 0; | 555 | return 0; |
535 | 556 | ||
536 | if (*sp < stack_page || | 557 | if (*sp < low || *sp + info.frame_size > high) |
537 | *sp + info.frame_size > stack_page + THREAD_SIZE - 32) | ||
538 | return 0; | 558 | return 0; |
539 | 559 | ||
540 | if (leaf) | 560 | if (leaf) |