powerpc/mce: Fix mce handler and add selftest
v3 cover powerpc/mce: Fix mce handler and add selftest
This patch series fixes mce handling for pseries, Adds LKDTM test for SLB multihit recovery and enables selftest for the same, basically to test MCE handling on pseries/powernv machines running in hash mmu mode.
v3:
* Merging selftest changes with patch 2/2, Instead of having separate patch.
* Minor improvements like adding enough comments, Makefile changes, including header file and adding some prints.
v2:
* Remove in_nmi check before calling nmi_enter/exit, as nesting is supported.
* Fix build errors and remove unused variables.
* Integrate error injection code into LKDTM.
* Add support to inject multihit in paca.
Ganesh Goudar (2):
powerpc/mce: remove nmi_enter/exit from real mode handler lkdtm/powerpc: Add SLB multihit test
arch/powerpc/kernel/mce.c | 10 +- drivers/misc/lkdtm/Makefile | 1 + drivers/misc/lkdtm/core.c | 3 + drivers/misc/lkdtm/lkdtm.h | 3 + drivers/misc/lkdtm/powerpc.c | 156 ++++++++++++++++++++++++ tools/testing/selftests/lkdtm/tests.txt | 1 + 6 files changed, 170 insertions(+), 4 deletions(-) create mode 100644 drivers/misc/lkdtm/powerpc.c
Signature · 1 line
2.26.2
PATCH v3 1/2 powerpc/mce: remove nmi_enter/exit from real mode handler
Use of nmi_enter/exit in real mode handler causes the kernel to panic and reboot on injecting slb mutihit on pseries machine running in hash mmu mode, As these calls try to accesses memory outside RMO region in real mode handler where translation is disabled.
Add check to not to use these calls on pseries machine running in hash mmu mode.
--- arch/powerpc/kernel/mce.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
arch/powerpc/kernel/mce.c +6 -4
@@ -591,12 +591,14 @@ EXPORT_SYMBOL_GPL(machine_check_print_event_info);long notrace machine_check_early (struct pt_regs *regs) {long handled =0 ; -bool nested =in_nmi (); +bool is_pseries_hpt_guest;u8 ftrace_enabled =this_cpu_get_ftrace_enabled ();this_cpu_set_ftrace_enabled (0 ); - -if (!nested) + is_pseries_hpt_guest =machine_is (pseries) && +mmu_has_feature (MMU_FTR_HPTE_TABLE ); +/* Do not use nmi_enter/exit for pseries hpte guest */ +if (!is_pseries_hpt_guest)nmi_enter ();hv_nmi_check_nonrecoverable (regs);
@@ -607,7 +609,7 @@ long notrace machine_check_early(struct pt_regs *regs)if (ppc_md.machine_check_early) handled = ppc_md.machine_check_early (regs); -if (!nested) +if (!is_pseries_hpt_guest)nmi_exit ();this_cpu_set_ftrace_enabled (ftrace_enabled);
Signature · 1 line
2.26.2
Re: [PATCH v3 1/2] powerpc/mce: remove nmi_enter/exit from real mode handler
Quoted 23 lines · Ganesh Goudar
Use of nmi_enter/exit in real mode handler causes the kernel to panic and reboot on injecting slb mutihit on pseries machine running in hash mmu mode, As these calls try to accesses memory outside RMO region in real mode handler where translation is disabled.
Add check to not to use these calls on pseries machine running in hash mmu mode.
Fixes 116ac378bb3f ("powerpc/64s: machine check interrupt update NMI accounting")Signed-off-by Ganesh Goudar <[email protected]>--- arch/powerpc/kernel/mce.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)arch/powerpc/kernel/mce.c +0
-1@@ -591,12 +591,14 @@ EXPORT_SYMBOL_GPL(machine_check_print_event_info);long notrace machine_check_early (struct pt_regs *regs) {long handled =0 ; -bool nested =in_nmi ();
arch/powerpc/kernel/mce.c EXPORT_SYMBOL_GPL(machine_check_print_event_info); · line 601
Quoted 10 lines
arch/powerpc/kernel/mce.c +5
-2+bool is_pseries_hpt_guest;u8 ftrace_enabled =this_cpu_get_ftrace_enabled ();this_cpu_set_ftrace_enabled (0 ); - -if (!nested) + is_pseries_hpt_guest =machine_is (pseries) && +mmu_has_feature (MMU_FTR_HPTE_TABLE ); +/* Do not use nmi_enter/exit for pseries hpte guest */ +if (!is_pseries_hpt_guest)
In an offline discussion mpe suggested to use radix_enabled() to check if it is radix or hash, as MMU_FTR_HPTE_TABLE may be true on radix machines also and use of FW_FEATURE_LPAR better than machine_is(pseries), sending v4 with these changes.
Quoted 12 lines
arch/powerpc/kernel/mce.c +1
-1nmi_enter ();hv_nmi_check_nonrecoverable (regs);@@ -607,7 +609,7 @@ long notrace machine_check_early(struct pt_regs *regs)if (ppc_md.machine_check_early) handled = ppc_md.machine_check_early (regs); -if (!nested) +if (!is_pseries_hpt_guest)nmi_exit ();this_cpu_set_ftrace_enabled (ftrace_enabled);
PATCH v3 2/2 lkdtm/powerpc: Add SLB multihit test
In reply to Ganesh GoudarTo check machine check handling, add support to inject slb multihit errors.
--- drivers/misc/lkdtm/Makefile | 1 + drivers/misc/lkdtm/core.c | 3 + drivers/misc/lkdtm/lkdtm.h | 3 + drivers/misc/lkdtm/powerpc.c | 156 ++++++++++++++++++++++++ tools/testing/selftests/lkdtm/tests.txt | 1 + 5 files changed, 164 insertions(+) create mode 100644 drivers/misc/lkdtm/powerpc.c
drivers/misc/lkdtm/Makefile +1 -0
@@ -10,6 +10,7 @@ lkdtm-$(CONFIG_LKDTM) += rodata_objcopy.o lkdtm-$(CONFIG_LKDTM) += usercopy.o lkdtm-$(CONFIG_LKDTM) += stackleak.o lkdtm-$(CONFIG_LKDTM) += cfi.o +lkdtm-$(CONFIG_PPC64) += powerpc.o KASAN_SANITIZE_stackleak.o := n KCOV_INSTRUMENT_rodata.o := n
drivers/misc/lkdtm/core.c +3 -0
@@ -178,6 +178,9 @@ static const struct crashtype crashtypes[] = {#ifdef CONFIG_X86_32 CRASHTYPE(DOUBLE_FAULT),#endif +#ifdef CONFIG_PPC64 + CRASHTYPE(PPC_SLB_MULTIHIT), +#endif };
drivers/misc/lkdtm/lkdtm.h +3 -0
@@ -104,4 +104,7 @@ void lkdtm_STACKLEAK_ERASING(void);/* cfi.c */ void lkdtm_CFI_FORWARD_PROTO (void ); +/* powerpc.c */ +void lkdtm_PPC_SLB_MULTIHIT (void ); +#endif
drivers/misc/lkdtm/powerpc.c new file +156 -0
156 lines not on this page · raw message
tools/testing/selftests/lkdtm/tests.txt +1 -0
@@ -70,3 +70,4 @@ USERCOPY_KERNEL USERCOPY_KERNEL_DS STACKLEAK_ERASING OK: the rest of the thread stack is properly erased CFI_FORWARD_PROTO +PPC_SLB_MULTIHIT Recovered
Signature · 1 line
2.26.2