Skip to content

Commit 0366a1c

Browse files
committed
powerpc/irq: Run softirqs off the top of the irq stack
Nowadays, irq_exit() calls __do_softirq() pretty much directly instead of calling do_softirq() which switches to the decicated softirq stack. This has lead to observed stack overflows on powerpc since we call irq_enter() and irq_exit() outside of the scope that switches to the irq stack. This fixes it by moving the stack switching up a level, making irq_enter() and irq_exit() run off the irq stack. Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
1 parent 4a10c2a commit 0366a1c

4 files changed

Lines changed: 62 additions & 65 deletions

File tree

‎arch/powerpc/include/asm/irq.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ extern struct thread_info *softirq_ctx[NR_CPUS];
6969

7070
extern void irq_ctx_init(void);
7171
extern void call_do_softirq(struct thread_info *tp);
72-
extern int call_handle_irq(int irq, void *p1,
73-
struct thread_info *tp, void *func);
72+
extern void call_do_irq(struct pt_regs *regs, struct thread_info *tp);
7473
extern void do_IRQ(struct pt_regs *regs);
74+
extern void __do_irq(struct pt_regs *regs);
7575

7676
int irq_choose_cpu(const struct cpumask *mask);
7777

‎arch/powerpc/kernel/irq.c‎

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -441,50 +441,6 @@ void migrate_irqs(void)
441441
}
442442
#endif
443443

444-
static inline void handle_one_irq(unsigned int irq)
445-
{
446-
struct thread_info *curtp, *irqtp;
447-
unsigned long saved_sp_limit;
448-
struct irq_desc *desc;
449-
450-
desc = irq_to_desc(irq);
451-
if (!desc)
452-
return;
453-
454-
/* Switch to the irq stack to handle this */
455-
curtp = current_thread_info();
456-
irqtp = hardirq_ctx[smp_processor_id()];
457-
458-
if (curtp == irqtp) {
459-
/* We're already on the irq stack, just handle it */
460-
desc->handle_irq(irq, desc);
461-
return;
462-
}
463-
464-
saved_sp_limit = current->thread.ksp_limit;
465-
466-
irqtp->task = curtp->task;
467-
irqtp->flags = 0;
468-
469-
/* Copy the softirq bits in preempt_count so that the
470-
* softirq checks work in the hardirq context. */
471-
irqtp->preempt_count = (irqtp->preempt_count & ~SOFTIRQ_MASK) |
472-
(curtp->preempt_count & SOFTIRQ_MASK);
473-
474-
current->thread.ksp_limit = (unsigned long)irqtp +
475-
_ALIGN_UP(sizeof(struct thread_info), 16);
476-
477-
call_handle_irq(irq, desc, irqtp, desc->handle_irq);
478-
current->thread.ksp_limit = saved_sp_limit;
479-
irqtp->task = NULL;
480-
481-
/* Set any flag that may have been set on the
482-
* alternate stack
483-
*/
484-
if (irqtp->flags)
485-
set_bits(irqtp->flags, &curtp->flags);
486-
}
487-
488444
static inline void check_stack_overflow(void)
489445
{
490446
#ifdef CONFIG_DEBUG_STACKOVERFLOW
@@ -501,9 +457,9 @@ static inline void check_stack_overflow(void)
501457
#endif
502458
}
503459

504-
void do_IRQ(struct pt_regs *regs)
460+
void __do_irq(struct pt_regs *regs)
505461
{
506-
struct pt_regs *old_regs = set_irq_regs(regs);
462+
struct irq_desc *desc;
507463
unsigned int irq;
508464

509465
irq_enter();
@@ -519,18 +475,64 @@ void do_IRQ(struct pt_regs *regs)
519475
*/
520476
irq = ppc_md.get_irq();
521477

522-
/* We can hard enable interrupts now */
478+
/* We can hard enable interrupts now to allow perf interrupts */
523479
may_hard_irq_enable();
524480

525481
/* And finally process it */
526-
if (irq != NO_IRQ)
527-
handle_one_irq(irq);
528-
else
482+
if (unlikely(irq == NO_IRQ))
529483
__get_cpu_var(irq_stat).spurious_irqs++;
484+
else {
485+
desc = irq_to_desc(irq);
486+
if (likely(desc))
487+
desc->handle_irq(irq, desc);
488+
}
530489

531490
trace_irq_exit(regs);
532491

533492
irq_exit();
493+
}
494+
495+
void do_IRQ(struct pt_regs *regs)
496+
{
497+
struct pt_regs *old_regs = set_irq_regs(regs);
498+
struct thread_info *curtp, *irqtp;
499+
unsigned long saved_sp_limit;
500+
501+
/* Switch to the irq stack to handle this */
502+
curtp = current_thread_info();
503+
irqtp = hardirq_ctx[raw_smp_processor_id()];
504+
505+
/* Already there ? */
506+
if (unlikely(curtp == irqtp)) {
507+
__do_irq(regs);
508+
set_irq_regs(old_regs);
509+
return;
510+
}
511+
512+
/* Adjust the stack limit */
513+
saved_sp_limit = current->thread.ksp_limit;
514+
current->thread.ksp_limit = (unsigned long)irqtp +
515+
_ALIGN_UP(sizeof(struct thread_info), 16);
516+
517+
518+
/* Prepare the thread_info in the irq stack */
519+
irqtp->task = curtp->task;
520+
irqtp->flags = 0;
521+
522+
/* Copy the preempt_count so that the [soft]irq checks work. */
523+
irqtp->preempt_count = curtp->preempt_count;
524+
525+
/* Switch stack and call */
526+
call_do_irq(regs, irqtp);
527+
528+
/* Restore stack limit */
529+
current->thread.ksp_limit = saved_sp_limit;
530+
irqtp->task = NULL;
531+
532+
/* Copy back updates to the thread_info */
533+
if (irqtp->flags)
534+
set_bits(irqtp->flags, &curtp->flags);
535+
534536
set_irq_regs(old_regs);
535537
}
536538

@@ -592,12 +594,10 @@ void irq_ctx_init(void)
592594
memset((void *)softirq_ctx[i], 0, THREAD_SIZE);
593595
tp = softirq_ctx[i];
594596
tp->cpu = i;
595-
tp->preempt_count = 0;
596597

597598
memset((void *)hardirq_ctx[i], 0, THREAD_SIZE);
598599
tp = hardirq_ctx[i];
599600
tp->cpu = i;
600-
tp->preempt_count = HARDIRQ_OFFSET;
601601
}
602602
}
603603

‎arch/powerpc/kernel/misc_32.S‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,12 @@ _GLOBAL(call_do_softirq)
4747
mtlr r0
4848
blr
4949

50-
_GLOBAL(call_handle_irq)
50+
_GLOBAL(call_do_irq)
5151
mflr r0
5252
stw r0,4(r1)
53-
mtctr r6
54-
stwu r1,THREAD_SIZE-STACK_FRAME_OVERHEAD(r5)
55-
mr r1,r5
56-
bctrl
53+
stwu r1,THREAD_SIZE-STACK_FRAME_OVERHEAD(r4)
54+
mr r1,r4
55+
bl __do_irq
5756
lwz r1,0(r1)
5857
lwz r0,4(r1)
5958
mtlr r0

‎arch/powerpc/kernel/misc_64.S‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,12 @@ _GLOBAL(call_do_softirq)
4040
mtlr r0
4141
blr
4242

43-
_GLOBAL(call_handle_irq)
44-
ld r8,0(r6)
43+
_GLOBAL(call_do_irq)
4544
mflr r0
4645
std r0,16(r1)
47-
mtctr r8
48-
stdu r1,THREAD_SIZE-STACK_FRAME_OVERHEAD(r5)
49-
mr r1,r5
50-
bctrl
46+
stdu r1,THREAD_SIZE-STACK_FRAME_OVERHEAD(r4)
47+
mr r1,r4
48+
bl .__do_irq
5149
ld r1,0(r1)
5250
ld r0,16(r1)
5351
mtlr r0

0 commit comments

Comments
 (0)