Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

David Carlier and committed by
Tejun Heo
625be345 55a24d92

+6 -1
+6 -1
tools/sched_ext/scx_pair.c
··· 56 56 skel = SCX_OPS_OPEN(pair_ops, scx_pair); 57 57 58 58 skel->rodata->nr_cpu_ids = libbpf_num_possible_cpus(); 59 - assert(skel->rodata->nr_cpu_ids > 0); 60 59 skel->rodata->pair_batch_dur_ns = __COMPAT_ENUM_OR_ZERO("scx_public_consts", "SCX_SLICE_DFL"); 61 60 62 61 /* pair up the earlier half to the latter by default, override with -s */ ··· 75 76 } 76 77 } 77 78 79 + /* Stride must be positive to pair distinct CPUs. */ 80 + if (stride <= 0) { 81 + fprintf(stderr, "Invalid stride %d, must be positive\n", stride); 82 + scx_pair__destroy(skel); 83 + return -1; 84 + } 78 85 bpf_map__set_max_entries(skel->maps.pair_ctx, skel->rodata->nr_cpu_ids / 2); 79 86 80 87 /* Resize arrays so their element count is equal to cpu count. */