23 Commits

Author SHA1 Message Date
Nicholas Piggin
dca0d53456 core: interrupt markers for stack traces
Use magic marker in the exception stack frame that is used by the
unwinder to decode the interrupt type and NIA. The below example trace
comes from a modified skiboot that uses virtual memory, but any
interrupt type will appear similarly.

 CPU 0000 Backtrace:
  S: 0000000031c13580 R: 0000000030028210   .vm_dsi+0x360
  S: 0000000031c13630 R: 000000003003b0dc   .exception_entry+0x4fc
  S: 0000000031c13830 R: 0000000030001f4c   exception_entry_foo+0x4
  --- Interrupt 0x300 at 000000003002431c ---
  S: 0000000031c13b40 R: 000000003002430c   .make_free.isra.0+0x110
  S: 0000000031c13bd0 R: 0000000030025198   .mem_alloc+0x4a0
  S: 0000000031c13c80 R: 0000000030028bac   .__memalign+0x48
  S: 0000000031c13d10 R: 0000000030028da4   .__zalloc+0x18
  S: 0000000031c13d90 R: 000000003002fb34   .opal_init_msg+0x34
  S: 0000000031c13e20 R: 00000000300234b4   .main_cpu_entry+0x61c
  S: 0000000031c13f00 R: 00000000300031b8   boot_entry+0x1b0
  --- OPAL boot ---

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[oliver: the new stackentry fields made our test heaps too small]
Signed-off-by: Oliver O'Halloran <oohall@gmail.com>

fixup! core: interrupt markers for stack traces
2020-06-11 12:52:55 +10:00
Stewart Smith
49496485fe Re-license IBM written files as Apache 2.0 OR GPLv2+
SPDX makes it a simpler diff.

I have audited the commit history of each file to ensure that they are
exclusively authored by IBM and thus we have the right to relicense.

The motivation behind this is twofold:
1) We want to enable experiments with coreboot, which is GPLv2 licensed
2) An upcoming firmware component wants to incorporate code from skiboot
   and code from the Linux kernel, which is GPLv2 licensed.

I have gone through the IBM internal way of gaining approval for this.

The following files are not exclusively authored by IBM, so are *not*
included in this update (I will be seeking approval from contributors):

core/direct-controls.c
core/flash.c
core/pcie-slot.c
external/common/arch_flash_unknown.c
external/common/rules.mk
external/gard/Makefile
external/gard/rules.mk
external/opal-prd/Makefile
external/pflash/Makefile
external/xscom-utils/Makefile
hdata/vpd.c
hw/dts.c
hw/ipmi/ipmi-watchdog.c
hw/phb4.c
include/cpu.h
include/phb4.h
include/platform.h
libflash/libffs.c
libstb/mbedtls/sha512.c
libstb/mbedtls/sha512.h
platforms/astbmc/barreleye.c
platforms/astbmc/garrison.c
platforms/astbmc/mihawk.c
platforms/astbmc/nicole.c
platforms/astbmc/p8dnu.c
platforms/astbmc/p8dtu.c
platforms/astbmc/p9dsu.c
platforms/astbmc/vesnin.c
platforms/rhesus/ec/config.h
platforms/rhesus/ec/gpio.h
platforms/rhesus/gpio.c
platforms/rhesus/rhesus.c
platforms/astbmc/talos.c
platforms/astbmc/romulus.c

Signed-off-by: Stewart Smith <stewart@linux.ibm.com>
[oliver: fixed up the drift]
Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
2020-03-12 20:33:18 +11:00
Nicholas Piggin
c47b2ffdd5 elf: endian conversions
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
2019-12-16 14:50:56 +11:00
Nicholas Piggin
2665739394 asm/cvc_entry.S: r2 save fix
The TOC save area for the current stack frame should be used to save
r2, not the caller's frame.

Acked-by: Stewart Smith <stewart@flamingspork.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
2019-12-16 14:50:56 +11:00
Nicholas Piggin
1785745d5a core/exceptions.c: do not include handler code in exception backtrace
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
2019-10-03 09:55:58 +10:00
Stewart Smith
5ef3dd30a9 SPDX-ify all skiboot code
Use Software Package Data Exchange (SPDX) to indicate license for each
file that is unique to skiboot.

At the same time, ensure the (C) who and years are correct.

See https://spdx.org/

Signed-off-by: Stewart Smith <stewart@linux.ibm.com>
[oliver: Added a few missing files]
Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
2019-07-26 15:08:03 +10:00
Andrew Donnellan
b965b9de25 core/stack: Rename backtrace functions, get rid of wrappers
Rename ___backtrace() to backtrace_create() and ___print_backtrace() to
backtrace_print(). Get rid of __backtrace() and __print_backtrace()
wrappers.

Signed-off-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
Signed-off-by: Stewart Smith <stewart@linux.ibm.com>
2019-03-28 15:24:13 +11:00
Andrew Donnellan
b971b67ac2 core/stack: Define a backtrace metadata struct
Every time we take a backtrace, we have to store the number of entries, the
OPAL API token, r1 caller and PIR values. Rather than defining these and
passing them around all over the place, let's throw them in a struct.

Define a struct, struct bt_metadata, to store these details, and convert
___backtrace() and ___print_backtrace() to use it.

We change the wrapper functions __backtrace() and __print_backtrace() to
call ___backtrace()/___print_backtrace() with struct bt_metadata, but don't
change their parameter profiles for now - we'll do that later.

Signed-off-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
Signed-off-by: Stewart Smith <stewart@linux.ibm.com>
2019-03-28 15:24:12 +11:00
Andrew Donnellan
c9bc52a250 core/stack: Remove r1 argument from ___backtrace()
___backtrace() is always called with r1 = __builtin_frame_address(0), and
it's unlikely we're going to need it to do something else any time soon, so
simplify the API by removing the parameter.

Signed-off-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
Signed-off-by: Stewart Smith <stewart@linux.ibm.com>
2019-03-28 15:24:12 +11:00
Nicholas Piggin
9c58bbd720 core/exceptions: save current MSR in exception frame
Save and print the MSR of the interrupt context. This can be derived
from the interrupt type, SRR1, and other system register settings. But
it can be useful to quickly verify what's happening.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Stewart Smith <stewart@linux.ibm.com>
2019-02-12 15:08:17 +11:00
Nicholas Piggin
3fdd262951 core/opal: Emergency stack for re-entry
This detects OPAL being re-entered by the OS, and switches to an
emergency stack if it was. This protects the firmware's main stack
from re-entrancy and allows the OS to use NMI facilities for crash
/ debug functionality.

Further nested re-entry will destroy the previous emergency stack
and prevent returning, but those should be rare cases.

This stack is sized at 16kB, which doubles the size of CPU stacks,
so as not to introduce a regression in primary stack size. The 16kB
stack originally had a 4kB machine check stack at the top, which was
removed by 80eee1946 ("opal: Remove machine check interrupt patching
in OPAL."). So it is possible the size could be tightened again, but
that would require further analysis.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Stewart Smith <stewart@linux.ibm.com>
2018-04-18 20:23:07 -05:00
Nicholas Piggin
ad0941960b core/stack: backtrace unwind basic OPAL call details
Put OPAL callers' r1 into the stack back chain, and then use that to
unwind back to the OPAL entry frame (as opposed to boot entry, which
has a 0 back chain).

>From there, dump the OPAL call token and the caller's r1. A backtrace
looks like this:

  CPU 0000 Backtrace:
   S: 0000000031c03ba0 R: 000000003001a548   ._abort+0x4c
   S: 0000000031c03c20 R: 000000003001baac   .opal_run_pollers+0x3c
   S: 0000000031c03ca0 R: 000000003001bcbc   .opal_poll_events+0xc4
   S: 0000000031c03d20 R: 00000000300051dc   opal_entry+0x12c
   --- OPAL call entry token: 0xa caller R1: 0xc0000000006d3b90 ---

This is pretty basic for the moment, but it does give you the bottom
of the Linux stack. It will allow some interesting improvements in
future.

First, with the eframe, all the call's parameters can be printed out
as well.  The ___backtrace / ___print_backtrace API needs to be
reworked in order to support this, but it's otherwise very simple
(see opal_trace_entry()).

Second, it will allow Linux's stack to be passed back to Linux via
a debugging opal call. This will allow Linux's BUG() or xmon to
also print the Linux back trace in case of a NMI or MCE or watchdog
lockup that hits in OPAL.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Stewart Smith <stewart@linux.ibm.com>
2018-04-18 20:23:07 -05:00
Nicholas Piggin
d5378d2a0d core/exception: beautify exception handler, add MCE-involved registers
Print DSISR and DAR, to help with deciphering machine check exceptions,
and improve the output a bit, decode NIP symbol, improve alignment, etc.
Also print a specific header for machine check, because we do expect to
see these if there is a hardware failure.

Before:
[    0.005968779,3] ***********************************************
[    0.005974102,3] Unexpected exception 200 !
[    0.005978696,3] SRR0 : 000000003002ad80 SRR1 : 9000000000001000
[    0.005985239,3] HSRR0: 00000000300027b4 HSRR1: 9000000030001000
[    0.005991782,3] LR   : 000000003002ad80 CTR  : 0000000000000000
[    0.005998130,3] CFAR : 00000000300b58bc
[    0.006002769,3] CR   : 40000004  XER: 20000000
[    0.006008069,3] GPR00: 000000003002ad80 GPR16: 0000000000000000
[    0.006015170,3] GPR01: 0000000031c03bd0 GPR17: 0000000000000000
[...]

After:
[    0.003287941,3] ***********************************************
[    0.003561769,3] Fatal MCE at 000000003002ad80   .nvram_init+0x24
[    0.003579628,3] CFAR : 00000000300b5964
[    0.003584268,3] SRR0 : 000000003002ad80 SRR1 : 9000000000001000
[    0.003590812,3] HSRR0: 00000000300027b4 HSRR1: 9000000030001000
[    0.003597355,3] DSISR: 00000000         DAR  : 0000000000000000
[    0.003603480,3] LR   : 000000003002ad68 CTR  : 0000000030093d80
[    0.003609930,3] CR   : 40000004         XER  : 20000000
[    0.003615698,3] GPR00: 00000000300149e8 GPR16: 0000000000000000
[    0.003622799,3] GPR01: 0000000031c03bc0 GPR17: 0000000000000000
[...]

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2018-02-08 18:21:42 -06:00
Benjamin Herrenschmidt
c7f2fab5c7 Add support for new gcc 7 parametrized stack protector
This gives us per-cpu guard values as well. For now I just
xor a magic constant with the CPU PIR value.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2017-12-20 22:15:36 -06:00
Stewart Smith
9eeb5af64b Fix spelling mistakes
See https://github.com/lucasdemarchi/codespel

Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2015-08-26 16:40:10 +10:00
Benjamin Herrenschmidt
989d8b68b6 exceptions: Catch exceptions at boot time
And print some informations about GPR state, backtrace, etc...

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
2015-03-31 15:42:37 +11:00
Mahesh Salgaonkar
0b446b4c8c opal: Remove MCE handling code.
Removed following:
- Machine check handle and other related routines.
- per-cpu MCE event used to record machine check data
	cpu_thread->mc_event;
- Machine check related definition including mce event structure from
  include/opal.h
- A comment above GET_STACK() #define that warns about runtime modification
  made to GET_STACK macro by MC patching code.

Signed-off-by: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2014-11-22 08:27:19 +11:00
Mahesh Salgaonkar
80eee19464 opal: Remove machine check interrupt patching in OPAL.
Now that we catch/handle machine check interrupt directly in Linux host
PowerNV kernel, we are not anymore dependent on OPAL firmware to do MCE
handling job for us. The MCE handling code in OPAL has exclusive stack
space (4k size) reserved and remains unused with Linux host not being
dependent on it anymore. Hence, this patch removes the code that allows
machine check interrupt patching in OPAL and reclaims back 4k of stack
space for use of normal stack. For older kernel the patching request
will result into an error.

The subsequent patch will remove the rest of MCE handling code from OPAL.

Signed-off-by: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2014-11-22 08:26:35 +11:00
Benjamin Herrenschmidt
c38c2e8d08 Add symbolic backtraces and expose skiboot map to Linux
We use a double link technique, doing a first pass with a .o containing
a dummy symbol map, then re-linking with a new .o

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2014-11-18 19:33:51 +11:00
Benjamin Herrenschmidt
8f41f30053 Capture backtraces when measuring stack depth
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2014-11-18 14:57:33 +11:00
Benjamin Herrenschmidt
efa6bbc48f Add functions to backtrace into a non-text buffer
Separate text translation from capture of the backtrace

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2014-11-18 14:42:27 +11:00
Benjamin Herrenschmidt
71664fd8d2 Stack checking extensions
This patch adds:

 - Normal builds are done with -fstack-protector (we want to investigate
using -fstack-protector-strong on gcc4.9 but for now we just use that

 - Build with STACK_CHECK=1 will use -fstack-protector-all and -pg and
will check the stack in mcount

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2014-11-17 18:22:04 +11:00
Benjamin Herrenschmidt
1d880992fd Initial commit of Open Source release
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2014-07-02 15:36:20 +10:00