Skip to content

Commit 36df96f

Browse files
maheshsalozbenh
authored andcommitted
powerpc/book3s: Decode and save machine check event.
Now that we handle machine check in linux, the MCE decoding should also take place in linux host. This info is crucial to log before we go down in case we can not handle the machine check errors. This patch decodes and populates a machine check event which contain high level meaning full MCE information. We do this in real mode C code with ME bit on. The MCE information is still available on emergency stack (in pt_regs structure format). Even if we take another exception at this point the MCE early handler will allocate a new stack frame on top of current one. So when we return back here we still have our MCE information safe on current stack. We use per cpu buffer to save high level MCE information. Each per cpu buffer is an array of machine check event structure indexed by per cpu counter mce_nest_count. The mce_nest_count is incremented every time we enter machine check early handler in real mode to get the current free slot (index = mce_nest_count - 1). The mce_nest_count is decremented once the MCE info is consumed by virtual mode machine exception handler. This patch provides save_mce_event(), get_mce_event() and release_mce_event() generic routines that can be used by machine check handlers to populate and retrieve the event. The routine release_mce_event() will free the event slot so that it can be reused. Caller can invoke get_mce_event() with a release flag either to release the event slot immediately OR keep it so that it can be fetched again. The event slot can be also released anytime by invoking release_mce_event(). This patch also updates kvm code to invoke get_mce_event to retrieve generic mce event rather than paca->opal_mce_evt. The KVM code always calls get_mce_event() with release flags set to false so that event is available for linus host machine If machine check occurs while we are in guest, KVM tries to handle the error. If KVM is able to handle MC error successfully, it enters the guest and delivers the machine check to guest. If KVM is not able to handle MC error, it exists the guest and passes the control to linux host machine check handler which then logs MC event and decides how to handle it in linux host. In failure case, KVM needs to make sure that the MC event is available for linux host to consume. Hence KVM always calls get_mce_event() with release flags set to false and later it invokes release_mce_event() only if it succeeds to handle error. Signed-off-by: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
1 parent ae744f3 commit 36df96f

6 files changed

Lines changed: 434 additions & 39 deletions

File tree

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

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,129 @@
6666

6767
#define P8_DSISR_MC_SLB_ERRORS (P7_DSISR_MC_SLB_ERRORS | \
6868
P8_DSISR_MC_ERAT_MULTIHIT_SEC)
69+
enum MCE_Version {
70+
MCE_V1 = 1,
71+
};
72+
73+
enum MCE_Severity {
74+
MCE_SEV_NO_ERROR = 0,
75+
MCE_SEV_WARNING = 1,
76+
MCE_SEV_ERROR_SYNC = 2,
77+
MCE_SEV_FATAL = 3,
78+
};
79+
80+
enum MCE_Disposition {
81+
MCE_DISPOSITION_RECOVERED = 0,
82+
MCE_DISPOSITION_NOT_RECOVERED = 1,
83+
};
84+
85+
enum MCE_Initiator {
86+
MCE_INITIATOR_UNKNOWN = 0,
87+
MCE_INITIATOR_CPU = 1,
88+
};
89+
90+
enum MCE_ErrorType {
91+
MCE_ERROR_TYPE_UNKNOWN = 0,
92+
MCE_ERROR_TYPE_UE = 1,
93+
MCE_ERROR_TYPE_SLB = 2,
94+
MCE_ERROR_TYPE_ERAT = 3,
95+
MCE_ERROR_TYPE_TLB = 4,
96+
};
97+
98+
enum MCE_UeErrorType {
99+
MCE_UE_ERROR_INDETERMINATE = 0,
100+
MCE_UE_ERROR_IFETCH = 1,
101+
MCE_UE_ERROR_PAGE_TABLE_WALK_IFETCH = 2,
102+
MCE_UE_ERROR_LOAD_STORE = 3,
103+
MCE_UE_ERROR_PAGE_TABLE_WALK_LOAD_STORE = 4,
104+
};
105+
106+
enum MCE_SlbErrorType {
107+
MCE_SLB_ERROR_INDETERMINATE = 0,
108+
MCE_SLB_ERROR_PARITY = 1,
109+
MCE_SLB_ERROR_MULTIHIT = 2,
110+
};
111+
112+
enum MCE_EratErrorType {
113+
MCE_ERAT_ERROR_INDETERMINATE = 0,
114+
MCE_ERAT_ERROR_PARITY = 1,
115+
MCE_ERAT_ERROR_MULTIHIT = 2,
116+
};
117+
118+
enum MCE_TlbErrorType {
119+
MCE_TLB_ERROR_INDETERMINATE = 0,
120+
MCE_TLB_ERROR_PARITY = 1,
121+
MCE_TLB_ERROR_MULTIHIT = 2,
122+
};
123+
124+
struct machine_check_event {
125+
enum MCE_Version version:8; /* 0x00 */
126+
uint8_t in_use; /* 0x01 */
127+
enum MCE_Severity severity:8; /* 0x02 */
128+
enum MCE_Initiator initiator:8; /* 0x03 */
129+
enum MCE_ErrorType error_type:8; /* 0x04 */
130+
enum MCE_Disposition disposition:8; /* 0x05 */
131+
uint8_t reserved_1[2]; /* 0x06 */
132+
uint64_t gpr3; /* 0x08 */
133+
uint64_t srr0; /* 0x10 */
134+
uint64_t srr1; /* 0x18 */
135+
union { /* 0x20 */
136+
struct {
137+
enum MCE_UeErrorType ue_error_type:8;
138+
uint8_t effective_address_provided;
139+
uint8_t physical_address_provided;
140+
uint8_t reserved_1[5];
141+
uint64_t effective_address;
142+
uint64_t physical_address;
143+
uint8_t reserved_2[8];
144+
} ue_error;
145+
146+
struct {
147+
enum MCE_SlbErrorType slb_error_type:8;
148+
uint8_t effective_address_provided;
149+
uint8_t reserved_1[6];
150+
uint64_t effective_address;
151+
uint8_t reserved_2[16];
152+
} slb_error;
153+
154+
struct {
155+
enum MCE_EratErrorType erat_error_type:8;
156+
uint8_t effective_address_provided;
157+
uint8_t reserved_1[6];
158+
uint64_t effective_address;
159+
uint8_t reserved_2[16];
160+
} erat_error;
161+
162+
struct {
163+
enum MCE_TlbErrorType tlb_error_type:8;
164+
uint8_t effective_address_provided;
165+
uint8_t reserved_1[6];
166+
uint64_t effective_address;
167+
uint8_t reserved_2[16];
168+
} tlb_error;
169+
} u;
170+
};
171+
172+
struct mce_error_info {
173+
enum MCE_ErrorType error_type:8;
174+
union {
175+
enum MCE_UeErrorType ue_error_type:8;
176+
enum MCE_SlbErrorType slb_error_type:8;
177+
enum MCE_EratErrorType erat_error_type:8;
178+
enum MCE_TlbErrorType tlb_error_type:8;
179+
} u;
180+
uint8_t reserved[2];
181+
};
182+
183+
#define MAX_MC_EVT 100
184+
185+
/* Release flags for get_mce_event() */
186+
#define MCE_EVENT_RELEASE true
187+
#define MCE_EVENT_DONTRELEASE false
188+
189+
extern void save_mce_event(struct pt_regs *regs, long handled,
190+
struct mce_error_info *mce_err, uint64_t addr);
191+
extern int get_mce_event(struct machine_check_event *mce, bool release);
192+
extern void release_mce_event(void);
69193

70194
#endif /* __ASM_PPC64_MCE_H__ */

‎arch/powerpc/kernel/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ obj-$(CONFIG_PPC64) += setup_64.o sys_ppc32.o \
3939
obj-$(CONFIG_HAVE_HW_BREAKPOINT) += hw_breakpoint.o
4040
obj-$(CONFIG_PPC_BOOK3S_64) += cpu_setup_ppc970.o cpu_setup_pa6t.o
4141
obj-$(CONFIG_PPC_BOOK3S_64) += cpu_setup_power.o
42-
obj-$(CONFIG_PPC_BOOK3S_64) += mce_power.o
42+
obj-$(CONFIG_PPC_BOOK3S_64) += mce.o mce_power.o
4343
obj64-$(CONFIG_RELOCATABLE) += reloc_64.o
4444
obj-$(CONFIG_PPC_BOOK3E_64) += exceptions-64e.o idle_book3e.o
4545
obj-$(CONFIG_PPC_A2) += cpu_setup_a2.o

‎arch/powerpc/kernel/mce.c‎

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
/*
2+
* Machine check exception handling.
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17+
*
18+
* Copyright 2013 IBM Corporation
19+
* Author: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>
20+
*/
21+
22+
#undef DEBUG
23+
#define pr_fmt(fmt) "mce: " fmt
24+
25+
#include <linux/types.h>
26+
#include <linux/ptrace.h>
27+
#include <linux/percpu.h>
28+
#include <linux/export.h>
29+
#include <asm/mce.h>
30+
31+
static DEFINE_PER_CPU(int, mce_nest_count);
32+
static DEFINE_PER_CPU(struct machine_check_event[MAX_MC_EVT], mce_event);
33+
34+
static void mce_set_error_info(struct machine_check_event *mce,
35+
struct mce_error_info *mce_err)
36+
{
37+
mce->error_type = mce_err->error_type;
38+
switch (mce_err->error_type) {
39+
case MCE_ERROR_TYPE_UE:
40+
mce->u.ue_error.ue_error_type = mce_err->u.ue_error_type;
41+
break;
42+
case MCE_ERROR_TYPE_SLB:
43+
mce->u.slb_error.slb_error_type = mce_err->u.slb_error_type;
44+
break;
45+
case MCE_ERROR_TYPE_ERAT:
46+
mce->u.erat_error.erat_error_type = mce_err->u.erat_error_type;
47+
break;
48+
case MCE_ERROR_TYPE_TLB:
49+
mce->u.tlb_error.tlb_error_type = mce_err->u.tlb_error_type;
50+
break;
51+
case MCE_ERROR_TYPE_UNKNOWN:
52+
default:
53+
break;
54+
}
55+
}
56+
57+
/*
58+
* Decode and save high level MCE information into per cpu buffer which
59+
* is an array of machine_check_event structure.
60+
*/
61+
void save_mce_event(struct pt_regs *regs, long handled,
62+
struct mce_error_info *mce_err,
63+
uint64_t addr)
64+
{
65+
uint64_t srr1;
66+
int index = __get_cpu_var(mce_nest_count)++;
67+
struct machine_check_event *mce = &__get_cpu_var(mce_event[index]);
68+
69+
/*
70+
* Return if we don't have enough space to log mce event.
71+
* mce_nest_count may go beyond MAX_MC_EVT but that's ok,
72+
* the check below will stop buffer overrun.
73+
*/
74+
if (index >= MAX_MC_EVT)
75+
return;
76+
77+
/* Populate generic machine check info */
78+
mce->version = MCE_V1;
79+
mce->srr0 = regs->nip;
80+
mce->srr1 = regs->msr;
81+
mce->gpr3 = regs->gpr[3];
82+
mce->in_use = 1;
83+
84+
mce->initiator = MCE_INITIATOR_CPU;
85+
if (handled)
86+
mce->disposition = MCE_DISPOSITION_RECOVERED;
87+
else
88+
mce->disposition = MCE_DISPOSITION_NOT_RECOVERED;
89+
mce->severity = MCE_SEV_ERROR_SYNC;
90+
91+
srr1 = regs->msr;
92+
93+
/*
94+
* Populate the mce error_type and type-specific error_type.
95+
*/
96+
mce_set_error_info(mce, mce_err);
97+
98+
if (!addr)
99+
return;
100+
101+
if (mce->error_type == MCE_ERROR_TYPE_TLB) {
102+
mce->u.tlb_error.effective_address_provided = true;
103+
mce->u.tlb_error.effective_address = addr;
104+
} else if (mce->error_type == MCE_ERROR_TYPE_SLB) {
105+
mce->u.slb_error.effective_address_provided = true;
106+
mce->u.slb_error.effective_address = addr;
107+
} else if (mce->error_type == MCE_ERROR_TYPE_ERAT) {
108+
mce->u.erat_error.effective_address_provided = true;
109+
mce->u.erat_error.effective_address = addr;
110+
} else if (mce->error_type == MCE_ERROR_TYPE_UE) {
111+
mce->u.ue_error.effective_address_provided = true;
112+
mce->u.ue_error.effective_address = addr;
113+
}
114+
return;
115+
}
116+
117+
/*
118+
* get_mce_event:
119+
* mce Pointer to machine_check_event structure to be filled.
120+
* release Flag to indicate whether to free the event slot or not.
121+
* 0 <= do not release the mce event. Caller will invoke
122+
* release_mce_event() once event has been consumed.
123+
* 1 <= release the slot.
124+
*
125+
* return 1 = success
126+
* 0 = failure
127+
*
128+
* get_mce_event() will be called by platform specific machine check
129+
* handle routine and in KVM.
130+
* When we call get_mce_event(), we are still in interrupt context and
131+
* preemption will not be scheduled until ret_from_expect() routine
132+
* is called.
133+
*/
134+
int get_mce_event(struct machine_check_event *mce, bool release)
135+
{
136+
int index = __get_cpu_var(mce_nest_count) - 1;
137+
struct machine_check_event *mc_evt;
138+
int ret = 0;
139+
140+
/* Sanity check */
141+
if (index < 0)
142+
return ret;
143+
144+
/* Check if we have MCE info to process. */
145+
if (index < MAX_MC_EVT) {
146+
mc_evt = &__get_cpu_var(mce_event[index]);
147+
/* Copy the event structure and release the original */
148+
if (mce)
149+
*mce = *mc_evt;
150+
if (release)
151+
mc_evt->in_use = 0;
152+
ret = 1;
153+
}
154+
/* Decrement the count to free the slot. */
155+
if (release)
156+
__get_cpu_var(mce_nest_count)--;
157+
158+
return ret;
159+
}
160+
161+
void release_mce_event(void)
162+
{
163+
get_mce_event(NULL, true);
164+
}

0 commit comments

Comments
 (0)