Skip to content
Commit 6a537453 authored by Joan Bruguera Micó's avatar Joan Bruguera Micó Committed by Alexei Starovoitov
Browse files

x86/bpf: Fix IP for relocating call depth accounting

The commit:

  59bec00a ("x86/percpu: Introduce %rip-relative addressing to PER_CPU_VAR()")

made PER_CPU_VAR() to use rip-relative addressing, hence
INCREMENT_CALL_DEPTH macro and skl_call_thunk_template got rip-relative
asm code inside of it. A follow up commit:

  17bce3b2 ("x86/callthunks: Handle %rip-relative relocations in call thunk template")

changed x86_call_depth_emit_accounting() to use apply_relocation(),
but mistakenly assumed that the code is being patched in-place (where
the destination of the relocation matches the address of the code),
using *pprog as the destination ip. This is not true for the call depth
accounting, emitted by the BPF JIT, so the calculated address was wrong,
JIT-ed BPF progs on kernels with call depth tracking got broken and
usually caused a page fault.

Pass the destination IP when the BPF JIT emits call depth accounting.

Fixes: 17bce3b2

 ("x86/callthunks: Handle %rip-relative relocations in call thunk template")
Signed-off-by: default avatarJoan Bruguera Micó <joanbrugueram@gmail.com>
Reviewed-by: default avatarUros Bizjak <ubizjak@gmail.com>
Acked-by: default avatarIngo Molnar <mingo@kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/r/20240401185821.224068-3-ubizjak@gmail.com
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent 9d98aa08
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment