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

Signed-off-by: Huang Ying <ying.huang@intel.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
This commit is contained in:
Huang Ying 2009-07-31 09:41:43 +08:00 committed by H. Peter Anvin
parent 5be9ed251f
commit bf783f9f7d
1 changed files with 64 additions and 11 deletions

View File

@ -204,6 +204,9 @@ static void print_mce_tail(void)
static atomic_t mce_paniced; 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 */ /* Panic in progress. Enable interrupts and wait for final IPI */
static void wait_for_panic(void) static void wait_for_panic(void)
{ {
@ -221,6 +224,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
{ {
int i; int i;
if (!fake_panic) {
/* /*
* Make sure only one CPU runs in machine check panic * Make sure only one CPU runs in machine check panic
*/ */
@ -230,6 +234,11 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
bust_spinlocks(1); bust_spinlocks(1);
console_verbose(); console_verbose();
} else {
/* Don't log too much for fake panic */
if (atomic_inc_return(&mce_fake_paniced) > 1)
return;
}
print_mce_head(); print_mce_head();
/* First print corrected ones that are still unlogged */ /* First print corrected ones that are still unlogged */
for (i = 0; i < MCE_LOG_LEN; i++) { 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(); print_mce_tail();
if (exp) if (exp)
printk(KERN_EMERG "Machine check: %s\n", exp); printk(KERN_EMERG "Machine check: %s\n", exp);
if (!fake_panic) {
if (panic_timeout == 0) if (panic_timeout == 0)
panic_timeout = mce_panic_timeout; panic_timeout = mce_panic_timeout;
panic(msg); panic(msg);
} else
printk(KERN_EMERG "Fake kernel panic: %s\n", msg);
} }
/* Support code for software error injection */ /* Support code for software error injection */
@ -2015,4 +2027,45 @@ struct dentry *mce_get_debugfs_dir(void)
return dmce; 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 #endif