Re: [RFC PATCH v1 7/7] powerpc/bpf: Implement extended BPF on PPC32
From: Andrii Nakryiko
Date: Fri Dec 18 2020 - 14:35:09 EST
On Thu, Dec 17, 2020 at 1:54 AM Christophe Leroy
<christophe.leroy@xxxxxxxxxx> wrote:
>
>
>
> Le 17/12/2020 à 07:11, Alexei Starovoitov a écrit :
> > On Wed, Dec 16, 2020 at 10:07:37AM +0000, Christophe Leroy wrote:
> >> Implement Extended Berkeley Packet Filter on Powerpc 32
> >>
> >> Test result with test_bpf module:
> >>
> >> test_bpf: Summary: 378 PASSED, 0 FAILED, [354/366 JIT'ed]
> >
> > nice!
> >
> >> Registers mapping:
> >>
> >> [BPF_REG_0] = r11-r12
> >> /* function arguments */
> >> [BPF_REG_1] = r3-r4
> >> [BPF_REG_2] = r5-r6
> >> [BPF_REG_3] = r7-r8
> >> [BPF_REG_4] = r9-r10
> >> [BPF_REG_5] = r21-r22 (Args 9 and 10 come in via the stack)
> >> /* non volatile registers */
> >> [BPF_REG_6] = r23-r24
> >> [BPF_REG_7] = r25-r26
> >> [BPF_REG_8] = r27-r28
> >> [BPF_REG_9] = r29-r30
> >> /* frame pointer aka BPF_REG_10 */
> >> [BPF_REG_FP] = r31
> >> /* eBPF jit internal registers */
> >> [BPF_REG_AX] = r19-r20
> >> [TMP_REG] = r18
> >>
> >> As PPC32 doesn't have a redzone in the stack,
> >> use r17 as tail call counter.
> >>
> >> r0 is used as temporary register as much as possible. It is referenced
> >> directly in the code in order to avoid misuse of it, because some
> >> instructions interpret it as value 0 instead of register r0
> >> (ex: addi, addis, stw, lwz, ...)
> >>
> >> 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 */
> >
> > Those are sensible limitations. MOD and DIV are rare, but XADD is common.
> > Please consider doing it as a cmpxchg loop in the future.
> >
> > Also please run test_progs. It will give a lot better coverage than test_bpf.ko
> >
>
> I'm having hard time cross building test_progs:
>
> ~/linux-powerpc/tools/testing/selftests/bpf/$ make CROSS_COMPILE=ppc-linux-
> ...
> GEN
> /home/chr/linux-powerpc/tools/testing/selftests/bpf/tools/build/bpftool/Documentation/bpf-helpers.7
> INSTALL eBPF_helpers-manpage
> INSTALL Documentation-man
> GEN vmlinux.h
> /bin/sh: /home/chr/linux-powerpc/tools/testing/selftests/bpf/tools/sbin/bpftool: cannot execute
> binary file
> make: *** [/home/chr/linux-powerpc/tools/testing/selftests/bpf/tools/include/vmlinux.h] Error 126
> make: *** Deleting file `/home/chr/linux-powerpc/tools/testing/selftests/bpf/tools/include/vmlinux.h'
>
> Looks like it builds bpftool for powerpc and tries to run it on my x86.
> How should I proceed ?
The best way would be to fix whatever needs to be fixed in
selftests/bpf and/or bpftool Makefiles to support cross-compilation.
There was some work already for bpftool to support that (with building
bpftool-bootstrap separately for a host architecture, etc). Please
check what's broken and let's try to fix it.
>
> Thanks
> Christophe