bpf, arm64: enable kfunc call
Subsystems (8)
v3 cover bpf, arm64: enable kfunc call
Hi,
The simple patchset tries to enable kfunc call for arm64. Patch #1 just overrides bpf_jit_supports_kfunc_call() to enable kfunc call, patch #2 unexports the subtests in ksyms_module.c to fix the confusion in test output and patch #3 add a test in ksyms_module.c to ensure s32 is sufficient for kfunc offset.
Change Log:
v3:
* patch #2: newly-addded to unexport unnecessary subtests
* patch #3: use kallsyms_find() instead of reimplementing it.
* patch #3: ensure kfunc call is supported before checking whether s32 will be overflowed or not.
v2: https://lore.kernel.org/bpf/[email protected]/
* add a test to check whether imm will be overflowed for kfunc call
v1: https://lore.kernel.org/bpf/[email protected]
Hou Tao (3):
bpf, arm64: enable kfunc call
selftests/bpf: do not export subtest as standalone test selftests/bpf: check whether s32 is sufficient for kfunc offset
arch/arm64/net/bpf_jit_comp.c | 5 ++ .../selftests/bpf/prog_tests/ksyms_module.c | 46 ++++++++++++++++++- .../bpf/prog_tests/xdp_adjust_frags.c | 6 --- .../bpf/prog_tests/xdp_adjust_tail.c | 4 +- .../bpf/prog_tests/xdp_cpumap_attach.c | 4 +- .../bpf/prog_tests/xdp_devmap_attach.c | 2 +- 6 files changed, 54 insertions(+), 13 deletions(-)
Signature · 1 line
2.20.1
PATCH v3 1/3 bpf, arm64: enable kfunc call
From: Hou Tao <[email protected]>
Since commit b2eed9b58811 ("arm64/kernel: kaslr: reduce module randomization range to 2 GB"), for arm64 whether KASLR is enabled or not, the module is placed within 2GB of the kernel region, so s32 in bpf_kfunc_desc is sufficient to represente the offset of module function relative to __bpf_call_base. The only thing needed is to override bpf_jit_supports_kfunc_call().
--- arch/arm64/net/bpf_jit_comp.c | 5 +++++ 1 file changed, 5 insertions(+)
arch/arm64/net/bpf_jit_comp.c +5 -0
@@ -1143,6 +1143,11 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)return prog; } +bool bpf_jit_supports_kfunc_call (void ) +{ +return true; +} +u64 bpf_jit_alloc_exec_limit (void ) {return VMALLOC_END -VMALLOC_START ;
Signature · 1 line
2.20.1
PATCH v3 2/3 selftests/bpf: do not export subtest as standalone test
In reply to Hou TaoTwo subtests in ksyms_module.c are not qualified as static, so these subtests are exported as standalone tests in tests.h and lead to confusion for the output of "./test_progs -t ksyms_module".
By using the following command:
grep "^void \(serial_\)\?test_[a-zA-Z0-9_]\+(\(void\)\?)" \
tools/testing/selftests/bpf/prog_tests/*.c | \
awk -F : '{print $1}' | sort | uniq -c | awk '$1 != 1'Find out that other tests also have the similar problem, so fix these tests by marking subtests in these tests as static. For xdp_adjust_frags.c, there is just one subtest, so just export the subtest directly.
--- tools/testing/selftests/bpf/prog_tests/ksyms_module.c | 4 ++-- tools/testing/selftests/bpf/prog_tests/xdp_adjust_frags.c | 6 ------ tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c | 4 ++-- tools/testing/selftests/bpf/prog_tests/xdp_cpumap_attach.c | 4 ++-- tools/testing/selftests/bpf/prog_tests/xdp_devmap_attach.c | 2 +- 5 files changed, 7 insertions(+), 13 deletions(-)
tools/testing/selftests/bpf/prog_tests/ksyms_module.c +2 -2
@@ -6,7 +6,7 @@#include "test_ksyms_module.lskel.h" #include "test_ksyms_module.skel.h" -void test_ksyms_module_lskel (void ) +static void test_ksyms_module_lskel (void ) {struct test_ksyms_module_lskel *skel;int retval;
@@ -30,7 +30,7 @@ void test_ksyms_module_lskel(void)test_ksyms_module_lskel__destroy (skel); } -void test_ksyms_module_libbpf (void ) +static void test_ksyms_module_libbpf (void ) {struct test_ksyms_module *skel;int retval, err;
tools/testing/selftests/bpf/prog_tests/xdp_adjust_frags.c +0 -6
@@ -96,9 +96,3 @@ void test_xdp_update_frags(void) out:bpf_object__close (obj); } - -void test_xdp_adjust_frags (void ) -{ -if (test__start_subtest ("xdp_adjust_frags" )) -test_xdp_update_frags (); -}
tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c +2 -2
@@ -118,7 +118,7 @@ static void test_xdp_adjust_tail_grow2(void)bpf_object__close (obj); } -void test_xdp_adjust_frags_tail_shrink (void ) +static void test_xdp_adjust_frags_tail_shrink (void ) {const char *file ="./test_xdp_adjust_tail_shrink.o" ;__u32 duration, retval, size, exp_size;
@@ -180,7 +180,7 @@ void test_xdp_adjust_frags_tail_shrink(void)bpf_object__close (obj); } -void test_xdp_adjust_frags_tail_grow (void ) +static void test_xdp_adjust_frags_tail_grow (void ) {const char *file ="./test_xdp_adjust_tail_grow.o" ;__u32 duration, retval, size, exp_size;
tools/testing/selftests/bpf/prog_tests/xdp_cpumap_attach.c +2 -2
@@ -8,7 +8,7 @@#define IFINDEX_LO 1 -void test_xdp_with_cpumap_helpers (void ) +static void test_xdp_with_cpumap_helpers (void ) {struct test_xdp_with_cpumap_helpers *skel;struct bpf_prog_info info = {};
@@ -68,7 +68,7 @@ void test_xdp_with_cpumap_helpers(void)test_xdp_with_cpumap_helpers__destroy (skel); } -void test_xdp_with_cpumap_frags_helpers (void ) +static void test_xdp_with_cpumap_frags_helpers (void ) {struct test_xdp_with_cpumap_frags_helpers *skel;struct bpf_prog_info info = {};
tools/testing/selftests/bpf/prog_tests/xdp_devmap_attach.c +1 -1
@@ -81,7 +81,7 @@ static void test_neg_xdp_devmap_helpers(void) } } -void test_xdp_with_devmap_frags_helpers (void ) +static void test_xdp_with_devmap_frags_helpers (void ) {struct test_xdp_with_devmap_frags_helpers *skel;struct bpf_prog_info info = {};
Signature · 1 line
2.20.1
PATCH v3 3/3 selftests/bpf: check whether s32 is sufficient for kfunc offset
In reply to Hou TaoFrom: Hou Tao <[email protected]>
In add_kfunc_call(), bpf_kfunc_desc->imm with type s32 is used to represent the offset of called kfunc from __bpf_call_base, so add a test to ensure that the offset will not be overflowed.
--- .../selftests/bpf/prog_tests/ksyms_module.c | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+)
tools/testing/selftests/bpf/prog_tests/ksyms_module.c +42 -0
@@ -3,9 +3,49 @@#include <test_progs.h> #include <network_helpers.h> +#include <trace_helpers.h> #include "test_ksyms_module.lskel.h" #include "test_ksyms_module.skel.h" +/* +* Check whether or not s32 in bpf_kfunc_desc is sufficient +* to represent the offset between bpf_testmod_test_mod_kfunc +* and __bpf_call_base. +*/ +static void test_ksyms_module_valid_offset (void ) +{ +struct test_ksyms_module *skel; +unsigned long long kfunc_addr; +unsigned long long base_addr; +long long actual_offset; +int used_offset; +int err; + +if (!env.has_testmod) { +test__skip (); +return ; + } + +/* Ensure kfunc call is supported */ + skel =test_ksyms_module__open_and_load (); +if (!ASSERT_OK_PTR (skel,"test_ksyms_module__open" )) +return ; + + err =kallsyms_find ("bpf_testmod_test_mod_kfunc" , &kfunc_addr); +if (!ASSERT_OK (err,"find kfunc addr" )) + goto cleanup; + + err =kallsyms_find ("__bpf_call_base" , &base_addr); +if (!ASSERT_OK (err,"find base addr" )) + goto cleanup; + + used_offset = kfunc_addr - base_addr; + actual_offset = kfunc_addr - base_addr; +ASSERT_EQ ((long long )used_offset, actual_offset,"kfunc offset overflowed" ); +cleanup: +test_ksyms_module__destroy (skel); +} +static void test_ksyms_module_lskel (void ) {struct test_ksyms_module_lskel *skel;
@@ -55,6 +95,8 @@ static void test_ksyms_module_libbpf(void)void test_ksyms_module (void ) { +if (test__start_subtest ("valid_offset" )) +test_ksyms_module_valid_offset ();if (test__start_subtest ("lskel" ))test_ksyms_module_lskel ();if (test__start_subtest ("libbpf" ))
Signature · 1 line
2.20.1
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 9 lines · On Sun, 30 Jan 2022 17:29:14 +0800 you wrote:
Hi,
The simple patchset tries to enable kfunc call for arm64. Patch #1 just overrides
bpf_jit_supports_kfunc_call()to enable kfunc call, patch #2 unexports the subtests inksyms_module.cto fix the confusion in test output and patch #3 add a test inksyms_module.cto ensure s32 is sufficient for kfunc offset.[...]
Here is the summary with links:
- [bpf-next,v3,1/3] bpf, arm64: enable kfunc call
https://git.kernel.org/bpf/bpf-next/c/b5e975d256db
- [bpf-next,v3,2/3] selftests/bpf: do not export subtest as standalone test (no matching commit)
- [bpf-next,v3,3/3] selftests/bpf: check whether s32 is sufficient for kfunc offset (no matching commit)
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Daniel Borkmann
maintainerQuoted 10 lines · Hou Tao
From: Hou Tao <[email protected]>
Since commit
b2eed9b58811("arm64/kernel: kaslr: reduce module randomization range to 2 GB"), for arm64 whether KASLR is enabled or not, the module is placed within 2GB of the kernel region, so s32 inbpf_kfunc_descis sufficient to represente the offset of module function relative to__bpf_call_base. The only thing needed is to overridebpf_jit_supports_kfunc_call().Signed-off-by Hou Tao <[email protected]>
Could you rebase patch 2 & 3 and resend as they don't apply to bpf-next right now. Meanwhile, applied this one, thanks a lot!