linux/arch/powerpc/kernel
Aditya Gupta b684c09f09 powerpc: update ppc_save_regs to save current r1 in pt_regs
ppc_save_regs() skips one stack frame while saving the CPU register states.
Instead of saving current R1, it pulls the previous stack frame pointer.

When vmcores caused by direct panic call (such as `echo c >
/proc/sysrq-trigger`), are debugged with gdb, gdb fails to show the
backtrace correctly. On further analysis, it was found that it was because
of mismatch between r1 and NIP.

GDB uses NIP to get current function symbol and uses corresponding debug
info of that function to unwind previous frames, but due to the
mismatching r1 and NIP, the unwinding does not work, and it fails to
unwind to the 2nd frame and hence does not show the backtrace.

GDB backtrace with vmcore of kernel without this patch:

---------
(gdb) bt
 #0  0xc0000000002a53e8 in crash_setup_regs (oldregs=<optimized out>,
    newregs=0xc000000004f8f8d8) at ./arch/powerpc/include/asm/kexec.h:69
 #1  __crash_kexec (regs=<optimized out>) at kernel/kexec_core.c:974
 #2  0x0000000000000063 in ?? ()
 #3  0xc000000003579320 in ?? ()
---------

Further analysis revealed that the mismatch occurred because
"ppc_save_regs" was saving the previous stack's SP instead of the current
r1. This patch fixes this by storing current r1 in the saved pt_regs.

GDB backtrace with vmcore of patched kernel:

--------
(gdb) bt
 #0  0xc0000000002a53e8 in crash_setup_regs (oldregs=0x0, newregs=0xc00000000670b8d8)
    at ./arch/powerpc/include/asm/kexec.h:69
 #1  __crash_kexec (regs=regs@entry=0x0) at kernel/kexec_core.c:974
 #2  0xc000000000168918 in panic (fmt=fmt@entry=0xc000000001654a60 "sysrq triggered crash\n")
    at kernel/panic.c:358
 #3  0xc000000000b735f8 in sysrq_handle_crash (key=<optimized out>) at drivers/tty/sysrq.c:155
 #4  0xc000000000b742cc in __handle_sysrq (key=key@entry=99, check_mask=check_mask@entry=false)
    at drivers/tty/sysrq.c:602
 #5  0xc000000000b7506c in write_sysrq_trigger (file=<optimized out>, buf=<optimized out>,
    count=2, ppos=<optimized out>) at drivers/tty/sysrq.c:1163
 #6  0xc00000000069a7bc in pde_write (ppos=<optimized out>, count=<optimized out>,
    buf=<optimized out>, file=<optimized out>, pde=0xc00000000362cb40) at fs/proc/inode.c:340
 #7  proc_reg_write (file=<optimized out>, buf=<optimized out>, count=<optimized out>,
    ppos=<optimized out>) at fs/proc/inode.c:352
 #8  0xc0000000005b3bbc in vfs_write (file=file@entry=0xc000000006aa6b00,
    buf=buf@entry=0x61f498b4f60 <error: Cannot access memory at address 0x61f498b4f60>,
    count=count@entry=2, pos=pos@entry=0xc00000000670bda0) at fs/read_write.c:582
 #9  0xc0000000005b4264 in ksys_write (fd=<optimized out>,
    buf=0x61f498b4f60 <error: Cannot access memory at address 0x61f498b4f60>, count=2)
    at fs/read_write.c:637
 #10 0xc00000000002ea2c in system_call_exception (regs=0xc00000000670be80, r0=<optimized out>)
    at arch/powerpc/kernel/syscall.c:171
 #11 0xc00000000000c270 in system_call_vectored_common ()
    at arch/powerpc/kernel/interrupt_64.S:192
--------

Nick adds:
  So this now saves regs as though it was an interrupt taken in the
  caller, at the instruction after the call to ppc_save_regs, whereas
  previously the NIP was there, but R1 came from the caller's caller and
  that mismatch is what causes gdb's dwarf unwinder to go haywire.

Signed-off-by: Aditya Gupta <adityag@linux.ibm.com>
Fixes: d16a58f885 ("powerpc: Improve ppc_save_regs()")
Reivewed-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/20230615091047.90433-1-adityag@linux.ibm.com
2023-06-19 17:37:14 +10:00
..
ptrace powerpc/ptrace: Expose HASHKEYR register to ptrace 2023-06-19 17:36:27 +10:00
syscalls powerpc/32: fix syscall wrappers with 64-bit arguments 2022-11-01 10:24:09 +11:00
trace powerpc/64: vmlinux support building with PCREL addresing 2023-04-20 12:59:21 +10:00
vdso powerpc/build: vdso linker warning for orphan sections 2023-06-15 14:04:19 +10:00
.gitignore
85xx_entry_mapping.S powerpc: Remove CONFIG_FSL_BOOKE 2022-09-26 22:47:37 +10:00
align.c powerpc/inst: Define ppc_inst_t 2021-12-09 22:41:21 +11:00
asm-offsets.c powerpc/64: vmlinux support building with PCREL addresing 2023-04-20 12:59:21 +10:00
audit.c
btext.c powerpc: Use of_property_read_bool() for boolean properties 2023-03-30 23:36:35 +11:00
cacheinfo.c powerpc: Remove asm/prom.h from all files that don't need it 2022-05-08 22:15:04 +10:00
cacheinfo.h
compat_audit.c
cpu_setup_6xx.S powerpc/32: Fix objtool unannotated intra-function call warnings 2022-11-18 19:00:06 +11:00
cpu_setup_44x.S
cpu_setup_e500.S powerpc/32: Fix objtool unannotated intra-function call warnings 2022-11-18 19:00:06 +11:00
cpu_setup_pa6t.S
cpu_setup_power.c powerpc/dexcr: Add initial Dynamic Execution Control Register (DEXCR) support 2023-06-19 17:36:25 +10:00
cpu_setup_ppc970.S
cpu_specs.h powerpc/cputable: Split cpu_specs[] for mpc85xx and e500mc 2022-09-26 23:00:05 +10:00
cpu_specs_8xx.h powerpc/cputable: Split cpu_specs[] out of cputable.h 2022-09-26 22:47:13 +10:00
cpu_specs_40x.h powerpc/cputable: Split cpu_specs[] out of cputable.h 2022-09-26 22:47:13 +10:00
cpu_specs_44x.h powerpc/cputable: Split cpu_specs[] out of cputable.h 2022-09-26 22:47:13 +10:00
cpu_specs_47x.h powerpc/cputable: Split cpu_specs[] out of cputable.h 2022-09-26 22:47:13 +10:00
cpu_specs_85xx.h powerpc/cputable: Split cpu_specs[] for mpc85xx and e500mc 2022-09-26 23:00:05 +10:00
cpu_specs_book3s_32.h powerpc/cputable: Split cpu_specs[] out of cputable.h 2022-09-26 22:47:13 +10:00
cpu_specs_book3s_64.h powerpc/cputable: Split cpu_specs[] out of cputable.h 2022-09-26 22:47:13 +10:00
cpu_specs_e500mc.h powerpc/cputable: Split cpu_specs[] for mpc85xx and e500mc 2022-09-26 23:00:05 +10:00
cputable.c powerpc/cputable: Split cpu_specs[] out of cputable.h 2022-09-26 22:47:13 +10:00
crash_dump.c powerpc updates for 5.19 2022-05-28 11:27:17 -07:00
dawr.c powerpc: Include asm/firmware.h in all users of firmware_has_feature() 2022-06-29 16:45:05 +10:00
dbell.c powerpc/64: Fix perf profiling asynchronous interrupt handlers 2023-01-30 20:07:42 +11:00
dma-iommu.c powerpc/iommu: Incorrect DDW Table is referenced for SR-IOV device 2023-05-17 00:54:55 +10:00
dma-mask.c
dma-swiotlb.c swiotlb: add a SWIOTLB_ANY flag to lift the low memory restriction 2022-04-18 07:21:12 +02:00
dt_cpu_ftrs.c powerpc: move from strlcpy with unused retval to strscpy 2022-08-26 11:02:20 +10:00
early_32.c powerpc: Move C prototypes out of asm-prototypes.h 2022-03-08 22:06:25 +11:00
eeh.c powerpc: fix typos in comments 2022-05-05 22:12:44 +10:00
eeh_cache.c powerpc/kernel: Add __init attribute to eligible functions 2021-12-23 22:33:10 +11:00
eeh_driver.c powerpc/eeh: Set channel state after notifying the drivers 2023-02-15 22:41:11 +11:00
eeh_event.c powerpc: fix typos in comments 2022-05-05 22:12:44 +10:00
eeh_pe.c powerpc: Fix all occurences of "the the" 2022-05-22 15:59:43 +10:00
eeh_sysfs.c powerpc: Add missing headers 2022-05-08 22:15:40 +10:00
entry_32.S powerpc: merge 32-bit and 64-bit _switch implementation 2023-06-15 14:03:55 +10:00
epapr_hcalls.S powerpc/epapr: Don't use wrteei on non booke 2023-02-17 22:07:04 +11:00
epapr_paravirt.c powerpc/inst: Define ppc_inst_t 2021-12-09 22:41:21 +11:00
exceptions-64e.S powerpc/64e: Clear gprs on interrupt routine entry on Book3E 2022-12-02 20:46:08 +11:00
exceptions-64s.S powerpc: add CFUNC assembly label annotation 2023-04-20 12:54:24 +10:00
fadump.c powerpc updates for 5.19 2022-05-28 11:27:17 -07:00
firmware.c
fpu.S powerpc/64s/interrupt: handle MSR EE and RI in interrupt entry wrapper 2021-12-16 21:31:45 +11:00
head_8xx.S Merge branch 'topic/objtool' into next 2022-12-08 23:57:47 +11:00
head_32.h powerpc: add a definition for the marker offset within the interrupt frame 2022-12-02 17:54:08 +11:00
head_40x.S Merge branch 'topic/objtool' into next 2022-12-08 23:57:47 +11:00
head_44x.S powerpc: allow minimum sized kernel stack frames 2022-12-02 17:54:09 +11:00
head_64.S powerpc/64: vmlinux support building with PCREL addresing 2023-04-20 12:59:21 +10:00
head_85xx.S powerpc/85xx: Fix unannotated intra-function call warning 2023-01-30 15:59:59 +11:00
head_book3s_32.S Merge branch 'topic/objtool' into next 2022-12-08 23:57:47 +11:00
head_booke.h powerpc/32: Include thread_info.h in head_booke.h 2023-04-11 23:13:33 +10:00
hw_breakpoint.c powerpc/8xx: Fix warning in hw_breakpoint_handler() 2022-11-24 23:31:49 +11:00
hw_breakpoint_constraints.c powerpc/inst: Define ppc_inst_t 2021-12-09 22:41:21 +11:00
idle.c powerpc: Simplify sysctl registration for powersave_nap_ctl_table 2023-03-16 15:18:12 +11:00
idle_6xx.S powerpc/mm: Switch obsolete dssall to .long 2021-12-23 22:35:13 +11:00
idle_64e.S powerpc: add ISA v3.0 / v3.1 wait opcode macro 2022-09-28 19:22:10 +10:00
idle_85xx.S powerpc: Cleanup idle for e500 2022-09-26 23:00:14 +10:00
idle_book3s.S
ima_arch.c
interrupt.c powerpc/interrupt: Don't read MSR from interrupt_exit_kernel_prepare() 2023-06-09 23:29:51 +10:00
interrupt_64.S powerpc: Fix merge conflict between pcrel and copy_thread changes 2023-04-26 16:20:16 +10:00
io-workarounds.c
io.c
iomap.c
iommu.c powerpc/iommu: DMA address offset is incorrectly calculated with 2MB TCEs 2023-05-17 00:53:06 +10:00
irq.c powerpc/64: vmlinux support building with PCREL addresing 2023-04-20 12:59:21 +10:00
irq_64.c powerpc/64: Don't call trace_hardirqs_on() in prep_irq_for_idle() 2023-04-20 13:21:49 +10:00
isa-bridge.c powerpc/isa-bridge: Fix ISA mapping when "ranges" is not present 2023-05-08 22:57:10 +10:00
jump_label.c
kdebugfs.c
kgdb.c powerpc: add definition for pt_regs offset within an interrupt frame 2022-12-02 17:54:08 +11:00
kprobes-ftrace.c
kprobes.c powerpc updates for 6.2 2022-12-19 07:13:33 -06:00
kvm.c powerpc: Remove CONFIG_PPC_BOOK3E_MMU 2022-09-26 23:00:14 +10:00
kvm_emul.S
l2cr_6xx.S powerpc/mm: Switch obsolete dssall to .long 2021-12-23 22:35:13 +11:00
legacy_serial.c powerpc: Use of_property_read_bool() for boolean properties 2023-03-30 23:36:35 +11:00
Makefile powerpc/64: Rename entry_64.S to prom_entry_64.S 2023-06-15 14:04:19 +10:00
mce.c powerpc/mce: log the error for all unrecoverable errors 2023-02-10 22:17:34 +11:00
mce_power.c powerpc/inst: Define ppc_inst_t 2021-12-09 22:41:21 +11:00
misc.S
misc_32.S powerpc: allow minimum sized kernel stack frames 2022-12-02 17:54:09 +11:00
misc_64.S powerpc: add CFUNC assembly label annotation 2023-04-20 12:54:24 +10:00
module.c powerpc: Replace PPC64_ELF_ABI_v{1/2} by CONFIG_PPC64_ELF_ABI_V{1/2} 2022-05-19 23:11:29 +10:00
module_32.c module: replace module_layout with module_memory 2023-03-09 12:55:15 -08:00
module_64.c powerpc/64: modules support building with PCREL addresing 2023-04-20 13:21:42 +10:00
msi.c
note.S
nvram_64.c powerpc: Add missing headers 2022-05-08 22:15:40 +10:00
of_platform.c
optprobes.c powerpc/kprobes: Have optimized_callback() use preempt_enable() 2022-11-24 23:31:49 +11:00
optprobes_head.S powerpc: add definition for pt_regs offset within an interrupt frame 2022-12-02 17:54:08 +11:00
paca.c powerpc/64: vmlinux support building with PCREL addresing 2023-04-20 12:59:21 +10:00
pci-common.c PCI: Introduce pci_dev_for_each_resource() 2023-04-04 10:43:52 -05:00
pci-hotplug.c powerpc: Add missing headers 2022-05-08 22:15:40 +10:00
pci_32.c powerpc/pci: Add option for using pci_to_OF_bus_map 2023-02-07 20:15:23 +11:00
pci_64.c powerpc/pci_64: Init pcibios subsys a bit later 2023-03-14 23:36:27 +11:00
pci_dn.c powerpc/pci_dn: Add missing of_node_put() 2022-09-05 17:30:25 +10:00
pci_of_scan.c powerpc: Add missing headers 2022-05-08 22:15:40 +10:00
pmc.c
ppc_save_regs.S powerpc: update ppc_save_regs to save current r1 in pt_regs 2023-06-19 17:37:14 +10:00
proc_powerpc.c powerpc: Add missing headers 2022-05-08 22:15:40 +10:00
process.c powerpc/dexcr: Support userspace ROP protection 2023-06-19 17:36:26 +10:00
prom.c powerpc/dexcr: Add initial Dynamic Execution Control Register (DEXCR) support 2023-06-19 17:36:25 +10:00
prom_entry_64.S powerpc/64: Rename entry_64.S to prom_entry_64.S 2023-06-15 14:04:19 +10:00
prom_init.c powerpc/prom_init: drop PROM_BUG() 2022-09-26 20:58:18 +10:00
prom_init_check.sh kasan, powerpc: don't rename memintrinsics if compiler adds prefixes 2023-03-23 17:18:33 -07:00
prom_parse.c
reloc_32.S
reloc_64.S powerpc/64: avoid using r13 in relocate 2022-09-28 19:22:13 +10:00
rtas-proc.c powerpc/rtas: arch-wide function token lookup conversions 2023-02-13 22:35:03 +11:00
rtas-rtc.c powerpc/rtas: arch-wide function token lookup conversions 2023-02-13 22:35:03 +11:00
rtas.c powerpc/rtas: lockdep annotations 2023-03-30 23:36:35 +11:00
rtas_entry.S powerpc/rtas: Fix RTAS MSR[HV] handling for Cell 2022-08-26 08:41:54 +10:00
rtas_flash.c powerpc/rtas: arch-wide function token lookup conversions 2023-02-13 22:35:03 +11:00
rtas_pci.c powerpc/rtas: arch-wide function token lookup conversions 2023-02-13 22:35:03 +11:00
rtasd.c powerpc/rtas: arch-wide function token lookup conversions 2023-02-13 22:35:03 +11:00
secure_boot.c
security.c powerpc: Remove CONFIG_PPC_FSL_BOOK3E 2022-09-26 23:00:13 +10:00
secvar-ops.c powerpc/secvar: Warn and error if multiple secvar ops are set 2023-02-12 22:12:36 +11:00
secvar-sysfs.c powerpc/secvar: Don't print error on ENOENT when reading variables 2023-02-12 22:12:37 +11:00
setup-common.c powerpc/machdep: Define 'compatible' property in ppc_md and use it 2023-03-15 00:52:10 +11:00
setup.h powerpc: Remove CONFIG_PPC_BOOK3E 2022-09-26 23:00:13 +10:00
setup_32.c powerpc: Change CONFIG_E500 to CONFIG_PPC_E500 2022-09-26 23:00:13 +10:00
setup_64.c cpu: Mark panic_smp_self_stop() __noreturn 2023-04-14 17:31:25 +02:00
signal.c powerpc/signal: Report minimum signal frame size to userspace via AT_MINSIGSTKSZ 2022-05-19 23:11:26 +10:00
signal.h powerpc: Don't add __powerpc_ prefix to syscall entry points 2022-10-07 00:59:54 +11:00
signal_32.c powerpc/signal32: Force inlining of __unsafe_save_user_regs() and save_tm_user_regs_unsafe() 2023-06-09 23:29:51 +10:00
signal_64.c powerpc/signal: Update comment for clarity 2022-07-28 16:22:14 +10:00
smp-tbsync.c
smp.c SMP cross-CPU function-call updates for v6.4: 2023-04-28 15:03:43 -07:00
stacktrace.c powerpc: allow minimum sized kernel stack frames 2022-12-02 17:54:09 +11:00
static_call.c
suspend.c
switch.S powerpc: merge 32-bit and 64-bit _switch implementation 2023-06-15 14:03:55 +10:00
swsusp.c
swsusp_32.S powerpc/32: Fix objtool unannotated intra-function call warnings 2022-11-18 19:00:06 +11:00
swsusp_64.c
swsusp_85xx.S powerpc: Remove CONFIG_FSL_BOOKE 2022-09-26 22:47:37 +10:00
swsusp_asm64.S powerpc/64: asm use consistent global variable declaration and access 2022-09-28 19:22:12 +10:00
sys_ppc32.c powerpc/32: fix syscall wrappers with 64-bit arguments 2022-11-01 10:24:09 +11:00
syscall.c powerpc: Provide syscall wrapper 2022-09-28 19:22:09 +10:00
syscalls.c powerpc: Adopt SYSCALL_DEFINE for arch-specific syscall handlers 2022-09-28 19:22:08 +10:00
sysfs.c powerpc/sysfs: move to use bus_get_dev_root() 2023-03-17 15:29:34 +01:00
systbl.c powerpc: Don't add __powerpc_ prefix to syscall entry points 2022-10-07 00:59:54 +11:00
tau_6xx.c powerpc: Move C prototypes out of asm-prototypes.h 2022-03-08 22:06:25 +11:00
time.c powerpc: Make generic_calibrate_decr() the default 2023-03-16 08:56:48 +11:00
tm.S powerpc: add definition for pt_regs offset within an interrupt frame 2022-12-02 17:54:08 +11:00
traps.c powerpc/dexcr: Handle hashchk exception 2023-06-19 17:36:26 +10:00
ucall.S
udbg.c powerpc: Add support for early debugging via Serial 16550 console 2022-09-28 19:22:09 +10:00
udbg_16550.c powerpc: Add support for early debugging via Serial 16550 console 2022-09-28 19:22:09 +10:00
uprobes.c powerpc: Reject probes on instructions that can't be single stepped 2022-05-06 00:00:20 +10:00
vdso.c mm: remove zap_page_range and create zap_vma_pages 2023-01-18 17:12:55 -08:00
vdso32_wrapper.S powerpc/vdso: Merge vdso64 and vdso32 into a single directory 2022-02-12 22:47:43 +11:00
vdso64_wrapper.S powerpc/vdso: Merge vdso64 and vdso32 into a single directory 2022-02-12 22:47:43 +11:00
vecemu.c powerpc/inst: Define ppc_inst_t 2021-12-09 22:41:21 +11:00
vector.S powerpc/64: vmlinux support building with PCREL addresing 2023-04-20 12:59:21 +10:00
vmlinux.lds.S powerpc/64: vmlinux support building with PCREL addresing 2023-04-20 12:59:21 +10:00
watchdog.c powerpc/watchdog: introduce a NMI watchdog's factor 2022-07-27 21:36:02 +10:00