]> www.infradead.org Git - users/hch/misc.git/commit
bpf, x86: Add x86 JIT support for timed may_goto
authorKumar Kartikeya Dwivedi <memxor@gmail.com>
Tue, 4 Mar 2025 00:32:39 +0000 (16:32 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Sat, 15 Mar 2025 18:48:28 +0000 (11:48 -0700)
commit2fb761823eadf2fdfb6fdf146c4b94807b4bc3ba
treeb109c094280af113cda230fce761407b94cd9127
parente723608bf428014b15d9904e062f44f5fe473ad6
bpf, x86: Add x86 JIT support for timed may_goto

Implement the arch_bpf_timed_may_goto function using inline assembly to
have control over which registers are spilled, and use our special
protocol of using BPF_REG_AX as an argument into the function, and as
the return value when going back.

Emit call depth accounting for the call made from this stub, and ensure
we don't have naked returns (when rethunk mitigations are enabled) by
falling back to the RET macro (instead of retq). After popping all saved
registers, the return address into the BPF program should be on top of
the stack.

Since the JIT support is now enabled, ensure selftests which are
checking the produced may_goto sequences do not break by adjusting them.
Make sure we still test the old may_goto sequence on other
architectures, while testing the new sequence on x86_64.

Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Link: https://lore.kernel.org/r/20250304003239.2390751-3-memxor@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
arch/x86/net/Makefile
arch/x86/net/bpf_jit_comp.c
arch/x86/net/bpf_timed_may_goto.S [new file with mode: 0644]
tools/testing/selftests/bpf/progs/verifier_bpf_fastcall.c
tools/testing/selftests/bpf/progs/verifier_may_goto_1.c