Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: Leon Hwang <leon.hwang@linux.dev>
To: bot+bpf-ci@kernel.org, bpf@vger.kernel.org
Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
	martin.lau@linux.dev, eddyz87@gmail.com, memxor@gmail.com,
	song@kernel.org, yonghong.song@linux.dev, jolsa@kernel.org,
	john.fastabend@gmail.com, qmo@kernel.org, shuah@kernel.org,
	linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
	kernel-patches-bot@fb.com, martin.lau@kernel.org, clm@meta.com,
	ihor.solodrai@linux.dev
Subject: Re: [PATCH bpf-next v7 08/11] selftests/bpf: Add tests to verify global percpu data
Date: Tue, 23 Jun 2026 12:02:02 +0800	[thread overview]
Message-ID: <79c14f81-0917-45dd-af0f-689d470b5370@linux.dev> (raw)
In-Reply-To: <eebc3e5edf723fd9c43307225efa00263590db7b56f385d384ff9b3f0220dd78@mail.kernel.org>

On 22/6/26 23:24, bot+bpf-ci@kernel.org wrote:
>> diff --git a/tools/testing/selftests/bpf/prog_tests/global_data_init.c b/tools/testing/selftests/bpf/prog_tests/global_data_init.c
>> index 8466332d7406..ea7e4e3d91cf 100644
>> --- a/tools/testing/selftests/bpf/prog_tests/global_data_init.c
>> +++ b/tools/testing/selftests/bpf/prog_tests/global_data_init.c
> 
> [ ... ]
> 
>> @@ -60,3 +63,184 @@ void test_global_data_init(void)
>> +
>> +static void test_global_percpu_data_init(void)
>> +{
>> +	struct test_global_percpu_data__percpu init_value = {};
>> +	struct test_global_percpu_data__percpu *init_data;
>> +	int key, prog_fd, err, num_cpus, num_online, i;
>> +	struct test_global_percpu_data *skel = NULL;
>> +	__u64 args[2] = {0x1234ULL, 0x5678ULL};
>> +	size_t init_data_sz;
>> +	struct bpf_map *map;
>> +	bool *online;
>> +	LIBBPF_OPTS(bpf_test_run_opts, topts,
>> +		    .ctx_in = args,
>> +		    .ctx_size_in = sizeof(args),
>> +		    .flags = BPF_F_TEST_RUN_ON_CPU,
>> +	);
>> +
>> +	num_cpus = libbpf_num_possible_cpus();
>> +	if (!ASSERT_GT(num_cpus, 0, "libbpf_num_possible_cpus"))
>> +		return;
>> +
>> +	err = parse_cpu_mask_file("/sys/devices/system/cpu/online", &online, &num_online);
>> +	if (!ASSERT_OK(err, "parse_cpu_mask_file"))
>> +		return;
> 
> This isn't a bug, but num_cpus is only read by the ASSERT_GT guard and is
> never used afterwards; the per-CPU loop is driven entirely by num_online
> from parse_cpu_mask_file().  Is the libbpf_num_possible_cpus() check needed
> here, or is num_online sufficient?  The same pattern appears in
> test_global_percpu_data_lskel().
> 

Will drop the unused "num_cpus".

> [ ... ]
> 
>> +static void test_global_percpu_data_lskel(void)
>> +{
> 
> [ ... ]
> 
>> +		flags = ((__u64) i << 32) | BPF_F_CPU;
>> +		err = bpf_map_lookup_elem_flags(map_fd, &key, &data, flags);
>> +		if (!ASSERT_OK(err, "bpf_map_lookup_elem_flags"))
>> +			goto out;
>> +
>> +		ASSERT_EQ(data.data, 1, "data.data");
>> +		ASSERT_TRUE(data.run, "data.run");
>> +		ASSERT_EQ(data.nums[6], 0xc0de, "data.nums[6]");
>> +		ASSERT_EQ(data.struct_data.i, 1, "struct_data.i");
>> +		ASSERT_TRUE(data.struct_data.set, "struct_data.set");
>> +		ASSERT_EQ(data.struct_data.nums[6], 0xc0de, "struct_data.nums[6]");
>> +	}
> 
> This isn't a bug, but this post-run assertion block duplicates the one in
> test_global_percpu_data_init() almost verbatim; the two loops share the same
> online-CPU iteration, the same bpf_prog_test_run_opts setup, and the same six
> data.* checks, differing only in the lookup call (bpf_map_lookup_elem_flags()
> vs bpf_map__lookup_elem()).  Could the six data.* checks be factored into a
> shared helper taking the looked-up value?
> 

Good catch.

Will factor out a helper for the whole 'for' block.

Thanks,
Leon


  reply	other threads:[~2026-06-23  4:02 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-22 14:35 [PATCH bpf-next v7 00/11] bpf: Introduce global percpu data Leon Hwang
2026-06-22 14:35 ` [PATCH bpf-next v7 01/11] bpf: Drop duplicate blank lines in verifier Leon Hwang
2026-06-22 14:35 ` [PATCH bpf-next v7 02/11] bpf: Disallow interpreter fallback for user BPF_ADDR_SPACE_CAST insn Leon Hwang
2026-06-22 14:35 ` [PATCH bpf-next v7 03/11] bpf: Disallow interpreter fallback for BPF_ADDR_PERCPU insn Leon Hwang
2026-06-22 14:35 ` [PATCH bpf-next v7 04/11] bpf: Introduce global percpu data Leon Hwang
2026-06-22 14:35 ` [PATCH bpf-next v7 05/11] libbpf: Probe percpu data feature Leon Hwang
2026-06-22 14:35 ` [PATCH bpf-next v7 06/11] libbpf: Add support for global percpu data Leon Hwang
2026-06-22 14:35 ` [PATCH bpf-next v7 07/11] bpftool: Generate skeleton " Leon Hwang
2026-06-22 14:35 ` [PATCH bpf-next v7 08/11] selftests/bpf: Add tests to verify " Leon Hwang
2026-06-22 15:24   ` bot+bpf-ci
2026-06-23  4:02     ` Leon Hwang [this message]
2026-06-22 14:35 ` [PATCH bpf-next v7 09/11] selftests/bpf: Add test to verify accessing rdonly percpu_array Leon Hwang
2026-06-22 14:35 ` [PATCH bpf-next v7 10/11] selftests/bpf: Add tests to verify verifier log for global percpu data Leon Hwang
2026-06-22 14:35 ` [PATCH bpf-next v7 11/11] selftests/bpf: Add test to verify bpf_iter " Leon Hwang
2026-06-22 15:24   ` bot+bpf-ci
2026-06-23  4:04     ` Leon Hwang

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=79c14f81-0917-45dd-af0f-689d470b5370@linux.dev \
    --to=leon.hwang@linux.dev \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bot+bpf-ci@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=clm@meta.com \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=ihor.solodrai@linux.dev \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kernel-patches-bot@fb.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=martin.lau@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=memxor@gmail.com \
    --cc=qmo@kernel.org \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=yonghong.song@linux.dev \
    /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