Skip to contentSkip to conversation

trace/osnoise: prevent osnoise hotplog worker running in UNBOUND workqueue

PATCH In review Andy Chiu 2 participants 2 messages Feb 1, 2024

Subsystems (2)
lore
Share & tools
lore

Andy Chiu

author
#0 lore raw

PATCH 1/1 trace/osnoise: prevent osnoise hotplog worker running in UNBOUND workqueue

smp_processor_id() should be called with migration disabled. This mean we may safely call smp_processor_id() in percpu thread. However, this is not the case if the work is (re-)queued into unbound workqueue, during cpu-hotplog. So, detect and return early if this work happens to run on an unbound wq.

---
 kernel/trace/trace_osnoise.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
kernel/trace/trace_osnoise.c +6 -1
index bd0d01d00fb9..cf7f716d3f35 100644
@@ -2068,7 +2068,12 @@ static int start_per_cpu_kthreads(void)
 #ifdef CONFIG_HOTPLUG_CPU
 static void osnoise_hotplug_workfn(struct work_struct *dummy)
 {
-	unsigned int cpu = smp_processor_id();
+	unsigned int cpu;
+
+	if (!is_percpu_thread())
+		return;
+
+	cpu = smp_processor_id();
 
 	mutex_lock(&trace_types_lock);
 
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 6 lines · On Thu, 1 Feb 2024 14:18:45 +0800 Andy Chiu <[email protected]> wrote:

smp_processor_id() should be called with migration disabled. This mean we may safely call smp_processor_id() in percpu thread. However, this is not the case if the work is (re-)queued into unbound workqueue, during cpu-hotplog. So, detect and return early if this work happens to run on an unbound wq.

Yeah I triggered this too, but never made it a priority to fix.

Quoted 10 lines
---
 kernel/trace/trace_osnoise.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
kernel/trace/trace_osnoise.c +0 -0
index bd0d01d00fb9..cf7f716d3f35 100644

kernel/trace/trace_osnoise.c static int start_per_cpu_kthreads(void) · line 2074

Quoted 8 lines
kernel/trace/trace_osnoise.c +4 -1
@@ -2068,7 +2068,12 @@ static int start_per_cpu_kthreads(void)
 #ifdef CONFIG_HOTPLUG_CPU
 static void osnoise_hotplug_workfn(struct work_struct *dummy)
 {
-	unsigned int cpu = smp_processor_id();
+	unsigned int cpu;
+
+	if (!is_percpu_thread())
+		return;

But doesn't this then fail to register the CPU thread?

I wonder if this has some race with schedule_work_on() and hotplug?

-- Steve

Quoted 5 lines
kernel/trace/trace_osnoise.c +2 -0
+
+	cpu = smp_processor_id();
 
 	mutex_lock(&trace_types_lock);