Skip to content

Commit b63a0ff

Browse files
maheshsalozbenh
authored andcommitted
powerpc/powernv: Machine check exception handling.
Add basic error handling in machine check exception handler. - If MSR_RI isn't set, we can not recover. - Check if disposition set to OpalMCE_DISPOSITION_RECOVERED. - Check if address at fault is inside kernel address space, if not then send SIGBUS to process if we hit exception when in userspace. - If address at fault is not provided then and if we get a synchronous machine check while in userspace then kill the task. Signed-off-by: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
1 parent 28446de commit b63a0ff

3 files changed

Lines changed: 70 additions & 1 deletion

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,5 +193,6 @@ extern void release_mce_event(void);
193193
extern void machine_check_queue_event(void);
194194
extern void machine_check_process_queued_event(void);
195195
extern void machine_check_print_event_info(struct machine_check_event *evt);
196+
extern uint64_t get_mce_fault_addr(struct machine_check_event *evt);
196197

197198
#endif /* __ASM_PPC64_MCE_H__ */

‎arch/powerpc/kernel/mce.c‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,3 +316,30 @@ void machine_check_print_event_info(struct machine_check_event *evt)
316316
break;
317317
}
318318
}
319+
320+
uint64_t get_mce_fault_addr(struct machine_check_event *evt)
321+
{
322+
switch (evt->error_type) {
323+
case MCE_ERROR_TYPE_UE:
324+
if (evt->u.ue_error.effective_address_provided)
325+
return evt->u.ue_error.effective_address;
326+
break;
327+
case MCE_ERROR_TYPE_SLB:
328+
if (evt->u.slb_error.effective_address_provided)
329+
return evt->u.slb_error.effective_address;
330+
break;
331+
case MCE_ERROR_TYPE_ERAT:
332+
if (evt->u.erat_error.effective_address_provided)
333+
return evt->u.erat_error.effective_address;
334+
break;
335+
case MCE_ERROR_TYPE_TLB:
336+
if (evt->u.tlb_error.effective_address_provided)
337+
return evt->u.tlb_error.effective_address;
338+
break;
339+
default:
340+
case MCE_ERROR_TYPE_UNKNOWN:
341+
break;
342+
}
343+
return 0;
344+
}
345+
EXPORT_SYMBOL(get_mce_fault_addr);

‎arch/powerpc/platforms/powernv/opal.c‎

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/interrupt.h>
1919
#include <linux/notifier.h>
2020
#include <linux/slab.h>
21+
#include <linux/sched.h>
2122
#include <linux/kobject.h>
2223
#include <asm/opal.h>
2324
#include <asm/firmware.h>
@@ -251,6 +252,44 @@ int opal_put_chars(uint32_t vtermno, const char *data, int total_len)
251252
return written;
252253
}
253254

255+
static int opal_recover_mce(struct pt_regs *regs,
256+
struct machine_check_event *evt)
257+
{
258+
int recovered = 0;
259+
uint64_t ea = get_mce_fault_addr(evt);
260+
261+
if (!(regs->msr & MSR_RI)) {
262+
/* If MSR_RI isn't set, we cannot recover */
263+
recovered = 0;
264+
} else if (evt->disposition == MCE_DISPOSITION_RECOVERED) {
265+
/* Platform corrected itself */
266+
recovered = 1;
267+
} else if (ea && !is_kernel_addr(ea)) {
268+
/*
269+
* Faulting address is not in kernel text. We should be fine.
270+
* We need to find which process uses this address.
271+
* For now, kill the task if we have received exception when
272+
* in userspace.
273+
*
274+
* TODO: Queue up this address for hwpoisioning later.
275+
*/
276+
if (user_mode(regs) && !is_global_init(current)) {
277+
_exception(SIGBUS, regs, BUS_MCEERR_AR, regs->nip);
278+
recovered = 1;
279+
} else
280+
recovered = 0;
281+
} else if (user_mode(regs) && !is_global_init(current) &&
282+
evt->severity == MCE_SEV_ERROR_SYNC) {
283+
/*
284+
* If we have received a synchronous error when in userspace
285+
* kill the task.
286+
*/
287+
_exception(SIGBUS, regs, BUS_MCEERR_AR, regs->nip);
288+
recovered = 1;
289+
}
290+
return recovered;
291+
}
292+
254293
int opal_machine_check(struct pt_regs *regs)
255294
{
256295
struct machine_check_event evt;
@@ -266,7 +305,9 @@ int opal_machine_check(struct pt_regs *regs)
266305
}
267306
machine_check_print_event_info(&evt);
268307

269-
return evt.severity == MCE_SEV_FATAL ? 0 : 1;
308+
if (opal_recover_mce(regs, &evt))
309+
return 1;
310+
return 0;
270311
}
271312

272313
static irqreturn_t opal_interrupt(int irq, void *data)

0 commit comments

Comments
 (0)