powerpc/64: Fix perf profiling asynchronous interrupt handlers
Nicholas Piggin
reviewerPATCH v2 1/1 powerpc/64: Fix perf profiling asynchronous interrupt handlers
Interrupt entry sets the soft mask to IRQS_ALL_DISABLED to match the hard irq disabled state. So when should_hard_irq_enable() returns true because we want PMI interrupts in irq handlers, MSR[EE] is enabled but PMIs just get soft-masked. Fix this by clearing IRQS_PMI_DISABLED before enabling MSR[EE].
This also tidies some of the warnings, no need to duplicate them in both should_hard_irq_enable() and do_hard_irq_enable().
---
Since v1: just a rebase and re-test.
arch/powerpc/include/asm/hw_irq.h | 41 ++++++++++++++++++++++--------- arch/powerpc/kernel/dbell.c | 2 +- arch/powerpc/kernel/irq.c | 2 +- arch/powerpc/kernel/time.c | 2 +- 4 files changed, 32 insertions(+), 15 deletions(-)
arch/powerpc/include/asm/hw_irq.h +29 -12
@@ -173,6 +173,15 @@ static inline notrace unsigned long irq_soft_mask_or_return(unsigned long mask)return flags; } +static inline notrace unsigned long irq_soft_mask_andc_return (unsigned long mask) +{ +unsigned long flags =irq_soft_mask_return (); + +irq_soft_mask_set (flags & ~mask); + +return flags; +} +static inline unsigned long arch_local_save_flags (void ) {return irq_soft_mask_return ();
@@ -334,10 +343,11 @@ bool power_pmu_wants_prompt_pmi(void);* is a different soft-masked interrupt pending that requires hard * masking. */ -static inline bool should_hard_irq_enable (void ) +static inline bool should_hard_irq_enable (struct pt_regs *regs) {if (IS_ENABLED (CONFIG_PPC_IRQ_SOFT_MASK_DEBUG )) { -WARN_ON (irq_soft_mask_return () ==IRQS_ENABLED ); +WARN_ON (irq_soft_mask_return () !=IRQS_ALL_DISABLED ); +WARN_ON (!(get_paca ()->irq_happened &PACA_IRQ_HARD_DIS ));WARN_ON (mfmsr () &MSR_EE ); }
@@ -350,8 +360,17 @@ static inline bool should_hard_irq_enable(void)* * TODO: Add test for 64e */ -if (IS_ENABLED (CONFIG_PPC_BOOK3S_64 ) && !power_pmu_wants_prompt_pmi ()) -return false; +if (IS_ENABLED (CONFIG_PPC_BOOK3S_64 )) { +if (!power_pmu_wants_prompt_pmi ()) +return false; +/* +* If PMIs are disabled then IRQs should be disabled as well, +* so we shouldn't see this condition, check for it just in +* case because we are about to enable PMIs. +*/ +if (WARN_ON_ONCE (regs->softe &IRQS_PMI_DISABLED )) +return false; + }if (get_paca ()->irq_happened &PACA_IRQ_MUST_HARD_MASK )return false;
@@ -361,18 +380,16 @@ static inline bool should_hard_irq_enable(void)/* * Do the hard enabling, only call this if should_hard_irq_enable is true. +* This allows PMI interrupts to profile irq handlers. */ static inline void do_hard_irq_enable (void ) { -if (IS_ENABLED (CONFIG_PPC_IRQ_SOFT_MASK_DEBUG )) { -WARN_ON (irq_soft_mask_return () ==IRQS_ENABLED ); -WARN_ON (get_paca ()->irq_happened &PACA_IRQ_MUST_HARD_MASK ); -WARN_ON (mfmsr () &MSR_EE ); - }/* -* This allows PMI interrupts (and watchdog soft-NMIs) through. -* There is no other reason to enable this way. +* Asynch interrupts come in with IRQS_ALL_DISABLED, +* PACA_IRQ_HARD_DIS, and MSR[EE]=0. */ +if (IS_ENABLED (CONFIG_PPC_BOOK3S_64 )) +irq_soft_mask_andc_return (IRQS_PMI_DISABLED );get_paca ()->irq_happened &= ~PACA_IRQ_HARD_DIS ;__hard_irq_enable (); }
@@ -455,7 +472,7 @@ static inline bool arch_irq_disabled_regs(struct pt_regs *regs)return !(regs->msr &MSR_EE ); } -static __always_inline bool should_hard_irq_enable(void) +static __always_inline bool should_hard_irq_enable(struct pt_regs *regs) {return false; }
arch/powerpc/kernel/dbell.c +1 -1
@@ -27,7 +27,7 @@ DEFINE_INTERRUPT_HANDLER_ASYNC(doorbell_exception)ppc_msgsync (); -if (should_hard_irq_enable ()) +if (should_hard_irq_enable (regs))do_hard_irq_enable ();kvmppc_clear_host_ipi (smp_processor_id ());
arch/powerpc/kernel/irq.c +1 -1
@@ -238,7 +238,7 @@ static void __do_irq(struct pt_regs *regs, unsigned long oldsp) irq =static_call (ppc_get_irq)();/* We can hard enable interrupts now to allow perf interrupts */ -if (should_hard_irq_enable ()) +if (should_hard_irq_enable (regs))do_hard_irq_enable ();/* And finally process it */
arch/powerpc/kernel/time.c +1 -1
@@ -515,7 +515,7 @@ DEFINE_INTERRUPT_HANDLER_ASYNC(timer_interrupt) }/* Conditionally hard-enable interrupts. */ -if (should_hard_irq_enable ()) { +if (should_hard_irq_enable (regs)) {/* * Ensure a positive value is written to the decrementer, or * else some CPUs will continue to take decrementer exceptions.
Signature · 1 line
2.37.2
Michael Ellerman
AppliedQuoted 10 lines · Nicholas Piggin
Interrupt entry sets the soft mask to
IRQS_ALL_DISABLEDto match the hard irq disabled state. So whenshould_hard_irq_enable()returns true because we want PMI interrupts in irq handlers, MSR[EE] is enabled but PMIs just get soft-masked. Fix this by clearingIRQS_PMI_DISABLEDbefore enabling MSR[EE].This also tidies some of the warnings, no need to duplicate them in both
should_hard_irq_enable()anddo_hard_irq_enable().[...]
Applied to powerpc/fixes.
[1/1] powerpc/64: Fix perf profiling asynchronous interrupt handlers
https://git.kernel.org/powerpc/c/c28548012ee2bac55772ef7685138bd1124b80c3
cheers