From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796328753; b=fIBf3OWIlWz+vRJTf6/bpt89Fde/fXSx6gCR2mmqCgVNcTqZ1yKG7RX8lhEfGaP6RFdn OjLihAKuo3sBZDZ2ip9JrgZbqJlkMtxgEohTlCt8iDT1M04hTUIqWPed5odOYGGQG9GV+ l064W8HDV2JOgduWA/QUlXH6PUFKzkwM9pdyMFo7/bAQctPuZuVCzYRVkfkgOixSnvcUy jhM2J8bNQeN4umOB6TF607UBl2U+qwoXN2zusb2+TafhzfkAmzR85WaVbSaQlrsA/AAXy RBzBO+LgrXSqERdm1qHJizjdMxLRzEJQhwUEJZRl1ExJBucOKZv0gZkGvRqqgS4URsw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796328753; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=BbdI4iH7Pn+2DhN28/cV6fqzOncTZOjlGiq25UdjlkU=; b=5RfuvxLs3Ge7lZ7jzWoAIUB1c8oHQpMAg9g6WRTYSlH4DZTnjmT8QqtEuhet3VSBUxZT ydaTZPNWl6rJoUwwYRGeyYCusksVkKFu10fVCx8q8pLLcWVf31RZdqxk2KK3wKP8m5bJH +caj2Y5ymKb2shj5AIgc9iHc/KuT3HUz9hdaZBfFhEgkdKdPNDgFdNGcZwpR+cFcSvdKK F2BHtjgLGEULhZP9PNsC0G9r9Jn+ZGfZ+zNEioV+H82EdaWwqvNVwKLV5vYqRBfhFj4pw 8ln0RI5qqVE1xHwiqebMPrtNlEDxo/ZW3Hfy2ZRTDiA6Qcf6NcIZsOdFK3sntGHxofQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=JXYkPSOj; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B31FC606A322 for ; Thu, 3 Dec 2026 20:12:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=JXYkPSOj Received: by smtp.kernel.org (Postfix) with ESMTPSA id 401971F000CE; Thu, 3 Dec 2026 20:12:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796328753; bh=BbdI4iH7Pn+2DhN28/cV6fqzOncTZOjlGiq25UdjlkU=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=JXYkPSOjOYpoHklh+Cx6+zxsb9s71182Q/RiwxF1VAQ7Ojj4EWiGojXRpG4k4Hahx BxQPoAoO6UB0PtiMdwcDrKKS4bNpnXqeyIZcLQNXg8G1u2wt7YLQlewaSxlQPmS5gO L7ymo+utNmDorkVxvLquXybn5dKupy5rJJx96xRUjHdWPxj+hORljpvisTH3py9zmv Otv1yyxI5c96SfdBT6RyK4pG1a2H6cL3g7FFcnM9iBCO79LZx7OEmPH1DGxJzehuO0 T7OLXD+BPGS+mKd0SVl7cPZqwUu3jGMexot+oSdk1YE9s4SsRbo2EOkYxb/gdrVLBq f5+fPdLYxBwFA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2] tracing/osnoise: validate and safely print sample runtime Reply-To: sashiko-reviews@lists.linux.dev To: "Kyuwon Cho" Cc: linux-trace-kernel@vger.kernel.org In-Reply-To: <179632406628.3855633.16468487680690267787@skku.edu> References: <179632406628.3855633.16468487680690267787@skku.edu> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 20:12:32 +0000 X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] tracing/osnoise: osnoise_max_period still overflows ktime_t in osnoise_sleep() - [Medium] tracing/osnoise: unchecked underflow in trace_osnoise_print() can cause #DE -- commit 18cb5b7e9e9bcf7ac48000897ed2f20aad86f24c Author: Kyuwon Cho tracing/osnoise: validate and safely print sample runtime This commit adds minimum and maximum bounds for the osnoise runtime and period parameters, drops zero-duration samples in run_osnoise(), and replaces the availability ratio division in trace_osnoise_print() with mul_u64_u64_div_u64(). > diff --git a/kernel/trace/trace_osnoise.c b/kernel/trace/trace_osnoise.c > index fbba422867474..7f8cbca7b9a7c 100644 > --- a/kernel/trace/trace_osnoise.c > +++ b/kernel/trace/trace_osnoise.c [ ... ] > @@ -2648,11 +2651,14 @@ static int timerlat_fd_release(struct inode *inod= e, struct file *file) > /* > * osnoise/runtime_us: cannot be greater than the period. > */ > +static u64 osnoise_min_runtime =3D 1; > +static u64 osnoise_max_period =3D S64_MAX / NSEC_PER_USEC; > + > static struct trace_min_max_param osnoise_runtime =3D { > .lock =3D &interface_lock, > .val =3D &osnoise_data.sample_runtime, > .max =3D &osnoise_data.sample_period, > - .min =3D NULL, > + .min =3D &osnoise_min_runtime, > }; > =20 > /* > @@ -2661,7 +2667,7 @@ static struct trace_min_max_param osnoise_runtime = =3D { > static struct trace_min_max_param osnoise_period =3D { > .lock =3D &interface_lock, > .val =3D &osnoise_data.sample_period, > - .max =3D NULL, > + .max =3D &osnoise_max_period, > .min =3D &osnoise_data.sample_runtime, > }; [Severity: Medium] Can osnoise_max_period still overflow ktime_t in osnoise_sleep()? S64_MAX / NSEC_PER_USEC converts to S64_MAX - 807 ns. In osnoise_sleep(), ktime_add_us(ktime_get(), interval) performs an unsaturating signed additio= n, so any period near osnoise_max_period wraps wake_time to a negative ktime_t. schedule_hrtimeout(&wake_time, HRTIMER_MODE_ABS) treats a negative deadline as already expired and returns immediately without sleeping. When tracing is off, osnoise_main() loops on osnoise_sleep(true) with no cond_resched(), spinning the per-CPU osnoise kthreads and contending on interface_lock. Using ktime_add_safe() in osnoise_sleep(), or passing a relative timeout wi= th HRTIMER_MODE_REL, would prevent the wrap. > diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c > index 0850b3ad57075..adf03e8222a1b 100644 > --- a/kernel/trace/trace_output.c > +++ b/kernel/trace/trace_output.c [ ... ] > @@ -1642,10 +1643,14 @@ trace_osnoise_print(struct trace_iterator *iter, = int flags, > /* > * compute the available % of cpu time. > */ > - net_runtime =3D field->runtime - field->noise; > - ratio =3D net_runtime * 10000000; > - do_div(ratio, field->runtime); > - ratio_dec =3D do_div(ratio, 100000); > + ratio =3D 0; > + ratio_dec =3D 0; > + if (field->runtime) { > + net_runtime =3D field->runtime - field->noise; > + ratio =3D mul_u64_u64_div_u64(net_runtime, 10000000, > + field->runtime); > + ratio_dec =3D do_div(ratio, 100000); > + } [Severity: Medium] Can an underflow in net_runtime trigger a #DE trap in mul_u64_u64_div_u64()? On x86_64, mul_u64_add_u64_div_u64() uses raw mulq and divq with no excepti= on table entry. If field->noise > field->runtime, net_runtime underflows near U64_MAX and raises an unhandled #DE for any runtime up to 9999999 us (including the default 1000000 us). run_osnoise() reads start and last_sample in separate time_get() calls without checking last_sample >=3D start. If sched_clock() steps backwards between them (for example in tsc_refine_calibration_work() -> set_cyc2ns_scale()), noise exceeds total and records noise > runtime > 0. Guarding the calculation with if (field->runtime > field->noise) avoids both divide-by-zero and the #DE trap. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/179632406628.385563= 3.16468487680690267787@skku.edu?part=3D1