* bpf/selftests: test_access_variable_array breaks due to sched_domain::span removal
@ 2026-04-07 16:12 Venkat Rao Bagalkote
2026-04-07 17:33 ` Alexei Starovoitov
0 siblings, 1 reply; 5+ messages in thread
From: Venkat Rao Bagalkote @ 2026-04-07 16:12 UTC (permalink / raw)
To: bpf, Saket Kumar Bhaskar, Hari Bathini, Abhishek Dubey,
Alexei Starovoitov, Peter Zijlstra, Andrii Nakryiko,
Madhavan Srinivasan, LKML, Ritesh Harjani
Hi,
While running BPF selftests on current linux-next, I noticed that
test_access_variable_array fails to build due to reliance on
struct sched_domain::span, which is no longer appers to be BTF-visible
after recent
scheduler refactoring.
The Build error I am seeing is:
progs/test_access_variable_array.c:14:13: error: no member named 'span'
in 'struct sched_domain' CLNG-BPF [test_progs] test_check_mtu.bpf.o
14 | span = sd->span[0];
| ~~ ^
Below is a proposed update to the test that switches from
sched_domain::span to sched_group::cpumask. This preserves the original
intent of validating variable-length array access via BTF while avoiding
reliance on removed scheduler internals.
diff --git
a/tools/testing/selftests/bpf/progs/test_access_variable_array.c
b/tools/testing/selftests/bpf/progs/test_access_variable_array.c
index 326b7d1f496a..c9f345ccde3c 100644
--- a/tools/testing/selftests/bpf/progs/test_access_variable_array.c
+++ b/tools/testing/selftests/bpf/progs/test_access_variable_array.c
@@ -4,14 +4,18 @@
#include "vmlinux.h"
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
+#include <bpf/bpf_core_read.h>
-unsigned long span = 0;
+unsigned long cpumask0 = 0;
-SEC("fentry/sched_balance_rq")
-int BPF_PROG(fentry_fentry, int this_cpu, struct rq *this_rq,
- struct sched_domain *sd)
+SEC("fentry/sched_balance_find_dst_group_cpu")
+int BPF_PROG(fentry_fentry, struct sched_group *sg, struct task_struct *p,
+ int this_cpu)
{
- span = sd->span[0];
+ unsigned long *mask;
+ /* Read pointer to variable-length CPU mask */
+ mask = BPF_CORE_READ(sg, cpumask);
+ cpumask0 = mask[0];
return 0;
}
I have tested this change, and it seems to be working as expected.
# ./test_progs -t access_variable_array
#1 access_variable_array:OK
Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED
Please note that this comes from my early days of working on upstream
kernel contributions, and I am still learning the BPF and scheduler
internals. My understanding here may be incomplete, so I wanted to
share this primarily to report the breakage I am seeing and propose a
possible direction for fixing the test.
I would appreciate any feedback on whether this is the right approach,
or if there is a more appropriate structure or hook to use for
preserving the variable-length array coverage in this selftest.
Regards,
Venkat.
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: bpf/selftests: test_access_variable_array breaks due to sched_domain::span removal
2026-04-07 16:12 bpf/selftests: test_access_variable_array breaks due to sched_domain::span removal Venkat Rao Bagalkote
@ 2026-04-07 17:33 ` Alexei Starovoitov
2026-04-08 4:51 ` Saket Kumar Bhaskar
0 siblings, 1 reply; 5+ messages in thread
From: Alexei Starovoitov @ 2026-04-07 17:33 UTC (permalink / raw)
To: Venkat Rao Bagalkote
Cc: bpf, Saket Kumar Bhaskar, Hari Bathini, Abhishek Dubey,
Alexei Starovoitov, Peter Zijlstra, Andrii Nakryiko,
Madhavan Srinivasan, LKML, Ritesh Harjani
On Tue, Apr 7, 2026 at 9:12 AM Venkat Rao Bagalkote
<venkat88@linux.ibm.com> wrote:
>
> Hi,
>
>
> While running BPF selftests on current linux-next, I noticed that
> test_access_variable_array fails to build due to reliance on
> struct sched_domain::span, which is no longer appers to be BTF-visible
> after recent
> scheduler refactoring.
>
> The Build error I am seeing is:
>
> progs/test_access_variable_array.c:14:13: error: no member named 'span'
> in 'struct sched_domain' CLNG-BPF [test_progs] test_check_mtu.bpf.o
>
> 14 | span = sd->span[0];
> | ~~ ^
>
> Below is a proposed update to the test that switches from
> sched_domain::span to sched_group::cpumask. This preserves the original
> intent of validating variable-length array access via BTF while avoiding
> reliance on removed scheduler internals.
>
>
> diff --git
> a/tools/testing/selftests/bpf/progs/test_access_variable_array.c
> b/tools/testing/selftests/bpf/progs/test_access_variable_array.c
> index 326b7d1f496a..c9f345ccde3c 100644
> --- a/tools/testing/selftests/bpf/progs/test_access_variable_array.c
> +++ b/tools/testing/selftests/bpf/progs/test_access_variable_array.c
> @@ -4,14 +4,18 @@
> #include "vmlinux.h"
> #include <bpf/bpf_helpers.h>
> #include <bpf/bpf_tracing.h>
> +#include <bpf/bpf_core_read.h>
>
> -unsigned long span = 0;
> +unsigned long cpumask0 = 0;
>
> -SEC("fentry/sched_balance_rq")
> -int BPF_PROG(fentry_fentry, int this_cpu, struct rq *this_rq,
> - struct sched_domain *sd)
> +SEC("fentry/sched_balance_find_dst_group_cpu")
> +int BPF_PROG(fentry_fentry, struct sched_group *sg, struct task_struct *p,
> + int this_cpu)
> {
> - span = sd->span[0];
> + unsigned long *mask;
> + /* Read pointer to variable-length CPU mask */
> + mask = BPF_CORE_READ(sg, cpumask);
> + cpumask0 = mask[0];
No. That defeats the point of the test.
It tests [] array in the kernel struct.
Just make one in testmod.ko and access that.
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: bpf/selftests: test_access_variable_array breaks due to sched_domain::span removal
2026-04-07 17:33 ` Alexei Starovoitov
@ 2026-04-08 4:51 ` Saket Kumar Bhaskar
2026-04-08 7:56 ` Peter Zijlstra
0 siblings, 1 reply; 5+ messages in thread
From: Saket Kumar Bhaskar @ 2026-04-08 4:51 UTC (permalink / raw)
To: Alexei Starovoitov
Cc: Venkat Rao Bagalkote, bpf, Hari Bathini, Abhishek Dubey,
Alexei Starovoitov, Peter Zijlstra, Andrii Nakryiko,
Madhavan Srinivasan, LKML, Ritesh Harjani
On Tue, Apr 07, 2026 at 10:33:51AM -0700, Alexei Starovoitov wrote:
> On Tue, Apr 7, 2026 at 9:12 AM Venkat Rao Bagalkote
> <venkat88@linux.ibm.com> wrote:
> >
> > Hi,
> >
> >
> > While running BPF selftests on current linux-next, I noticed that
> > test_access_variable_array fails to build due to reliance on
> > struct sched_domain::span, which is no longer appers to be BTF-visible
> > after recent
> > scheduler refactoring.
> >
> > The Build error I am seeing is:
> >
> > progs/test_access_variable_array.c:14:13: error: no member named 'span'
> > in 'struct sched_domain' CLNG-BPF [test_progs] test_check_mtu.bpf.o
> >
> > 14 | span = sd->span[0];
> > | ~~ ^
> >
> > Below is a proposed update to the test that switches from
> > sched_domain::span to sched_group::cpumask. This preserves the original
> > intent of validating variable-length array access via BTF while avoiding
> > reliance on removed scheduler internals.
> >
> >
> > diff --git
> > a/tools/testing/selftests/bpf/progs/test_access_variable_array.c
> > b/tools/testing/selftests/bpf/progs/test_access_variable_array.c
> > index 326b7d1f496a..c9f345ccde3c 100644
> > --- a/tools/testing/selftests/bpf/progs/test_access_variable_array.c
> > +++ b/tools/testing/selftests/bpf/progs/test_access_variable_array.c
> > @@ -4,14 +4,18 @@
> > #include "vmlinux.h"
> > #include <bpf/bpf_helpers.h>
> > #include <bpf/bpf_tracing.h>
> > +#include <bpf/bpf_core_read.h>
> >
> > -unsigned long span = 0;
> > +unsigned long cpumask0 = 0;
> >
> > -SEC("fentry/sched_balance_rq")
> > -int BPF_PROG(fentry_fentry, int this_cpu, struct rq *this_rq,
> > - struct sched_domain *sd)
> > +SEC("fentry/sched_balance_find_dst_group_cpu")
> > +int BPF_PROG(fentry_fentry, struct sched_group *sg, struct task_struct *p,
> > + int this_cpu)
> > {
> > - span = sd->span[0];
> > + unsigned long *mask;
> > + /* Read pointer to variable-length CPU mask */
> > + mask = BPF_CORE_READ(sg, cpumask);
> > + cpumask0 = mask[0];
>
> No. That defeats the point of the test.
> It tests [] array in the kernel struct.
> Just make one in testmod.ko and access that.
Hi Alexei,
We do have cpumask as [] array in sched_group:
struct sched_group {
struct sched_group *next; /* Must be a circular list */
atomic_t ref;
unsigned int group_weight;
unsigned int cores;
struct sched_group_capacity *sgc;
int asym_prefer_cpu; /* CPU of highest priority in group */
int flags;
/*
* The CPUs this group covers.
*
* NOTE: this field is variable length. (Allocated dynamically
* by attaching extra space to the end of the structure,
* depending on how many CPUs the kernel has booted up with)
*/
unsigned long cpumask[];
};
Wouldn't be good if it is used as:
cpumask0 = sg->cpumask[0];
Also, there is already a selftest that makes [] in testmod.ko
and access that.
Thanks,
Saket
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: bpf/selftests: test_access_variable_array breaks due to sched_domain::span removal
2026-04-08 4:51 ` Saket Kumar Bhaskar
@ 2026-04-08 7:56 ` Peter Zijlstra
2026-04-08 8:36 ` Alan Maguire
0 siblings, 1 reply; 5+ messages in thread
From: Peter Zijlstra @ 2026-04-08 7:56 UTC (permalink / raw)
To: Saket Kumar Bhaskar
Cc: Alexei Starovoitov, Venkat Rao Bagalkote, bpf, Hari Bathini,
Abhishek Dubey, Alexei Starovoitov, Andrii Nakryiko,
Madhavan Srinivasan, LKML, Ritesh Harjani
On Wed, Apr 08, 2026 at 10:21:46AM +0530, Saket Kumar Bhaskar wrote:
> We do have cpumask as [] array in sched_group:
>
> struct sched_group {
> struct sched_group *next; /* Must be a circular list */
> atomic_t ref;
>
> unsigned int group_weight;
> unsigned int cores;
> struct sched_group_capacity *sgc;
> int asym_prefer_cpu; /* CPU of highest priority in group */
> int flags;
>
> /*
> * The CPUs this group covers.
> *
> * NOTE: this field is variable length. (Allocated dynamically
> * by attaching extra space to the end of the structure,
> * depending on how many CPUs the kernel has booted up with)
> */
> unsigned long cpumask[];
> };
For now. But given how utterly broken flex arrays are, this thing will
be gone the second we run into that same thing again.
> Wouldn't be good if it is used as:
>
> cpumask0 = sg->cpumask[0];
I'm thinking Alexei's point is that this test should not rely on random
kernel code.
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: bpf/selftests: test_access_variable_array breaks due to sched_domain::span removal
2026-04-08 7:56 ` Peter Zijlstra
@ 2026-04-08 8:36 ` Alan Maguire
0 siblings, 0 replies; 5+ messages in thread
From: Alan Maguire @ 2026-04-08 8:36 UTC (permalink / raw)
To: Peter Zijlstra, Saket Kumar Bhaskar
Cc: Alexei Starovoitov, Venkat Rao Bagalkote, bpf, Hari Bathini,
Abhishek Dubey, Alexei Starovoitov, Andrii Nakryiko,
Madhavan Srinivasan, LKML, Ritesh Harjani
On 08/04/2026 08:56, Peter Zijlstra wrote:
> On Wed, Apr 08, 2026 at 10:21:46AM +0530, Saket Kumar Bhaskar wrote:
>
>> We do have cpumask as [] array in sched_group:
>>
>> struct sched_group {
>> struct sched_group *next; /* Must be a circular list */
>> atomic_t ref;
>>
>> unsigned int group_weight;
>> unsigned int cores;
>> struct sched_group_capacity *sgc;
>> int asym_prefer_cpu; /* CPU of highest priority in group */
>> int flags;
>>
>> /*
>> * The CPUs this group covers.
>> *
>> * NOTE: this field is variable length. (Allocated dynamically
>> * by attaching extra space to the end of the structure,
>> * depending on how many CPUs the kernel has booted up with)
>> */
>> unsigned long cpumask[];
>> };
>
> For now. But given how utterly broken flex arrays are, this thing will
> be gone the second we run into that same thing again.
>
>> Wouldn't be good if it is used as:
>>
>> cpumask0 = sg->cpumask[0];
>
> I'm thinking Alexei's point is that this test should not rely on random
> kernel code.
>
looks like we already have
struct bpf_testmod_struct_arg_3 {
int a;
int b[];
};
and function
int bpf_testmod_test_struct_arg_3(int a, int b, struct bpf_testmod_struct_arg_2 c);
...in selftests/bpf/test_kmods/bpf_testmod.c so we could potentially use that instead.
Alan
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-04-08 8:36 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-07 16:12 bpf/selftests: test_access_variable_array breaks due to sched_domain::span removal Venkat Rao Bagalkote
2026-04-07 17:33 ` Alexei Starovoitov
2026-04-08 4:51 ` Saket Kumar Bhaskar
2026-04-08 7:56 ` Peter Zijlstra
2026-04-08 8:36 ` Alan Maguire
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox