Skip to content

Commit 2c29d9d

Browse files
Chen Gongaegl
authored andcommitted
x86: add IRQ context simulation in module mce-inject
mce-inject provides a mechanism to simulate errors so that test scripts can check for correct operation of the kernel without requiring any specialized hardware to create rare events. The existing code can simulate events in normal process context and also in NMI context - but not in IRQ context. This patch fills that gap. Link: https://lkml.org/lkml/2011/12/7/537 Signed-off-by: Chen Gong <gong.chen@linux.intel.com> Signed-off-by: Tony Luck <tony.luck@intel.com>
1 parent dc47ce9 commit 2c29d9d

2 files changed

Lines changed: 35 additions & 8 deletions

File tree

‎arch/x86/include/asm/mce.h‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,11 @@
5050
#define MCJ_CTX_MASK 3
5151
#define MCJ_CTX(flags) ((flags) & MCJ_CTX_MASK)
5252
#define MCJ_CTX_RANDOM 0 /* inject context: random */
53-
#define MCJ_CTX_PROCESS 1 /* inject context: process */
54-
#define MCJ_CTX_IRQ 2 /* inject context: IRQ */
55-
#define MCJ_NMI_BROADCAST 4 /* do NMI broadcasting */
56-
#define MCJ_EXCEPTION 8 /* raise as exception */
53+
#define MCJ_CTX_PROCESS 0x1 /* inject context: process */
54+
#define MCJ_CTX_IRQ 0x2 /* inject context: IRQ */
55+
#define MCJ_NMI_BROADCAST 0x4 /* do NMI broadcasting */
56+
#define MCJ_EXCEPTION 0x8 /* raise as exception */
57+
#define MCJ_IRQ_BRAODCAST 0x10 /* do IRQ broadcasting */
5758

5859
/* Fields are zero when not available */
5960
struct mce {

‎arch/x86/kernel/cpu/mcheck/mce-inject.c‎

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <linux/kernel.h>
1818
#include <linux/string.h>
1919
#include <linux/fs.h>
20+
#include <linux/preempt.h>
2021
#include <linux/smp.h>
2122
#include <linux/notifier.h>
2223
#include <linux/kdebug.h>
@@ -92,6 +93,18 @@ static int mce_raise_notify(unsigned int cmd, struct pt_regs *regs)
9293
return NMI_HANDLED;
9394
}
9495

96+
static void mce_irq_ipi(void *info)
97+
{
98+
int cpu = smp_processor_id();
99+
struct mce *m = &__get_cpu_var(injectm);
100+
101+
if (cpumask_test_cpu(cpu, mce_inject_cpumask) &&
102+
m->inject_flags & MCJ_EXCEPTION) {
103+
cpumask_clear_cpu(cpu, mce_inject_cpumask);
104+
raise_exception(m, NULL);
105+
}
106+
}
107+
95108
/* Inject mce on current CPU */
96109
static int raise_local(void)
97110
{
@@ -139,9 +152,10 @@ static void raise_mce(struct mce *m)
139152
return;
140153

141154
#ifdef CONFIG_X86_LOCAL_APIC
142-
if (m->inject_flags & MCJ_NMI_BROADCAST) {
155+
if (m->inject_flags & (MCJ_IRQ_BRAODCAST | MCJ_NMI_BROADCAST)) {
143156
unsigned long start;
144157
int cpu;
158+
145159
get_online_cpus();
146160
cpumask_copy(mce_inject_cpumask, cpu_online_mask);
147161
cpumask_clear_cpu(get_cpu(), mce_inject_cpumask);
@@ -151,13 +165,25 @@ static void raise_mce(struct mce *m)
151165
MCJ_CTX(mcpu->inject_flags) != MCJ_CTX_RANDOM)
152166
cpumask_clear_cpu(cpu, mce_inject_cpumask);
153167
}
154-
if (!cpumask_empty(mce_inject_cpumask))
155-
apic->send_IPI_mask(mce_inject_cpumask, NMI_VECTOR);
168+
if (!cpumask_empty(mce_inject_cpumask)) {
169+
if (m->inject_flags & MCJ_IRQ_BRAODCAST) {
170+
/*
171+
* don't wait because mce_irq_ipi is necessary
172+
* to be sync with following raise_local
173+
*/
174+
preempt_disable();
175+
smp_call_function_many(mce_inject_cpumask,
176+
mce_irq_ipi, NULL, 0);
177+
preempt_enable();
178+
} else if (m->inject_flags & MCJ_NMI_BROADCAST)
179+
apic->send_IPI_mask(mce_inject_cpumask,
180+
NMI_VECTOR);
181+
}
156182
start = jiffies;
157183
while (!cpumask_empty(mce_inject_cpumask)) {
158184
if (!time_before(jiffies, start + 2*HZ)) {
159185
printk(KERN_ERR
160-
"Timeout waiting for mce inject NMI %lx\n",
186+
"Timeout waiting for mce inject %lx\n",
161187
*cpumask_bits(mce_inject_cpumask));
162188
break;
163189
}

0 commit comments

Comments
 (0)