From mboxrd@z Thu Jan 1 00:00:00 1970 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: 8bit 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 --- 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