Linux Trace Kernel
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Crystal Wood" <crwood@redhat.com>
Cc: linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH v2 3/9] tracing/osnoise: Per-cpu mutexes and fd detachment
Date: Sat, 10 Oct 2026 02:35:20 +0000	[thread overview]
Message-ID: <sashiko-outbox-166222@kernel.org> (raw)
In-Reply-To: <20261010022338.2507589-4-crwood@redhat.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] tracing/osnoise: sampling state is never cleared when no-workload tracer stops
--

commit f0d962e5159ec760bce6edd22ecbeb40abce0874
Author: Crystal Wood <crwood@redhat.com>

tracing/osnoise: Per-cpu mutexes and fd detachment

This commit cleans up synchronization issues by introducing per-cpu mutexes
for guarding kthread changes and fd open/close/revoke operations. It also
replaces a SIGKILL hack for userspace timerlat threads with a
mutex-protected detachment mechanism.

> diff --git a/kernel/trace/trace_osnoise.c b/kernel/trace/trace_osnoise.c
> --- a/kernel/trace/trace_osnoise.c
> +++ b/kernel/trace/trace_osnoise.c

[ ... ]

> @@ -1976,32 +2008,23 @@ static int timerlat_main(void *data)
>   */
>  static void stop_kthread(unsigned int cpu)
>  {
> -	struct task_struct *kthread;
> +	struct osnoise_variables *osn_var = cpu_osn_var(cpu);
>  
> -	kthread = xchg_relaxed(&cpu_osn_var(cpu)->kthread, NULL);
> -	if (kthread) {
> -		if (cpumask_test_and_clear_cpu(cpu, &kthread_cpumask) &&
> -		    !WARN_ON(!test_bit(OSN_WORKLOAD, &osnoise_options))) {
> -			kthread_stop(kthread);
> -		} else if (!WARN_ON(test_bit(OSN_WORKLOAD, &osnoise_options))) {
> -			/*
> -			 * This is a user thread waiting on the timerlat_fd. We need
> -			 * to close all users, and the best way to guarantee this is
> -			 * by killing the thread. NOTE: this is a purpose specific file.
> -			 */
> -			kill_pid(kthread->thread_pid, SIGKILL, 1);
> -		}
> -		put_task_struct(kthread);
> -	} else {
> -		/* if no workload, just return */
> -		if (!test_bit(OSN_WORKLOAD, &osnoise_options)) {
> -			/*
> -			 * This is set in the osnoise tracer case.
> -			 */
> -			cpu_osn_var(cpu)->sampling = false;
> -			barrier();
> -		}
> +	mutex_lock(&osn_var->lock);
> +
> +	if (osn_var->fdd) {
> +		WARN_ON(test_bit(OSN_WORKLOAD, &osnoise_options));
> +		WARN_ON(osn_var->kthread);
> +		osn_var->fdd->detach(osn_var->fdd);
> +	} else if (osn_var->kthread) {
> +		WARN_ON(!cpumask_test_and_clear_cpu(cpu, &kthread_cpumask));
> +		WARN_ON(!test_bit(OSN_WORKLOAD, &osnoise_options));
> +		kthread_stop(osn_var->kthread);
> +		put_task_struct(osn_var->kthread);
> +		osn_var->kthread = NULL;
>  	}
> +
> +	mutex_unlock(&osn_var->lock);
>  }

[Severity: Medium]
Does this removal leave the sampling state permanently enabled when the
tracer is stopped in the no-workload configuration?

When the osnoise tracer starts without a workload (!OSN_WORKLOAD),
start_kthread() sets osn_var->sampling = true but exits without spawning
a kthread. Because both osn_var->kthread and osn_var->fdd remain NULL in
this mode, this new logic in stop_kthread() appears to do nothing.

The previous code had an else block that explicitly reset the sampling
flag:

    } else {
        /* if no workload, just return */
        if (!test_bit(OSN_WORKLOAD, &osnoise_options)) {
            /*
             * This is set in the osnoise tracer case.
             */
            cpu_osn_var(cpu)->sampling = false;
            barrier();
        }
    }

Without this fallback, the sampling flag remains permanently true. This
could cause tracepoint callbacks (like NMI, IRQ, and softirq) to continue
incurring execution overhead and recording events into the ring buffer
even after the tracer is stopped, eventually triggering warnings in
osn_var_reset() upon subsequent starts.

Could we restore the cleanup of the sampling flag for the no-workload
case?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261010022338.2507589-1-crwood@redhat.com?part=3

  reply	other threads:[~2026-10-10  2:35 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 ` [PATCH v2 2/9] tracing/osnoise: Hold a ref on osn->kthread Crystal Wood
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 [this message]
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=sashiko-outbox-166222@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=crwood@redhat.com \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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