sst-linux/arch/x86
Andrii Nakryiko bd04497003 perf,x86: avoid missing caller address in stack traces captured in uprobe
[ Upstream commit cfa7f3d2c526c224a6271cc78a4a27a0de06f4f0 ]

When tracing user functions with uprobe functionality, it's common to
install the probe (e.g., a BPF program) at the first instruction of the
function. This is often going to be `push %rbp` instruction in function
preamble, which means that within that function frame pointer hasn't
been established yet. This leads to consistently missing an actual
caller of the traced function, because perf_callchain_user() only
records current IP (capturing traced function) and then following frame
pointer chain (which would be caller's frame, containing the address of
caller's caller).

So when we have target_1 -> target_2 -> target_3 call chain and we are
tracing an entry to target_3, captured stack trace will report
target_1 -> target_3 call chain, which is wrong and confusing.

This patch proposes a x86-64-specific heuristic to detect `push %rbp`
(`push %ebp` on 32-bit architecture) instruction being traced. Given
entire kernel implementation of user space stack trace capturing works
under assumption that user space code was compiled with frame pointer
register (%rbp/%ebp) preservation, it seems pretty reasonable to use
this instruction as a strong indicator that this is the entry to the
function. In that case, return address is still pointed to by %rsp/%esp,
so we fetch it and add to stack trace before proceeding to unwind the
rest using frame pointer-based logic.

We also check for `endbr64` (for 64-bit modes) as another common pattern
for function entry, as suggested by Josh Poimboeuf. Even if we get this
wrong sometimes for uprobes attached not at the function entry, it's OK
because stack trace will still be overall meaningful, just with one
extra bogus entry. If we don't detect this, we end up with guaranteed to
be missing caller function entry in the stack trace, which is worse
overall.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20240729175223.23914-1-andrii@kernel.org
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-10-17 15:21:46 +02:00
..
boot x86/boot: Don't add the EFI stub to targets, again 2024-06-21 14:35:53 +02:00
coco x86/tdx: Fix "in-kernel MMIO" check 2024-10-17 15:21:29 +02:00
configs
crypto crypto: x86/sha512-avx2 - add missing vzeroupper 2024-06-12 11:03:05 +02:00
entry x86/bhi: Avoid warning in #DB handler due to BHI mitigation 2024-07-18 13:18:44 +02:00
events perf,x86: avoid missing caller address in stack traces captured in uprobe 2024-10-17 15:21:46 +02:00
hyperv x86/hyperv: Fix the detection of E820_TYPE_PRAM in a Gen2 VM 2023-12-20 17:00:21 +01:00
ia32
include x86/syscall: Avoid memcpy() for ia32 syscall_get_arguments() 2024-10-17 15:21:41 +02:00
kernel x86/kexec: Add EFI config table identity mapping for kexec kernel 2024-10-17 15:21:41 +02:00
kvm KVM: x86: Move x2APIC ICR helper above kvm_apic_write_nodecode() 2024-10-17 15:21:17 +02:00
lib x86/kmsan: Fix hook for unaligned accesses 2024-09-12 11:10:19 +02:00
math-emu
mm x86/mm: Switch to new Intel CPU model defines 2024-09-30 16:23:56 +02:00
net x86/returnthunk: Allow different return thunks 2024-03-01 13:26:33 +01:00
pci x86/pci/xen: Fix PCIBIOS_* return code handling 2024-08-03 08:48:54 +02:00
platform x86/platform/iosf_mbi: Convert PCIBIOS_* return codes to errnos 2024-08-03 08:48:54 +02:00
power
purgatory x86/purgatory: Switch to the position-independent small code model 2024-06-12 11:03:12 +02:00
ras
realmode
tools x86/boot: Ignore relocations in .notes sections in walk_relocs() too 2024-06-12 11:03:07 +02:00
um um: Fix the -Wmissing-prototypes warning for get_thread_reg 2024-06-12 11:03:47 +02:00
video
virt/vmx/tdx
xen xen: use correct end address of kernel for conflict checking 2024-10-17 15:20:54 +02:00
.gitignore
Kbuild
Kconfig cpu: Re-enable CPU mitigations by default for !X86 architectures 2024-05-02 16:29:28 +02:00
Kconfig.assembler
Kconfig.cpu x86/Kconfig: Transmeta Crusoe is CPU family 5, not 6 2024-02-23 09:12:43 +01:00
Kconfig.debug x86/kconfig: Select ARCH_WANT_FRAME_POINTERS again when UNWINDER_FRAME_POINTER=y 2024-06-12 11:03:50 +02:00
Makefile
Makefile_32.cpu
Makefile.um