* [PATCH] tracing/osnoise: reject a zero sample runtime
@ 2026-12-03 16:44 Kyuwon Cho
2026-12-03 17:33 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Kyuwon Cho @ 2026-12-03 16:44 UTC (permalink / raw)
To: Steven Rostedt
Cc: Masami Hiramatsu, Mathieu Desnoyers, Daniel Bristot de Oliveira,
linux-kernel, linux-trace-kernel
The osnoise runtime parameter accepts zero, allowing the tracer to emit a
sample whose runtime is zero. Reading that sample from trace divides the
available CPU time by the zero runtime in trace_osnoise_print().
Set the runtime parameter minimum to one microsecond so every emitted
sample has a valid denominator.
Fixes: bce29ac9ce0b ("trace: Add osnoise tracer")
Signed-off-by: Kyuwon Cho <kyuwon.cho@skku.edu>
---
The issue was found by an LLM-guided test generator that we are
developing as a research prototype.
The reproducer mounts tracefs, writes zero to osnoise/runtime_us, enables
the osnoise tracer, and reads its trace. Access to tracefs requires root
in the initial namespace.
The decoded trace is:
Oops: divide error: 0000 [#1] SMP KASAN NOPTI
RIP: 0010:trace_osnoise_print (kernel/trace/trace_output.c:1601)
Call Trace:
print_trace_line (kernel/trace/trace.c:3090 kernel/trace/trace.c:3256)
seq_read_iter (fs/seq_file.c:273)
seq_read (fs/seq_file.c:163)
vfs_read (fs/read_write.c:552)
The patch was tested on v7.4-rc5 and rebased onto tracing commit
175e5f3eddc6 ("tracing: Use test_bit() in event_enable_count_probe()").
kernel/trace/trace_osnoise.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/kernel/trace/trace_osnoise.c b/kernel/trace/trace_osnoise.c
index fbba42286747..f0af4133a506 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,
};
/*
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] tracing/osnoise: reject a zero sample runtime
2026-12-03 16:44 [PATCH] tracing/osnoise: reject a zero sample runtime Kyuwon Cho
@ 2026-12-03 17:33 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-03 17:33 UTC (permalink / raw)
To: Kyuwon Cho; +Cc: linux-trace-kernel
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-03 17:33 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 16:44 [PATCH] tracing/osnoise: reject a zero sample runtime Kyuwon Cho
2026-12-03 17:33 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox