• Maciej Fijalkowski's avatar
    bpf: x64: Do not emit sub/add 0, %rsp when !stack_depth · 4d0b8c0b
    Maciej Fijalkowski authored
    There is no particular reason for keeping the "sub 0, %rsp" insn within
    the BPF's x64 JIT prologue.
    
    When tail call code was skipping the whole prologue section these 7
    bytes that represent the rsp subtraction could not be simply discarded
    as the jump target address would be broken. An option to address that
    would be to substitute it with nop7.
    
    Right now tail call is skipping only first 11 bytes of target program's
    prologue and "sub X, %rsp" is the first insn that is processed, so if
    stack depth is zero then this insn could be omitted without the need for
    nop7 swap.
    
    Therefore, do not emit the "sub 0, %rsp" in prologue when program is not
    making use of R10 register. Also, make the emission of "add X, %rsp"
    conditional in tail call code logic and take into account the presence
    of mentioned insn when calculating the jump offsets.
    Signed-off-by: default avatarMaciej Fijalkowski <maciej.fijalkowski@intel.com>
    Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
    Link: https://lore.kernel.org/bpf/20200929204653.4325-3-maciej.fijalkowski@intel.com
    4d0b8c0b
bpf_jit_comp.c 55.7 KB