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_userland: fix restart and stats thread lifecycle bugs

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>
Signed-off-by: Tejun Heo <tj@kernel.org>

authored by

David Carlier and committed by
Tejun Heo
048714d9 988369d2

+3 -2
+3 -2
tools/sched_ext/scx_userland.c
··· 54 54 static volatile int exit_req; 55 55 static int enqueued_fd, dispatched_fd; 56 56 57 + static pthread_t stats_printer; 57 58 static struct scx_userland *skel; 58 59 static struct bpf_link *ops_link; 59 60 ··· 320 319 321 320 static int spawn_stats_thread(void) 322 321 { 323 - pthread_t stats_printer; 324 - 325 322 return pthread_create(&stats_printer, NULL, run_stats_printer, NULL); 326 323 } 327 324 ··· 374 375 375 376 static void bootstrap(char *comm) 376 377 { 378 + exit_req = 0; 377 379 skel = SCX_OPS_OPEN(userland_ops, scx_userland); 378 380 379 381 skel->rodata->num_possible_cpus = libbpf_num_possible_cpus(); ··· 428 428 429 429 exit_req = 1; 430 430 bpf_link__destroy(ops_link); 431 + pthread_join(stats_printer, NULL); 431 432 ecode = UEI_REPORT(skel, uei); 432 433 scx_userland__destroy(skel); 433 434