From: Huang Ying <ying.huang@intel.com>
To: Ingo Molnar <mingo@elte.hu>, "H. Peter Anvin" <hpa@zytor.com>,
Andi Kleen <ak@linux.intel.com>,
Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: [BUGFIX 2/2] x86, mce, inject: Make injected mce valid only during faked handler call
Date: Tue, 22 Sep 2009 14:35:58 +0800 [thread overview]
Message-ID: <1253601358.15717.758.camel@yhuang-dev.sh.intel.com> (raw)
In current implementation, injected mce is valid from MCE is injected
to MCE is processed by faked handler call. It is possible for it to be
consumed by real machine_check_poll. This may confuse real system
error and mce test suite.
To fix this, this patch introduces another flag MCJ_VALID to indacate
the MCE entry is valid for injector but not for handler, while
mce.finished is used to indicate the MCE entry is valid for
handler. mce.finished is enabled only during faked MCE handler call
and protected by IRQ disabling. This make it impossible for real
machine_check_poll to consume it.
Signed-off-by: Huang Ying <ying.huang@intel.com>
---
arch/x86/include/asm/mce.h | 17 +++++++++++------
arch/x86/kernel/cpu/mcheck/mce-inject.c | 23 ++++++++++++++++-------
2 files changed, 27 insertions(+), 13 deletions(-)
--- a/arch/x86/include/asm/mce.h
+++ b/arch/x86/include/asm/mce.h
@@ -38,13 +38,18 @@
#define MCM_ADDR_MEM 3 /* memory address */
#define MCM_ADDR_GENERIC 7 /* generic */
-#define MCJ_CTX_MASK 3
+#define _MCJ_NMI_BROADCAST 2 /* do NMI broadcasting */
+#define _MCJ_EXCEPTION 3 /* raise as exception */
+#define _MCJ_VALID 4 /* entry is valid for injector */
+
+#define MCJ_CTX_MASK 0x03
#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 */
-#define MCJ_EXCEPTION 8 /* raise as exception */
+#define MCJ_CTX_RANDOM 0x00 /* inject context: random */
+#define MCJ_CTX_PROCESS 0x01 /* inject context: process */
+#define MCJ_CTX_IRQ 0x02 /* inject context: IRQ */
+#define MCJ_NMI_BROADCAST (1 << _MCJ_NMI_BROADCAST)
+#define MCJ_EXCEPTION (1 << _MCJ_EXCEPTION)
+#define MCJ_VALID (1 << _MCJ_VALID)
/* Fields are zero when not available */
struct mce {
--- a/arch/x86/kernel/cpu/mcheck/mce-inject.c
+++ b/arch/x86/kernel/cpu/mcheck/mce-inject.c
@@ -32,16 +32,16 @@ static void inject_mce(struct mce *m)
/* Make sure noone reads partially written injectm */
i->finished = 0;
+ clear_bit(_MCJ_VALID, (unsigned long *)&i->inject_flags);
mb();
m->finished = 0;
- /* First set the fields after finished */
+ clear_bit(_MCJ_VALID, (unsigned long *)&m->inject_flags);
i->extcpu = m->extcpu;
mb();
- /* Now write record in order, finished last (except above) */
memcpy(i, m, sizeof(struct mce));
/* Finally activate it */
mb();
- i->finished = 1;
+ set_bit(_MCJ_VALID, (unsigned long *)&i->inject_flags);
}
static void raise_poll(struct mce *m)
@@ -51,9 +51,11 @@ static void raise_poll(struct mce *m)
memset(&b, 0xff, sizeof(mce_banks_t));
local_irq_save(flags);
+ m->finished = 1;
machine_check_poll(0, &b);
- local_irq_restore(flags);
m->finished = 0;
+ clear_bit(_MCJ_VALID, (unsigned long *)&m->inject_flags);
+ local_irq_restore(flags);
}
static void raise_exception(struct mce *m, struct pt_regs *pregs)
@@ -69,9 +71,11 @@ static void raise_exception(struct mce *
}
/* in mcheck exeception handler, irq will be disabled */
local_irq_save(flags);
+ m->finished = 1;
do_machine_check(pregs, 0);
- local_irq_restore(flags);
m->finished = 0;
+ clear_bit(_MCJ_VALID, (unsigned long *)&m->inject_flags);
+ local_irq_restore(flags);
}
static cpumask_t mce_inject_cpumask;
@@ -89,6 +93,8 @@ static int mce_raise_notify(struct notif
raise_exception(m, args->regs);
else if (m->status)
raise_poll(m);
+ else
+ clear_bit(_MCJ_VALID, (unsigned long *)&m->inject_flags);
return NOTIFY_STOP;
}
@@ -129,7 +135,7 @@ static int raise_local(void)
mce_notify_irq();
printk(KERN_INFO "Machine check poll done on CPU %d\n", cpu);
} else
- m->finished = 0;
+ clear_bit(_MCJ_VALID, (unsigned long *)&m->inject_flags);
return ret;
}
@@ -152,10 +158,13 @@ static void raise_mce(struct mce *m)
cpu_clear(get_cpu(), mce_inject_cpumask);
for_each_online_cpu(cpu) {
struct mce *mcpu = &per_cpu(injectm, cpu);
- if (!mcpu->finished ||
+ if (!test_bit(_MCJ_VALID,
+ (unsigned long *)&mcpu->inject_flags) ||
MCJ_CTX(mcpu->inject_flags) != MCJ_CTX_RANDOM)
cpu_clear(cpu, mce_inject_cpumask);
}
+ /* make sure needed data is available on other CPUs */
+ smp_mb();
if (!cpus_empty(mce_inject_cpumask))
apic->send_IPI_mask(&mce_inject_cpumask, NMI_VECTOR);
start = jiffies;
next reply other threads:[~2009-09-22 6:36 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-22 6:35 Huang Ying [this message]
2009-09-22 15:23 ` Ingo Molnar
2009-09-23 9:13 ` Huang Ying
2009-09-23 18:53 ` Ingo Molnar
2009-09-24 2:15 ` Huang Ying
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1253601358.15717.758.camel@yhuang-dev.sh.intel.com \
--to=ying.huang@intel.com \
--cc=ak@linux.intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=seto.hidetoshi@jp.fujitsu.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®