riscv, bpf: Add bpf_arch_text_poke support for RV64
authorPu Lehui <pulehui@huawei.com>
Wed, 15 Feb 2023 13:52:04 +0000 (21:52 +0800)
committerDaniel Borkmann <daniel@iogearbox.net>
Fri, 17 Feb 2023 20:45:30 +0000 (21:45 +0100)
commit596f2e6f9cf41436a5512a3f278c86da5c5598fb
tree379ec18fcd887274967b6b0d31c1ab3941b412c5
parent0fd1fd0104954380477353aea29c347e85dff16d
riscv, bpf: Add bpf_arch_text_poke support for RV64

Implement bpf_arch_text_poke for RV64. For call scenario, to make BPF
trampoline compatible with the kernel and BPF context, we follow the
framework of RV64 ftrace to reserve 4 nops for BPF programs as function
entry, and use auipc+jalr instructions for function call. However, since
auipc+jalr call instruction is non-atomic operation, we need to use
stop-machine to make sure instructions patching in atomic context. Also,
we use auipc+jalr pair and need to patch in stop-machine context for
jump scenario.

Signed-off-by: Pu Lehui <pulehui@huawei.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Tested-by: Björn Töpel <bjorn@rivosinc.com>
Acked-by: Björn Töpel <bjorn@rivosinc.com>
Link: https://lore.kernel.org/bpf/20230215135205.1411105-4-pulehui@huaweicloud.com
arch/riscv/net/bpf_jit.h
arch/riscv/net/bpf_jit_comp64.c