* [PATCH bpf-next v3 0/3] bpf, arm64: enable kfunc call
@ 2022-01-30 9:29 ` Hou Tao
0 siblings, 0 replies; 12+ messages in thread
From: Hou Tao @ 2022-01-30 9:29 UTC (permalink / raw)
To: Daniel Borkmann
Cc: Alexei Starovoitov, Martin KaFai Lau, Yonghong Song,
Andrii Nakryiko, David S . Miller, Jakub Kicinski,
John Fastabend, netdev, bpf, houtao1, Zi Shen Lim,
Catalin Marinas, Will Deacon, Ard Biesheuvel, linux-arm-kernel,
Hou Tao
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/20220127071532.384888-1-houtao1@huawei.com/
* add a test to check whether imm will be overflowed for kfunc call
v1: https://lore.kernel.org/bpf/20220119144942.305568-1-houtao1@huawei.com
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(-)
--
2.20.1
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH bpf-next v3 0/3] bpf, arm64: enable kfunc call
@ 2022-01-30 9:29 ` Hou Tao
0 siblings, 0 replies; 12+ messages in thread
From: Hou Tao @ 2022-01-30 9:29 UTC (permalink / raw)
To: Daniel Borkmann
Cc: Alexei Starovoitov, Martin KaFai Lau, Yonghong Song,
Andrii Nakryiko, David S . Miller, Jakub Kicinski,
John Fastabend, netdev, bpf, houtao1, Zi Shen Lim,
Catalin Marinas, Will Deacon, Ard Biesheuvel, linux-arm-kernel,
Hou Tao
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/20220127071532.384888-1-houtao1@huawei.com/
* add a test to check whether imm will be overflowed for kfunc call
v1: https://lore.kernel.org/bpf/20220119144942.305568-1-houtao1@huawei.com
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(-)
--
2.20.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH bpf-next v3 1/3] bpf, arm64: enable kfunc call
2022-01-30 9:29 ` Hou Tao
@ 2022-01-30 9:29 ` Hou Tao
-1 siblings, 0 replies; 12+ messages in thread
From: Hou Tao @ 2022-01-30 9:29 UTC (permalink / raw)
To: Daniel Borkmann
Cc: Alexei Starovoitov, Martin KaFai Lau, Yonghong Song,
Andrii Nakryiko, David S . Miller, Jakub Kicinski,
John Fastabend, netdev, bpf, houtao1, Zi Shen Lim,
Catalin Marinas, Will Deacon, Ard Biesheuvel, linux-arm-kernel
From: Hou Tao <houtao1@huawei.com>
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().
Signed-off-by: Hou Tao <houtao1@huawei.com>
---
arch/arm64/net/bpf_jit_comp.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c
index e96d4d87291f..74f9a9b6a053 100644
--- a/arch/arm64/net/bpf_jit_comp.c
+++ b/arch/arm64/net/bpf_jit_comp.c
@@ -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;
--
2.20.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH bpf-next v3 1/3] bpf, arm64: enable kfunc call
@ 2022-01-30 9:29 ` Hou Tao
0 siblings, 0 replies; 12+ messages in thread
From: Hou Tao @ 2022-01-30 9:29 UTC (permalink / raw)
To: Daniel Borkmann
Cc: Alexei Starovoitov, Martin KaFai Lau, Yonghong Song,
Andrii Nakryiko, David S . Miller, Jakub Kicinski,
John Fastabend, netdev, bpf, houtao1, Zi Shen Lim,
Catalin Marinas, Will Deacon, Ard Biesheuvel, linux-arm-kernel
From: Hou Tao <houtao1@huawei.com>
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().
Signed-off-by: Hou Tao <houtao1@huawei.com>
---
arch/arm64/net/bpf_jit_comp.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c
index e96d4d87291f..74f9a9b6a053 100644
--- a/arch/arm64/net/bpf_jit_comp.c
+++ b/arch/arm64/net/bpf_jit_comp.c
@@ -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;
--
2.20.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH bpf-next v3 2/3] selftests/bpf: do not export subtest as standalone test
2022-01-30 9:29 ` Hou Tao
@ 2022-01-30 9:29 ` Hou Tao
-1 siblings, 0 replies; 12+ messages in thread
From: Hou Tao @ 2022-01-30 9:29 UTC (permalink / raw)
To: Daniel Borkmann
Cc: Alexei Starovoitov, Martin KaFai Lau, Yonghong Song,
Andrii Nakryiko, David S . Miller, Jakub Kicinski,
John Fastabend, netdev, bpf, houtao1, Zi Shen Lim,
Catalin Marinas, Will Deacon, Ard Biesheuvel, linux-arm-kernel,
Hou Tao
Two 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.
Signed-off-by: Hou Tao <hotforest@gmail.com>
---
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(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/ksyms_module.c b/tools/testing/selftests/bpf/prog_tests/ksyms_module.c
index d490ad80eccb..997aa90dea64 100644
--- a/tools/testing/selftests/bpf/prog_tests/ksyms_module.c
+++ b/tools/testing/selftests/bpf/prog_tests/ksyms_module.c
@@ -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;
diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_adjust_frags.c b/tools/testing/selftests/bpf/prog_tests/xdp_adjust_frags.c
index 31c188666e81..6ca3582bb056 100644
--- a/tools/testing/selftests/bpf/prog_tests/xdp_adjust_frags.c
+++ b/tools/testing/selftests/bpf/prog_tests/xdp_adjust_frags.c
@@ -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();
-}
diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c b/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c
index ccc9e63254a8..a254c54c3ada 100644
--- a/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c
+++ b/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c
@@ -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;
diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_cpumap_attach.c b/tools/testing/selftests/bpf/prog_tests/xdp_cpumap_attach.c
index 13aabb3b6cf2..15e48098c8b8 100644
--- a/tools/testing/selftests/bpf/prog_tests/xdp_cpumap_attach.c
+++ b/tools/testing/selftests/bpf/prog_tests/xdp_cpumap_attach.c
@@ -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 = {};
diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_devmap_attach.c b/tools/testing/selftests/bpf/prog_tests/xdp_devmap_attach.c
index 2a784ccd3136..08d074ec471d 100644
--- a/tools/testing/selftests/bpf/prog_tests/xdp_devmap_attach.c
+++ b/tools/testing/selftests/bpf/prog_tests/xdp_devmap_attach.c
@@ -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 = {};
--
2.20.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH bpf-next v3 2/3] selftests/bpf: do not export subtest as standalone test
@ 2022-01-30 9:29 ` Hou Tao
0 siblings, 0 replies; 12+ messages in thread
From: Hou Tao @ 2022-01-30 9:29 UTC (permalink / raw)
To: Daniel Borkmann
Cc: Alexei Starovoitov, Martin KaFai Lau, Yonghong Song,
Andrii Nakryiko, David S . Miller, Jakub Kicinski,
John Fastabend, netdev, bpf, houtao1, Zi Shen Lim,
Catalin Marinas, Will Deacon, Ard Biesheuvel, linux-arm-kernel,
Hou Tao
Two 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.
Signed-off-by: Hou Tao <hotforest@gmail.com>
---
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(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/ksyms_module.c b/tools/testing/selftests/bpf/prog_tests/ksyms_module.c
index d490ad80eccb..997aa90dea64 100644
--- a/tools/testing/selftests/bpf/prog_tests/ksyms_module.c
+++ b/tools/testing/selftests/bpf/prog_tests/ksyms_module.c
@@ -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;
diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_adjust_frags.c b/tools/testing/selftests/bpf/prog_tests/xdp_adjust_frags.c
index 31c188666e81..6ca3582bb056 100644
--- a/tools/testing/selftests/bpf/prog_tests/xdp_adjust_frags.c
+++ b/tools/testing/selftests/bpf/prog_tests/xdp_adjust_frags.c
@@ -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();
-}
diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c b/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c
index ccc9e63254a8..a254c54c3ada 100644
--- a/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c
+++ b/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c
@@ -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;
diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_cpumap_attach.c b/tools/testing/selftests/bpf/prog_tests/xdp_cpumap_attach.c
index 13aabb3b6cf2..15e48098c8b8 100644
--- a/tools/testing/selftests/bpf/prog_tests/xdp_cpumap_attach.c
+++ b/tools/testing/selftests/bpf/prog_tests/xdp_cpumap_attach.c
@@ -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 = {};
diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_devmap_attach.c b/tools/testing/selftests/bpf/prog_tests/xdp_devmap_attach.c
index 2a784ccd3136..08d074ec471d 100644
--- a/tools/testing/selftests/bpf/prog_tests/xdp_devmap_attach.c
+++ b/tools/testing/selftests/bpf/prog_tests/xdp_devmap_attach.c
@@ -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 = {};
--
2.20.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH bpf-next v3 3/3] selftests/bpf: check whether s32 is sufficient for kfunc offset
2022-01-30 9:29 ` Hou Tao
@ 2022-01-30 9:29 ` Hou Tao
-1 siblings, 0 replies; 12+ messages in thread
From: Hou Tao @ 2022-01-30 9:29 UTC (permalink / raw)
To: Daniel Borkmann
Cc: Alexei Starovoitov, Martin KaFai Lau, Yonghong Song,
Andrii Nakryiko, David S . Miller, Jakub Kicinski,
John Fastabend, netdev, bpf, houtao1, Zi Shen Lim,
Catalin Marinas, Will Deacon, Ard Biesheuvel, linux-arm-kernel
From: Hou Tao <houtao1@huawei.com>
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.
Signed-off-by: Hou Tao <houtao1@huawei.com>
---
.../selftests/bpf/prog_tests/ksyms_module.c | 42 +++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/tools/testing/selftests/bpf/prog_tests/ksyms_module.c b/tools/testing/selftests/bpf/prog_tests/ksyms_module.c
index 997aa90dea64..955a9ede4756 100644
--- a/tools/testing/selftests/bpf/prog_tests/ksyms_module.c
+++ b/tools/testing/selftests/bpf/prog_tests/ksyms_module.c
@@ -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"))
--
2.20.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH bpf-next v3 3/3] selftests/bpf: check whether s32 is sufficient for kfunc offset
@ 2022-01-30 9:29 ` Hou Tao
0 siblings, 0 replies; 12+ messages in thread
From: Hou Tao @ 2022-01-30 9:29 UTC (permalink / raw)
To: Daniel Borkmann
Cc: Alexei Starovoitov, Martin KaFai Lau, Yonghong Song,
Andrii Nakryiko, David S . Miller, Jakub Kicinski,
John Fastabend, netdev, bpf, houtao1, Zi Shen Lim,
Catalin Marinas, Will Deacon, Ard Biesheuvel, linux-arm-kernel
From: Hou Tao <houtao1@huawei.com>
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.
Signed-off-by: Hou Tao <houtao1@huawei.com>
---
.../selftests/bpf/prog_tests/ksyms_module.c | 42 +++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/tools/testing/selftests/bpf/prog_tests/ksyms_module.c b/tools/testing/selftests/bpf/prog_tests/ksyms_module.c
index 997aa90dea64..955a9ede4756 100644
--- a/tools/testing/selftests/bpf/prog_tests/ksyms_module.c
+++ b/tools/testing/selftests/bpf/prog_tests/ksyms_module.c
@@ -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"))
--
2.20.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH bpf-next v3 0/3] bpf, arm64: enable kfunc call
2022-01-30 9:29 ` Hou Tao
@ 2022-02-04 15:40 ` patchwork-bot+netdevbpf
-1 siblings, 0 replies; 12+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-02-04 15:40 UTC (permalink / raw)
To: Hou Tao
Cc: daniel, ast, kafai, yhs, andrii, davem, kuba, john.fastabend,
netdev, bpf, houtao1, zlim.lnx, catalin.marinas, will,
ard.biesheuvel, linux-arm-kernel
Hello:
This series was applied to bpf/bpf-next.git (master)
by Daniel Borkmann <daniel@iogearbox.net>:
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 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.
>
> [...]
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!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH bpf-next v3 0/3] bpf, arm64: enable kfunc call
@ 2022-02-04 15:40 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 12+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-02-04 15:40 UTC (permalink / raw)
To: Hou Tao
Cc: daniel, ast, kafai, yhs, andrii, davem, kuba, john.fastabend,
netdev, bpf, houtao1, zlim.lnx, catalin.marinas, will,
ard.biesheuvel, linux-arm-kernel
Hello:
This series was applied to bpf/bpf-next.git (master)
by Daniel Borkmann <daniel@iogearbox.net>:
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 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.
>
> [...]
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!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH bpf-next v3 1/3] bpf, arm64: enable kfunc call
2022-01-30 9:29 ` Hou Tao
@ 2022-02-04 15:42 ` Daniel Borkmann
-1 siblings, 0 replies; 12+ messages in thread
From: Daniel Borkmann @ 2022-02-04 15:42 UTC (permalink / raw)
To: Hou Tao
Cc: Alexei Starovoitov, Martin KaFai Lau, Yonghong Song,
Andrii Nakryiko, David S . Miller, Jakub Kicinski,
John Fastabend, netdev, bpf, houtao1, Zi Shen Lim,
Catalin Marinas, Will Deacon, Ard Biesheuvel, linux-arm-kernel
On 1/30/22 10:29 AM, Hou Tao wrote:
> From: Hou Tao <houtao1@huawei.com>
>
> 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().
>
> Signed-off-by: Hou Tao <houtao1@huawei.com>
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!
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH bpf-next v3 1/3] bpf, arm64: enable kfunc call
@ 2022-02-04 15:42 ` Daniel Borkmann
0 siblings, 0 replies; 12+ messages in thread
From: Daniel Borkmann @ 2022-02-04 15:42 UTC (permalink / raw)
To: Hou Tao
Cc: Alexei Starovoitov, Martin KaFai Lau, Yonghong Song,
Andrii Nakryiko, David S . Miller, Jakub Kicinski,
John Fastabend, netdev, bpf, houtao1, Zi Shen Lim,
Catalin Marinas, Will Deacon, Ard Biesheuvel, linux-arm-kernel
On 1/30/22 10:29 AM, Hou Tao wrote:
> From: Hou Tao <houtao1@huawei.com>
>
> 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().
>
> Signed-off-by: Hou Tao <houtao1@huawei.com>
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!
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2022-02-04 15:43 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-30 9:29 [PATCH bpf-next v3 0/3] bpf, arm64: enable kfunc call Hou Tao
2022-01-30 9:29 ` Hou Tao
2022-01-30 9:29 ` [PATCH bpf-next v3 1/3] " Hou Tao
2022-01-30 9:29 ` Hou Tao
2022-02-04 15:42 ` Daniel Borkmann
2022-02-04 15:42 ` Daniel Borkmann
2022-01-30 9:29 ` [PATCH bpf-next v3 2/3] selftests/bpf: do not export subtest as standalone test Hou Tao
2022-01-30 9:29 ` Hou Tao
2022-01-30 9:29 ` [PATCH bpf-next v3 3/3] selftests/bpf: check whether s32 is sufficient for kfunc offset Hou Tao
2022-01-30 9:29 ` Hou Tao
2022-02-04 15:40 ` [PATCH bpf-next v3 0/3] bpf, arm64: enable kfunc call patchwork-bot+netdevbpf
2022-02-04 15:40 ` patchwork-bot+netdevbpf
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.