powerpc64/bpf: Optimize instruction sequence used for function calls
authorNaveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Mon, 14 Feb 2022 10:41:43 +0000 (16:11 +0530)
committerMichael Ellerman <mpe@ellerman.id.au>
Mon, 7 Mar 2022 13:04:58 +0000 (00:04 +1100)
commitfeb6307289d85262c5aed04d6f192d38abba7c45
tree20eb973dd96b2884a80092f46f79b3d51cd49363
parent43d636f8b4fd2ee668e75e835fae2fcf4bc0f699
powerpc64/bpf: Optimize instruction sequence used for function calls

When calling BPF helpers, we load the function address to call into a
register. This can result in upto 5 instructions. Optimize this by
instead using the kernel toc in r2 and adjusting offset to the BPF
helper. This works since all BPF helpers are part of kernel text, and
all BPF programs/functions utilize the kernel TOC.

Further more:
- load the actual function entry address in elf v1, rather than loading
  it through the function descriptor address.
- load the Local Entry Point (LEP) in elf v2 skipping TOC setup.
- consolidate code across elf abi v1 and v2 by using r12 on both.

Reported-by: Anton Blanchard <anton@ozlabs.org>
Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/1233c7544e60dcb021c52b1f840b0f21a87b33ed.1644834730.git.naveen.n.rao@linux.vnet.ibm.com
arch/powerpc/net/bpf_jit_comp64.c