mbox series

[v2,0/8] Implement EBPF on powerpc32

Message ID cover.1616430991.git.christophe.leroy@csgroup.eu
Headers show
Series Implement EBPF on powerpc32 | expand

Message

Christophe Leroy March 22, 2021, 4:37 p.m. UTC
This series implements extended BPF on powerpc32. For the implementation
details, see the patch before the last.

The following operations are not implemented:

		case BPF_ALU64 | BPF_DIV | BPF_X: /* dst /= src */
		case BPF_ALU64 | BPF_MOD | BPF_X: /* dst %= src */
		case BPF_STX | BPF_XADD | BPF_DW: /* *(u64 *)(dst + off) += src */

The following operations are only implemented for power of two constants:

		case BPF_ALU64 | BPF_MOD | BPF_K: /* dst %= imm */
		case BPF_ALU64 | BPF_DIV | BPF_K: /* dst /= imm */

Below are the results on a powerpc 885:
- with the patch, with and without bpf_jit_enable
- without the patch, with bpf_jit_enable (ie with CBPF)

With the patch, with bpf_jit_enable = 1 :

[   60.826529] test_bpf: Summary: 378 PASSED, 0 FAILED, [354/366 JIT'ed]
[   60.832505] test_bpf: test_skb_segment: Summary: 2 PASSED, 0 FAILED

With the patch, with bpf_jit_enable = 0 :

[   75.186337] test_bpf: Summary: 378 PASSED, 0 FAILED, [0/366 JIT'ed]
[   75.192325] test_bpf: test_skb_segment: Summary: 2 PASSED, 0 FAILED

Without the patch, with bpf_jit_enable = 1 :

[  186.112429] test_bpf: Summary: 371 PASSED, 7 FAILED, [119/366 JIT'ed]

Couldn't run test_progs because it doesn't build (clang 11 crashes during the build).

Changes in v2:
- Simplify 16 bits swap
- Rework tailcall, use stack for tailcall counter
- Fix handling of BPF_REG_FP:
  - must be handler like any other register allthough only the lower 32 bits part is used as a pointer.
  - r18 was TMP_REG, r17/r18 become de BPF_REG_FP
  - r31 was BPF_REG_FP, it is now TMP_REG
- removed bpf_jit32.h
- Reorder register allocation dynamically to use the volatile registers as much as possible when not doing function calls (last patch - new)

Christophe Leroy (8):
  powerpc/bpf: Remove classical BPF support for PPC32
  powerpc/bpf: Change register numbering for bpf_set/is_seen_register()
  powerpc/bpf: Move common helpers into bpf_jit.h
  powerpc/bpf: Move common functions into bpf_jit_comp.c
  powerpc/bpf: Change values of SEEN_ flags
  powerpc/asm: Add some opcodes in asm/ppc-opcode.h for PPC32 eBPF
  powerpc/bpf: Implement extended BPF on PPC32
  powerpc/bpf: Reallocate BPF registers to volatile registers when
    possible on PPC32

 Documentation/admin-guide/sysctl/net.rst |    2 +-
 arch/powerpc/Kconfig                     |    3 +-
 arch/powerpc/include/asm/ppc-opcode.h    |   12 +
 arch/powerpc/net/Makefile                |    6 +-
 arch/powerpc/net/bpf_jit.h               |   61 ++
 arch/powerpc/net/bpf_jit32.h             |  139 ---
 arch/powerpc/net/bpf_jit64.h             |   21 +-
 arch/powerpc/net/bpf_jit_asm.S           |  226 -----
 arch/powerpc/net/bpf_jit_comp.c          |  782 ++++-----------
 arch/powerpc/net/bpf_jit_comp32.c        | 1095 ++++++++++++++++++++++
 arch/powerpc/net/bpf_jit_comp64.c        |  295 +-----
 11 files changed, 1372 insertions(+), 1270 deletions(-)
 delete mode 100644 arch/powerpc/net/bpf_jit32.h
 delete mode 100644 arch/powerpc/net/bpf_jit_asm.S
 create mode 100644 arch/powerpc/net/bpf_jit_comp32.c

Comments

Christophe Leroy March 26, 2021, 2:41 p.m. UTC | #1
Le 22/03/2021 à 18:53, Andrii Nakryiko a écrit :
> On Mon, Mar 22, 2021 at 9:37 AM Christophe Leroy

> <christophe.leroy@csgroup.eu> wrote:

>>

>> This series implements extended BPF on powerpc32. For the implementation

>> details, see the patch before the last.

>>

>> The following operations are not implemented:

>>

>>                  case BPF_ALU64 | BPF_DIV | BPF_X: /* dst /= src */

>>                  case BPF_ALU64 | BPF_MOD | BPF_X: /* dst %= src */

>>                  case BPF_STX | BPF_XADD | BPF_DW: /* *(u64 *)(dst + off) += src */

>>

>> The following operations are only implemented for power of two constants:

>>

>>                  case BPF_ALU64 | BPF_MOD | BPF_K: /* dst %= imm */

>>                  case BPF_ALU64 | BPF_DIV | BPF_K: /* dst /= imm */

>>

>> Below are the results on a powerpc 885:

>> - with the patch, with and without bpf_jit_enable

>> - without the patch, with bpf_jit_enable (ie with CBPF)

>>

>> With the patch, with bpf_jit_enable = 1 :

>>

>> [   60.826529] test_bpf: Summary: 378 PASSED, 0 FAILED, [354/366 JIT'ed]

>> [   60.832505] test_bpf: test_skb_segment: Summary: 2 PASSED, 0 FAILED

>>

>> With the patch, with bpf_jit_enable = 0 :

>>

>> [   75.186337] test_bpf: Summary: 378 PASSED, 0 FAILED, [0/366 JIT'ed]

>> [   75.192325] test_bpf: test_skb_segment: Summary: 2 PASSED, 0 FAILED

>>

>> Without the patch, with bpf_jit_enable = 1 :

>>

>> [  186.112429] test_bpf: Summary: 371 PASSED, 7 FAILED, [119/366 JIT'ed]

>>

>> Couldn't run test_progs because it doesn't build (clang 11 crashes during the build).

> 

> Can you please try checking out the latest clang from sources and use

> that one instead?


The crash is fixed, it builds one step more, then fails at:

[root@PC-server-ldb bpf]# make CROSS_COMPILE=ppc-linux- ARCH=powerpc V=1
/root/gen_ldb/linux-powerpc/tools/testing/selftests/bpf/host-tools/sbin/bpftool gen skeleton 
/root/gen_ldb/linux-powerpc/tools/testing/selftests/bpf/atomic_bounds.o > 
/root/gen_ldb/linux-powerpc/tools/testing/selftests/bpf/atomic_bounds.skel.h
libbpf: elf: endianness mismatch in atomic_bounds.
Error: failed to open BPF object file: Endian mismatch

I'm cross-building on x86 for powerpc/32

[root@PC-server-ldb bpf]# file atomic_bounds.o
atomic_bounds.o: ELF 64-bit MSB relocatable, eBPF, version 1 (SYSV), with debug_info, not stripped

Christophe
Andrii Nakryiko March 26, 2021, 6:09 p.m. UTC | #2
On Fri, Mar 26, 2021 at 7:42 AM Christophe Leroy
<christophe.leroy@csgroup.eu> wrote:
>

>

>

> Le 22/03/2021 à 18:53, Andrii Nakryiko a écrit :

> > On Mon, Mar 22, 2021 at 9:37 AM Christophe Leroy

> > <christophe.leroy@csgroup.eu> wrote:

> >>

> >> This series implements extended BPF on powerpc32. For the implementation

> >> details, see the patch before the last.

> >>

> >> The following operations are not implemented:

> >>

> >>                  case BPF_ALU64 | BPF_DIV | BPF_X: /* dst /= src */

> >>                  case BPF_ALU64 | BPF_MOD | BPF_X: /* dst %= src */

> >>                  case BPF_STX | BPF_XADD | BPF_DW: /* *(u64 *)(dst + off) += src */

> >>

> >> The following operations are only implemented for power of two constants:

> >>

> >>                  case BPF_ALU64 | BPF_MOD | BPF_K: /* dst %= imm */

> >>                  case BPF_ALU64 | BPF_DIV | BPF_K: /* dst /= imm */

> >>

> >> Below are the results on a powerpc 885:

> >> - with the patch, with and without bpf_jit_enable

> >> - without the patch, with bpf_jit_enable (ie with CBPF)

> >>

> >> With the patch, with bpf_jit_enable = 1 :

> >>

> >> [   60.826529] test_bpf: Summary: 378 PASSED, 0 FAILED, [354/366 JIT'ed]

> >> [   60.832505] test_bpf: test_skb_segment: Summary: 2 PASSED, 0 FAILED

> >>

> >> With the patch, with bpf_jit_enable = 0 :

> >>

> >> [   75.186337] test_bpf: Summary: 378 PASSED, 0 FAILED, [0/366 JIT'ed]

> >> [   75.192325] test_bpf: test_skb_segment: Summary: 2 PASSED, 0 FAILED

> >>

> >> Without the patch, with bpf_jit_enable = 1 :

> >>

> >> [  186.112429] test_bpf: Summary: 371 PASSED, 7 FAILED, [119/366 JIT'ed]

> >>

> >> Couldn't run test_progs because it doesn't build (clang 11 crashes during the build).

> >

> > Can you please try checking out the latest clang from sources and use

> > that one instead?

>

> The crash is fixed, it builds one step more, then fails at:

>

> [root@PC-server-ldb bpf]# make CROSS_COMPILE=ppc-linux- ARCH=powerpc V=1

> /root/gen_ldb/linux-powerpc/tools/testing/selftests/bpf/host-tools/sbin/bpftool gen skeleton

> /root/gen_ldb/linux-powerpc/tools/testing/selftests/bpf/atomic_bounds.o >

> /root/gen_ldb/linux-powerpc/tools/testing/selftests/bpf/atomic_bounds.skel.h

> libbpf: elf: endianness mismatch in atomic_bounds.

> Error: failed to open BPF object file: Endian mismatch

>

> I'm cross-building on x86 for powerpc/32


yeah, I'm not sure selftests/bpf supports cross-compiling. bpftool got
some patches recently to enable cross-compiling, but probably not
selftests/bpf.

>

> [root@PC-server-ldb bpf]# file atomic_bounds.o

> atomic_bounds.o: ELF 64-bit MSB relocatable, eBPF, version 1 (SYSV), with debug_info, not stripped

>

> Christophe
Michael Ellerman April 10, 2021, 2:28 p.m. UTC | #3
On Mon, 22 Mar 2021 16:37:45 +0000 (UTC), Christophe Leroy wrote:
> This series implements extended BPF on powerpc32. For the implementation

> details, see the patch before the last.

> 

> The following operations are not implemented:

> 

> 		case BPF_ALU64 | BPF_DIV | BPF_X: /* dst /= src */

> 		case BPF_ALU64 | BPF_MOD | BPF_X: /* dst %= src */

> 		case BPF_STX | BPF_XADD | BPF_DW: /* *(u64 *)(dst + off) += src */

> 

> [...]


Applied to powerpc/next.

[1/8] powerpc/bpf: Remove classical BPF support for PPC32
      https://git.kernel.org/powerpc/c/6944caad78fc4de4ecd0364bbc9715b62b020965
[2/8] powerpc/bpf: Change register numbering for bpf_set/is_seen_register()
      https://git.kernel.org/powerpc/c/ed573b57e77a7860fe4026e1700faa2f6938caf1
[3/8] powerpc/bpf: Move common helpers into bpf_jit.h
      https://git.kernel.org/powerpc/c/f1b1583d5faa86cb3dcb7b740594868debad7c30
[4/8] powerpc/bpf: Move common functions into bpf_jit_comp.c
      https://git.kernel.org/powerpc/c/4ea76e90a97d22f86adbb10044d29d919e620f2e
[5/8] powerpc/bpf: Change values of SEEN_ flags
      https://git.kernel.org/powerpc/c/c426810fcf9f96e3b43d16039e41ecb959f6dc29
[6/8] powerpc/asm: Add some opcodes in asm/ppc-opcode.h for PPC32 eBPF
      https://git.kernel.org/powerpc/c/355a8d26cd0416e7e764e4db766cf91e773a03e7
[7/8] powerpc/bpf: Implement extended BPF on PPC32
      https://git.kernel.org/powerpc/c/51c66ad849a703d9bbfd7704c941827aed0fd9fd
[8/8] powerpc/bpf: Reallocate BPF registers to volatile registers when possible on PPC32
      https://git.kernel.org/powerpc/c/40272035e1d0edcd515ad45be297c4cce044536d

cheers