Various RISC-V BPF improvements
Subsystems (9)
Björn Töpel
maintainerv2 cover 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
v1->v2: A newline sneaked into the Makefile for patch 4, which broke the build. Removed.
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 | 2 +- 4 files changed, 36 insertions(+), 3 deletions(-)
base-commit: b066abba3ef16a4a085d237e95da0de3f0b87713
Signature · 1 line
2.32.0
Björn Töpel
maintainerPATCH v2 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 v2 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 v2 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 v2 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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/Makefile +1 -1
@@ -277,7 +277,7 @@ $(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
This series was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:
Hello:
This series was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:
Quoted 8 lines · On Thu, 28 Oct 2021 18:10:53 +0200 you wrote:
Unfortunately selftest/bpf does not build for RV64. This series fixes that.
* JIT requires more iterations to converge
* SomeMakefileissues
*bpf_tracing.hwas missing RISC-V macros forPT_REGS[...]
Here is the summary with links:
- [bpf-next,v2,1/4] riscv, bpf: Increase the maximum number of iterations
https://git.kernel.org/bpf/bpf-next/c/4b54214f39ff - [bpf-next,v2,2/4] tools build: Add RISC-V to HOSTARCH parsing https://git.kernel.org/bpf/bpf-next/c/b390d69831ee - [bpf-next,v2,3/4] riscv, libbpf: Add RISC-V (RV64) support to bpf_tracing.h https://git.kernel.org/bpf/bpf-next/c/589fed479ba1 - [bpf-next,v2,4/4] selftests/bpf: Fix broken riscv build https://git.kernel.org/bpf/bpf-next/c/36e70b9b06bf
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html