2011-09-20 00:44:57 +07:00
|
|
|
/*
|
|
|
|
* PowerNV OPAL high level interfaces
|
|
|
|
*
|
|
|
|
* Copyright 2011 IBM Corp.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version
|
|
|
|
* 2 of the License, or (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
2014-12-11 08:39:49 +07:00
|
|
|
#define pr_fmt(fmt) "opal: " fmt
|
2011-09-20 00:44:57 +07:00
|
|
|
|
2014-12-11 08:39:49 +07:00
|
|
|
#include <linux/printk.h>
|
2011-09-20 00:44:57 +07:00
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/of.h>
|
2013-09-26 19:40:04 +07:00
|
|
|
#include <linux/of_fdt.h>
|
2011-09-20 00:44:57 +07:00
|
|
|
#include <linux/of_platform.h>
|
2017-07-19 04:36:33 +07:00
|
|
|
#include <linux/of_address.h>
|
2011-09-20 00:45:03 +07:00
|
|
|
#include <linux/interrupt.h>
|
2013-06-20 17:13:22 +07:00
|
|
|
#include <linux/notifier.h>
|
2013-05-10 13:59:18 +07:00
|
|
|
#include <linux/slab.h>
|
2013-10-30 21:36:13 +07:00
|
|
|
#include <linux/sched.h>
|
2013-08-27 16:39:52 +07:00
|
|
|
#include <linux/kobject.h>
|
2014-01-15 13:02:04 +07:00
|
|
|
#include <linux/delay.h>
|
2013-12-16 12:16:24 +07:00
|
|
|
#include <linux/memblock.h>
|
2014-11-14 12:13:50 +07:00
|
|
|
#include <linux/kthread.h>
|
|
|
|
#include <linux/freezer.h>
|
2017-07-19 13:59:10 +07:00
|
|
|
#include <linux/printk.h>
|
|
|
|
#include <linux/kmsg_dump.h>
|
|
|
|
#include <linux/console.h>
|
|
|
|
#include <linux/sched/debug.h>
|
2014-07-15 19:22:24 +07:00
|
|
|
|
|
|
|
#include <asm/machdep.h>
|
2011-09-20 00:44:57 +07:00
|
|
|
#include <asm/opal.h>
|
|
|
|
#include <asm/firmware.h>
|
2013-10-30 21:35:40 +07:00
|
|
|
#include <asm/mce.h>
|
2017-07-19 04:36:33 +07:00
|
|
|
#include <asm/imc-pmu.h>
|
powerpc/powernv: Use kernel crash path for machine checks
There are quite a few machine check exceptions that can be caused by
kernel bugs. To make debugging easier, use the kernel crash path in
cases of synchronous machine checks that occur in kernel mode, if that
would not result in the machine going straight to panic or crash dump.
There is a downside here that die()ing the process in kernel mode can
still leave the system unstable. panic_on_oops will always force the
system to fail-stop, so systems where that behaviour is important will
still do the right thing.
As a test, when triggering an i-side 0111b error (ifetch from foreign
address) in kernel mode process context on POWER9, the kernel currently
dies quickly like this:
Severe Machine check interrupt [Not recovered]
NIP [ffff000000000000]: 0xffff000000000000
Initiator: CPU
Error type: Real address [Instruction fetch (foreign)]
[ 127.426651616,0] OPAL: Reboot requested due to Platform error.
Effective[ 127.426693712,3] OPAL: Reboot requested due to Platform error. address: ffff000000000000
opal: Reboot type 1 not supported
Kernel panic - not syncing: PowerNV Unrecovered Machine Check
CPU: 56 PID: 4425 Comm: syscall Tainted: G M 4.12.0-rc1-13857-ga4700a261072-dirty #35
Call Trace:
[ 128.017988928,4] IPMI: BUG: Dropping ESEL on the floor due to
buggy/mising code in OPAL for this BMC
Rebooting in 10 seconds..
Trying to free IRQ 496 from IRQ context!
After this patch, the process is killed and the kernel continues with
this message, which gives enough information to identify the offending
branch (i.e., with CFAR):
Severe Machine check interrupt [Not recovered]
NIP [ffff000000000000]: 0xffff000000000000
Initiator: CPU
Error type: Real address [Instruction fetch (foreign)]
Effective address: ffff000000000000
Oops: Machine check, sig: 7 [#1]
SMP NR_CPUS=2048
NUMA
PowerNV
Modules linked in: iptable_mangle ipt_MASQUERADE nf_nat_masquerade_ipv4 ...
CPU: 22 PID: 4436 Comm: syscall Tainted: G M 4.12.0-rc1-13857-ga4700a261072-dirty #36
task: c000000932300000 task.stack: c000000932380000
NIP: ffff000000000000 LR: 00000000217706a4 CTR: ffff000000000000
REGS: c00000000fc8fd80 TRAP: 0200 Tainted: G M (4.12.0-rc1-13857-ga4700a261072-dirty)
MSR: 90000000001c1003 <SF,HV,ME,RI,LE>
CR: 24000484 XER: 20000000
CFAR: c000000000004c80 DAR: 0000000021770a90 DSISR: 0a000000 SOFTE: 1
GPR00: 0000000000001ebe 00007fffce4818b0 0000000021797f00 0000000000000000
GPR04: 00007fff8007ac24 0000000044000484 0000000000004000 00007fff801405e8
GPR08: 900000000280f033 0000000024000484 0000000000000000 0000000000000030
GPR12: 9000000000001003 00007fff801bc370 0000000000000000 0000000000000000
GPR16: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
GPR20: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
GPR24: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
GPR28: 00007fff801b0000 0000000000000000 00000000217707a0 00007fffce481918
NIP [ffff000000000000] 0xffff000000000000
LR [00000000217706a4] 0x217706a4
Call Trace:
Instruction dump:
XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Reviewed-by: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2017-07-19 13:59:11 +07:00
|
|
|
#include <asm/bug.h>
|
2011-09-20 00:44:57 +07:00
|
|
|
|
|
|
|
#include "powernv.h"
|
|
|
|
|
2013-08-27 16:39:52 +07:00
|
|
|
/* /sys/firmware/opal */
|
|
|
|
struct kobject *opal_kobj;
|
|
|
|
|
2011-09-20 00:44:57 +07:00
|
|
|
struct opal {
|
|
|
|
u64 base;
|
|
|
|
u64 entry;
|
2013-12-16 12:16:24 +07:00
|
|
|
u64 size;
|
2011-09-20 00:44:57 +07:00
|
|
|
} opal;
|
|
|
|
|
2013-12-16 12:16:24 +07:00
|
|
|
struct mcheck_recoverable_range {
|
|
|
|
u64 start_addr;
|
|
|
|
u64 end_addr;
|
|
|
|
u64 recover_addr;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct mcheck_recoverable_range *mc_recoverable_range;
|
|
|
|
static int mc_recoverable_range_len;
|
|
|
|
|
2014-04-01 10:58:19 +07:00
|
|
|
struct device_node *opal_node;
|
2011-09-20 00:44:57 +07:00
|
|
|
static DEFINE_SPINLOCK(opal_write_lock);
|
2013-11-18 17:05:58 +07:00
|
|
|
static struct atomic_notifier_head opal_msg_notifier_head[OPAL_MSG_TYPE_MAX];
|
2014-11-14 12:13:50 +07:00
|
|
|
static uint32_t opal_heartbeat;
|
2016-07-04 11:51:44 +07:00
|
|
|
static struct task_struct *kopald_tsk;
|
2011-09-20 00:44:57 +07:00
|
|
|
|
2016-07-05 12:03:49 +07:00
|
|
|
void opal_configure_cores(void)
|
2014-05-20 08:01:28 +07:00
|
|
|
{
|
2017-07-01 05:37:32 +07:00
|
|
|
u64 reinit_flags = 0;
|
|
|
|
|
2014-05-20 08:01:28 +07:00
|
|
|
/* Do the actual re-init, This will clobber all FPRs, VRs, etc...
|
|
|
|
*
|
|
|
|
* It will preserve non volatile GPRs and HSPRG0/1. It will
|
|
|
|
* also restore HIDs and other SPRs to their original value
|
|
|
|
* but it might clobber a bunch.
|
|
|
|
*/
|
|
|
|
#ifdef __BIG_ENDIAN__
|
2017-07-01 05:37:32 +07:00
|
|
|
reinit_flags |= OPAL_REINIT_CPUS_HILE_BE;
|
2014-05-20 08:01:28 +07:00
|
|
|
#else
|
2017-07-01 05:37:32 +07:00
|
|
|
reinit_flags |= OPAL_REINIT_CPUS_HILE_LE;
|
2014-05-20 08:01:28 +07:00
|
|
|
#endif
|
2016-07-05 12:03:49 +07:00
|
|
|
|
2017-07-01 05:37:32 +07:00
|
|
|
/*
|
|
|
|
* POWER9 always support running hash:
|
|
|
|
* ie. Host hash supports hash guests
|
|
|
|
* Host radix supports hash/radix guests
|
|
|
|
*/
|
2017-07-17 18:19:01 +07:00
|
|
|
if (early_cpu_has_feature(CPU_FTR_ARCH_300)) {
|
2017-07-01 05:37:32 +07:00
|
|
|
reinit_flags |= OPAL_REINIT_CPUS_MMU_HASH;
|
|
|
|
if (early_radix_enabled())
|
|
|
|
reinit_flags |= OPAL_REINIT_CPUS_MMU_RADIX;
|
|
|
|
}
|
|
|
|
|
|
|
|
opal_reinit_cpus(reinit_flags);
|
|
|
|
|
2016-07-05 12:03:49 +07:00
|
|
|
/* Restore some bits */
|
|
|
|
if (cur_cpu_spec->cpu_restore)
|
|
|
|
cur_cpu_spec->cpu_restore();
|
2014-05-20 08:01:28 +07:00
|
|
|
}
|
|
|
|
|
2011-09-20 00:44:57 +07:00
|
|
|
int __init early_init_dt_scan_opal(unsigned long node,
|
|
|
|
const char *uname, int depth, void *data)
|
|
|
|
{
|
2013-12-16 12:16:24 +07:00
|
|
|
const void *basep, *entryp, *sizep;
|
2014-04-02 11:49:03 +07:00
|
|
|
int basesz, entrysz, runtimesz;
|
2011-09-20 00:44:57 +07:00
|
|
|
|
|
|
|
if (depth != 1 || strcmp(uname, "ibm,opal") != 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
basep = of_get_flat_dt_prop(node, "opal-base-address", &basesz);
|
|
|
|
entryp = of_get_flat_dt_prop(node, "opal-entry-address", &entrysz);
|
2013-12-16 12:16:24 +07:00
|
|
|
sizep = of_get_flat_dt_prop(node, "opal-runtime-size", &runtimesz);
|
2011-09-20 00:44:57 +07:00
|
|
|
|
2013-12-16 12:16:24 +07:00
|
|
|
if (!basep || !entryp || !sizep)
|
2011-09-20 00:44:57 +07:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
opal.base = of_read_number(basep, basesz/4);
|
|
|
|
opal.entry = of_read_number(entryp, entrysz/4);
|
2013-12-16 12:16:24 +07:00
|
|
|
opal.size = of_read_number(sizep, runtimesz/4);
|
2011-09-20 00:44:57 +07:00
|
|
|
|
2014-04-02 11:49:03 +07:00
|
|
|
pr_debug("OPAL Base = 0x%llx (basep=%p basesz=%d)\n",
|
2011-09-20 00:44:57 +07:00
|
|
|
opal.base, basep, basesz);
|
2014-04-02 11:49:03 +07:00
|
|
|
pr_debug("OPAL Entry = 0x%llx (entryp=%p basesz=%d)\n",
|
2011-09-20 00:44:57 +07:00
|
|
|
opal.entry, entryp, entrysz);
|
2014-04-02 11:49:03 +07:00
|
|
|
pr_debug("OPAL Entry = 0x%llx (sizep=%p runtimesz=%d)\n",
|
2013-12-16 12:16:24 +07:00
|
|
|
opal.size, sizep, runtimesz);
|
2011-09-20 00:44:57 +07:00
|
|
|
|
2013-05-14 12:10:02 +07:00
|
|
|
if (of_flat_dt_is_compatible(node, "ibm,opal-v3")) {
|
2015-12-09 13:18:20 +07:00
|
|
|
powerpc_firmware_features |= FW_FEATURE_OPAL;
|
2017-11-22 13:01:06 +07:00
|
|
|
pr_debug("OPAL detected !\n");
|
2011-09-20 00:44:57 +07:00
|
|
|
} else {
|
2015-12-09 13:18:18 +07:00
|
|
|
panic("OPAL != V3 detected, no longer supported.\n");
|
2011-09-20 00:44:57 +07:00
|
|
|
}
|
|
|
|
|
2013-05-02 05:31:50 +07:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-12-16 12:16:24 +07:00
|
|
|
int __init early_init_dt_scan_recoverable_ranges(unsigned long node,
|
|
|
|
const char *uname, int depth, void *data)
|
|
|
|
{
|
2014-04-02 11:49:03 +07:00
|
|
|
int i, psize, size;
|
2013-12-16 12:16:24 +07:00
|
|
|
const __be32 *prop;
|
|
|
|
|
|
|
|
if (depth != 1 || strcmp(uname, "ibm,opal") != 0)
|
|
|
|
return 0;
|
|
|
|
|
2014-03-30 12:33:23 +07:00
|
|
|
prop = of_get_flat_dt_prop(node, "mcheck-recoverable-ranges", &psize);
|
2013-12-16 12:16:24 +07:00
|
|
|
|
|
|
|
if (!prop)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
pr_debug("Found machine check recoverable ranges.\n");
|
|
|
|
|
2014-03-30 12:33:23 +07:00
|
|
|
/*
|
|
|
|
* Calculate number of available entries.
|
|
|
|
*
|
|
|
|
* Each recoverable address range entry is (start address, len,
|
|
|
|
* recovery address), 2 cells each for start and recovery address,
|
|
|
|
* 1 cell for len, totalling 5 cells per entry.
|
|
|
|
*/
|
|
|
|
mc_recoverable_range_len = psize / (sizeof(*prop) * 5);
|
|
|
|
|
|
|
|
/* Sanity check */
|
|
|
|
if (!mc_recoverable_range_len)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* Size required to hold all the entries. */
|
|
|
|
size = mc_recoverable_range_len *
|
|
|
|
sizeof(struct mcheck_recoverable_range);
|
|
|
|
|
2013-12-16 12:16:24 +07:00
|
|
|
/*
|
2017-08-13 08:33:39 +07:00
|
|
|
* Allocate a buffer to hold the MC recoverable ranges.
|
2013-12-16 12:16:24 +07:00
|
|
|
*/
|
2017-08-13 08:33:39 +07:00
|
|
|
mc_recoverable_range =__va(memblock_alloc(size, __alignof__(u64)));
|
2013-12-16 12:16:24 +07:00
|
|
|
memset(mc_recoverable_range, 0, size);
|
|
|
|
|
2014-03-30 12:33:23 +07:00
|
|
|
for (i = 0; i < mc_recoverable_range_len; i++) {
|
2013-12-16 12:16:24 +07:00
|
|
|
mc_recoverable_range[i].start_addr =
|
|
|
|
of_read_number(prop + (i * 5) + 0, 2);
|
|
|
|
mc_recoverable_range[i].end_addr =
|
|
|
|
mc_recoverable_range[i].start_addr +
|
|
|
|
of_read_number(prop + (i * 5) + 2, 1);
|
|
|
|
mc_recoverable_range[i].recover_addr =
|
|
|
|
of_read_number(prop + (i * 5) + 3, 2);
|
|
|
|
|
|
|
|
pr_debug("Machine check recoverable range: %llx..%llx: %llx\n",
|
|
|
|
mc_recoverable_range[i].start_addr,
|
|
|
|
mc_recoverable_range[i].end_addr,
|
|
|
|
mc_recoverable_range[i].recover_addr);
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-05-02 05:31:50 +07:00
|
|
|
static int __init opal_register_exception_handlers(void)
|
|
|
|
{
|
2013-09-23 09:05:04 +07:00
|
|
|
#ifdef __BIG_ENDIAN__
|
2013-05-02 05:31:50 +07:00
|
|
|
u64 glue;
|
|
|
|
|
|
|
|
if (!(powerpc_firmware_features & FW_FEATURE_OPAL))
|
|
|
|
return -ENODEV;
|
|
|
|
|
2013-10-30 21:35:58 +07:00
|
|
|
/* Hookup some exception handlers except machine check. We use the
|
|
|
|
* fwnmi area at 0x7000 to provide the glue space to OPAL
|
2011-09-20 00:45:04 +07:00
|
|
|
*/
|
|
|
|
glue = 0x7000;
|
2014-10-10 22:58:26 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if we are running on newer firmware that exports
|
|
|
|
* OPAL_HANDLE_HMI token. If yes, then don't ask OPAL to patch
|
|
|
|
* the HMI interrupt and we catch it directly in Linux.
|
|
|
|
*
|
|
|
|
* For older firmware (i.e currently released POWER8 System Firmware
|
|
|
|
* as of today <= SV810_087), we fallback to old behavior and let OPAL
|
|
|
|
* patch the HMI vector and handle it inside OPAL firmware.
|
|
|
|
*
|
|
|
|
* For newer firmware (in development/yet to be released) we will
|
|
|
|
* start catching/handling HMI directly in Linux.
|
|
|
|
*/
|
|
|
|
if (!opal_check_token(OPAL_HANDLE_HMI)) {
|
2015-01-28 11:10:33 +07:00
|
|
|
pr_info("Old firmware detected, OPAL handles HMIs.\n");
|
2014-10-10 22:58:26 +07:00
|
|
|
opal_register_exception_handler(
|
|
|
|
OPAL_HYPERVISOR_MAINTENANCE_HANDLER,
|
|
|
|
0, glue);
|
|
|
|
glue += 128;
|
|
|
|
}
|
|
|
|
|
2011-09-20 00:45:04 +07:00
|
|
|
opal_register_exception_handler(OPAL_SOFTPATCH_HANDLER, 0, glue);
|
2013-09-23 09:05:04 +07:00
|
|
|
#endif
|
2011-09-20 00:45:04 +07:00
|
|
|
|
2013-05-02 05:31:50 +07:00
|
|
|
return 0;
|
2011-09-20 00:44:57 +07:00
|
|
|
}
|
2014-07-15 19:22:24 +07:00
|
|
|
machine_early_initcall(powernv, opal_register_exception_handlers);
|
2013-05-02 05:31:50 +07:00
|
|
|
|
2013-11-18 17:05:58 +07:00
|
|
|
/*
|
|
|
|
* Opal message notifier based on message type. Allow subscribers to get
|
|
|
|
* notified for specific messgae type.
|
|
|
|
*/
|
2015-02-17 16:01:54 +07:00
|
|
|
int opal_message_notifier_register(enum opal_msg_type msg_type,
|
2013-11-18 17:05:58 +07:00
|
|
|
struct notifier_block *nb)
|
|
|
|
{
|
2015-02-11 13:27:06 +07:00
|
|
|
if (!nb || msg_type >= OPAL_MSG_TYPE_MAX) {
|
2016-10-25 11:00:08 +07:00
|
|
|
pr_warn("%s: Invalid arguments, msg_type:%d\n",
|
|
|
|
__func__, msg_type);
|
2013-11-18 17:05:58 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2015-02-11 13:27:06 +07:00
|
|
|
|
2013-11-18 17:05:58 +07:00
|
|
|
return atomic_notifier_chain_register(
|
|
|
|
&opal_msg_notifier_head[msg_type], nb);
|
|
|
|
}
|
2015-05-20 10:23:33 +07:00
|
|
|
EXPORT_SYMBOL_GPL(opal_message_notifier_register);
|
2013-11-18 17:05:58 +07:00
|
|
|
|
2015-03-26 16:03:16 +07:00
|
|
|
int opal_message_notifier_unregister(enum opal_msg_type msg_type,
|
2015-02-11 13:27:23 +07:00
|
|
|
struct notifier_block *nb)
|
|
|
|
{
|
|
|
|
return atomic_notifier_chain_unregister(
|
|
|
|
&opal_msg_notifier_head[msg_type], nb);
|
|
|
|
}
|
2015-05-20 10:23:33 +07:00
|
|
|
EXPORT_SYMBOL_GPL(opal_message_notifier_unregister);
|
2015-02-11 13:27:23 +07:00
|
|
|
|
2013-11-18 17:05:58 +07:00
|
|
|
static void opal_message_do_notify(uint32_t msg_type, void *msg)
|
|
|
|
{
|
|
|
|
/* notify subscribers */
|
|
|
|
atomic_notifier_call_chain(&opal_msg_notifier_head[msg_type],
|
|
|
|
msg_type, msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void opal_handle_message(void)
|
|
|
|
{
|
|
|
|
s64 ret;
|
|
|
|
/*
|
|
|
|
* TODO: pre-allocate a message buffer depending on opal-msg-size
|
|
|
|
* value in /proc/device-tree.
|
|
|
|
*/
|
|
|
|
static struct opal_msg msg;
|
2014-03-28 12:33:33 +07:00
|
|
|
u32 type;
|
2013-11-18 17:05:58 +07:00
|
|
|
|
|
|
|
ret = opal_get_msg(__pa(&msg), sizeof(msg));
|
|
|
|
/* No opal message pending. */
|
|
|
|
if (ret == OPAL_RESOURCE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* check for errors. */
|
|
|
|
if (ret) {
|
2016-10-25 11:00:08 +07:00
|
|
|
pr_warn("%s: Failed to retrieve opal message, err=%lld\n",
|
|
|
|
__func__, ret);
|
2013-11-18 17:05:58 +07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-28 12:33:33 +07:00
|
|
|
type = be32_to_cpu(msg.msg_type);
|
|
|
|
|
2013-11-18 17:05:58 +07:00
|
|
|
/* Sanity check */
|
2015-02-11 13:27:06 +07:00
|
|
|
if (type >= OPAL_MSG_TYPE_MAX) {
|
2015-12-11 08:08:23 +07:00
|
|
|
pr_warn_once("%s: Unknown message type: %u\n", __func__, type);
|
2013-11-18 17:05:58 +07:00
|
|
|
return;
|
|
|
|
}
|
2014-03-28 12:33:33 +07:00
|
|
|
opal_message_do_notify(type, (void *)&msg);
|
2013-11-18 17:05:58 +07:00
|
|
|
}
|
|
|
|
|
2015-05-15 11:06:41 +07:00
|
|
|
static irqreturn_t opal_message_notify(int irq, void *data)
|
2013-11-18 17:05:58 +07:00
|
|
|
{
|
2015-05-15 11:06:41 +07:00
|
|
|
opal_handle_message();
|
|
|
|
return IRQ_HANDLED;
|
2013-11-18 17:05:58 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int __init opal_message_init(void)
|
|
|
|
{
|
2015-05-15 11:06:41 +07:00
|
|
|
int ret, i, irq;
|
2013-11-18 17:05:58 +07:00
|
|
|
|
|
|
|
for (i = 0; i < OPAL_MSG_TYPE_MAX; i++)
|
|
|
|
ATOMIC_INIT_NOTIFIER_HEAD(&opal_msg_notifier_head[i]);
|
|
|
|
|
2015-05-15 11:06:41 +07:00
|
|
|
irq = opal_event_request(ilog2(OPAL_EVENT_MSG_PENDING));
|
|
|
|
if (!irq) {
|
|
|
|
pr_err("%s: Can't register OPAL event irq (%d)\n",
|
|
|
|
__func__, irq);
|
|
|
|
return irq;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = request_irq(irq, opal_message_notify,
|
|
|
|
IRQ_TYPE_LEVEL_HIGH, "opal-msg", NULL);
|
2013-11-18 17:05:58 +07:00
|
|
|
if (ret) {
|
2015-05-15 11:06:41 +07:00
|
|
|
pr_err("%s: Can't request OPAL event irq (%d)\n",
|
2013-11-18 17:05:58 +07:00
|
|
|
__func__, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
2015-05-15 11:06:41 +07:00
|
|
|
|
2013-11-18 17:05:58 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-09-20 00:44:57 +07:00
|
|
|
int opal_get_chars(uint32_t vtermno, char *buf, int count)
|
|
|
|
{
|
2013-09-23 09:05:02 +07:00
|
|
|
s64 rc;
|
|
|
|
__be64 evt, len;
|
2011-09-20 00:44:57 +07:00
|
|
|
|
|
|
|
if (!opal.entry)
|
2011-09-20 00:44:59 +07:00
|
|
|
return -ENODEV;
|
2011-09-20 00:44:57 +07:00
|
|
|
opal_poll_events(&evt);
|
2013-09-23 09:05:02 +07:00
|
|
|
if ((be64_to_cpu(evt) & OPAL_EVENT_CONSOLE_INPUT) == 0)
|
2011-09-20 00:44:57 +07:00
|
|
|
return 0;
|
2013-09-23 09:05:02 +07:00
|
|
|
len = cpu_to_be64(count);
|
2014-04-02 11:49:03 +07:00
|
|
|
rc = opal_console_read(vtermno, &len, buf);
|
2011-09-20 00:44:57 +07:00
|
|
|
if (rc == OPAL_SUCCESS)
|
2013-09-23 09:05:02 +07:00
|
|
|
return be64_to_cpu(len);
|
2011-09-20 00:44:57 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-04-30 21:55:51 +07:00
|
|
|
static int __opal_put_chars(uint32_t vtermno, const char *data, int total_len, bool atomic)
|
2011-09-20 00:44:57 +07:00
|
|
|
{
|
2018-04-30 21:55:51 +07:00
|
|
|
unsigned long flags = 0 /* shut up gcc */;
|
2018-04-30 21:55:49 +07:00
|
|
|
int written;
|
|
|
|
__be64 olen;
|
|
|
|
s64 rc;
|
2011-09-20 00:44:57 +07:00
|
|
|
|
|
|
|
if (!opal.entry)
|
2011-09-20 00:44:59 +07:00
|
|
|
return -ENODEV;
|
2011-09-20 00:44:57 +07:00
|
|
|
|
2018-04-30 21:55:51 +07:00
|
|
|
if (atomic)
|
|
|
|
spin_lock_irqsave(&opal_write_lock, flags);
|
2015-12-09 13:18:20 +07:00
|
|
|
rc = opal_console_write_buffer_space(vtermno, &olen);
|
2018-04-30 21:55:49 +07:00
|
|
|
if (rc || be64_to_cpu(olen) < total_len) {
|
2015-12-09 13:18:20 +07:00
|
|
|
/* Closed -> drop characters */
|
|
|
|
if (rc)
|
2018-04-30 21:55:49 +07:00
|
|
|
written = total_len;
|
|
|
|
else
|
|
|
|
written = -EAGAIN;
|
|
|
|
goto out;
|
2011-09-20 00:44:57 +07:00
|
|
|
}
|
|
|
|
|
2018-04-30 21:55:49 +07:00
|
|
|
/* Should not get a partial write here because space is available. */
|
|
|
|
olen = cpu_to_be64(total_len);
|
|
|
|
rc = opal_console_write(vtermno, &olen, data);
|
|
|
|
if (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) {
|
2018-04-30 21:55:58 +07:00
|
|
|
if (rc == OPAL_BUSY_EVENT)
|
2018-04-30 21:55:49 +07:00
|
|
|
opal_poll_events(NULL);
|
|
|
|
written = -EAGAIN;
|
|
|
|
goto out;
|
|
|
|
}
|
2018-04-30 21:55:45 +07:00
|
|
|
|
2018-04-30 21:55:49 +07:00
|
|
|
/* Closed or other error drop */
|
|
|
|
if (rc != OPAL_SUCCESS) {
|
|
|
|
written = opal_error_code(rc);
|
|
|
|
goto out;
|
|
|
|
}
|
2018-04-30 21:55:45 +07:00
|
|
|
|
2018-04-30 21:55:49 +07:00
|
|
|
written = be64_to_cpu(olen);
|
|
|
|
if (written < total_len) {
|
2018-04-30 21:55:51 +07:00
|
|
|
if (atomic) {
|
|
|
|
/* Should not happen */
|
|
|
|
pr_warn("atomic console write returned partial "
|
|
|
|
"len=%d written=%d\n", total_len, written);
|
|
|
|
}
|
2018-04-30 21:55:49 +07:00
|
|
|
if (!written)
|
|
|
|
written = -EAGAIN;
|
2018-04-30 21:55:48 +07:00
|
|
|
}
|
2018-04-30 21:55:49 +07:00
|
|
|
|
|
|
|
out:
|
2018-04-30 21:55:51 +07:00
|
|
|
if (atomic)
|
|
|
|
spin_unlock_irqrestore(&opal_write_lock, flags);
|
2018-04-30 21:55:48 +07:00
|
|
|
|
|
|
|
return written;
|
|
|
|
}
|
|
|
|
|
2018-04-30 21:55:51 +07:00
|
|
|
int opal_put_chars(uint32_t vtermno, const char *data, int total_len)
|
|
|
|
{
|
|
|
|
return __opal_put_chars(vtermno, data, total_len, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* opal_put_chars_atomic will not perform partial-writes. Data will be
|
|
|
|
* atomically written to the terminal or not at all. This is not strictly
|
|
|
|
* true at the moment because console space can race with OPAL's console
|
|
|
|
* writes.
|
|
|
|
*/
|
|
|
|
int opal_put_chars_atomic(uint32_t vtermno, const char *data, int total_len)
|
|
|
|
{
|
|
|
|
return __opal_put_chars(vtermno, data, total_len, true);
|
|
|
|
}
|
|
|
|
|
2018-04-30 21:55:58 +07:00
|
|
|
static s64 __opal_flush_console(uint32_t vtermno)
|
2018-04-30 21:55:48 +07:00
|
|
|
{
|
|
|
|
s64 rc;
|
|
|
|
|
|
|
|
if (!opal_check_token(OPAL_CONSOLE_FLUSH)) {
|
|
|
|
__be64 evt;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If OPAL_CONSOLE_FLUSH is not implemented in the firmware,
|
|
|
|
* the console can still be flushed by calling the polling
|
|
|
|
* function while it has OPAL_EVENT_CONSOLE_OUTPUT events.
|
|
|
|
*/
|
2018-04-30 21:55:58 +07:00
|
|
|
WARN_ONCE(1, "opal: OPAL_CONSOLE_FLUSH missing.\n");
|
|
|
|
|
|
|
|
opal_poll_events(&evt);
|
|
|
|
if (!(be64_to_cpu(evt) & OPAL_EVENT_CONSOLE_OUTPUT))
|
|
|
|
return OPAL_SUCCESS;
|
|
|
|
return OPAL_BUSY;
|
2018-04-30 21:55:48 +07:00
|
|
|
|
2018-04-30 21:55:58 +07:00
|
|
|
} else {
|
|
|
|
rc = opal_console_flush(vtermno);
|
|
|
|
if (rc == OPAL_BUSY_EVENT) {
|
|
|
|
opal_poll_events(NULL);
|
|
|
|
rc = OPAL_BUSY;
|
|
|
|
}
|
|
|
|
return rc;
|
2011-09-20 00:44:57 +07:00
|
|
|
}
|
2018-04-30 21:55:48 +07:00
|
|
|
|
2018-04-30 21:55:58 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* opal_flush_console spins until the console is flushed
|
|
|
|
*/
|
|
|
|
int opal_flush_console(uint32_t vtermno)
|
|
|
|
{
|
|
|
|
for (;;) {
|
|
|
|
s64 rc = __opal_flush_console(vtermno);
|
|
|
|
|
|
|
|
if (rc == OPAL_BUSY || rc == OPAL_PARTIAL) {
|
|
|
|
mdelay(1);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
return opal_error_code(rc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* opal_flush_chars is an hvc interface that sleeps until the console is
|
|
|
|
* flushed if wait, otherwise it will return -EBUSY if the console has data,
|
|
|
|
* -EAGAIN if it has data and some of it was flushed.
|
|
|
|
*/
|
|
|
|
int opal_flush_chars(uint32_t vtermno, bool wait)
|
|
|
|
{
|
|
|
|
for (;;) {
|
|
|
|
s64 rc = __opal_flush_console(vtermno);
|
|
|
|
|
|
|
|
if (rc == OPAL_BUSY || rc == OPAL_PARTIAL) {
|
|
|
|
if (wait) {
|
|
|
|
msleep(OPAL_BUSY_DELAY_MS);
|
|
|
|
continue;
|
2018-04-30 21:55:48 +07:00
|
|
|
}
|
2018-04-30 21:55:58 +07:00
|
|
|
if (rc == OPAL_PARTIAL)
|
|
|
|
return -EAGAIN;
|
2018-04-30 21:55:48 +07:00
|
|
|
}
|
|
|
|
|
2018-04-30 21:55:58 +07:00
|
|
|
return opal_error_code(rc);
|
|
|
|
}
|
2011-09-20 00:44:57 +07:00
|
|
|
}
|
|
|
|
|
2013-10-30 21:36:13 +07:00
|
|
|
static int opal_recover_mce(struct pt_regs *regs,
|
|
|
|
struct machine_check_event *evt)
|
|
|
|
{
|
|
|
|
int recovered = 0;
|
|
|
|
|
|
|
|
if (!(regs->msr & MSR_RI)) {
|
|
|
|
/* If MSR_RI isn't set, we cannot recover */
|
2016-08-09 12:09:13 +07:00
|
|
|
pr_err("Machine check interrupt unrecoverable: MSR(RI=0)\n");
|
2013-10-30 21:36:13 +07:00
|
|
|
recovered = 0;
|
|
|
|
} else if (evt->disposition == MCE_DISPOSITION_RECOVERED) {
|
|
|
|
/* Platform corrected itself */
|
|
|
|
recovered = 1;
|
2017-02-28 09:00:46 +07:00
|
|
|
} else if (evt->severity == MCE_SEV_FATAL) {
|
|
|
|
/* Fatal machine check */
|
|
|
|
pr_err("Machine check interrupt is fatal\n");
|
|
|
|
recovered = 0;
|
powerpc/powernv: Use kernel crash path for machine checks
There are quite a few machine check exceptions that can be caused by
kernel bugs. To make debugging easier, use the kernel crash path in
cases of synchronous machine checks that occur in kernel mode, if that
would not result in the machine going straight to panic or crash dump.
There is a downside here that die()ing the process in kernel mode can
still leave the system unstable. panic_on_oops will always force the
system to fail-stop, so systems where that behaviour is important will
still do the right thing.
As a test, when triggering an i-side 0111b error (ifetch from foreign
address) in kernel mode process context on POWER9, the kernel currently
dies quickly like this:
Severe Machine check interrupt [Not recovered]
NIP [ffff000000000000]: 0xffff000000000000
Initiator: CPU
Error type: Real address [Instruction fetch (foreign)]
[ 127.426651616,0] OPAL: Reboot requested due to Platform error.
Effective[ 127.426693712,3] OPAL: Reboot requested due to Platform error. address: ffff000000000000
opal: Reboot type 1 not supported
Kernel panic - not syncing: PowerNV Unrecovered Machine Check
CPU: 56 PID: 4425 Comm: syscall Tainted: G M 4.12.0-rc1-13857-ga4700a261072-dirty #35
Call Trace:
[ 128.017988928,4] IPMI: BUG: Dropping ESEL on the floor due to
buggy/mising code in OPAL for this BMC
Rebooting in 10 seconds..
Trying to free IRQ 496 from IRQ context!
After this patch, the process is killed and the kernel continues with
this message, which gives enough information to identify the offending
branch (i.e., with CFAR):
Severe Machine check interrupt [Not recovered]
NIP [ffff000000000000]: 0xffff000000000000
Initiator: CPU
Error type: Real address [Instruction fetch (foreign)]
Effective address: ffff000000000000
Oops: Machine check, sig: 7 [#1]
SMP NR_CPUS=2048
NUMA
PowerNV
Modules linked in: iptable_mangle ipt_MASQUERADE nf_nat_masquerade_ipv4 ...
CPU: 22 PID: 4436 Comm: syscall Tainted: G M 4.12.0-rc1-13857-ga4700a261072-dirty #36
task: c000000932300000 task.stack: c000000932380000
NIP: ffff000000000000 LR: 00000000217706a4 CTR: ffff000000000000
REGS: c00000000fc8fd80 TRAP: 0200 Tainted: G M (4.12.0-rc1-13857-ga4700a261072-dirty)
MSR: 90000000001c1003 <SF,HV,ME,RI,LE>
CR: 24000484 XER: 20000000
CFAR: c000000000004c80 DAR: 0000000021770a90 DSISR: 0a000000 SOFTE: 1
GPR00: 0000000000001ebe 00007fffce4818b0 0000000021797f00 0000000000000000
GPR04: 00007fff8007ac24 0000000044000484 0000000000004000 00007fff801405e8
GPR08: 900000000280f033 0000000024000484 0000000000000000 0000000000000030
GPR12: 9000000000001003 00007fff801bc370 0000000000000000 0000000000000000
GPR16: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
GPR20: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
GPR24: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
GPR28: 00007fff801b0000 0000000000000000 00000000217707a0 00007fffce481918
NIP [ffff000000000000] 0xffff000000000000
LR [00000000217706a4] 0x217706a4
Call Trace:
Instruction dump:
XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Reviewed-by: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2017-07-19 13:59:11 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!recovered && evt->severity == MCE_SEV_ERROR_SYNC) {
|
2013-10-30 21:36:13 +07:00
|
|
|
/*
|
powerpc/powernv: Use kernel crash path for machine checks
There are quite a few machine check exceptions that can be caused by
kernel bugs. To make debugging easier, use the kernel crash path in
cases of synchronous machine checks that occur in kernel mode, if that
would not result in the machine going straight to panic or crash dump.
There is a downside here that die()ing the process in kernel mode can
still leave the system unstable. panic_on_oops will always force the
system to fail-stop, so systems where that behaviour is important will
still do the right thing.
As a test, when triggering an i-side 0111b error (ifetch from foreign
address) in kernel mode process context on POWER9, the kernel currently
dies quickly like this:
Severe Machine check interrupt [Not recovered]
NIP [ffff000000000000]: 0xffff000000000000
Initiator: CPU
Error type: Real address [Instruction fetch (foreign)]
[ 127.426651616,0] OPAL: Reboot requested due to Platform error.
Effective[ 127.426693712,3] OPAL: Reboot requested due to Platform error. address: ffff000000000000
opal: Reboot type 1 not supported
Kernel panic - not syncing: PowerNV Unrecovered Machine Check
CPU: 56 PID: 4425 Comm: syscall Tainted: G M 4.12.0-rc1-13857-ga4700a261072-dirty #35
Call Trace:
[ 128.017988928,4] IPMI: BUG: Dropping ESEL on the floor due to
buggy/mising code in OPAL for this BMC
Rebooting in 10 seconds..
Trying to free IRQ 496 from IRQ context!
After this patch, the process is killed and the kernel continues with
this message, which gives enough information to identify the offending
branch (i.e., with CFAR):
Severe Machine check interrupt [Not recovered]
NIP [ffff000000000000]: 0xffff000000000000
Initiator: CPU
Error type: Real address [Instruction fetch (foreign)]
Effective address: ffff000000000000
Oops: Machine check, sig: 7 [#1]
SMP NR_CPUS=2048
NUMA
PowerNV
Modules linked in: iptable_mangle ipt_MASQUERADE nf_nat_masquerade_ipv4 ...
CPU: 22 PID: 4436 Comm: syscall Tainted: G M 4.12.0-rc1-13857-ga4700a261072-dirty #36
task: c000000932300000 task.stack: c000000932380000
NIP: ffff000000000000 LR: 00000000217706a4 CTR: ffff000000000000
REGS: c00000000fc8fd80 TRAP: 0200 Tainted: G M (4.12.0-rc1-13857-ga4700a261072-dirty)
MSR: 90000000001c1003 <SF,HV,ME,RI,LE>
CR: 24000484 XER: 20000000
CFAR: c000000000004c80 DAR: 0000000021770a90 DSISR: 0a000000 SOFTE: 1
GPR00: 0000000000001ebe 00007fffce4818b0 0000000021797f00 0000000000000000
GPR04: 00007fff8007ac24 0000000044000484 0000000000004000 00007fff801405e8
GPR08: 900000000280f033 0000000024000484 0000000000000000 0000000000000030
GPR12: 9000000000001003 00007fff801bc370 0000000000000000 0000000000000000
GPR16: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
GPR20: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
GPR24: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
GPR28: 00007fff801b0000 0000000000000000 00000000217707a0 00007fffce481918
NIP [ffff000000000000] 0xffff000000000000
LR [00000000217706a4] 0x217706a4
Call Trace:
Instruction dump:
XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Reviewed-by: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2017-07-19 13:59:11 +07:00
|
|
|
* Try to kill processes if we get a synchronous machine check
|
|
|
|
* (e.g., one caused by execution of this instruction). This
|
|
|
|
* will devolve into a panic if we try to kill init or are in
|
|
|
|
* an interrupt etc.
|
2013-10-30 21:36:13 +07:00
|
|
|
*
|
|
|
|
* TODO: Queue up this address for hwpoisioning later.
|
powerpc/powernv: Use kernel crash path for machine checks
There are quite a few machine check exceptions that can be caused by
kernel bugs. To make debugging easier, use the kernel crash path in
cases of synchronous machine checks that occur in kernel mode, if that
would not result in the machine going straight to panic or crash dump.
There is a downside here that die()ing the process in kernel mode can
still leave the system unstable. panic_on_oops will always force the
system to fail-stop, so systems where that behaviour is important will
still do the right thing.
As a test, when triggering an i-side 0111b error (ifetch from foreign
address) in kernel mode process context on POWER9, the kernel currently
dies quickly like this:
Severe Machine check interrupt [Not recovered]
NIP [ffff000000000000]: 0xffff000000000000
Initiator: CPU
Error type: Real address [Instruction fetch (foreign)]
[ 127.426651616,0] OPAL: Reboot requested due to Platform error.
Effective[ 127.426693712,3] OPAL: Reboot requested due to Platform error. address: ffff000000000000
opal: Reboot type 1 not supported
Kernel panic - not syncing: PowerNV Unrecovered Machine Check
CPU: 56 PID: 4425 Comm: syscall Tainted: G M 4.12.0-rc1-13857-ga4700a261072-dirty #35
Call Trace:
[ 128.017988928,4] IPMI: BUG: Dropping ESEL on the floor due to
buggy/mising code in OPAL for this BMC
Rebooting in 10 seconds..
Trying to free IRQ 496 from IRQ context!
After this patch, the process is killed and the kernel continues with
this message, which gives enough information to identify the offending
branch (i.e., with CFAR):
Severe Machine check interrupt [Not recovered]
NIP [ffff000000000000]: 0xffff000000000000
Initiator: CPU
Error type: Real address [Instruction fetch (foreign)]
Effective address: ffff000000000000
Oops: Machine check, sig: 7 [#1]
SMP NR_CPUS=2048
NUMA
PowerNV
Modules linked in: iptable_mangle ipt_MASQUERADE nf_nat_masquerade_ipv4 ...
CPU: 22 PID: 4436 Comm: syscall Tainted: G M 4.12.0-rc1-13857-ga4700a261072-dirty #36
task: c000000932300000 task.stack: c000000932380000
NIP: ffff000000000000 LR: 00000000217706a4 CTR: ffff000000000000
REGS: c00000000fc8fd80 TRAP: 0200 Tainted: G M (4.12.0-rc1-13857-ga4700a261072-dirty)
MSR: 90000000001c1003 <SF,HV,ME,RI,LE>
CR: 24000484 XER: 20000000
CFAR: c000000000004c80 DAR: 0000000021770a90 DSISR: 0a000000 SOFTE: 1
GPR00: 0000000000001ebe 00007fffce4818b0 0000000021797f00 0000000000000000
GPR04: 00007fff8007ac24 0000000044000484 0000000000004000 00007fff801405e8
GPR08: 900000000280f033 0000000024000484 0000000000000000 0000000000000030
GPR12: 9000000000001003 00007fff801bc370 0000000000000000 0000000000000000
GPR16: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
GPR20: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
GPR24: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
GPR28: 00007fff801b0000 0000000000000000 00000000217707a0 00007fffce481918
NIP [ffff000000000000] 0xffff000000000000
LR [00000000217706a4] 0x217706a4
Call Trace:
Instruction dump:
XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Reviewed-by: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2017-07-19 13:59:11 +07:00
|
|
|
* TODO: This is not quite right for d-side machine
|
|
|
|
* checks ->nip is not necessarily the important
|
|
|
|
* address.
|
2013-10-30 21:36:13 +07:00
|
|
|
*/
|
powerpc/powernv: Use kernel crash path for machine checks
There are quite a few machine check exceptions that can be caused by
kernel bugs. To make debugging easier, use the kernel crash path in
cases of synchronous machine checks that occur in kernel mode, if that
would not result in the machine going straight to panic or crash dump.
There is a downside here that die()ing the process in kernel mode can
still leave the system unstable. panic_on_oops will always force the
system to fail-stop, so systems where that behaviour is important will
still do the right thing.
As a test, when triggering an i-side 0111b error (ifetch from foreign
address) in kernel mode process context on POWER9, the kernel currently
dies quickly like this:
Severe Machine check interrupt [Not recovered]
NIP [ffff000000000000]: 0xffff000000000000
Initiator: CPU
Error type: Real address [Instruction fetch (foreign)]
[ 127.426651616,0] OPAL: Reboot requested due to Platform error.
Effective[ 127.426693712,3] OPAL: Reboot requested due to Platform error. address: ffff000000000000
opal: Reboot type 1 not supported
Kernel panic - not syncing: PowerNV Unrecovered Machine Check
CPU: 56 PID: 4425 Comm: syscall Tainted: G M 4.12.0-rc1-13857-ga4700a261072-dirty #35
Call Trace:
[ 128.017988928,4] IPMI: BUG: Dropping ESEL on the floor due to
buggy/mising code in OPAL for this BMC
Rebooting in 10 seconds..
Trying to free IRQ 496 from IRQ context!
After this patch, the process is killed and the kernel continues with
this message, which gives enough information to identify the offending
branch (i.e., with CFAR):
Severe Machine check interrupt [Not recovered]
NIP [ffff000000000000]: 0xffff000000000000
Initiator: CPU
Error type: Real address [Instruction fetch (foreign)]
Effective address: ffff000000000000
Oops: Machine check, sig: 7 [#1]
SMP NR_CPUS=2048
NUMA
PowerNV
Modules linked in: iptable_mangle ipt_MASQUERADE nf_nat_masquerade_ipv4 ...
CPU: 22 PID: 4436 Comm: syscall Tainted: G M 4.12.0-rc1-13857-ga4700a261072-dirty #36
task: c000000932300000 task.stack: c000000932380000
NIP: ffff000000000000 LR: 00000000217706a4 CTR: ffff000000000000
REGS: c00000000fc8fd80 TRAP: 0200 Tainted: G M (4.12.0-rc1-13857-ga4700a261072-dirty)
MSR: 90000000001c1003 <SF,HV,ME,RI,LE>
CR: 24000484 XER: 20000000
CFAR: c000000000004c80 DAR: 0000000021770a90 DSISR: 0a000000 SOFTE: 1
GPR00: 0000000000001ebe 00007fffce4818b0 0000000021797f00 0000000000000000
GPR04: 00007fff8007ac24 0000000044000484 0000000000004000 00007fff801405e8
GPR08: 900000000280f033 0000000024000484 0000000000000000 0000000000000030
GPR12: 9000000000001003 00007fff801bc370 0000000000000000 0000000000000000
GPR16: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
GPR20: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
GPR24: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
GPR28: 00007fff801b0000 0000000000000000 00000000217707a0 00007fffce481918
NIP [ffff000000000000] 0xffff000000000000
LR [00000000217706a4] 0x217706a4
Call Trace:
Instruction dump:
XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Reviewed-by: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2017-07-19 13:59:11 +07:00
|
|
|
if ((user_mode(regs))) {
|
|
|
|
_exception(SIGBUS, regs, BUS_MCEERR_AR, regs->nip);
|
|
|
|
recovered = 1;
|
|
|
|
} else if (die_will_crash()) {
|
|
|
|
/*
|
|
|
|
* die() would kill the kernel, so better to go via
|
|
|
|
* the platform reboot code that will log the
|
|
|
|
* machine check.
|
|
|
|
*/
|
|
|
|
recovered = 0;
|
|
|
|
} else {
|
|
|
|
die("Machine check", regs, SIGBUS);
|
|
|
|
recovered = 1;
|
|
|
|
}
|
2013-10-30 21:36:13 +07:00
|
|
|
}
|
powerpc/powernv: Use kernel crash path for machine checks
There are quite a few machine check exceptions that can be caused by
kernel bugs. To make debugging easier, use the kernel crash path in
cases of synchronous machine checks that occur in kernel mode, if that
would not result in the machine going straight to panic or crash dump.
There is a downside here that die()ing the process in kernel mode can
still leave the system unstable. panic_on_oops will always force the
system to fail-stop, so systems where that behaviour is important will
still do the right thing.
As a test, when triggering an i-side 0111b error (ifetch from foreign
address) in kernel mode process context on POWER9, the kernel currently
dies quickly like this:
Severe Machine check interrupt [Not recovered]
NIP [ffff000000000000]: 0xffff000000000000
Initiator: CPU
Error type: Real address [Instruction fetch (foreign)]
[ 127.426651616,0] OPAL: Reboot requested due to Platform error.
Effective[ 127.426693712,3] OPAL: Reboot requested due to Platform error. address: ffff000000000000
opal: Reboot type 1 not supported
Kernel panic - not syncing: PowerNV Unrecovered Machine Check
CPU: 56 PID: 4425 Comm: syscall Tainted: G M 4.12.0-rc1-13857-ga4700a261072-dirty #35
Call Trace:
[ 128.017988928,4] IPMI: BUG: Dropping ESEL on the floor due to
buggy/mising code in OPAL for this BMC
Rebooting in 10 seconds..
Trying to free IRQ 496 from IRQ context!
After this patch, the process is killed and the kernel continues with
this message, which gives enough information to identify the offending
branch (i.e., with CFAR):
Severe Machine check interrupt [Not recovered]
NIP [ffff000000000000]: 0xffff000000000000
Initiator: CPU
Error type: Real address [Instruction fetch (foreign)]
Effective address: ffff000000000000
Oops: Machine check, sig: 7 [#1]
SMP NR_CPUS=2048
NUMA
PowerNV
Modules linked in: iptable_mangle ipt_MASQUERADE nf_nat_masquerade_ipv4 ...
CPU: 22 PID: 4436 Comm: syscall Tainted: G M 4.12.0-rc1-13857-ga4700a261072-dirty #36
task: c000000932300000 task.stack: c000000932380000
NIP: ffff000000000000 LR: 00000000217706a4 CTR: ffff000000000000
REGS: c00000000fc8fd80 TRAP: 0200 Tainted: G M (4.12.0-rc1-13857-ga4700a261072-dirty)
MSR: 90000000001c1003 <SF,HV,ME,RI,LE>
CR: 24000484 XER: 20000000
CFAR: c000000000004c80 DAR: 0000000021770a90 DSISR: 0a000000 SOFTE: 1
GPR00: 0000000000001ebe 00007fffce4818b0 0000000021797f00 0000000000000000
GPR04: 00007fff8007ac24 0000000044000484 0000000000004000 00007fff801405e8
GPR08: 900000000280f033 0000000024000484 0000000000000000 0000000000000030
GPR12: 9000000000001003 00007fff801bc370 0000000000000000 0000000000000000
GPR16: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
GPR20: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
GPR24: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
GPR28: 00007fff801b0000 0000000000000000 00000000217707a0 00007fffce481918
NIP [ffff000000000000] 0xffff000000000000
LR [00000000217706a4] 0x217706a4
Call Trace:
Instruction dump:
XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Reviewed-by: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2017-07-19 13:59:11 +07:00
|
|
|
|
2013-10-30 21:36:13 +07:00
|
|
|
return recovered;
|
|
|
|
}
|
|
|
|
|
2018-09-25 21:29:33 +07:00
|
|
|
void __noreturn pnv_platform_error_reboot(struct pt_regs *regs, const char *msg)
|
2017-07-19 13:59:10 +07:00
|
|
|
{
|
powerpc/pseries, ps3: panic flush kernel messages before halting system
Platforms with a panic handler that halts the system can have problems
getting kernel messages out, because the panic notifiers are called
before kernel/panic.c does its flushing of printk buffers an console
etc.
This was attempted to be solved with commit a3b2cb30f252 ("powerpc: Do
not call ppc_md.panic in fadump panic notifier"), but that wasn't the
right approach and caused other problems, and was reverted by commit
ab9dbf771ff9.
Instead, the powernv shutdown paths have already had a similar
problem, fixed by taking the message flushing sequence from
kernel/panic.c. That's a little bit ugly, but while we have the code
duplicated, it will work for this case as well. So have ppc panic
handlers do the same flushing before they terminate.
Without this patch, a qemu pseries_le_defconfig guest stops silently
when issued the nmi command when xmon is off and no crash dumpers
enabled. Afterwards, an oops is printed by each CPU as expected.
Fixes: ab9dbf771ff9 ("Revert "powerpc: Do not call ppc_md.panic in fadump panic notifier"")
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2017-12-23 23:49:23 +07:00
|
|
|
panic_flush_kmsg_start();
|
|
|
|
|
2017-07-19 13:59:10 +07:00
|
|
|
pr_emerg("Hardware platform error: %s\n", msg);
|
|
|
|
if (regs)
|
|
|
|
show_regs(regs);
|
|
|
|
smp_send_stop();
|
powerpc/pseries, ps3: panic flush kernel messages before halting system
Platforms with a panic handler that halts the system can have problems
getting kernel messages out, because the panic notifiers are called
before kernel/panic.c does its flushing of printk buffers an console
etc.
This was attempted to be solved with commit a3b2cb30f252 ("powerpc: Do
not call ppc_md.panic in fadump panic notifier"), but that wasn't the
right approach and caused other problems, and was reverted by commit
ab9dbf771ff9.
Instead, the powernv shutdown paths have already had a similar
problem, fixed by taking the message flushing sequence from
kernel/panic.c. That's a little bit ugly, but while we have the code
duplicated, it will work for this case as well. So have ppc panic
handlers do the same flushing before they terminate.
Without this patch, a qemu pseries_le_defconfig guest stops silently
when issued the nmi command when xmon is off and no crash dumpers
enabled. Afterwards, an oops is printed by each CPU as expected.
Fixes: ab9dbf771ff9 ("Revert "powerpc: Do not call ppc_md.panic in fadump panic notifier"")
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2017-12-23 23:49:23 +07:00
|
|
|
|
|
|
|
panic_flush_kmsg_end();
|
2017-07-19 13:59:10 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Don't bother to shut things down because this will
|
|
|
|
* xstop the system.
|
|
|
|
*/
|
|
|
|
if (opal_cec_reboot2(OPAL_REBOOT_PLATFORM_ERROR, msg)
|
|
|
|
== OPAL_UNSUPPORTED) {
|
|
|
|
pr_emerg("Reboot type %d not supported for %s\n",
|
|
|
|
OPAL_REBOOT_PLATFORM_ERROR, msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We reached here. There can be three possibilities:
|
|
|
|
* 1. We are running on a firmware level that do not support
|
|
|
|
* opal_cec_reboot2()
|
|
|
|
* 2. We are running on a firmware level that do not support
|
|
|
|
* OPAL_REBOOT_PLATFORM_ERROR reboot type.
|
|
|
|
* 3. We are running on FSP based system that does not need
|
|
|
|
* opal to trigger checkstop explicitly for error analysis.
|
|
|
|
* The FSP PRD component would have already got notified
|
|
|
|
* about this error through other channels.
|
2018-03-08 07:36:06 +07:00
|
|
|
* 4. We are running on a newer skiboot that by default does
|
|
|
|
* not cause a checkstop, drops us back to the kernel to
|
|
|
|
* extract context and state at the time of the error.
|
2017-07-19 13:59:10 +07:00
|
|
|
*/
|
|
|
|
|
2018-03-08 07:36:06 +07:00
|
|
|
panic(msg);
|
2017-07-19 13:59:10 +07:00
|
|
|
}
|
|
|
|
|
2011-09-20 00:45:04 +07:00
|
|
|
int opal_machine_check(struct pt_regs *regs)
|
|
|
|
{
|
2013-10-30 21:35:40 +07:00
|
|
|
struct machine_check_event evt;
|
2011-09-20 00:45:04 +07:00
|
|
|
|
2013-10-30 21:35:40 +07:00
|
|
|
if (!get_mce_event(&evt, MCE_EVENT_RELEASE))
|
|
|
|
return 0;
|
2011-09-20 00:45:04 +07:00
|
|
|
|
|
|
|
/* Print things out */
|
2013-10-30 21:35:40 +07:00
|
|
|
if (evt.version != MCE_V1) {
|
2011-09-20 00:45:04 +07:00
|
|
|
pr_err("Machine Check Exception, Unknown event version %d !\n",
|
|
|
|
evt.version);
|
|
|
|
return 0;
|
|
|
|
}
|
2017-04-03 12:29:34 +07:00
|
|
|
machine_check_print_event_info(&evt, user_mode(regs));
|
2011-09-20 00:45:04 +07:00
|
|
|
|
2013-10-30 21:36:13 +07:00
|
|
|
if (opal_recover_mce(regs, &evt))
|
|
|
|
return 1;
|
2015-07-31 22:54:38 +07:00
|
|
|
|
2017-07-19 13:59:10 +07:00
|
|
|
pnv_platform_error_reboot(regs, "Unrecoverable Machine Check exception");
|
2011-09-20 00:45:04 +07:00
|
|
|
}
|
|
|
|
|
2014-07-29 20:10:01 +07:00
|
|
|
/* Early hmi handler called in real mode. */
|
|
|
|
int opal_hmi_exception_early(struct pt_regs *regs)
|
|
|
|
{
|
2014-07-29 20:10:07 +07:00
|
|
|
s64 rc;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call opal hmi handler. Pass paca address as token.
|
|
|
|
* The return value OPAL_SUCCESS is an indication that there is
|
|
|
|
* an HMI event generated waiting to pull by Linux.
|
|
|
|
*/
|
|
|
|
rc = opal_handle_hmi();
|
|
|
|
if (rc == OPAL_SUCCESS) {
|
|
|
|
local_paca->hmi_event_available = 1;
|
|
|
|
return 1;
|
|
|
|
}
|
2014-07-29 20:10:01 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* HMI exception handler called in virtual mode during check_irq_replay. */
|
|
|
|
int opal_handle_hmi_exception(struct pt_regs *regs)
|
|
|
|
{
|
2014-07-29 20:10:07 +07:00
|
|
|
/*
|
|
|
|
* Check if HMI event is available.
|
2018-05-11 00:20:05 +07:00
|
|
|
* if Yes, then wake kopald to process them.
|
2014-07-29 20:10:07 +07:00
|
|
|
*/
|
|
|
|
if (!local_paca->hmi_event_available)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
local_paca->hmi_event_available = 0;
|
2018-05-11 00:20:05 +07:00
|
|
|
opal_wake_poller();
|
2014-07-29 20:10:07 +07:00
|
|
|
|
|
|
|
return 1;
|
2014-07-29 20:10:01 +07:00
|
|
|
}
|
|
|
|
|
2013-12-16 12:16:24 +07:00
|
|
|
static uint64_t find_recovery_address(uint64_t nip)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < mc_recoverable_range_len; i++)
|
|
|
|
if ((nip >= mc_recoverable_range[i].start_addr) &&
|
|
|
|
(nip < mc_recoverable_range[i].end_addr))
|
|
|
|
return mc_recoverable_range[i].recover_addr;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool opal_mce_check_early_recovery(struct pt_regs *regs)
|
|
|
|
{
|
|
|
|
uint64_t recover_addr = 0;
|
|
|
|
|
|
|
|
if (!opal.base || !opal.size)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if ((regs->nip >= opal.base) &&
|
2015-12-21 14:28:37 +07:00
|
|
|
(regs->nip < (opal.base + opal.size)))
|
2013-12-16 12:16:24 +07:00
|
|
|
recover_addr = find_recovery_address(regs->nip);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Setup regs->nip to rfi into fixup address.
|
|
|
|
*/
|
|
|
|
if (recover_addr)
|
|
|
|
regs->nip = recover_addr;
|
|
|
|
|
|
|
|
out:
|
|
|
|
return !!recover_addr;
|
|
|
|
}
|
|
|
|
|
2013-08-27 16:39:52 +07:00
|
|
|
static int opal_sysfs_init(void)
|
|
|
|
{
|
|
|
|
opal_kobj = kobject_create_and_add("opal", firmware_kobj);
|
|
|
|
if (!opal_kobj) {
|
|
|
|
pr_warn("kobject_create_and_add opal failed\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-12-11 08:39:49 +07:00
|
|
|
static ssize_t symbol_map_read(struct file *fp, struct kobject *kobj,
|
|
|
|
struct bin_attribute *bin_attr,
|
|
|
|
char *buf, loff_t off, size_t count)
|
|
|
|
{
|
|
|
|
return memory_read_from_buffer(buf, count, &off, bin_attr->private,
|
|
|
|
bin_attr->size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static BIN_ATTR_RO(symbol_map, 0);
|
|
|
|
|
|
|
|
static void opal_export_symmap(void)
|
|
|
|
{
|
|
|
|
const __be64 *syms;
|
|
|
|
unsigned int size;
|
|
|
|
struct device_node *fw;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
fw = of_find_node_by_path("/ibm,opal/firmware");
|
|
|
|
if (!fw)
|
|
|
|
return;
|
|
|
|
syms = of_get_property(fw, "symbol-map", &size);
|
|
|
|
if (!syms || size != 2 * sizeof(__be64))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Setup attributes */
|
|
|
|
bin_attr_symbol_map.private = __va(be64_to_cpu(syms[0]));
|
|
|
|
bin_attr_symbol_map.size = be64_to_cpu(syms[1]);
|
|
|
|
|
|
|
|
rc = sysfs_create_bin_file(opal_kobj, &bin_attr_symbol_map);
|
|
|
|
if (rc)
|
|
|
|
pr_warn("Error %d creating OPAL symbols file\n", rc);
|
|
|
|
}
|
|
|
|
|
2017-03-30 06:28:01 +07:00
|
|
|
static ssize_t export_attr_read(struct file *fp, struct kobject *kobj,
|
|
|
|
struct bin_attribute *bin_attr, char *buf,
|
|
|
|
loff_t off, size_t count)
|
|
|
|
{
|
|
|
|
return memory_read_from_buffer(buf, count, &off, bin_attr->private,
|
|
|
|
bin_attr->size);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* opal_export_attrs: creates a sysfs node for each property listed in
|
|
|
|
* the device-tree under /ibm,opal/firmware/exports/
|
|
|
|
* All new sysfs nodes are created under /opal/exports/.
|
|
|
|
* This allows for reserved memory regions (e.g. HDAT) to be read.
|
|
|
|
* The new sysfs nodes are only readable by root.
|
|
|
|
*/
|
|
|
|
static void opal_export_attrs(void)
|
|
|
|
{
|
|
|
|
struct bin_attribute *attr;
|
|
|
|
struct device_node *np;
|
|
|
|
struct property *prop;
|
|
|
|
struct kobject *kobj;
|
|
|
|
u64 vals[2];
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
np = of_find_node_by_path("/ibm,opal/firmware/exports");
|
|
|
|
if (!np)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Create new 'exports' directory - /sys/firmware/opal/exports */
|
|
|
|
kobj = kobject_create_and_add("exports", opal_kobj);
|
|
|
|
if (!kobj) {
|
|
|
|
pr_warn("kobject_create_and_add() of exports failed\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for_each_property_of_node(np, prop) {
|
|
|
|
if (!strcmp(prop->name, "name") || !strcmp(prop->name, "phandle"))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (of_property_read_u64_array(np, prop->name, &vals[0], 2))
|
|
|
|
continue;
|
|
|
|
|
2017-04-26 12:57:19 +07:00
|
|
|
attr = kzalloc(sizeof(*attr), GFP_KERNEL);
|
2017-03-30 06:28:01 +07:00
|
|
|
|
|
|
|
if (attr == NULL) {
|
|
|
|
pr_warn("Failed kmalloc for bin_attribute!");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-04-26 12:57:19 +07:00
|
|
|
sysfs_bin_attr_init(attr);
|
2017-03-30 06:28:01 +07:00
|
|
|
attr->attr.name = kstrdup(prop->name, GFP_KERNEL);
|
|
|
|
attr->attr.mode = 0400;
|
|
|
|
attr->read = export_attr_read;
|
|
|
|
attr->private = __va(vals[0]);
|
|
|
|
attr->size = vals[1];
|
|
|
|
|
|
|
|
if (attr->attr.name == NULL) {
|
|
|
|
pr_warn("Failed kstrdup for bin_attribute attr.name");
|
|
|
|
kfree(attr);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = sysfs_create_bin_file(kobj, attr);
|
|
|
|
if (rc) {
|
|
|
|
pr_warn("Error %d creating OPAL sysfs exports/%s file\n",
|
|
|
|
rc, prop->name);
|
|
|
|
kfree(attr->attr.name);
|
|
|
|
kfree(attr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
of_node_put(np);
|
|
|
|
}
|
|
|
|
|
2014-08-09 12:45:45 +07:00
|
|
|
static void __init opal_dump_region_init(void)
|
|
|
|
{
|
|
|
|
void *addr;
|
|
|
|
uint64_t size;
|
|
|
|
int rc;
|
|
|
|
|
2015-02-12 12:25:27 +07:00
|
|
|
if (!opal_check_token(OPAL_REGISTER_DUMP_REGION))
|
|
|
|
return;
|
|
|
|
|
2014-08-09 12:45:45 +07:00
|
|
|
/* Register kernel log buffer */
|
|
|
|
addr = log_buf_addr_get();
|
2015-01-22 09:26:09 +07:00
|
|
|
if (addr == NULL)
|
|
|
|
return;
|
|
|
|
|
2014-08-09 12:45:45 +07:00
|
|
|
size = log_buf_len_get();
|
2015-01-22 09:26:09 +07:00
|
|
|
if (size == 0)
|
|
|
|
return;
|
|
|
|
|
2014-08-09 12:45:45 +07:00
|
|
|
rc = opal_register_dump_region(OPAL_DUMP_REGION_LOG_BUF,
|
|
|
|
__pa(addr), size);
|
|
|
|
/* Don't warn if this is just an older OPAL that doesn't
|
|
|
|
* know about that call
|
|
|
|
*/
|
|
|
|
if (rc && rc != OPAL_UNSUPPORTED)
|
|
|
|
pr_warn("DUMP: Failed to register kernel log buffer. "
|
|
|
|
"rc = %d\n", rc);
|
|
|
|
}
|
2014-11-06 10:38:27 +07:00
|
|
|
|
2016-08-11 07:32:40 +07:00
|
|
|
static void opal_pdev_init(const char *compatible)
|
2015-04-01 13:05:30 +07:00
|
|
|
{
|
|
|
|
struct device_node *np;
|
|
|
|
|
2016-08-11 07:32:40 +07:00
|
|
|
for_each_compatible_node(np, NULL, compatible)
|
2014-12-14 01:01:05 +07:00
|
|
|
of_platform_device_create(np, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2017-07-19 04:36:33 +07:00
|
|
|
static void __init opal_imc_init_dev(void)
|
|
|
|
{
|
|
|
|
struct device_node *np;
|
|
|
|
|
|
|
|
np = of_find_compatible_node(NULL, NULL, IMC_DTB_COMPAT);
|
|
|
|
if (np)
|
|
|
|
of_platform_device_create(np, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2014-11-14 12:13:50 +07:00
|
|
|
static int kopald(void *unused)
|
|
|
|
{
|
2016-07-04 11:51:44 +07:00
|
|
|
unsigned long timeout = msecs_to_jiffies(opal_heartbeat) + 1;
|
2015-05-15 11:06:37 +07:00
|
|
|
|
2014-11-14 12:13:50 +07:00
|
|
|
set_freezable();
|
|
|
|
do {
|
|
|
|
try_to_freeze();
|
2018-05-11 00:20:05 +07:00
|
|
|
|
|
|
|
opal_handle_events();
|
|
|
|
|
|
|
|
set_current_state(TASK_INTERRUPTIBLE);
|
|
|
|
if (opal_have_pending_events())
|
|
|
|
__set_current_state(TASK_RUNNING);
|
|
|
|
else
|
|
|
|
schedule_timeout(timeout);
|
|
|
|
|
2014-11-14 12:13:50 +07:00
|
|
|
} while (!kthread_should_stop());
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-07-04 11:51:44 +07:00
|
|
|
void opal_wake_poller(void)
|
|
|
|
{
|
|
|
|
if (kopald_tsk)
|
|
|
|
wake_up_process(kopald_tsk);
|
|
|
|
}
|
|
|
|
|
2014-11-14 12:13:50 +07:00
|
|
|
static void opal_init_heartbeat(void)
|
|
|
|
{
|
|
|
|
/* Old firwmware, we assume the HVC heartbeat is sufficient */
|
|
|
|
if (of_property_read_u32(opal_node, "ibm,heartbeat-ms",
|
|
|
|
&opal_heartbeat) != 0)
|
|
|
|
opal_heartbeat = 0;
|
|
|
|
|
|
|
|
if (opal_heartbeat)
|
2016-07-04 11:51:44 +07:00
|
|
|
kopald_tsk = kthread_run(kopald, NULL, "kopald");
|
2014-11-14 12:13:50 +07:00
|
|
|
}
|
|
|
|
|
2011-09-20 00:44:57 +07:00
|
|
|
static int __init opal_init(void)
|
|
|
|
{
|
2015-08-19 23:49:53 +07:00
|
|
|
struct device_node *np, *consoles, *leds;
|
2015-01-23 10:25:05 +07:00
|
|
|
int rc;
|
2011-09-20 00:44:57 +07:00
|
|
|
|
|
|
|
opal_node = of_find_node_by_path("/ibm,opal");
|
|
|
|
if (!opal_node) {
|
2015-01-28 11:10:33 +07:00
|
|
|
pr_warn("Device node not found\n");
|
2011-09-20 00:44:57 +07:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
2013-07-15 10:03:14 +07:00
|
|
|
|
|
|
|
/* Register OPAL consoles if any ports */
|
2015-12-09 13:18:19 +07:00
|
|
|
consoles = of_find_node_by_path("/ibm,opal/consoles");
|
2013-07-15 10:03:14 +07:00
|
|
|
if (consoles) {
|
|
|
|
for_each_child_of_node(consoles, np) {
|
|
|
|
if (strcmp(np->name, "serial"))
|
|
|
|
continue;
|
|
|
|
of_platform_device_create(np, NULL, NULL);
|
|
|
|
}
|
|
|
|
of_node_put(consoles);
|
2011-09-20 00:44:57 +07:00
|
|
|
}
|
2011-09-20 00:45:03 +07:00
|
|
|
|
2015-05-15 11:06:36 +07:00
|
|
|
/* Initialise OPAL messaging system */
|
|
|
|
opal_message_init();
|
|
|
|
|
|
|
|
/* Initialise OPAL asynchronous completion interface */
|
|
|
|
opal_async_comp_init();
|
|
|
|
|
|
|
|
/* Initialise OPAL sensor interface */
|
|
|
|
opal_sensor_init();
|
|
|
|
|
|
|
|
/* Initialise OPAL hypervisor maintainence interrupt handling */
|
|
|
|
opal_hmi_handler_init();
|
|
|
|
|
2014-12-14 01:01:05 +07:00
|
|
|
/* Create i2c platform devices */
|
2016-08-11 07:32:40 +07:00
|
|
|
opal_pdev_init("ibm,opal-i2c");
|
2014-12-14 01:01:05 +07:00
|
|
|
|
2018-04-06 12:21:16 +07:00
|
|
|
/* Handle non-volatile memory devices */
|
|
|
|
opal_pdev_init("pmem-region");
|
|
|
|
|
2014-11-14 12:13:50 +07:00
|
|
|
/* Setup a heatbeat thread if requested by OPAL */
|
|
|
|
opal_init_heartbeat();
|
|
|
|
|
2017-07-19 04:36:33 +07:00
|
|
|
/* Detect In-Memory Collection counters and create devices*/
|
|
|
|
opal_imc_init_dev();
|
|
|
|
|
2015-08-19 23:49:53 +07:00
|
|
|
/* Create leds platform devices */
|
|
|
|
leds = of_find_node_by_path("/ibm,opal/leds");
|
|
|
|
if (leds) {
|
|
|
|
of_platform_device_create(leds, "opal_leds", NULL);
|
|
|
|
of_node_put(leds);
|
|
|
|
}
|
|
|
|
|
2016-02-09 14:17:48 +07:00
|
|
|
/* Initialise OPAL message log interface */
|
|
|
|
opal_msglog_init();
|
|
|
|
|
2013-08-27 16:39:52 +07:00
|
|
|
/* Create "opal" kobject under /sys/firmware */
|
|
|
|
rc = opal_sysfs_init();
|
2013-10-24 17:34:58 +07:00
|
|
|
if (rc == 0) {
|
2014-12-11 08:39:49 +07:00
|
|
|
/* Export symbol map to userspace */
|
|
|
|
opal_export_symmap();
|
2014-08-09 12:45:45 +07:00
|
|
|
/* Setup dump region interface */
|
|
|
|
opal_dump_region_init();
|
powerpc/powernv: Read OPAL error log and export it through sysfs
Based on a patch by: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>
This patch adds support to read error logs from OPAL and export
them to userspace through a sysfs interface.
We export each log entry as a directory in /sys/firmware/opal/elog/
Currently, OPAL will buffer up to 128 error log records, we don't
need to have any knowledge of this limit on the Linux side as that
is actually largely transparent to us.
Each error log entry has the following files: id, type, acknowledge, raw.
Currently we just export the raw binary error log in the 'raw' attribute.
In a future patch, we may parse more of the error log to make it a bit
easier for userspace (e.g. to be able to display a brief summary in
petitboot without having to have a full parser).
If we have >128 logs from OPAL, we'll only be notified of 128 until
userspace starts acknowledging them. This limitation may be lifted in
the future and with this patch, that should "just work" from the linux side.
A userspace daemon should:
- wait for error log entries using normal mechanisms (we announce creation)
- read error log entry
- save error log entry safely to disk
- acknowledge the error log entry
- rinse, repeat.
On the Linux side, we read the error log when we're notified of it. This
possibly isn't ideal as it would be better to only read them on-demand.
However, this doesn't really work with current OPAL interface, so we
read the error log immediately when notified at the moment.
I've tested this pretty extensively and am rather confident that the
linux side of things works rather well. There is currently an issue with
the service processor side of things for >128 error logs though.
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2014-02-28 07:58:32 +07:00
|
|
|
/* Setup error log interface */
|
|
|
|
rc = opal_elog_init();
|
2013-10-24 17:34:58 +07:00
|
|
|
/* Setup code update interface */
|
2015-04-01 13:05:30 +07:00
|
|
|
opal_flash_update_init();
|
2014-03-03 06:25:42 +07:00
|
|
|
/* Setup platform dump extract interface */
|
|
|
|
opal_platform_dump_init();
|
2014-03-07 12:32:09 +07:00
|
|
|
/* Setup system parameters interface */
|
|
|
|
opal_sys_param_init();
|
2016-02-09 14:17:48 +07:00
|
|
|
/* Setup message log sysfs interface. */
|
|
|
|
opal_msglog_sysfs_init();
|
2013-10-24 17:34:58 +07:00
|
|
|
}
|
2013-08-27 16:39:52 +07:00
|
|
|
|
2017-03-30 06:28:01 +07:00
|
|
|
/* Export all properties */
|
|
|
|
opal_export_attrs();
|
|
|
|
|
2015-06-04 20:51:47 +07:00
|
|
|
/* Initialize platform devices: IPMI backend, PRD & flash interface */
|
2016-08-11 07:32:40 +07:00
|
|
|
opal_pdev_init("ibm,opal-ipmi");
|
|
|
|
opal_pdev_init("ibm,opal-flash");
|
|
|
|
opal_pdev_init("ibm,opal-prd");
|
2015-04-01 13:05:30 +07:00
|
|
|
|
2016-06-29 10:38:39 +07:00
|
|
|
/* Initialise platform device: oppanel interface */
|
2016-08-11 07:32:40 +07:00
|
|
|
opal_pdev_init("ibm,opal-oppanel");
|
2016-06-29 10:38:39 +07:00
|
|
|
|
2015-11-27 13:23:07 +07:00
|
|
|
/* Initialise OPAL kmsg dumper for flushing console on panic */
|
|
|
|
opal_kmsg_init();
|
|
|
|
|
2017-08-10 10:31:18 +07:00
|
|
|
/* Initialise OPAL powercap interface */
|
|
|
|
opal_powercap_init();
|
|
|
|
|
2017-08-10 10:31:19 +07:00
|
|
|
/* Initialise OPAL Power-Shifting-Ratio interface */
|
|
|
|
opal_psr_init();
|
|
|
|
|
2017-08-10 10:31:20 +07:00
|
|
|
/* Initialise OPAL sensor groups */
|
|
|
|
opal_sensor_groups_init();
|
|
|
|
|
2011-09-20 00:44:57 +07:00
|
|
|
return 0;
|
|
|
|
}
|
2014-07-15 19:22:24 +07:00
|
|
|
machine_subsys_initcall(powernv, opal_init);
|
2013-05-10 13:59:18 +07:00
|
|
|
|
|
|
|
void opal_shutdown(void)
|
|
|
|
{
|
2014-01-15 13:02:04 +07:00
|
|
|
long rc = OPAL_BUSY;
|
2013-05-10 13:59:18 +07:00
|
|
|
|
2015-05-15 11:06:37 +07:00
|
|
|
opal_event_shutdown();
|
2014-01-15 13:02:04 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Then sync with OPAL which ensure anything that can
|
|
|
|
* potentially write to our memory has completed such
|
|
|
|
* as an ongoing dump retrieval
|
|
|
|
*/
|
|
|
|
while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) {
|
|
|
|
rc = opal_sync_host_reboot();
|
|
|
|
if (rc == OPAL_BUSY)
|
|
|
|
opal_poll_events(NULL);
|
|
|
|
else
|
|
|
|
mdelay(10);
|
|
|
|
}
|
2014-08-09 12:45:45 +07:00
|
|
|
|
|
|
|
/* Unregister memory dump region */
|
2015-02-12 12:25:27 +07:00
|
|
|
if (opal_check_token(OPAL_UNREGISTER_DUMP_REGION))
|
|
|
|
opal_unregister_dump_region(OPAL_DUMP_REGION_LOG_BUF);
|
2013-05-10 13:59:18 +07:00
|
|
|
}
|
2014-04-01 10:58:20 +07:00
|
|
|
|
|
|
|
/* Export this so that test modules can use it */
|
|
|
|
EXPORT_SYMBOL_GPL(opal_invalid_call);
|
2015-05-20 10:23:33 +07:00
|
|
|
EXPORT_SYMBOL_GPL(opal_xscom_read);
|
|
|
|
EXPORT_SYMBOL_GPL(opal_xscom_write);
|
2014-11-06 10:38:27 +07:00
|
|
|
EXPORT_SYMBOL_GPL(opal_ipmi_send);
|
|
|
|
EXPORT_SYMBOL_GPL(opal_ipmi_recv);
|
2015-04-01 13:05:30 +07:00
|
|
|
EXPORT_SYMBOL_GPL(opal_flash_read);
|
|
|
|
EXPORT_SYMBOL_GPL(opal_flash_write);
|
|
|
|
EXPORT_SYMBOL_GPL(opal_flash_erase);
|
2015-06-04 20:51:47 +07:00
|
|
|
EXPORT_SYMBOL_GPL(opal_prd_msg);
|
2018-06-13 14:28:57 +07:00
|
|
|
EXPORT_SYMBOL_GPL(opal_check_token);
|
2014-04-22 12:01:26 +07:00
|
|
|
|
|
|
|
/* Convert a region of vmalloc memory to an opal sg list */
|
|
|
|
struct opal_sg_list *opal_vmalloc_to_sg_list(void *vmalloc_addr,
|
|
|
|
unsigned long vmalloc_size)
|
|
|
|
{
|
|
|
|
struct opal_sg_list *sg, *first = NULL;
|
|
|
|
unsigned long i = 0;
|
|
|
|
|
|
|
|
sg = kzalloc(PAGE_SIZE, GFP_KERNEL);
|
|
|
|
if (!sg)
|
|
|
|
goto nomem;
|
|
|
|
|
|
|
|
first = sg;
|
|
|
|
|
|
|
|
while (vmalloc_size > 0) {
|
|
|
|
uint64_t data = vmalloc_to_pfn(vmalloc_addr) << PAGE_SHIFT;
|
|
|
|
uint64_t length = min(vmalloc_size, PAGE_SIZE);
|
|
|
|
|
|
|
|
sg->entry[i].data = cpu_to_be64(data);
|
|
|
|
sg->entry[i].length = cpu_to_be64(length);
|
|
|
|
i++;
|
|
|
|
|
|
|
|
if (i >= SG_ENTRIES_PER_NODE) {
|
|
|
|
struct opal_sg_list *next;
|
|
|
|
|
|
|
|
next = kzalloc(PAGE_SIZE, GFP_KERNEL);
|
|
|
|
if (!next)
|
|
|
|
goto nomem;
|
|
|
|
|
|
|
|
sg->length = cpu_to_be64(
|
|
|
|
i * sizeof(struct opal_sg_entry) + 16);
|
|
|
|
i = 0;
|
|
|
|
sg->next = cpu_to_be64(__pa(next));
|
|
|
|
sg = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
vmalloc_addr += length;
|
|
|
|
vmalloc_size -= length;
|
|
|
|
}
|
|
|
|
|
|
|
|
sg->length = cpu_to_be64(i * sizeof(struct opal_sg_entry) + 16);
|
|
|
|
|
|
|
|
return first;
|
|
|
|
|
|
|
|
nomem:
|
|
|
|
pr_err("%s : Failed to allocate memory\n", __func__);
|
|
|
|
opal_free_sg_list(first);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void opal_free_sg_list(struct opal_sg_list *sg)
|
|
|
|
{
|
|
|
|
while (sg) {
|
|
|
|
uint64_t next = be64_to_cpu(sg->next);
|
|
|
|
|
|
|
|
kfree(sg);
|
|
|
|
|
|
|
|
if (next)
|
|
|
|
sg = __va(next);
|
|
|
|
else
|
|
|
|
sg = NULL;
|
|
|
|
}
|
|
|
|
}
|
2014-10-14 15:38:36 +07:00
|
|
|
|
2015-03-30 17:06:09 +07:00
|
|
|
int opal_error_code(int rc)
|
|
|
|
{
|
|
|
|
switch (rc) {
|
|
|
|
case OPAL_SUCCESS: return 0;
|
|
|
|
|
|
|
|
case OPAL_PARAMETER: return -EINVAL;
|
|
|
|
case OPAL_ASYNC_COMPLETION: return -EINPROGRESS;
|
2017-11-03 09:41:45 +07:00
|
|
|
case OPAL_BUSY:
|
2015-03-30 17:06:09 +07:00
|
|
|
case OPAL_BUSY_EVENT: return -EBUSY;
|
|
|
|
case OPAL_NO_MEM: return -ENOMEM;
|
2015-04-08 14:31:10 +07:00
|
|
|
case OPAL_PERMISSION: return -EPERM;
|
2015-03-30 17:06:09 +07:00
|
|
|
|
|
|
|
case OPAL_UNSUPPORTED: return -EIO;
|
|
|
|
case OPAL_HARDWARE: return -EIO;
|
|
|
|
case OPAL_INTERNAL_ERROR: return -EIO;
|
2017-08-10 10:31:18 +07:00
|
|
|
case OPAL_TIMEOUT: return -ETIMEDOUT;
|
2015-03-30 17:06:09 +07:00
|
|
|
default:
|
|
|
|
pr_err("%s: unexpected OPAL error %d\n", __func__, rc);
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-14 09:36:51 +07:00
|
|
|
void powernv_set_nmmu_ptcr(unsigned long ptcr)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (firmware_has_feature(FW_FEATURE_OPAL)) {
|
|
|
|
rc = opal_nmmu_set_ptcr(-1UL, ptcr);
|
|
|
|
if (rc != OPAL_SUCCESS && rc != OPAL_UNSUPPORTED)
|
|
|
|
pr_warn("%s: Unable to set nest mmu ptcr\n", __func__);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-14 15:38:36 +07:00
|
|
|
EXPORT_SYMBOL_GPL(opal_poll_events);
|
|
|
|
EXPORT_SYMBOL_GPL(opal_rtc_read);
|
|
|
|
EXPORT_SYMBOL_GPL(opal_rtc_write);
|
|
|
|
EXPORT_SYMBOL_GPL(opal_tpo_read);
|
|
|
|
EXPORT_SYMBOL_GPL(opal_tpo_write);
|
2014-12-14 01:01:05 +07:00
|
|
|
EXPORT_SYMBOL_GPL(opal_i2c_request);
|
2015-08-19 23:49:53 +07:00
|
|
|
/* Export these symbols for PowerNV LED class driver */
|
|
|
|
EXPORT_SYMBOL_GPL(opal_leds_get_ind);
|
|
|
|
EXPORT_SYMBOL_GPL(opal_leds_set_ind);
|
2016-06-29 10:38:39 +07:00
|
|
|
/* Export this symbol for PowerNV Operator Panel class driver */
|
|
|
|
EXPORT_SYMBOL_GPL(opal_write_oppanel_async);
|
2016-11-21 12:01:36 +07:00
|
|
|
/* Export this for KVM */
|
|
|
|
EXPORT_SYMBOL_GPL(opal_int_set_mfrr);
|
2017-04-05 14:54:56 +07:00
|
|
|
EXPORT_SYMBOL_GPL(opal_int_eoi);
|
2017-11-03 09:41:45 +07:00
|
|
|
EXPORT_SYMBOL_GPL(opal_error_code);
|
2018-06-13 14:32:40 +07:00
|
|
|
/* Export the below symbol for NX compression */
|
|
|
|
EXPORT_SYMBOL(opal_nx_coproc_init);
|