From: David Carlier <devnexen@gmail.com>
To: Tejun Heo <tj@kernel.org>, Andrea Righi <arighi@nvidia.com>
Cc: linux-kernel@vger.kernel.org, David Carlier <devnexen@gmail.com>
Subject: [PATCH 3/3] scx_userland: fix restart and stats thread lifecycle bugs
Date: Thu, 12 Feb 2026 20:35:19 +0000 [thread overview]
Message-ID: <20260212203519.15091-1-devnexen@gmail.com> (raw)
Fix three issues in scx_userland's restart path:
- exit_req is not reset on restart, causing sched_main_loop() to exit
immediately without doing any scheduling work.
- stats_printer thread handle is local to spawn_stats_thread(), making
it impossible to join from main(). Promote it to file scope.
- The stats thread continues reading skel->bss after the skeleton is
destroyed on restart, causing a use-after-free. Join the stats thread
before destroying the skeleton to ensure it has exited.
Signed-off-by: David Carlier <devnexen@gmail.com>
---
tools/sched_ext/scx_userland.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/tools/sched_ext/scx_userland.c b/tools/sched_ext/scx_userland.c
index 10b31020f44f..63f89b35d999 100644
--- a/tools/sched_ext/scx_userland.c
+++ b/tools/sched_ext/scx_userland.c
@@ -54,6 +54,7 @@ static bool verbose;
static volatile int exit_req;
static int enqueued_fd, dispatched_fd;
+static pthread_t stats_printer;
static struct scx_userland *skel;
static struct bpf_link *ops_link;
@@ -319,8 +320,6 @@ static void *run_stats_printer(void *arg)
static int spawn_stats_thread(void)
{
- pthread_t stats_printer;
-
return pthread_create(&stats_printer, NULL, run_stats_printer, NULL);
}
@@ -375,6 +374,7 @@ static void pre_bootstrap(int argc, char **argv)
static void bootstrap(char *comm)
{
+ exit_req = 0;
skel = SCX_OPS_OPEN(userland_ops, scx_userland);
skel->rodata->num_possible_cpus = libbpf_num_possible_cpus();
@@ -428,6 +428,7 @@ int main(int argc, char **argv)
exit_req = 1;
bpf_link__destroy(ops_link);
+ pthread_join(stats_printer, NULL);
ecode = UEI_REPORT(skel, uei);
scx_userland__destroy(skel);
--
2.51.0
next reply other threads:[~2026-02-12 20:35 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-12 20:35 David Carlier [this message]
2026-02-12 21:19 ` [PATCH 3/3] scx_userland: fix restart and stats thread lifecycle bugs 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=20260212203519.15091-1-devnexen@gmail.com \
--to=devnexen@gmail.com \
--cc=arighi@nvidia.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.