bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next v2 0/4] Various RISC-V BPF improvements
@ 2021-10-28 16:10 Björn Töpel
  2021-10-28 16:10 ` [PATCH bpf-next v2 1/4] riscv, bpf: Increase the maximum number of iterations Björn Töpel
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Björn Töpel @ 2021-10-28 16:10 UTC (permalink / raw)
  To: ast, daniel, netdev, bpf
  Cc: Björn Töpel, luke.r.nels, xi.wang, linux-riscv

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
-- 
2.32.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH bpf-next v2 1/4] riscv, bpf: Increase the maximum number of iterations
  2021-10-28 16:10 [PATCH bpf-next v2 0/4] Various RISC-V BPF improvements Björn Töpel
@ 2021-10-28 16:10 ` Björn Töpel
  2021-10-28 16:10 ` [PATCH bpf-next v2 2/4] tools build: Add RISC-V to HOSTARCH parsing Björn Töpel
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Björn Töpel @ 2021-10-28 16:10 UTC (permalink / raw)
  To: ast, daniel, netdev, bpf
  Cc: Björn Töpel, luke.r.nels, xi.wang, linux-riscv

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.

Signed-off-by: Björn Töpel <bjorn@kernel.org>
---
 arch/riscv/net/bpf_jit_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/riscv/net/bpf_jit_core.c b/arch/riscv/net/bpf_jit_core.c
index 7ccc809f2c19..ef9fcf6ea749 100644
--- a/arch/riscv/net/bpf_jit_core.c
+++ b/arch/riscv/net/bpf_jit_core.c
@@ -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	32
 
 static int build_body(struct rv_jit_context *ctx, bool extra_pass, int *offset)
 {
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH bpf-next v2 2/4] tools build: Add RISC-V to HOSTARCH parsing
  2021-10-28 16:10 [PATCH bpf-next v2 0/4] Various RISC-V BPF improvements Björn Töpel
  2021-10-28 16:10 ` [PATCH bpf-next v2 1/4] riscv, bpf: Increase the maximum number of iterations Björn Töpel
@ 2021-10-28 16:10 ` Björn Töpel
  2021-10-28 16:10 ` [PATCH bpf-next v2 3/4] riscv, libbpf: Add RISC-V (RV64) support to bpf_tracing.h Björn Töpel
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Björn Töpel @ 2021-10-28 16:10 UTC (permalink / raw)
  To: ast, daniel, netdev, bpf
  Cc: Björn Töpel, luke.r.nels, xi.wang, linux-riscv

Add 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.

Signed-off-by: Björn Töpel <bjorn@kernel.org>
---
 tools/scripts/Makefile.arch | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/scripts/Makefile.arch b/tools/scripts/Makefile.arch
index b10b7a27c33f..0c6c7f456887 100644
--- a/tools/scripts/Makefile.arch
+++ b/tools/scripts/Makefile.arch
@@ -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)
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH bpf-next v2 3/4] riscv, libbpf: Add RISC-V (RV64) support to bpf_tracing.h
  2021-10-28 16:10 [PATCH bpf-next v2 0/4] Various RISC-V BPF improvements Björn Töpel
  2021-10-28 16:10 ` [PATCH bpf-next v2 1/4] riscv, bpf: Increase the maximum number of iterations Björn Töpel
  2021-10-28 16:10 ` [PATCH bpf-next v2 2/4] tools build: Add RISC-V to HOSTARCH parsing Björn Töpel
@ 2021-10-28 16:10 ` Björn Töpel
  2021-10-28 16:10 ` [PATCH bpf-next v2 4/4] selftests/bpf: Fix broken riscv build Björn Töpel
  2021-11-01 16:20 ` [PATCH bpf-next v2 0/4] Various RISC-V BPF improvements patchwork-bot+netdevbpf
  4 siblings, 0 replies; 6+ messages in thread
From: Björn Töpel @ 2021-10-28 16:10 UTC (permalink / raw)
  To: ast, daniel, netdev, bpf
  Cc: Björn Töpel, luke.r.nels, xi.wang, linux-riscv

Add macros for 64-bit RISC-V PT_REGS to bpf_tracing.h.

Signed-off-by: Björn Töpel <bjorn@kernel.org>
---
 tools/lib/bpf/bpf_tracing.h | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/tools/lib/bpf/bpf_tracing.h b/tools/lib/bpf/bpf_tracing.h
index d6bfbe009296..db05a5937105 100644
--- a/tools/lib/bpf/bpf_tracing.h
+++ b/tools/lib/bpf/bpf_tracing.h
@@ -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)
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH bpf-next v2 4/4] selftests/bpf: Fix broken riscv build
  2021-10-28 16:10 [PATCH bpf-next v2 0/4] Various RISC-V BPF improvements Björn Töpel
                   ` (2 preceding siblings ...)
  2021-10-28 16:10 ` [PATCH bpf-next v2 3/4] riscv, libbpf: Add RISC-V (RV64) support to bpf_tracing.h Björn Töpel
@ 2021-10-28 16:10 ` Björn Töpel
  2021-11-01 16:20 ` [PATCH bpf-next v2 0/4] Various RISC-V BPF improvements patchwork-bot+netdevbpf
  4 siblings, 0 replies; 6+ messages in thread
From: Björn Töpel @ 2021-10-28 16:10 UTC (permalink / raw)
  To: ast, daniel, netdev, bpf
  Cc: Björn Töpel, luke.r.nels, xi.wang, linux-riscv

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_LONG defaults to
32, unless explicitly set. Workaround this problem, by explicitly
setting __BITS_PER_LONG to __riscv_xlen.

Signed-off-by: Björn Töpel <bjorn@kernel.org>
---
 tools/testing/selftests/bpf/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index ac47cf9760fc..88e2a975352b 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -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.
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH bpf-next v2 0/4] Various RISC-V BPF improvements
  2021-10-28 16:10 [PATCH bpf-next v2 0/4] Various RISC-V BPF improvements Björn Töpel
                   ` (3 preceding siblings ...)
  2021-10-28 16:10 ` [PATCH bpf-next v2 4/4] selftests/bpf: Fix broken riscv build Björn Töpel
@ 2021-11-01 16:20 ` patchwork-bot+netdevbpf
  4 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-11-01 16:20 UTC (permalink / raw)
  To: =?utf-8?b?QmrDtnJuIFTDtnBlbCA8Ympvcm5Aa2VybmVsLm9yZz4=?=
  Cc: ast, daniel, netdev, bpf, luke.r.nels, xi.wang, linux-riscv

Hello:

This series was applied to bpf/bpf-next.git (master)
by Daniel Borkmann <daniel@iogearbox.net>:

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
> * Some Makefile issues
> * bpf_tracing.h was missing RISC-V macros for PT_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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-11-01 16:20 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-28 16:10 [PATCH bpf-next v2 0/4] Various RISC-V BPF improvements Björn Töpel
2021-10-28 16:10 ` [PATCH bpf-next v2 1/4] riscv, bpf: Increase the maximum number of iterations Björn Töpel
2021-10-28 16:10 ` [PATCH bpf-next v2 2/4] tools build: Add RISC-V to HOSTARCH parsing Björn Töpel
2021-10-28 16:10 ` [PATCH bpf-next v2 3/4] riscv, libbpf: Add RISC-V (RV64) support to bpf_tracing.h Björn Töpel
2021-10-28 16:10 ` [PATCH bpf-next v2 4/4] selftests/bpf: Fix broken riscv build Björn Töpel
2021-11-01 16:20 ` [PATCH bpf-next v2 0/4] Various RISC-V BPF improvements patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).