More NMI IPI enablement work
Nicholas Piggin
reviewercover More NMI IPI enablement work
Hi,
Here is the NMI IPI enablement for powernv, which requires supported firmware and hardware:
https://lists.ozlabs.org/pipermail/skiboot/2017-September/009111.html
And some preceeding patches that fix issues I ran into when testing it.
Thanks,
Nick
Nicholas Piggin (5):
powerpc/watchdog: do not panic from locked CPU's IPI handler powerpc/watchdog: do not backtrace locked CPUs twice if allcpus
backtrace is enabled
powerpc/watchdog: do not trigger SMP crash from touch_nmi_watchdog powerpc/xmon: avoid tripping SMP hardlockup watchdog powerpc/powernv: implement NMI IPI with OPAL_SIGNAL_SYSTEM_RESET
arch/powerpc/include/asm/opal-api.h | 1 + arch/powerpc/include/asm/opal.h | 2 ++ arch/powerpc/kernel/irq.c | 43 +++++++++++++++++++--- arch/powerpc/kernel/watchdog.c | 29 ++++++++------- arch/powerpc/platforms/powernv/opal-wrappers.S | 1 + arch/powerpc/platforms/powernv/powernv.h | 1 + arch/powerpc/platforms/powernv/setup.c | 3 ++ arch/powerpc/platforms/powernv/smp.c | 50 ++++++++++++++++++++++++++ arch/powerpc/xmon/xmon.c | 17 ++++++--- 9 files changed, 127 insertions(+), 20 deletions(-)
Signature · 1 line
2.13.3
Nicholas Piggin
reviewerPATCH 1/5 powerpc/watchdog: do not panic from locked CPU's IPI handler
The SMP watchdog will detect locked CPUs and IPI them to print a backtrace and registers. If panic on hard lockup is enabled, do not panic from this handler, because that can cause recursion into the IPI layer during the panic.
The caller already panics in this case.
--- arch/powerpc/kernel/watchdog.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
arch/powerpc/kernel/watchdog.c +1 -2
@@ -97,8 +97,7 @@ static void wd_lockup_ipi(struct pt_regs *regs)else dump_stack (); -if (hardlockup_panic) -nmi_panic (regs,"Hard LOCKUP" ); +/* Do not panic from here because that can recurse into NMI IPI layer */ }static void set_cpumask_stuck (const struct cpumask *cpumask,u64 tb)
Signature · 1 line
2.13.3
Nicholas Piggin
reviewerPATCH 2/5 powerpc/watchdog: do not backtrace locked CPUs twice if allcpus backtrace is enabled
In reply to Nicholas PigginIf sysctl_hardlockup_all_cpu_backtrace is enabled, there is no need to IPI stuck CPUs for backtrace before trigger_allbutself_cpu_backtrace(), which does the same thing again.
--- arch/powerpc/kernel/watchdog.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-)
arch/powerpc/kernel/watchdog.c +11 -8
@@ -133,15 +133,18 @@ static void watchdog_smp_panic(int cpu, u64 tb)pr_emerg ("Watchdog CPU:%d detected Hard LOCKUP other CPUS:%*pbl\n" , cpu,cpumask_pr_args (&wd_smp_cpus_pending)); -/* -* Try to trigger the stuck CPUs. -*/ -for_each_cpu (c, &wd_smp_cpus_pending) { -if (c == cpu) -continue ; -smp_send_nmi_ipi (c, wd_lockup_ipi,1000000 ); +if (!sysctl_hardlockup_all_cpu_backtrace) { +/* +* Try to trigger the stuck CPUs, unless we are going to +* get a backtrace on all of them anyway. +*/ +for_each_cpu (c, &wd_smp_cpus_pending) { +if (c == cpu) +continue ; +smp_send_nmi_ipi (c, wd_lockup_ipi,1000000 ); + } +smp_flush_nmi_ipi (1000000 ); } -smp_flush_nmi_ipi (1000000 );/* Take the stuck CPUs out of the watch group */ set_cpumask_stuck (&wd_smp_cpus_pending, tb);
Signature · 1 line
2.13.3
Nicholas Piggin
reviewerPATCH 3/5 powerpc/watchdog: do not trigger SMP crash from touch_nmi_watchdog
In reply to Nicholas PigginIn xmon, touch_nmi_watchdog() is not expected to be checking that other CPUs have not touched the watchdog, so the code will just call touch_nmi_watchdog() once before re-enabling hard interrupts.
Just update our CPU's state, and ignore apparently stuck SMP threads.
Arguably touch_nmi_watchdog should check for SMP lockups, and callers should be fixed, but that's not trivial for the input code of xmon.
--- arch/powerpc/kernel/watchdog.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
arch/powerpc/kernel/watchdog.c +5 -2
@@ -277,9 +277,12 @@ void arch_touch_nmi_watchdog(void) {unsigned long ticks = tb_ticks_per_usec * wd_timer_period_ms *1000 ;int cpu =smp_processor_id (); +u64 tb =get_tb (); -if (get_tb () -per_cpu (wd_timer_tb, cpu) >= ticks) -watchdog_timer_interrupt (cpu); +if (tb -per_cpu (wd_timer_tb, cpu) >= ticks) { +per_cpu (wd_timer_tb, cpu) = tb; +wd_smp_clear_cpu_pending (cpu, tb); + } }EXPORT_SYMBOL (arch_touch_nmi_watchdog);
Signature · 1 line
2.13.3
Nicholas Piggin
reviewerPATCH 4/5 powerpc/xmon: avoid tripping SMP hardlockup watchdog
In reply to Nicholas PigginThe SMP hardlockup watchdog cross-checks other CPUs for lockups, which causes xmon headaches because it's assuming interrupts hard disabled means no watchdog troubles. Try to improve that by calling touch_nmi_watchdog() in obvious places where secondaries are spinning.
Also annotate these spin loops with spin_begin/end calls.
--- arch/powerpc/xmon/xmon.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)
arch/powerpc/xmon/xmon.c +13 -4
@@ -530,14 +530,19 @@ static int xmon_core(struct pt_regs *regs, int fromipi) waiting: secondary =1 ; +spin_begin ();while (secondary && !xmon_gate) {if (in_xmon ==0 ) { -if (fromipi) +if (fromipi) { +spin_end (); goto leave; + } secondary =test_and_set_bit (0 , &in_xmon); } -barrier (); +spin_cpu_relax (); +touch_nmi_watchdog (); } +spin_end ();if (!secondary && !xmon_gate) {/* we are the first cpu to come in */
@@ -568,21 +573,25 @@ static int xmon_core(struct pt_regs *regs, int fromipi)mb (); xmon_gate =1 ;barrier (); +touch_nmi_watchdog (); } cmdloop:while (in_xmon) {if (secondary) { +spin_begin ();if (cpu == xmon_owner) {if (!test_and_set_bit (0 , &xmon_taken)) { secondary =0 ; +spin_end ();continue ; }/* missed it */ while (cpu == xmon_owner) -barrier (); +spin_cpu_relax (); } -barrier (); +spin_cpu_relax (); +touch_nmi_watchdog (); }else { cmd =cmds (regs);if (cmd !=0 ) {
Signature · 1 line
2.13.3
Nicholas Piggin
reviewerPATCH 5/5 powerpc/powernv: implement NMI IPI with OPAL_SIGNAL_SYSTEM_RESET
In reply to Nicholas PigginThis allows MSR[EE]=0 lockups to be detected on an OPAL (bare metal) system similarly to the hcall NMI IPI on pseries guests, when the platform/firmware supports it.
This is an example of CPU10 spinning with interrupts hard disabled:
Watchdog CPU:32 detected Hard LOCKUP other CPUS:10 Watchdog CPU:10 Hard LOCKUP
CPU: 10 PID: 4410 Comm: bash Not tainted 4.13.0-rc7-00074-ge89ce1f89f62-dirty #34
task: c0000003a82b4400 task.stack: c0000003af55c000
NIP: c0000000000a7b38 LR: c000000000659044 CTR: c0000000000a7b00
REGS: c00000000fd23d80 TRAP: 0100 Not tainted (4.13.0-rc7-00074-ge89ce1f89f62-dirty)
MSR: 90000000000c1033 <SF,HV,ME,IR,DR,RI,LE>
CR: 28422222 XER: 20000000
CFAR: c0000000000a7b38 SOFTE: 0
GPR00: c000000000659044 c0000003af55fbb0 c000000001072a00 0000000000000078
GPR04: c0000003c81b5c80 c0000003c81cc7e8 9000000000009033 0000000000000000
GPR08: 0000000000000000 c0000000000a7b00 0000000000000001 9000000000001003
GPR12: c0000000000a7b00 c00000000fd83200 0000000010180df8 0000000010189e60
GPR16: 0000000010189ed8 0000000010151270 000000001018bd88 000000001018de78
GPR20: 00000000370a0668 0000000000000001 00000000101645e0 0000000010163c10
GPR24: 00007fffd14d6294 00007fffd14d6290 c000000000fba6f0 0000000000000004
GPR28: c000000000f351d8 0000000000000078 c000000000f4095c 0000000000000000 NIP [c0000000000a7b38] sysrq_handle_xmon+0x38/0x40
LR [c000000000659044] __handle_sysrq+0xe4/0x270
Call Trace: [c0000003af55fbd0] [c000000000659044] __handle_sysrq+0xe4/0x270 [c0000003af55fc70] [c000000000659810] write_sysrq_trigger+0x70/0xa0 [c0000003af55fca0] [c0000000003da650] proc_reg_write+0xb0/0x110 [c0000003af55fcf0] [c0000000003423bc] __vfs_write+0x6c/0x1b0 [c0000003af55fd90] [c000000000344398] vfs_write+0xd8/0x240 [c0000003af55fde0] [c00000000034632c] SyS_write+0x6c/0x110 [c0000003af55fe30] [c00000000000b220] system_call+0x58/0x6c
--- arch/powerpc/include/asm/opal-api.h | 1 + arch/powerpc/include/asm/opal.h | 2 ++ arch/powerpc/kernel/irq.c | 43 +++++++++++++++++++--- arch/powerpc/platforms/powernv/opal-wrappers.S | 1 + arch/powerpc/platforms/powernv/powernv.h | 1 + arch/powerpc/platforms/powernv/setup.c | 3 ++ arch/powerpc/platforms/powernv/smp.c | 50 ++++++++++++++++++++++++++ 7 files changed, 97 insertions(+), 4 deletions(-)
arch/powerpc/include/asm/opal-api.h +1 -0
@@ -188,6 +188,7 @@#define OPAL_XIVE_DUMP 142#define OPAL_XIVE_RESERVED3 143#define OPAL_XIVE_RESERVED4 144 +#define OPAL_SIGNAL_SYSTEM_RESET 145#define OPAL_NPU_INIT_CONTEXT 146#define OPAL_NPU_DESTROY_CONTEXT 147#define OPAL_NPU_MAP_LPAR 148
arch/powerpc/include/asm/opal.h +2 -0
@@ -281,6 +281,8 @@ int opal_get_power_shift_ratio(u32 handle, int token, u32 *psr);int opal_set_power_shift_ratio (u32 handle,int token,u32 psr);int opal_sensor_group_clear (u32 group_hndl,int token); +int64_t opal_signal_system_reset (int32_t cpu); +/* Internal functions */ extern int early_init_dt_scan_opal (unsigned long node,const char *uname,int depth,void *data);
arch/powerpc/kernel/irq.c +39 -4
65 lines not on this page · raw message
arch/powerpc/platforms/powernv/opal-wrappers.S +1 -0
@@ -307,6 +307,7 @@ OPAL_CALL(opal_xive_get_vp_info, OPAL_XIVE_GET_VP_INFO); OPAL_CALL(opal_xive_set_vp_info, OPAL_XIVE_SET_VP_INFO); OPAL_CALL(opal_xive_sync, OPAL_XIVE_SYNC); OPAL_CALL(opal_xive_dump, OPAL_XIVE_DUMP); +OPAL_CALL(opal_signal_system_reset, OPAL_SIGNAL_SYSTEM_RESET); OPAL_CALL(opal_npu_init_context, OPAL_NPU_INIT_CONTEXT); OPAL_CALL(opal_npu_destroy_context, OPAL_NPU_DESTROY_CONTEXT); OPAL_CALL(opal_npu_map_lpar, OPAL_NPU_MAP_LPAR);
arch/powerpc/platforms/powernv/powernv.h +1 -0
@@ -3,6 +3,7 @@#ifdef CONFIG_SMP extern void pnv_smp_init (void ); +extern int pnv_system_reset_exception (struct pt_regs *regs);#else static inline void pnv_smp_init (void ) { }#endif
arch/powerpc/platforms/powernv/setup.c +3 -0
@@ -282,6 +282,9 @@ static void __init pnv_setup_machdep_opal(void) ppc_md.restart = pnv_restart; pm_power_off = pnv_power_off; ppc_md.halt = pnv_halt; +#ifdef CONFIG_SMP + ppc_md.system_reset_exception = pnv_system_reset_exception; +#endif ppc_md.machine_check_exception = opal_machine_check; ppc_md.mce_check_early_recovery = opal_mce_check_early_recovery; ppc_md.hmi_exception_early = opal_hmi_exception_early;
arch/powerpc/platforms/powernv/smp.c +50 -0
62 lines not on this page · raw message
Signature · 1 line
2.13.3
Michael Ellerman
reviewerQuoted 9 lines · Nicholas Piggin
Hi,
Here is the NMI IPI enablement for powernv, which requires supported firmware and hardware:
https://lists.ozlabs.org/pipermail/skiboot/2017-September/009111.html
And some preceeding patches that fix issues I ran into when testing it.
Are any of these critical such that I should pick them up for 4.14 or earlier?
cheers
Nicholas Piggin
reviewerQuoted 7 lines · On Thu, 21 Sep 2017 21:10:42 +1000 Michael Ellerman <[email protected]> wrote:
Quoted 5 lines · Nicholas Piggin
Hi,
Here is the NMI IPI enablement for powernv, which requires supported firmware and hardware:
Quoted 7 lines
Quoted 4 lines
https://lists.ozlabs.org/pipermail/skiboot/2017-September/009111.html
And some preceeding patches that fix issues I ran into when testing it.
Are any of these critical such that I should pick them up for 4.14 or earlier?
Good point, yes. The hardlockup watchdog now does SMP cross-checking, so it can blow up when you stay in xmon for about 10 seconds since the new watchdog was merged. We want patches 3-4 for that.
Patch 1 is not really required, I only ran into it when I tried making smp_send_stop use the NMI IPI, which we are not doing just yet. That being said, the watchdog code is new, so probably doesn't hurt to put in 4.14.
Patch 3 makes all-cpus backtraces a bit more concise. Less critical.
The system reset stuff I guess we'll want to backport for distros, so 4.14 might be reasonable not sure.
Actually patch 5 before you merge it I should remove the DD1 workaround too because we're not supporting that in OPAL anymore.
Thanks,
Nick