From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (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 A2AD632B12D for ; Thu, 18 Jun 2026 03:11:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781752292; cv=none; b=YYbcehMLBJDjEqdx9+lingFYOxVjyvPlrLwJTcVKIpM0VLQiW/IDs9+oUxwe6RQ26ixhJaRxFCOdxQw1K14m2+Xkswngc2gP517L2LoRKe27FXFUQulu1dgJhWGlqbS2g0QBIOKF4p10spCQ+e6TTWgVbT3icD722H4wDtDDt90= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781752292; c=relaxed/simple; bh=LFnUvZsdMV36HeugdzJp7p/REa5uLOArHKOIqQWkJY0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=CtearVOAjj1os1sECse3DAsn9MchtkRLYlGfRTXvLn7B9TxzIoePnyv47fAIHwyTIBKePN3Pzv8TIkQ5lreGAGc55MrEjZasVfvqIv6hM+oKQ3xYybtlvF/v4EaBKOlfK14HgVukHqGC6cujb/2buaHHE5nmsOf5JxUIaKGfsnk= 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=djEp0eok; arc=none smtp.client-ip=209.85.214.170 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="djEp0eok" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-2c6bb8a5980so3214555ad.2 for ; Wed, 17 Jun 2026 20:11:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781752291; x=1782357091; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=WzKJaLY4P29xr36n94cF6pafuVv3SDEbWpOz12HsOhM=; b=djEp0eokhQ2NMzAcX24vYUFw7KCOYo04rjPuhwnJxmAZUa3gbFVTm+4j3DGzDUGPyI DIKUBNI+QvlSbkuKWdia3u4U+ICMFPC3G4vw5fJBciBwb87g6yNhgaJ79ePKvvyAG1to 9AFC9zVvEUuU9Tqk5/+GOczqNlBGwyrLCrfNsLfoW0VUE4mzaoS6FrnEaeP8/8TNjG4V eCAKW3knJoh8YMN/rAVJAbLfn/W5c2Jte6eAUKlcwCD9/yVhgUqSsEmstPkEWKKeoC1l /djM+oK4tN5Iayfhe9A6NKs26Jrap7Gkn+J4WbhSaj8NM5Idz3QanszWiLIJseWhGKgR xHxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781752291; x=1782357091; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=WzKJaLY4P29xr36n94cF6pafuVv3SDEbWpOz12HsOhM=; b=Q0TyfO/W2+NY/fcnCGNFDIxw+GKnzmDie+a6+bwbF62nO75t1kC3UVtoHjlwT/qsxx Ml0ptNGi2swDSc5NveaBCmJt38dn988yHsTXawYMqzDqPMHpt7elMQMzik8/IybKe+is OlzPfTf6cKz55OKkfdp/3e/Rh5UdWKjdoK8e3KphI0rhxQwjTTsc2340YThXcP7G9+9v OOg3TXjO6u/8vAD+7sKdt/Ppvi7ybI3yKg2cwqr25X8KEPdJVgQ1fyLwKtCVdxTRQCE0 cl/R2rkWz4gb8x7Isc1cURnx196swdLNwrHf6vbfmIDZhLm7xICddabfAymr2RBKvRE5 sG8w== X-Forwarded-Encrypted: i=1; AFNElJ9HqF4ztg3128syv7BqvEliVf6YAWxEGdJQ5LIjo+2kJ88K2d6fhbSggyYV33yEdc4lkM7zAQkp+iE=@vger.kernel.org X-Gm-Message-State: AOJu0YzzB4SlAoa5EwPgDWihh6nv6q4EaPTJxaD6zm6Rok0lkG1o/Gfx CcaUfoSJm21yG58/HQxnBD/tHSJvtYZ3HTBiSSRJkoClfQDkerCtqj3I X-Gm-Gg: AfdE7cmyTSQ7FWnbkarc2hCzRvFnGKNx3bHv6TEIX82yJkCtayHRtlez8VxuBiRY/iZ qCXT9JMG/lNJsnEPNu3sEghcr7dWqV2gmSf1veijpYafWjftBQMQvTMoC80tWwNC8GT4aKjpYhP 8uPawgTL0MUai1Wn1Nsg5pWXaHB3fM3GRyEu7hhnedjMY+l6qemmtxdsIBae54IEgU3bEtAxXyf CnDKk78DmXWWrMFyaERy5mb4+3Vpd2oGfMwZEZwqyU+ihDgQpH36a528hEj7clionqG0wO81uOH Y0siB43VtO4X1SMVokwQsRaBfqAgc6HaF1DkZRFiJtrKo1i3JGs4eByRK/7eWak2YlYiFT2+q5p GQihEuxea3uyP2lVbxwl7FUr9vft2RIEC/ecEk09w0OwvMunsGCrVFMpdR+Pt9tD2LvjVcI/B4n hZBqUwtu6ROIQ= X-Received: by 2002:a17:902:f688:b0:2c6:c66b:4b03 with SMTP id d9443c01a7336-2c6e4746cb1mr16305205ad.10.1781752290966; Wed, 17 Jun 2026 20:11:30 -0700 (PDT) Received: from [127.0.1.1] ([138.199.21.246]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2c6a403b242sm60152975ad.31.2026.06.17.20.11.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jun 2026 20:11:30 -0700 (PDT) From: Jing Wu Date: Thu, 18 Jun 2026 11:11:12 +0800 Subject: [PATCH v3 01/13] sched/isolation: Replace notifier chain with explicit callback interface Precedence: bulk X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20260618-wujing-dhm-v3-1-28f1a4d83b68@gmail.com> References: <20260618-wujing-dhm-v3-0-28f1a4d83b68@gmail.com> In-Reply-To: <20260618-wujing-dhm-v3-0-28f1a4d83b68@gmail.com> To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , "Paul E. McKenney" , Frederic Weisbecker , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Boqun Feng , Uladzislau Rezki , Mathieu Desnoyers , Lai Jiangshan , Zqiang , Anna-Maria Behnsen , Tejun Heo , Jonathan Corbet , Shuah Khan , Shuah Khan , Thomas Gleixner Cc: linux-kernel@vger.kernel.org, rcu@vger.kernel.org, cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Jing Wu , Qiliang Yuan X-Mailer: b4 0.13.0 Replace the blocking notifier chain with an explicit per-type callback table (struct housekeeping_cbs). Each subsystem registers callbacks at initcall time; pre_validate() runs before the RCU pointer swap to allow rejecting the update, and apply() runs after synchronize_rcu() when the new mask is visible to readers. The table is limited to HK_MAX_CBS (4) slots per type, sufficient for the kernel-noise subsystems and avoiding unbounded dynamic allocation in the update path. The interface provides deterministic callback order and explicit registration, giving each subsystem maintainer clear visibility into when and why its callback is invoked — unlike the opaque priority-based dispatch of notifier chains. Signed-off-by: Jing Wu Signed-off-by: Qiliang Yuan --- include/linux/sched/isolation.h | 31 +++++++++++++++ kernel/sched/isolation.c | 87 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+) diff --git a/include/linux/sched/isolation.h b/include/linux/sched/isolation.h index cf0fd03dd7a24..f362876b3ebdf 100644 --- a/include/linux/sched/isolation.h +++ b/include/linux/sched/isolation.h @@ -46,6 +46,33 @@ extern bool housekeeping_test_cpu(int cpu, enum hk_type type); extern int housekeeping_update(struct cpumask *isol_mask); extern void __init housekeeping_init(void); +/** + * struct housekeeping_cbs - Per-subsystem callbacks for housekeeping mask changes + * @name: Subsystem name for diagnostic messages + * @pre_validate: Run before RCU pointer swap. Return -EINVAL + * to reject the update. + * @apply: Run after synchronize_rcu(). Reconfigure subsystem + * state. The new mask is visible to readers. + * + * Register subsystem callbacks at initcall time. + * Invoke callbacks in registration order when the corresponding + * housekeeping mask changes. Skip types not present in the update + * mask. + * + * Replace the notifier-chain pattern with deterministic callback + * ordering. + */ +struct housekeeping_cbs { + const char *name; + int (*pre_validate)(enum hk_type type, + const struct cpumask *cur_mask, + const struct cpumask *new_mask); + void (*apply)(enum hk_type type); +}; + +int housekeeping_register_cbs(enum hk_type type, struct housekeeping_cbs *cbs); +int housekeeping_unregister_cbs(enum hk_type type, struct housekeeping_cbs *cbs); + #else static inline int housekeeping_any_cpu(enum hk_type type) @@ -73,6 +100,10 @@ static inline bool housekeeping_test_cpu(int cpu, enum hk_type type) static inline int housekeeping_update(struct cpumask *isol_mask) { return 0; } static inline void housekeeping_init(void) { } +static inline int housekeeping_register_cbs(enum hk_type type, + struct housekeeping_cbs *cbs) { return 0; } +static inline int housekeeping_unregister_cbs(enum hk_type type, + struct housekeeping_cbs *cbs) { return 0; } #endif /* CONFIG_CPU_ISOLATION */ static inline bool housekeeping_cpu(int cpu, enum hk_type type) diff --git a/kernel/sched/isolation.c b/kernel/sched/isolation.c index ef152d401fe20..aae4dff7fbfc8 100644 --- a/kernel/sched/isolation.c +++ b/kernel/sched/isolation.c @@ -28,6 +28,93 @@ struct housekeeping { static struct housekeeping housekeeping; +/* + * Maintain an explicit callback table indexed by housekeeping type. + * Invoke callbacks for affected types in deterministic order: + * pre_validate() before the RCU pointer swap, apply() after + * synchronize_rcu(). + */ +#define HK_MAX_CBS 4 + +static struct { + struct housekeeping_cbs *cbs[HK_MAX_CBS]; + int nr; +} housekeeping_cbs_table[HK_TYPE_MAX]; + +/** + * housekeeping_register_cbs - Register explicit callbacks for a housekeeping type + * @type: Housekeeping type to register for + * @cbs: Callback structure containing pre_validate() and apply() + * + * Callbacks run in registration order when the mask for @type changes: + * pre_validate() before the RCU swap may reject the update; apply() + * after synchronize_rcu() reconfigures subsystem state. + * + * Return: 0 on success, -EINVAL if @type or @cbs is invalid, + * -ENOSPC if the per-type table is full. + */ +int housekeeping_register_cbs(enum hk_type type, struct housekeeping_cbs *cbs) +{ + if (type >= HK_TYPE_MAX || !cbs) + return -EINVAL; + if (housekeeping_cbs_table[type].nr >= HK_MAX_CBS) + return -ENOSPC; + housekeeping_cbs_table[type].cbs[housekeeping_cbs_table[type].nr++] = cbs; + return 0; +} +EXPORT_SYMBOL_GPL(housekeeping_register_cbs); + +/** + * housekeeping_unregister_cbs - Remove previously registered callbacks + * @type: Housekeeping type + * @cbs: Callback structure to remove + * + * Return: 0 on success, -EINVAL if arguments are invalid, + * -ENOENT if @cbs was not registered. + */ +int housekeeping_unregister_cbs(enum hk_type type, struct housekeeping_cbs *cbs) +{ + int i; + + if (type >= HK_TYPE_MAX || !cbs) + return -EINVAL; + for (i = 0; i < housekeeping_cbs_table[type].nr; i++) { + if (housekeeping_cbs_table[type].cbs[i] == cbs) { + housekeeping_cbs_table[type].cbs[i] = + housekeeping_cbs_table[type].cbs[--housekeeping_cbs_table[type].nr]; + return 0; + } + } + return -ENOENT; +} +EXPORT_SYMBOL_GPL(housekeeping_unregister_cbs); + +static int housekeeping_pre_validate_cbs(enum hk_type type, + const struct cpumask *cur, + const struct cpumask *new) +{ + int i, ret; + + for (i = 0; i < housekeeping_cbs_table[type].nr; i++) { + if (!housekeeping_cbs_table[type].cbs[i]->pre_validate) + continue; + ret = housekeeping_cbs_table[type].cbs[i]->pre_validate(type, cur, new); + if (ret < 0) + return ret; + } + return 0; +} + +static void housekeeping_apply_cbs(enum hk_type type) +{ + int i; + + for (i = 0; i < housekeeping_cbs_table[type].nr; i++) { + if (housekeeping_cbs_table[type].cbs[i]->apply) + housekeeping_cbs_table[type].cbs[i]->apply(type); + } +} + bool housekeeping_enabled(enum hk_type type) { return !!(READ_ONCE(housekeeping.flags) & BIT(type)); -- 2.43.0