Skip to content

Commit 1f98857

Browse files
HaiyangLuorostedt
authored andcommitted
tracing: Fix potential deadlock in cpu hotplug with osnoise
The following sequence may leads deadlock in cpu hotplug: task1 task2 task3 ----- ----- ----- mutex_lock(&interface_lock) [CPU GOING OFFLINE] cpus_write_lock(); osnoise_cpu_die(); kthread_stop(task3); wait_for_completion(); osnoise_sleep(); mutex_lock(&interface_lock); cpus_read_lock(); [DEAD LOCK] Fix by swap the order of cpus_read_lock() and mutex_lock(&interface_lock). Cc: [email protected] Cc: <[email protected]> Cc: <[email protected]> Cc: <[email protected]> Cc: <[email protected]> Fixes: bce29ac ("trace: Add osnoise tracer") Link: https://patch.msgid.link/[email protected] Reviewed-by: Masami Hiramatsu (Google) <[email protected]> Signed-off-by: Luo Haiyang <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 50b35c9 commit 1f98857

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

kernel/trace/trace_osnoise.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2073,8 +2073,8 @@ static void osnoise_hotplug_workfn(struct work_struct *dummy)
20732073
if (!osnoise_has_registered_instances())
20742074
return;
20752075

2076-
guard(mutex)(&interface_lock);
20772076
guard(cpus_read_lock)();
2077+
guard(mutex)(&interface_lock);
20782078

20792079
if (!cpu_online(cpu))
20802080
return;
@@ -2237,11 +2237,11 @@ static ssize_t osnoise_options_write(struct file *filp, const char __user *ubuf,
22372237
if (running)
22382238
stop_per_cpu_kthreads();
22392239

2240-
mutex_lock(&interface_lock);
22412240
/*
22422241
* avoid CPU hotplug operations that might read options.
22432242
*/
22442243
cpus_read_lock();
2244+
mutex_lock(&interface_lock);
22452245

22462246
retval = cnt;
22472247

@@ -2257,8 +2257,8 @@ static ssize_t osnoise_options_write(struct file *filp, const char __user *ubuf,
22572257
clear_bit(option, &osnoise_options);
22582258
}
22592259

2260-
cpus_read_unlock();
22612260
mutex_unlock(&interface_lock);
2261+
cpus_read_unlock();
22622262

22632263
if (running)
22642264
start_per_cpu_kthreads();
@@ -2345,16 +2345,16 @@ osnoise_cpus_write(struct file *filp, const char __user *ubuf, size_t count,
23452345
if (running)
23462346
stop_per_cpu_kthreads();
23472347

2348-
mutex_lock(&interface_lock);
23492348
/*
23502349
* osnoise_cpumask is read by CPU hotplug operations.
23512350
*/
23522351
cpus_read_lock();
2352+
mutex_lock(&interface_lock);
23532353

23542354
cpumask_copy(&osnoise_cpumask, osnoise_cpumask_new);
23552355

2356-
cpus_read_unlock();
23572356
mutex_unlock(&interface_lock);
2357+
cpus_read_unlock();
23582358

23592359
if (running)
23602360
start_per_cpu_kthreads();

0 commit comments

Comments
 (0)