RT and deadline policies force timer_slack_ns to zero while a task runs under the realtime policy. The original slack value is kept in default_timer_slack_ns so it can be restored when the task returns to a normal policy. copy_process() initializes the child's default_timer_slack_ns from current->timer_slack_ns. For an RT/DL parent this copies the temporary zero value into the child's default. If the parent also uses SCHED_RESET_ON_FORK, sched_fork() resets the child to SCHED_NORMAL and restores timer_slack_ns from that already-poisoned default, leaving the child with zero slack. Preserve current->default_timer_slack_ns when current->timer_slack_ns is zero so reset-on-fork children can restore a real default slack value. Fixes: ed4fb6d7ef68 ("hrtimer: Use and report correct timerslack values for realtime tasks") Signed-off-by: zhidao su (Xiaomi) --- kernel/fork.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/kernel/fork.c b/kernel/fork.c index addc555a1077..39db7502379b 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -2196,7 +2196,14 @@ __latent_entropy struct task_struct *copy_process( retval = -EAGAIN; #endif - p->default_timer_slack_ns = current->timer_slack_ns; + /* + * RT/DL tasks run with timer_slack_ns forced to zero, but their + * default_timer_slack_ns still carries the value to restore when + * returning to a normal policy. Preserve that default across fork so + * SCHED_RESET_ON_FORK children can restore a real slack value. + */ + p->default_timer_slack_ns = current->timer_slack_ns ?: + current->default_timer_slack_ns; #ifdef CONFIG_PSI p->psi_flags = 0; base-commit: e771677c937da5808f7b6c1f0e4a97ec1a84f8a8 -- 2.43.0