From: Hou Tao <hotforest@gmail.com>
To: Daniel Borkmann <daniel@iogearbox.net>
Cc: Alexei Starovoitov <ast@kernel.org>,
Martin KaFai Lau <kafai@fb.com>, Yonghong Song <yhs@fb.com>,
Andrii Nakryiko <andrii@kernel.org>,
"David S . Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
John Fastabend <john.fastabend@gmail.com>,
netdev@vger.kernel.org, bpf@vger.kernel.org, houtao1@huawei.com,
Zi Shen Lim <zlim.lnx@gmail.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>,
Ard Biesheuvel <ard.biesheuvel@arm.com>,
linux-arm-kernel@lists.infradead.org
Subject: [PATCH bpf-next v3 3/3] selftests/bpf: check whether s32 is sufficient for kfunc offset
Date: Sun, 30 Jan 2022 17:29:17 +0800 [thread overview]
Message-ID: <20220130092917.14544-4-hotforest@gmail.com> (raw)
In-Reply-To: <20220130092917.14544-1-hotforest@gmail.com>
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
next prev parent reply other threads:[~2022-01-30 9:30 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-30 9:29 [PATCH bpf-next v3 0/3] bpf, arm64: enable kfunc call Hou Tao
2022-01-30 9:29 ` [PATCH bpf-next v3 1/3] " Hou Tao
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 [this message]
2022-02-04 15:40 ` [PATCH bpf-next v3 0/3] bpf, arm64: enable kfunc call patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220130092917.14544-4-hotforest@gmail.com \
--to=hotforest@gmail.com \
--cc=andrii@kernel.org \
--cc=ard.biesheuvel@arm.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=catalin.marinas@arm.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=houtao1@huawei.com \
--cc=john.fastabend@gmail.com \
--cc=kafai@fb.com \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=netdev@vger.kernel.org \
--cc=will@kernel.org \
--cc=yhs@fb.com \
--cc=zlim.lnx@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).