All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Kyuwon Cho" <kyuwon.cho@skku.edu>
Cc: linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH] tracing/osnoise: reject a zero sample runtime
Date: Thu, 03 Dec 2026 17:33:24 +0000	[thread overview]
Message-ID: <sashiko-outbox-248266@kernel.org> (raw)
In-Reply-To: <179620722295.2187910.14090340832228644346@skku.edu>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] tracing/osnoise: sample_runtime overflow and unguarded do_div()
  still oops
- [Medium] tracing/osnoise: early kthread_should_stop() in run_osnoise()
  emits 0 runtime
--

commit 0bc0514d9a266d7169b712fb53eb8b8e5f3c1884
Author: Kyuwon Cho <kyuwon.cho@skku.edu>

tracing/osnoise: reject a zero sample runtime

This commit sets a lower bound of one microsecond on the osnoise/runtime_us
parameter to prevent emitting zero-runtime samples that trigger a divide
error in trace_osnoise_print().

> diff --git a/kernel/trace/trace_osnoise.c b/kernel/trace/trace_osnoise.c
> index fbba422867474..f0af4133a506a 100644
> --- a/kernel/trace/trace_osnoise.c
> +++ b/kernel/trace/trace_osnoise.c
> @@ -2648,11 +2648,13 @@ static int timerlat_fd_release(struct inode *inode, struct file *file)
>  /*
>   * osnoise/runtime_us: cannot be greater than the period.
>   */
> +static u64 osnoise_min_runtime = 1;
> +
>  static struct trace_min_max_param osnoise_runtime = {
>  	.lock	= &interface_lock,
>  	.val	= &osnoise_data.sample_runtime,
>  	.max	= &osnoise_data.sample_period,
> -	.min	= NULL,
> +	.min	= &osnoise_min_runtime,
>  };

[Severity: High]
Can sample_runtime still overflow to zero in run_osnoise() because
osnoise_period has no upper bound?

osnoise_period sets .max = NULL, so userspace can write 1ULL << 61
(2305843009213693952) to osnoise/period_us and then osnoise/runtime_us.
In run_osnoise(), osnoise_data.sample_runtime * NSEC_PER_USEC wraps u64
to 0, causing the loop to exit with total < 1000 ns and emit s.runtime == 0,
which still triggers a divide-by-zero oops in trace_osnoise_print().

In addition, trace_osnoise_print() passes u64 field->runtime to do_div(),
which truncates the divisor to 32 bits, so any runtime that is a multiple of
2^32 microseconds also divides by zero and runtimes >= 2^32 us compute the
wrong percentage.

Adding an upper bound to osnoise_period and guarding field->runtime == 0
with div64_u64() in trace_osnoise_print() would cover both cases.

[Severity: Medium]
Does run_osnoise() still emit a zero-runtime sample if the kthread is
stopped before the first microsecond elapses?

Control paths like osnoise_cpus_write() call stop_per_cpu_kthreads() while
instances are still registered in osnoise_instances:

CPU0 (osnoise kthread)            CPU1 (osnoise_cpus_write)
run_osnoise()
  start = time_get()
  do { ... }
                                  stop_per_cpu_kthreads()
                                    kthread_stop()
  while (total < runtime &&
         !kthread_should_stop())  <-- exits with total < 1000 ns
  s.runtime = time_to_us(total)   <-- truncates to 0
  record_osnoise_sample(&s)

Reading that committed entry then hits the same divide-by-zero oops in
trace_osnoise_print().  Skipping samples when s.runtime == 0 (or guarding
the division in trace_osnoise_print()) would prevent this.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/179620722295.2187910.14090340832228644346@skku.edu?part=1

      reply	other threads:[~2026-12-03 17:33 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 16:44 [PATCH] tracing/osnoise: reject a zero sample runtime Kyuwon Cho
2026-12-03 17:33 ` sashiko-bot [this message]

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-248266@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kyuwon.cho@skku.edu \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.