Skip to content

Commit edf7c81

Browse files
committed
Merge branch 'x86-mce-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
* 'x86-mce-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86: add IRQ context simulation in module mce-inject x86, mce, therm_throt: Don't report power limit and package level thermal throttle events in mcelog x86, MCE: Drain mcelog buffer x86, mce: Add wrappers for registering on the decode chain
2 parents 82406da + a228b58 commit edf7c81

7 files changed

Lines changed: 107 additions & 46 deletions

File tree

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

Lines changed: 7 additions & 5 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 {
@@ -120,7 +121,8 @@ struct mce_log {
120121

121122
#ifdef __KERNEL__
122123

123-
extern struct atomic_notifier_head x86_mce_decoder_chain;
124+
extern void mce_register_decode_chain(struct notifier_block *nb);
125+
extern void mce_unregister_decode_chain(struct notifier_block *nb);
124126

125127
#include <linux/percpu.h>
126128
#include <linux/init.h>

‎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
}

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

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,20 +95,19 @@ static DECLARE_WAIT_QUEUE_HEAD(mce_chrdev_wait);
9595
static DEFINE_PER_CPU(struct mce, mces_seen);
9696
static int cpu_missing;
9797

98-
/*
99-
* CPU/chipset specific EDAC code can register a notifier call here to print
100-
* MCE errors in a human-readable form.
101-
*/
102-
ATOMIC_NOTIFIER_HEAD(x86_mce_decoder_chain);
103-
EXPORT_SYMBOL_GPL(x86_mce_decoder_chain);
104-
10598
/* MCA banks polled by the period polling timer for corrected events */
10699
DEFINE_PER_CPU(mce_banks_t, mce_poll_banks) = {
107100
[0 ... BITS_TO_LONGS(MAX_NR_BANKS)-1] = ~0UL
108101
};
109102

110103
static DEFINE_PER_CPU(struct work_struct, mce_work);
111104

105+
/*
106+
* CPU/chipset specific EDAC code can register a notifier call here to print
107+
* MCE errors in a human-readable form.
108+
*/
109+
ATOMIC_NOTIFIER_HEAD(x86_mce_decoder_chain);
110+
112111
/* Do initial initialization of a struct mce */
113112
void mce_setup(struct mce *m)
114113
{
@@ -188,6 +187,57 @@ void mce_log(struct mce *mce)
188187
set_bit(0, &mce_need_notify);
189188
}
190189

190+
static void drain_mcelog_buffer(void)
191+
{
192+
unsigned int next, i, prev = 0;
193+
194+
next = rcu_dereference_check_mce(mcelog.next);
195+
196+
do {
197+
struct mce *m;
198+
199+
/* drain what was logged during boot */
200+
for (i = prev; i < next; i++) {
201+
unsigned long start = jiffies;
202+
unsigned retries = 1;
203+
204+
m = &mcelog.entry[i];
205+
206+
while (!m->finished) {
207+
if (time_after_eq(jiffies, start + 2*retries))
208+
retries++;
209+
210+
cpu_relax();
211+
212+
if (!m->finished && retries >= 4) {
213+
pr_err("MCE: skipping error being logged currently!\n");
214+
break;
215+
}
216+
}
217+
smp_rmb();
218+
atomic_notifier_call_chain(&x86_mce_decoder_chain, 0, m);
219+
}
220+
221+
memset(mcelog.entry + prev, 0, (next - prev) * sizeof(*m));
222+
prev = next;
223+
next = cmpxchg(&mcelog.next, prev, 0);
224+
} while (next != prev);
225+
}
226+
227+
228+
void mce_register_decode_chain(struct notifier_block *nb)
229+
{
230+
atomic_notifier_chain_register(&x86_mce_decoder_chain, nb);
231+
drain_mcelog_buffer();
232+
}
233+
EXPORT_SYMBOL_GPL(mce_register_decode_chain);
234+
235+
void mce_unregister_decode_chain(struct notifier_block *nb)
236+
{
237+
atomic_notifier_chain_unregister(&x86_mce_decoder_chain, nb);
238+
}
239+
EXPORT_SYMBOL_GPL(mce_unregister_decode_chain);
240+
191241
static void print_mce(struct mce *m)
192242
{
193243
int ret = 0;

‎arch/x86/kernel/cpu/mcheck/therm_throt.c‎

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -323,17 +323,6 @@ device_initcall(thermal_throttle_init_device);
323323

324324
#endif /* CONFIG_SYSFS */
325325

326-
/*
327-
* Set up the most two significant bit to notify mce log that this thermal
328-
* event type.
329-
* This is a temp solution. May be changed in the future with mce log
330-
* infrasture.
331-
*/
332-
#define CORE_THROTTLED (0)
333-
#define CORE_POWER_LIMIT ((__u64)1 << 62)
334-
#define PACKAGE_THROTTLED ((__u64)2 << 62)
335-
#define PACKAGE_POWER_LIMIT ((__u64)3 << 62)
336-
337326
static void notify_thresholds(__u64 msr_val)
338327
{
339328
/* check whether the interrupt handler is defined;
@@ -363,27 +352,23 @@ static void intel_thermal_interrupt(void)
363352
if (therm_throt_process(msr_val & THERM_STATUS_PROCHOT,
364353
THERMAL_THROTTLING_EVENT,
365354
CORE_LEVEL) != 0)
366-
mce_log_therm_throt_event(CORE_THROTTLED | msr_val);
355+
mce_log_therm_throt_event(msr_val);
367356

368357
if (this_cpu_has(X86_FEATURE_PLN))
369-
if (therm_throt_process(msr_val & THERM_STATUS_POWER_LIMIT,
358+
therm_throt_process(msr_val & THERM_STATUS_POWER_LIMIT,
370359
POWER_LIMIT_EVENT,
371-
CORE_LEVEL) != 0)
372-
mce_log_therm_throt_event(CORE_POWER_LIMIT | msr_val);
360+
CORE_LEVEL);
373361

374362
if (this_cpu_has(X86_FEATURE_PTS)) {
375363
rdmsrl(MSR_IA32_PACKAGE_THERM_STATUS, msr_val);
376-
if (therm_throt_process(msr_val & PACKAGE_THERM_STATUS_PROCHOT,
364+
therm_throt_process(msr_val & PACKAGE_THERM_STATUS_PROCHOT,
377365
THERMAL_THROTTLING_EVENT,
378-
PACKAGE_LEVEL) != 0)
379-
mce_log_therm_throt_event(PACKAGE_THROTTLED | msr_val);
366+
PACKAGE_LEVEL);
380367
if (this_cpu_has(X86_FEATURE_PLN))
381-
if (therm_throt_process(msr_val &
368+
therm_throt_process(msr_val &
382369
PACKAGE_THERM_STATUS_POWER_LIMIT,
383370
POWER_LIMIT_EVENT,
384-
PACKAGE_LEVEL) != 0)
385-
mce_log_therm_throt_event(PACKAGE_POWER_LIMIT
386-
| msr_val);
371+
PACKAGE_LEVEL);
387372
}
388373
}
389374

‎drivers/edac/i7core_edac.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2234,7 +2234,7 @@ static void i7core_unregister_mci(struct i7core_dev *i7core_dev)
22342234
if (pvt->enable_scrub)
22352235
disable_sdram_scrub_setting(mci);
22362236

2237-
atomic_notifier_chain_unregister(&x86_mce_decoder_chain, &i7_mce_dec);
2237+
mce_unregister_decode_chain(&i7_mce_dec);
22382238

22392239
/* Disable EDAC polling */
22402240
i7core_pci_ctl_release(pvt);
@@ -2336,7 +2336,7 @@ static int i7core_register_mci(struct i7core_dev *i7core_dev)
23362336
/* DCLK for scrub rate setting */
23372337
pvt->dclk_freq = get_dclk_freq();
23382338

2339-
atomic_notifier_chain_register(&x86_mce_decoder_chain, &i7_mce_dec);
2339+
mce_register_decode_chain(&i7_mce_dec);
23402340

23412341
return 0;
23422342

‎drivers/edac/mce_amd.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@ static int __init mce_amd_init(void)
884884

885885
pr_info("MCE: In-kernel MCE decoding enabled.\n");
886886

887-
atomic_notifier_chain_register(&x86_mce_decoder_chain, &amd_mce_dec_nb);
887+
mce_register_decode_chain(&amd_mce_dec_nb);
888888

889889
return 0;
890890
}
@@ -893,7 +893,7 @@ early_initcall(mce_amd_init);
893893
#ifdef MODULE
894894
static void __exit mce_amd_exit(void)
895895
{
896-
atomic_notifier_chain_unregister(&x86_mce_decoder_chain, &amd_mce_dec_nb);
896+
mce_unregister_decode_chain(&amd_mce_dec_nb);
897897
kfree(fam_ops);
898898
}
899899

‎drivers/edac/sb_edac.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,8 +1659,7 @@ static void sbridge_unregister_mci(struct sbridge_dev *sbridge_dev)
16591659
debugf0("MC: " __FILE__ ": %s(): mci = %p, dev = %p\n",
16601660
__func__, mci, &sbridge_dev->pdev[0]->dev);
16611661

1662-
atomic_notifier_chain_unregister(&x86_mce_decoder_chain,
1663-
&sbridge_mce_dec);
1662+
mce_unregister_decode_chain(&sbridge_mce_dec);
16641663

16651664
/* Remove MC sysfs nodes */
16661665
edac_mc_del_mc(mci->dev);
@@ -1729,8 +1728,7 @@ static int sbridge_register_mci(struct sbridge_dev *sbridge_dev)
17291728
goto fail0;
17301729
}
17311730

1732-
atomic_notifier_chain_register(&x86_mce_decoder_chain,
1733-
&sbridge_mce_dec);
1731+
mce_register_decode_chain(&sbridge_mce_dec);
17341732
return 0;
17351733

17361734
fail0:

0 commit comments

Comments
 (0)