mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Avi Weiss <thnkslprpt@gmail.com>
To: mingo@redhat.com, peterz@infradead.org
Cc: juri.lelli@redhat.com, vincent.guittot@linaro.org,
	dietmar.eggemann@arm.com, tommaso.cucinotta@gmail.com,
	linux-kernel@vger.kernel.org, linux-api@vger.kernel.org,
	Avi Weiss <thnkslprpt@gmail.com>
Subject: [PATCH] sched/deadline: Clamp negative runtime in sched_getattr
Date: Tue,  3 Nov 2026 19:10:14 +0200	[thread overview]
Message-ID: <20261103171013.2511027-2-thnkslprpt@gmail.com> (raw)

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.

Fixes: 2e7af192697e ("sched/deadline: Add reporting of runtime left & abs deadline to sched_getattr() for DEADLINE tasks")
Signed-off-by: Avi Weiss <thnkslprpt@gmail.com>
---
 kernel/sched/deadline.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index c0ebdcde5fe5..7b098da8076c 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -3870,7 +3870,7 @@ void __getparam_dl(struct task_struct *p, struct sched_attr *attr, unsigned int
 		if (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
-- 
2.43.0


                 reply	other threads:[~2026-11-03 17:10 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261103171013.2511027-2-thnkslprpt@gmail.com \
    --to=thnkslprpt@gmail.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=juri.lelli@redhat.com \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=tommaso.cucinotta@gmail.com \
    --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®