public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: Paul Chaignon <paul.chaignon@gmail.com>
To: Matt Bobrowski <mattbobrowski@google.com>
Cc: bpf@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Eduard Zingerman <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	Jiri Olsa <jolsa@kernel.org>,
	Emil Tsalapatis <emil@etsalapatis.com>
Subject: Re: [PATCH bpf-next] selftests/bpf: fix off-by-one in bpf_cpumask_populate related selftest
Date: Mon, 20 Apr 2026 14:00:04 +0200	[thread overview]
Message-ID: <aeYVRJhCs3lSLJAS@mail.gmail.com> (raw)
In-Reply-To: <20260420093734.2400330-1-mattbobrowski@google.com>

On Mon, Apr 20, 2026 at 09:37:34AM +0000, Matt Bobrowski wrote:
> The test_populate test uses >= instead of > when checking if the
> runtime nr_cpus exceeds the bit capacity of a cpumask_t.
> 
> On a system where the physical CPU core count perfectly matches the
> CONFIG_NR_CPUS upper bound (e.g. nr_cpus = 512 and CONFIG_NR_CPUS =
> 512), the condition nr_cpus >= CPUMASK_TEST_MASKLEN * 8 evaluates to
> true (512 >= 512). This incorrectly causes the test to fail with an
> error value of 3.
> 
> A 512-bit cpumask_t provides enough bits (indices 0 through 511) to
> represent 512 CPUs. The subsequent bpf_for(i, 0, nr_cpus) loop
> iterates up to nr_cpus - 1 (511), which perfectly aligns with the
> maximum valid index of the bitmask.
> 
> Change the condition to nr_cpus > CPUMASK_TEST_MASKLEN * 8 to fix the
> false positive failure on these systems.
> 
> Fixes: 918ba2636d4e ("selftests: bpf: add bpf_cpumask_populate selftests")
> Signed-off-by: Matt Bobrowski <mattbobrowski@google.com>

Acked-by: Paul Chaignon <paul.chaignon@gmail.com>

> ---
>  tools/testing/selftests/bpf/progs/cpumask_success.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/bpf/progs/cpumask_success.c b/tools/testing/selftests/bpf/progs/cpumask_success.c
> index 0e04c31b91c0..774706e7b058 100644
> --- a/tools/testing/selftests/bpf/progs/cpumask_success.c
> +++ b/tools/testing/selftests/bpf/progs/cpumask_success.c
> @@ -866,7 +866,7 @@ int BPF_PROG(test_populate, struct task_struct *task, u64 clone_flags)
>  	 * access NR_CPUS, the upper bound for nr_cpus, so we infer
>  	 * it from the size of cpumask_t.
>  	 */
> -	if (nr_cpus < 0 || nr_cpus >= CPUMASK_TEST_MASKLEN * 8) {
> +	if (nr_cpus < 0 || nr_cpus > CPUMASK_TEST_MASKLEN * 8) {
>  		err = 3;
>  		goto out;
>  	}
> -- 
> 2.54.0.rc1.513.gad8abe7a5a-goog
> 
> 

  reply	other threads:[~2026-04-20 12:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-20  9:37 [PATCH bpf-next] selftests/bpf: fix off-by-one in bpf_cpumask_populate related selftest Matt Bobrowski
2026-04-20 12:00 ` Paul Chaignon [this message]
2026-04-20 14:30 ` 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=aeYVRJhCs3lSLJAS@mail.gmail.com \
    --to=paul.chaignon@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=jolsa@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=mattbobrowski@google.com \
    --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