From nobody Sun May 24 18:43:54 2026 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 02046399D08 for ; Fri, 22 May 2026 13:11:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779455467; cv=none; b=EIDwPc+71cVjk12McRQ1SREkDfP7TcS9w5teAMKjksEX4Wu7nFXb7oiXug6tdKFnZzA3K44Ni5fC0ckgmyI15WwBkJVEX8TGOWa/l+UwmUdcmbuIiex3Rjyum3do56nj9P6RAmk7X/I2DeX+EBZm7z6EBWleY/ZD2Qz0IZqn26I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779455467; c=relaxed/simple; bh=SDx360DtEOZHLmhSdI1nX0zyhUvTr80q/W04L+gHgkQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Wl+UkZ3z2S2NJq+0m83vZxhU0QS83YavhVBJ8dIl1RKA+wdXmoxP6pSu7qNpz5kX2T2OdZeXrLE+DQOwtoNJ5gGqUfCdY0MqlX14JV7Cv3s5Te+fgVSKqImROoFb3LQG0tMzphON/j2gjZaFHzUGMZWgJfD4fGA+qTrpdA6Ao4Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=c9ttZW4r; arc=none smtp.client-ip=209.85.221.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="c9ttZW4r" Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-43d734223e4so4853850f8f.0 for ; Fri, 22 May 2026 06:11:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779455464; x=1780060264; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KmabjaMDg5u07f9PVlpPJqjtwnGDgN0UGdthr0aasrM=; b=c9ttZW4r2NN7AJuCV3UmHF3bZUyX3otTgcLn8roBe0l+eIom5azG2yNdiJX2qiXUJk bSl4LdS3Z8NfvX5D0S0baqjudR93tJrcVNVUxDERXhhJURPrEoe545KZDgnBdnDl9AT1 MAvoP1ijeeqZToXvsSHmIk+kiJPerhm0xjYGaboKEp384O4oQU4bL8ZSsvBMWdcdAdjn LhxFUYiOM3VVOVON13nYkPqT6dW0JqHy4BR8Adr2jS8anLupuZw4J0An1GQIQMWZCn04 W8Wd3UfHbiE5raCQdFQfW6DEYVWJdH7OsclAvsN9sB+QZI64AsgMI9D2j4/GOA/6lgO7 awpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779455464; x=1780060264; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=KmabjaMDg5u07f9PVlpPJqjtwnGDgN0UGdthr0aasrM=; b=VbB0FCof7WvAMNirBlrRyZymq2iQ6LM1k2qn3JBJOvmH+AA0jjcSHY1yTfBpzLf/hQ 31BVUfp1wab3ysH9Hcnc+uCGtmNxhwl20VtUmAWZG5IJlQlNxAK6wfhvtG7QuSWNaLzj oY2nldEee4pNmJ4wglM4D4KQzEmqVMRqSNf7P8cgPEAyvzM63iljgvhciGL0L5vW97fo WpGRXfoSi/R5IaRKr9QRfDL4n81XFAdXTFM1yYhA8efb/cwCcqqB6EQe03+M2Fp2dm2z VIN9XE72/j9kVIf0O2NnVSOUYuav/k3Gnc72gTwazETnM57hivjXgoCDAFMBCj6yuHAM WPtQ== X-Forwarded-Encrypted: i=1; AFNElJ/A9xc+CTyJrzpK2kwn3WnWHt6lypgiHVc0xLYOaPtZVryKnqF/PTUX6krPRpOPR5yL5uvEOdC9Y7Ack2w=@vger.kernel.org X-Gm-Message-State: AOJu0YxVJIFouocuLxZ7NNDHoBGLxY2leASOHUvI1tPTMkptFKjdS/EN 6uuv7tmUlrFSLZhf8ByLDF7QywQ04G9CsiiDIueDfzfzEsZyYPkkk9/o X-Gm-Gg: Acq92OFEL5LDowNphI3U1Y/RRkF7hyQVfulTd8LwngKJbgHHc85Ds/zz/WOl9vaG+dm KJ9E0Z28Yen8uI5iQhZCKmWETCMGA4NTlj4Sm/Xb+yvgeGBhg3BISXndSvBH3BmWwTJqYjWC8qU dkUGPLFyKAyYLYnDh6qvPQNrh2WM+c/DTJYDsWgY/xkOFpcsL9delB8xPMMDw1OeF3+nK1Oy8K/ NepWhHjoD85EQhG6oYVKN+yJ0UyWKLhdCseCeciBZ4NGt0gnNTgozqYKevFtzs9ZTOkjOi5Fo90 9Rh7EnLEFWh7JwSQhNPEsgjVNBs/CHKObMVScpqAQa3FSTkivbO3bqgakndrUYurTBmCx+CHqpB WcQ4DMarY8OTPVRvxUplx3VMJwnvJRZG17+tOPJzfoF4IM1f+xOqrCBy2eWJ4mCNvpoA4OiNdq2 deO4A4Fg0Ez4oKOYiMaToLa4wiBdeGSQmyb1o/nXyh4aGktKSgD3KpH3Igw1CgUR8= X-Received: by 2002:a05:6000:26c4:b0:45e:739b:2750 with SMTP id ffacd0b85a97d-45eb30ec2e2mr5180404f8f.9.1779455464361; Fri, 22 May 2026 06:11:04 -0700 (PDT) Received: from mi-HP-ProDesk-600-G5-PCI-MT.mioffice.cn ([43.224.245.239]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-45eb6d5e484sm4091262f8f.30.2026.05.22.06.10.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2026 06:11:03 -0700 (PDT) From: "Guanyou.Chen" X-Google-Original-From: "Guanyou.Chen" To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Andrew Morton Cc: Thomas Gleixner , Felix Moessbauer , Dietmar Eggemann , Steven Rostedt , Kees Cook , K Prateek Nayak , chenguanyou@xiaomi.com, linqiaoting@xiaomi.com, chunhui.li@mediatek.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 1/2] sched: restore timer_slack_ns when resetting RT policy on fork Date: Fri, 22 May 2026 21:09:59 +0800 Message-Id: <20260522131000.1664983-2-chenguanyou@xiaomi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260522131000.1664983-1-chenguanyou@xiaomi.com> References: <20260521070440.GD3126523@noisy.programming.kicks-ass.net> <20260522131000.1664983-1-chenguanyou@xiaomi.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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=3D0 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 =3D SCHED_NORMAL; p->static_prio =3D NICE_TO_PRIO(0); p->rt_priority =3D 0; + p->timer_slack_ns =3D p->default_timer_slack_ns; } else if (PRIO_TO_NICE(p->static_prio) < 0) p->static_prio =3D NICE_TO_PRIO(0); =20 --=20 2.34.1 From nobody Sun May 24 18:43:54 2026 Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 63C7839A801 for ; Fri, 22 May 2026 13:11:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779455476; cv=none; b=ouCoiTLYCq+jBkcPwVMd4sBtachSKBGV+TDMfbpvhUmzbYYO2QYtOUtPTIzponIAompFmiKeQ2ykMYzDgD5ISLPQBv6N/J/Ts/U/ZdcNawOR4hMikBib/nh/j6Qhx5DZUgOoviONeJCLY9BeYXktTMwP2lq48WycynYlC/7MKWo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779455476; c=relaxed/simple; bh=8Qmb4NUWQKug52jxg4KO30zYqHSTL0W3sImtSojvI84=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Q4neISAgcMO0FN/B0xxrFgL/d4fxk8YohmGZ0dCaiLTKbwglHzGnQE4hLWAN3T4E1WqDEtR4qocKQPstbKto9BmYwQoFV4Y1q8afCKdcdtdi5uTmWnanl3tRIBr7+YuIKmG+taBzRla+F+LPwCG94kvf3tqHbbUVoooXul4BjbE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ofwPGqMm; arc=none smtp.client-ip=209.85.221.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ofwPGqMm" Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-459bf19e87bso4376130f8f.1 for ; Fri, 22 May 2026 06:11:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779455473; x=1780060273; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=eqaGR9QC9sk0vele50CdUpWtSWhtR0zZvI8lmeOz5HE=; b=ofwPGqMmZIcRMMv2APRl5goBEgdi2FUwpuhJak1L0U+172/6Axtbt55Hcfbwn0F/wo 5d14teoMyfIvBEqK1EEO++1dh/RDPXpiP3UoxEyIpuGJa+zcz2CNVf0ciDRTSx4VZQmd L/YKQi7yvGv8OxrbrxpKys1oZbD+FjesHuB5kfAwgvLrId1qws2rFyr9ecI9a6HJnXpv 68HLRs5oNJ5OEqgCvoeSpfpNPXfRu9M69n/vhqKoOa9+ZPmSBGUn3U8K8y2sBY7zDwil fvdGYYvxE9IDf77Dtgn94oUHul9jD/VnRqU93fcjKmJYlsCWOyeoG2cAeNo0fMz1+CHu E/iQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779455473; x=1780060273; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=eqaGR9QC9sk0vele50CdUpWtSWhtR0zZvI8lmeOz5HE=; b=Nqtj4K3DLR4JjNKiFplu3RdT0qvZ1TVLT7lCixOc0QrOfwnCslKFxwH30XyToxN5DD cgJch6TFGp3SkjljKArgkHbWOmJRKxk6BhqM3jL+BIpFbrmIT2JFQ2tTgJSr8k0CIWrA 29o7SFBJZhAcgD4vg1FaEpKiVEDjPLxNgybetVLCpZ55Jv3xbzhJSuTzLfMSfvFgTDeL B1v8/s87s6CPehGxP5Co9RykpyhQlGzlSgbfvDYaY70BFdrcQkAFvcSnyWSVBiDThDXz Z69XnGGE29vfxXHzUyZ7+gyVRJik+JKmeEyD/yBExvzcBTVYHqKxIkbpYbIORXcbuM5j Pqew== X-Forwarded-Encrypted: i=1; AFNElJ9Vh5esPkySiMLgBqa/JmSc+DoSoXXQDyFJow0qT+/qaEpyxAd/citnCtPxtT8KXIpJKHLUPumVg6JMslw=@vger.kernel.org X-Gm-Message-State: AOJu0Yy4j/YUmkf57qTiXsQySPCmj4zZY0yDBpSRCyyBPLw5DVfJf4Kk hT66gPkg7D8iDtH7+BbfwMy2Xq00aajFCtXyf6Jg3IxQemFPhT7vaXGW X-Gm-Gg: Acq92OH7+fXbGktI/yAdD8opJ7wPJCbAntXbMLY2gT88jXzdWmE29Hs7t/oxsxmiXf6 iMOqPOMUTQOxShVFrl8dIyRJhMpcjC+7FgrOBkQoQJepK2lnVyA8R0sXraS2DhuM2spUWMNmVDE 3VXDuwNrDli8/uQHisCuJh/ZTbpYP0OHZG9ihxdFCfMZ3m+CTZSgiOLXAMTM8zXdTDjDgifw3ic K6hpheKSRyWjAy1io8vSBwrAFGYb0MXqL3tD7/Sbk3IUv1AlNnmGl/mRZcoq8tGZpfLiH3ExgbI h7GzXIMD5Lfvm6Yo1JYtL0wexAp3IGgCQ4EfYqnQTYDAqEhcpIWGPU0u4c46F+NliBbHl6xfWPx gbN4hkxYwNRLZzEELr8WMrB/CDmDlp4PREF4vv5ARM5TDN7L05GMb+vWDjZ3iAyYGeN4RefXzrf gN7EjZOMgbod738zarm5CbTcMiVW09NvHxDRfie2gcilZEj4MJHkSQvxgBggGVjxU= X-Received: by 2002:a05:6000:1a87:b0:43f:dd91:b022 with SMTP id ffacd0b85a97d-45eb38d7d0emr5367027f8f.35.1779455472506; Fri, 22 May 2026 06:11:12 -0700 (PDT) Received: from mi-HP-ProDesk-600-G5-PCI-MT.mioffice.cn ([43.224.245.239]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-45eb6d5e484sm4091262f8f.30.2026.05.22.06.11.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2026 06:11:12 -0700 (PDT) From: "Guanyou.Chen" X-Google-Original-From: "Guanyou.Chen" To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Andrew Morton Cc: Thomas Gleixner , Felix Moessbauer , Dietmar Eggemann , Steven Rostedt , Kees Cook , K Prateek Nayak , chenguanyou@xiaomi.com, linqiaoting@xiaomi.com, chunhui.li@mediatek.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 2/2] fork: fix default_timer_slack_ns inheritance from RT parent Date: Fri, 22 May 2026 21:10:00 +0800 Message-Id: <20260522131000.1664983-3-chenguanyou@xiaomi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260522131000.1664983-1-chenguanyou@xiaomi.com> References: <20260521070440.GD3126523@noisy.programming.kicks-ass.net> <20260522131000.1664983-1-chenguanyou@xiaomi.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 =3D -EAGAIN; #endif =20 - p->default_timer_slack_ns =3D current->timer_slack_ns; + if (rt_or_dl_task_policy(current)) + p->default_timer_slack_ns =3D current->default_timer_slack_ns; + else + p->default_timer_slack_ns =3D current->timer_slack_ns; =20 #ifdef CONFIG_PSI p->psi_flags =3D 0; --=20 2.34.1