powerpc/mce: Avoid using irq_work_queue() in realmode
PATCH v5 1/1 powerpc/mce: Avoid using irq_work_queue() in realmode
In realmode mce handler we use irq_work_queue() to defer the processing of mce events, irq_work_queue() can only be called when translation is enabled because it touches memory outside RMA, hence we enable translation before calling irq_work_queue and disable on return, though it is not safe to do in realmode.
To avoid this, program the decrementer and call the event processing functions from timer handler.
---
V2:
* Use arch_irq_work_raise to raise decrementer interrupt.
* Avoid having atomic variable.
V3:
* Fix build error.
Reported by kernel test bot.
V4:
* Rename some functions and variables
* Remove mces_to_process counter and add a flag to indicate there is a mce info to process.
V5:
* Fix the build warning, reported by kernel test robot.
--- arch/powerpc/include/asm/machdep.h | 2 + arch/powerpc/include/asm/mce.h | 13 +++++ arch/powerpc/include/asm/paca.h | 1 + arch/powerpc/kernel/mce.c | 60 +++++++++++++----------- arch/powerpc/kernel/time.c | 2 + arch/powerpc/platforms/pseries/pseries.h | 1 + arch/powerpc/platforms/pseries/ras.c | 32 +------------ arch/powerpc/platforms/pseries/setup.c | 1 + 8 files changed, 53 insertions(+), 59 deletions(-)
arch/powerpc/include/asm/machdep.h +2 -0
@@ -99,6 +99,8 @@ struct machdep_calls {/* Called during machine check exception to retrive fixup address. */ bool (*mce_check_early_recovery)(struct pt_regs *regs); +void (*machine_check_log_err)(void ); +/* Motherboard/chipset features. This is a kind of general purpose * hook used to control some machine specific features (like reset * lines, chip power control, etc...).
arch/powerpc/include/asm/mce.h +13 -0
@@ -235,8 +235,21 @@ extern void machine_check_print_event_info(struct machine_check_event *evt,unsigned long addr_to_pfn (struct pt_regs *regs,unsigned long addr);extern void mce_common_process_ue (struct pt_regs *regs,struct mce_error_info *mce_err); +void mce_irq_work_queue (void );int mce_register_notifier (struct notifier_block *nb);int mce_unregister_notifier (struct notifier_block *nb); + +#ifdef CONFIG_PPC_BOOK3S_64 +void mce_run_irq_context_handlers (void ); +#else +static inline void mce_run_irq_context_handlers (void ) { }; +#endif /* CONFIG_PPC_BOOK3S_64 */ + +#ifdef CONFIG_PPC_BOOK3S_64 +void set_mce_pending_irq_work (void ); +void clear_mce_pending_irq_work (void ); +#endif /* CONFIG_PPC_BOOK3S_64 */ +#ifdef CONFIG_PPC_BOOK3S_64 void flush_and_reload_slb (void );void flush_erat (void );
arch/powerpc/include/asm/paca.h +1 -0
@@ -288,6 +288,7 @@ struct paca_struct {#endif #ifdef CONFIG_PPC_BOOK3S_64 struct mce_info *mce_info; +u8 mce_pending_irq_work;#endif /* CONFIG_PPC_BOOK3S_64 */ }____cacheline_aligned ;
arch/powerpc/kernel/mce.c +32 -28
111 lines not on this page · raw message
arch/powerpc/kernel/time.c +2 -0
@@ -70,6 +70,7 @@#include <asm/vdso_datapage.h> #include <asm/firmware.h> #include <asm/asm-prototypes.h> +#include <asm/mce.h> /* powerpc clocksource/clockevent code */
@@ -638,6 +639,7 @@ DEFINE_INTERRUPT_HANDLER_ASYNC(timer_interrupt)if (test_irq_work_pending ()) {clear_irq_work_pending (); +mce_run_irq_context_handlers ();irq_work_run (); }
arch/powerpc/platforms/pseries/pseries.h +1 -0
@@ -21,6 +21,7 @@ struct pt_regs;extern int pSeries_system_reset_exception (struct pt_regs *regs);extern int pSeries_machine_check_exception (struct pt_regs *regs);extern long pseries_machine_check_realmode (struct pt_regs *regs); +void pSeries_machine_check_log_err (void );#ifdef CONFIG_SMP extern void smp_init_pseries (void );
arch/powerpc/platforms/pseries/ras.c +1 -31
@@ -23,11 +23,6 @@ static DEFINE_SPINLOCK(ras_log_buf_lock);static int ras_check_exception_token; -static void mce_process_errlog_event (struct irq_work *work); -static struct irq_work mce_errlog_process_work = { - .func = mce_process_errlog_event, -}; -#define EPOW_SENSOR_TOKEN 9#define EPOW_SENSOR_INDEX 0
@@ -717,7 +712,6 @@ static int mce_handle_error(struct pt_regs *regs, struct rtas_error_log *errp)struct pseries_errorlog *pseries_log;struct pseries_mc_errorlog *mce_log =NULL ;int disposition =rtas_error_disposition (errp); -unsigned long msr;u8 error_type;if (!rtas_error_extended (errp))
@@ -731,40 +725,16 @@ static int mce_handle_error(struct pt_regs *regs, struct rtas_error_log *errp) error_type = mce_log->error_type; disposition =mce_handle_err_realmode (disposition, error_type); - -/* -* Enable translation as we will be accessing per-cpu variables -* in save_mce_event() which may fall outside RMO region, also -* leave it enabled because subsequently we will be queuing work -* to workqueues where again per-cpu variables accessed, besides -* fwnmi_release_errinfo() crashes when called in realmode on -* pseries. -* Note: All the realmode handling like flushing SLB entries for -* SLB multihit is done by now. -*/ out: - msr =mfmsr (); -mtmsr (msr |MSR_IR |MSR_DR ); - disposition =mce_handle_err_virtmode (regs, errp, mce_log, disposition); - -/* -* Queue irq work to log this rtas event later. -* irq_work_queue uses per-cpu variables, so do this in virt -* mode as well. -*/ -irq_work_queue (&mce_errlog_process_work); - -mtmsr (msr); -return disposition; }/* * Process MCE rtas errlog event. */ -static void mce_process_errlog_event (struct irq_work *work) +void pSeries_machine_check_log_err (void ) {struct rtas_error_log *err;
arch/powerpc/platforms/pseries/setup.c +1 -0
@@ -1086,6 +1086,7 @@ define_machine(pseries) { .system_reset_exception = pSeries_system_reset_exception, .machine_check_early = pseries_machine_check_realmode, .machine_check_exception = pSeries_machine_check_exception, + .machine_check_log_err = pSeries_machine_check_log_err, #ifdef CONFIG_KEXEC_CORE .machine_kexec = pSeries_machine_kexec, .kexec_cpu_down = pseries_kexec_cpu_down,
Signature · 1 line
2.31.1
Michael Ellerman
AppliedQuoted 8 lines · Ganesh Goudar
In realmode mce handler we use
irq_work_queue()to defer the processing of mce events,irq_work_queue()can only be called when translation is enabled because it touches memory outside RMA, hence we enable translation before callingirq_work_queueand disable on return, though it is not safe to do in realmode.[...]
Applied to powerpc/next.
[1/1] powerpc/mce: Avoid using irq_work_queue() in realmode
https://git.kernel.org/powerpc/c/cc15ff3275694fedc33cd3d53212a43eec7aa0bc
cheers