LoongArch: BPF: Support 64-bit pointers to kfuncs
Subsystems (3)
Hengqi Chen
reviewerPATCH 1/1 LoongArch: BPF: Support 64-bit pointers to kfuncs
Like commit 1cf3bfc60f98 ("bpf: Support 64-bit pointers to kfuncs") for s390x, add support for 64-bit pointers to kfuncs for LoongArch. Since the infrastructure is already implemented in BPF core, the only thing need to be done is to override bpf_jit_supports_far_kfunc_call().
Before this change, several test_verifier tests failed:
# ./test_verifier | grep # | grep FAIL #119/p calls: invalid kfunc call: ptr_to_mem to struct with non-scalar FAIL #120/p calls: invalid kfunc call: ptr_to_mem to struct with nesting depth > 4 FAIL #121/p calls: invalid kfunc call: ptr_to_mem to struct with FAM FAIL #122/p calls: invalid kfunc call: reg->type != PTR_TO_CTX FAIL #123/p calls: invalid kfunc call: void * not allowed in func proto without mem size arg FAIL #124/p calls: trigger reg2btf_ids[reg->type] for reg->type > __BPF_REG_TYPE_MAX FAIL #125/p calls: invalid kfunc call: reg->off must be zero when passed to release kfunc FAIL #126/p calls: invalid kfunc call: don't match first member type when passed to release kfunc FAIL #127/p calls: invalid kfunc call: PTR_TO_BTF_ID with negative offset FAIL #128/p calls: invalid kfunc call: PTR_TO_BTF_ID with variable offset FAIL #129/p calls: invalid kfunc call: referenced arg needs refcounted PTR_TO_BTF_ID FAIL #130/p calls: valid kfunc call: referenced arg needs refcounted PTR_TO_BTF_ID FAIL #486/p map_kptr: ref: reference state created and released on xchg FAIL
This is because the kfuncs in the loaded module are far away from __bpf_call_base:
ffff800002009440 t bpf_kfunc_call_test_fail1 [bpf_testmod]
9000000002e128d8 T __bpf_call_base
The offset relative to __bpf_call_base does NOT fit in s32, which breaks the assumption in BPF core. Enable bpf_jit_supports_far_kfunc_call() lifts this limit.
With this change, the test_verifier tests now all passed:
# ./test_verifier ... Summary: 777 PASSED, 0 SKIPPED, 0 FAILED
--- arch/loongarch/net/bpf_jit.c | 5 +++++ 1 file changed, 5 insertions(+)
arch/loongarch/net/bpf_jit.c +5 -0
@@ -201,6 +201,11 @@ bool bpf_jit_supports_kfunc_call(void)return true; } +bool bpf_jit_supports_far_kfunc_call (void ) +{ +return true; +} +/* initialized on the first pass of build_body() */ static int out_offset =-1 ;static int emit_bpf_tail_call (struct jit_ctx *ctx)
Signature · 1 line
2.27.0
Hi Hengqi,
Thanks for the patch, sorry for the late reply.
Quoted 8 lines · Hengqi Chen
Like commit
1cf3bfc60f98("bpf: Support 64-bit pointers to kfuncs") for s390x, add support for 64-bit pointers to kfuncs for LoongArch. Since the infrastructure is already implemented in BPF core, the only thing need to be done is to overridebpf_jit_supports_far_kfunc_call().Before this change, several
test_verifiertests failed:# ./test_verifier | grep # | grep FAIL
[root@linux bpf]# ./test_verifier | grep # | grep FAIL
Usage: grep [OPTION]... PATTERNS [FILE]... Try 'grep --help' for more information.
It should be:
[root@linux bpf]# ./test_verifier | grep "#" | grep FAIL
Quoted 24 lines
#119/p calls: invalid kfunc call:
ptr_to_memto struct with non-scalar FAIL #120/p calls: invalid kfunc call:ptr_to_memto struct with nesting depth > 4 FAIL #121/p calls: invalid kfunc call:ptr_to_memto struct with FAM FAIL
#122/p calls: invalid kfunc call:reg->type!=PTR_TO_CTXFAIL
#123/p calls: invalid kfunc call: void * not allowed in func proto without mem size arg FAIL #124/p calls: trigger reg2btf_ids[reg->type] forreg->type>__BPF_REG_TYPE_MAXFAIL #125/p calls: invalid kfunc call:reg->offmust be zero when passed to release kfunc FAIL #126/p calls: invalid kfunc call: don't match first member type when passed to release kfunc FAIL #127/p calls: invalid kfunc call:PTR_TO_BTF_IDwith negative offset FAIL
#128/p calls: invalid kfunc call:PTR_TO_BTF_IDwith variable offset FAIL
#129/p calls: invalid kfunc call: referenced arg needs refcountedPTR_TO_BTF_IDFAIL #130/p calls: valid kfunc call: referenced arg needs refcountedPTR_TO_BTF_IDFAIL #486/pmap_kptr: ref: reference state created and released on xchg FAILThis is because the kfuncs in the loaded module are far away from
__bpf_call_base:
ffff800002009440tbpf_kfunc_call_test_fail1[bpf_testmod]
9000000002e128d8T__bpf_call_baseThe offset relative to
__bpf_call_basedoes NOT fit in s32, which breaks the assumption in BPF core. Enablebpf_jit_supports_far_kfunc_call()lifts this limit.
Quoted 5 lines
With this change, the
test_verifiertests now all passed:# ./test_verifier ... Summary: 777 PASSED, 0 SKIPPED, 0 FAILED
I met build errors and failed/skipped tests at the beginning, so I spent some time to analysis the problems. In order to achieve success, it is necessary to do the following steps:
(1) build with loongson3_defconfig and also setCONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT=yCONFIG_DEBUG_INFO_BTF=yCONFIG_FTRACE_SYSCALLS=yCONFIG_BPF_LSM=y
(2) enable bpf jit and enable unprivileged bpf before test echo 1 > /proc/sys/net/core/bpf_jit_enable
echo 0 > /proc/sys/kernel/unprivileged_bpf_disabled
Otherwise there exist build errors when execute
make headers && cd tools/testing/selftests/bpf && make -j4
Furthermore, there exist failed test "#507/p sleepable lsm accept FAIL" and many skipped tests when execute "./test_verifier".
I think it would be best to add the above info in the commit message so that the users know how to test and how to solve or avoid the failures.
Quoted 2 lines
Signed-off-by Hengqi Chen <[email protected]>
Feel free to add a
Thanks,
Tiezhu
Hengqi Chen
reviewerQuoted 77 lines · Tiezhu Yang
Hi Hengqi,
Thanks for the patch, sorry for the late reply.
Quoted 8 lines · Hengqi Chen
Like commit
1cf3bfc60f98("bpf: Support 64-bit pointers to kfuncs") for s390x, add support for 64-bit pointers to kfuncs for LoongArch. Since the infrastructure is already implemented in BPF core, the only thing need to be done is to overridebpf_jit_supports_far_kfunc_call().Before this change, several
test_verifiertests failed:# ./test_verifier | grep # | grep FAIL[root@linux bpf]# ./test_verifier | grep # | grep FAIL
Usage: grep [OPTION]... PATTERNS [FILE]... Try 'grep --help' for more information.It should be:
[root@linux bpf]# ./test_verifier | grep "#" | grep FAILQuoted 24 lines
#119/p calls: invalid kfunc call:
ptr_to_memto struct with non-scalar FAIL #120/p calls: invalid kfunc call:ptr_to_memto struct with nesting depth > 4 FAIL #121/p calls: invalid kfunc call:ptr_to_memto struct with FAM FAIL
#122/p calls: invalid kfunc call:reg->type!=PTR_TO_CTXFAIL
#123/p calls: invalid kfunc call: void * not allowed in func proto without mem size arg FAIL #124/p calls: trigger reg2btf_ids[reg->type] forreg->type>__BPF_REG_TYPE_MAXFAIL #125/p calls: invalid kfunc call:reg->offmust be zero when passed to release kfunc FAIL #126/p calls: invalid kfunc call: don't match first member type when passed to release kfunc FAIL #127/p calls: invalid kfunc call:PTR_TO_BTF_IDwith negative offset FAIL
#128/p calls: invalid kfunc call:PTR_TO_BTF_IDwith variable offset FAIL
#129/p calls: invalid kfunc call: referenced arg needs refcountedPTR_TO_BTF_IDFAIL #130/p calls: valid kfunc call: referenced arg needs refcountedPTR_TO_BTF_IDFAIL #486/pmap_kptr: ref: reference state created and released on xchg FAILThis is because the kfuncs in the loaded module are far away from
__bpf_call_base:
ffff800002009440tbpf_kfunc_call_test_fail1[bpf_testmod]
9000000002e128d8T__bpf_call_baseThe offset relative to
__bpf_call_basedoes NOT fit in s32, which breaks the assumption in BPF core. Enablebpf_jit_supports_far_kfunc_call()lifts this limit.Quoted 5 lines
With this change, the
test_verifiertests now all passed:# ./test_verifier ... Summary: 777 PASSED, 0 SKIPPED, 0 FAILEDI met build errors and failed/skipped tests at the beginning, so I spent some time to analysis the problems. In order to achieve success, it is necessary to do the following steps:
(1) build with
loongson3_defconfigand also setCONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT=yCONFIG_DEBUG_INFO_BTF=yCONFIG_FTRACE_SYSCALLS=yCONFIG_BPF_LSM=y(2) enable bpf jit and enable unprivileged bpf before test echo 1 >
/proc/sys/net/core/bpf_jit_enable
echo 0 >/proc/sys/kernel/unprivileged_bpf_disabledOtherwise there exist build errors when execute
make headers && cd tools/testing/selftests/bpf && make -j4Furthermore, there exist failed test "#507/p sleepable lsm accept FAIL" and many skipped tests when execute "./test_verifier".
I think it would be best to add the above info in the commit message so that the users know how to test and how to solve or avoid the failures.
Quoted 1 line
Quoted 9 lines
Quoted 1 line
Signed-off-by Hengqi Chen <[email protected]>Feel free to add a
Tested-by Tiezhu Yang <[email protected]>Thanks,
Tiezhu
Thanks, will send a v2 soon.