• Ilya Leoshkevich's avatar
    s390/bpf: Implement bpf_arch_text_poke() · f1d5df84
    Ilya Leoshkevich authored
    bpf_arch_text_poke() is used to hotpatch eBPF programs and trampolines.
    s390x has a very strict hotpatching restriction: the only thing that is
    allowed to be hotpatched is conditional branch mask.
    
    Take the same approach as commit de5012b4 ("s390/ftrace: implement
    hotpatching"): create a conditional jump to a "plt", which loads the
    target address from memory and jumps to it; then first patch this
    address, and then the mask.
    
    Trampolines (introduced in the next patch) respect the ftrace calling
    convention: the return address is in %r0, and %r1 is clobbered. With
    that in mind, bpf_arch_text_poke() does not differentiate between jumps
    and calls.
    
    However, there is a simple optimization for jumps (for the epilogue_ip
    case): if a jump already points to the destination, then there is no
    "plt" and we can just flip the mask.
    
    For simplicity, the "plt" template is defined in assembly, and its size
    is used to define C arrays. There doesn't seem to be a way to convey
    this size to C as a constant, so it's hardcoded and double-checked
    during runtime.
    Signed-off-by: default avatarIlya Leoshkevich <iii@linux.ibm.com>
    Link: https://lore.kernel.org/r/20230129190501.1624747-4-iii@linux.ibm.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
    f1d5df84
bpf_jit_comp.c 51.9 KB