Skip to content

Commit 5f8c1a5

Browse files
Andi KleenH. Peter Anvin
authored andcommitted
x86, mce: add MSR read wrappers for easier error injection
This will be used by future patches to allow machine check error injection. Right now it's a nop, except for adding some wrappers around the MSR reads. This is early in the sequence to avoid too many conflicts. Signed-off-by: Andi Kleen <ak@linux.intel.com> Signed-off-by: H. Peter Anvin <hpa@zytor.com> Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com> Signed-off-by: H. Peter Anvin <hpa@zytor.com>
1 parent a9862e0 commit 5f8c1a5

File tree

1 file changed

+25
-12
lines changed
  • arch/x86/kernel/cpu/mcheck

1 file changed

+25
-12
lines changed

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

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,19 @@ static void mce_panic(char *msg, struct mce *backup, u64 start)
194194
panic(msg);
195195
}
196196

197+
/* MSR access wrappers used for error injection */
198+
static u64 mce_rdmsrl(u32 msr)
199+
{
200+
u64 v;
201+
rdmsrl(msr, v);
202+
return v;
203+
}
204+
205+
static void mce_wrmsrl(u32 msr, u64 v)
206+
{
207+
wrmsrl(msr, v);
208+
}
209+
197210
int mce_available(struct cpuinfo_x86 *c)
198211
{
199212
if (mce_disabled)
@@ -213,7 +226,7 @@ static inline void mce_get_rip(struct mce *m, struct pt_regs *regs)
213226
if (rip_msr) {
214227
/* Assume the RIP in the MSR is exact. Is this true? */
215228
m->mcgstatus |= MCG_STATUS_EIPV;
216-
rdmsrl(rip_msr, m->ip);
229+
m->ip = mce_rdmsrl(rip_msr);
217230
m->cs = 0;
218231
}
219232
}
@@ -231,7 +244,7 @@ void machine_check_poll(enum mcp_flags flags, mce_banks_t *b)
231244

232245
mce_setup(&m);
233246

234-
rdmsrl(MSR_IA32_MCG_STATUS, m.mcgstatus);
247+
m.mcgstatus = mce_rdmsrl(MSR_IA32_MCG_STATUS);
235248
for (i = 0; i < banks; i++) {
236249
if (!bank[i] || !test_bit(i, *b))
237250
continue;
@@ -242,7 +255,7 @@ void machine_check_poll(enum mcp_flags flags, mce_banks_t *b)
242255
m.tsc = 0;
243256

244257
barrier();
245-
rdmsrl(MSR_IA32_MC0_STATUS + i*4, m.status);
258+
m.status = mce_rdmsrl(MSR_IA32_MC0_STATUS + i*4);
246259
if (!(m.status & MCI_STATUS_VAL))
247260
continue;
248261

@@ -257,9 +270,9 @@ void machine_check_poll(enum mcp_flags flags, mce_banks_t *b)
257270
continue;
258271

259272
if (m.status & MCI_STATUS_MISCV)
260-
rdmsrl(MSR_IA32_MC0_MISC + i*4, m.misc);
273+
m.misc = mce_rdmsrl(MSR_IA32_MC0_MISC + i*4);
261274
if (m.status & MCI_STATUS_ADDRV)
262-
rdmsrl(MSR_IA32_MC0_ADDR + i*4, m.addr);
275+
m.addr = mce_rdmsrl(MSR_IA32_MC0_ADDR + i*4);
263276

264277
if (!(flags & MCP_TIMESTAMP))
265278
m.tsc = 0;
@@ -275,7 +288,7 @@ void machine_check_poll(enum mcp_flags flags, mce_banks_t *b)
275288
/*
276289
* Clear state for this bank.
277290
*/
278-
wrmsrl(MSR_IA32_MC0_STATUS+4*i, 0);
291+
mce_wrmsrl(MSR_IA32_MC0_STATUS+4*i, 0);
279292
}
280293

281294
/*
@@ -320,7 +333,7 @@ void do_machine_check(struct pt_regs *regs, long error_code)
320333

321334
mce_setup(&m);
322335

323-
rdmsrl(MSR_IA32_MCG_STATUS, m.mcgstatus);
336+
m.mcgstatus = mce_rdmsrl(MSR_IA32_MCG_STATUS);
324337

325338
/* if the restart IP is not valid, we're done for */
326339
if (!(m.mcgstatus & MCG_STATUS_RIPV))
@@ -338,7 +351,7 @@ void do_machine_check(struct pt_regs *regs, long error_code)
338351
m.addr = 0;
339352
m.bank = i;
340353

341-
rdmsrl(MSR_IA32_MC0_STATUS + i*4, m.status);
354+
m.status = mce_rdmsrl(MSR_IA32_MC0_STATUS + i*4);
342355
if ((m.status & MCI_STATUS_VAL) == 0)
343356
continue;
344357

@@ -378,9 +391,9 @@ void do_machine_check(struct pt_regs *regs, long error_code)
378391
}
379392

380393
if (m.status & MCI_STATUS_MISCV)
381-
rdmsrl(MSR_IA32_MC0_MISC + i*4, m.misc);
394+
m.misc = mce_rdmsrl(MSR_IA32_MC0_MISC + i*4);
382395
if (m.status & MCI_STATUS_ADDRV)
383-
rdmsrl(MSR_IA32_MC0_ADDR + i*4, m.addr);
396+
m.addr = mce_rdmsrl(MSR_IA32_MC0_ADDR + i*4);
384397

385398
mce_get_rip(&m, regs);
386399
mce_log(&m);
@@ -449,9 +462,9 @@ void do_machine_check(struct pt_regs *regs, long error_code)
449462
/* the last thing we do is clear state */
450463
for (i = 0; i < banks; i++) {
451464
if (test_bit(i, toclear))
452-
wrmsrl(MSR_IA32_MC0_STATUS+4*i, 0);
465+
mce_wrmsrl(MSR_IA32_MC0_STATUS+4*i, 0);
453466
}
454-
wrmsrl(MSR_IA32_MCG_STATUS, 0);
467+
mce_wrmsrl(MSR_IA32_MCG_STATUS, 0);
455468
out2:
456469
atomic_dec(&mce_entry);
457470
}

0 commit comments

Comments
 (0)