Skip to content

Commit 625be34

Browse files
devnexenhtejun
authored andcommitted
tools/sched_ext: scx_pair: fix stride == 0 crash on single-CPU systems
nr_cpu_ids / 2 produces stride 0 on a single-CPU system, which later causes SCX_BUG_ON(i == j) to fire. Validate stride after option parsing to also catch invalid user-supplied values via -S. Signed-off-by: David Carlier <devnexen@gmail.com> Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent 55a24d9 commit 625be34

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

tools/sched_ext/scx_pair.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ int main(int argc, char **argv)
5656
skel = SCX_OPS_OPEN(pair_ops, scx_pair);
5757

5858
skel->rodata->nr_cpu_ids = libbpf_num_possible_cpus();
59-
assert(skel->rodata->nr_cpu_ids > 0);
6059
skel->rodata->pair_batch_dur_ns = __COMPAT_ENUM_OR_ZERO("scx_public_consts", "SCX_SLICE_DFL");
6160

6261
/* pair up the earlier half to the latter by default, override with -s */
@@ -76,6 +75,12 @@ int main(int argc, char **argv)
7675
}
7776
}
7877

78+
/* Stride must be positive to pair distinct CPUs. */
79+
if (stride <= 0) {
80+
fprintf(stderr, "Invalid stride %d, must be positive\n", stride);
81+
scx_pair__destroy(skel);
82+
return -1;
83+
}
7984
bpf_map__set_max_entries(skel->maps.pair_ctx, skel->rodata->nr_cpu_ids / 2);
8085

8186
/* Resize arrays so their element count is equal to cpu count. */

0 commit comments

Comments
 (0)