From: Peter Zijlstra <peterz@infradead.org>
To: Omar Sandoval <osandov@osandov.com>
Cc: Ingo Molnar <mingo@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Steven Rostedt <rostedt@goodmis.org>,
linux-kernel@vger.kernel.org, Rik van Riel <riel@surriel.com>,
Chris Mason <clm@meta.com>,
kernel-team@fb.com, Pat Cody <pat@patcody.io>,
Breno Leitao <leitao@debian.org>
Subject: Re: [PATCH] sched/eevdf: Fix se->slice being set to U64_MAX and resulting crash
Date: Fri, 25 Apr 2025 12:32:49 +0200 [thread overview]
Message-ID: <20250425103249.GO18306@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <f0c2d1072be229e1bdddc73c0703919a8b00c652.1745570998.git.osandov@fb.com>
On Fri, Apr 25, 2025 at 01:51:24AM -0700, Omar Sandoval wrote:
> From: Omar Sandoval <osandov@fb.com>
>
> There is a code path in dequeue_entities() that can set the slice of a
> sched_entity to U64_MAX, which sometimes results in a crash.
>
> The offending case is when dequeue_entities() is called to dequeue a
> delayed group entity, and then the entity's parent's dequeue is delayed.
> In that case:
>
> 1. In the if (entity_is_task(se)) else block at the beginning of
> dequeue_entities(), slice is set to
> cfs_rq_min_slice(group_cfs_rq(se)). If the entity was delayed, then
> it has no queued tasks, so cfs_rq_min_slice() returns U64_MAX.
Whoopsy..
> 2. The first for_each_sched_entity() loop dequeues the entity.
> 3. If the entity was its parent's only child, then the next iteration
> tries to dequeue the parent.
> 4. If the parent's dequeue needs to be delayed, then it breaks from the
> first for_each_sched_entity() loop _without updating slice_.
> 5. The second for_each_sched_entity() loop sets the parent's ->slice to
> the saved slice, which is still U64_MAX.
>
> This throws off subsequent calculations with potentially catastrophic
> results. A manifestation we saw in production was:
>
> 6. In update_entity_lag(), se->slice is used to calculate limit, which
> ends up as a huge negative number.
> 7. limit is used in se->vlag = clamp(vlag, -limit, limit). Because limit
> is negative, vlag > limit, so se->vlag is set to the same huge
> negative number.
> 8. In place_entity(), se->vlag is scaled, which overflows and results in
> another huge (positive or negative) number.
> 9. The adjusted lag is subtracted from se->vruntime, which increases or
> decreases se->vruntime by a huge number.
> 10. pick_eevdf() calls entity_eligible()/vruntime_eligible(), which
> incorrectly returns false because the vruntime is so far from the
> other vruntimes on the queue, causing the
> (vruntime - cfs_rq->min_vruntime) * load calulation to overflow.
> 11. Nothing appears to be eligible, so pick_eevdf() returns NULL.
> 12. pick_next_entity() tries to dereference the return value of
> pick_eevdf() and crashes.
Impressive fail chain that.
> Dumping the cfs_rq states from the core dumps with drgn showed tell-tale
> huge vruntime ranges and bogus vlag values, and I also traced se->slice
> being set to U64_MAX on live systems (which was usually "benign" since
> the rest of the runqueue needed to be in a particular state to crash).
>
> Fix it in dequeue_entities() by always setting slice from the first
> non-empty cfs_rq.
>
> Fixes: aef6987d8954 ("sched/eevdf: Propagate min_slice up the cgroup hierarchy")
> Signed-off-by: Omar Sandoval <osandov@fb.com>
Thanks!
next prev parent reply other threads:[~2025-04-25 10:33 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-25 8:51 Omar Sandoval
2025-04-25 10:32 ` Peter Zijlstra [this message]
2025-04-25 10:50 ` [tip: sched/urgent] " tip-bot2 for Omar Sandoval
2025-04-26 8:56 ` tip-bot2 for Omar Sandoval
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=20250425103249.GO18306@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=clm@meta.com \
--cc=dietmar.eggemann@arm.com \
--cc=kernel-team@fb.com \
--cc=leitao@debian.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=osandov@osandov.com \
--cc=pat@patcody.io \
--cc=riel@surriel.com \
--cc=rostedt@goodmis.org \
--cc=vincent.guittot@linaro.org \
/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®