From: Crystal Wood <crwood@redhat.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Tomas Glozar <tglozar@redhat.com>, John Kacur <jkacur@redhat.com>,
linux-trace-kernel@vger.kernel.org,
Crystal Wood <crwood@redhat.com>
Subject: [PATCH v2 2/9] tracing/osnoise: Hold a ref on osn->kthread
Date: Fri, 9 Oct 2026 21:23:31 -0500 [thread overview]
Message-ID: <20261010022338.2507589-3-crwood@redhat.com> (raw)
In-Reply-To: <20261010022338.2507589-1-crwood@redhat.com>
Deal with early kthread termination by holding a reference to the
task_struct and always running the cleanup code in stop_kthread(), rather
than with hacks like osnoise_migration_pending().
This avoids a potential deadlock when a later patch switches from xchg
to using a lock to protect osn->kthread updates, and also deals with
any other situations where a kthread might exit early.
Signed-off-by: Crystal Wood <crwood@redhat.com>
---
v2: New patch. I did this in response to Sashiko pointing out a deadlock
in v1 with the use of osn->lock in osnoise_migration_pending. That might
no longer be an issue now that detach_lock is split out, but this is still
the cleaner and more robust approach.
---
kernel/trace/trace_osnoise.c | 17 ++++-------------
1 file changed, 4 insertions(+), 13 deletions(-)
diff --git a/kernel/trace/trace_osnoise.c b/kernel/trace/trace_osnoise.c
index 953936bd5eec..47ede1696c91 100644
--- a/kernel/trace/trace_osnoise.c
+++ b/kernel/trace/trace_osnoise.c
@@ -1691,17 +1691,6 @@ static inline int osnoise_migration_pending(void)
* thus: taint and leave to unblock the blocked thread.
*/
osnoise_taint("migration requested to osnoise threads, leaving.");
-
- /*
- * Unset this thread from the threads managed by the interface.
- * The tracers are responsible for cleaning their env before
- * exiting.
- */
- mutex_lock(&interface_lock);
- this_cpu_osn_var()->kthread = NULL;
- cpumask_clear_cpu(smp_processor_id(), &kthread_cpumask);
- mutex_unlock(&interface_lock);
-
return 1;
}
@@ -2001,8 +1990,8 @@ static void stop_kthread(unsigned int cpu)
* by killing the thread. NOTE: this is a purpose specific file.
*/
kill_pid(kthread->thread_pid, SIGKILL, 1);
- put_task_struct(kthread);
}
+ put_task_struct(kthread);
} else {
/* if no workload, just return */
if (!test_bit(OSN_WORKLOAD, &osnoise_options)) {
@@ -2059,15 +2048,17 @@ static int start_kthread(unsigned int cpu)
snprintf(comm, 24, "osnoise/%d", cpu);
}
- kthread = kthread_run_on_cpu(main, NULL, cpu, comm);
+ kthread = kthread_create_on_cpu(main, NULL, cpu, comm);
if (IS_ERR(kthread)) {
pr_err(BANNER "could not start sampling thread\n");
return -ENOMEM;
}
+ get_task_struct(kthread);
cpu_osn_var(cpu)->kthread = kthread;
cpumask_set_cpu(cpu, &kthread_cpumask);
+ wake_up_process(kthread);
return 0;
}
--
2.54.0
next prev parent reply other threads:[~2026-10-10 2:24 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-10 2:23 [PATCH v2 0/9] tracing/osnoise: Synchronization fixes Crystal Wood
2026-10-10 2:23 ` [PATCH v2 1/9] tracing/osnoise: Variable cleanup Crystal Wood
2026-10-10 2:23 ` Crystal Wood [this message]
2026-10-10 2:23 ` [PATCH v2 3/9] tracing/osnoise: Per-cpu mutexes and fd detachment Crystal Wood
2026-10-10 2:35 ` sashiko-bot
2026-10-10 2:23 ` [PATCH v2 4/9] tracing/osnoise: kthreads: Verify CPU after migrate_disable() Crystal Wood
2026-10-10 2:23 ` [PATCH v2 5/9] tracing/osnoise: start_kthread: Always check OSN_WORKLOAD Crystal Wood
2026-10-10 2:34 ` sashiko-bot
2026-10-10 2:23 ` [PATCH v2 6/9] tracing/osnoise: Take trace_types_lock in timerlat_fd_open Crystal Wood
2026-10-10 2:23 ` [PATCH v2 7/9] tracing/osnoise: Split out per-cpu variable resets Crystal Wood
2026-10-10 2:36 ` sashiko-bot
2026-10-10 2:23 ` [PATCH v2 8/9] tracing/osnoise: Print taint message for timerlat Crystal Wood
2026-10-10 2:23 ` [PATCH v2 9/9] tracing/osnoise: Refuse timerlat fd open if tracer inactive Crystal Wood
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261010022338.2507589-3-crwood@redhat.com \
--to=crwood@redhat.com \
--cc=jkacur@redhat.com \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=tglozar@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox