diff options
| author | David Carlier <devnexen@gmail.com> | 2026-02-17 23:08:36 +0300 |
|---|---|---|
| committer | Tejun Heo <tj@kernel.org> | 2026-02-18 20:03:57 +0300 |
| commit | 625be3456b3ced6e2dca6166962c0cf6cc2e546d (patch) | |
| tree | 490e4be1332f4150bb869200df639c40b62736ad | |
| parent | 55a24d9203979d1cd0196ba1d189860e8b828c2e (diff) | |
| download | linux-625be3456b3ced6e2dca6166962c0cf6cc2e546d.tar.xz | |
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>
| -rw-r--r-- | tools/sched_ext/scx_pair.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/tools/sched_ext/scx_pair.c b/tools/sched_ext/scx_pair.c index d3e97faa6334..2a82d8a8a0aa 100644 --- a/tools/sched_ext/scx_pair.c +++ b/tools/sched_ext/scx_pair.c @@ -56,7 +56,6 @@ restart: skel = SCX_OPS_OPEN(pair_ops, scx_pair); skel->rodata->nr_cpu_ids = libbpf_num_possible_cpus(); - assert(skel->rodata->nr_cpu_ids > 0); skel->rodata->pair_batch_dur_ns = __COMPAT_ENUM_OR_ZERO("scx_public_consts", "SCX_SLICE_DFL"); /* pair up the earlier half to the latter by default, override with -s */ @@ -76,6 +75,12 @@ restart: } } + /* Stride must be positive to pair distinct CPUs. */ + if (stride <= 0) { + fprintf(stderr, "Invalid stride %d, must be positive\n", stride); + scx_pair__destroy(skel); + return -1; + } bpf_map__set_max_entries(skel->maps.pair_ctx, skel->rodata->nr_cpu_ids / 2); /* Resize arrays so their element count is equal to cpu count. */ |
