diff options
author | Daniel Bristot de Oliveira <bristot@redhat.com> | 2021-06-22 17:42:29 +0300 |
---|---|---|
committer | Steven Rostedt (VMware) <rostedt@goodmis.org> | 2021-06-26 02:57:24 +0300 |
commit | 039a602db393c00665e7a3b968b15fb6fd7042b1 (patch) | |
tree | 611af650bfef1c82513e65ec7bd83327f3973548 /kernel/trace | |
parent | a955d7eac1779b437ceb24fc352026a2cbcec140 (diff) | |
download | linux-039a602db393c00665e7a3b968b15fb6fd7042b1.tar.xz |
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/20210621134636.5b332226@oasis.local.home/
Link: https://lkml.kernel.org/r/8bdb2a56f46abfd301d6fffbf43448380c09a6f5.1624372313.git.bristot@redhat.com
Cc: Phil Auld <pauld@redhat.com>
Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Kate Carcia <kcarcia@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Alexandre Chartre <alexandre.chartre@oracle.com>
Cc: Clark Willaims <williams@redhat.com>
Cc: John Kacur <jkacur@redhat.com>
Cc: Juri Lelli <juri.lelli@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: x86@kernel.org
Cc: linux-doc@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Suggested-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Daniel Bristot de Oliveira <bristot@redhat.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Diffstat (limited to 'kernel/trace')
-rw-r--r-- | kernel/trace/trace_hwlat.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/kernel/trace/trace_hwlat.c b/kernel/trace/trace_hwlat.c index a625bfdb844e..20e31f79ebd9 100644 --- a/kernel/trace/trace_hwlat.c +++ b/kernel/trace/trace_hwlat.c @@ -396,13 +396,19 @@ static int kthread_fn(void *data) static void stop_single_kthread(void) { struct hwlat_kthread_data *kdata = get_cpu_data(); - struct task_struct *kthread = kdata->kthread; + struct task_struct *kthread; + + get_online_cpus(); + kthread = kdata->kthread; if (!kthread) - return; + goto out_put_cpus; kthread_stop(kthread); kdata->kthread = NULL; + +out_put_cpus: + put_online_cpus(); } @@ -419,20 +425,19 @@ static int start_single_kthread(struct trace_array *tr) struct task_struct *kthread; int next_cpu; + get_online_cpus(); if (kdata->kthread) - return 0; + goto out_put_cpus; kthread = kthread_create(kthread_fn, NULL, "hwlatd"); if (IS_ERR(kthread)) { pr_err(BANNER "could not start sampling thread\n"); + put_online_cpus(); return -ENOMEM; } - /* Just pick the first CPU on first iteration */ - get_online_cpus(); cpumask_and(current_mask, cpu_online_mask, tr->tracing_cpumask); - put_online_cpus(); if (hwlat_data.thread_mode == MODE_ROUND_ROBIN) { next_cpu = cpumask_first(current_mask); @@ -446,6 +451,8 @@ static int start_single_kthread(struct trace_array *tr) kdata->kthread = kthread; wake_up_process(kthread); +out_put_cpus: + put_online_cpus(); return 0; } |