21/01/2026 11:16, Marat Khalili: > Correctly align stack pointer on x86 JIT if external calls are present. > > According to x86-64 ABI (https://gitlab.com/x86-psABIs/x86-64-ABI, > section 3.2.2 The Stack Frame) stack needs to be 16 (or more) bytes > aligned immediately before the call instruction is executed. Once > control has been transferred to the function entry point it is always > off by 8 bytes. It means that JIT-compiled BPF function will always have > its stack misaligned for any nested call unless it performs operations > with the stack; even if it does use stack there is still 50% chance of > stack being misaligned since it uses it in multiples of 8. > > To solve the issue mark RBP as used whenever we have external function > calls, and align RSP using AND instruction at the end of the prolog. > Marking RBP as used triggers stack pointer saving in prolog and > restoration in epilog. > > Add tests for external calls from BPF program demonstrating the problem: > * direct verification of a local variable alignment; > * operations with 128-bit integers; > * aligned and unaligned SSE2 instructions; > * memcpy and rte_memcpy (may use vector instructions in their code). > > (Such variety is needed because not all of these tests are available or > reproduce the problem on all targets even when the problem exists.) > > Fixes: cc752e43e079 ("bpf: add JIT compilation for x86_64 ISA") > Cc: [email protected] > > Signed-off-by: Marat Khalili <[email protected]> > Acked-by: Konstantin Ananyev <[email protected]> > Tested-by: Konstantin Ananyev <[email protected]>
Applied, thanks.

