From: sashiko-bot@kernel.org
To: "Mathieu Desnoyers" <mathieu.desnoyers@efficios.com>
Cc: linux-rt-devel@lists.linux.dev, tj@kernel.org,
hannes@cmpxchg.org, mkoutny@suse.com,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 10/17] sched/deadline: Fix an overflow of the 0-lag time with long periods
Date: Thu, 19 Nov 2026 14:07:26 +0000 [thread overview]
Message-ID: <sashiko-outbox-223251@kernel.org> (raw)
In-Reply-To: <b341033dd787d5bd4a5259cf654fb725f57629c2.1795092090.git.mathieu.desnoyers@efficios.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] sched/deadline: divide error and overflow in
task_non_contending()
--
commit 8f3d9963b4f77fcaacfd297c2fa7927bf18777cd
Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
sched/deadline: Fix an overflow of the 0-lag time with long periods
This commit replaces div64_long() in task_non_contending() with
mul_u64_u64_div_u64() so that computing the 0-lag time does not overflow
64-bit multiplication on long deadline periods.
> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
> index d6d2657dcddd6..86297ef5ac076 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c
> @@ -425,9 +425,20 @@ static void task_non_contending(struct sched_dl_entity *dl_se, bool dl_task)
>
> WARN_ON(dl_se->dl_non_contending);
>
> - zerolag_time = dl_se->deadline -
> - div64_long((dl_se->runtime * dl_se->dl_period),
> - dl_se->dl_runtime);
> + /*
> + * The 0-lag time is the deadline minus the runtime left, scaled by
> + * dl_period / dl_runtime. The product of the runtime and dl_period
> + * can overflow s64 with periods of a few seconds, so multiply on 128
> + * bits. The runtime is negative after an overrun.
> + */
> + if (dl_se->runtime >= 0)
> + zerolag_time = dl_se->deadline -
> + mul_u64_u64_div_u64(dl_se->runtime, dl_se->dl_period,
> + dl_se->dl_runtime);
> + else
> + zerolag_time = dl_se->deadline +
> + mul_u64_u64_div_u64(-dl_se->runtime, dl_se->dl_period,
> + dl_se->dl_runtime);
[Severity: Medium]
Can mul_u64_u64_div_u64() trap with a divide error (#DE) on x86-64 or
overflow s64 zerolag_time when |dl_se->runtime| exceeds dl_se->dl_runtime?
On x86-64, mul_u64_u64_div_u64() uses an unguarded divq instruction that
traps with #DE whenever the quotient does not fit in u64, and even when it
fits in u64, a quotient above S64_MAX wraps s64 zerolag_time into the wrong
sign.
|dl_se->runtime| is not bounded by dl_se->dl_runtime when root raises
sysctl_sched_dl_period_max: for example, if an active task with a 140s
runtime and period calls sched_setattr() to lower sched_runtime to 1024 ns
while dl_se->deadline is still in the future, __setparam_dl() updates
dl_se->dl_runtime to 1024 without clamping dl_se->runtime, and
enqueue_dl_entity() skips setup_new_dl_entity():
kernel/sched/deadline.c:enqueue_dl_entity() {
...
} else if ((flags & ENQUEUE_MOVE) &&
!is_dl_boosted(dl_se) &&
dl_time_before(dl_se->deadline, rq_clock(rq_of_dl_se(dl_se)))) {
setup_new_dl_entity(dl_se);
}
...
}
When the task then blocks or leaves SCHED_DEADLINE, task_non_contending()
divides 140e9 * 140e9 by 1024 (> U64_MAX) and panics in divq with rq->__lock
held (or in the else branch when a task with dl_runtime = 1024 ns and a
large dl_period overruns by a scheduler tick before blocking).
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1795092090.git.mathieu.desnoyers@efficios.com?part=10
next prev parent reply other threads:[~2026-11-19 14:07 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 13:49 [PATCH v3 00/17] sched/deadline: first bandwidth accounting fixes and selftests Mathieu Desnoyers
2026-11-19 13:49 ` [PATCH v3 01/17] sched: Refuse SCHED_FLAG_KEEP_PARAMS that would change the policy or the class Mathieu Desnoyers
2026-11-19 13:49 ` [PATCH v3 02/17] sched/deadline: Do not admit bandwidth for parameters that are kept Mathieu Desnoyers
2026-11-19 13:49 ` [PATCH v3 03/17] sched: Let a task boosted by a deadline waiter change its policy Mathieu Desnoyers
2026-11-19 13:49 ` [PATCH v3 04/17] sched/deadline: Do not divide by zero active CPUs of a root domain Mathieu Desnoyers
2026-11-19 14:08 ` sashiko-bot
2026-11-19 13:49 ` [PATCH v3 05/17] sched/deadline: Refuse dl_server debugfs writes while the rq is offline Mathieu Desnoyers
2026-11-19 13:49 ` [PATCH v3 06/17] sched: Take cpuset_mutex for a deadline policy change only with pi Mathieu Desnoyers
2026-11-19 13:49 ` [PATCH v3 07/17] sched/deadline: Do not lose a throttled task switched out and back Mathieu Desnoyers
2026-11-19 13:49 ` [PATCH v3 08/17] sched/deadline: Do not replenish a boost from cleared parameters Mathieu Desnoyers
2026-11-19 13:49 ` [PATCH v3 09/17] sched/deadline: Reset the deadline and the runtime with the parameters Mathieu Desnoyers
2026-11-19 14:17 ` sashiko-bot
2026-11-19 13:49 ` [PATCH v3 10/17] sched/deadline: Fix an overflow of the 0-lag time with long periods Mathieu Desnoyers
2026-11-19 14:07 ` sashiko-bot [this message]
2026-11-19 13:49 ` [PATCH v3 11/17] sched/deadline: Release the bandwidth of a task that leaves the class asleep Mathieu Desnoyers
2026-11-19 13:49 ` [PATCH v3 12/17] sched/deadline: Reject SCHED_DEADLINE on exited tasks Mathieu Desnoyers
2026-11-19 13:49 ` [PATCH v3 13/17] sched/deadline: Fix this_bw when a task is changed during a remote wakeup Mathieu Desnoyers
2026-11-19 13:49 ` [PATCH v3 14/17] sched/deadline: Check SCHED_DEADLINE affinity under the rq lock Mathieu Desnoyers
2026-11-19 13:49 ` [PATCH v3 15/17] sched/debug: Show the deadline bandwidth of each runqueue Mathieu Desnoyers
2026-11-19 13:49 ` [PATCH v3 16/17] selftests/sched: Add a test of SCHED_DEADLINE policy round trips Mathieu Desnoyers
2026-11-19 13:49 ` [PATCH v3 17/17] selftests/sched: Add a test of SCHED_DEADLINE bandwidth accounting Mathieu Desnoyers
2026-11-19 14:22 ` sashiko-bot
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-223251@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-devel@lists.linux.dev \
--cc=mathieu.desnoyers@efficios.com \
--cc=mkoutny@suse.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tj@kernel.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