[tip: sched/core] sched: restore timer_slack_ns when resetting RT policy on fork

tip-bot2 for Guanyou.Chen posted 1 patch 3 days, 11 hours ago
kernel/sched/core.c | 1 +
1 file changed, 1 insertion(+)
[tip: sched/core] sched: restore timer_slack_ns when resetting RT policy on fork
Posted by tip-bot2 for Guanyou.Chen 3 days, 11 hours ago
The following commit has been merged into the sched/core branch of tip:

Commit-ID:     63c1a12bc0e09af7dee919c4fb4a300a719d5125
Gitweb:        https://git.kernel.org/tip/63c1a12bc0e09af7dee919c4fb4a300a719d5125
Author:        Guanyou.Chen <chenguanyou9338@gmail.com>
AuthorDate:    Fri, 22 May 2026 21:09:59 +08:00
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Tue, 02 Jun 2026 12:26:10 +02:00

sched: restore timer_slack_ns when resetting RT policy on fork

Commit ed4fb6d7ef68 ("hrtimer: Use and report correct timerslack values
for realtime tasks") sets timer_slack_ns to 0 for RT tasks in
__setscheduler_params(). However, when an RT task with SCHED_RESET_ON_FORK
creates child threads, the children inherit timer_slack_ns=0 from the
parent. sched_fork() resets the child's policy to SCHED_NORMAL but does
not restore timer_slack_ns, leaving the child permanently running with
zero slack.

Fix this by restoring timer_slack_ns from default_timer_slack_ns in
sched_fork() when resetting from RT/DL to NORMAL policy, matching the
existing behavior in __setscheduler_params().

Note: this fix alone requires a correct default_timer_slack_ns to be
effective. See the following patch for that fix.

Fixes: ed4fb6d7ef68 ("hrtimer: Use and report correct timerslack values for realtime tasks")
Reported-by: Qiaoting.Lin <linqiaoting@xiaomi.com>
Signed-off-by: Guanyou.Chen <chenguanyou@xiaomi.com>
Signed-off-by: Chunhui.Li <chunhui.li@mediatek.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://patch.msgid.link/20260522131000.1664983-2-chenguanyou@xiaomi.com
---
 kernel/sched/core.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 5a317f6..2cfe893 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -4826,6 +4826,7 @@ int sched_fork(u64 clone_flags, struct task_struct *p)
 			p->policy = SCHED_NORMAL;
 			p->static_prio = NICE_TO_PRIO(0);
 			p->rt_priority = 0;
+			p->timer_slack_ns = p->default_timer_slack_ns;
 		} else if (PRIO_TO_NICE(p->static_prio) < 0)
 			p->static_prio = NICE_TO_PRIO(0);