Re: [PATCH v3 10/17] sched/deadline: Fix an overflow of the 0-lag time with long periods

From: Mathieu Desnoyers

Date: Thu Nov 19 2026 - 11:07:20 EST


> 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?

Yes, and this patch brings it in. The old div64_long() wrapped there
instead of trapping. I reproduced it in an x86-64 guest. With the
period limit at 300s, a task of 150s every 300s shrank its runtime to
1024ns while asleep. Switching it to SCHED_OTHER then oopsed with a
divide error in task_non_contending().

In v4, task_non_contending() will first compare the runtime left with
what the parameters give until the deadline:

(deadline - now) * dl_runtime / dl_period

This quotient fits in 64 bits: dl_runtime is at most dl_period, so it
is at most deadline - now. If the runtime left is larger, the 0-lag
time has passed, and the bandwidth is released without the division.
Otherwise, the quotient of the 0-lag time is at most deadline - now
too. A negative runtime is an overrun, which the next tick stops, so
its quotient fits. Two new cases of v4 will test this:
params_switched_asleep and params_shrunk_long_period.

Thanks,

Mathieu

--
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com