• Kumar Kartikeya Dwivedi's avatar
    arch/x86: Implement arch_bpf_stack_walk · fd5d27b7
    Kumar Kartikeya Dwivedi authored
    The plumbing for offline unwinding when we throw an exception in
    programs would require walking the stack, hence introduce a new
    arch_bpf_stack_walk function. This is provided when the JIT supports
    exceptions, i.e. bpf_jit_supports_exceptions is true. The arch-specific
    code is really minimal, hence it should be straightforward to extend
    this support to other architectures as well, as it reuses the logic of
    arch_stack_walk, but allowing access to unwind_state data.
    
    Once the stack pointer and frame pointer are known for the main subprog
    during the unwinding, we know the stack layout and location of any
    callee-saved registers which must be restored before we return back to
    the kernel. This handling will be added in the subsequent patches.
    
    Note that while we primarily unwind through BPF frames, which are
    effectively CONFIG_UNWINDER_FRAME_POINTER, we still need one of this or
    CONFIG_UNWINDER_ORC to be able to unwind through the bpf_throw frame
    from which we begin walking the stack. We also require both sp and bp
    (stack and frame pointers) from the unwind_state structure, which are
    only available when one of these two options are enabled.
    Signed-off-by: default avatarKumar Kartikeya Dwivedi <memxor@gmail.com>
    Link: https://lore.kernel.org/r/20230912233214.1518551-3-memxor@gmail.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
    fd5d27b7
bpf_jit_comp.c 80 KB