Re: [PATCH bpf-next v3 1/2] bpf: Require a BPF cpumask for bpf_cpumask_populate()

"Kumar Kartikeya Dwivedi" <[email protected]>
Newsgroups dev.linux.lists.sched-ext,dev.linux.lists.sashiko-reviews,org.kernel.vger.bpf
Message-ID <[email protected]>
On Thu Jul 9, 2026 at 8:39 PM CEST, sashiko-bot wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [Low] The BPF selftests and their headers were not updated to reflect the new `struct bpf_cpumask *` signature for `bpf_cpumask_populate()`.
> --
>
> --- Patch [1]: [PATCH bpf-next v3 1/2] bpf: Require a BPF cpumask for bpf_cpumask_populate() ---
> commit 79080c077263fb184f42fe92f3d8db1f3967a4b5
> Author: Nicholas Dudar <[email protected]>
>
> bpf: Require a BPF cpumask for bpf_cpumask_populate()
>
> This commit changes the first argument of bpf_cpumask_populate() to require
> a struct bpf_cpumask pointer instead of a struct cpumask pointer. This
> ensures the function follows the same ownership rules as other mutating
> cpumask kfuncs.
>
>> diff --git a/kernel/bpf/cpumask.c b/kernel/bpf/cpumask.c
>> index b8c805b4b06a0..1336a4efa7553 100644
>> --- a/kernel/bpf/cpumask.c
>> +++ b/kernel/bpf/cpumask.c
> [ ... ]
>> @@ -467,7 +467,7 @@ __bpf_kfunc int bpf_cpumask_populate(struct cpumask *cpumask, void *src, size_t
>>  		!IS_ALIGNED(source, sizeof(long)))
>>  		return -EINVAL;
>>
>> -	bitmap_copy(cpumask_bits(cpumask), src, nr_cpu_ids);
>> +	bitmap_copy(cpumask_bits(&cpumask->cpumask), src, nr_cpu_ids);
>>
>>  	return 0;
>>  }
>> diff --git a/tools/sched_ext/include/scx/compat.bpf.h b/tools/sched_ext/include/scx/compat.bpf.h
>> index 87f15f2962348..3f74d522f7e79 100644
>> --- a/tools/sched_ext/include/scx/compat.bpf.h
>> +++ b/tools/sched_ext/include/scx/compat.bpf.h
>> @@ -84,7 +84,7 @@ bool scx_bpf_dispatch_vtime_from_dsq___old(struct bpf_iter_scx_dsq *it__iter, st
>>   *
>>   * Compat macro will be dropped on v6.19 release.
>>   */
>> -int bpf_cpumask_populate(struct cpumask *dst, void *src, size_t src__sz) __ksym __weak;
>> +int bpf_cpumask_populate(struct bpf_cpumask *dst, void *src, size_t src__sz) __ksym __weak;
>
> [Severity: Low]
> This isn't a bug, but should the BPF selftest headers also be updated to
> reflect this new signature?
>
> Looking at tools/testing/selftests/bpf/progs/cpumask_common.h, it appears it
> still declares the old signature for the kfunc:
>
> int bpf_cpumask_populate(struct cpumask *cpumask, void *src, size_t src__sz) __ksym __weak;
>
> Because of this, the tests in cpumask_success.c and cpumask_failure.c under
> tools/testing/selftests/bpf/progs/ continue to use explicit C-level casts
> from struct bpf_cpumask * to struct cpumask *. For example, in
> test_populate_success():
>
> ret = bpf_cpumask_populate((struct cpumask *)mask, bits, CPUMASK_TEST_MASKLEN);
>
> While this doesn't cause runtime failures since the BPF verifier matches the
> runtime register BTF type instead of C-level casts, updating the selftests
> would ensure complete consistency with the new kfunc signature.

Once this lands, please send a follow up to address this.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.