Skip to contentSkip to conversation

selftests/bpf: Add support for MIPS systems

PATCH Superseded Tony Ambardar 4 participants 13 messages Jul 21, 2024 – Jul 23, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover selftests/bpf: Add support for MIPS systems

Hello,

This series includes two fixes to support builds targeting MIPS systems. The patches have been tested both with the kernel-patches/bpf CI and locally using mips64el-gcc/musl-libc and QEMU with an OpenWrt rootfs.

Patch 1 adds support for MIPS system includes when compiling BPF. Patch 2 fixes a MIPS GOT issue when linking uprobe_multi.

Feedback and suggestions for improvement are welcome!

Thanks,
Tony

Tony Ambardar (2):
selftests/bpf: Add missing system defines for mips selftests/bpf: Fix error linking uprobe_multi on mips

 tools/testing/selftests/bpf/Makefile | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/2 selftests/bpf: Add missing system defines for mips

Update get_sys_includes in Makefile with missing MIPS-related definitions to fix many, many compilation errors building selftests/bpf. The following added defines drive conditional logic in system headers for word-size and endianness selection:

MIPSEL, MIPSEB
_MIPS_SZPTR
_MIPS_SZLONG
_MIPS_SIM, _ABIO32, _ABIN32, _ABI64

---
 tools/testing/selftests/bpf/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/Makefile +2 -1
index 05b234248b38..a9c447c63fee 100644
@@ -396,7 +396,8 @@ define get_sys_includes
 $(shell $(1) $(2) -v -E - </dev/null 2>&1 \
 	| sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') \
 $(shell $(1) $(2) -dM -E - </dev/null | grep '__riscv_xlen ' | awk '{printf("-D__riscv_xlen=%d -D__BITS_PER_LONG=%d", $$3, $$3)}') \
-$(shell $(1) $(2) -dM -E - </dev/null | grep '__loongarch_grlen ' | awk '{printf("-D__BITS_PER_LONG=%d", $$3)}')
+$(shell $(1) $(2) -dM -E - </dev/null | grep '__loongarch_grlen ' | awk '{printf("-D__BITS_PER_LONG=%d", $$3)}') \
+$(shell $(1) $(2) -dM -E - </dev/null | grep -E 'MIPS(EL|EB)|_MIPS_SZ(PTR|LONG) |_MIPS_SIM |_ABI(O32|N32|64) ' | awk '{printf("-D%s=%s ", $$2, $$3)}')
 endef
 
 # Determine target endianness.
Signature · 1 line
2.34.1
#2 lore raw

PATCH 2/2 selftests/bpf: Fix error linking uprobe_multi on mips

In reply to Tony Ambardar

Linking uprobe_multi.c on mips64el fails due to relocation overflows, when the GOT entries required exceeds the default maximum. Add a specific CFLAGS (-mxgot) for uprobe_multi.c on MIPS that allows using a larger GOT and avoids errors such as:

/tmp/ccBTNQzv.o: in function `bench':
uprobe_multi.c:49:(.text+0x1d7720): relocation truncated to fit: R_MIPS_GOT_DISP against uprobe_multi_func_08188' uprobe_multi.c:49:(.text+0x1d7730): relocation truncated to fit: R_MIPS_GOT_DISP against uprobe_multi_func_08189'
...
collect2: error: ld returned 1 exit status

Fixes 519dfeaf5119 ("selftests/bpf: Add uprobe_multi test program")
---
 tools/testing/selftests/bpf/Makefile | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/Makefile +4 -1
index a9c447c63fee..0b4bfbc0ef68 100644
@@ -784,9 +784,12 @@ $(OUTPUT)/veristat: $(OUTPUT)/veristat.o
 	$(call msg,BINARY,,$@)
 	$(Q)$(CC) $(CFLAGS) $(LDFLAGS) $(filter %.a %.o,$^) $(LDLIBS) -o $@
 
+# Linking uprobe_multi can fail due to relocation overflows on mips.
+uprobe_multi.c-CFLAGS := $(if $(filter mips, $(ARCH)),-mxgot)
+
 $(OUTPUT)/uprobe_multi: uprobe_multi.c
 	$(call msg,BINARY,,$@)
-	$(Q)$(CC) $(CFLAGS) -O0 $(LDFLAGS) $^ $(LDLIBS) -o $@
+	$(Q)$(CC) $(CFLAGS) $($<-CFLAGS) -O0 $(LDFLAGS) $^ $(LDLIBS) -o $@
 
 EXTRA_CLEAN := $(SCRATCH_DIR) $(HOST_SCRATCH_DIR)			\
 	prog_tests/tests.h map_tests/tests.h verifier/tests.h		\
Signature · 1 line
2.34.1
#5 lore raw
In reply to Tony Ambardar
CI has tested the following submission:

Dear patch submitter,

CI has tested the following submission:

Status:     SUCCESS
Name:       [bpf-next,v1,0/2] selftests/bpf: Add support for MIPS systems
Patchwork:  https://patchwork.kernel.org/project/netdevbpf/list/?series=872744&state=*
Matrix:     https://github.com/kernel-patches/bpf/actions/runs/10026705403

No further action is necessary on your part.

Please note: this email is coming from an unmonitored mailbox. If you have questions or feedback, please reach out to the Meta Kernel CI team at [email protected].

#3 lore raw

Re: [PATCH bpf-next v1 2/2] selftests/bpf: Fix error linking uprobe_multi on mips

In reply to Tony Ambardar
Quoted 23 lines · Tony Ambardar

Linking uprobe_multi.c on mips64el fails due to relocation overflows, when the GOT entries required exceeds the default maximum. Add a specific CFLAGS (-mxgot) for uprobe_multi.c on MIPS that allows using a larger GOT and avoids errors such as:

/tmp/ccBTNQzv.o: in function `bench':
uprobe_multi.c:49:(.text+0x1d7720): relocation truncated to fit: R_MIPS_GOT_DISP against uprobe_multi_func_08188' uprobe_multi.c:49:(.text+0x1d7730): relocation truncated to fit: R_MIPS_GOT_DISP against uprobe_multi_func_08189'
...
collect2: error: ld returned 1 exit status

Fixes 519dfeaf5119 ("selftests/bpf: Add uprobe_multi test program")
---
 tools/testing/selftests/bpf/Makefile | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/Makefile +0 -0
index a9c447c63fee..0b4bfbc0ef68 100644

tools/testing/selftests/bpf/Makefile $(OUTPUT)/veristat: $(OUTPUT)/veristat.o · line 792

Quoted 10 lines
tools/testing/selftests/bpf/Makefile +4 -1
@@ -784,9 +784,12 @@ $(OUTPUT)/veristat: $(OUTPUT)/veristat.o
        $(call msg,BINARY,,$@)
        $(Q)$(CC) $(CFLAGS) $(LDFLAGS) $(filter %.a %.o,$^) $(LDLIBS) -o $@
 
+# Linking uprobe_multi can fail due to relocation overflows on mips.
+uprobe_multi.c-CFLAGS := $(if $(filter mips, $(ARCH)),-mxgot)
+
 $(OUTPUT)/uprobe_multi: uprobe_multi.c
        $(call msg,BINARY,,$@)
-       $(Q)$(CC) $(CFLAGS) -O0 $(LDFLAGS) $^ $(LDLIBS) -o $@
+       $(Q)$(CC) $(CFLAGS) $($<-CFLAGS) -O0 $(LDFLAGS) $^ $(LDLIBS) -o $@

this $($<-CFLAGS) approach is fragile, non-obvious and will break. But there is also no need for this, see:

$(OUTPUT)/bench: LDLIBS += -lm

make allows to override envvars on a per-target basis, so all you should need is:

$(OUTPUT)/uprobe_multi: CFLAGS += $(if $(filter mips, $(ARCH)),-mxgot) $(OUTPUT)/uprobe_multi: uprobe_multi.c
... the rest is the same with no change whatsoever ...

Quoted 6 lines
tools/testing/selftests/bpf/Makefile +0 -1
 EXTRA_CLEAN := $(SCRATCH_DIR) $(HOST_SCRATCH_DIR)                      \
        prog_tests/tests.h map_tests/tests.h verifier/tests.h           \
--

2.34.1

#4 lore raw

Re: [PATCH bpf-next v1 2/2] selftests/bpf: Fix error linking uprobe_multi on mips

Quoted 1 line · Andrii Nakryiko

On Sun, Jul 21, 2024 at 12:51 AM Tony Ambardar <[email protected]> wrote:

[...]

Quoted 19 lines

tools/testing/selftests/bpf/Makefile $(OUTPUT)/veristat: $(OUTPUT)/veristat.o · line 792

Quoted 13 lines
tools/testing/selftests/bpf/Makefile +4 -1
@@ -784,9 +784,12 @@ $(OUTPUT)/veristat: $(OUTPUT)/veristat.o
        $(call msg,BINARY,,$@)
        $(Q)$(CC) $(CFLAGS) $(LDFLAGS) $(filter %.a %.o,$^) $(LDLIBS) -o $@
 
+# Linking uprobe_multi can fail due to relocation overflows on mips.
+uprobe_multi.c-CFLAGS := $(if $(filter mips, $(ARCH)),-mxgot)
+
 $(OUTPUT)/uprobe_multi: uprobe_multi.c
        $(call msg,BINARY,,$@)
-       $(Q)$(CC) $(CFLAGS) -O0 $(LDFLAGS) $^ $(LDLIBS) -o $@
+       $(Q)$(CC) $(CFLAGS) $($<-CFLAGS) -O0 $(LDFLAGS) $^ $(LDLIBS) -o $@

this $($<-CFLAGS) approach is fragile, non-obvious and will break. But there is also no need for this, see:

$(OUTPUT)/bench: LDLIBS += -lm

Quoted 8 lines

make allows to override envvars on a per-target basis, so all you should need is:

$(OUTPUT)/uprobe_multi: CFLAGS += $(if $(filter mips, $(ARCH)),-mxgot) $(OUTPUT)/uprobe_multi: uprobe_multi.c
... the rest is the same with no change whatsoever ...

Great suggestion, thanks for pointing that out! I'll update and send v2.

Quoted 6 lines
Quoted 6 lines
tools/testing/selftests/bpf/Makefile +0 -1
 EXTRA_CLEAN := $(SCRATCH_DIR) $(HOST_SCRATCH_DIR)                      \
        prog_tests/tests.h map_tests/tests.h verifier/tests.h           \
--

2.34.1

#6 lore raw

v2 cover selftests/bpf: Add support for MIPS systems

In reply to Tony Ambardar

From: Tony Ambardar <[email protected]>

Hello,

This series includes two fixes to support builds targeting MIPS systems. The patches have been tested both with the kernel-patches/bpf CI and locally using mips64el-gcc/musl-libc and QEMU with an OpenWrt rootfs.

Patch 1 adds support for MIPS system includes when compiling BPF. Patch 2 fixes a MIPS GOT issue when linking uprobe_multi.

Feedback and suggestions for improvement are welcome!

Thanks,
Tony

v1->v2:
- improve CFLAGS handling per Andrii's suggestion

Tony Ambardar (2):
selftests/bpf: Add missing system defines for mips selftests/bpf: Fix error linking uprobe_multi on mips

 tools/testing/selftests/bpf/Makefile | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
Signature · 1 line
2.34.1
#7 lore raw

PATCH v2 1/2 selftests/bpf: Add missing system defines for mips

From: Tony Ambardar <[email protected]>

Update get_sys_includes in Makefile with missing MIPS-related definitions to fix many, many compilation errors building selftests/bpf. The following added defines drive conditional logic in system headers for word-size and endianness selection:

MIPSEL, MIPSEB
_MIPS_SZPTR
_MIPS_SZLONG
_MIPS_SIM, _ABIO32, _ABIN32, _ABI64

---
 tools/testing/selftests/bpf/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/Makefile +2 -1
index 3b638069446d..11fdf126cb7c 100644
@@ -396,7 +396,8 @@ define get_sys_includes
 $(shell $(1) $(2) -v -E - </dev/null 2>&1 \
 	| sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') \
 $(shell $(1) $(2) -dM -E - </dev/null | grep '__riscv_xlen ' | awk '{printf("-D__riscv_xlen=%d -D__BITS_PER_LONG=%d", $$3, $$3)}') \
-$(shell $(1) $(2) -dM -E - </dev/null | grep '__loongarch_grlen ' | awk '{printf("-D__BITS_PER_LONG=%d", $$3)}')
+$(shell $(1) $(2) -dM -E - </dev/null | grep '__loongarch_grlen ' | awk '{printf("-D__BITS_PER_LONG=%d", $$3)}') \
+$(shell $(1) $(2) -dM -E - </dev/null | grep -E 'MIPS(EL|EB)|_MIPS_SZ(PTR|LONG) |_MIPS_SIM |_ABI(O32|N32|64) ' | awk '{printf("-D%s=%s ", $$2, $$3)}')
 endef
 
 # Determine target endianness.
Signature · 1 line
2.34.1
#9 lore raw

PATCH v2 2/2 selftests/bpf: Fix error linking uprobe_multi on mips

In reply to Tony Ambardar

From: Tony Ambardar <[email protected]>

Linking uprobe_multi.c on mips64el fails due to relocation overflows, when the GOT entries required exceeds the default maximum. Add a specific CFLAGS (-mxgot) for uprobe_multi.c on MIPS that allows using a larger GOT and avoids errors such as:

/tmp/ccBTNQzv.o: in function `bench':
uprobe_multi.c:49:(.text+0x1d7720): relocation truncated to fit: R_MIPS_GOT_DISP against uprobe_multi_func_08188' uprobe_multi.c:49:(.text+0x1d7730): relocation truncated to fit: R_MIPS_GOT_DISP against uprobe_multi_func_08189'
...
collect2: error: ld returned 1 exit status

Fixes 519dfeaf5119 ("selftests/bpf: Add uprobe_multi test program")
---
 tools/testing/selftests/bpf/Makefile | 2 ++
 1 file changed, 2 insertions(+)
tools/testing/selftests/bpf/Makefile +2 -0
index 11fdf126cb7c..60a07605a162 100644
@@ -785,6 +785,8 @@ $(OUTPUT)/veristat: $(OUTPUT)/veristat.o
 	$(call msg,BINARY,,$@)
 	$(Q)$(CC) $(CFLAGS) $(LDFLAGS) $(filter %.a %.o,$^) $(LDLIBS) -o $@
 
+# Linking uprobe_multi can fail due to relocation overflows on mips.
+$(OUTPUT)/uprobe_multi: CFLAGS += $(if $(filter mips, $(ARCH)),-mxgot)
 $(OUTPUT)/uprobe_multi: uprobe_multi.c
 	$(call msg,BINARY,,$@)
 	$(Q)$(CC) $(CFLAGS) -O0 $(LDFLAGS) $^ $(LDLIBS) -o $@
Signature · 1 line
2.34.1
#10 lore raw

Re: [PATCH bpf-next v2 2/2] selftests/bpf: Fix error linking uprobe_multi on mips

CI has tested the following submission:

Dear patch submitter,

CI has tested the following submission:

Status:     SUCCESS
Name:       [bpf-next,v2,2/2] selftests/bpf: Fix error linking uprobe_multi on mips
Patchwork:  https://patchwork.kernel.org/project/netdevbpf/list/?series=873092&state=*
Matrix:     https://github.com/kernel-patches/bpf/actions/runs/10050383298

No further action is necessary on your part.

Please note: this email is coming from an unmonitored mailbox. If you have questions or feedback, please reach out to the Meta Kernel CI team at [email protected].

#11 lore raw

Re: [PATCH bpf-next v2 2/2] selftests/bpf: Fix error linking uprobe_multi on mips

In reply to Tony Ambardar
CI has tested the following submission:

Dear patch submitter,

CI has tested the following submission:

Status:     FAILURE
Name:       [bpf-next,v2,2/2] selftests/bpf: Fix error linking uprobe_multi on mips
Patchwork:  https://patchwork.kernel.org/project/netdevbpf/list/?series=873092&state=*
Matrix:     https://github.com/kernel-patches/bpf/actions/runs/10050686380

Failed jobs:
test_progs_no_alu32-aarch64-gcc: https://github.com/kernel-patches/bpf/actions/runs/10050686380/job/27779204312
test_progs_no_alu32-s390x-gcc: https://github.com/kernel-patches/bpf/actions/runs/10050686380/job/27779282003
test_progs_no_alu32-x86_64-gcc: https://github.com/kernel-patches/bpf/actions/runs/10050686380/job/27779242545
test_progs_no_alu32-x86_64-llvm-17: https://github.com/kernel-patches/bpf/actions/runs/10050686380/job/27779265515
test_progs_no_alu32-x86_64-llvm-18: https://github.com/kernel-patches/bpf/actions/runs/10050686380/job/27779280320

First test_progs failure (test_progs_no_alu32-aarch64-gcc):
#134 libbpf_get_fd_by_id_opts
libbpf: prog 'check_access': BPF program load failed: Invalid argument
libbpf: prog 'check_access': -- BEGIN PROG LOAD LOG --
0: R1=ctx() R10=fp0
; int BPF_PROG(check_access, struct bpf_map *map, fmode_t fmode) @ test_libbpf_get_fd_by_id_opts.c:27
0: (b7) r0 = 0 ; R0_w=0
1: (79) r2 = *(u64 *)(r1 +0)
func 'bpf_lsm_bpf_map' arg0 has btf_id 2072 type STRUCT 'bpf_map'
2: R1=ctx() R2_w=trusted_ptr_bpf_map()
; if (map != (struct bpf_map *)&data_input) @ test_libbpf_get_fd_by_id_opts.c:29
2: (18) r3 = 0xffff0000c4890c00 ; R3_w=map_ptr(map=data_input,ks=4,vs=4)
4: (5d) if r2 != r3 goto pc+4 ; R2_w=trusted_ptr_bpf_map() R3_w=map_ptr(map=data_input,ks=4,vs=4)
; int BPF_PROG(check_access, struct bpf_map *map, fmode_t fmode) @ test_libbpf_get_fd_by_id_opts.c:27
5: (79) r0 = *(u64 *)(r1 +8) ; R0_w=scalar() R1=ctx()
; if (fmode & FMODE_WRITE) @ test_libbpf_get_fd_by_id_opts.c:32
6: (67) r0 <<= 62 ; R0_w=scalar(smax=0x4000000000000000,umax=0xc000000000000000,smin32=0,smax32=umax32=0,var_off=(0x0; 0xc000000000000000))
7: (c7) r0 s>>= 63 ; R0_w=scalar(smin=smin32=-1,smax=smax32=0)
; @ test_libbpf_get_fd_by_id_opts.c:0
8: (57) r0 &= -13 ; R0_w=scalar(smax=0x7ffffffffffffff3,umax=0xfffffffffffffff3,smax32=0x7ffffff3,umax32=0xfffffff3,var_off=(0x0; 0xfffffffffffffff3))
; int BPF_PROG(check_access, struct bpf_map *map, fmode_t fmode) @ test_libbpf_get_fd_by_id_opts.c:27 9: (95) exit
At program exit the register R0 has smax=9223372036854775795 should have been in [-4095, 0] processed 9 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0 -- END PROG LOAD LOG --
libbpf: prog 'check_access': failed to load: -22
libbpf: failed to load object 'test_libbpf_get_fd_by_id_opts'
libbpf: failed to load BPF skeleton 'test_libbpf_get_fd_by_id_opts': -22 test_libbpf_get_fd_by_id_opts:FAIL:test_libbpf_get_fd_by_id_opts__open_and_load unexpected error: -22

Please note: this email is coming from an unmonitored mailbox. If you have questions or feedback, please reach out to the Meta Kernel CI team at [email protected].

#12 lore raw

Re: [PATCH bpf-next v2 2/2] selftests/bpf: Fix error linking uprobe_multi on mips

In reply to Tony Ambardar
CI has tested the following submission:

Dear patch submitter,

CI has tested the following submission:

Status:     SUCCESS
Name:       [bpf-next,v2,2/2] selftests/bpf: Fix error linking uprobe_multi on mips
Patchwork:  https://patchwork.kernel.org/project/netdevbpf/list/?series=873092&state=*
Matrix:     https://github.com/kernel-patches/bpf/actions/runs/10051521603

No further action is necessary on your part.

Please note: this email is coming from an unmonitored mailbox. If you have questions or feedback, please reach out to the Meta Kernel CI team at [email protected].

#8 lore raw

Re: [PATCH bpf-next v2 1/2] selftests/bpf: Add missing system defines for mips

In reply to Tony Ambardar
This series was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:

Hello:

This series was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:

Quoted 8 lines · On Mon, 22 Jul 2024 17:13:28 -0700 you wrote:

From: Tony Ambardar <[email protected]>

Update get_sys_includes in Makefile with missing MIPS-related definitions to fix many, many compilation errors building selftests/bpf. The following added defines drive conditional logic in system headers for word-size and endianness selection:

[...]

Here is the summary with links:
- [bpf-next,v2,1/2] selftests/bpf: Add missing system defines for mips

    https://git.kernel.org/bpf/bpf-next/c/84b4e873b10a
  - [bpf-next,v2,2/2] selftests/bpf: Fix error linking uprobe_multi on mips
    https://git.kernel.org/bpf/bpf-next/c/64d50da31564

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html