x86: MCE: testing enhancement
cover x86: MCE: testing enhancement
Hi, All,
This patchset is necessary for MCE regression testing suite mce-test
(http://www.kernel.org/pub/scm/utils/cpu/mce/mce-test.git) to work properly.
This version is rebased on x86-tip.git/mce
Best Regards,
Huang Ying
PATCH 1/4 x86: MCE: Support specifying context for software mce injection
The cpu context is specified via the new mce.inject_flags fields. This allows more realistic machine check testing in different situations. "RANDOM" context is implemented via NMI broadcasting to add randomization to testing.
AK: Fix NMI broadcasting check. Fix 32-bit building. Some race fixes. Move to module. Various changes
ChangeLog:
v3:
- Re-based on latest x86-tip.git/mce4
- Fix 32-bit building
v2:
- Re-base on latest x86-tip.git/mce3
--- arch/x86/include/asm/mce.h | 11 ++- arch/x86/kernel/cpu/mcheck/mce-inject.c | 156 +++++++++++++++++++++++++------ 2 files changed, 135 insertions(+), 32 deletions(-)
arch/x86/include/asm/mce.h +9 -2
@@ -38,6 +38,13 @@#define MCM_ADDR_MEM 3/* memory address */ #define MCM_ADDR_GENERIC 7/* generic */ +#define MCJ_CTX_MASK 3 +#define MCJ_CTX (flags) ((flags) & MCJ_CTX_MASK) +#define MCJ_CTX_RANDOM 0/* inject context: random */ +#define MCJ_CTX_PROCESS 1/* inject context: process */ +#define MCJ_CTX_IRQ 2/* inject context: IRQ */ +#define MCJ_NMI_BROADCAST 4/* do NMI broadcasting */ +/* Fields are zero when not available */ struct mce {__u64 status;
@@ -48,8 +55,8 @@ struct mce {__u64 tsc;/* cpu time stamp counter */ __u64 time;/* wall time_t when error was detected */ __u8 cpuvendor;/* cpu vendor as encoded in system.h */ -__u8 pad1; -__u16 pad2; +__u8 inject_flags;/* software inject flags */ +__u16 pad;__u32 cpuid;/* CPUID 1 EAX */ __u8 cs;/* code segment */ __u8 bank;/* machine check bank */
arch/x86/kernel/cpu/mcheck/mce-inject.c +126 -30
202 lines not on this page · raw message
Signature · 1 line
1.6.3.3
PATCH 2/4 x86: MCE: Support specifying raise mode for software MCE injection
Raise mode include raising as exception or raising as poll, it is specified via the mce.inject_flags field.
This can be used to specify raise mode of UCNA, which is UC error but raised not as exception. And this can be used to test the filter code of poll handler or exception handler too. For example, enforce a poll raise mode for a fatal MCE.
ChangeLog:
v2:
- Re-base on latest x86-tip.git/mce3
--- arch/x86/include/asm/mce.h | 1 + arch/x86/kernel/cpu/mcheck/mce-inject.c | 16 ++++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-)
arch/x86/include/asm/mce.h +1 -0
@@ -44,6 +44,7 @@#define MCJ_CTX_PROCESS 1/* inject context: process */ #define MCJ_CTX_IRQ 2/* inject context: IRQ */ #define MCJ_NMI_BROADCAST 4/* do NMI broadcasting */ +#define MCJ_EXCEPTION 8/* raise as exception */ /* Fields are zero when not available */ struct mce {
arch/x86/kernel/cpu/mcheck/mce-inject.c +8 -8
@@ -44,7 +44,7 @@ static void inject_mce(struct mce *m) i->finished =1 ; } -static void raise_corrected (struct mce *m) +static void raise_poll (struct mce *m) {unsigned long flags;mce_banks_t b;
@@ -56,7 +56,7 @@ static void raise_corrected(struct mce *m) m->finished =0 ; } -static void raise_uncorrected (struct mce *m,struct pt_regs *pregs) +static void raise_exception (struct mce *m,struct pt_regs *pregs) {struct pt_regs regs;unsigned long flags;
@@ -85,10 +85,10 @@ static int mce_raise_notify(struct notifier_block *self,if (val !=DIE_NMI_IPI || !cpu_isset (cpu, mce_inject_cpumask))return NOTIFY_DONE ;cpu_clear (cpu, mce_inject_cpumask); -if (m->status &MCI_STATUS_UC ) -raise_uncorrected (m, args->regs); +if (m->inject_flags &MCJ_EXCEPTION ) +raise_exception (m, args->regs);else if (m->status) -raise_corrected (m); +raise_poll (m);return NOTIFY_STOP ; }
@@ -104,7 +104,7 @@ static int raise_local(struct mce *m)int ret =0 ;int cpu = m->extcpu; -if (m->status &MCI_STATUS_UC ) { +if (m->inject_flags &MCJ_EXCEPTION ) {printk (KERN_INFO "Triggering MCE exception on CPU %d\n" , cpu);switch (context) {case MCJ_CTX_IRQ :
@@ -115,7 +115,7 @@ static int raise_local(struct mce *m)*/ /*FALL THROUGH*/ case MCJ_CTX_PROCESS : -raise_uncorrected (m,NULL ); +raise_exception (m,NULL );break ;default :printk (KERN_INFO "Invalid MCE context\n" );
@@ -124,7 +124,7 @@ static int raise_local(struct mce *m)printk (KERN_INFO "MCE exception done on CPU %d\n" , cpu); }else if (m->status) {printk (KERN_INFO "Starting machine check poll CPU %d\n" , cpu); -raise_corrected (m); +raise_poll (m);mce_notify_irq ();printk (KERN_INFO "Machine check poll done on CPU %d\n" , cpu); }else
Signature · 1 line
1.6.3.3
PATCH 3/4 x86: MCE: Move debugfs mce dir creating to mce.c
Because more debugfs files under mce dir will be create in mce.c.
ChangeLog:
v5:
- Rebased on x86-tip.git/mce
--- arch/x86/kernel/cpu/mcheck/mce-internal.h | 1 + arch/x86/kernel/cpu/mcheck/mce-severity.c | 4 +--- arch/x86/kernel/cpu/mcheck/mce.c | 13 +++++++++++++ 3 files changed, 15 insertions(+), 3 deletions(-)
arch/x86/kernel/cpu/mcheck/mce-internal.h +1 -0
@@ -22,6 +22,7 @@ struct mce_bank { };int mce_severity (struct mce *a,int tolerant,char **msg); +struct dentry *mce_get_debugfs_dir (void );extern int mce_ser;
arch/x86/kernel/cpu/mcheck/mce-severity.c +1 -3
@@ -197,7 +197,7 @@ static int __init severities_debugfs_init(void) {struct dentry *dmce =NULL , *fseverities_coverage =NULL ; - dmce =debugfs_create_dir ("mce" ,NULL ); + dmce =mce_get_debugfs_dir ();if (dmce ==NULL ) goto err_out; fseverities_coverage = debugfs_create_file("severities-coverage",
@@ -209,8 +209,6 @@ static int __init severities_debugfs_init(void)return 0 ; err_out: -if (dmce) -debugfs_remove (dmce);return -ENOMEM ; }late_initcall (severities_debugfs_init);
arch/x86/kernel/cpu/mcheck/mce.c +13 -0
@@ -34,6 +34,7 @@#include <linux/smp.h> #include <linux/fs.h> #include <linux/mm.h> +#include <linux/debugfs.h> #include <asm/processor.h> #include <asm/hw_irq.h>
@@ -2003,3 +2004,15 @@ static int __init mcheck_disable(char *str)return 1 ; }__setup ("nomce" , mcheck_disable); + +#ifdef CONFIG_DEBUG_FS +struct dentry *mce_get_debugfs_dir (void ) +{ +static struct dentry *dmce; + +if (!dmce) + dmce =debugfs_create_dir ("mce" ,NULL ); + +return dmce; +} +#endif
Signature · 1 line
1.6.3.3
PATCH 4/4 x86: MCE: Fake panic support for MCE testing
If "fake panic" mode is turned on, just log panic message instead of go real panic. This is used for testing only, so that the test suite can check for the correct panic message and do regression testing for MCE would go panic.
This patch is based on x86-tip.git/mce.
ChangeLog:
v5:
- Rebased on x86-tip.git/mce
v4:
- Move config file from sysfs to debugfs
--- arch/x86/kernel/cpu/mcheck/mce.c | 75 ++++++++++++++++++++++++++++++++------ 1 files changed, 64 insertions(+), 11 deletions(-)
arch/x86/kernel/cpu/mcheck/mce.c +64 -11
@@ -204,6 +204,9 @@ static void print_mce_tail(void)static atomic_t mce_paniced; +static int fake_panic; +static atomic_t mce_fake_paniced; +/* Panic in progress. Enable interrupts and wait for final IPI */ static void wait_for_panic (void ) {
@@ -221,15 +224,21 @@ static void mce_panic(char *msg, struct mce *final, char *exp) {int i; -/* -* Make sure only one CPU runs in machine check panic -*/ -if (atomic_inc_return (&mce_paniced) >1 ) -wait_for_panic (); -barrier (); +if (!fake_panic) { +/* +* Make sure only one CPU runs in machine check panic +*/ +if (atomic_inc_return (&mce_paniced) >1 ) +wait_for_panic (); +barrier (); -bust_spinlocks (1 ); -console_verbose (); +bust_spinlocks (1 ); +console_verbose (); + }else { +/* Don't log too much for fake panic */ +if (atomic_inc_return (&mce_fake_paniced) >1 ) +return ; + }print_mce_head ();/* First print corrected ones that are still unlogged */ for (i =0 ; i <MCE_LOG_LEN ; i++) {
@@ -256,9 +265,12 @@ static void mce_panic(char *msg, struct mce *final, char *exp)print_mce_tail ();if (exp)printk (KERN_EMERG "Machine check: %s\n" , exp); -if (panic_timeout ==0 ) - panic_timeout = mce_panic_timeout; -panic (msg); +if (!fake_panic) { +if (panic_timeout ==0 ) + panic_timeout = mce_panic_timeout; +panic (msg); + }else +printk (KERN_EMERG "Fake kernel panic: %s\n" , msg); }/* Support code for software error injection */
@@ -2015,4 +2027,45 @@ struct dentry *mce_get_debugfs_dir(void)return dmce; } + +static void mce_reset (void ) +{ + cpu_missing =0 ; +atomic_set (&mce_fake_paniced,0 ); +atomic_set (&mce_executing,0 ); +atomic_set (&mce_callin,0 ); +atomic_set (&global_nwo,0 ); +} + +static int fake_panic_get (void *data,u64 *val) +{ + *val = fake_panic; +return 0 ; +} + +static int fake_panic_set (void *data,u64 val) +{ +mce_reset (); + fake_panic = val; +return 0 ; +} + +DEFINE_SIMPLE_ATTRIBUTE (fake_panic_fops, fake_panic_get, + fake_panic_set,"%llu\n" ); + +static int __init mce_debugfs_init (void ) +{ +struct dentry *dmce, *ffake_panic; + + dmce =mce_get_debugfs_dir (); +if (!dmce) +return -ENOMEM ; + ffake_panic =debugfs_create_file ("fake_panic" ,0444 , dmce,NULL , + &fake_panic_fops); +if (!ffake_panic) +return -ENOMEM ; + +return 0 ; +} +late_initcall (mce_debugfs_init);#endif
Signature · 1 line
1.6.3.3