linux/arch/powerpc/net
Hari Bathini 23b51916ee bpf ppc32: Add BPF_PROBE_MEM support for JIT
BPF load instruction with BPF_PROBE_MEM mode can cause a fault
inside kernel. Append exception table for such instructions
within BPF program.

Unlike other archs which uses extable 'fixup' field to pass dest_reg
and nip, BPF exception table on PowerPC follows the generic PowerPC
exception table design, where it populates both fixup and extable
sections within BPF program. fixup section contains 3 instructions,
first 2 instructions clear dest_reg (lower & higher 32-bit registers)
and last instruction jumps to next instruction in the BPF code.
extable 'insn' field contains relative offset of the instruction and
'fixup' field contains relative offset of the fixup entry. Example
layout of BPF program with extable present:

             +------------------+
             |                  |
             |                  |
   0x4020 -->| lwz   r28,4(r4)  |
             |                  |
             |                  |
   0x40ac -->| lwz  r3,0(r24)   |
             | lwz  r4,4(r24)   |
             |                  |
             |                  |
             |------------------|
   0x4278 -->| li  r28,0        |  \
             | li  r27,0        |  | fixup entry
             | b   0x4024       |  /
   0x4284 -->| li  r4,0         |
             | li  r3,0         |
             | b   0x40b4       |
             |------------------|
   0x4290 -->| insn=0xfffffd90  |  \ extable entry
             | fixup=0xffffffe4 |  /
   0x4298 -->| insn=0xfffffe14  |
             | fixup=0xffffffe8 |
             +------------------+

   (Addresses shown here are chosen random, not real)

Signed-off-by: Hari Bathini <hbathini@linux.ibm.com>
Reviewed-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20211012123056.485795-8-hbathini@linux.ibm.com
2021-11-25 11:25:32 +11:00
..
bpf_jit64.h powerpc/bpf: Emit stf barrier instruction sequences for BPF_NOSPEC 2021-10-07 19:52:58 +11:00
bpf_jit_comp32.c bpf ppc32: Add BPF_PROBE_MEM support for JIT 2021-11-25 11:25:32 +11:00
bpf_jit_comp64.c bpf ppc64: Access only if addr is kernel address 2021-11-25 11:25:32 +11:00
bpf_jit_comp.c bpf ppc32: Add BPF_PROBE_MEM support for JIT 2021-11-25 11:25:32 +11:00
bpf_jit.h bpf ppc32: Add BPF_PROBE_MEM support for JIT 2021-11-25 11:25:32 +11:00
Makefile powerpc/bpf: Implement extended BPF on PPC32 2021-04-03 21:22:21 +11:00