[PATCH 2/2] fork: fix default_timer_slack_ns inheritance from RT parent

From: Guanyou.Chen

Date: Thu May 21 2026 - 03:42:11 EST


copy_process() sets the child's default_timer_slack_ns from the parent's
timer_slack_ns. Since commit ed4fb6d7ef68 ("hrtimer: Use and report
correct timerslack values for realtime tasks"), RT tasks have
timer_slack_ns forced to 0. This corrupts the child's
default_timer_slack_ns to 0, making prctl(PR_SET_TIMERSLACK, 0) unable
to restore a meaningful default.

Additionally, init_task never initialized default_timer_slack_ns (it was
implicitly 0). The original fork code masked this by always overwriting
the child's default from timer_slack_ns. With this fix, init_task must
explicitly initialize it.

Fix this by:
1. Initializing default_timer_slack_ns=50000 in init_task.
2. Removing the default_timer_slack_ns override in copy_process()
(dup_task_struct already copies both fields correctly from the
parent).

The semantic of default_timer_slack_ns is a "reset target" for
prctl(PR_SET_TIMERSLACK, 0). No userspace API modifies it, so it should
propagate unchanged through the process tree via struct copy.

Fixes: 6976675d9404 ("hrtimer: create a "timer_slack" field in the task struct")
Signed-off-by: Guanyou.Chen <chenguanyou@xxxxxxxxxx>
---
init/init_task.c | 1 +
kernel/fork.c | 2 --
2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/init/init_task.c b/init/init_task.c
index 5c838757fc10..57ff8dae9bfb 100644
--- a/init/init_task.c
+++ b/init/init_task.c
@@ -170,6 +170,7 @@ struct task_struct init_task __aligned(L1_CACHE_BYTES) = {
INIT_CPU_TIMERS(init_task)
.pi_lock = __RAW_SPIN_LOCK_UNLOCKED(init_task.pi_lock),
.timer_slack_ns = 50000, /* 50 usec default slack */
+ .default_timer_slack_ns = 50000, /* 50 usec default slack */
.thread_pid = &init_struct_pid,
.thread_node = LIST_HEAD_INIT(init_signals.thread_head),
#ifdef CONFIG_AUDIT
diff --git a/kernel/fork.c b/kernel/fork.c
index 65113a304518..8358df80e11d 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -2133,8 +2133,6 @@ __latent_entropy struct task_struct *copy_process(
retval = -EAGAIN;
#endif

- p->default_timer_slack_ns = current->timer_slack_ns;
-
#ifdef CONFIG_PSI
p->psi_flags = 0;
#endif
--
2.34.1