From: Steven Rostedt <rostedt@goodmis.org>
To: Joseph Salisbury <joseph.salisbury@oracle.com>
Cc: Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
Valentin Schneider <vschneid@redhat.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] sched/core: initialize resched_latency in sched_tick()
Date: Tue, 17 Mar 2026 17:09:43 -0400 [thread overview]
Message-ID: <20260317170943.44c41263@gandalf.local.home> (raw)
In-Reply-To: <20260317195807.98850-1-joseph.salisbury@oracle.com>
On Tue, 17 Mar 2026 15:58:07 -0400
Joseph Salisbury <joseph.salisbury@oracle.com> wrote:
> sched_tick() only assigns resched_latency when the LATENCY_WARN feature is
> enabled, but tests the variable later in a separate feature check.
>
> That leaves the code dependent on both checks observing identical state.
> Initializing resched_latency to zero makes the later test safe even if the
> feature state changes between the two checks.
>
> This does not change behavior when LATENCY_WARN is enabled. It only avoids
> using an uninitialized local value.
>
> Fixes: c006fac556e4 ("sched: Warn on long periods of pending need_resched")
> Cc: stable@vger.kernel.org
> Assisted-by: Codex:GPT-5
> Signed-off-by: Joseph Salisbury <joseph.salisbury@oracle.com>
> ---
> kernel/sched/core.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 08a06162dd9a..15916186e4ff 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -5548,7 +5548,7 @@ void sched_tick(void)
> struct task_struct *donor;
> struct rq_flags rf;
> unsigned long hw_pressure;
> - u64 resched_latency;
> + u64 resched_latency = 0;
>
> if (housekeeping_cpu(cpu, HK_TYPE_KERNEL_NOISE))
> arch_scale_freq_tick();
The code has:
if (sched_feat(LATENCY_WARN))
resched_latency = cpu_resched_latency(rq);
calc_global_load_tick(rq);
sched_core_tick(rq);
scx_tick(rq);
rq_unlock(rq, &rf);
if (sched_feat(LATENCY_WARN) && resched_latency)
resched_latency_warn(cpu, resched_latency);
I guess if LATENCY_WARN gets enabled between the first check and the
second, then the resched_latency could be uninitialized.
Heck, probably could even get rid of the second sched_feat(LATENCY_WARN),
and make it simply:
if (resched_latency)
Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>
-- Steve
next prev parent reply other threads:[~2026-03-17 21:09 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-17 19:58 Joseph Salisbury
2026-03-17 21:09 ` Steven Rostedt [this message]
2026-03-18 6:30 ` Shrikanth Hegde
2026-03-18 14:48 ` Steven Rostedt
2026-03-18 14:53 ` Peter Zijlstra
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=20260317170943.44c41263@gandalf.local.home \
--to=rostedt@goodmis.org \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=joseph.salisbury@oracle.com \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@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
all inboxes | Powered by JetHome®