powerpc/64/bpf: fix tail calls for PCREL addressing
authorHari Bathini <hbathini@linux.ibm.com>
Thu, 2 May 2024 17:32:04 +0000 (23:02 +0530)
committerMichael Ellerman <mpe@ellerman.id.au>
Mon, 6 May 2024 12:05:18 +0000 (22:05 +1000)
commit2ecfe59cd7de1f202e9af2516a61fbbf93d0bd4d
tree26b5ae261b36c0c074b43aa26749c306f2958f58
parentfae573060c8da4d84a2551c6753d272abfda8ddc
powerpc/64/bpf: fix tail calls for PCREL addressing

With PCREL addressing, there is no kernel TOC. So, it is not setup in
prologue when PCREL addressing is used. But the number of instructions
to skip on a tail call was not adjusted accordingly. That resulted in
not so obvious failures while using tailcalls. 'tailcalls' selftest
crashed the system with the below call trace:

  bpf_test_run+0xe8/0x3cc (unreliable)
  bpf_prog_test_run_skb+0x348/0x778
  __sys_bpf+0xb04/0x2b00
  sys_bpf+0x28/0x38
  system_call_exception+0x168/0x340
  system_call_vectored_common+0x15c/0x2ec

Also, as bpf programs are always module addresses and a bpf helper in
general is a core kernel text address, using PC relative addressing
often fails with "out of range of pcrel address" error. Switch to
using kernel base for relative addressing to handle this better.

Fixes: 7e3a68be42e1 ("powerpc/64: vmlinux support building with PCREL addresing")
Cc: stable@vger.kernel.org # v6.4+
Signed-off-by: Hari Bathini <hbathini@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/20240502173205.142794-1-hbathini@linux.ibm.com
arch/powerpc/net/bpf_jit_comp64.c