From: David Carlier <devnexen@gmail.com>
To: Tejun Heo <tj@kernel.org>, David Vernet <dvernet@meta.com>
Cc: linux-kernel@vger.kernel.org, David Carlier <devnexen@gmail.com>
Subject: [PATCH] tools/sched_ext: scx_central: fix sched_setaffinity() call with the set size
Date: Wed, 11 Feb 2026 21:30:27 +0000 [thread overview]
Message-ID: <20260211213027.914485-1-devnexen@gmail.com> (raw)
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>
---
tools/sched_ext/scx_central.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/tools/sched_ext/scx_central.c b/tools/sched_ext/scx_central.c
index 55931a4cd71c..a6dfd45de70c 100644
--- a/tools/sched_ext/scx_central.c
+++ b/tools/sched_ext/scx_central.c
@@ -50,6 +50,7 @@ int main(int argc, char **argv)
__u64 seq = 0, ecode;
__s32 opt;
cpu_set_t *cpuset;
+ size_t cpuset_size;
libbpf_set_print(libbpf_print_fn);
signal(SIGINT, sigint_handler);
@@ -106,9 +107,10 @@ int main(int argc, char **argv)
*/
cpuset = CPU_ALLOC(skel->rodata->nr_cpu_ids);
SCX_BUG_ON(!cpuset, "Failed to allocate cpuset");
- CPU_ZERO_S(CPU_ALLOC_SIZE(skel->rodata->nr_cpu_ids), cpuset);
+ cpuset_size = CPU_ALLOC_SIZE(skel->rodata->nr_cpu_ids);
+ CPU_ZERO_S(cpuset_size, cpuset);
CPU_SET(skel->rodata->central_cpu, cpuset);
- SCX_BUG_ON(sched_setaffinity(0, sizeof(*cpuset), cpuset),
+ SCX_BUG_ON(sched_setaffinity(0, cpuset_size, cpuset),
"Failed to affinitize to central CPU %d (max %d)",
skel->rodata->central_cpu, skel->rodata->nr_cpu_ids - 1);
CPU_FREE(cpuset);
--
2.51.0
next reply other threads:[~2026-02-11 21:30 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-11 21:30 David Carlier [this message]
2026-02-12 17:31 ` [PATCH] tools/sched_ext: scx_central: fix sched_setaffinity() call with the set size Tejun Heo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260211213027.914485-1-devnexen@gmail.com \
--to=devnexen@gmail.com \
--cc=dvernet@meta.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.