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_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>

authored by

David Carlier and committed by
Tejun Heo
988369d2 11fece49

+4 -2
+4 -2
tools/sched_ext/scx_central.c
··· 50 50 __u64 seq = 0, ecode; 51 51 __s32 opt; 52 52 cpu_set_t *cpuset; 53 + size_t cpuset_size; 53 54 54 55 libbpf_set_print(libbpf_print_fn); 55 56 signal(SIGINT, sigint_handler); ··· 107 106 */ 108 107 cpuset = CPU_ALLOC(skel->rodata->nr_cpu_ids); 109 108 SCX_BUG_ON(!cpuset, "Failed to allocate cpuset"); 110 - CPU_ZERO_S(CPU_ALLOC_SIZE(skel->rodata->nr_cpu_ids), cpuset); 109 + cpuset_size = CPU_ALLOC_SIZE(skel->rodata->nr_cpu_ids); 110 + CPU_ZERO_S(cpuset_size, cpuset); 111 111 CPU_SET(skel->rodata->central_cpu, cpuset); 112 - SCX_BUG_ON(sched_setaffinity(0, sizeof(*cpuset), cpuset), 112 + SCX_BUG_ON(sched_setaffinity(0, cpuset_size, cpuset), 113 113 "Failed to affinitize to central CPU %d (max %d)", 114 114 skel->rodata->central_cpu, skel->rodata->nr_cpu_ids - 1); 115 115 CPU_FREE(cpuset);