Skip to content

Commit 039a602

Browse files
Daniel Bristot de Oliveirarostedt
authored andcommitted
trace/hwlat: Protect kdata->kthread with get/put_online_cpus
In preparation to the hotplug support, protect kdata->kthread with get/put_online_cpus() to avoid concurrency with hotplug operations. Link: https://lore.kernel.org/linux-doc/[email protected]/ Link: https://lkml.kernel.org/r/8bdb2a56f46abfd301d6fffbf43448380c09a6f5.1624372313.git.bristot@redhat.com Cc: Phil Auld <[email protected]> Cc: Sebastian Andrzej Siewior <[email protected]> Cc: Kate Carcia <[email protected]> Cc: Jonathan Corbet <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Alexandre Chartre <[email protected]> Cc: Clark Willaims <[email protected]> Cc: John Kacur <[email protected]> Cc: Juri Lelli <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: "H. Peter Anvin" <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Suggested-by: Steven Rostedt (VMware) <[email protected]> Signed-off-by: Daniel Bristot de Oliveira <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent a955d7e commit 039a602

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

kernel/trace/trace_hwlat.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -396,13 +396,19 @@ static int kthread_fn(void *data)
396396
static void stop_single_kthread(void)
397397
{
398398
struct hwlat_kthread_data *kdata = get_cpu_data();
399-
struct task_struct *kthread = kdata->kthread;
399+
struct task_struct *kthread;
400+
401+
get_online_cpus();
402+
kthread = kdata->kthread;
400403

401404
if (!kthread)
402-
return;
405+
goto out_put_cpus;
403406

404407
kthread_stop(kthread);
405408
kdata->kthread = NULL;
409+
410+
out_put_cpus:
411+
put_online_cpus();
406412
}
407413

408414

@@ -419,20 +425,19 @@ static int start_single_kthread(struct trace_array *tr)
419425
struct task_struct *kthread;
420426
int next_cpu;
421427

428+
get_online_cpus();
422429
if (kdata->kthread)
423-
return 0;
430+
goto out_put_cpus;
424431

425432
kthread = kthread_create(kthread_fn, NULL, "hwlatd");
426433
if (IS_ERR(kthread)) {
427434
pr_err(BANNER "could not start sampling thread\n");
435+
put_online_cpus();
428436
return -ENOMEM;
429437
}
430438

431-
432439
/* Just pick the first CPU on first iteration */
433-
get_online_cpus();
434440
cpumask_and(current_mask, cpu_online_mask, tr->tracing_cpumask);
435-
put_online_cpus();
436441

437442
if (hwlat_data.thread_mode == MODE_ROUND_ROBIN) {
438443
next_cpu = cpumask_first(current_mask);
@@ -446,6 +451,8 @@ static int start_single_kthread(struct trace_array *tr)
446451
kdata->kthread = kthread;
447452
wake_up_process(kthread);
448453

454+
out_put_cpus:
455+
put_online_cpus();
449456
return 0;
450457
}
451458

0 commit comments

Comments
 (0)