As reported by Alan, the CFI (Call Frame Information) in the VDSO time routines is incorrect since commit ce7d8056e38b ("powerpc/vdso: Prepare for switching VDSO to generic C implementation."). DWARF has a concept called the CFA (Canonical Frame Address), which on powerpc is calculated as an offset from the stack pointer (r1). That means when the stack pointer is changed there must be a corresponding CFI directive to update the calculation of the CFA. The current code is missing those directives for the changes to r1, which prevents gdb from being able to generate a backtrace from inside VDSO functions, eg: Breakpoint 1, 0x00007ffff7f804dc in __kernel_clock_gettime () (gdb) bt #0 0x00007ffff7f804dc in __kernel_clock_gettime () #1 0x00007ffff7d8872c in clock_gettime@@GLIBC_2.17 () from /lib64/libc.so.6 #2 0x00007fffffffd960 in ?? () #3 0x00007ffff7d8872c in clock_gettime@@GLIBC_2.17 () from /lib64/libc.so.6 Backtrace stopped: frame did not save the PC Alan helpfully describes some rules for correctly maintaining the CFI information: 1) Every adjustment to the current frame address reg (ie. r1) must be described, and exactly at the instruction where r1 changes. Why? Because stack unwinding might want to access previous frames. 2) If a function changes LR or any non-volatile register, the save location for those regs must be given. The CFI can be at any instruction after the saves up to the point that the reg is changed. (Exception: LR save should be described before a bl. not after) 3) If asychronous unwind info is needed then restores of LR and non-volatile regs must also be described. The CFI can be at any instruction after the reg is restored up to the point where the save location is (potentially) trashed. Fix the inability to backtrace by adding CFI directives describing the changes to r1, ie. satisfying rule 1. Also change the information for LR to point to the copy saved on the stack, not the value in r0 that will be overwritten by the function call. Finally, add CFI directives describing the save/restore of r2. With the fix gdb can correctly back trace and navigate up and down the stack: Breakpoint 1, 0x00007ffff7f804dc in __kernel_clock_gettime () (gdb) bt #0 0x00007ffff7f804dc in __kernel_clock_gettime () #1 0x00007ffff7d8872c in clock_gettime@@GLIBC_2.17 () from /lib64/libc.so.6 #2 0x0000000100015b60 in gettime () #3 0x000000010000c8bc in print_long_format () #4 0x000000010000d180 in print_current_files () #5 0x00000001000054ac in main () (gdb) up #1 0x00007ffff7d8872c in clock_gettime@@GLIBC_2.17 () from /lib64/libc.so.6 (gdb) #2 0x0000000100015b60 in gettime () (gdb) #3 0x000000010000c8bc in print_long_format () (gdb) #4 0x000000010000d180 in print_current_files () (gdb) #5 0x00000001000054ac in main () (gdb) Initial frame selected; you cannot go up. (gdb) down #4 0x000000010000d180 in print_current_files () (gdb) #3 0x000000010000c8bc in print_long_format () (gdb) #2 0x0000000100015b60 in gettime () (gdb) #1 0x00007ffff7d8872c in clock_gettime@@GLIBC_2.17 () from /lib64/libc.so.6 (gdb) #0 0x00007ffff7f804dc in __kernel_clock_gettime () (gdb) Fixes: ce7d8056e38b ("powerpc/vdso: Prepare for switching VDSO to generic C implementation.") Cc: stable@vger.kernel.org # v5.11+ Reported-by: Alan Modra <amodra@gmail.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Reviewed-by: Segher Boessenkool <segher@kernel.crashing.org> Link: https://lore.kernel.org/r/20220502125010.1319370-1-mpe@ellerman.id.au
130 lines
3.0 KiB
ArmAsm
130 lines
3.0 KiB
ArmAsm
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
/*
|
|
* Userland implementation of gettimeofday() for processes
|
|
* for use in the vDSO
|
|
*
|
|
* Copyright (C) 2004 Benjamin Herrenschmuidt (benh@kernel.crashing.org,
|
|
* IBM Corp.
|
|
*/
|
|
#include <asm/processor.h>
|
|
#include <asm/ppc_asm.h>
|
|
#include <asm/vdso.h>
|
|
#include <asm/vdso_datapage.h>
|
|
#include <asm/asm-offsets.h>
|
|
#include <asm/unistd.h>
|
|
|
|
/*
|
|
* The macro sets two stack frames, one for the caller and one for the callee
|
|
* because there are no requirement for the caller to set a stack frame when
|
|
* calling VDSO so it may have omitted to set one, especially on PPC64
|
|
*/
|
|
|
|
.macro cvdso_call funct call_time=0
|
|
.cfi_startproc
|
|
PPC_STLU r1, -PPC_MIN_STKFRM(r1)
|
|
.cfi_adjust_cfa_offset PPC_MIN_STKFRM
|
|
mflr r0
|
|
PPC_STLU r1, -PPC_MIN_STKFRM(r1)
|
|
.cfi_adjust_cfa_offset PPC_MIN_STKFRM
|
|
PPC_STL r0, PPC_MIN_STKFRM + PPC_LR_STKOFF(r1)
|
|
.cfi_rel_offset lr, PPC_MIN_STKFRM + PPC_LR_STKOFF
|
|
#ifdef __powerpc64__
|
|
PPC_STL r2, PPC_MIN_STKFRM + STK_GOT(r1)
|
|
.cfi_rel_offset r2, PPC_MIN_STKFRM + STK_GOT
|
|
#endif
|
|
get_datapage r5
|
|
.ifeq \call_time
|
|
addi r5, r5, VDSO_DATA_OFFSET
|
|
.else
|
|
addi r4, r5, VDSO_DATA_OFFSET
|
|
.endif
|
|
bl DOTSYM(\funct)
|
|
PPC_LL r0, PPC_MIN_STKFRM + PPC_LR_STKOFF(r1)
|
|
#ifdef __powerpc64__
|
|
PPC_LL r2, PPC_MIN_STKFRM + STK_GOT(r1)
|
|
.cfi_restore r2
|
|
#endif
|
|
.ifeq \call_time
|
|
cmpwi r3, 0
|
|
.endif
|
|
mtlr r0
|
|
addi r1, r1, 2 * PPC_MIN_STKFRM
|
|
.cfi_restore lr
|
|
.cfi_def_cfa_offset 0
|
|
crclr so
|
|
.ifeq \call_time
|
|
beqlr+
|
|
crset so
|
|
neg r3, r3
|
|
.endif
|
|
blr
|
|
.cfi_endproc
|
|
.endm
|
|
|
|
.text
|
|
/*
|
|
* Exact prototype of gettimeofday
|
|
*
|
|
* int __kernel_gettimeofday(struct timeval *tv, struct timezone *tz);
|
|
*
|
|
*/
|
|
V_FUNCTION_BEGIN(__kernel_gettimeofday)
|
|
cvdso_call __c_kernel_gettimeofday
|
|
V_FUNCTION_END(__kernel_gettimeofday)
|
|
|
|
/*
|
|
* Exact prototype of clock_gettime()
|
|
*
|
|
* int __kernel_clock_gettime(clockid_t clock_id, struct timespec *tp);
|
|
*
|
|
*/
|
|
V_FUNCTION_BEGIN(__kernel_clock_gettime)
|
|
cvdso_call __c_kernel_clock_gettime
|
|
V_FUNCTION_END(__kernel_clock_gettime)
|
|
|
|
/*
|
|
* Exact prototype of clock_gettime64()
|
|
*
|
|
* int __kernel_clock_gettime64(clockid_t clock_id, struct __timespec64 *ts);
|
|
*
|
|
*/
|
|
#ifndef __powerpc64__
|
|
V_FUNCTION_BEGIN(__kernel_clock_gettime64)
|
|
cvdso_call __c_kernel_clock_gettime64
|
|
V_FUNCTION_END(__kernel_clock_gettime64)
|
|
#endif
|
|
|
|
/*
|
|
* Exact prototype of clock_getres()
|
|
*
|
|
* int __kernel_clock_getres(clockid_t clock_id, struct timespec *res);
|
|
*
|
|
*/
|
|
V_FUNCTION_BEGIN(__kernel_clock_getres)
|
|
cvdso_call __c_kernel_clock_getres
|
|
V_FUNCTION_END(__kernel_clock_getres)
|
|
|
|
|
|
/*
|
|
* Exact prototype of time()
|
|
*
|
|
* time_t time(time *t);
|
|
*
|
|
*/
|
|
V_FUNCTION_BEGIN(__kernel_time)
|
|
cvdso_call __c_kernel_time call_time=1
|
|
V_FUNCTION_END(__kernel_time)
|
|
|
|
/* Routines for restoring integer registers, called by the compiler. */
|
|
/* Called with r11 pointing to the stack header word of the caller of the */
|
|
/* function, just beyond the end of the integer restore area. */
|
|
#ifndef __powerpc64__
|
|
_GLOBAL(_restgpr_31_x)
|
|
_GLOBAL(_rest32gpr_31_x)
|
|
lwz r0,4(r11)
|
|
lwz r31,-4(r11)
|
|
mtlr r0
|
|
mr r1,r11
|
|
blr
|
|
#endif
|