powerpc: Add workaround for P9 vector CI load issue
PATCH 1/2 powerpc: Add workaround for P9 vector CI load issue
POWER9 DD2.1 and earlier has an issue where some cache inhibited vector load will return bad data. The workaround is two part, one firmware/microcode part triggers HMI interrupts when hitting such loads, the other part is this patch which then emulates the instructions in Linux.
The affected instructions are limited to lxvd2x, lxvw4x, lxvb16x and lxvh8x.
When an instruction triggers the HMI, all threads in the core will be sent to the HMI handler, not just the one running the vector load.
In general, these spurious HMIs are detected by the emulation code and we just return back to the running process. Unfortunately, if a spurious interrupt occurs on a vector load that's to normal memory we have no way to detect that it's spurious (unless we walk the page tables, which is very expensive). In this case we emulate the load but we need do so using a vector load itself to ensure 128bit atomicity is preserved.
Some additional debugfs emulated instruction counters are added also.
--- arch/powerpc/include/asm/emulated_ops.h | 4 + arch/powerpc/include/asm/paca.h | 1 + arch/powerpc/include/asm/uaccess.h | 17 +++ arch/powerpc/kernel/exceptions-64s.S | 16 ++- arch/powerpc/kernel/mce.c | 30 ++++- arch/powerpc/kernel/traps.c | 201 ++++++++++++++++++++++++++++++++ arch/powerpc/platforms/powernv/smp.c | 7 ++ 7 files changed, 271 insertions(+), 5 deletions(-)
arch/powerpc/include/asm/emulated_ops.h +4 -0
@@ -55,6 +55,10 @@ extern struct ppc_emulated {struct ppc_emulated_entry mfdscr;struct ppc_emulated_entry mtdscr;struct ppc_emulated_entry lq_stq; +struct ppc_emulated_entry lxvw4x; +struct ppc_emulated_entry lxvh8x; +struct ppc_emulated_entry lxvd2x; +struct ppc_emulated_entry lxvb16x;#endif } ppc_emulated;
arch/powerpc/include/asm/paca.h +1 -0
@@ -210,6 +210,7 @@ struct paca_struct {*/ u16 in_mce;u8 hmi_event_available;/* HMI event is available */ +u8 hmi_p9_special_emu;/* HMI P9 special emulation */ #endif /* Stuff for accurate time accounting */
arch/powerpc/include/asm/uaccess.h +17 -0
@@ -173,6 +173,23 @@ do { \extern long __get_user_bad (void ); +/* +* This does an atomic 128 byte aligned load from userspace. +* Upto caller to do enable_kernel_vmx() before calling! +*/ +#define __get_user_atomic_128_aligned (kaddr, uaddr, err) \ + __asm__ __volatile__( \ + "1: lvx 0,0,%1 # get user\n" \ + " stvx 0,0,%2 # put kernel\n" \ + "2:\n" \ + ".section .fixup,\"ax\"\n" \ + "3: li %0,%3\n" \ + " b 2b\n" \ + ".previous\n" \ + EX_TABLE(1b, 3b) \ + : "=r" (err) \ + : "b" (uaddr), "b" (kaddr), "i" (-EFAULT), "0" (err)) +#define __get_user_asm (x, addr, err, op) \ __asm__ __volatile__( \ "1: "op" %1,0(%2) # get_user\n" \
arch/powerpc/kernel/exceptions-64s.S +12 -4
@@ -1010,6 +1010,8 @@ TRAMP_REAL_BEGIN(hmi_exception_early) EXCEPTION_PROLOG_COMMON_3(0xe60) addi r3,r1,STACK_FRAME_OVERHEAD BRANCH_LINK_TO_FAR(hmi_exception_realmode) /* Function call ABI */ + cmpdi cr0,r3,0 + /* Windup the stack. */ /* Move original HSRR0 and HSRR1 into the respective regs */ ld r9,_MSR(r1)
@@ -1026,10 +1028,15 @@ TRAMP_REAL_BEGIN(hmi_exception_early) REST_8GPRS(2, r1) REST_GPR(10, r1) ld r11,_CCR(r1) + REST_2GPRS(12, r1) + bne 1f mtcr r11 REST_GPR(11, r1) - REST_2GPRS(12, r1) - /* restore original r1. */ + ld r1,GPR1(r1) + hrfid + +1: mtcr r11 + REST_GPR(11, r1) ld r1,GPR1(r1) /*
@@ -1042,8 +1049,9 @@ hmi_exception_after_realmode: EXCEPTION_PROLOG_0(PACA_EXGEN) b tramp_real_hmi_exception -EXC_COMMON_ASYNC(hmi_exception_common, 0xe60, handle_hmi_exception) - +EXC_COMMON_BEGIN(hmi_exception_common) +EXCEPTION_COMMON(PACA_EXGEN, 0xe60, hmi_exception_common, handle_hmi_exception, + ret_from_except, FINISH_NAP;ADD_NVGPRS;ADD_RECONCILE;RUNLATCH_ON) EXC_REAL_OOL_MASKABLE_HV(h_doorbell, 0xe80, 0x20) EXC_VIRT_OOL_MASKABLE_HV(h_doorbell, 0x4e80, 0x20, 0xe80)
arch/powerpc/kernel/mce.c +29 -1
@@ -470,6 +470,34 @@ long hmi_exception_realmode(struct pt_regs *regs) {__this_cpu_inc (irq_stat.hmi_exceptions); +#ifdef CONFIG_PPC_BOOK3S_64 +/* Workaround for P9 vector CI loads (see p9_hmi_special_emu) */ +if (pvr_version_is (PVR_POWER9 )) { +unsigned long hmer =mfspr (SPRN_HMER ); + +/* Do we have the debug bit set */ +if (hmer &PPC_BIT (17 )) { + hmer &= ~PPC_BIT (17 ); +mtspr (SPRN_HMER , hmer); + +/* +* Now to avoid problems with soft-disable we +* only do the emulation if we are coming from +* user space +*/ +if (user_mode (regs)) + local_paca->hmi_p9_special_emu =1 ; + +/* +* Don't bother going to OPAL if that's the +* only relevant bit. +*/ +if (!(hmer &mfspr (SPRN_HMEER ))) +return local_paca->hmi_p9_special_emu; + } + } +#endif /* CONFIG_PPC_BOOK3S_64 */ +wait_for_subcore_guest_exit ();if (ppc_md.hmi_exception_early)
@@ -477,5 +505,5 @@ long hmi_exception_realmode(struct pt_regs *regs)wait_for_tb_resync (); -return 0 ; +return 1 ; }
arch/powerpc/kernel/traps.c +201 -0
225 lines not on this page · raw message
arch/powerpc/platforms/powernv/smp.c +7 -0
@@ -49,6 +49,13 @@static void pnv_smp_setup_cpu (int cpu) { +/* +* P9 workaround for CI vector load (see traps.c), +* enable the corresponding HMI interrupt +*/ +if (pvr_version_is (PVR_POWER9 )) +mtspr (SPRN_HMEER ,mfspr (SPRN_HMEER ) |PPC_BIT (17 )); +if (xive_enabled ())xive_smp_setup_cpu ();else if (cpu != boot_cpuid)
Signature · 1 line
2.11.0
PATCH 2/2 powerpc: Handle MCE on POWER9 with only DSISR bit 33 set
On POWER9 DD2.1 and below, it's possible to get Machine Check Exception (MCE) where only DSISR bit 33 is set. This will result in the linux MCE handler seeing an unknown event, which triggers linux to crash.
We change this by detecting unknown events in the MCE handler and marking them as handled so that we no longer crash. We do this only on chip revisions known to have this problem.
--- arch/powerpc/kernel/mce_power.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
arch/powerpc/kernel/mce_power.c +15 -0
@@ -595,6 +595,7 @@ static long mce_handle_error(struct pt_regs *regs,uint64_t addr;uint64_t srr1 = regs->msr;long handled; +unsigned long pvr;if (SRR1_MC_LOADSTORE (srr1)) handled =mce_handle_derror (regs, dtable, &mce_err, &addr);
@@ -604,6 +605,20 @@ static long mce_handle_error(struct pt_regs *regs,if (!handled && mce_err.error_type ==MCE_ERROR_TYPE_UE ) handled =mce_handle_ue_error (regs); +/* +* On POWER9 DD2.1 and below, it's possible to get machine +* check where only DSISR bit 33 is set. This will result in +* the MCE handler seeing an unknown event and us crashing. +* Change this to mark as handled on these revisions. +*/ + pvr =mfspr (SPRN_PVR ); +if (((PVR_VER (pvr) ==PVR_POWER9 ) && + (PVR_CFG (pvr) ==2 ) && + (PVR_MIN (pvr) <=1 )) ||cpu_has_feature (CPU_FTR_POWER9_DD1 )) +/* DD2.1 and below */ +if (mce_err.error_type ==MCE_ERROR_TYPE_UNKNOWN ) + handled =1 ; +save_mce_event (regs, handled, &mce_err, regs->nip, addr);return handled;
Signature · 1 line
2.11.0
Re: [PATCH 2/2] powerpc: Handle MCE on POWER9 with only DSISR bit 33 set
Quoted 34 lines · Michael Neuling
On POWER9 DD2.1 and below, it's possible to get Machine Check Exception (MCE) where only DSISR bit 33 is set. This will result in the linux MCE handler seeing an unknown event, which triggers linux to crash.
We change this by detecting unknown events in the MCE handler and marking them as handled so that we no longer crash. We do this only on chip revisions known to have this problem.
Signed-off-by Michael Neuling <[email protected]>--- arch/powerpc/kernel/mce_power.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)arch/powerpc/kernel/mce_power.c +5
-0@@ -595,6 +595,7 @@ static long mce_handle_error(struct pt_regs *regs,uint64_t addr;uint64_t srr1 = regs->msr;long handled; +unsigned long pvr;if (SRR1_MC_LOADSTORE (srr1)) handled =mce_handle_derror (regs, dtable, &mce_err, &addr);@@ -604,6 +605,20 @@ static long mce_handle_error(struct pt_regs *regs,if (!handled && mce_err.error_type ==MCE_ERROR_TYPE_UE ) handled =mce_handle_ue_error (regs); +/* +* On POWER9 DD2.1 and below, it's possible to get machine +* check where only DSISR bit 33 is set. This will result in +* the MCE handler seeing an unknown event and us crashing.
arch/powerpc/kernel/mce_power.c static long mce_handle_error(struct pt_regs *regs, · line 621
Quoted 10 lines
arch/powerpc/kernel/mce_power.c +10
-0+* Change this to mark as handled on these revisions. +*/ + pvr =mfspr (SPRN_PVR ); +if (((PVR_VER (pvr) ==PVR_POWER9 ) && + (PVR_CFG (pvr) ==2 ) && + (PVR_MIN (pvr) <=1 )) ||cpu_has_feature (CPU_FTR_POWER9_DD1 )) +/* DD2.1 and below */ +if (mce_err.error_type ==MCE_ERROR_TYPE_UNKNOWN ) + handled =1 ; +
What does this mean in terms of handling? Since we do not know the event, how do we recover/handle? The system will anyway crash for not-recovered cases. Does this prevent us from seeing the same exception several times?
Balbir Singh.
Re: [PATCH 2/2] powerpc: Handle MCE on POWER9 with only DSISR bit 33 set
Cj4gPiArwqDCoMKgwqDCoMKgwqAvKgo+ID4gK8KgwqDCoMKgwqDCoMKgwqAqIE9uIFBPV0VSOSBE RDIuMSBhbmQgYmVsb3csIGl0J3MgcG9zc2libGUgdG8gZ2V0IG1hY2hpbmUKPiA+ICvCoMKgwqDC oMKgwqDCoMKgKiBjaGVjayB3aGVyZSBvbmx5IERTSVNSIGJpdCAzMyBpcyBzZXQuIFRoaXMgd2ls bCByZXN1bHQgaW4KPiA+ICvCoMKgwqDCoMKgwqDCoMKgKiB0aGUgTUNFIGhhbmRsZXIgc2VlaW5n IGFuIHVua25vd24gZXZlbnQgYW5kIHVzIGNyYXNoaW5nLgo+ID4gK8KgwqDCoMKgwqDCoMKgwqAq IENoYW5nZSB0aGlzIHRvIG1hcmsgYXMgaGFuZGxlZCBvbiB0aGVzZSByZXZpc2lvbnMuCj4gPiAr wqDCoMKgwqDCoMKgwqDCoCovCj4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iZSBzZXJ2aWNlZCwgdGhlIENQVSB3aWxsIHJhaXNlIHRoZSBNQ0UKYWdh aW4gd2l0aCB0aGUgY29ycmVjdCBEU0lTUiBzbyB0aGF0IGl0IGNhbiBiZSBzZXJ2aWNlZC4KCkkn bGwgYWRkIGEgY29tbWVudCB0byB0aGF0IGVmZmVjdCBhbmQgcmVwb3J0LgoKVGhhbmtzCk1pa2V5
Michael Ellerman
reviewerRe: [PATCH 2/2] powerpc: Handle MCE on POWER9 with only DSISR bit 33 set
In reply to Michael NeulingQuoted 4 lines · Michael Neuling
On POWER9 DD2.1 and below, it's possible to get Machine Check Exception (MCE) where only DSISR bit 33 is set. This will result in the linux MCE handler seeing an unknown event, which triggers linux to crash.
Why do we get a machine check with just one bit set, and why is it OK to just treat it as handled without doing anything?
Is it just entirely spurious?
cheers
Quoted 20 lines · Michael Neuling
POWER9 DD2.1 and earlier has an issue where some cache inhibited vector load will return bad data. The workaround is two part, one
firmware/microcodepart triggers HMI interrupts when hitting such loads, the other part is this patch which then emulates the instructions in Linux.The affected instructions are limited to lxvd2x, lxvw4x, lxvb16x and lxvh8x.
When an instruction triggers the HMI, all threads in the core will be sent to the HMI handler, not just the one running the vector load.
In general, these spurious HMIs are detected by the emulation code and we just return back to the running process. Unfortunately, if a spurious interrupt occurs on a vector load that's to normal memory we have no way to detect that it's spurious (unless we walk the page tables, which is very expensive). In this case we emulate the load but we need do so using a vector load itself to ensure 128bit atomicity is preserved.
Quoted 4 lines
Some additional debugfs emulated instruction counters are added also.
Signed-off-by Michael Neuling <[email protected]>Signed-off-by Benjamin Herrenschmidt <[email protected]>
Patch 1 applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/5080332c2c893118dbc18755f35c8b
cheers