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 Signed-off-by: Guanyou.Chen Signed-off-by: Chunhui.Li --- kernel/sched/core.c | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index b7f77c165a6e..b1a241810ce0 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -4649,6 +4649,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); -- 2.34.1 Per prctl(2), "Timer slack is not applied to threads that are scheduled under a real-time scheduling policy." This means RT tasks' timer_slack_ns is forcibly 0 - not a user-chosen value but a "not applicable" state. When copy_process() sets the child's default_timer_slack_ns from the parent's timer_slack_ns, it inherits this forced 0 for RT parents. This corrupts the child's reset target, making prctl(PR_SET_TIMERSLACK, 0) and sched_setscheduler() back to NORMAL unable to restore a meaningful default. Fix this by using default_timer_slack_ns (which preserves the pre-RT value) when the parent is RT/DL. For non-RT parents, timer_slack_ns is a meaningful user value and the existing behavior is preserved. Fixes: ed4fb6d7ef68 ("hrtimer: Use and report correct timerslack values for realtime tasks") Reported-by: Qiaoting.Lin Signed-off-by: Guanyou.Chen Signed-off-by: Chunhui.Li --- kernel/fork.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kernel/fork.c b/kernel/fork.c index 65113a304518..bc4df18bfd90 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -2133,7 +2134,10 @@ __latent_entropy struct task_struct *copy_process( retval = -EAGAIN; #endif - p->default_timer_slack_ns = current->timer_slack_ns; + if (rt_or_dl_task_policy(current)) + p->default_timer_slack_ns = current->default_timer_slack_ns; + else + p->default_timer_slack_ns = current->timer_slack_ns; #ifdef CONFIG_PSI p->psi_flags = 0; -- 2.34.1