public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: Yonghong Song <yonghong.song@linux.dev>
To: KaFai Wan <kafai.wan@linux.dev>,
	ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
	martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org,
	john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me,
	haoluo@google.com, jolsa@kernel.org, shuah@kernel.org,
	toke@redhat.com, linux-kernel@vger.kernel.org,
	bpf@vger.kernel.org, linux-kselftest@vger.kernel.org
Subject: Re: [PATCH bpf v2 2/2] selftests/bpf: Add test for unpinning htab with internal timer struct
Date: Mon, 6 Oct 2025 21:04:26 -0700	[thread overview]
Message-ID: <79ffb312-4aa4-425e-b05b-02aee21acfe6@linux.dev> (raw)
In-Reply-To: <20251007012235.755853-3-kafai.wan@linux.dev>



On 10/6/25 6:22 PM, KaFai Wan wrote:
> Add test to verify that unpinning hash tables containing internal timer
> structures does not trigger context warnings.
>
> Each subtest (timer_prealloc and timer_no_prealloc) can trigger the
> context warning when unpinning, but the warning cannot be triggered
> twice within a short time interval (a HZ), which is expected behavior.
>
> Signed-off-by: KaFai Wan <kafai.wan@linux.dev>

Ack with a nit below.

Acked-by: Yonghong Song <yonghong.song@linux.dev>

> ---
>   .../selftests/bpf/prog_tests/pinning_htab.c   | 37 +++++++++++++++++++
>   .../selftests/bpf/progs/test_pinning_htab.c   | 25 +++++++++++++
>   2 files changed, 62 insertions(+)
>   create mode 100644 tools/testing/selftests/bpf/prog_tests/pinning_htab.c
>   create mode 100644 tools/testing/selftests/bpf/progs/test_pinning_htab.c
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/pinning_htab.c b/tools/testing/selftests/bpf/prog_tests/pinning_htab.c
> new file mode 100644
> index 000000000000..fc804bb87b26
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/prog_tests/pinning_htab.c
> @@ -0,0 +1,37 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +#include <test_progs.h>
> +#include "test_pinning_htab.skel.h"
> +
> +static void unpin_map(const char *map_name, const char *pin_path)
> +{
> +	struct test_pinning_htab *skel;
> +	struct bpf_map *map;
> +	int err;
> +
> +	skel = test_pinning_htab__open_and_load();
> +	if (!ASSERT_OK_PTR(skel, "skel open_and_load"))
> +		return;
> +
> +	map = bpf_object__find_map_by_name(skel->obj, map_name);
> +	if (!ASSERT_OK_PTR(map, "bpf_object__find_map_by_name"))
> +		goto out;
> +
> +	err = bpf_map__pin(map, pin_path);
> +	if (!ASSERT_OK(err, "bpf_map__pin"))
> +		goto out;
> +
> +	err = bpf_map__unpin(map, pin_path);
> +	if (!ASSERT_OK(err, "bpf_map__unpin"))
> +		goto out;

No need to have 'goto out'. Just do
	ASSERT_OK(err, "bpf_map__unpin"

> +out:
> +	test_pinning_htab__destroy(skel);
> +}
> +
> +void test_pinning_htab(void)
> +{
> +	if (test__start_subtest("timer_prealloc"))
> +		unpin_map("timer_prealloc", "/sys/fs/bpf/timer_prealloc");
> +	if (test__start_subtest("timer_no_prealloc"))
> +		unpin_map("timer_no_prealloc", "/sys/fs/bpf/timer_no_prealloc");
> +}
> diff --git a/tools/testing/selftests/bpf/progs/test_pinning_htab.c b/tools/testing/selftests/bpf/progs/test_pinning_htab.c
> new file mode 100644
> index 000000000000..ae227930c73c
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/progs/test_pinning_htab.c
> @@ -0,0 +1,25 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +#include "vmlinux.h"
> +#include <bpf/bpf_helpers.h>
> +
> +char _license[] SEC("license") = "GPL";
> +
> +struct timer_val {
> +	struct bpf_timer timer;
> +};
> +
> +struct {
> +	__uint(type, BPF_MAP_TYPE_HASH);
> +	__type(key, __u32);
> +	__type(value, struct timer_val);
> +	__uint(max_entries, 1);
> +} timer_prealloc SEC(".maps");
> +
> +struct {
> +	__uint(type, BPF_MAP_TYPE_HASH);
> +	__type(key, __u32);
> +	__type(value, struct timer_val);
> +	__uint(max_entries, 1);
> +	__uint(map_flags, BPF_F_NO_PREALLOC);
> +} timer_no_prealloc SEC(".maps");


      reply	other threads:[~2025-10-07  4:04 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-07  1:22 [PATCH bpf v2 0/2] bpf: Avoid RCU context warning when unpinning htab with internal structs KaFai Wan
2025-10-07  1:22 ` [PATCH bpf v2 1/2] " KaFai Wan
2025-10-07  4:05   ` Yonghong Song
2025-10-07  1:22 ` [PATCH bpf v2 2/2] selftests/bpf: Add test for unpinning htab with internal timer struct KaFai Wan
2025-10-07  4:04   ` Yonghong Song [this message]

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=79ffb312-4aa4-425e-b05b-02aee21acfe6@linux.dev \
    --to=yonghong.song@linux.dev \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kafai.wan@linux.dev \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=sdf@fomichev.me \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=toke@redhat.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