From: Yonghong Song <yhs@fb.com>
To: Andrii Nakryiko <andrii@kernel.org>, <bpf@vger.kernel.org>,
<netdev@vger.kernel.org>, <ast@fb.com>, <daniel@iogearbox.net>
Cc: <kernel-team@fb.com>, Hao Luo <haoluo@google.com>
Subject: Re: [PATCH v2 bpf-next 7/7] selftests/bpf: test kernel module ksym externs
Date: Sun, 10 Jan 2021 20:18:37 -0800 [thread overview]
Message-ID: <24b84186-4cd6-131c-2284-d0fdc51ce7b4@fb.com> (raw)
In-Reply-To: <20210108220930.482456-8-andrii@kernel.org>
On 1/8/21 2:09 PM, Andrii Nakryiko wrote:
> Add per-CPU variable to bpf_testmod.ko and use those from new selftest to
> validate it works end-to-end.
>
> Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Ack with a nit below.
Acked-by: Yonghong Song <yhs@fb.com>
> ---
> .../selftests/bpf/bpf_testmod/bpf_testmod.c | 3 ++
> .../selftests/bpf/prog_tests/ksyms_module.c | 33 +++++++++++++++++++
> .../selftests/bpf/progs/test_ksyms_module.c | 26 +++++++++++++++
> 3 files changed, 62 insertions(+)
> create mode 100644 tools/testing/selftests/bpf/prog_tests/ksyms_module.c
> create mode 100644 tools/testing/selftests/bpf/progs/test_ksyms_module.c
>
> diff --git a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c
> index 2df19d73ca49..0b991e115d1f 100644
> --- a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c
> +++ b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c
> @@ -3,6 +3,7 @@
> #include <linux/error-injection.h>
> #include <linux/init.h>
> #include <linux/module.h>
> +#include <linux/percpu-defs.h>
> #include <linux/sysfs.h>
> #include <linux/tracepoint.h>
> #include "bpf_testmod.h"
> @@ -10,6 +11,8 @@
> #define CREATE_TRACE_POINTS
> #include "bpf_testmod-events.h"
>
> +DEFINE_PER_CPU(int, bpf_testmod_ksym_percpu) = 123;
> +
> noinline ssize_t
> bpf_testmod_test_read(struct file *file, struct kobject *kobj,
> struct bin_attribute *bin_attr,
> diff --git a/tools/testing/selftests/bpf/prog_tests/ksyms_module.c b/tools/testing/selftests/bpf/prog_tests/ksyms_module.c
> new file mode 100644
> index 000000000000..7fa3d8b6ca30
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/prog_tests/ksyms_module.c
> @@ -0,0 +1,33 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/* Copyright (c) 2021 Facebook */
> +
> +#include <test_progs.h>
> +#include <bpf/libbpf.h>
> +#include <bpf/btf.h>
> +#include "test_ksyms_module.skel.h"
> +
> +static int duration;
> +
> +void test_ksyms_module(void)
> +{
> + struct test_ksyms_module* skel;
> + struct test_ksyms_module__bss *bss;
> + int err;
> +
> + skel = test_ksyms_module__open_and_load();
> + if (CHECK(!skel, "skel_open", "failed to open skeleton\n"))
> + return;
> + bss = skel->bss;
> +
> + err = test_ksyms_module__attach(skel);
> + if (CHECK(err, "skel_attach", "skeleton attach failed: %d\n", err))
> + goto cleanup;
> +
> + usleep(1);
The above bss = skel->bss might be moved here for better readability.
Or better, you can remove definition bss and just use skel->bss
in below two ASSERT_EQs.
> + ASSERT_EQ(bss->triggered, true, "triggered");
> + ASSERT_EQ(bss->out_mod_ksym_global, 123, "global_ksym_val");
> +
> +cleanup:
> + test_ksyms_module__destroy(skel);
> +}
> diff --git a/tools/testing/selftests/bpf/progs/test_ksyms_module.c b/tools/testing/selftests/bpf/progs/test_ksyms_module.c
> new file mode 100644
> index 000000000000..d6a0b3086b90
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/progs/test_ksyms_module.c
> @@ -0,0 +1,26 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/* Copyright (c) 2021 Facebook */
> +
> +#include "vmlinux.h"
> +
> +#include <bpf/bpf_helpers.h>
> +
> +extern const int bpf_testmod_ksym_percpu __ksym;
> +
> +int out_mod_ksym_global = 0;
> +bool triggered = false;
> +
> +SEC("raw_tp/sys_enter")
> +int handler(const void *ctx)
> +{
> + int *val;
> + __u32 cpu;
> +
> + val = (int *)bpf_this_cpu_ptr(&bpf_testmod_ksym_percpu);
> + out_mod_ksym_global = *val;
> + triggered = true;
> +
> + return 0;
> +}
> +
> +char LICENSE[] SEC("license") = "GPL";
>
next prev parent reply other threads:[~2021-01-11 4:19 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-08 22:09 [PATCH v2 bpf-next 0/7] Support kernel module ksym variables Andrii Nakryiko
2021-01-08 22:09 ` [PATCH v2 bpf-next 1/7] bpf: add bpf_patch_call_args prototype to include/linux/bpf.h Andrii Nakryiko
2021-01-11 4:02 ` Yonghong Song
2021-01-08 22:09 ` [PATCH v2 bpf-next 2/7] bpf: avoid warning when re-casting __bpf_call_base into __bpf_call_base_args Andrii Nakryiko
2021-01-11 4:03 ` Yonghong Song
2021-01-08 22:09 ` [PATCH v2 bpf-next 3/7] bpf: declare __bpf_free_used_maps() unconditionally Andrii Nakryiko
2021-01-11 4:03 ` Yonghong Song
2021-01-08 22:09 ` [PATCH v2 bpf-next 4/7] selftests/bpf: sync RCU before unloading bpf_testmod Andrii Nakryiko
2021-01-11 4:05 ` Yonghong Song
2021-01-11 18:59 ` Hao Luo
2021-01-08 22:09 ` [PATCH v2 bpf-next 5/7] bpf: support BPF ksym variables in kernel modules Andrii Nakryiko
2021-01-11 4:13 ` Yonghong Song
2021-01-11 21:29 ` Andrii Nakryiko
2021-01-12 1:25 ` Yonghong Song
2021-01-11 18:59 ` Hao Luo
2021-01-11 21:31 ` Andrii Nakryiko
2021-01-08 22:09 ` [PATCH v2 bpf-next 6/7] libbpf: support kernel module ksym externs Andrii Nakryiko
2021-01-11 4:15 ` Yonghong Song
2021-01-11 21:37 ` Andrii Nakryiko
2021-01-12 1:34 ` Yonghong Song
2021-01-12 6:45 ` Andrii Nakryiko
2021-01-11 19:00 ` Hao Luo
2021-01-11 21:39 ` Andrii Nakryiko
2021-01-08 22:09 ` [PATCH v2 bpf-next 7/7] selftests/bpf: test " Andrii Nakryiko
2021-01-11 4:18 ` Yonghong Song [this message]
2021-01-11 21:40 ` Andrii Nakryiko
2021-01-11 19:00 ` Hao Luo
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=24b84186-4cd6-131c-2284-d0fdc51ce7b4@fb.com \
--to=yhs@fb.com \
--cc=andrii@kernel.org \
--cc=ast@fb.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=haoluo@google.com \
--cc=kernel-team@fb.com \
--cc=netdev@vger.kernel.org \
/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