]> git.ipfire.org Git - thirdparty/linux.git/commit
s390/bpf: Implement bpf_arch_text_poke()
authorIlya Leoshkevich <iii@linux.ibm.com>
Sun, 29 Jan 2023 19:04:56 +0000 (20:04 +0100)
committerAlexei Starovoitov <ast@kernel.org>
Mon, 30 Jan 2023 03:16:28 +0000 (19:16 -0800)
commitf1d5df84cd8c3ec6460c78f5b86be7c84577a83f
tree306b5571011f42a5d67e5200982ad88eb545342f
parentbb4ef8fc3d193ed8d5583fb47cbeff5d8fb8302f
s390/bpf: Implement bpf_arch_text_poke()

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 de5012b41e5c ("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: Ilya Leoshkevich <iii@linux.ibm.com>
Link: https://lore.kernel.org/r/20230129190501.1624747-4-iii@linux.ibm.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
arch/s390/net/bpf_jit_comp.c