Skip to content

Commit 988369d

Browse files
devnexenhtejun
authored andcommitted
tools/sched_ext: scx_central: fix sched_setaffinity() call with the set size
The cpu set is dynamically allocated for nr_cpu_ids using CPU_ALLOC(), so the size passed to sched_setaffinity() should be CPU_ALLOC_SIZE() rather than sizeof(cpu_set_t). Valgrind flagged this as accessing unaddressable bytes past the allocation. Signed-off-by: David Carlier <devnexen@gmail.com> Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent 11fece4 commit 988369d

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

tools/sched_ext/scx_central.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ int main(int argc, char **argv)
5050
__u64 seq = 0, ecode;
5151
__s32 opt;
5252
cpu_set_t *cpuset;
53+
size_t cpuset_size;
5354

5455
libbpf_set_print(libbpf_print_fn);
5556
signal(SIGINT, sigint_handler);
@@ -106,9 +107,10 @@ int main(int argc, char **argv)
106107
*/
107108
cpuset = CPU_ALLOC(skel->rodata->nr_cpu_ids);
108109
SCX_BUG_ON(!cpuset, "Failed to allocate cpuset");
109-
CPU_ZERO_S(CPU_ALLOC_SIZE(skel->rodata->nr_cpu_ids), cpuset);
110+
cpuset_size = CPU_ALLOC_SIZE(skel->rodata->nr_cpu_ids);
111+
CPU_ZERO_S(cpuset_size, cpuset);
110112
CPU_SET(skel->rodata->central_cpu, cpuset);
111-
SCX_BUG_ON(sched_setaffinity(0, sizeof(*cpuset), cpuset),
113+
SCX_BUG_ON(sched_setaffinity(0, cpuset_size, cpuset),
112114
"Failed to affinitize to central CPU %d (max %d)",
113115
skel->rodata->central_cpu, skel->rodata->nr_cpu_ids - 1);
114116
CPU_FREE(cpuset);

0 commit comments

Comments
 (0)