Commit 1da5351f authored by Nicholas Piggin's avatar Nicholas Piggin Committed by Michael Ellerman

powerpc/64/irq: tidy soft-masked irq replay and improve documentation

irq replay is quite complicated because of softirq processing which
itself enables and disables irqs. Several considerations need to be
accounted for due to this, and they are not clearly documented.

Refactor the irq replay code a bit to tidy and deduplicate some common
functions. Add comments, debug checks.

This has a minor functional change that irq tracing enable/disable is
done after each interrupt replayed, rather than after a batch. It also
re-sets state to IRQS_ALL_DISABLED after an interrupt, which doesn't
matter much because interrupts are hard disabled at this point, but it
is more consistent with how interrupt handlers are called.
Signed-off-by: default avatarNicholas Piggin <npiggin@gmail.com>
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20220926054305.2671436-8-npiggin@gmail.com
parent f7bff6e7
...@@ -68,6 +68,35 @@ ...@@ -68,6 +68,35 @@
int distribute_irqs = 1; int distribute_irqs = 1;
static inline void next_interrupt(struct pt_regs *regs)
{
/*
* Softirq processing can enable/disable irqs, which will leave
* MSR[EE] enabled and the soft mask set to IRQS_DISABLED. Fix
* this up.
*/
if (!(local_paca->irq_happened & PACA_IRQ_HARD_DIS))
hard_irq_disable();
else
irq_soft_mask_set(IRQS_ALL_DISABLED);
/*
* We are responding to the next interrupt, so interrupt-off
* latencies should be reset here.
*/
trace_hardirqs_on();
trace_hardirqs_off();
}
static inline bool irq_happened_test_and_clear(u8 irq)
{
if (local_paca->irq_happened & irq) {
local_paca->irq_happened &= ~irq;
return true;
}
return false;
}
void replay_soft_interrupts(void) void replay_soft_interrupts(void)
{ {
struct pt_regs regs; struct pt_regs regs;
...@@ -79,18 +108,25 @@ void replay_soft_interrupts(void) ...@@ -79,18 +108,25 @@ void replay_soft_interrupts(void)
* recurse into this function. Don't keep any state across * recurse into this function. Don't keep any state across
* interrupt handler calls which may change underneath us. * interrupt handler calls which may change underneath us.
* *
* Softirqs can not be disabled over replay to stop this recursion
* because interrupts taken in idle code may require RCU softirq
* to run in the irq RCU tracking context. This is a hard problem
* to fix without changes to the softirq or idle layer.
*
* We use local_paca rather than get_paca() to avoid all the * We use local_paca rather than get_paca() to avoid all the
* debug_smp_processor_id() business in this low level function. * debug_smp_processor_id() business in this low level function.
*/ */
if (IS_ENABLED(CONFIG_PPC_IRQ_SOFT_MASK_DEBUG)) {
WARN_ON_ONCE(mfmsr() & MSR_EE);
WARN_ON(!(local_paca->irq_happened & PACA_IRQ_HARD_DIS));
}
ppc_save_regs(&regs); ppc_save_regs(&regs);
regs.softe = IRQS_ENABLED; regs.softe = IRQS_ENABLED;
regs.msr |= MSR_EE; regs.msr |= MSR_EE;
again: again:
if (IS_ENABLED(CONFIG_PPC_IRQ_SOFT_MASK_DEBUG))
WARN_ON_ONCE(mfmsr() & MSR_EE);
/* /*
* Force the delivery of pending soft-disabled interrupts on PS3. * Force the delivery of pending soft-disabled interrupts on PS3.
* Any HV call will have this side effect. * Any HV call will have this side effect.
...@@ -105,56 +141,47 @@ void replay_soft_interrupts(void) ...@@ -105,56 +141,47 @@ void replay_soft_interrupts(void)
* This is a higher priority interrupt than the others, so * This is a higher priority interrupt than the others, so
* replay it first. * replay it first.
*/ */
if (IS_ENABLED(CONFIG_PPC_BOOK3S) && (local_paca->irq_happened & PACA_IRQ_HMI)) { if (IS_ENABLED(CONFIG_PPC_BOOK3S) &&
local_paca->irq_happened &= ~PACA_IRQ_HMI; irq_happened_test_and_clear(PACA_IRQ_HMI)) {
regs.trap = INTERRUPT_HMI; regs.trap = INTERRUPT_HMI;
handle_hmi_exception(&regs); handle_hmi_exception(&regs);
if (!(local_paca->irq_happened & PACA_IRQ_HARD_DIS)) next_interrupt(&regs);
hard_irq_disable();
} }
if (local_paca->irq_happened & PACA_IRQ_DEC) { if (irq_happened_test_and_clear(PACA_IRQ_DEC)) {
local_paca->irq_happened &= ~PACA_IRQ_DEC;
regs.trap = INTERRUPT_DECREMENTER; regs.trap = INTERRUPT_DECREMENTER;
timer_interrupt(&regs); timer_interrupt(&regs);
if (!(local_paca->irq_happened & PACA_IRQ_HARD_DIS)) next_interrupt(&regs);
hard_irq_disable();
} }
if (local_paca->irq_happened & PACA_IRQ_EE) { if (irq_happened_test_and_clear(PACA_IRQ_EE)) {
local_paca->irq_happened &= ~PACA_IRQ_EE;
regs.trap = INTERRUPT_EXTERNAL; regs.trap = INTERRUPT_EXTERNAL;
do_IRQ(&regs); do_IRQ(&regs);
if (!(local_paca->irq_happened & PACA_IRQ_HARD_DIS)) next_interrupt(&regs);
hard_irq_disable();
} }
if (IS_ENABLED(CONFIG_PPC_DOORBELL) && (local_paca->irq_happened & PACA_IRQ_DBELL)) { if (IS_ENABLED(CONFIG_PPC_DOORBELL) &&
local_paca->irq_happened &= ~PACA_IRQ_DBELL; irq_happened_test_and_clear(PACA_IRQ_DBELL)) {
regs.trap = INTERRUPT_DOORBELL; regs.trap = INTERRUPT_DOORBELL;
doorbell_exception(&regs); doorbell_exception(&regs);
if (!(local_paca->irq_happened & PACA_IRQ_HARD_DIS)) next_interrupt(&regs);
hard_irq_disable();
} }
/* Book3E does not support soft-masking PMI interrupts */ /* Book3E does not support soft-masking PMI interrupts */
if (IS_ENABLED(CONFIG_PPC_BOOK3S) && (local_paca->irq_happened & PACA_IRQ_PMI)) { if (IS_ENABLED(CONFIG_PPC_BOOK3S) &&
local_paca->irq_happened &= ~PACA_IRQ_PMI; irq_happened_test_and_clear(PACA_IRQ_PMI)) {
regs.trap = INTERRUPT_PERFMON; regs.trap = INTERRUPT_PERFMON;
performance_monitor_exception(&regs); performance_monitor_exception(&regs);
if (!(local_paca->irq_happened & PACA_IRQ_HARD_DIS)) next_interrupt(&regs);
hard_irq_disable();
} }
if (local_paca->irq_happened & ~PACA_IRQ_HARD_DIS) { /*
/* * Softirq processing can enable and disable interrupts, which can
* We are responding to the next interrupt, so interrupt-off * result in new irqs becoming pending. Must keep looping until we
* latencies should be reset here. * have cleared out all pending interrupts.
*/ */
trace_hardirqs_on(); if (local_paca->irq_happened & ~PACA_IRQ_HARD_DIS)
trace_hardirqs_off();
goto again; goto again;
}
} }
#if defined(CONFIG_PPC_BOOK3S_64) && defined(CONFIG_PPC_KUAP) #if defined(CONFIG_PPC_BOOK3S_64) && defined(CONFIG_PPC_KUAP)
...@@ -270,10 +297,12 @@ notrace void arch_local_irq_restore(unsigned long mask) ...@@ -270,10 +297,12 @@ notrace void arch_local_irq_restore(unsigned long mask)
trace_hardirqs_off(); trace_hardirqs_off();
replay_soft_interrupts_irqrestore(); replay_soft_interrupts_irqrestore();
local_paca->irq_happened = 0;
trace_hardirqs_on(); trace_hardirqs_on();
irq_soft_mask_set(IRQS_ENABLED); irq_soft_mask_set(IRQS_ENABLED);
if (IS_ENABLED(CONFIG_PPC_IRQ_SOFT_MASK_DEBUG))
WARN_ON(local_paca->irq_happened != PACA_IRQ_HARD_DIS);
local_paca->irq_happened = 0;
__hard_irq_enable(); __hard_irq_enable();
preempt_enable(); preempt_enable();
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment