From nobody Sun May 24 21:39:21 2026 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (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 440F239A81B for ; Thu, 21 May 2026 07:35:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779348934; cv=none; b=IJC5M9UwnC0rTTrC1khBhMPGbdYxGWgYydMA2dp7CeQOU5YHbDR8KJrE1N6Wx6oThZwEUls77WgaZ31tccUvpsynCbTSLV3lcNyhXc51vy3BXoRwbGjKvNk9WiFmCbE8qBNuSL1YY/jgQHO4W+EClqY00O2Dz/Or9EMyKWc9aRM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779348934; c=relaxed/simple; bh=SDx360DtEOZHLmhSdI1nX0zyhUvTr80q/W04L+gHgkQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nrxPZM3W/NZrQG6jB1n00XXJgUCi52S3IHN6G/iNUvsSNkIDjMjSHTd73OQySFMZRv+6XcwmB5hFtt3w/HRkMkj1rY0kLPNTsx8hr/xddGfrxmQ3Hy4tC6WrI2P5AuAPK8JfV1NFoL0HP36dgolNtqLn0k1CJsRggdAm6iYC9mM= 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=cDCvfoaW; arc=none smtp.client-ip=209.85.214.182 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="cDCvfoaW" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-2ba4a1a0325so36510345ad.0 for ; Thu, 21 May 2026 00:35:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779348932; x=1779953732; 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=cDCvfoaWHNJ4ZpaIsIjOrMBfVpFe1vbieBGyKt/O+kSF0uy6LqU+YbvXaWdGunmjGM DA5Hgo0yyImh7N9ilFTr9ybTK0CoW/7d4Px319H6eO3p9iWL93m4l7xycZIi2rbAA4XW 8ajg9PRa253zbYdEKLQC6UlK17DD7GCNqlnJKgV8Y6RG6z+5HcmTW+HS7W8ksHeDWR2f Pr5FuVDH1nluQBS8nv451mniJiXrru21ZdiGcDDTyI26KKpIEAa9RSMpzLEsksUVNg+o GKpHGfMw0RdLqZxtCzsvZBf8Ddthtc6S7wq95cbIUkQUCDUpjfAFwWdBeRH/JJsAUaKT UdDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779348932; x=1779953732; 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=i02BuUKckoluxCuOSXOqH6JNuqwFjSM5//V5jJh3Y3JngeWmugv/iECugLVxjkkXGB 4WUyxacL7bVQIo0J6RcyrV3K3L37yXtUJ+EfbZ1GbyHDV8SHL8I+Q48VXabHWJ6fTFOZ zNzG/btkYz4EYbjk9nqKvdPnuYARu9F8Kc2r6/LP3sIEaerj5sj+wR3GT3i1iN8KEVRM 3KNrW0RCQXSrvfX6MiR2qf2Ww3o6iIiXtjtY+AHEDp03z4d8GzXITc2cCqw37j7yW9EH ccm1oevTM9Mj48Pyb3ACWErMrqjQRLco5HMSRNt7tfMqBH0u2a1pKL1JPHAgRcDeFVPw zMaA== X-Forwarded-Encrypted: i=1; AFNElJ8Uyq78dXC3UCzyo4eAOZDixiu/1sHMLFcnwAiAdiQ7hNaOM8MpeDRUcjpQWKYPzkdyaiSLdOf6bj8/+ok=@vger.kernel.org X-Gm-Message-State: AOJu0Yx1i1d2J57f2GSo0lR7vVMISajf48Gkven61FBTH45dr/nVbh74 BKSz/bg5Xjj7Aw+NgEut3CMReQiQeWYkUgSAxKpR0/oCpr39s38lPoOg X-Gm-Gg: Acq92OFYZZsnQ3gCE6yK7wucszpofL5Aegbbms5S1gk7WzU3kvqJuxP7OQXwagH8qdD eKGKu1fY6sv0+I1L2ewTwH7C70IqBhVxPAyzUHHwCpfZHnZDyD8/Lc8RqEXXMqzfZqfPu52+/W7 dNE5SBEsN6Uf5uCOVFpJ0oJxXuPqoD0B6BpCXaB/rBXccZftsXpEXQ3XKUJKUyl+A3n35HibXcA p0jIASOVfxlXGs+rLFM8e6JQPTjwTZxlOW6Zoq9MG2gHqXadPUyj93qoKFW0Tfgk8zok35iy+il 8bvlGSemRJ+6tqkKu0Zxn4asoF8ch5hjHuVs+Kg9sqG64eMCN+7ifSYHOxI6Gh2/m0J8mBvGONN huQDJowyydcTXiWd74GKMqXZyBOzLLmSBw/Pq4f05mu5dv6u06+dYB3ZxqK6XVcOiUh6Rcd67i+ fuNEXhFoxr+TyblO4b4RIICICvVzM1xVKauMvBiLtm9IWhFoZPIJa7KTcUaQ/1T6A= X-Received: by 2002:a17:902:e54b:b0:2b0:c59f:3b58 with SMTP id d9443c01a7336-2bea32d41a0mr19148595ad.9.1779348932487; Thu, 21 May 2026 00:35:32 -0700 (PDT) Received: from mi-HP-ProDesk-600-G5-PCI-MT.mioffice.cn ([43.224.245.239]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2bea98ed8d3sm1260405ad.38.2026.05.21.00.35.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 May 2026 00:35:32 -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 , chenguanyou@xiaomi.com, linqiaoting@xiaomi.com, chunhui.li@mediatek.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 1/2] sched: restore timer_slack_ns when resetting RT policy on fork Date: Thu, 21 May 2026 15:35:11 +0800 Message-Id: <20260521073512.1499230-2-chenguanyou@xiaomi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260521073512.1499230-1-chenguanyou@xiaomi.com> References: <20260521070440.GD3126523@noisy.programming.kicks-ass.net> <20260521073512.1499230-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 21:39:21 2026 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (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 854D739A4B3 for ; Thu, 21 May 2026 07:35:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779348938; cv=none; b=dX9IZAkC6Ekg6gM9c/muKm+HxE38lfUv52HPzrCTcDkMhntBVrYdq/RvAEi2V+tqkOKpXTiOaDsjyF9Xo/zDTylk00e687IctBzkrz/e/UwqvpX81tnXwgf5uBCiHRQ5AikGcWXipf67K+zP+wuRUYsn9ZCATebbMOXZInJO6UI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779348938; c=relaxed/simple; bh=CjAYnxoE6zmZgTt9l5CR/hFujhYT2dhD0e3QkfJE2WQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=K6wK29Jpi9wItQNM6BxjZlLC+ra95RYfVlwWd4mAJ+xju6tbmMsDbiRkMi7JX3W0Fyv1fx8sFyJ7SBGAJvU93u5wx1WaNOp0pWq16wQd3xTD49ddFz/88lC/cRLtinQKd/kWyykwG8dLG48Ql/jllvWBsW9UuSfB1MTrxAL2aZY= 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=tIi9er4h; arc=none smtp.client-ip=209.85.214.178 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="tIi9er4h" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-2bd80b3aa13so37206235ad.0 for ; Thu, 21 May 2026 00:35:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779348937; x=1779953737; 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=ilJ2bjdtasfHYuZJGgma9SqBM85uGWQuyCvdR0Kx+7c=; b=tIi9er4h/9dv+PhncaR+aIoO+XFAfFK7d/Tnn4XKJ4EUgtyPCPsIPyaDsnIQfLE7g+ FvWlzh/ufk4hGAXRQqEZu+PcJTX2GnfY10rBW3FpL6smUM4TSqvOg4YTs6yDbxz1OFW2 8bY7cNLFSa97mCxm6Ns5uLEnQNunKeEX02BHzhZzLgbHaVSwMdNmSQcgfO9A8y4OVn4p rECIeg/P0JwTTXvCaOi/VXMeOh1o5rjT/FLSYGVhDbHsy+EhKJGixDx2Pdw9BIg3maXF hQRUwchB+scxanYtiGJqgNE8f/ujEGy4W3NX38QwlaB/sc4BWt/0zJOlyW9fxQg7K2os MoMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779348937; x=1779953737; 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=ilJ2bjdtasfHYuZJGgma9SqBM85uGWQuyCvdR0Kx+7c=; b=k3o8PEFEbguG/oALUnH11smQOwo9Pnrx9t/YXGgRj4wwTxJ4s6WyVA4QCJRTCFa0dz luHT4dEcgGbA2GBEETKuwJd1AagpVOoSjBiGXnMY56C1qJ4n/mJJVwAsXLGvdOeP4XXy sPL76xwzGdii+rAFp9/V7Hh6p9c6yCmJ0vYjD2s/aC7XjaoH4yH+7Ct4xJXhPux/r3qL MMkO/mugSZJ3yZyzO6DndwdoMIW5OPrWDvPBniz3DNOkwrIqmc/Rb8IA2JUPfuTIYbDN XHo2MqVEW1dSTGLyVrQhKf62QyVdJElROJrwPlD6tR41eNg8hTaStpLcebAUjn2JzFoZ lTnA== X-Forwarded-Encrypted: i=1; AFNElJ+0v0ZZ+XW90FL/YbvS1VomZU9HSKQyGgFj74AlOEB2ewtX+jZBD71TQp6QqpV4GNncqeJcpG3FMK4Pnpg=@vger.kernel.org X-Gm-Message-State: AOJu0YyX4u5TUvcRl7D36zbgu6g9fdrPTDnmXokx2RsAuV+Ogccq6gKk 1b+ZgM2+QisPau7BGy9rm1WY6CcKrkbYdDDskhGOBxXTxZD1fy/ysow/ X-Gm-Gg: Acq92OGG0DsWIgM3tEpTz0RuCmWaVE8ZK+RBiZT8Gut6IwnbeUvewdNDy7hORYW3VDf rWFGh2AT6nCJhIfSZaGkFXm6edxwANPJR5HZXsaxvF1wAIu8dblq88GIgbif2CNqWYOIMKYsE2P rRKXDNxRlxDwNz52sJTuYwYLaFR0k+XI5Fh/OAvdstVbfikmdvhwAyytQTwacCj0b3Grug/LsAK nSDqmZP6iXNKC98ik2nYVAk6DLjQBX+DSVkBZAyJhCpcLW6DpxxiY2bdjy7vazp+rVDaCbbj8s3 M7N9K1Xx2hfMjZSgGQTs/7s1xc4Qibt5VUT+bQQTgJu/cm9SqnoKD85KgJIBMLvtjnzKY0oCGQH 7cNO10PnzdryjalEC/1ah/2WVzilg4J/t+ll0zGkHrqEXOUSqC7Y3kfx6ELrZMvq41q0II8B8XP FgKoVsL8GLScurr2fXYGcJgsyAQAPIC+l4zLwNyhMD9+Cfxd3REvpg92ePFUN4uhvaIc5q4JqbM w== X-Received: by 2002:a17:903:2312:b0:2b2:4b4e:e4d2 with SMTP id d9443c01a7336-2bea31bdb81mr17712525ad.15.1779348936719; Thu, 21 May 2026 00:35:36 -0700 (PDT) Received: from mi-HP-ProDesk-600-G5-PCI-MT.mioffice.cn ([43.224.245.239]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2bea98ed8d3sm1260405ad.38.2026.05.21.00.35.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 May 2026 00:35:36 -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 , chenguanyou@xiaomi.com, linqiaoting@xiaomi.com, chunhui.li@mediatek.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 2/2] fork: fix default_timer_slack_ns inheritance from RT parent Date: Thu, 21 May 2026 15:35:12 +0800 Message-Id: <20260521073512.1499230-3-chenguanyou@xiaomi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260521073512.1499230-1-chenguanyou@xiaomi.com> References: <20260521070440.GD3126523@noisy.programming.kicks-ass.net> <20260521073512.1499230-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" 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=3D50000 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 str= uct") Signed-off-by: Guanyou.Chen --- 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) = =3D { INIT_CPU_TIMERS(init_task) .pi_lock =3D __RAW_SPIN_LOCK_UNLOCKED(init_task.pi_lock), .timer_slack_ns =3D 50000, /* 50 usec default slack */ + .default_timer_slack_ns =3D 50000, /* 50 usec default slack */ .thread_pid =3D &init_struct_pid, .thread_node =3D 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 =3D -EAGAIN; #endif =20 - p->default_timer_slack_ns =3D current->timer_slack_ns; - #ifdef CONFIG_PSI p->psi_flags =3D 0; #endif --=20 2.34.1