sched/deadline: Clamp negative runtime in sched_getattr
PATCH 1/1 sched/deadline: Clamp negative runtime in sched_getattr
A SCHED_DEADLINE task can overrun its execution budget, leaving dl_se->runtime negative until replenishment. Dynamic sched_getattr() copies this signed value into the unsigned sched_attr.sched_runtime, causing userspace to see a value near U64_MAX instead of zero remaining budget.
Clamp negative runtime to zero when reporting the dynamic value. Keep the signed deadline accounting unchanged.
Reproduced the overflow on an unpatched 7.4-rc1 kernel in a QEMU guest. Verified that the patched kernel reports zero for negative runtime, while positive runtime, static parameters, replenishment, and non-deadline queries behave as expected.
A five-run VM benchmark of the unchanged static sched_getattr() path showed no apparent regression (median 110.62 ns before, 102.10 ns after). Negligible improvement maybe just due to noise.
--- kernel/sched/deadline.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/deadline.c +1 -1
@@ -3870,7 +3870,7 @@ void __getparam_dl(struct task_struct *p, struct sched_attr *attr, unsigned intif (task_current (rq, p))update_curr_dl (rq); - attr->sched_runtime = dl_se->runtime; + attr->sched_runtime =max_t (s64, dl_se->runtime,0 ); adj_deadline = dl_se->deadline -rq_clock (rq) +ktime_get_ns (); attr->sched_deadline = adj_deadline; }else {
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
Signature · 1 line
2.43.0