Various RISC-V BPF improvements
Subsystems (9)
Björn Töpel
maintainercover Various RISC-V BPF improvements
Unfortunately selftest/bpf does not build for RV64. This series fixes that.
* JIT requires more iterations to converge
* Some Makefile issues
* bpf_tracing.h was missing RISC-V macros for PT_REGS
More details are in each commit.
There are still many failing tests, but this is a start.
Cheers,
Björn
Björn Töpel (4):
riscv, bpf: Increase the maximum number of iterations tools build: Add RISC-V to HOSTARCH parsing riscv, libbpf: Add RISC-V (RV64) support to bpf_tracing.h selftests/bpf: Fix broken riscv build
arch/riscv/net/bpf_jit_core.c | 2 +- tools/lib/bpf/bpf_tracing.h | 32 ++++++++++++++++++++++++++++ tools/scripts/Makefile.arch | 3 ++- tools/testing/selftests/bpf/Makefile | 3 ++- 4 files changed, 37 insertions(+), 3 deletions(-)
base-commit: b066abba3ef16a4a085d237e95da0de3f0b87713
Signature · 1 line
2.32.0
Björn Töpel
maintainerPATCH 1/4 riscv, bpf: Increase the maximum number of iterations
Now that BPF programs can be up to 1M instructions, it is not uncommon that a program requires more than the current 16 iterations to converge.
Bump it to 32, which is enough for selftests/bpf, and test_bpf.ko.
--- arch/riscv/net/bpf_jit_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/net/bpf_jit_core.c +1 -1
@@ -11,7 +11,7 @@#include "bpf_jit.h" /* Number of iterations to try until offsets converge. */ -#define NR_JIT_ITERATIONS 16 +#define NR_JIT_ITERATIONS 32static int build_body (struct rv_jit_context *ctx,bool extra_pass,int *offset) {
Signature · 1 line
2.32.0
Björn Töpel
maintainerPATCH 2/4 tools build: Add RISC-V to HOSTARCH parsing
In reply to Björn TöpelAdd RISC-V to the HOSTARCH parsing, so that ARCH is "riscv", and not "riscv32" or "riscv64".
This affects the perf and libbpf builds, so that arch specific includes are correctly picked up for RISC-V.
--- tools/scripts/Makefile.arch | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/scripts/Makefile.arch +2 -1
@@ -4,7 +4,8 @@ HOSTARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ \ -e /arm64/!s/arm.*/arm/ -e s/sa110/arm/ \ -e s/s390x/s390/ -e s/parisc64/parisc/ \ -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \ - -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ ) + -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ \ + -e s/riscv.*/riscv/) ifndef ARCH ARCH := $(HOSTARCH)
Signature · 1 line
2.32.0
Björn Töpel
maintainerPATCH 3/4 riscv, libbpf: Add RISC-V (RV64) support to bpf_tracing.h
In reply to Björn TöpelAdd macros for 64-bit RISC-V PT_REGS to bpf_tracing.h.
--- tools/lib/bpf/bpf_tracing.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
tools/lib/bpf/bpf_tracing.h +32 -0
@@ -24,6 +24,9 @@#elif defined(__TARGET_ARCH_sparc)#define bpf_target_sparc#define bpf_target_defined +#elif defined(__TARGET_ARCH_riscv) +#define bpf_target_riscv +#define bpf_target_defined#else /* Fall back to what the compiler says */
@@ -48,6 +51,9 @@#elif defined(__sparc__)#define bpf_target_sparc#define bpf_target_defined +#elif defined(__riscv) && __riscv_xlen ==64 +#define bpf_target_riscv +#define bpf_target_defined#endif /* no compiler target */ #endif
@@ -288,6 +294,32 @@ struct pt_regs;#define PT_REGS_IP_CORE (x) BPF_CORE_READ((x), pc)#endif +#elif defined(bpf_target_riscv) + +struct pt_regs ; +#define PT_REGS_RV const volatile struct user_regs_struct +#define PT_REGS_PARM1 (x) (((PT_REGS_RV *)(x))->a0) +#define PT_REGS_PARM2 (x) (((PT_REGS_RV *)(x))->a1) +#define PT_REGS_PARM3 (x) (((PT_REGS_RV *)(x))->a2) +#define PT_REGS_PARM4 (x) (((PT_REGS_RV *)(x))->a3) +#define PT_REGS_PARM5 (x) (((PT_REGS_RV *)(x))->a4) +#define PT_REGS_RET (x) (((PT_REGS_RV *)(x))->ra) +#define PT_REGS_FP (x) (((PT_REGS_RV *)(x))->s5) +#define PT_REGS_RC (x) (((PT_REGS_RV *)(x))->a5) +#define PT_REGS_SP (x) (((PT_REGS_RV *)(x))->sp) +#define PT_REGS_IP (x) (((PT_REGS_RV *)(x))->epc) + +#define PT_REGS_PARM1_CORE (x) BPF_CORE_READ((PT_REGS_RV *)(x), a0) +#define PT_REGS_PARM2_CORE (x) BPF_CORE_READ((PT_REGS_RV *)(x), a1) +#define PT_REGS_PARM3_CORE (x) BPF_CORE_READ((PT_REGS_RV *)(x), a2) +#define PT_REGS_PARM4_CORE (x) BPF_CORE_READ((PT_REGS_RV *)(x), a3) +#define PT_REGS_PARM5_CORE (x) BPF_CORE_READ((PT_REGS_RV *)(x), a4) +#define PT_REGS_RET_CORE (x) BPF_CORE_READ((PT_REGS_RV *)(x), ra) +#define PT_REGS_FP_CORE (x) BPF_CORE_READ((PT_REGS_RV *)(x), fp) +#define PT_REGS_RC_CORE (x) BPF_CORE_READ((PT_REGS_RV *)(x), a5) +#define PT_REGS_SP_CORE (x) BPF_CORE_READ((PT_REGS_RV *)(x), sp) +#define PT_REGS_IP_CORE (x) BPF_CORE_READ((PT_REGS_RV *)(x), epc) +#endif #if defined(bpf_target_powerpc)
Signature · 1 line
2.32.0
Björn Töpel
maintainerPATCH 4/4 selftests/bpf: Fix broken riscv build
In reply to Björn TöpelThis patch is closely related to commit 6016df8fe874 ("selftests/bpf:
Fix broken riscv build"). When clang includes the system include directories, but targeting BPF program, __BITS_PER_LONG defaults to 32, unless explicitly set. Workaround this problem, by explicitly setting __BITS_PER_LONG to __riscv_xlen.
--- tools/testing/selftests/bpf/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/Makefile +2 -1
@@ -277,7 +277,8 @@ $(RESOLVE_BTFIDS): $(HOST_BPFOBJ) | $(HOST_BUILD_DIR)/resolve_btfids \ define get_sys_includes $(shell $(1) -v -E - </dev/null 2>&1 \ | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') \ -$(shell $(1) -dM -E - </dev/null | grep '#define __riscv_xlen ' | sed 's/#define /-D/' | sed 's/ /=/') +$(shell $(1) -dM -E - </dev/null | grep '__riscv_xlen ' | awk '{printf("-D__riscv_xlen=%d -D__BITS_PER_LONG=%d", $$3, $$3)}') + endef # Determine target endianness.
Signature · 1 line
2.32.0
Re: [PATCH bpf-next 4/4] selftests/bpf: Fix broken riscv build
Quoted 17 lines · Björn Töpel
This patch is closely related to commit
6016df8fe874("selftests/bpf:
Fix broken riscv build"). When clang includes the system include directories, but targeting BPF program,__BITS_PER_LONGdefaults to 32, unless explicitly set. Workaround this problem, by explicitly setting__BITS_PER_LONGto__riscv_xlen.Signed-off-by Björn Töpel <[email protected]>--- tools/testing/selftests/bpf/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)tools/testing/selftests/bpf/Makefile +0
-0
tools/testing/selftests/bpf/Makefile $(RESOLVE_BTFIDS): $(HOST_BPFOBJ) | $(HOST_BUILD_DIR)/resolve_btfids \ · line 281
Quoted 6 lines
tools/testing/selftests/bpf/Makefile +2
-1@@ -277,7 +277,8 @@ $(RESOLVE_BTFIDS): $(HOST_BPFOBJ) | $(HOST_BUILD_DIR)/resolve_btfids \ define get_sys_includes $(shell $(1) -v -E - </dev/null 2>&1 \ | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') \ -$(shell $(1) -dM -E - </dev/null | grep '#define __riscv_xlen ' | sed 's/#define /-D/' | sed 's/ /=/') +$(shell $(1) -dM -E - </dev/null | grep '__riscv_xlen ' | awk '{printf("-D__riscv_xlen=%d -D__BITS_PER_LONG=%d", $$3, $$3)}') +
Argh, this messes things up. I'll spin a v2 with the extra NL removed.
Björn
Quoted 6 lines
tools/testing/selftests/bpf/Makefile +0
-1endef # Determine target endianness. --2.32.0