Machine check handling in linux host.
Subsystems (3)
v2 cover Machine check handling in linux host.
Hi,
Please find the patch set that performs the machine check handling inside linux host. The design is to be able to handle re-entrancy so that we do not clobber the machine check information during nested machine check interrupt.
The patch 2 introduces separate emergency stack in paca structure exclusively for machine check exception handling. Patch 3 implements the logic to save the raw MCE info onto the emergency stack and prepares to take another exception. Patch 4 and 5 adds CPU-side hooks for early machine check handler and TLB flush. The patch 6 and 7 is responsible to detect SLB/TLB errors and flush them off in the real mode. The patch 9 implements the logic to decode and save high level MCE information to per cpu buffer without clobbering. The patch 10 adds the basic error handling to the high level C code with MMU on.
I have tested SLB multihit scenario on powernv.
Please review and let me know your comments.
Changes in v2:
- Moved early machine check handling code under CPU_FTR_HVMODE section. This makes sure that the early machine check handler will get executed only in hypervisor kernel.
- Add dedicated emergency stack for machine check so that we don't end up disturbing others who use same emergency stack.
- Fixed the machine check early handle where it used to assume that r1 always contains the valid stack pointer.
- Fixed an issue where per-cpu mce_nest_count variable underflows when kvm fails to handle MC error and exit the guest.
- Fixed the code to restore r13 before exiting early handler.
Thanks,
-Mahesh.
---
Mahesh Salgaonkar (10):
powerpc/book3s: Split the common exception prolog logic into two section. powerpc/book3s: Introduce exclusive emergency stack for machine check exception. powerpc/book3s: handle machine check in Linux host. powerpc/book3s: Introduce a early machine check hook in cpu_spec. powerpc/book3s: Add flush_tlb operation in cpu_spec. powerpc/book3s: Flush SLB/TLBs if we get SLB/TLB machine check errors on power7. powerpc/book3s: Flush SLB/TLBs if we get SLB/TLB machine check errors on power8. powerpc/book3s: Decode and save machine check event. powerpc/powernv: Remove machine check handling in OPAL. powerpc/powernv: Machine check exception handling.
arch/powerpc/include/asm/bitops.h | 5 + arch/powerpc/include/asm/cputable.h | 12 + arch/powerpc/include/asm/exception-64s.h | 67 ++++--- arch/powerpc/include/asm/mce.h | 195 ++++++++++++++++++++ arch/powerpc/include/asm/paca.h | 9 + arch/powerpc/kernel/Makefile | 1 arch/powerpc/kernel/asm-offsets.c | 4 arch/powerpc/kernel/cpu_setup_power.S | 38 +++- arch/powerpc/kernel/cputable.c | 16 ++ arch/powerpc/kernel/exceptions-64s.S | 108 +++++++++++ arch/powerpc/kernel/mce.c | 191 ++++++++++++++++++++ arch/powerpc/kernel/mce_power.c | 287 ++++++++++++++++++++++++++++++ arch/powerpc/kernel/setup_64.c | 8 + arch/powerpc/kernel/traps.c | 15 ++ arch/powerpc/kvm/book3s_hv_ras.c | 50 +++-- arch/powerpc/platforms/powernv/opal.c | 84 ++++++--- arch/powerpc/xmon/xmon.c | 2 17 files changed, 998 insertions(+), 94 deletions(-) create mode 100644 arch/powerpc/include/asm/mce.h create mode 100644 arch/powerpc/kernel/mce.c create mode 100644 arch/powerpc/kernel/mce_power.c
Signature · 1 line
-Mahesh
RFC PATCH v2 1/10 powerpc/book3s: Split the common exception prolog logic into two section.
From: Mahesh Salgaonkar <[email protected]>
This patch splits the common exception prolog logic into two parts to facilitate reuse of existing code in the next patch. The second part will be reused in the machine check exception routine in the next patch.
Please note that this patch does not introduce or change existing code logic. Instead it is just a code movement.
--- arch/powerpc/include/asm/exception-64s.h | 67 ++++++++++++++++-------------- 1 file changed, 35 insertions(+), 32 deletions(-)
arch/powerpc/include/asm/exception-64s.h +35 -32
@@ -248,6 +248,40 @@ do_kvm_##n: \#define NOTEST (n) +#define EXCEPTION_PROLOG_COMMON_2 (n, area) \ + std r2,GPR2(r1);/* save r2 in stackframe */ \ +SAVE_4GPRS (3 , r1);/* save r3 - r6 in stackframe */ \ +SAVE_2GPRS (7 , r1);/* save r7, r8 in stackframe */ \ + ld r9,area+EX_R9(r13); /* move r9, r10 to stackframe */ \ + ld r10,area+EX_R10(r13); \ +std r9,GPR9 (r1 ); \ +std r10,GPR10 (r1 ); \ + ld r9,area+EX_R11(r13); /* move r11 - r13 to stackframe */ \ + ld r10,area+EX_R12(r13); \ + ld r11,area+EX_R13(r13); \ +std r9,GPR11 (r1 ); \ +std r10,GPR12 (r1 ); \ +std r11,GPR13 (r1 ); \ +BEGIN_FTR_SECTION_NESTED (66 ); \ + ld r10,area+EX_CFAR(r13); \ +std r10,ORIG_GPR3 (r1 ); \ +END_FTR_SECTION_NESTED (CPU_FTR_CFAR ,CPU_FTR_CFAR ,66 ); \ +GET_LR (r9,area);/* Get LR, later save to stack */ \ +ld r2,PACATOC (r13 );/* get kernel TOC into r2 */ \ +std r9,_LINK (r1 ); \ +mfctr r10;/* save CTR in stackframe */ \ +std r10,_CTR (r1 ); \ +lbz r10,PACASOFTIRQEN (r13 ); \ +mfspr r11,SPRN_XER ;/* save XER in stackframe */ \ +std r10,SOFTE (r1 ); \ +std r11,_XER (r1 ); \ + li r9,(n)+1; \ +std r9,_TRAP (r1 );/* set trap number */ \ + li r10,0; \ + ld r11,exception_marker@toc(r2); \ +std r10,RESULT (r1 );/* clear regs->result */ \ + std r11,STACK_FRAME_OVERHEAD-16(r1); /* mark the frame */ +/* * The common exception prolog is used for all except a few exceptions * such as a segment miss on a kernel address. We have to be prepared
@@ -281,38 +315,7 @@ do_kvm_##n: \ beq 4f; /* if from kernel mode */ \ACCOUNT_CPU_USER_ENTRY (r9, r10); \SAVE_PPR (area, r9, r10); \ -4: std r2,GPR2(r1); /* save r2 in stackframe */ \ -SAVE_4GPRS (3 , r1);/* save r3 - r6 in stackframe */ \ -SAVE_2GPRS (7 , r1);/* save r7, r8 in stackframe */ \ - ld r9,area+EX_R9(r13); /* move r9, r10 to stackframe */ \ - ld r10,area+EX_R10(r13); \ -std r9,GPR9 (r1 ); \ -std r10,GPR10 (r1 ); \ - ld r9,area+EX_R11(r13); /* move r11 - r13 to stackframe */ \ - ld r10,area+EX_R12(r13); \ - ld r11,area+EX_R13(r13); \ -std r9,GPR11 (r1 ); \ -std r10,GPR12 (r1 ); \ -std r11,GPR13 (r1 ); \ -BEGIN_FTR_SECTION_NESTED (66 ); \ - ld r10,area+EX_CFAR(r13); \ -std r10,ORIG_GPR3 (r1 ); \ -END_FTR_SECTION_NESTED (CPU_FTR_CFAR ,CPU_FTR_CFAR ,66 ); \ -GET_LR (r9,area);/* Get LR, later save to stack */ \ -ld r2,PACATOC (r13 );/* get kernel TOC into r2 */ \ -std r9,_LINK (r1 ); \ -mfctr r10;/* save CTR in stackframe */ \ -std r10,_CTR (r1 ); \ -lbz r10,PACASOFTIRQEN (r13 ); \ -mfspr r11,SPRN_XER ;/* save XER in stackframe */ \ -std r10,SOFTE (r1 ); \ -std r11,_XER (r1 ); \ - li r9,(n)+1; \ -std r9,_TRAP (r1 );/* set trap number */ \ - li r10,0; \ - ld r11,exception_marker@toc(r2); \ -std r10,RESULT (r1 );/* clear regs->result */ \ - std r11,STACK_FRAME_OVERHEAD-16(r1); /* mark the frame */ \ +4: EXCEPTION_PROLOG_COMMON_2(n, area) \ACCOUNT_STOLEN_TIME /*
RFC PATCH v2 2/10 powerpc/book3s: Introduce exclusive emergency stack for machine check exception.
In reply to Mahesh J SalgaonkarFrom: Mahesh Salgaonkar <[email protected]>
This patch introduces exclusive emergency stack for machine check exception. We use emergency stack to handle machine check exception so that we can save MCE information (srr1, srr0, dar and dsisr) before turning on ME bit and be ready for re-entrancy. This helps us to prevent clobbering of MCE information in case of nested machine checks.
The reason for using emergency stack over normal kernel stack is that the machine check might occur in the middle of setting up a stack frame which may result into improper use of kernel stack.
--- arch/powerpc/include/asm/paca.h | 9 +++++++++ arch/powerpc/kernel/setup_64.c | 8 +++++++- arch/powerpc/xmon/xmon.c | 2 ++ 3 files changed, 18 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/paca.h +9 -0
@@ -147,6 +147,15 @@ struct paca_struct {*/ struct opal_machine_check_event *opal_mc_evt;#endif +#ifdef CONFIG_PPC_BOOK3S_64 +/* Exclusive emergency stack pointer for machine check exception. */ +void *mc_emergency_sp; +/* +* Flag to check whether we are in machine check early handler +* and already using emergency stack. +*/ +u16 in_mce; +#endif /* Stuff for accurate time accounting */ u64 user_time;/* accumulated usermode TB ticks */
arch/powerpc/kernel/setup_64.c +7 -1
@@ -529,7 +529,8 @@ static void __init exc_lvl_early_init(void)/* * Stack space used when we detect a bad kernel stack pointer, and -* early in SMP boots before relocation is enabled. +* early in SMP boots before relocation is enabled. Exclusive emergency +* stack for machine checks. */ static void __init emergency_stack_init (void ) {
@@ -552,6 +553,11 @@ static void __init emergency_stack_init(void) sp =memblock_alloc_base (THREAD_SIZE ,THREAD_SIZE , limit); sp +=THREAD_SIZE ; paca[i].emergency_sp =__va (sp); + +/* emergency stack for machine check exception handling. */ + sp =memblock_alloc_base (THREAD_SIZE ,THREAD_SIZE , limit); + sp +=THREAD_SIZE ; + paca[i].mc_emergency_sp =__va (sp); } }
arch/powerpc/xmon/xmon.c +2 -0
@@ -2044,6 +2044,8 @@ static void dump_one_paca(int cpu)DUMP (p, stab_addr,"lx" );#endif DUMP (p, emergency_sp,"p" ); +DUMP (p, mc_emergency_sp,"p" ); +DUMP (p, in_mce,"x" );DUMP (p, data_offset,"lx" );DUMP (p, hw_cpu_id,"x" );DUMP (p, cpu_start,"x" );
Re: [RFC PATCH v2 02/10] powerpc/book3s: Introduce exclusive emergency stack for machine check exception.
Quoted 55 lines · Mahesh J Salgaonkar
From: Mahesh Salgaonkar <[email protected]>
This patch introduces exclusive emergency stack for machine check exception. We use emergency stack to handle machine check exception so that we can save MCE information (srr1, srr0, dar and dsisr) before turning on ME bit and be ready for re-entrancy. This helps us to prevent clobbering of MCE information in case of nested machine checks.
The reason for using emergency stack over normal kernel stack is that the machine check might occur in the middle of setting up a stack frame which may result into improper use of kernel stack.
Signed-off-by Mahesh Salgaonkar <[email protected]>--- arch/powerpc/include/asm/paca.h | 9 +++++++++ arch/powerpc/kernel/setup_64.c | 8 +++++++- arch/powerpc/xmon/xmon.c | 2 ++ 3 files changed, 18 insertions(+), 1 deletion(-)arch/powerpc/include/asm/paca.h +9
-0@@ -147,6 +147,15 @@ struct paca_struct {*/ struct opal_machine_check_event *opal_mc_evt;#endif +#ifdef CONFIG_PPC_BOOK3S_64 +/* Exclusive emergency stack pointer for machine check exception. */ +void *mc_emergency_sp; +/* +* Flag to check whether we are in machine check early handler +* and already using emergency stack. +*/ +u16 in_mce; +#endif /* Stuff for accurate time accounting */ u64 user_time;/* accumulated usermode TB ticks */ arch/powerpc/kernel/setup_64.c +2
-1@@ -529,7 +529,8 @@ static void __init exc_lvl_early_init(void)/* * Stack space used when we detect a bad kernel stack pointer, and -* early in SMP boots before relocation is enabled. +* early in SMP boots before relocation is enabled. Exclusive emergency +* stack for machine checks. */ static void __init emergency_stack_init (void ) {@@ -552,6 +553,11 @@ static void __init emergency_stack_init(void) sp =memblock_alloc_base (THREAD_SIZE ,THREAD_SIZE , limit);
arch/powerpc/kernel/setup_64.c static void __init emergency_stack_init(void) · line 563
Quoted 10 lines
arch/powerpc/kernel/setup_64.c +5
-0sp +=THREAD_SIZE ; paca[i].emergency_sp =__va (sp); + +/* emergency stack for machine check exception handling. */ + sp =memblock_alloc_base (THREAD_SIZE ,THREAD_SIZE , limit); + sp +=THREAD_SIZE ; + paca[i].mc_emergency_sp =__va (sp); } }
Just a concern, kindly ignore it if it is irrelevant. you have defined mc_emergency_sp under CONFIG_PPC_BOOK3S_64, but assigning memory in a common code. This may break build for other configs such as like ppc64e_defconfig.
Quoted 19 lines
arch/powerpc/xmon/xmon.c +2
-0@@ -2044,6 +2044,8 @@ static void dump_one_paca(int cpu)DUMP (p, stab_addr,"lx" );#endif DUMP (p, emergency_sp,"p" ); +DUMP (p, mc_emergency_sp,"p" ); +DUMP (p, in_mce,"x" );DUMP (p, data_offset,"lx" );DUMP (p, hw_cpu_id,"x" );DUMP (p, cpu_start,"x" );_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://lists.ozlabs.org/listinfo/linuxppc-dev
Re: [RFC PATCH v2 02/10] powerpc/book3s: Introduce exclusive emergency stack for machine check exception.
Quoted 62 lines · Madhavan Srinivasan
Quoted 61 lines · Mahesh J Salgaonkar
From: Mahesh Salgaonkar <[email protected]>
This patch introduces exclusive emergency stack for machine check exception. We use emergency stack to handle machine check exception so that we can save MCE information (srr1, srr0, dar and dsisr) before turning on ME bit and be ready for re-entrancy. This helps us to prevent clobbering of MCE information in case of nested machine checks.
The reason for using emergency stack over normal kernel stack is that the machine check might occur in the middle of setting up a stack frame which may result into improper use of kernel stack.
Signed-off-by Mahesh Salgaonkar <[email protected]>--- arch/powerpc/include/asm/paca.h | 9 +++++++++ arch/powerpc/kernel/setup_64.c | 8 +++++++- arch/powerpc/xmon/xmon.c | 2 ++ 3 files changed, 18 insertions(+), 1 deletion(-)arch/powerpc/include/asm/paca.h +9
-0@@ -147,6 +147,15 @@ struct paca_struct {*/ struct opal_machine_check_event *opal_mc_evt;#endif +#ifdef CONFIG_PPC_BOOK3S_64 +/* Exclusive emergency stack pointer for machine check exception. */ +void *mc_emergency_sp; +/* +* Flag to check whether we are in machine check early handler +* and already using emergency stack. +*/ +u16 in_mce; +#endif /* Stuff for accurate time accounting */ u64 user_time;/* accumulated usermode TB ticks */ arch/powerpc/kernel/setup_64.c +6
-1@@ -529,7 +529,8 @@ static void __init exc_lvl_early_init(void)/* * Stack space used when we detect a bad kernel stack pointer, and -* early in SMP boots before relocation is enabled. +* early in SMP boots before relocation is enabled. Exclusive emergency +* stack for machine checks. */ static void __init emergency_stack_init (void ) {@@ -552,6 +553,11 @@ static void __init emergency_stack_init(void) sp =memblock_alloc_base (THREAD_SIZE ,THREAD_SIZE , limit); sp +=THREAD_SIZE ; paca[i].emergency_sp =__va (sp); + +/* emergency stack for machine check exception handling. */ + sp =memblock_alloc_base (THREAD_SIZE ,THREAD_SIZE , limit); + sp +=THREAD_SIZE ;
Quoted 8 lines
arch/powerpc/kernel/setup_64.c static void __init emergency_stack_init(void) · line 563
Quoted 4 lines
arch/powerpc/kernel/setup_64.c +1
-0+ paca[i].mc_emergency_sp =__va (sp); } }Just a concern, kindly ignore it if it is irrelevant. you have defined
mc_emergency_spunderCONFIG_PPC_BOOK3S_64, but assigning memory in a common code. This may break build for other configs such as likeppc64e_defconfig.
Nice catch. Will fix it in next spin.
Thanks,
-Mahesh.
RFC PATCH v2 3/10 powerpc/book3s: handle machine check in Linux host.
In reply to Mahesh J SalgaonkarFrom: Mahesh Salgaonkar <[email protected]>
Move machine check entry point into Linux. So far we were dependent on firmware to decode MCE error details and handover the high level info to OS.
This patch introduces early machine check routine that saves the MCE information (srr1, srr0, dar and dsisr) to the emergency stack. We allocate stack frame on emergency stack and set the r1 accordingly. This allows us to be prepared to take another exception without loosing context. One thing to note here that, if we get another machine check while ME bit is off then we risk a checkstop. Hence we restrict ourselves to save only MCE information and turn the ME bit on. We use paca->in_mce flag to differentiate between first entry and nested machine check entry which helps proper use of emergency stack. We increment paca->in_mce every time we enter in early machine check handler and decrement it while leaving. When we enter machine check early handler first time (paca->in_mce == 0), we are sure nobody is using MC emergency stack and allocate a stack frame at the start of the emergency stack. During subsequent entry (paca->in_mce > 0), we know that r1 points inside emergency stack and we allocate separate stack frame accordingly. This prevents us from clobbering MCE information during nested machine checks.
The early machine check handler changes are placed under CPU_FTR_HVMODE section. This makes sure that the early machine check handler will get executed only in hypervisor kernel.
This is the code flow:
Machine Check Interrupt | V 0x200 vector ME=0, IR=0, DR=0 | V +-----------------------------------------------+ |machine_check_pSeries_early: | ME=0, IR=0, DR=0 | Alloc frame on emergency stack | | Save srr1, srr0, dar and dsisr on stack | +-----------------------------------------------+ | (ME=1, IR=0, DR=0, RFID) | V machine_check_handle_early ME=1, IR=0, DR=0 | V +-----------------------------------------------+ | machine_check_early (r3=pt_regs) | ME=1, IR=0, DR=0 | Things to do: (in next patches) | | Flush SLB for SLB errors | | Flush TLB for TLB errors | | Decode and save MCE info | +-----------------------------------------------+ | (Fall through existing exception handler routine.) | V machine_check_pSerie ME=1, IR=0, DR=0 | (ME=1, IR=1, DR=1, RFID) | V machine_check_common ME=1, IR=1, DR=1 . . .
--- arch/powerpc/kernel/asm-offsets.c | 4 + arch/powerpc/kernel/exceptions-64s.S | 108 ++++++++++++++++++++++++++++++++++ arch/powerpc/kernel/traps.c | 12 ++++ 3 files changed, 124 insertions(+)
arch/powerpc/kernel/asm-offsets.c +4 -0
@@ -235,6 +235,10 @@ int main(void)DEFINE (PACA_DTL_RIDX , offsetof(struct paca_struct , dtl_ridx));#endif /* CONFIG_PPC_STD_MMU_64 */ DEFINE (PACAEMERGSP , offsetof(struct paca_struct , emergency_sp)); +#ifdef CONFIG_PPC_BOOK3S_64 +DEFINE (PACAMCEMERGSP , offsetof(struct paca_struct , mc_emergency_sp)); +DEFINE (PACA_IN_MCE , offsetof(struct paca_struct , in_mce)); +#endif DEFINE (PACAHWCPUID , offsetof(struct paca_struct , hw_cpu_id));DEFINE (PACAKEXECSTATE , offsetof(struct paca_struct , kexec_state));DEFINE (PACA_STARTTIME , offsetof(struct paca_struct , starttime));
arch/powerpc/kernel/exceptions-64s.S +108 -0
127 lines not on this page · raw message
arch/powerpc/kernel/traps.c +12 -0
@@ -286,6 +286,18 @@ void system_reset_exception(struct pt_regs *regs) /* What should we do here? We could issue a shutdown or hard reset. */ } + +/* +* This function is called in real mode. Strictly no printk's please. +* +* regs->nip and regs->msr contains srr0 and ssr1. +*/ +long machine_check_early (struct pt_regs *regs) +{ +/* TODO: handle/decode machine check reason */ +return 0 ; +} +#endif /*
RFC PATCH v2 4/10 powerpc/book3s: Introduce a early machine check hook in cpu_spec.
In reply to Mahesh J SalgaonkarFrom: Mahesh Salgaonkar <[email protected]>
This patch adds the early machine check function pointer in cputable for CPU specific early machine check handling. The early machine handle routine will be called in real mode to handle SLB and TLB errors. This patch just sets up a mechanism invoke CPU specific handler. The subsequent patches will populate the function pointer.
--- arch/powerpc/include/asm/cputable.h | 7 +++++++ arch/powerpc/kernel/traps.c | 7 +++++-- 2 files changed, 12 insertions(+), 2 deletions(-)
arch/powerpc/include/asm/cputable.h +7 -0
@@ -90,6 +90,13 @@ struct cpu_spec {* if the error is fatal, 1 if it was fully recovered and 0 to * pass up (not CPU originated) */ int (*machine_check)(struct pt_regs *regs); + +/* +* Processor specific early machine check handler which is +* called in real mode to handle SLB and TLB errors. +*/ +long (*machine_check_early)(struct pt_regs *regs); + };extern struct cpu_spec *cur_cpu_spec;
arch/powerpc/kernel/traps.c +5 -2
@@ -294,8 +294,11 @@ void system_reset_exception(struct pt_regs *regs)*/ long machine_check_early (struct pt_regs *regs) { -/* TODO: handle/decode machine check reason */ -return 0 ; +long handled =0 ; + +if (cur_cpu_spec && cur_cpu_spec->machine_check_early) + handled = cur_cpu_spec->machine_check_early (regs); +return handled; }#endif
RFC PATCH v2 5/10 powerpc/book3s: Add flush_tlb operation in cpu_spec.
In reply to Mahesh J SalgaonkarFrom: Mahesh Salgaonkar <[email protected]>
This patch introduces flush_tlb operation in cpu_spec structure. This will help us to invoke appropriate CPU-side flush tlb routine. This patch adds the foundation to invoke CPU specific flush routine for respective architectures. Currently this patch introduce flush_tlb for p7 and p8.
--- arch/powerpc/include/asm/cputable.h | 5 ++++ arch/powerpc/kernel/cpu_setup_power.S | 38 +++++++++++++++++++++++---------- arch/powerpc/kernel/cputable.c | 8 +++++++ arch/powerpc/kvm/book3s_hv_ras.c | 18 +++------------- 4 files changed, 44 insertions(+), 25 deletions(-)
arch/powerpc/include/asm/cputable.h +5 -0
@@ -97,6 +97,11 @@ struct cpu_spec {*/ long (*machine_check_early)(struct pt_regs *regs); +/* +* Processor specific routine to flush tlbs. +*/ +void (*flush_tlb)(unsigned long inval_selector); + };extern struct cpu_spec *cur_cpu_spec;
arch/powerpc/kernel/cpu_setup_power.S +27 -11
@@ -29,7 +29,7 @@ _GLOBAL(__setup_cpu_power7) mtspr SPRN_LPID,r0 mfspr r3,SPRN_LPCR bl __init_LPCR - bl __init_TLB + bl __init_tlb_power7 mtlr r11 blr
@@ -42,7 +42,7 @@ _GLOBAL(__restore_cpu_power7) mtspr SPRN_LPID,r0 mfspr r3,SPRN_LPCR bl __init_LPCR - bl __init_TLB + bl __init_tlb_power7 mtlr r11 blr
@@ -59,7 +59,7 @@ _GLOBAL(__setup_cpu_power8) oris r3, r3, LPCR_AIL_3@h bl __init_LPCR bl __init_HFSCR - bl __init_TLB + bl __init_tlb_power8 bl __init_PMU_HV mtlr r11 blr
@@ -78,7 +78,7 @@ _GLOBAL(__restore_cpu_power8) oris r3, r3, LPCR_AIL_3@h bl __init_LPCR bl __init_HFSCR - bl __init_TLB + bl __init_tlb_power8 bl __init_PMU_HV mtlr r11 blr
@@ -134,15 +134,31 @@ __init_HFSCR: mtspr SPRN_HFSCR,r3 blr -__init_TLB: - /* - * Clear the TLB using the "IS 3" form of tlbiel instruction - * (invalidate by congruence class). P7 has 128 CCs, P8 has 512 - * so we just always do 512 - */ +/* + * Clear the TLB using the specified IS form of tlbiel instruction + * (invalidate by congruence class). P7 has 128 CCs., P8 has 512. + * + * r3 = IS field + */ +__init_tlb_power7: + li r3,0xc00 /* IS field = 0b11 */ +_GLOBAL(__flush_tlb_power7) + li r6,128 + mtctr r6 + mr r7,r3 /* IS field */ + ptesync +2: tlbiel r7 + addi r7,r7,0x1000 + bdnz 2b + ptesync +1: blr + +__init_tlb_power8: + li r3,0xc00 /* IS field = 0b11 */ +_GLOBAL(__flush_tlb_power8) li r6,512 mtctr r6 - li r7,0xc00 /* IS field = 0b11 */ + mr r7,r3 /* IS field */ ptesync 2: tlbiel r7 addi r7,r7,0x1000
arch/powerpc/kernel/cputable.c +8 -0
@@ -71,6 +71,8 @@ extern void __restore_cpu_power7(void);extern void __setup_cpu_power8 (unsigned long offset,struct cpu_spec * spec);extern void __restore_cpu_power8 (void );extern void __restore_cpu_a2 (void ); +extern void __flush_tlb_power7 (unsigned long inval_selector); +extern void __flush_tlb_power8 (unsigned long inval_selector);#endif /* CONFIG_PPC64 */ #if defined(CONFIG_E500 )extern void __setup_cpu_e5500 (unsigned long offset,struct cpu_spec * spec);
@@ -440,6 +442,7 @@ static struct cpu_spec __initdata cpu_specs[] = { .oprofile_cpu_type = "ppc64/ibm-compat-v1", .cpu_setup = __setup_cpu_power7, .cpu_restore = __restore_cpu_power7, + .flush_tlb = __flush_tlb_power7, .platform = "power7", }, {/* 2.07-compliant processor, i.e. Power8 "architected" mode */
@@ -456,6 +459,7 @@ static struct cpu_spec __initdata cpu_specs[] = { .oprofile_cpu_type = "ppc64/ibm-compat-v1", .cpu_setup = __setup_cpu_power8, .cpu_restore = __restore_cpu_power8, + .flush_tlb = __flush_tlb_power8, .platform = "power8", }, {/* Power7 */
@@ -474,6 +478,7 @@ static struct cpu_spec __initdata cpu_specs[] = { .oprofile_type = PPC_OPROFILE_POWER4, .cpu_setup = __setup_cpu_power7, .cpu_restore = __restore_cpu_power7, + .flush_tlb = __flush_tlb_power7, .platform = "power7", }, {/* Power7+ */
@@ -492,6 +497,7 @@ static struct cpu_spec __initdata cpu_specs[] = { .oprofile_type = PPC_OPROFILE_POWER4, .cpu_setup = __setup_cpu_power7, .cpu_restore = __restore_cpu_power7, + .flush_tlb = __flush_tlb_power7, .platform = "power7+", }, {/* Power8E */
@@ -510,6 +516,7 @@ static struct cpu_spec __initdata cpu_specs[] = { .oprofile_type = PPC_OPROFILE_INVALID, .cpu_setup = __setup_cpu_power8, .cpu_restore = __restore_cpu_power8, + .flush_tlb = __flush_tlb_power8, .platform = "power8", }, {/* Power8 */
@@ -528,6 +535,7 @@ static struct cpu_spec __initdata cpu_specs[] = { .oprofile_type = PPC_OPROFILE_INVALID, .cpu_setup = __setup_cpu_power8, .cpu_restore = __restore_cpu_power8, + .flush_tlb = __flush_tlb_power8, .platform = "power8", }, {/* Cell Broadband Engine */
arch/powerpc/kvm/book3s_hv_ras.c +4 -14
@@ -58,18 +58,6 @@ static void reload_slb(struct kvm_vcpu *vcpu) } } -/* POWER7 TLB flush */ -static void flush_tlb_power7 (struct kvm_vcpu *vcpu) -{ -unsigned long i, rb; - - rb =TLBIEL_INVAL_SET_LPID ; -for (i =0 ; i <POWER7_TLB_SETS ; ++i) { - asmvolatile ("tlbiel %0" : :"r" (rb)); - rb +=1 <<TLBIEL_INVAL_SET_SHIFT ; - } -} -/* * On POWER7, see if we can handle a machine check that occurred inside * the guest in real mode, without switching to the host partition.
@@ -96,7 +84,8 @@ static long kvmppc_realmode_mc_power7(struct kvm_vcpu *vcpu) DSISR_MC_SLB_PARITY | DSISR_MC_DERAT_MULTI); }if (dsisr &DSISR_MC_TLB_MULTI ) { -flush_tlb_power7 (vcpu); +if (cur_cpu_spec && cur_cpu_spec->flush_tlb) + cur_cpu_spec->flush_tlb (TLBIEL_INVAL_SET_LPID ); dsisr &= ~DSISR_MC_TLB_MULTI ; }/* Any other errors we don't understand? */
@@ -113,7 +102,8 @@ static long kvmppc_realmode_mc_power7(struct kvm_vcpu *vcpu)reload_slb (vcpu);break ;case SRR1_MC_IFETCH_TLBMULTI : -flush_tlb_power7 (vcpu); +if (cur_cpu_spec && cur_cpu_spec->flush_tlb) + cur_cpu_spec->flush_tlb (TLBIEL_INVAL_SET_LPID );break ;default : handled =0 ;
RFC PATCH v2 6/10 powerpc/book3s: Flush SLB/TLBs if we get SLB/TLB machine check errors on power7.
In reply to Mahesh J SalgaonkarFrom: Mahesh Salgaonkar <[email protected]>
If we get a machine check exception due to SLB or TLB errors, then flush SLBs/TLBs and reload SLBs to recover. We do this in real mode before turning on MMU. Otherwise we would run into nested machine checks.
If we get a machine check when we are in guest, then just flush the SLBs and continue. This patch handles errors for power7. The next patch will handle errors for power8
--- arch/powerpc/include/asm/bitops.h | 5 + arch/powerpc/include/asm/mce.h | 67 ++++++++++++++++ arch/powerpc/kernel/Makefile | 1 arch/powerpc/kernel/cputable.c | 4 + arch/powerpc/kernel/mce_power.c | 153 +++++++++++++++++++++++++++++++++++++ 5 files changed, 230 insertions(+) create mode 100644 arch/powerpc/include/asm/mce.h create mode 100644 arch/powerpc/kernel/mce_power.c
arch/powerpc/include/asm/bitops.h +5 -0
@@ -46,6 +46,11 @@#include <asm/asm-compat.h> #include <asm/synch.h> +/* PPC bit number conversion */ +#define PPC_BIT (bit) (0x8000000000000000UL >> (bit)) +#define PPC_BITLSHIFT (be) (63 - (be)) +#define PPC_BITMASK (bs, be) ((PPC_BIT(bs) - PPC_BIT(be)) | PPC_BIT(bs)) +/* * clear_bit doesn't imply a memory barrier */
arch/powerpc/include/asm/mce.h new file +67 -0
67 lines not on this page · raw message
arch/powerpc/kernel/Makefile +1 -0
@@ -39,6 +39,7 @@ obj-$(CONFIG_PPC64) += setup_64.o sys_ppc32.o \ obj-$(CONFIG_HAVE_HW_BREAKPOINT) += hw_breakpoint.o obj-$(CONFIG_PPC_BOOK3S_64) += cpu_setup_ppc970.o cpu_setup_pa6t.o obj-$(CONFIG_PPC_BOOK3S_64) += cpu_setup_power.o +obj-$(CONFIG_PPC_BOOK3S_64) += mce_power.o obj64-$(CONFIG_RELOCATABLE) += reloc_64.o obj-$(CONFIG_PPC_BOOK3E_64) += exceptions-64e.o idle_book3e.o obj-$(CONFIG_PPC_A2) += cpu_setup_a2.o
arch/powerpc/kernel/cputable.c +4 -0
@@ -73,6 +73,7 @@ extern void __restore_cpu_power8(void);extern void __restore_cpu_a2 (void );extern void __flush_tlb_power7 (unsigned long inval_selector);extern void __flush_tlb_power8 (unsigned long inval_selector); +extern long __machine_check_early_realmode_p7 (struct pt_regs *regs);#endif /* CONFIG_PPC64 */ #if defined(CONFIG_E500 )extern void __setup_cpu_e5500 (unsigned long offset,struct cpu_spec * spec);
@@ -443,6 +444,7 @@ static struct cpu_spec __initdata cpu_specs[] = { .cpu_setup = __setup_cpu_power7, .cpu_restore = __restore_cpu_power7, .flush_tlb = __flush_tlb_power7, + .machine_check_early = __machine_check_early_realmode_p7, .platform = "power7", }, {/* 2.07-compliant processor, i.e. Power8 "architected" mode */
@@ -479,6 +481,7 @@ static struct cpu_spec __initdata cpu_specs[] = { .cpu_setup = __setup_cpu_power7, .cpu_restore = __restore_cpu_power7, .flush_tlb = __flush_tlb_power7, + .machine_check_early = __machine_check_early_realmode_p7, .platform = "power7", }, {/* Power7+ */
@@ -498,6 +501,7 @@ static struct cpu_spec __initdata cpu_specs[] = { .cpu_setup = __setup_cpu_power7, .cpu_restore = __restore_cpu_power7, .flush_tlb = __flush_tlb_power7, + .machine_check_early = __machine_check_early_realmode_p7, .platform = "power7+", }, {/* Power8E */
arch/powerpc/kernel/mce_power.c new file +153 -0
153 lines not on this page · raw message
RFC PATCH v2 7/10 powerpc/book3s: Flush SLB/TLBs if we get SLB/TLB machine check errors on power8.
In reply to Mahesh J SalgaonkarFrom: Mahesh Salgaonkar <[email protected]>
This patch handles the memory errors on power8. If we get a machine check exception due to SLB or TLB errors, then flush SLBs/TLBs and reload SLBs to recover.
I do not have access to power8 box, hence this patch haven't been tested yet.
--- arch/powerpc/include/asm/mce.h | 3 +++ arch/powerpc/kernel/cputable.c | 4 ++++ arch/powerpc/kernel/mce_power.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+)
arch/powerpc/include/asm/mce.h +3 -0
@@ -64,4 +64,7 @@ P7_DSISR_MC_SLB_MULTIHIT | \ P7_DSISR_MC_SLB_MULTIHIT_PARITY) +#define P8_DSISR_MC_SLB_ERRORS (P7_DSISR_MC_SLB_ERRORS | \ + P8_DSISR_MC_ERAT_MULTIHIT_SEC) +#endif /* __ASM_PPC64_MCE_H__ */
arch/powerpc/kernel/cputable.c +4 -0
@@ -74,6 +74,7 @@ extern void __restore_cpu_a2(void);extern void __flush_tlb_power7 (unsigned long inval_selector);extern void __flush_tlb_power8 (unsigned long inval_selector);extern long __machine_check_early_realmode_p7 (struct pt_regs *regs); +extern long __machine_check_early_realmode_p8 (struct pt_regs *regs);#endif /* CONFIG_PPC64 */ #if defined(CONFIG_E500 )extern void __setup_cpu_e5500 (unsigned long offset,struct cpu_spec * spec);
@@ -462,6 +463,7 @@ static struct cpu_spec __initdata cpu_specs[] = { .cpu_setup = __setup_cpu_power8, .cpu_restore = __restore_cpu_power8, .flush_tlb = __flush_tlb_power8, + .machine_check_early = __machine_check_early_realmode_p8, .platform = "power8", }, {/* Power7 */
@@ -521,6 +523,7 @@ static struct cpu_spec __initdata cpu_specs[] = { .cpu_setup = __setup_cpu_power8, .cpu_restore = __restore_cpu_power8, .flush_tlb = __flush_tlb_power8, + .machine_check_early = __machine_check_early_realmode_p8, .platform = "power8", }, {/* Power8 */
@@ -540,6 +543,7 @@ static struct cpu_spec __initdata cpu_specs[] = { .cpu_setup = __setup_cpu_power8, .cpu_restore = __restore_cpu_power8, .flush_tlb = __flush_tlb_power8, + .machine_check_early = __machine_check_early_realmode_p8, .platform = "power8", }, {/* Cell Broadband Engine */
arch/powerpc/kernel/mce_power.c +34 -0
@@ -151,3 +151,37 @@ long __machine_check_early_realmode_p7(struct pt_regs *regs)/* TODO: Decode machine check reason. */ return handled; } + +static long mce_handle_ierror_p8 (uint64_t srr1) +{ +long handled =0 ; + + handled =mce_handle_common_ierror (srr1); + +if (P7_SRR1_MC_IFETCH (srr1) ==P8_SRR1_MC_IFETCH_ERAT_MULTIHIT ) { +flush_and_reload_slb (); + handled =1 ; + } +return handled; +} + +static long mce_handle_derror_p8 (uint64_t dsisr) +{ +return mce_handle_derror (dsisr,P8_DSISR_MC_SLB_ERRORS ); +} + +long __machine_check_early_realmode_p8 (struct pt_regs *regs) +{ +uint64_t srr1; +long handled =1 ; + + srr1 = regs->msr; + +if (P7_SRR1_MC_LOADSTORE (srr1)) + handled =mce_handle_derror_p8 (regs->dsisr); +else + handled =mce_handle_ierror_p8 (srr1); + +/* TODO: Decode machine check reason. */ +return handled; +}
RFC PATCH v2 8/10 powerpc/book3s: Decode and save machine check event.
In reply to Mahesh J SalgaonkarFrom: Mahesh Salgaonkar <[email protected]>
Now that we handle machine check in linux, the MCE decoding should also take place in linux host. This info is crucial to log before we go down in case we can not handle the machine check errors. This patch decodes and populates a machine check event which contain high level meaning full MCE information.
We do this in real mode C code with ME bit on. The MCE information is still available on emergency stack (in pt_regs structure format). Even if we take another exception at this point the MCE early handler will allocate a new stack frame on top of current one. So when we return back here we still have our MCE information safe on current stack.
We use per cpu buffer to save high level MCE information. Each per cpu buffer is an array of machine check event structure indexed by per cpu counter mce_nest_count. The mce_nest_count is incremented every time we enter machine check early handler in real mode to get the current free slot (index = mce_nest_count - 1). The mce_nest_count is decremented once the MCE info is consumed by virtual mode machine exception handler.
This patch provides save_mce_event(), get_mce_event() and release_mce_event() generic routines that can be used by machine check handlers to populate and retrieve the event. The routine release_mce_event() will free the event slot so that it can be reused. Caller can invoke get_mce_event() with a release flag either to release the event slot immediately OR keep it so that it can be fetched again. The event slot can be also released anytime by invoking release_mce_event().
This patch also updates kvm code to invoke get_mce_event to retrieve generic mce event rather than paca->opal_mce_evt.
The KVM code always calls get_mce_event() with release flags set to false so that event is available for linus host machine
If machine check occurs while we are in guest, KVM tries to handle the error. If KVM is able to handle MC error successfully, it enters the guest and delivers the machine check to guest. If KVM is not able to handle MC error, it exists the guest and passes the control to linux host machine check handler which then logs MC event and decides how to handle it in linux host. In failure case, KVM needs to make sure that the MC event is available for linux host to consume. Hence KVM always calls get_mce_event() with release flags set to false and later it invokes release_mce_event() only if it succeeds to handle error.
--- arch/powerpc/include/asm/mce.h | 124 +++++++++++++++++++++++++ arch/powerpc/kernel/Makefile | 2 arch/powerpc/kernel/mce.c | 164 +++++++++++++++++++++++++++++++++ arch/powerpc/kernel/mce_power.c | 116 ++++++++++++++++++++++- arch/powerpc/kvm/book3s_hv_ras.c | 32 ++++-- arch/powerpc/platforms/powernv/opal.c | 35 +++---- 6 files changed, 434 insertions(+), 39 deletions(-) create mode 100644 arch/powerpc/kernel/mce.c
arch/powerpc/include/asm/mce.h +124 -0
@@ -66,5 +66,129 @@#define P8_DSISR_MC_SLB_ERRORS (P7_DSISR_MC_SLB_ERRORS | \ P8_DSISR_MC_ERAT_MULTIHIT_SEC) +enum MCE_Version { +MCE_V1 =1 , +}; + +enum MCE_Severity { +MCE_SEV_NO_ERROR =0 , +MCE_SEV_WARNING =1 , +MCE_SEV_ERROR_SYNC =2 , +MCE_SEV_FATAL =3 , +}; + +enum MCE_Disposition { +MCE_DISPOSITION_RECOVERED =0 , +MCE_DISPOSITION_NOT_RECOVERED =1 , +}; + +enum MCE_Initiator { +MCE_INITIATOR_UNKNOWN =0 , +MCE_INITIATOR_CPU =1 , +}; + +enum MCE_ErrorType { +MCE_ERROR_TYPE_UNKNOWN =0 , +MCE_ERROR_TYPE_UE =1 , +MCE_ERROR_TYPE_SLB =2 , +MCE_ERROR_TYPE_ERAT =3 , +MCE_ERROR_TYPE_TLB =4 , +}; + +enum MCE_UeErrorType { +MCE_UE_ERROR_INDETERMINATE =0 , +MCE_UE_ERROR_IFETCH =1 , +MCE_UE_ERROR_PAGE_TABLE_WALK_IFETCH =2 , +MCE_UE_ERROR_LOAD_STORE =3 , +MCE_UE_ERROR_PAGE_TABLE_WALK_LOAD_STORE =4 , +}; + +enum MCE_SlbErrorType { +MCE_SLB_ERROR_INDETERMINATE =0 , +MCE_SLB_ERROR_PARITY =1 , +MCE_SLB_ERROR_MULTIHIT =2 , +}; + +enum MCE_EratErrorType { +MCE_ERAT_ERROR_INDETERMINATE =0 , +MCE_ERAT_ERROR_PARITY =1 , +MCE_ERAT_ERROR_MULTIHIT =2 , +}; + +enum MCE_TlbErrorType { +MCE_TLB_ERROR_INDETERMINATE =0 , +MCE_TLB_ERROR_PARITY =1 , +MCE_TLB_ERROR_MULTIHIT =2 , +}; + +struct machine_check_event { +enum MCE_Version version:8 ;/* 0x00 */ +uint8_t in_use;/* 0x01 */ +enum MCE_Severity severity:8 ;/* 0x02 */ +enum MCE_Initiator initiator:8 ;/* 0x03 */ +enum MCE_ErrorType error_type:8 ;/* 0x04 */ +enum MCE_Disposition disposition:8 ;/* 0x05 */ +uint8_t reserved_1[2 ];/* 0x06 */ +uint64_t gpr3;/* 0x08 */ +uint64_t srr0;/* 0x10 */ +uint64_t srr1;/* 0x18 */ +union {/* 0x20 */ +struct { +enum MCE_UeErrorType ue_error_type:8 ; +uint8_t effective_address_provided; +uint8_t physical_address_provided; +uint8_t reserved_1[5 ]; +uint64_t effective_address; +uint64_t physical_address; +uint8_t reserved_2[8 ]; + } ue_error; + +struct { +enum MCE_SlbErrorType slb_error_type:8 ; +uint8_t effective_address_provided; +uint8_t reserved_1[6 ]; +uint64_t effective_address; +uint8_t reserved_2[16 ]; + } slb_error; + +struct { +enum MCE_EratErrorType erat_error_type:8 ; +uint8_t effective_address_provided; +uint8_t reserved_1[6 ]; +uint64_t effective_address; +uint8_t reserved_2[16 ]; + } erat_error; + +struct { +enum MCE_TlbErrorType tlb_error_type:8 ; +uint8_t effective_address_provided; +uint8_t reserved_1[6 ]; +uint64_t effective_address; +uint8_t reserved_2[16 ]; + } tlb_error; + } u; +}; + +struct mce_error_info { +enum MCE_ErrorType error_type:8 ; +union { +enum MCE_UeErrorType ue_error_type:8 ; +enum MCE_SlbErrorType slb_error_type:8 ; +enum MCE_EratErrorType erat_error_type:8 ; +enum MCE_TlbErrorType tlb_error_type:8 ; + } u; +uint8_t reserved[2 ]; +}; + +#define MAX_MC_EVT 100 + +/* Release flags for get_mce_event() */ +#define MCE_EVENT_RELEASE true +#define MCE_EVENT_DONTRELEASE false + +extern void save_mce_event (struct pt_regs *regs,long handled, +struct mce_error_info *mce_err,uint64_t addr); +extern int get_mce_event (struct machine_check_event *mce,bool release); +extern void release_mce_event (void );#endif /* __ASM_PPC64_MCE_H__ */
arch/powerpc/kernel/Makefile +1 -1
@@ -39,7 +39,7 @@ obj-$(CONFIG_PPC64) += setup_64.o sys_ppc32.o \ obj-$(CONFIG_HAVE_HW_BREAKPOINT) += hw_breakpoint.o obj-$(CONFIG_PPC_BOOK3S_64) += cpu_setup_ppc970.o cpu_setup_pa6t.o obj-$(CONFIG_PPC_BOOK3S_64) += cpu_setup_power.o -obj-$(CONFIG_PPC_BOOK3S_64) += mce_power.o +obj-$(CONFIG_PPC_BOOK3S_64) += mce.o mce_power.o obj64-$(CONFIG_RELOCATABLE) += reloc_64.o obj-$(CONFIG_PPC_BOOK3E_64) += exceptions-64e.o idle_book3e.o obj-$(CONFIG_PPC_A2) += cpu_setup_a2.o
arch/powerpc/kernel/mce.c new file +164 -0
164 lines not on this page · raw message
arch/powerpc/kernel/mce_power.c +108 -8
146 lines not on this page · raw message
arch/powerpc/kvm/book3s_hv_ras.c +20 -12
@@ -12,6 +12,7 @@#include <linux/kvm_host.h> #include <linux/kernel.h> #include <asm/opal.h> +#include <asm/mce.h> /* SRR1 bits for machine check on POWER7 */ #define SRR1_MC_LDSTERR (1ul << (63-42))
@@ -67,9 +68,7 @@ static void reload_slb(struct kvm_vcpu *vcpu)static long kvmppc_realmode_mc_power7 (struct kvm_vcpu *vcpu) {unsigned long srr1 = vcpu->arch.shregs.msr; -#ifdef CONFIG_PPC_POWERNV -struct opal_machine_check_event *opal_evt; -#endif +struct machine_check_event mce_evt;long handled =1 ;if (srr1 &SRR1_MC_LDSTERR ) {
@@ -109,22 +108,31 @@ static long kvmppc_realmode_mc_power7(struct kvm_vcpu *vcpu) handled =0 ; } -#ifdef CONFIG_PPC_POWERNV /* -* See if OPAL has already handled the condition. -* We assume that if the condition is recovered then OPAL +* See if we have already handled the condition in the linux host. +* We assume that if the condition is recovered then linux host * will have generated an error log event that we will pick * up and log later. +* Don't release mce event now. In case if condition is not +* recovered we do guest exit and go back to linux host machine +* check handler. Hence we need make sure that current mce event +* is available for linux host to consume. */ - opal_evt = local_paca->opal_mc_evt; -if (opal_evt->version == OpalMCE_V1 && - (opal_evt->severity == OpalMCE_SEV_NO_ERROR || - opal_evt->disposition == OpalMCE_DISPOSITION_RECOVERED)) +if (!get_mce_event (&mce_evt,MCE_EVENT_DONTRELEASE )) + goto out; + +if (mce_evt.version ==MCE_V1 && + (mce_evt.severity ==MCE_SEV_NO_ERROR || + mce_evt.disposition ==MCE_DISPOSITION_RECOVERED )) handled =1 ; +out: +/* +* If we have handled the error, then release the mce event because +* we will be delivering machine check to guest. +*/ if (handled) - opal_evt->in_use =0 ; -#endif +release_mce_event ();return handled; }
arch/powerpc/platforms/powernv/opal.c +17 -18
@@ -19,6 +19,7 @@#include <linux/slab.h> #include <asm/opal.h> #include <asm/firmware.h> +#include <asm/mce.h> #include "powernv.h"
@@ -245,8 +246,7 @@ int opal_put_chars(uint32_t vtermno, const char *data, int total_len)int opal_machine_check (struct pt_regs *regs) { -struct opal_machine_check_event *opal_evt =get_paca ()->opal_mc_evt; -struct opal_machine_check_event evt; +struct machine_check_event evt;const char *level, *sevstr, *subtype;static const char *opal_mc_ue_types[] = {"Indeterminate" ,
@@ -271,30 +271,29 @@ int opal_machine_check(struct pt_regs *regs) "Multihit", }; -/* Copy the event structure and release the original */ - evt = *opal_evt; - opal_evt->in_use =0 ; +if (!get_mce_event (&evt,MCE_EVENT_RELEASE )) +return 0 ;/* Print things out */ -if (evt.version != OpalMCE_V1) { +if (evt.version !=MCE_V1 ) {pr_err ("Machine Check Exception, Unknown event version %d !\n" , evt.version);return 0 ; }switch (evt.severity) { -case OpalMCE_SEV_NO_ERROR: +case MCE_SEV_NO_ERROR : level =KERN_INFO ; sevstr ="Harmless" ;break ; -case OpalMCE_SEV_WARNING: +case MCE_SEV_WARNING : level =KERN_WARNING ; sevstr ="" ;break ; -case OpalMCE_SEV_ERROR_SYNC: +case MCE_SEV_ERROR_SYNC : level =KERN_ERR ; sevstr ="Severe" ;break ; -case OpalMCE_SEV_FATAL: +case MCE_SEV_FATAL :default : level =KERN_ERR ; sevstr ="Fatal" ;
@@ -302,12 +301,12 @@ int opal_machine_check(struct pt_regs *regs) }printk ("%s%s Machine check interrupt [%s]\n" , level, sevstr, - evt.disposition == OpalMCE_DISPOSITION_RECOVERED ? + evt.disposition ==MCE_DISPOSITION_RECOVERED ?"Recovered" :"[Not recovered" );printk ("%s Initiator: %s\n" , level, - evt.initiator == OpalMCE_INITIATOR_CPU ?"CPU" :"Unknown" ); + evt.initiator ==MCE_INITIATOR_CPU ?"CPU" :"Unknown" );switch (evt.error_type) { -case OpalMCE_ERROR_TYPE_UE: +case MCE_ERROR_TYPE_UE : subtype = evt.u.ue_error.ue_error_type < ARRAY_SIZE(opal_mc_ue_types) ? opal_mc_ue_types[evt.u.ue_error.ue_error_type]
@@ -320,7 +319,7 @@ int opal_machine_check(struct pt_regs *regs)printk ("%s Physial address: %016llx\n" , level, evt.u.ue_error.physical_address);break ; -case OpalMCE_ERROR_TYPE_SLB: +case MCE_ERROR_TYPE_SLB : subtype = evt.u.slb_error.slb_error_type < ARRAY_SIZE(opal_mc_slb_types) ? opal_mc_slb_types[evt.u.slb_error.slb_error_type]
@@ -330,7 +329,7 @@ int opal_machine_check(struct pt_regs *regs)printk ("%s Effective address: %016llx\n" , level, evt.u.slb_error.effective_address);break ; -case OpalMCE_ERROR_TYPE_ERAT: +case MCE_ERROR_TYPE_ERAT : subtype = evt.u.erat_error.erat_error_type < ARRAY_SIZE(opal_mc_erat_types) ? opal_mc_erat_types[evt.u.erat_error.erat_error_type]
@@ -340,7 +339,7 @@ int opal_machine_check(struct pt_regs *regs)printk ("%s Effective address: %016llx\n" , level, evt.u.erat_error.effective_address);break ; -case OpalMCE_ERROR_TYPE_TLB: +case MCE_ERROR_TYPE_TLB : subtype = evt.u.tlb_error.tlb_error_type < ARRAY_SIZE(opal_mc_tlb_types) ? opal_mc_tlb_types[evt.u.tlb_error.tlb_error_type]
@@ -351,11 +350,11 @@ int opal_machine_check(struct pt_regs *regs) level, evt.u.tlb_error.effective_address);break ;default : -case OpalMCE_ERROR_TYPE_UNKNOWN: +case MCE_ERROR_TYPE_UNKNOWN :printk ("%s Error type: Unknown\n" , level);break ; } -return evt.severity == OpalMCE_SEV_FATAL ?0 :1 ; +return evt.severity ==MCE_SEV_FATAL ?0 :1 ; }static irqreturn_t opal_interrupt (int irq,void *data)
RFC PATCH v2 9/10 powerpc/powernv: Remove machine check handling in OPAL.
In reply to Mahesh J SalgaonkarFrom: Mahesh Salgaonkar <[email protected]>
Now that we are ready to handle machine check directly in linux, do not register with firmware to handle machine check exception.
--- arch/powerpc/platforms/powernv/opal.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
arch/powerpc/platforms/powernv/opal.c +2 -6
@@ -83,14 +83,10 @@ static int __init opal_register_exception_handlers(void)if (!(powerpc_firmware_features &FW_FEATURE_OPAL ))return -ENODEV ; -/* Hookup some exception handlers. We use the fwnmi area at 0x7000 -* to provide the glue space to OPAL +/* Hookup some exception handlers except machine check. We use the +* fwnmi area at 0x7000 to provide the glue space to OPAL */ glue =0x7000 ; -opal_register_exception_handler (OPAL_MACHINE_CHECK_HANDLER , -__pa (opal_mc_secondary_handler[0 ]), - glue); - glue +=128 ;opal_register_exception_handler (OPAL_HYPERVISOR_MAINTENANCE_HANDLER ,0 , glue); glue +=128 ;
RFC PATCH v2 10/10 powerpc/powernv: Machine check exception handling.
In reply to Mahesh J SalgaonkarFrom: Mahesh Salgaonkar <[email protected]>
Add basic error handling in machine check exception handler.
- If MSR_RI isn't set, we can not recover.
- Check if disposition set to OpalMCE_DISPOSITION_RECOVERED.
- Check if address at fault is inside kernel address space, if not then send SIGBUS to process if we hit exception when in userspace.
- If address at fault is not provided then and if we get a synchronous machine check while in userspace then kill the task.
--- arch/powerpc/include/asm/mce.h | 1 + arch/powerpc/kernel/mce.c | 27 +++++++++++++++++++++ arch/powerpc/platforms/powernv/opal.c | 43 ++++++++++++++++++++++++++++++++- 3 files changed, 70 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/mce.h +1 -0
@@ -190,5 +190,6 @@ extern void save_mce_event(struct pt_regs *regs, long handled, struct mce_error_info *mce_err, uint64_t addr);extern int get_mce_event (struct machine_check_event *mce,bool release);extern void release_mce_event (void ); +extern uint64_t get_mce_fault_addr (struct machine_check_event *evt);#endif /* __ASM_PPC64_MCE_H__ */
arch/powerpc/kernel/mce.c +27 -0
@@ -162,3 +162,30 @@ void release_mce_event(void) {get_mce_event (NULL , true); } + +uint64_t get_mce_fault_addr (struct machine_check_event *evt) +{ +switch (evt->error_type) { +case MCE_ERROR_TYPE_UE : +if (evt->u.ue_error.effective_address_provided) +return evt->u.ue_error.effective_address; +break ; +case MCE_ERROR_TYPE_SLB : +if (evt->u.slb_error.effective_address_provided) +return evt->u.slb_error.effective_address; +break ; +case MCE_ERROR_TYPE_ERAT : +if (evt->u.erat_error.effective_address_provided) +return evt->u.erat_error.effective_address; +break ; +case MCE_ERROR_TYPE_TLB : +if (evt->u.tlb_error.effective_address_provided) +return evt->u.tlb_error.effective_address; +break ; +default : +case MCE_ERROR_TYPE_UNKNOWN : +break ; + } +return 0 ; +} +EXPORT_SYMBOL (get_mce_fault_addr);
arch/powerpc/platforms/powernv/opal.c +42 -1
61 lines not on this page · raw message