From nobody Tue Jun 16 20:36:47 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9677E265CA2 for ; Tue, 21 Apr 2026 03:05:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776740712; cv=none; b=Si4RQbWBzCggussr9F/QBbDs/Zg6+rsoNMw7HMYPUdjOYIVeQ7/FNX0W0q2cws9ydwB5OTiT+JZ2fHEoGd8ee2CZrIqa/3tNYrgA7lOwmxWBVyQitP+WmZlobcrQlbwYnBakp2y4+4qLVqgWLy5qO52prsmuz1F33TuIp1wxg5E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776740712; c=relaxed/simple; bh=p9SIr6JlyYQGg3qYXe3y5yHG3ZDHW+SwoXZ/LQtgZsk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KtYldcJskIxEMtrFs8gJVG2ROkadzOdyabTbpk5RgYZE/V46bwkt1YGqEIeYY2vH5YTLLbhU/JwcftqcXSEgZTapkXX0M5TqZB4WHnJc/6EcJgem+sbMsXzDnauDYSxiIqf+nKaOBRX0TwkNVDEIOZfMWLLayeuJPVpM/5YdIoY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=dUEQ5ffc; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="dUEQ5ffc" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776740708; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=B+3KY5q3C4zcW8nPMRe1a9XaTfWzQ7AxIKaewiYDXwA=; b=dUEQ5ffcWgmA1Vq1rJ5+evqqbX2MaSESS4x2OCVw/dU4wQlOC0tluOiNsKK0JRTXssr3AL Dc2/T21iqsH8+SDeGNRAONtxPSa6tVHoKJUQT/n8HM2bxbzxcoueK+hgYXazOKl/iD5Oq5 NwaCZfcvajQ9edvE5LtFkykMqdgFfGY= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-681-nv81B0bGPKm_IRIqpOUuyw-1; Mon, 20 Apr 2026 23:05:04 -0400 X-MC-Unique: nv81B0bGPKm_IRIqpOUuyw-1 X-Mimecast-MFC-AGG-ID: nv81B0bGPKm_IRIqpOUuyw_1776740700 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id AF1101800473; Tue, 21 Apr 2026 03:04:58 +0000 (UTC) Received: from llong-thinkpadp16vgen1.westford.csb (unknown [10.22.65.81]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 67A2F19560B7; Tue, 21 Apr 2026 03:04:50 +0000 (UTC) From: Waiman Long To: Tejun Heo , Johannes Weiner , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Jonathan Corbet , Shuah Khan , Catalin Marinas , Will Deacon , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li , Guenter Roeck , Frederic Weisbecker , "Paul E. McKenney" , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Boqun Feng , Uladzislau Rezki , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Zqiang , Anna-Maria Behnsen , Ingo Molnar , Thomas Gleixner , Chen Ridong , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-hwmon@vger.kernel.org, rcu@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Costa Shulyupin , Qiliang Yuan , Waiman Long Subject: [PATCH 01/23] sched/isolation: Add HK_TYPE_KERNEL_NOISE_BOOT & HK_TYPE_MANAGED_IRQ_BOOT Date: Mon, 20 Apr 2026 23:03:29 -0400 Message-ID: <20260421030351.281436-2-longman@redhat.com> In-Reply-To: <20260421030351.281436-1-longman@redhat.com> References: <20260421030351.281436-1-longman@redhat.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 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" Since commit 4fca0e550d50 ("sched/isolation: Save boot defined domain flags"), HK_TYPE_DOMAIN_BOOT was added to record the boot time "isolcpus{=3Ddomain}" setting. As we are going to make the HK_TYPE_MANAGED_IRQ and HK_TYPE_KERNEL_NOISE housekeeping cpumasks runtime modifiable, we need some additional cpumasks to record the boot time settings to make sure that those housekeeping cpumasks will always be a subset of their boot time equivalents. Introduce the new HK_TYPE_KERNEL_NOISE_BOOT and HK_TYPE_MANAGED_IRQ_BOOT housekeeping types to do that. Signed-off-by: Waiman Long --- include/linux/sched/isolation.h | 16 ++++++++++++++-- kernel/sched/isolation.c | 16 +++++++++------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/include/linux/sched/isolation.h b/include/linux/sched/isolatio= n.h index dc3975ff1b2e..d1707f121e20 100644 --- a/include/linux/sched/isolation.h +++ b/include/linux/sched/isolation.h @@ -14,10 +14,22 @@ enum hk_type { * is always a subset of HK_TYPE_DOMAIN_BOOT. */ HK_TYPE_DOMAIN, - /* Inverse of boot-time isolcpus=3Dmanaged_irq argument */ - HK_TYPE_MANAGED_IRQ, + /* Inverse of boot-time nohz_full=3D or isolcpus=3Dnohz arguments */ + HK_TYPE_KERNEL_NOISE_BOOT, + /* + * A subset of HK_TYPE_KERNEL_NOISE_BOOT as it may excludes some + * additional isolated CPUs at run time. + */ HK_TYPE_KERNEL_NOISE, + + /* Inverse of boot-time isolcpus=3Dmanaged_irq argument */ + HK_TYPE_MANAGED_IRQ_BOOT, + /* + * A subset of HK_TYPE_MANAGED_IRQ_BOOT as it may excludes some + * additional isolated CPUs at run time. + */ + HK_TYPE_MANAGED_IRQ, HK_TYPE_MAX, =20 /* diff --git a/kernel/sched/isolation.c b/kernel/sched/isolation.c index a947d75b43f1..9ec9ae510dc7 100644 --- a/kernel/sched/isolation.c +++ b/kernel/sched/isolation.c @@ -12,10 +12,12 @@ #include "sched.h" =20 enum hk_flags { - HK_FLAG_DOMAIN_BOOT =3D BIT(HK_TYPE_DOMAIN_BOOT), - HK_FLAG_DOMAIN =3D BIT(HK_TYPE_DOMAIN), - HK_FLAG_MANAGED_IRQ =3D BIT(HK_TYPE_MANAGED_IRQ), - HK_FLAG_KERNEL_NOISE =3D BIT(HK_TYPE_KERNEL_NOISE), + HK_FLAG_DOMAIN_BOOT =3D BIT(HK_TYPE_DOMAIN_BOOT), + HK_FLAG_DOMAIN =3D BIT(HK_TYPE_DOMAIN), + HK_FLAG_KERNEL_NOISE_BOOT =3D BIT(HK_TYPE_KERNEL_NOISE_BOOT), + HK_FLAG_KERNEL_NOISE =3D BIT(HK_TYPE_KERNEL_NOISE), + HK_FLAG_MANAGED_IRQ_BOOT =3D BIT(HK_TYPE_MANAGED_IRQ_BOOT), + HK_FLAG_MANAGED_IRQ =3D BIT(HK_TYPE_MANAGED_IRQ), }; =20 DEFINE_STATIC_KEY_FALSE(housekeeping_overridden); @@ -315,7 +317,7 @@ static int __init housekeeping_nohz_full_setup(char *st= r) { unsigned long flags; =20 - flags =3D HK_FLAG_KERNEL_NOISE; + flags =3D HK_FLAG_KERNEL_NOISE | HK_FLAG_KERNEL_NOISE_BOOT; =20 return housekeeping_setup(str, flags); } @@ -334,7 +336,7 @@ static int __init housekeeping_isolcpus_setup(char *str) */ if (!strncmp(str, "nohz,", 5)) { str +=3D 5; - flags |=3D HK_FLAG_KERNEL_NOISE; + flags |=3D HK_FLAG_KERNEL_NOISE | HK_FLAG_KERNEL_NOISE_BOOT; continue; } =20 @@ -346,7 +348,7 @@ static int __init housekeeping_isolcpus_setup(char *str) =20 if (!strncmp(str, "managed_irq,", 12)) { str +=3D 12; - flags |=3D HK_FLAG_MANAGED_IRQ; + flags |=3D HK_FLAG_MANAGED_IRQ | HK_FLAG_MANAGED_IRQ_BOOT; continue; } =20 --=20 2.53.0 From nobody Tue Jun 16 20:36:47 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 46C99265CA2 for ; Tue, 21 Apr 2026 03:05:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776740720; cv=none; b=VY43qeJU7RiwyvNZPCUHtzE7NvQ2nSk9pHzNsb3HH5AVg+z1d90JxG5VGMaylY+2ffiK8h05eWS8VrAFb+HoHoYrfY+UOtrqtrrR7GY//cM6ZMzPQnv8vP7cG/9XC8vnel+lGB7EHE5izcdK6aemtLMJPxWjMrJpv23fnnnFfH0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776740720; c=relaxed/simple; bh=1Nd7aPAPB5e+PcIf2RAe7/ngkqO3BsCY9Zy6mLvapVQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EY6DRMq1KxDs3J+4EHLBT73QrfXRPlQZUtFg+iv7NM4fO9wlq9lFBWjbiCgEevl2TF3l7iqU0tig71BMQp1ULvXZdgZRIrXtXhMHjY11CYIqLQMs8lt/jQe2tF5WEL5JQs4YmI2xMOUz48IdIjCMXk4Ub+2KKcd85ea14AVXw5w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=FDVSy5Nj; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="FDVSy5Nj" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776740718; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZQviQUpprZdMxpcMLHlo8S0MLdAxDjnOlUbcwDg0V50=; b=FDVSy5NjYXisSE3WBv0n8cJG+A99TXKSeGBKyJcn47QqtrC/hD3iYmoK01xPWUrjxGmrDN rnQvyUavYBVbYEnpi6E3Eh4ynICxYjuVezF/+ubGV0E1oP6ki4pslLtBsgsMoCw/SHp8yj crfbCzT8Tu1DLr/p+Pq/+OXmX35jwEc= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-267-IEHGJGybNguUVibdx0jmng-1; Mon, 20 Apr 2026 23:05:13 -0400 X-MC-Unique: IEHGJGybNguUVibdx0jmng-1 X-Mimecast-MFC-AGG-ID: IEHGJGybNguUVibdx0jmng_1776740708 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9E4CA18001C7; Tue, 21 Apr 2026 03:05:07 +0000 (UTC) Received: from llong-thinkpadp16vgen1.westford.csb (unknown [10.22.65.81]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E6DE819560AB; Tue, 21 Apr 2026 03:04:58 +0000 (UTC) From: Waiman Long To: Tejun Heo , Johannes Weiner , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Jonathan Corbet , Shuah Khan , Catalin Marinas , Will Deacon , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li , Guenter Roeck , Frederic Weisbecker , "Paul E. McKenney" , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Boqun Feng , Uladzislau Rezki , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Zqiang , Anna-Maria Behnsen , Ingo Molnar , Thomas Gleixner , Chen Ridong , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-hwmon@vger.kernel.org, rcu@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Costa Shulyupin , Qiliang Yuan , Waiman Long Subject: [PATCH 02/23] sched/isolation: Enhance housekeeping_update() to support updating more than one HK cpumask Date: Mon, 20 Apr 2026 23:03:30 -0400 Message-ID: <20260421030351.281436-3-longman@redhat.com> In-Reply-To: <20260421030351.281436-1-longman@redhat.com> References: <20260421030351.281436-1-longman@redhat.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 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" The housekeeping_update() function currently allows update to the HK_TYPE_DOMAIN cpumask only. As we are going to enable dynamic modification of the other housekeeping cpumasks, we need to extend it to support passing in the information about the HK cpumask(s) to be updated. In cases where some HK cpumasks happen to be the same, it will be more efficient to update multiple HK cpumasks in one single call instead of calling it multiple times. Extend housekeeping_update() to support that as well. Also add the restriction that passed in isolated cpumask parameter of housekeeping_update() must include all the CPUs isolated at boot time. This is currently the case for cpuset anyway. Signed-off-by: Waiman Long --- include/linux/sched/isolation.h | 2 +- kernel/cgroup/cpuset.c | 2 +- kernel/sched/isolation.c | 99 +++++++++++++++++++++++---------- 3 files changed, 71 insertions(+), 32 deletions(-) diff --git a/include/linux/sched/isolation.h b/include/linux/sched/isolatio= n.h index d1707f121e20..a17f16e0156e 100644 --- a/include/linux/sched/isolation.h +++ b/include/linux/sched/isolation.h @@ -51,7 +51,7 @@ extern const struct cpumask *housekeeping_cpumask(enum hk= _type type); extern bool housekeeping_enabled(enum hk_type type); extern void housekeeping_affine(struct task_struct *t, enum hk_type type); extern bool housekeeping_test_cpu(int cpu, enum hk_type type); -extern int housekeeping_update(struct cpumask *isol_mask); +extern int housekeeping_update(struct cpumask *isol_mask, unsigned long fl= ags); extern void __init housekeeping_init(void); =20 #else diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 1335e437098e..a4eccb0ec0d1 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -1354,7 +1354,7 @@ static void cpuset_update_sd_hk_unlock(void) */ mutex_unlock(&cpuset_mutex); cpus_read_unlock(); - WARN_ON_ONCE(housekeeping_update(isolated_hk_cpus)); + WARN_ON_ONCE(housekeeping_update(isolated_hk_cpus, BIT(HK_TYPE_DOMAIN))); mutex_unlock(&cpuset_top_mutex); } else { cpuset_full_unlock(); diff --git a/kernel/sched/isolation.c b/kernel/sched/isolation.c index 9ec9ae510dc7..965d6f8fe344 100644 --- a/kernel/sched/isolation.c +++ b/kernel/sched/isolation.c @@ -120,48 +120,87 @@ bool housekeeping_test_cpu(int cpu, enum hk_type type) } EXPORT_SYMBOL_GPL(housekeeping_test_cpu); =20 -int housekeeping_update(struct cpumask *isol_mask) -{ - struct cpumask *trial, *old =3D NULL; - int err; +/* HK type processing table */ +static struct { + int type; + int boot_type; +} hk_types[] =3D { + { HK_TYPE_DOMAIN, HK_TYPE_DOMAIN_BOOT }, + { HK_TYPE_MANAGED_IRQ, HK_TYPE_MANAGED_IRQ_BOOT }, + { HK_TYPE_KERNEL_NOISE, HK_TYPE_KERNEL_NOISE_BOOT } +}; =20 - trial =3D kmalloc(cpumask_size(), GFP_KERNEL); - if (!trial) - return -ENOMEM; +#define HK_TYPE_CNT ARRAY_SIZE(hk_types) =20 - cpumask_andnot(trial, housekeeping_cpumask(HK_TYPE_DOMAIN_BOOT), isol_mas= k); - if (!cpumask_intersects(trial, cpu_online_mask)) { - kfree(trial); - return -EINVAL; +int housekeeping_update(struct cpumask *isol_mask, unsigned long flags) +{ + struct cpumask *trial[HK_TYPE_CNT]; + int i, err =3D 0; + + for (i =3D 0; i < HK_TYPE_CNT; i++) { + int type =3D hk_types[i].type; + int boot =3D hk_types[i].boot_type; + + trial[i] =3D NULL; + if (flags & BIT(type)) { + trial[i] =3D kmalloc(cpumask_size(), GFP_KERNEL); + if (!trial[i]) { + err =3D -ENOMEM; + goto out; + } + /* + * The new HK cpumask must be a subset of its boot + * cpumask. + */ + cpumask_andnot(trial[i], cpu_possible_mask, isol_mask); + if (!cpumask_intersects(trial[i], cpu_online_mask) || + !cpumask_subset(trial[i], housekeeping_cpumask(boot))) { + i++; + err =3D -EINVAL; + goto out; + } + } } =20 if (!housekeeping.flags) static_branch_enable(&housekeeping_overridden); =20 - if (housekeeping.flags & HK_FLAG_DOMAIN) - old =3D housekeeping_cpumask_dereference(HK_TYPE_DOMAIN); - else - WRITE_ONCE(housekeeping.flags, housekeeping.flags | HK_FLAG_DOMAIN); - rcu_assign_pointer(housekeeping.cpumasks[HK_TYPE_DOMAIN], trial); - - synchronize_rcu(); - - pci_probe_flush_workqueue(); - mem_cgroup_flush_workqueue(); - vmstat_flush_workqueue(); + for (i =3D 0; i < HK_TYPE_CNT; i++) { + int type =3D hk_types[i].type; + struct cpumask *old; =20 - err =3D workqueue_unbound_housekeeping_update(housekeeping_cpumask(HK_TYP= E_DOMAIN)); - WARN_ON_ONCE(err < 0); + if (!trial[i]) + continue; + old =3D NULL; + if (housekeeping.flags & BIT(type)) + old =3D housekeeping_cpumask_dereference(type); + rcu_assign_pointer(housekeeping.cpumasks[type], trial[i]); + trial[i] =3D old; + } =20 - err =3D tmigr_isolated_exclude_cpumask(isol_mask); - WARN_ON_ONCE(err < 0); + if ((housekeeping.flags & flags) !=3D flags) + WRITE_ONCE(housekeeping.flags, housekeeping.flags | flags); =20 - err =3D kthreads_update_housekeeping(); - WARN_ON_ONCE(err < 0); + synchronize_rcu(); =20 - kfree(old); + if (flags & HK_FLAG_DOMAIN) { + /* + * HK_TYPE_DOMAIN specific callbacks + */ + pci_probe_flush_workqueue(); + mem_cgroup_flush_workqueue(); + vmstat_flush_workqueue(); + + WARN_ON_ONCE(workqueue_unbound_housekeeping_update( + housekeeping_cpumask(HK_TYPE_DOMAIN)) < 0); + WARN_ON_ONCE(tmigr_isolated_exclude_cpumask(isol_mask) < 0); + WARN_ON_ONCE(kthreads_update_housekeeping() < 0); + } =20 - return 0; +out: + while (--i >=3D 0) + kfree(trial[i]); + return err; } =20 void __init housekeeping_init(void) --=20 2.53.0 From nobody Tue Jun 16 20:36:47 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E0A9B364045 for ; Tue, 21 Apr 2026 03:05:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776740729; cv=none; b=f4PZ0HIkBDwPe/t93I+5WM/enORJZEir+l9wt9IBIrz/g8HaDBvJWN+o/bwKXnkH9MhxyjxTenqkZJkcVQ+AEAoFfcFhKyL14Fsp+XZYRfp6pLRvqkbU+EPG53C4oOcUuCIteUxfi0Phoo0BI/baJwmGRbmFjCfQUl9UBci6oOw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776740729; c=relaxed/simple; bh=hqObzbSQGEeAd7/YyUO8I2dq8I5WxHIwNaMjXklxMws=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Cvl/ibPnps2Tx69TAyy+/cEXkN9Ok9QDrZYA+SUdz/1GRFUnvlKrtzsTeXcy5GWNHy2YYsK7fO453E5E8/gaU8dZBoFtA40shuUKncCItWp3DnM05G4Gu+IkxJ7P33Kbd1K8mP+GUQf/0szwgLaA++xAoNdtR3aEAGKpS2e4DvM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=cbd/XcDq; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="cbd/XcDq" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776740727; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kgcYIn++c2e0e5rWh9wDxm2bDr9HTUBWeCOEDxOtpq8=; b=cbd/XcDqO8FVl2Y8WBjvAQmquzOHree3wXt6XtEshYv/y70adRkHZ7M1UgfskcvEaPhpSc zJ0DP/uz6Z35gJ9loG1xESUwlaCB3J+FPveCS3gT3VERL3pyCntZeNOReEfb4qYtO5tFLP fy7cNYmO2twF0mQTu3BM7huRt3AEEPg= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-353-mmfyWDemMNW9Ib7eyF-ndg-1; Mon, 20 Apr 2026 23:05:22 -0400 X-MC-Unique: mmfyWDemMNW9Ib7eyF-ndg-1 X-Mimecast-MFC-AGG-ID: mmfyWDemMNW9Ib7eyF-ndg_1776740717 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 17D231955F18; Tue, 21 Apr 2026 03:05:16 +0000 (UTC) Received: from llong-thinkpadp16vgen1.westford.csb (unknown [10.22.65.81]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D59E119560B7; Tue, 21 Apr 2026 03:05:07 +0000 (UTC) From: Waiman Long To: Tejun Heo , Johannes Weiner , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Jonathan Corbet , Shuah Khan , Catalin Marinas , Will Deacon , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li , Guenter Roeck , Frederic Weisbecker , "Paul E. McKenney" , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Boqun Feng , Uladzislau Rezki , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Zqiang , Anna-Maria Behnsen , Ingo Molnar , Thomas Gleixner , Chen Ridong , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-hwmon@vger.kernel.org, rcu@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Costa Shulyupin , Qiliang Yuan , Waiman Long Subject: [PATCH 03/23] tick/nohz: Make nohz_full parameter optional Date: Mon, 20 Apr 2026 23:03:31 -0400 Message-ID: <20260421030351.281436-4-longman@redhat.com> In-Reply-To: <20260421030351.281436-1-longman@redhat.com> References: <20260421030351.281436-1-longman@redhat.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 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" To provide nohz_full tick support, there is a set of tick dependency masks that need to be evaluated on every IRQ and context switch. Switching on nohz_full tick support at runtime will be problematic as some of the tick dependency masks may not be properly set causing problem down the road. Allow nohz_full boot option to be specified without any parameter to force enable nohz_full tick support without any CPU in the tick_nohz_full_mask yet. The context_tracking_key and tick_nohz_full_running flag will be enabled in this case to make tick_nohz_full_enabled() return true. There is still a small performance overhead by force enable nohz_full this way. So it should only be used if there is a chance that some CPUs may become isolated later via the cpuset isolated partition functionality and better CPU isolation closed to nohz_full is desired. Signed-off-by: Waiman Long --- Documentation/admin-guide/kernel-parameters.txt | 15 +++++++++------ include/linux/context_tracking.h | 7 ++++++- kernel/context_tracking.c | 4 +++- kernel/rcu/tree_nocb.h | 2 +- kernel/sched/isolation.c | 13 ++++++++++++- kernel/time/tick-sched.c | 11 +++++++++-- 6 files changed, 40 insertions(+), 12 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentatio= n/admin-guide/kernel-parameters.txt index 95f97ce487a4..f0eedaebe9d6 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -4550,13 +4550,16 @@ Kernel parameters Valid arguments: on, off Default: on =20 - nohz_full=3D [KNL,BOOT,SMP,ISOL] - The argument is a cpu list, as described above. + nohz_full[=3Dcpu-list] + [KNL,BOOT,SMP,ISOL] In kernels built with CONFIG_NO_HZ_FULL=3Dy, set - the specified list of CPUs whose tick will be stopped - whenever possible. The boot CPU will be forced outside - the range to maintain the timekeeping. Any CPUs - in this list will have their RCU callbacks offloaded, + the specified list of CPUs whose tick will be + stopped whenever possible. If the argument is + not specified, nohz_full will be forced enabled + without any CPU in the nohz_full list yet. + The boot CPU will be forced outside the range + to maintain the timekeeping. Any CPUs in this + list will have their RCU callbacks offloaded, just as if they had also been called out in the rcu_nocbs=3D boot parameter. =20 diff --git a/include/linux/context_tracking.h b/include/linux/context_track= ing.h index af9fe87a0922..a3fea7f9fef6 100644 --- a/include/linux/context_tracking.h +++ b/include/linux/context_tracking.h @@ -9,8 +9,13 @@ =20 #include =20 - #ifdef CONFIG_CONTEXT_TRACKING_USER +/* + * Pass CONTEXT_TRACKING_FORCE_ENABLE to ct_cpu_track_user() to force enab= le + * user context tracking. + */ +#define CONTEXT_TRACKING_FORCE_ENABLE (-1) + extern void ct_cpu_track_user(int cpu); =20 /* Called with interrupts disabled. */ diff --git a/kernel/context_tracking.c b/kernel/context_tracking.c index a743e7ffa6c0..925999de1a28 100644 --- a/kernel/context_tracking.c +++ b/kernel/context_tracking.c @@ -678,7 +678,9 @@ void __init ct_cpu_track_user(int cpu) { static __initdata bool initialized =3D false; =20 - if (!per_cpu(context_tracking.active, cpu)) { + if (cpu =3D=3D CONTEXT_TRACKING_FORCE_ENABLE) { + static_branch_inc(&context_tracking_key); + } else if (!per_cpu(context_tracking.active, cpu)) { per_cpu(context_tracking.active, cpu) =3D true; static_branch_inc(&context_tracking_key); } diff --git a/kernel/rcu/tree_nocb.h b/kernel/rcu/tree_nocb.h index b3337c7231cc..2d06dcb61f37 100644 --- a/kernel/rcu/tree_nocb.h +++ b/kernel/rcu/tree_nocb.h @@ -1267,7 +1267,7 @@ void __init rcu_init_nohz(void) struct shrinker * __maybe_unused lazy_rcu_shrinker; =20 #if defined(CONFIG_NO_HZ_FULL) - if (tick_nohz_full_running && !cpumask_empty(tick_nohz_full_mask)) + if (tick_nohz_full_running) cpumask =3D tick_nohz_full_mask; #endif =20 diff --git a/kernel/sched/isolation.c b/kernel/sched/isolation.c index 965d6f8fe344..c233d55a1e95 100644 --- a/kernel/sched/isolation.c +++ b/kernel/sched/isolation.c @@ -268,6 +268,7 @@ static int __init housekeeping_setup(char *str, unsigne= d long flags) } =20 alloc_bootmem_cpumask_var(&non_housekeeping_mask); + if (cpulist_parse(str, non_housekeeping_mask) < 0) { pr_warn("Housekeeping: nohz_full=3D or isolcpus=3D incorrect CPU range\n= "); goto free_non_housekeeping_mask; @@ -277,6 +278,13 @@ static int __init housekeeping_setup(char *str, unsign= ed long flags) cpumask_andnot(housekeeping_staging, cpu_possible_mask, non_housekeeping_mask); =20 + /* + * Allow "nohz_full" without parameter to force enable nohz_full + * at boot time without any CPUs in the nohz_full list yet. + */ + if ((flags & HK_FLAG_KERNEL_NOISE) && !*str) + goto setup_housekeeping_staging; + first_cpu =3D cpumask_first_and(cpu_present_mask, housekeeping_staging); if (first_cpu >=3D nr_cpu_ids || first_cpu >=3D setup_max_cpus) { __cpumask_set_cpu(smp_processor_id(), housekeeping_staging); @@ -290,6 +298,7 @@ static int __init housekeeping_setup(char *str, unsigne= d long flags) if (cpumask_empty(non_housekeeping_mask)) goto free_housekeeping_staging; =20 +setup_housekeeping_staging: if (!housekeeping.flags) { /* First setup call ("nohz_full=3D" or "isolcpus=3D") */ enum hk_type type; @@ -357,10 +366,12 @@ static int __init housekeeping_nohz_full_setup(char *= str) unsigned long flags; =20 flags =3D HK_FLAG_KERNEL_NOISE | HK_FLAG_KERNEL_NOISE_BOOT; + if (*str =3D=3D '=3D') + str++; =20 return housekeeping_setup(str, flags); } -__setup("nohz_full=3D", housekeeping_nohz_full_setup); +__setup("nohz_full", housekeeping_nohz_full_setup); =20 static int __init housekeeping_isolcpus_setup(char *str) { diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index 9e5264458414..ed877b2c9040 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -676,8 +676,15 @@ void __init tick_nohz_init(void) } } =20 - for_each_cpu(cpu, tick_nohz_full_mask) - ct_cpu_track_user(cpu); + /* + * Force enable context_tracking_key if tick_nohz_full_mask empty + */ + if (cpumask_empty(tick_nohz_full_mask)) { + ct_cpu_track_user(CONTEXT_TRACKING_FORCE_ENABLE); + } else { + for_each_cpu(cpu, tick_nohz_full_mask) + ct_cpu_track_user(cpu); + } =20 ret =3D cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, "kernel/nohz:predown", NULL, --=20 2.53.0 From nobody Tue Jun 16 20:36:47 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ED4F3366075 for ; Tue, 21 Apr 2026 03:05:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776740734; cv=none; b=WW/z4ureMh/75Yux7AABIkXSntCGqeB6E6d1t3CC5oLtkju+4hEKi1W9aDHifcIy2jjjf6UZDp/PyOycieMDkhiHnQkTJ1TyiqKtpAw9I+TQAsxRJ180/JcWG9oJEeH3b1eIANxh7ertTEVrInyqG5naR1ZvsQhPjXP321TUBm0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776740734; c=relaxed/simple; bh=AAudttYRisFlY5Ez9Un7A1GLFdgmsNoB8kueTD7e+vk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=N3GNQgn2arDXVatiLZXUiSeCWGkZeNjE1Vp2zf6WoijOKe3gOYHV3F781V3JZ3qL1fkPW2hVY+P7mJRtzSo7ka7B0EKV6ARtVoXYr1iqlmC3cGzNfpyuDqP3rdVopR+ZtSx7bXRW5j4WjS56EDwDv0W5Wemb0MxrG8fF5v+nAQQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=NfEXrYXu; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="NfEXrYXu" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776740732; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cQwM3QXUNwSlfxVNwPQNRKjpWMNQLGduAjCpqdPCyps=; b=NfEXrYXu/CGd5DLSW/Ys9KNlymRiebUpqbfT9fMghg0CNq2px84lSZZO5YFXUIpGPCZc4k /qj9DrXdlLv2EsunBZkRsi2BhhpHrNrjlv1EiMYAbNVjCfJamJfo9iWwms0VRZboDJOTL5 bIqho1jY/zkAoNnS9obMsCEOkkt86Z4= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-122-J0hBtGLTO-KlPDV8avLGEg-1; Mon, 20 Apr 2026 23:05:29 -0400 X-MC-Unique: J0hBtGLTO-KlPDV8avLGEg-1 X-Mimecast-MFC-AGG-ID: J0hBtGLTO-KlPDV8avLGEg_1776740725 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0D69719560B4; Tue, 21 Apr 2026 03:05:24 +0000 (UTC) Received: from llong-thinkpadp16vgen1.westford.csb (unknown [10.22.65.81]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 384F31955F21; Tue, 21 Apr 2026 03:05:16 +0000 (UTC) From: Waiman Long To: Tejun Heo , Johannes Weiner , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Jonathan Corbet , Shuah Khan , Catalin Marinas , Will Deacon , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li , Guenter Roeck , Frederic Weisbecker , "Paul E. McKenney" , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Boqun Feng , Uladzislau Rezki , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Zqiang , Anna-Maria Behnsen , Ingo Molnar , Thomas Gleixner , Chen Ridong , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-hwmon@vger.kernel.org, rcu@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Costa Shulyupin , Qiliang Yuan , Waiman Long Subject: [PATCH 04/23] tick/nohz: Allow runtime changes in full dynticks CPUs Date: Mon, 20 Apr 2026 23:03:32 -0400 Message-ID: <20260421030351.281436-5-longman@redhat.com> In-Reply-To: <20260421030351.281436-1-longman@redhat.com> References: <20260421030351.281436-1-longman@redhat.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 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" Full dynticks can only be enabled if "nohz_full" boot option has been been specified with or without parameter. Any change in the list of nohz_full CPUs have to be reflected in tick_nohz_full_mask. Introduce a new tick_nohz_full_update_cpus() helper that can be called to update the tick_nohz_full_mask at run time. The housekeeping_update() function is modified to call the new helper when the HK_TYPE_KERNEL_NOSIE cpumask is going to be changed. We also need to enable CPU context tracking for those CPUs that are in tick_nohz_full_mask. So remove __init from tick_nohz_init() and ct_cpu_track_user() so that they be called later when an isolated cpuset partition is being created. The __ro_after_init attribute is taken away from context_tracking_key as well. Also add a new ct_cpu_untrack_user() function to reverse the action of ct_cpu_track_user() in case we need to disable the nohz_full mode of a CPU. With nohz_full enabled, the boot CPU (typically CPU 0) will be the tick CPU which cannot be shut down easily. So the boot CPU should not be used in an isolated cpuset partition. With runtime modification of nohz_full CPUs, tick_do_timer_cpu can become TICK_DO_TIMER_NONE. So remove the two TICK_DO_TIMER_NONE WARN_ON_ONCE() checks in tick-sched.c to avoid unnecessary warnings. Signed-off-by: Waiman Long --- include/linux/context_tracking.h | 1 + include/linux/tick.h | 2 ++ kernel/context_tracking.c | 15 ++++++++++--- kernel/sched/isolation.c | 3 +++ kernel/time/tick-sched.c | 37 ++++++++++++++++++++++++++------ 5 files changed, 48 insertions(+), 10 deletions(-) diff --git a/include/linux/context_tracking.h b/include/linux/context_track= ing.h index a3fea7f9fef6..1a6b816f1ad6 100644 --- a/include/linux/context_tracking.h +++ b/include/linux/context_tracking.h @@ -17,6 +17,7 @@ #define CONTEXT_TRACKING_FORCE_ENABLE (-1) =20 extern void ct_cpu_track_user(int cpu); +extern void ct_cpu_untrack_user(int cpu); =20 /* Called with interrupts disabled. */ extern void __ct_user_enter(enum ctx_state state); diff --git a/include/linux/tick.h b/include/linux/tick.h index 738007d6f577..05586f14461c 100644 --- a/include/linux/tick.h +++ b/include/linux/tick.h @@ -274,6 +274,7 @@ static inline void tick_dep_clear_signal(struct signal_= struct *signal, extern void tick_nohz_full_kick_cpu(int cpu); extern void __tick_nohz_task_switch(void); extern void __init tick_nohz_full_setup(cpumask_var_t cpumask); +extern void tick_nohz_full_update_cpus(struct cpumask *cpumask); #else static inline bool tick_nohz_full_enabled(void) { return false; } static inline bool tick_nohz_full_cpu(int cpu) { return false; } @@ -299,6 +300,7 @@ static inline void tick_dep_clear_signal(struct signal_= struct *signal, static inline void tick_nohz_full_kick_cpu(int cpu) { } static inline void __tick_nohz_task_switch(void) { } static inline void tick_nohz_full_setup(cpumask_var_t cpumask) { } +static inline void tick_nohz_full_update_cpus(struct cpumask *cpumask) { } #endif =20 static inline void tick_nohz_task_switch(void) diff --git a/kernel/context_tracking.c b/kernel/context_tracking.c index 925999de1a28..394e432630a3 100644 --- a/kernel/context_tracking.c +++ b/kernel/context_tracking.c @@ -411,7 +411,7 @@ static __always_inline void ct_kernel_enter(bool user, = int offset) { } #define CREATE_TRACE_POINTS #include =20 -DEFINE_STATIC_KEY_FALSE_RO(context_tracking_key); +DEFINE_STATIC_KEY_FALSE(context_tracking_key); EXPORT_SYMBOL_GPL(context_tracking_key); =20 static noinstr bool context_tracking_recursion_enter(void) @@ -674,9 +674,9 @@ void user_exit_callable(void) } NOKPROBE_SYMBOL(user_exit_callable); =20 -void __init ct_cpu_track_user(int cpu) +void ct_cpu_track_user(int cpu) { - static __initdata bool initialized =3D false; + static bool initialized; =20 if (cpu =3D=3D CONTEXT_TRACKING_FORCE_ENABLE) { static_branch_inc(&context_tracking_key); @@ -700,6 +700,15 @@ void __init ct_cpu_track_user(int cpu) initialized =3D true; } =20 +void ct_cpu_untrack_user(int cpu) +{ + if (!per_cpu(context_tracking.active, cpu)) + return; + + per_cpu(context_tracking.active, cpu) =3D false; + static_branch_dec(&context_tracking_key); +} + #ifdef CONFIG_CONTEXT_TRACKING_USER_FORCE void __init context_tracking_init(void) { diff --git a/kernel/sched/isolation.c b/kernel/sched/isolation.c index c233d55a1e95..48b155e0b290 100644 --- a/kernel/sched/isolation.c +++ b/kernel/sched/isolation.c @@ -181,6 +181,9 @@ int housekeeping_update(struct cpumask *isol_mask, unsi= gned long flags) if ((housekeeping.flags & flags) !=3D flags) WRITE_ONCE(housekeeping.flags, housekeeping.flags | flags); =20 + if (flags & HK_FLAG_KERNEL_NOISE) + tick_nohz_full_update_cpus(isol_mask); + synchronize_rcu(); =20 if (flags & HK_FLAG_DOMAIN) { diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index ed877b2c9040..7baa757ca45f 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -241,9 +241,6 @@ static void tick_sched_do_timer(struct tick_sched *ts, = ktime_t now) tick_cpu =3D READ_ONCE(tick_do_timer_cpu); =20 if (IS_ENABLED(CONFIG_NO_HZ_COMMON) && unlikely(tick_cpu =3D=3D TICK_DO_T= IMER_NONE)) { -#ifdef CONFIG_NO_HZ_FULL - WARN_ON_ONCE(tick_nohz_full_running); -#endif WRITE_ONCE(tick_do_timer_cpu, cpu); tick_cpu =3D cpu; } @@ -629,6 +626,36 @@ void __init tick_nohz_full_setup(cpumask_var_t cpumask) tick_nohz_full_running =3D true; } =20 +/* Get the new set of run-time nohz CPU list & update accordingly */ +void tick_nohz_full_update_cpus(struct cpumask *cpumask) +{ + int cpu; + + if (!tick_nohz_full_running) { + pr_warn_once("Full dynticks cannot be enabled without the nohz_full kern= el boot parameter!\n"); + return; + } + + /* + * To properly enable/disable nohz_full dynticks for the affected CPUs, + * the new nohz_full CPUs have to be copied to tick_nohz_full_mask and + * ct_cpu_track_user/ct_cpu_untrack_user() will have to be called + * for those CPUs that have their states changed. Those CPUs should be + * in an offline state. + */ + for_each_cpu_andnot(cpu, cpumask, tick_nohz_full_mask) { + WARN_ON_ONCE(cpu_online(cpu)); + ct_cpu_track_user(cpu); + cpumask_set_cpu(cpu, tick_nohz_full_mask); + } + + for_each_cpu_andnot(cpu, tick_nohz_full_mask, cpumask) { + WARN_ON_ONCE(cpu_online(cpu)); + ct_cpu_untrack_user(cpu); + cpumask_clear_cpu(cpu, tick_nohz_full_mask); + } +} + bool tick_nohz_cpu_hotpluggable(unsigned int cpu) { /* @@ -1238,10 +1265,6 @@ static bool can_stop_idle_tick(int cpu, struct tick_= sched *ts) */ if (tick_cpu =3D=3D cpu) return false; - - /* Should not happen for nohz-full */ - if (WARN_ON_ONCE(tick_cpu =3D=3D TICK_DO_TIMER_NONE)) - return false; } =20 return true; --=20 2.53.0 From nobody Tue Jun 16 20:36:47 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2C74F364045 for ; Tue, 21 Apr 2026 03:05:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776740742; cv=none; b=pRaUi18dGDGuooGUNhIAfCHgHbEmdVac3Fh9a6vJiBpiF0iQtPMpLQfCFIvyvgXgIT7fiIWSLCdjZ7lEsMUP8IP9m33A+sE7tTxmd0IAXV/y1I+ijl6/V1DCFsSi03mA/HahsS8BEJQ85afOJO05l1xcqv4R0bxNZL+wUp2rqQw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776740742; c=relaxed/simple; bh=1a0p9+mSm7V86W1Fk085amvC7d0rMa8bbbudBvOyyns=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mx3LF5sobxtJr1cqe0Ru1sKoVSdWBn9niHyL04XlnQQLOMj/K/ROCW9VzROD2nNdegRYGBN2wkv02eoYHQP1kiEsa46PTKV9X820LQYrYZmcH0dG5T8BVu+w/1s+LRvbYKP22FY71EntyugFVDfVCAG4NINEsxAqIf3gp+A/gP4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=OSNwVAhk; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="OSNwVAhk" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776740740; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CvxrjlgvnWjaqR0yDbbq75WXz4VuqzuFoTUCXieYzlk=; b=OSNwVAhkR2RFHBRBjQOFz+v0L3cv8/dTa/gHDR2NJJ8PN1ZIcJ8I4hR6ftI+uHR+8radik X49ZprmZMfJJQlfcKYQ/lHCyTFJs5d3bnZDL7r2n5R2fWVMmO1rCFIUZ1IiMmNitIshCdS zIdgjiiHbEyPN6QLlueufHKpN0dk1dA= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-116-yuc8Te4wOrS43YrXrrHjqw-1; Mon, 20 Apr 2026 23:05:36 -0400 X-MC-Unique: yuc8Te4wOrS43YrXrrHjqw-1 X-Mimecast-MFC-AGG-ID: yuc8Te4wOrS43YrXrrHjqw_1776740731 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9730E1800352; Tue, 21 Apr 2026 03:05:31 +0000 (UTC) Received: from llong-thinkpadp16vgen1.westford.csb (unknown [10.22.65.81]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4466C19560B7; Tue, 21 Apr 2026 03:05:24 +0000 (UTC) From: Waiman Long To: Tejun Heo , Johannes Weiner , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Jonathan Corbet , Shuah Khan , Catalin Marinas , Will Deacon , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li , Guenter Roeck , Frederic Weisbecker , "Paul E. McKenney" , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Boqun Feng , Uladzislau Rezki , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Zqiang , Anna-Maria Behnsen , Ingo Molnar , Thomas Gleixner , Chen Ridong , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-hwmon@vger.kernel.org, rcu@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Costa Shulyupin , Qiliang Yuan , Waiman Long Subject: [PATCH 05/23] tick: Pass timer tick job to an online HK CPU in tick_cpu_dying() Date: Mon, 20 Apr 2026 23:03:33 -0400 Message-ID: <20260421030351.281436-6-longman@redhat.com> In-Reply-To: <20260421030351.281436-1-longman@redhat.com> References: <20260421030351.281436-1-longman@redhat.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 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" In tick_cpu_dying(), if the dying CPU is the current timekeeper, it has to pass the job over to another CPU. The current code passes it to another online CPU. However, that CPU may not be a timer tick housekeeping CPU. If that happens, another CPU will have to manually take it over again later. Avoid this unnecessary work by directly assigning an online housekeeping CPU. Use READ_ONCE/WRITE_ONCE() to access tick_do_timer_cpu in case the non-HK CPUs may not be in stop machine in the future. Signed-off-by: Waiman Long --- kernel/time/tick-common.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/kernel/time/tick-common.c b/kernel/time/tick-common.c index d305d8521896..4834a1b9044b 100644 --- a/kernel/time/tick-common.c +++ b/kernel/time/tick-common.c @@ -17,6 +17,7 @@ #include #include #include +#include #include =20 #include @@ -394,12 +395,19 @@ int tick_cpu_dying(unsigned int dying_cpu) { /* * If the current CPU is the timekeeper, it's the only one that can - * safely hand over its duty. Also all online CPUs are in stop - * machine, guaranteed not to be idle, therefore there is no + * safely hand over its duty. Also all online housekeeping CPUs are + * in stop machine, guaranteed not to be idle, therefore there is no * concurrency and it's safe to pick any online successor. */ - if (tick_do_timer_cpu =3D=3D dying_cpu) - tick_do_timer_cpu =3D cpumask_first(cpu_online_mask); + if (READ_ONCE(tick_do_timer_cpu) =3D=3D dying_cpu) { + unsigned int new_cpu; + + guard(rcu)(); + new_cpu =3D cpumask_first_and(cpu_online_mask, housekeeping_cpumask(HK_T= YPE_TICK)); + if (WARN_ON_ONCE(new_cpu >=3D nr_cpu_ids)) + new_cpu =3D cpumask_first(cpu_online_mask); + WRITE_ONCE(tick_do_timer_cpu, new_cpu); + } =20 /* Make sure the CPU won't try to retake the timekeeping duty */ tick_sched_timer_dying(dying_cpu); --=20 2.53.0 From nobody Tue Jun 16 20:36:47 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 600E1366054 for ; Tue, 21 Apr 2026 03:05:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776740748; cv=none; b=khGp36igL4EVxtN0X+KwmOEODscZ8QPrxFwbqHo5Sey0dv6qFO44iorQZ/gWncQtze4d/1jQCE2XtjMuGtF4EQLb/x5d9JdBAS6vG8VVW2t4fmLOqE0Wd1MIym/zZ4dhCGm7CbopGIHTqo98amZEBFHgCfmJP4vUSqyTocDXjZ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776740748; c=relaxed/simple; bh=rOGBf0wYekJdoD4SBA74vbDVOqUx1Wsq4aN0zXB95Dk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ib2i6fj0lkiX5lpS4+U3cqYX02y4U3PRFoJbs0gCgJOGuGRgOajUhgXxtat2EiqaxzRW1z03fP9qqXELumxvVFgXpOq50U0rvzYSJIdvD5DoQxvQ5+j/Yfd+RsB5y94OVPu9hjqaU3jkTxuKqU7xIPdMFAaUp3AZXfCtPebtP1Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=a7vsmOq7; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="a7vsmOq7" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776740746; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7VstpRTEn9ptpP1VmY9IUyGFYY+MvC6/GBVaS0P0YxY=; b=a7vsmOq7OpAeEcuM3kif8QL34XqX//jr8J0yJQFZEZlYbRlnlMKCn90iA0k7jvDgnSpyk/ FiPeCRHrfDp9p1Kn0L6sz4Z04OHmbITCAiAIsnZkkdhlgdFrK0pPndoor3djChHLOsLnnV 0Giev1QgiEjzpZbwQl468zKs1v4bvrA= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-304-wfxxcSTJNc2iOwvbuYVEbw-1; Mon, 20 Apr 2026 23:05:44 -0400 X-MC-Unique: wfxxcSTJNc2iOwvbuYVEbw-1 X-Mimecast-MFC-AGG-ID: wfxxcSTJNc2iOwvbuYVEbw_1776740740 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DEEC219560BC; Tue, 21 Apr 2026 03:05:38 +0000 (UTC) Received: from llong-thinkpadp16vgen1.westford.csb (unknown [10.22.65.81]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CECEB19560AB; Tue, 21 Apr 2026 03:05:31 +0000 (UTC) From: Waiman Long To: Tejun Heo , Johannes Weiner , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Jonathan Corbet , Shuah Khan , Catalin Marinas , Will Deacon , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li , Guenter Roeck , Frederic Weisbecker , "Paul E. McKenney" , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Boqun Feng , Uladzislau Rezki , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Zqiang , Anna-Maria Behnsen , Ingo Molnar , Thomas Gleixner , Chen Ridong , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-hwmon@vger.kernel.org, rcu@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Costa Shulyupin , Qiliang Yuan , Waiman Long Subject: [PATCH 06/23] rcu/nocbs: Allow runtime changes in RCU NOCBS cpumask Date: Mon, 20 Apr 2026 23:03:34 -0400 Message-ID: <20260421030351.281436-7-longman@redhat.com> In-Reply-To: <20260421030351.281436-1-longman@redhat.com> References: <20260421030351.281436-1-longman@redhat.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 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" We can make use of the rcu_nocb_cpu_offload()/rcu_nocb_cpu_deoffload() APIs to enable RCU NO-CB CPU offloading of newly isolated CPUs and deoffloading of de-isolated CPUs. Add a new rcu_nocb_update_cpus() helper to do that and call it directly from housekeeping_update() when the HK_TYPE_KERNEL_NOISE cpumask is being changed. This dynamic RCU NO-CB CPU offloading feature can only used if either "rcs_nocbs" or the "nohz_full" boot command parameters are used with or without parameter so that the proper RCU NO-CB resources are properly initialized at boot time. Signed-off-by: Waiman Long --- include/linux/rcupdate.h | 2 ++ kernel/rcu/tree_nocb.h | 22 ++++++++++++++++++++++ kernel/sched/isolation.c | 4 +++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h index 04f3f86a4145..987e3d1d413e 100644 --- a/include/linux/rcupdate.h +++ b/include/linux/rcupdate.h @@ -150,6 +150,7 @@ void rcu_init_nohz(void); int rcu_nocb_cpu_offload(int cpu); int rcu_nocb_cpu_deoffload(int cpu); void rcu_nocb_flush_deferred_wakeup(void); +void rcu_nocb_update_cpus(struct cpumask *cpumask); =20 #define RCU_NOCB_LOCKDEP_WARN(c, s) RCU_LOCKDEP_WARN(c, s) =20 @@ -159,6 +160,7 @@ static inline void rcu_init_nohz(void) { } static inline int rcu_nocb_cpu_offload(int cpu) { return -EINVAL; } static inline int rcu_nocb_cpu_deoffload(int cpu) { return 0; } static inline void rcu_nocb_flush_deferred_wakeup(void) { } +static inline void rcu_nocb_update_cpus(struct cpumask *cpumask) { } =20 #define RCU_NOCB_LOCKDEP_WARN(c, s) =20 diff --git a/kernel/rcu/tree_nocb.h b/kernel/rcu/tree_nocb.h index 2d06dcb61f37..b2daba1e5cb9 100644 --- a/kernel/rcu/tree_nocb.h +++ b/kernel/rcu/tree_nocb.h @@ -1173,6 +1173,28 @@ int rcu_nocb_cpu_offload(int cpu) } EXPORT_SYMBOL_GPL(rcu_nocb_cpu_offload); =20 +void rcu_nocb_update_cpus(struct cpumask *cpumask) +{ + int cpu, ret; + + if (!rcu_state.nocb_is_setup) { + pr_warn_once("Dynamic RCU NOCB cannot be enabled without nohz_full/rcu_n= ocbs kernel boot parameter!\n"); + return; + } + + for_each_cpu_andnot(cpu, cpumask, rcu_nocb_mask) { + ret =3D rcu_nocb_cpu_offload(cpu); + if (WARN_ON_ONCE(ret)) + return; + } + + for_each_cpu_andnot(cpu, rcu_nocb_mask, cpumask) { + ret =3D rcu_nocb_cpu_deoffload(cpu); + if (WARN_ON_ONCE(ret)) + return; + } +} + #ifdef CONFIG_RCU_LAZY static unsigned long lazy_rcu_shrink_count(struct shrinker *shrink, struct shrink_control *sc) diff --git a/kernel/sched/isolation.c b/kernel/sched/isolation.c index 48b155e0b290..b5635484ec69 100644 --- a/kernel/sched/isolation.c +++ b/kernel/sched/isolation.c @@ -181,8 +181,10 @@ int housekeeping_update(struct cpumask *isol_mask, uns= igned long flags) if ((housekeeping.flags & flags) !=3D flags) WRITE_ONCE(housekeeping.flags, housekeeping.flags | flags); =20 - if (flags & HK_FLAG_KERNEL_NOISE) + if (flags & HK_FLAG_KERNEL_NOISE) { tick_nohz_full_update_cpus(isol_mask); + rcu_nocb_update_cpus(isol_mask); + } =20 synchronize_rcu(); =20 --=20 2.53.0 From nobody Tue Jun 16 20:36:47 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B70CA374737 for ; Tue, 21 Apr 2026 03:05:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776740760; cv=none; b=aVm2wIl79U8+ogISoJFTZuBDPKzUx4cqarFN8MaVMvb2yt6sLyzEFZo4mxlybUmwVYRguqLcSezxBiazsbELShrTwrZaTyJG3GuPL5L1p3rLTZPuWR8P09d6PXNdxXdfMd8LIXTNqSXVdHDMmCqRXLRfe5dpufi4fuETVEfYSbc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776740760; c=relaxed/simple; bh=6dOR9VvfHXSOAa+3ONfN9QOA7EaOHN44SvLAlIcSGZo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LdWFl6L6wPTPQzdDx99kXJTDibH4RaT/EfojetgApyyRQvFqxd6WRHuojmnn6zsb2l0/cUdyvzs/0UUXetSICAKgTEmeXXHI22Fg8TZ/m0/CagdaGZsimvHnDYimY6OXYdfyrPB++1cD8HkdWYcGasF+lfot3HOdYI5sGRZhPns= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=ALPnGfzY; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ALPnGfzY" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776740757; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iRnLiTFd5Q/8p4sCGe2o1EMdVAtDIxePLghGCtdhHc0=; b=ALPnGfzYiHL6RLkchoOZpSJ6BwP74FcSaccPPn7jSgoz0mTJVj4IbZqDK9I4S3FFow40bi oT+e/Jv4oKS5HD5jcF8OQQ6mgEu2AZOdjnCGzhvPxoKTyPtKD7q20mInDjSDH/9q25PvOF uS8IcoAEml6sEof8/hUzsXJtxIa6e9E= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-30-2NDOP3YyMf-mNL6wwN032w-1; Mon, 20 Apr 2026 23:05:51 -0400 X-MC-Unique: 2NDOP3YyMf-mNL6wwN032w-1 X-Mimecast-MFC-AGG-ID: 2NDOP3YyMf-mNL6wwN032w_1776740746 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7ACED19560AD; Tue, 21 Apr 2026 03:05:46 +0000 (UTC) Received: from llong-thinkpadp16vgen1.westford.csb (unknown [10.22.65.81]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2157519560B7; Tue, 21 Apr 2026 03:05:39 +0000 (UTC) From: Waiman Long To: Tejun Heo , Johannes Weiner , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Jonathan Corbet , Shuah Khan , Catalin Marinas , Will Deacon , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li , Guenter Roeck , Frederic Weisbecker , "Paul E. McKenney" , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Boqun Feng , Uladzislau Rezki , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Zqiang , Anna-Maria Behnsen , Ingo Molnar , Thomas Gleixner , Chen Ridong , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-hwmon@vger.kernel.org, rcu@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Costa Shulyupin , Qiliang Yuan , Waiman Long Subject: [PATCH 07/23] watchdog: Sync up with runtime change of isolated CPUs Date: Mon, 20 Apr 2026 23:03:35 -0400 Message-ID: <20260421030351.281436-8-longman@redhat.com> In-Reply-To: <20260421030351.281436-1-longman@redhat.com> References: <20260421030351.281436-1-longman@redhat.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 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" At bootup, watchdog will exclude nohz_full CPUs specified at boot time. As we are now enabling runtime changes to nohz_full CPUs, the list of CPUs with watchdog timer running should be updated to exclude the current set of isolated CPUs. Add a new watchdog_cpumask_update() helper to be invoked by housekeeping_update() when the HK_TYPE_KERNEL_NOISE (HK_TYPE_TIMER) cpumask is being updated to update watchdog_cpumask and watchdog_allowed_mask for soft lockup detector. The cpumask updates will be done when the affected CPUs are in the offline state. When those CPUs are brought up later, the new cpumask will be used to determine if any hard/soft watchdog should be enabled again. Signed-off-by: Waiman Long --- include/linux/nmi.h | 2 ++ kernel/sched/isolation.c | 1 + kernel/watchdog.c | 24 ++++++++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/include/linux/nmi.h b/include/linux/nmi.h index bc1162895f35..5bf941d2b168 100644 --- a/include/linux/nmi.h +++ b/include/linux/nmi.h @@ -17,6 +17,7 @@ void lockup_detector_init(void); void lockup_detector_retry_init(void); void lockup_detector_soft_poweroff(void); +void watchdog_cpumask_update(struct cpumask *mask); =20 extern int watchdog_user_enabled; extern int watchdog_thresh; @@ -37,6 +38,7 @@ extern int sysctl_hardlockup_all_cpu_backtrace; static inline void lockup_detector_init(void) { } static inline void lockup_detector_retry_init(void) { } static inline void lockup_detector_soft_poweroff(void) { } +static inline void watchdog_cpumask_update(struct cpumask *mask) { } #endif /* !CONFIG_LOCKUP_DETECTOR */ =20 #ifdef CONFIG_SOFTLOCKUP_DETECTOR diff --git a/kernel/sched/isolation.c b/kernel/sched/isolation.c index b5635484ec69..1f3f1c83dd12 100644 --- a/kernel/sched/isolation.c +++ b/kernel/sched/isolation.c @@ -184,6 +184,7 @@ int housekeeping_update(struct cpumask *isol_mask, unsi= gned long flags) if (flags & HK_FLAG_KERNEL_NOISE) { tick_nohz_full_update_cpus(isol_mask); rcu_nocb_update_cpus(isol_mask); + watchdog_cpumask_update(isol_mask); } =20 synchronize_rcu(); diff --git a/kernel/watchdog.c b/kernel/watchdog.c index 87dd5e0f6968..498c1463b843 100644 --- a/kernel/watchdog.c +++ b/kernel/watchdog.c @@ -1071,6 +1071,30 @@ static inline void lockup_detector_setup(void) } #endif /* !CONFIG_SOFTLOCKUP_DETECTOR */ =20 +/** + * watchdog_cpumask_update - update watchdog_cpumask & watchdog_allowed_ma= sk + * @isol_mask: cpumask of isolated CPUs + * + * Update watchdog_cpumask and watchdog_allowed_mask to be inverse of the + * given isolated cpumask to disable watchdog activities on isolated CPUs. + * It should be called with the affected CPUs in offline state which will = be + * brought up online later. + * + * Any changes made in watchdog_cpumask by users via the sysctl parameter = will + * be overridden. However, proc_watchdog_update() isn't called. So change = will + * only happens on CPUs that will brought up later on to minimize changes = to + * the existing watchdog configuration. + */ +void watchdog_cpumask_update(struct cpumask *isol_mask) +{ + mutex_lock(&watchdog_mutex); + cpumask_andnot(&watchdog_cpumask, cpu_possible_mask, isol_mask); +#ifdef CONFIG_SOFTLOCKUP_DETECTOR + cpumask_copy(&watchdog_allowed_mask, &watchdog_cpumask); +#endif + mutex_unlock(&watchdog_mutex); +} + /** * lockup_detector_soft_poweroff - Interface to stop lockup detector(s) * --=20 2.53.0 From nobody Tue Jun 16 20:36:48 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 14B4836AB6B for ; Tue, 21 Apr 2026 03:06:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776740765; cv=none; b=tGMfIFWyN42Qr1mfuSB20UZRgeeXCYQrCFytmPyQpTNv34L9fCuG0216X+9TyptXHbjd0fZzEeRSExRS3F5b2WYQMXvblDeZarcdxv5cdDwjLj/YwssrJFuWGgT8IHuQnJoVLw4EGE3nSqMDyvMV/LnrJOJVq92/1MfoutQKVzc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776740765; c=relaxed/simple; bh=TxL29QnTwq/820ZjxDXVDgXLQ2KjHnCopRJMsMKEbOE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ct2KJ09VQU1PX6VF13U1NsFtGEnBmkroF6v5vuWtfFjfXEHsBsWyH0YS2yaUYtlV271xXbOuLiTyZpKcV/3renNyw7W9ANKQMv10V7PGaVtdQBJgxK06TQbfGd91amVDNvuXwMDj+C2wARcZfKeiupkOF/lGWWM/p/pg6ofQMF0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=NPaDRmJC; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="NPaDRmJC" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776740763; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xLt3YbZO8LaJ7i/PL30alZF/tGSXpd8N0J3i5JY/BrE=; b=NPaDRmJCpHDIkw1ac01Dfbi8Pl/jqLl9PjjWiW8duRqpYHYuBd20b5JbeGS85CxCo900o2 XlQ29Yjx59YfOOeHL+B6pPWVoylBLGWCu+oq9GRp22TfsbUgG/mopsCIexZim8fecIkR5Q eLRDzz+S+xrlL17WIpgi5yVv4uLRJc0= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-302-OH2KDsxlO5S_BO4AkuvH1A-1; Mon, 20 Apr 2026 23:05:59 -0400 X-MC-Unique: OH2KDsxlO5S_BO4AkuvH1A-1 X-Mimecast-MFC-AGG-ID: OH2KDsxlO5S_BO4AkuvH1A_1776740754 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 091971800663; Tue, 21 Apr 2026 03:05:54 +0000 (UTC) Received: from llong-thinkpadp16vgen1.westford.csb (unknown [10.22.65.81]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B279A19560AB; Tue, 21 Apr 2026 03:05:46 +0000 (UTC) From: Waiman Long To: Tejun Heo , Johannes Weiner , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Jonathan Corbet , Shuah Khan , Catalin Marinas , Will Deacon , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li , Guenter Roeck , Frederic Weisbecker , "Paul E. McKenney" , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Boqun Feng , Uladzislau Rezki , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Zqiang , Anna-Maria Behnsen , Ingo Molnar , Thomas Gleixner , Chen Ridong , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-hwmon@vger.kernel.org, rcu@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Costa Shulyupin , Qiliang Yuan , Waiman Long Subject: [PATCH 08/23] arm64: topology: Use RCU to protect access to HK_TYPE_TICK cpumask Date: Mon, 20 Apr 2026 23:03:36 -0400 Message-ID: <20260421030351.281436-9-longman@redhat.com> In-Reply-To: <20260421030351.281436-1-longman@redhat.com> References: <20260421030351.281436-1-longman@redhat.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 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" As the HK_TYPE_TICK cpumask is going to be changeable at run time, we need to use RCU to protect access to the cpumask to prevent it from going away in the middle of the operation. Signed-off-by: Waiman Long --- arch/arm64/kernel/topology.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c index b32f13358fbb..48f150801689 100644 --- a/arch/arm64/kernel/topology.c +++ b/arch/arm64/kernel/topology.c @@ -173,6 +173,7 @@ void arch_cpu_idle_enter(void) if (!amu_fie_cpu_supported(cpu)) return; =20 + guard(rcu)(); /* Kick in AMU update but only if one has not happened already */ if (housekeeping_cpu(cpu, HK_TYPE_TICK) && time_is_before_jiffies(per_cpu(cpu_amu_samples.last_scale_update, cpu= ))) @@ -187,11 +188,16 @@ int arch_freq_get_on_cpu(int cpu) unsigned int start_cpu =3D cpu; unsigned long last_update; unsigned int freq =3D 0; + bool hk_cpu; u64 scale; =20 if (!amu_fie_cpu_supported(cpu) || !arch_scale_freq_ref(cpu)) return -EOPNOTSUPP; =20 + scoped_guard(rcu) { + hk_cpu =3D housekeeping_cpu(cpu, HK_TYPE_TICK); + } + while (1) { =20 amu_sample =3D per_cpu_ptr(&cpu_amu_samples, cpu); @@ -204,16 +210,21 @@ int arch_freq_get_on_cpu(int cpu) * (and thus freq scale), if available, for given policy: this boils * down to identifying an active cpu within the same freq domain, if any. */ - if (!housekeeping_cpu(cpu, HK_TYPE_TICK) || + if (!hk_cpu || time_is_before_jiffies(last_update + msecs_to_jiffies(AMU_SAMPLE_EXP= _MS))) { struct cpufreq_policy *policy =3D cpufreq_cpu_get(cpu); + bool hk_intersects; int ref_cpu; =20 if (!policy) return -EINVAL; =20 - if (!cpumask_intersects(policy->related_cpus, - housekeeping_cpumask(HK_TYPE_TICK))) { + scoped_guard(rcu) { + hk_intersects =3D cpumask_intersects(policy->related_cpus, + housekeeping_cpumask(HK_TYPE_TICK)); + } + + if (!hk_intersects) { cpufreq_cpu_put(policy); return -EOPNOTSUPP; } --=20 2.53.0 From nobody Tue Jun 16 20:36:48 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8AA6C265CA2 for ; Tue, 21 Apr 2026 03:06:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776740771; cv=none; b=IVkPS4/jwT+0XkaQwmR/JQ8MPU3Z7HYTM+ULaEObwJ9v1y8oSZTv94/JdUyJesi+P8sbPznsvQdse89T0BaBH4xU11lxUhmvW+5pmpPuCrex5Ib08HpBu6avDQUcTeZjfqMi6D4LhAlCB7tSP8iP6mvUkoWajtbd5MYVuFk1xFw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776740771; c=relaxed/simple; bh=hCmoCLgv9WCiy0WI6qTXzkfORhAfAjfFBOqTe129+N0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gg08SyQv0nPEVwosmA3gpndhRDVUDr9lckBV3ggZ6eOqqfcOTc17DarIn42/W9lvl6ckIbQ5+cseyjNPjZJoTHVcBwTz3dm2Y+e3b9bfNFKe8Fy9Uw2qFyMjTAiPZ05USPHBYFFO15Hc4iPiSCap9MC+sU/8ant+R/mOIaK6qD8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=dFiDcHKY; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="dFiDcHKY" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776740769; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UPmUBuUEIaNw490oCfROl6vphIOJhbJ7/BzVQQsjdOs=; b=dFiDcHKYJNx64B9xYHWt3flcPkpEdlyoTItnszrNg7FUOs2EA5ohebPcoE+cBQdiR9tuoq vyUq2k4VaAkl5C9dqq98spNJc7ZA6JUdzeNFaAc+49Y78lHZZSudpFuwbC0LpWmGJZDMRO Tyz1A3y1z5/9QUwwO0cJZfuYjH7mp7M= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-322-RV6ELyvuOd2DCv8Y77dPXA-1; Mon, 20 Apr 2026 23:06:06 -0400 X-MC-Unique: RV6ELyvuOd2DCv8Y77dPXA-1 X-Mimecast-MFC-AGG-ID: RV6ELyvuOd2DCv8Y77dPXA_1776740761 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4AE0B1800655; Tue, 21 Apr 2026 03:06:01 +0000 (UTC) Received: from llong-thinkpadp16vgen1.westford.csb (unknown [10.22.65.81]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3FE6A19560AB; Tue, 21 Apr 2026 03:05:54 +0000 (UTC) From: Waiman Long To: Tejun Heo , Johannes Weiner , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Jonathan Corbet , Shuah Khan , Catalin Marinas , Will Deacon , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li , Guenter Roeck , Frederic Weisbecker , "Paul E. McKenney" , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Boqun Feng , Uladzislau Rezki , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Zqiang , Anna-Maria Behnsen , Ingo Molnar , Thomas Gleixner , Chen Ridong , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-hwmon@vger.kernel.org, rcu@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Costa Shulyupin , Qiliang Yuan , Waiman Long Subject: [PATCH 09/23] workqueue: Use RCU to protect access of HK_TYPE_TIMER cpumask Date: Mon, 20 Apr 2026 23:03:37 -0400 Message-ID: <20260421030351.281436-10-longman@redhat.com> In-Reply-To: <20260421030351.281436-1-longman@redhat.com> References: <20260421030351.281436-1-longman@redhat.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 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" As HK_TYPE_TIMER cpumask is going to be changeable at run time, use RCU to protect access to the cpumask. Signed-off-by: Waiman Long --- kernel/workqueue.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 08b1c786b463..2dab3872281a 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -2557,8 +2557,10 @@ static void __queue_delayed_work(int cpu, struct wor= kqueue_struct *wq, if (housekeeping_enabled(HK_TYPE_TIMER)) { /* If the current cpu is a housekeeping cpu, use it. */ cpu =3D smp_processor_id(); - if (!housekeeping_test_cpu(cpu, HK_TYPE_TIMER)) - cpu =3D housekeeping_any_cpu(HK_TYPE_TIMER); + scoped_guard(rcu) { + if (!housekeeping_test_cpu(cpu, HK_TYPE_TIMER)) + cpu =3D housekeeping_any_cpu(HK_TYPE_TIMER); + } add_timer_on(timer, cpu); } else { if (likely(cpu =3D=3D WORK_CPU_UNBOUND)) --=20 2.53.0 From nobody Tue Jun 16 20:36:48 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1F9B6369203 for ; Tue, 21 Apr 2026 03:06:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776740781; cv=none; b=GW9sMGPlj/OqJQyEAcSumdTdUWTqyM6OggzL+UXiCSsM2SCiqsisu17ce4fc3Khc6N6oGHb3R7NlI874dMDPRbOVY0deX9EO/mkYYeCyJS6iFC/+o9+mm+VtMlNSPAxq8PS9y6uSjOfn9kzpu50D26I3NykjVGQ5igKB9e/mtM8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776740781; c=relaxed/simple; bh=vsZBuAhEaXxVIC0Xh69lKeORTO6BKToGt/jnTc3OjjM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qop3O5gJ3jOzSj1Y1To1FMQuNFxjWXCvkw1KyQWgc0T5LSOBUvulAWlJnzFLEzo2DaLF0qP0WbRdLpzPUkJKiX+m+839lT2F/eJOF67HDEPZ3Laf5tP0lTowPaqkz2yOSAQSiNeYyiqLEOBAB73+K61KhyIjZi6vVXC2e5iggOo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=FC6sPNq3; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="FC6sPNq3" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776740779; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Bmswg87Ok06uTiC+ecczzP/a3g4t/eC6rxArbw4L2sc=; b=FC6sPNq31VMD/iB1ojOXKRnLdeHcRTCxstrBsuOZQFWhFr/o5GeEmgUGen+o9dtGxqXRVI 0is2cPBMGxXVv9gGfM07wRHVsBXAHYd3X2NVwuzsDpmzQt2Q/9tpBJ87O2dFHJLQvfa3O8 I0SqGCJZoc+WF0IjQewUPDlPI5C8w2M= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-20-tKbAhyaOMFy0K2mFNqLy0Q-1; Mon, 20 Apr 2026 23:06:13 -0400 X-MC-Unique: tKbAhyaOMFy0K2mFNqLy0Q-1 X-Mimecast-MFC-AGG-ID: tKbAhyaOMFy0K2mFNqLy0Q_1776740768 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B65631956089; Tue, 21 Apr 2026 03:06:08 +0000 (UTC) Received: from llong-thinkpadp16vgen1.westford.csb (unknown [10.22.65.81]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 82F3519560B7; Tue, 21 Apr 2026 03:06:01 +0000 (UTC) From: Waiman Long To: Tejun Heo , Johannes Weiner , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Jonathan Corbet , Shuah Khan , Catalin Marinas , Will Deacon , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li , Guenter Roeck , Frederic Weisbecker , "Paul E. McKenney" , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Boqun Feng , Uladzislau Rezki , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Zqiang , Anna-Maria Behnsen , Ingo Molnar , Thomas Gleixner , Chen Ridong , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-hwmon@vger.kernel.org, rcu@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Costa Shulyupin , Qiliang Yuan , Waiman Long Subject: [PATCH 10/23] cpu: Use RCU to protect access of HK_TYPE_TIMER cpumask Date: Mon, 20 Apr 2026 23:03:38 -0400 Message-ID: <20260421030351.281436-11-longman@redhat.com> In-Reply-To: <20260421030351.281436-1-longman@redhat.com> References: <20260421030351.281436-1-longman@redhat.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 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" As HK_TYPE_TIMER cpumask is going to be changeable at run time, use RCU to protect access to the cpumask. Signed-off-by: Waiman Long --- kernel/cpu.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/cpu.c b/kernel/cpu.c index bc4f7a9ba64e..0d02b5d7a7ba 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -1890,6 +1890,8 @@ int freeze_secondary_cpus(int primary) cpu_maps_update_begin(); if (primary =3D=3D -1) { primary =3D cpumask_first(cpu_online_mask); + + guard(rcu)(); if (!housekeeping_cpu(primary, HK_TYPE_TIMER)) primary =3D housekeeping_any_cpu(HK_TYPE_TIMER); } else { --=20 2.53.0 From nobody Tue Jun 16 20:36:48 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ED8B8374186 for ; Tue, 21 Apr 2026 03:06:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776740797; cv=none; b=a2D2JPuScjuxqZcu7K82Hxs2H4LcgaoR1m4glCfo52JmMwooMmRwRBrECnXh1EO9AQ65aF1X+sWx1I44G1ZZLWDu4t8bsOx0mWNsKK7kA/aRtSiFceDEXeRpN/secOZG44sKgh3JPmbWLSUyeYT9kOSjuBfgHcO5REtkPVQM7LY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776740797; c=relaxed/simple; bh=NizBy5F5iqz3lIlv4/HGfGfpmqCFIGJCsc8UXnSMbdo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=A6kD7rtahAQniapgXcNFUan1CPc6vAcfd8rmb2ioKorQGzYU3rJZMf3JjWSfrC1JsbnuNBXy/PfZ2Bbqi00B+Bx5jaFcmxrp/QJA+QEQS3sNEHBR1W2ytM73ojsn+BLrCN2Zq1k1jb7X5cj7oEAprIsYFnFx5w7yXAAdr10p60g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=HwR/h+dt; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="HwR/h+dt" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776740785; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=COchuuNtaUwzp4yU7u6iY7uNboUt1slktmJkiZmVfdo=; b=HwR/h+dt3mi4bGvYFRguxi2y3t6dXbrAKJn3fHmrmNv3FYwwuUgcgzUha7EfeINXwFOP5u VNhOaoMgA2HwhibJ73aiOCVKsrg2+UJR2DY3/w6u15zuiaTIMoKSm3oXhy2oyfm2fYkBtC UIiQZ5MS9oabovMi9gz7ONcUrcSZIUc= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-343-Ht1zoOtzOmaoJByl8D1ezg-1; Mon, 20 Apr 2026 23:06:21 -0400 X-MC-Unique: Ht1zoOtzOmaoJByl8D1ezg-1 X-Mimecast-MFC-AGG-ID: Ht1zoOtzOmaoJByl8D1ezg_1776740776 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id EEC4219560B2; Tue, 21 Apr 2026 03:06:15 +0000 (UTC) Received: from llong-thinkpadp16vgen1.westford.csb (unknown [10.22.65.81]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id ED1DE19560B7; Tue, 21 Apr 2026 03:06:08 +0000 (UTC) From: Waiman Long To: Tejun Heo , Johannes Weiner , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Jonathan Corbet , Shuah Khan , Catalin Marinas , Will Deacon , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li , Guenter Roeck , Frederic Weisbecker , "Paul E. McKenney" , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Boqun Feng , Uladzislau Rezki , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Zqiang , Anna-Maria Behnsen , Ingo Molnar , Thomas Gleixner , Chen Ridong , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-hwmon@vger.kernel.org, rcu@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Costa Shulyupin , Qiliang Yuan , Waiman Long Subject: [PATCH 11/23] hrtimer: Use RCU to protect access of HK_TYPE_TIMER cpumask Date: Mon, 20 Apr 2026 23:03:39 -0400 Message-ID: <20260421030351.281436-12-longman@redhat.com> In-Reply-To: <20260421030351.281436-1-longman@redhat.com> References: <20260421030351.281436-1-longman@redhat.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 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" As HK_TYPE_TIMER cpumask is going to be changeable at run time, use RCU to protect access to the cpumask. The access of HK_TYPE_TIMER cpumask within hrtimers_cpu_dying() is protected as interrupt is disabled and all the other CPUs are stopped when this function is invoked as part of the CPU tear down process. Signed-off-by: Waiman Long --- kernel/time/hrtimer.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c index 000fb6ba7d74..85495400a193 100644 --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -242,8 +242,10 @@ static bool hrtimer_suitable_target(struct hrtimer *ti= mer, struct hrtimer_clock_ static inline struct hrtimer_cpu_base *get_target_base(struct hrtimer_cpu_= base *base, bool pinned) { if (!hrtimer_base_is_online(base)) { - int cpu =3D cpumask_any_and(cpu_online_mask, housekeeping_cpumask(HK_TYP= E_TIMER)); + int cpu; =20 + guard(rcu)(); + cpu =3D cpumask_any_and(cpu_online_mask, housekeeping_cpumask(HK_TYPE_TI= MER)); return &per_cpu(hrtimer_bases, cpu); } =20 --=20 2.53.0 From nobody Tue Jun 16 20:36:48 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 61736375AA8 for ; Tue, 21 Apr 2026 03:06:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776740793; cv=none; b=G5t+1qGX19KgXvVpBuUGgw/wO/UFCGtxKkSuhDg4WsobIeGoc/ZhcxpFZe8LSgOLaHCUYk3drF0OSt+QJ9g0cHAJoUo6u3Q1SfTDelBDSwaHtm0mo+Fr+2wWaNdWBRyUYr9fmvH6urR/iapr8oMrTdAN4Z39fUiKrarPtYrS6ws= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776740793; c=relaxed/simple; bh=G9rLZc4yI51EJ8pv1UnHTCwv9/p1NjVFbaeofm5LZWM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uahScZ1LNTj5EUWnz/se5GMT5DlA4HjwWgZXaDgt9IhXc++rWIPnhiQ78wYFq3JWMHK3VygzJxYF8xzBN9qLMNU6TBUBJWuFOxSUqJnpKck2zeCSB1p22lYiLsVz/D4RHNiQnyhBE+t3d/PyP7F7PXK/lIQ4xVTjzsSenDsb+yY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=c4eh76bM; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="c4eh76bM" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776740791; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2vSDcfbLcuN36y3FIAsgLPjIMhKRfkRmgcpEgQOy2ng=; b=c4eh76bMuswG9ucSAVF2cmsznlLZArW3/sn9CSGDo9Ls0zIP1zJDIKmYbK6dRGyxo3Dx2m iFINTQHeITOK8iNPr57lLGVPgWDNkuPTsL3qq8aVsNpGkjyPgxHahNvmBkSRcswtdwntTI 4K+n7f32LudYBSpdYY+9Ry4QyBV/pnQ= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-84-FG7_zAziN9-KML86Xom_Fg-1; Mon, 20 Apr 2026 23:06:28 -0400 X-MC-Unique: FG7_zAziN9-KML86Xom_Fg-1 X-Mimecast-MFC-AGG-ID: FG7_zAziN9-KML86Xom_Fg_1776740783 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1C59F19560BB; Tue, 21 Apr 2026 03:06:23 +0000 (UTC) Received: from llong-thinkpadp16vgen1.westford.csb (unknown [10.22.65.81]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 327A619560AB; Tue, 21 Apr 2026 03:06:16 +0000 (UTC) From: Waiman Long To: Tejun Heo , Johannes Weiner , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Jonathan Corbet , Shuah Khan , Catalin Marinas , Will Deacon , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li , Guenter Roeck , Frederic Weisbecker , "Paul E. McKenney" , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Boqun Feng , Uladzislau Rezki , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Zqiang , Anna-Maria Behnsen , Ingo Molnar , Thomas Gleixner , Chen Ridong , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-hwmon@vger.kernel.org, rcu@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Costa Shulyupin , Qiliang Yuan , Waiman Long Subject: [PATCH 12/23] net: Use boot time housekeeping cpumask settings for now Date: Mon, 20 Apr 2026 23:03:40 -0400 Message-ID: <20260421030351.281436-13-longman@redhat.com> In-Reply-To: <20260421030351.281436-1-longman@redhat.com> References: <20260421030351.281436-1-longman@redhat.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 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" Checking of the housekeeping cpumasks was originally added to the store_rps_map() method in commit 07bbecb34106 ("net: Restrict receive packets queuing to housekeeping CPUs"). This store method ensures that only CPUs in housekeeping cpumask can be set in the "rps_cpus" of the individual network devices. Later, commit 662ff1aac854 ("net: Keep ignoring isolated cpuset change") replaced HK_TYPE_DOMAIN by HK_TYPE_DOMAIN_BOOT as HK_TYPE_DOMAIN cpumask was going to be made changeable at run time. Now we are going to make the nohz_full housekeeping cpumask to be changeable at run time too. Ideally we should update the housekeeping cpumasks changes should be propagated to the RPS cpumasks, but we need more thoughts to properly synchronize them. Ignore the run time housekeeping cpumask changes and only use the boot time "isolcpus=3D" and "nohz_full=3D" values for now. Signed-off-by: Waiman Long --- net/core/net-sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c index e430645748a7..9e666cc3b34c 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -1023,7 +1023,7 @@ int rps_cpumask_housekeeping(struct cpumask *mask) { if (!cpumask_empty(mask)) { cpumask_and(mask, mask, housekeeping_cpumask(HK_TYPE_DOMAIN_BOOT)); - cpumask_and(mask, mask, housekeeping_cpumask(HK_TYPE_WQ)); + cpumask_and(mask, mask, housekeeping_cpumask(HK_TYPE_KERNEL_NOISE_BOOT)); if (cpumask_empty(mask)) return -EINVAL; } --=20 2.53.0 From nobody Tue Jun 16 20:36:48 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EFB112EBB84 for ; Tue, 21 Apr 2026 03:06:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776740803; cv=none; b=XPHFfMLo2ZnqTPdGLyYYEaFr9EPjnuF6/8t5ioN9Xk1ni58Nygr2Qm2hFuCFMmqGMvTgW8cJBhqNXGenuFfdjzgWrw50VsowF2eQHmpHssq2oqXGc2ofWThtwgXd9GObs3DqyZ+fn/BZxtW4+QbDE8MmZUZfyiXjWkLzaZPuKEE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776740803; c=relaxed/simple; bh=y21cwGAHYaNaF8YRvTFnxXt2GMtqpW0sgbaYNH/AjnQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bn8qDzP+bWBBRrDs2X3LCkPkiVmgErFyEve0mrltBJnFeOu/vWExsjJ/dQXA3nwAcbXWIyz+KCZqcP51x6RI2PsujxhC8MV6vN1dXXOnyUa8FvG0y0hRzAwKNyEP7nj91oRH3Lt+MP8RgLsk46sqcLLgsT3rSmwhBpj5uoyHmgQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=KPkVULae; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="KPkVULae" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776740801; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aKF+VwmZQV0pl/RDzNAg6PxSXQMnzdlIZnccx5H1z+o=; b=KPkVULaeI+ZeLGs78193eLzsIEpNv4o3+9Hrdlai4YinxG6PvcS0Trf7Zn59oJSl4hvWvd D1+lYMqs6QUsLljJ3HQHUTxXQbG1DdzZgmsn+ztAoYuM1XopGupUpSlLmfVYOdt8AHVTHh qv+VFjJNUz7/x8uuyt7UgBP6Cg1WqlE= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-195-8E3QXaAOMxq70JNFAK8-2A-1; Mon, 20 Apr 2026 23:06:38 -0400 X-MC-Unique: 8E3QXaAOMxq70JNFAK8-2A-1 X-Mimecast-MFC-AGG-ID: 8E3QXaAOMxq70JNFAK8-2A_1776740790 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 95D931956054; Tue, 21 Apr 2026 03:06:30 +0000 (UTC) Received: from llong-thinkpadp16vgen1.westford.csb (unknown [10.22.65.81]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 572CA19560AB; Tue, 21 Apr 2026 03:06:23 +0000 (UTC) From: Waiman Long To: Tejun Heo , Johannes Weiner , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Jonathan Corbet , Shuah Khan , Catalin Marinas , Will Deacon , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li , Guenter Roeck , Frederic Weisbecker , "Paul E. McKenney" , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Boqun Feng , Uladzislau Rezki , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Zqiang , Anna-Maria Behnsen , Ingo Molnar , Thomas Gleixner , Chen Ridong , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-hwmon@vger.kernel.org, rcu@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Costa Shulyupin , Qiliang Yuan , Waiman Long Subject: [PATCH 13/23] sched/core: Use RCU to protect access of HK_TYPE_KERNEL_NOISE cpumask Date: Mon, 20 Apr 2026 23:03:41 -0400 Message-ID: <20260421030351.281436-14-longman@redhat.com> In-Reply-To: <20260421030351.281436-1-longman@redhat.com> References: <20260421030351.281436-1-longman@redhat.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 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" As HK_TYPE_KERNEL_NOISE is going to be changeable at run time, use RCU to protect access to the cpumask when needed. Some access of the HK_TYPE_KERNEL_NOISE cpumask is done inside the tick code that has interrupt disabled which is a rcu_read_lock() critical section. Anyway, housekeeping_cpumask() will warn if they are used in invalid context. Signed-off-by: Waiman Long --- kernel/sched/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 8952f5764517..6ae00c23d8a7 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -1261,6 +1261,8 @@ int get_nohz_timer_target(void) struct sched_domain *sd; const struct cpumask *hk_mask; =20 + guard(rcu)(); + if (housekeeping_cpu(cpu, HK_TYPE_KERNEL_NOISE)) { if (!idle_cpu(cpu)) return cpu; @@ -1269,8 +1271,6 @@ int get_nohz_timer_target(void) =20 hk_mask =3D housekeeping_cpumask(HK_TYPE_KERNEL_NOISE); =20 - guard(rcu)(); - for_each_domain(cpu, sd) { for_each_cpu_and(i, sched_domain_span(sd), hk_mask) { if (cpu =3D=3D i) --=20 2.53.0 From nobody Tue Jun 16 20:36:48 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3251437755D for ; Tue, 21 Apr 2026 03:06:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776740810; cv=none; b=EYNLAtZrCnmrWX0JxYz0KNUPnNlBwyEX5UZsrmH4rZoITEJw1LGj8t2kHl7FGVR1OzhLWVyE6zleQpo5ZScG2RIJAY3Z2VDPaZ0c5eIpGJvHfoTMdFcp3+NofsYEOq+EqmJ0unAetd+AmlJVkAGxFSv50tPTyDmwb5gQYFAwJ4I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776740810; c=relaxed/simple; bh=k5g7pP+2/ZD9JxKbuSILo333vnrc8GjjdJo8hw2U1bo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sSReSwcZyx9PEZ/p3pxU6/saEUIkbzQBh1eRbQtQAEOVysJGrYJjrcgny2oqsXSA6vQLrHXXqp7JhIMQgIIDkEH1F/9//KlgpuV17MgN6RK4ASWGo+JvSZ0IeBcaYxfooOGYJTH/xeodFNN/VcBxMYC1EvoubiT4qdVXXunTdAo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=hosshHqf; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="hosshHqf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776740808; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+WNNC/jKnAyyd7qhSX1oISqS9Aod8NglMEV4NJJnJ44=; b=hosshHqfzg8sD/YdxO6slwUeSTiAowaYtl9PkJm1h8WzeP9P8tNcBVvgxMlwY9RtsCcePL wv4s9mi25on21xNr4jp1oIA+iNBU71jTdPaDyg6N1T+bGfl28Khmp9Q2eh/wRh9K8pxlDv I2C6vssu11uiphsKNU6ztOLG7G5ppcE= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-635-K3QwEf64Osazpz2xQZ8DLQ-1; Mon, 20 Apr 2026 23:06:42 -0400 X-MC-Unique: K3QwEf64Osazpz2xQZ8DLQ-1 X-Mimecast-MFC-AGG-ID: K3QwEf64Osazpz2xQZ8DLQ_1776740797 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B10771956056; Tue, 21 Apr 2026 03:06:37 +0000 (UTC) Received: from llong-thinkpadp16vgen1.westford.csb (unknown [10.22.65.81]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CE75C19560AB; Tue, 21 Apr 2026 03:06:30 +0000 (UTC) From: Waiman Long To: Tejun Heo , Johannes Weiner , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Jonathan Corbet , Shuah Khan , Catalin Marinas , Will Deacon , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li , Guenter Roeck , Frederic Weisbecker , "Paul E. McKenney" , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Boqun Feng , Uladzislau Rezki , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Zqiang , Anna-Maria Behnsen , Ingo Molnar , Thomas Gleixner , Chen Ridong , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-hwmon@vger.kernel.org, rcu@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Costa Shulyupin , Qiliang Yuan , Waiman Long Subject: [PATCH 14/23] hwmon/coretemp: Use RCU to protect access of HK_TYPE_MISC cpumask Date: Mon, 20 Apr 2026 23:03:42 -0400 Message-ID: <20260421030351.281436-15-longman@redhat.com> In-Reply-To: <20260421030351.281436-1-longman@redhat.com> References: <20260421030351.281436-1-longman@redhat.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 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" As HK_TYPE_MISC cpumask is going to be changeable at run time, use RCU to protect access to the cpumask. Signed-off-by: Waiman Long --- drivers/hwmon/coretemp.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c index 6a0d94711ead..0284ea6a3b79 100644 --- a/drivers/hwmon/coretemp.c +++ b/drivers/hwmon/coretemp.c @@ -563,8 +563,10 @@ static int create_core_data(struct platform_device *pd= ev, unsigned int cpu, u32 eax, edx; int err; =20 - if (!housekeeping_cpu(cpu, HK_TYPE_MISC)) - return 0; + scoped_guard(rcu) { + if (!housekeeping_cpu(cpu, HK_TYPE_MISC)) + return 0; + } =20 tdata =3D init_temp_data(pdata, cpu, pkg_flag); if (!tdata) --=20 2.53.0 From nobody Tue Jun 16 20:36:48 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3E8CA37BE65 for ; Tue, 21 Apr 2026 03:06:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776740815; cv=none; b=LHR1YeDiSAaKv+QZuohPIc1m+l+zQdp89TkidMIFRhHa13tn/gjVkE9s/ArhnXlxB9qcCVbGec4dAbyu4YDlnxm+z/rYbYyLq0q939Flw2haEiLC9HPZ+HCT+u73m4U9kBC8orpaUNz611m0kZ9IJfMkxuIs7Fuu2+9lsrGYuI0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776740815; c=relaxed/simple; bh=jlSzrdRoCk8O53BdpCgrGHVT1k8wkXcmtZiCQ2yPsTQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nbL1WQHQyLdJUeCan317g2XPDmeeocx5BxcMTNJ7TvVm58a7IEOC2TbfYZMTC0P9TsznZahQl9yKO3wk3Jpn+Yt6lHZ6C3TOk2ZpD14prhtBNLrmx18UxT12MqCnIuU8YX5gpNUhT4w4Nq28p70zHCyePOzFVmkGA04iwnBDQts= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=ZPnlD8Ad; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ZPnlD8Ad" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776740813; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=L6fqD7LU2lkfHc9CGeiddofdvg6nvrDcuHa8qiOr5+o=; b=ZPnlD8Addo1RHT42k/JVn+3kzZwx3nQkx3ogb3EWQyzwmgkVgJhOOUou4tbrivIDZoX3sp TlErNTiPSUIJMpxFp2n4ooKPl9kvfrNsVn8vAF6EUsAW3aGf+ZKE4K6WTgM2+55k73FJi/ xeXlM254PWsHFYEbcFTj0GEjPPtau/4= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-203-3E8X-6EKONCGjFMgsGHa1w-1; Mon, 20 Apr 2026 23:06:49 -0400 X-MC-Unique: 3E8X-6EKONCGjFMgsGHa1w-1 X-Mimecast-MFC-AGG-ID: 3E8X-6EKONCGjFMgsGHa1w_1776740805 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D587C18005AA; Tue, 21 Apr 2026 03:06:44 +0000 (UTC) Received: from llong-thinkpadp16vgen1.westford.csb (unknown [10.22.65.81]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E7C5619560AB; Tue, 21 Apr 2026 03:06:37 +0000 (UTC) From: Waiman Long To: Tejun Heo , Johannes Weiner , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Jonathan Corbet , Shuah Khan , Catalin Marinas , Will Deacon , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li , Guenter Roeck , Frederic Weisbecker , "Paul E. McKenney" , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Boqun Feng , Uladzislau Rezki , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Zqiang , Anna-Maria Behnsen , Ingo Molnar , Thomas Gleixner , Chen Ridong , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-hwmon@vger.kernel.org, rcu@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Costa Shulyupin , Qiliang Yuan , Waiman Long Subject: [PATCH 15/23] Drivers: hv: Use RCU to protect access of HK_TYPE_MANAGED_IRQ cpumask Date: Mon, 20 Apr 2026 23:03:43 -0400 Message-ID: <20260421030351.281436-16-longman@redhat.com> In-Reply-To: <20260421030351.281436-1-longman@redhat.com> References: <20260421030351.281436-1-longman@redhat.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 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" As HK_TYPE_MANAGED_IRQ cpumask is going to be changeable at run time, use RCU to protect access to the cpumask. The memory allocation alloc_cpumask_var() call is done before taking the rcu_read_lock() as this call can be sleepable. Signed-off-by: Waiman Long --- drivers/hv/channel_mgmt.c | 15 +++++++++------ drivers/hv/vmbus_drv.c | 7 +++++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c index 84eb0a6a0b54..44441dafed90 100644 --- a/drivers/hv/channel_mgmt.c +++ b/drivers/hv/channel_mgmt.c @@ -752,13 +752,16 @@ static void init_vp_index(struct vmbus_channel *chann= el) u32 i, ncpu =3D num_online_cpus(); cpumask_var_t available_mask; struct cpumask *allocated_mask; - const struct cpumask *hk_mask =3D housekeeping_cpumask(HK_TYPE_MANAGED_IR= Q); + const struct cpumask *hk_mask; u32 target_cpu; int numa_node; + bool alloc_ok; =20 - if (!perf_chn || - !alloc_cpumask_var(&available_mask, GFP_KERNEL) || - cpumask_empty(hk_mask)) { + alloc_ok =3D alloc_cpumask_var(&available_mask, GFP_KERNEL); + guard(rcu)(); + hk_mask =3D housekeeping_cpumask(HK_TYPE_MANAGED_IRQ); + + if (!perf_chn || !alloc_ok || cpumask_empty(hk_mask)) { /* * If the channel is not a performance critical * channel, bind it to VMBUS_CONNECT_CPU. @@ -770,7 +773,7 @@ static void init_vp_index(struct vmbus_channel *channel) channel->target_cpu =3D VMBUS_CONNECT_CPU; if (perf_chn) hv_set_allocated_cpu(VMBUS_CONNECT_CPU); - return; + goto out_free; } =20 for (i =3D 1; i <=3D ncpu + 1; i++) { @@ -808,7 +811,7 @@ static void init_vp_index(struct vmbus_channel *channel) } =20 channel->target_cpu =3D target_cpu; - +out_free: free_cpumask_var(available_mask); } =20 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index 3faa74e49a6b..60c7a5ac15c0 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -1763,8 +1763,11 @@ int vmbus_channel_set_cpu(struct vmbus_channel *chan= nel, u32 target_cpu) if (target_cpu >=3D nr_cpumask_bits) return -EINVAL; =20 - if (!cpumask_test_cpu(target_cpu, housekeeping_cpumask(HK_TYPE_MANAGED_IR= Q))) - return -EINVAL; + scoped_guard(rcu) { + if (!cpumask_test_cpu(target_cpu, + housekeeping_cpumask(HK_TYPE_MANAGED_IRQ))) + return -EINVAL; + } =20 if (!cpu_online(target_cpu)) return -EINVAL; --=20 2.53.0 From nobody Tue Jun 16 20:36:48 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9C75A31AA9B for ; Tue, 21 Apr 2026 03:07:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776740825; cv=none; b=MSDi3TJ/oblkh9qdpVApExXBWlbi2vW5ASdx/BN0sosZz38VmHMKlVEnTyl0i4la7TTSW4QGQjnaOXC7z+707zebseEVJiLqDAyW56WcjFv/X7CdkKLZyJADhtQBQdOMLUGArchVm4Z236i7P4K61eFJlEt+tFI6lGE1oJ3kpcc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776740825; c=relaxed/simple; bh=wBqbSVNLmblycpPiB4EVKCEJkX8NpN5Q/069MdSR2vo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=X4RslNnk0AArbLco1aOKiijo7Q1tpn29Zu3ggfe442ImQekQoeHS9akuoFLFzshf3vOBwL8TUvZqpKK4uW5bB3AlbewxSxuW4uIOOasEYwdeoKvD6vxtm7NFBsfHBQV7lf8Ed4IDRz1Obtfm+6ROzWxGM0YTS7JTr9WTFx6IDXw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=LLaFrSe7; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="LLaFrSe7" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776740821; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IJ1jBK4Qvk6IyuAc9PHelYKQB7rpI+GlQygtFZv3Gyc=; b=LLaFrSe7H0iJGX0Shmd444Jti497+4/hQXAeDIXxtssgSZ+YLVZUbF7t1y1ZqqXgqwrPVx b7btcECQdH26GRKNOsCSYbyJixN8YoNfeskAPXggQH3vIUvfOoUpuDyfB6eUtcna6zDuN5 6Zkcs5lviN+4DaTeg6zSLGx+xLh+gOU= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-376-wTudjAQlMAi-26eGJaOhJw-1; Mon, 20 Apr 2026 23:06:57 -0400 X-MC-Unique: wTudjAQlMAi-26eGJaOhJw-1 X-Mimecast-MFC-AGG-ID: wTudjAQlMAi-26eGJaOhJw_1776740812 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 517F11956054; Tue, 21 Apr 2026 03:06:52 +0000 (UTC) Received: from llong-thinkpadp16vgen1.westford.csb (unknown [10.22.65.81]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1DB4119560AB; Tue, 21 Apr 2026 03:06:44 +0000 (UTC) From: Waiman Long To: Tejun Heo , Johannes Weiner , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Jonathan Corbet , Shuah Khan , Catalin Marinas , Will Deacon , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li , Guenter Roeck , Frederic Weisbecker , "Paul E. McKenney" , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Boqun Feng , Uladzislau Rezki , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Zqiang , Anna-Maria Behnsen , Ingo Molnar , Thomas Gleixner , Chen Ridong , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-hwmon@vger.kernel.org, rcu@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Costa Shulyupin , Qiliang Yuan , Waiman Long Subject: [PATCH 16/23] genirq/cpuhotplug: Use RCU to protect access of HK_TYPE_MANAGED_IRQ cpumask Date: Mon, 20 Apr 2026 23:03:44 -0400 Message-ID: <20260421030351.281436-17-longman@redhat.com> In-Reply-To: <20260421030351.281436-1-longman@redhat.com> References: <20260421030351.281436-1-longman@redhat.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 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" As HK_TYPE_MANAGED_IRQ cpumask is going to be changeable at run time, use RCU to protect access to the cpumask. To enable the new HK_TYPE_MANAGED_IRQ cpumask to take effect, the following steps can be done. 1) Update the HK_TYPE_MANAGED_IRQ cpumask to take out the newly isolated CPUs and add back the de-isolated CPUs. 2) Tear down the affected CPUs to cause irq_migrate_all_off_this_cpu() to be called on the affected CPUs to migrate the irqs to other HK_TYPE_MANAGED_IRQ housekeeping CPUs. 3) Bring up the previously offline CPUs to invoke irq_affinity_online_cpu() to allow the newly de-isolated CPUs to be used for managed irqs. Signed-off-by: Waiman Long --- kernel/irq/cpuhotplug.c | 1 + kernel/irq/manage.c | 1 + 2 files changed, 2 insertions(+) diff --git a/kernel/irq/cpuhotplug.c b/kernel/irq/cpuhotplug.c index cd5689e383b0..86437c78f1f2 100644 --- a/kernel/irq/cpuhotplug.c +++ b/kernel/irq/cpuhotplug.c @@ -196,6 +196,7 @@ static bool hk_should_isolate(struct irq_data *data, un= signed int cpu) if (!housekeeping_enabled(HK_TYPE_MANAGED_IRQ)) return false; =20 + guard(rcu)(); hk_mask =3D housekeeping_cpumask(HK_TYPE_MANAGED_IRQ); if (cpumask_subset(irq_data_get_effective_affinity_mask(data), hk_mask)) return false; diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c index 2e8072437826..8270c4de260b 100644 --- a/kernel/irq/manage.c +++ b/kernel/irq/manage.c @@ -263,6 +263,7 @@ int irq_do_set_affinity(struct irq_data *data, const st= ruct cpumask *mask, bool housekeeping_enabled(HK_TYPE_MANAGED_IRQ)) { const struct cpumask *hk_mask; =20 + guard(rcu)(); hk_mask =3D housekeeping_cpumask(HK_TYPE_MANAGED_IRQ); =20 cpumask_and(tmp_mask, mask, hk_mask); --=20 2.53.0 From nobody Tue Jun 16 20:36:48 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9113F377560 for ; Tue, 21 Apr 2026 03:07:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776740829; cv=none; b=JtnCsbkOCfA2kMI1zeiTGq7wgi4lV+8VKEqLjhxMo2O5Nsaf0t8rVVt4wpt3e16UwmLezDMPzYLe2Mhaii1+IyJ0k0ZwRcUx3Q5taeKvkvzk6KIUakGjsrOSc+TfpRX2aE7Fl7evugMNsL5b6ewQKKjwd9GNC4gTIbnCdH80nic= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776740829; c=relaxed/simple; bh=0bGGT6V5Q/frPq9S5iAZsTcMRt+nPcX7PGfKt6HDhdU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YBcYwhJF/eOaxyjGofbOUAa5ZPt/ZCv5OB6l3JhQSbdGUsdAdwDHz2dxW5addKZyyajileekyoeja7KCSt6BbC5Hu/XvEwlA/fEgz2Lgf47uFsF9ZQB9u7zZa0ybBLNaGZXBE77ZkEvqTT80GsXgvSBOMXPc3lJVN7/8sC8W6+c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=WzNL7cBT; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="WzNL7cBT" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776740827; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sjKKGFReES6fBmLSbBk8lBaxQLaUKd2+7TGo9rl4EsY=; b=WzNL7cBTgUM3FiU803WlS+j3vkDzZJSKu/HAcaDBXdbYswXSwjcs+qX0eFDeozJhwMBIPP bL/6b4A21ga+LtT8BydgoFoqi1T18A6aInG6AIAxX1eLqBeJrFUofPt6gBeaFqiLmOAsKF sCkaHu8c+9fK/HzwlUkLqTtickyKHPY= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-654-NeFIKFsmNKaVw44PsfsFGA-1; Mon, 20 Apr 2026 23:07:04 -0400 X-MC-Unique: NeFIKFsmNKaVw44PsfsFGA-1 X-Mimecast-MFC-AGG-ID: NeFIKFsmNKaVw44PsfsFGA_1776740819 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 995781956095; Tue, 21 Apr 2026 03:06:59 +0000 (UTC) Received: from llong-thinkpadp16vgen1.westford.csb (unknown [10.22.65.81]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 897CB19560AB; Tue, 21 Apr 2026 03:06:52 +0000 (UTC) From: Waiman Long To: Tejun Heo , Johannes Weiner , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Jonathan Corbet , Shuah Khan , Catalin Marinas , Will Deacon , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li , Guenter Roeck , Frederic Weisbecker , "Paul E. McKenney" , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Boqun Feng , Uladzislau Rezki , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Zqiang , Anna-Maria Behnsen , Ingo Molnar , Thomas Gleixner , Chen Ridong , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-hwmon@vger.kernel.org, rcu@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Costa Shulyupin , Qiliang Yuan , Waiman Long Subject: [PATCH 17/23] sched/isolation: Extend housekeeping_dereference_check() to cover changes in nohz_full or manged_irqs cpumasks Date: Mon, 20 Apr 2026 23:03:45 -0400 Message-ID: <20260421030351.281436-18-longman@redhat.com> In-Reply-To: <20260421030351.281436-1-longman@redhat.com> References: <20260421030351.281436-1-longman@redhat.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 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" As we are going to make HK_TYPE_KERNEL_NOISE and HK_TYPE_MANAGED_IRQ housekeeping cpumasks run time changeable, extend housekeeping_dereference_check() to cover changes to those cpumasks as well. Signed-off-by: Waiman Long --- kernel/sched/isolation.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/sched/isolation.c b/kernel/sched/isolation.c index 1f3f1c83dd12..1647e7b08bac 100644 --- a/kernel/sched/isolation.c +++ b/kernel/sched/isolation.c @@ -38,7 +38,8 @@ EXPORT_SYMBOL_GPL(housekeeping_enabled); =20 static bool housekeeping_dereference_check(enum hk_type type) { - if (IS_ENABLED(CONFIG_LOCKDEP) && type =3D=3D HK_TYPE_DOMAIN) { + if (IS_ENABLED(CONFIG_LOCKDEP) && + (BIT(type) & (HK_FLAG_DOMAIN | HK_FLAG_KERNEL_NOISE | HK_FLAG_MANAGED_= IRQ))) { /* Cpuset isn't even writable yet? */ if (system_state <=3D SYSTEM_SCHEDULING) return true; --=20 2.53.0 From nobody Tue Jun 16 20:36:48 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 408C3375AA8 for ; Tue, 21 Apr 2026 03:07:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776740837; cv=none; b=Lyq4YqeukAiLlEGa96PjOmUlhEFzem6UjYLWcsJwQGeuwD5xqkpudOzBuyz0XvLU64CN0h+lIbgaLZBjgCNJTZ60zdwqT69w7DbVt3DKQtJfekNTJgNnMgbqJBQMcZcuVvQ9CEddvubMK1OjKjvUVsGBvHozB6PCztbZCKhxS6c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776740837; c=relaxed/simple; bh=7PyCAYPTzVOicWSr/jRl6qoxbI9T+FJqQCf6F+XuTOM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=h9VlNvci4SAjWFtoil+BH3KiGb80/HjCFh/vEKWkgYJ7tYtV07xc+Zq3zHO+kwz5wjgyaGS/I+AITnUYX3GQdbo4w4OsiZOhuSRBiJP7Z+IURfUpwBwndx4m01z0zmQhw18RkuqvF9kuhgeAqmdbZbhmSeuf24CAi5IaUySrt8c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=RSL2y46h; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="RSL2y46h" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776740835; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3J2xEvoiZlc0ekRXR4e4rpd5+KNi4GznOay8CXNFrmI=; b=RSL2y46hDyIDHmFZ8dlGwcPwBT8AiHt6RcbYd0sSdt1CoaPFrdw9kIy05PLhUASJnm7Nt0 LWNwEml80Oc1h5lnpOo27BRsPp/Mh2kKW1uOU4nd2fCSJfhyPYsc80tELl6HMR289brOYO KnTprEM0s9lsZa0mDRh7sBV3e2wHBnQ= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-42-TOLBnhFlOXqsjWlnoZiSkQ-1; Mon, 20 Apr 2026 23:07:11 -0400 X-MC-Unique: TOLBnhFlOXqsjWlnoZiSkQ-1 X-Mimecast-MFC-AGG-ID: TOLBnhFlOXqsjWlnoZiSkQ_1776740827 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E22E61956056; Tue, 21 Apr 2026 03:07:06 +0000 (UTC) Received: from llong-thinkpadp16vgen1.westford.csb (unknown [10.22.65.81]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D134019560AB; Tue, 21 Apr 2026 03:06:59 +0000 (UTC) From: Waiman Long To: Tejun Heo , Johannes Weiner , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Jonathan Corbet , Shuah Khan , Catalin Marinas , Will Deacon , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li , Guenter Roeck , Frederic Weisbecker , "Paul E. McKenney" , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Boqun Feng , Uladzislau Rezki , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Zqiang , Anna-Maria Behnsen , Ingo Molnar , Thomas Gleixner , Chen Ridong , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-hwmon@vger.kernel.org, rcu@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Costa Shulyupin , Qiliang Yuan , Waiman Long Subject: [PATCH 18/23] cpu/hotplug: Add a new cpuhp_offline_cb() API Date: Mon, 20 Apr 2026 23:03:46 -0400 Message-ID: <20260421030351.281436-19-longman@redhat.com> In-Reply-To: <20260421030351.281436-1-longman@redhat.com> References: <20260421030351.281436-1-longman@redhat.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 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" Add a new cpuhp_offline_cb() API that allows us to offline a set of CPUs one-by-one, run the given callback function and then bring those CPUs back online again while inhibiting any concurrent CPU hotplug operations from happening. This new API can be used to enable runtime adjustment of nohz_full and isolcpus boot command line options. A new cpuhp_offline_cb_mode flag is also added to signal that the system is in this offline callback transient state so that some hotplug operations can be optimized out if we choose to. Signed-off-by: Waiman Long --- include/linux/cpuhplock.h | 9 +++++ kernel/cpu.c | 70 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/include/linux/cpuhplock.h b/include/linux/cpuhplock.h index 286b3ab92e15..37637baa32eb 100644 --- a/include/linux/cpuhplock.h +++ b/include/linux/cpuhplock.h @@ -9,7 +9,9 @@ =20 #include #include +#include =20 +typedef int (*cpuhp_cb_t)(void *arg); struct device; =20 extern int lockdep_is_cpus_held(void); @@ -29,6 +31,8 @@ void clear_tasks_mm_cpumask(int cpu); int remove_cpu(unsigned int cpu); int cpu_device_down(struct device *dev); void smp_shutdown_nonboot_cpus(unsigned int primary_cpu); +int cpuhp_offline_cb(struct cpumask *mask, cpuhp_cb_t func, void *arg); +extern bool cpuhp_offline_cb_mode; =20 #else /* CONFIG_HOTPLUG_CPU */ =20 @@ -43,6 +47,11 @@ static inline void cpu_hotplug_disable(void) { } static inline void cpu_hotplug_enable(void) { } static inline int remove_cpu(unsigned int cpu) { return -EPERM; } static inline void smp_shutdown_nonboot_cpus(unsigned int primary_cpu) { } +static inline int cpuhp_offline_cb(struct cpumask *mask, cpuhp_cb_t func, = void *arg) +{ + return -EPERM; +} +#define cpuhp_offline_cb_mode false #endif /* !CONFIG_HOTPLUG_CPU */ =20 DEFINE_LOCK_GUARD_0(cpus_read_lock, cpus_read_lock(), cpus_read_unlock()) diff --git a/kernel/cpu.c b/kernel/cpu.c index 0d02b5d7a7ba..9b32f742cd1d 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -1520,6 +1520,76 @@ int remove_cpu(unsigned int cpu) } EXPORT_SYMBOL_GPL(remove_cpu); =20 +bool cpuhp_offline_cb_mode; + +/** + * cpuhp_offline_cb - offline CPUs, invoke callback function & online CPUs= afterward + * @mask: A mask of CPUs to be taken offline and then online + * @func: A callback function to be invoked while the given CPUs are offli= ne + * @arg: Argument to be passed back to the callback function + * + * Return: 0 if successful, an error code otherwise + */ +int cpuhp_offline_cb(struct cpumask *mask, cpuhp_cb_t func, void *arg) +{ + int off_cpu, on_cpu, ret, ret2 =3D 0; + + if (WARN_ON_ONCE(cpumask_empty(mask) || + !cpumask_subset(mask, cpu_online_mask))) + return -EINVAL; + + pr_debug("%s: begin (CPU list =3D %*pbl)\n", __func__, cpumask_pr_args(ma= sk)); + lock_device_hotplug(); + cpuhp_offline_cb_mode =3D true; + /* + * If all offline operations succeed, off_cpu should become nr_cpu_ids. + */ + for_each_cpu(off_cpu, mask) { + ret =3D device_offline(get_cpu_device(off_cpu)); + if (unlikely(ret)) + break; + } + if (!ret) + ret =3D func(arg); + + /* Bring previously offline CPUs back online */ + for_each_cpu(on_cpu, mask) { + int retries =3D 0; + + if (on_cpu =3D=3D off_cpu) + break; + +retry: + ret2 =3D device_online(get_cpu_device(on_cpu)); + + /* + * With the unlikely event that CPU hotplug is disabled while + * this operation is in progress, we will need to wait a bit + * for hotplug to hopefully be re-enabled again. If not, print + * a warning and return the error. + * + * cpu_hotplug_disabled is supposed to be accessed while + * holding the cpu_add_remove_lock mutex. So we need to + * use the data_race() macro to access it here. + */ + while ((ret2 =3D=3D -EBUSY) && data_race(cpu_hotplug_disabled) && + (++retries <=3D 5)) { + msleep(20); + if (!data_race(cpu_hotplug_disabled)) + goto retry; + } + if (ret2) { + pr_warn("%s: Failed to bring CPU %d back online!\n", + __func__, on_cpu); + break; + } + } + cpuhp_offline_cb_mode =3D false; + unlock_device_hotplug(); + pr_debug("%s: end\n", __func__); + return ret ? ret : ret2; +} + void smp_shutdown_nonboot_cpus(unsigned int primary_cpu) { unsigned int cpu; --=20 2.53.0 From nobody Tue Jun 16 20:36:48 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E3064375AA8 for ; Tue, 21 Apr 2026 03:07:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776740847; cv=none; b=cSnQ4htv50aFae+U5xCu3+ULhwP2TEUtG1ykB9IGhT29G/jpl5i10Rht56FDEjCX+5dejRSDWjYjdFEL/SfuzzmPzAkekvVsp9hw4Bs1oNypzThbmOU3y40ZUy3dPywT8jkgHSySaSYc0jFBB6dstO6/h/IhSnU2wHfHtiifGVE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776740847; c=relaxed/simple; bh=aF/UkhCs2sXjpLZZ8EJMXj3n8vqyVnU6ma6HupdSaMw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NOSji2N9A29GLSbiamaqx37hHRaztLk5UTAdZuVziJTV8LcjosFhbpiGIZ7pgIlKuc0riXxnsvlj0nYf5bwoHtMey9LLsG+KWOVg69bJNDTh3AwpPi1k2JnLAeOuAUwIjls+Bkws4tLcssYO52BkhDaRvO/21Bk3l89vOXJ2YmM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=ROlz3vKd; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ROlz3vKd" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776740844; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oqkCB8gg1IaUA29GIqPtEMXErOagjLMO2tdDX2wDRaY=; b=ROlz3vKdVda7VYJdoWm6Lbe2Rn2DMW9SZxnAbSZ9I5p4OtTebMLVn6lvPXQVzd+jlZ7Wu4 LRVRAEdbfmmOyOS71etJy3zFTpencUJ9SePB1iaoXyt0Xlv+vaGS75inqPor+whmmyx6vO v1rNzQ1HjcO8qPMN5aW6sSuRDYqmb2I= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-449-0aQeQXPvOxGsYdnzx6me9Q-1; Mon, 20 Apr 2026 23:07:19 -0400 X-MC-Unique: 0aQeQXPvOxGsYdnzx6me9Q-1 X-Mimecast-MFC-AGG-ID: 0aQeQXPvOxGsYdnzx6me9Q_1776740834 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 37476195608E; Tue, 21 Apr 2026 03:07:14 +0000 (UTC) Received: from llong-thinkpadp16vgen1.westford.csb (unknown [10.22.65.81]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0D92F19560AB; Tue, 21 Apr 2026 03:07:06 +0000 (UTC) From: Waiman Long To: Tejun Heo , Johannes Weiner , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Jonathan Corbet , Shuah Khan , Catalin Marinas , Will Deacon , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li , Guenter Roeck , Frederic Weisbecker , "Paul E. McKenney" , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Boqun Feng , Uladzislau Rezki , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Zqiang , Anna-Maria Behnsen , Ingo Molnar , Thomas Gleixner , Chen Ridong , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-hwmon@vger.kernel.org, rcu@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Costa Shulyupin , Qiliang Yuan , Waiman Long Subject: [PATCH 19/23] cgroup/cpuset: Improve check for calling housekeeping_update() Date: Mon, 20 Apr 2026 23:03:47 -0400 Message-ID: <20260421030351.281436-20-longman@redhat.com> In-Reply-To: <20260421030351.281436-1-longman@redhat.com> References: <20260421030351.281436-1-longman@redhat.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 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" By making sure that isolated_hk_cpus matches isolated_cpus at boot time, we can more accurately determine if calling housekeeping_update() is needed by comparing if the two cpumasks are equal. The update_housekeeping flag still have a use in cpuset_handle_hotplug() to determine if a work function should be queued to invoke cpuset_update_sd_hk_unlock() as it is not supposed to look at isolated_hk_cpus without holding cpuset_top_mutex. Signed-off-by: Waiman Long --- kernel/cgroup/cpuset.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index a4eccb0ec0d1..1b0c50b46a49 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -1339,26 +1339,29 @@ static void cpuset_update_sd_hk_unlock(void) __releases(&cpuset_mutex) __releases(&cpuset_top_mutex) { + update_housekeeping =3D false; + /* force_sd_rebuild will be cleared in rebuild_sched_domains_locked() */ if (force_sd_rebuild) rebuild_sched_domains_locked(); =20 - if (update_housekeeping) { - update_housekeeping =3D false; - cpumask_copy(isolated_hk_cpus, isolated_cpus); - - /* - * housekeeping_update() is now called without holding - * cpus_read_lock and cpuset_mutex. Only cpuset_top_mutex - * is still being held for mutual exclusion. - */ - mutex_unlock(&cpuset_mutex); - cpus_read_unlock(); - WARN_ON_ONCE(housekeeping_update(isolated_hk_cpus, BIT(HK_TYPE_DOMAIN))); - mutex_unlock(&cpuset_top_mutex); - } else { + if (cpumask_equal(isolated_hk_cpus, isolated_cpus)) { + /* No housekeeping cpumask update needed */ cpuset_full_unlock(); + return; } + + cpumask_copy(isolated_hk_cpus, isolated_cpus); + + /* + * housekeeping_update() is now called without holding + * cpus_read_lock and cpuset_mutex. Only cpuset_top_mutex + * is still being held for mutual exclusion. + */ + mutex_unlock(&cpuset_mutex); + cpus_read_unlock(); + WARN_ON_ONCE(housekeeping_update(isolated_hk_cpus, BIT(HK_TYPE_DOMAIN))); + mutex_unlock(&cpuset_top_mutex); } =20 /* @@ -3692,10 +3695,11 @@ int __init cpuset_init(void) =20 BUG_ON(!alloc_cpumask_var(&cpus_attach, GFP_KERNEL)); =20 - if (housekeeping_enabled(HK_TYPE_DOMAIN_BOOT)) + if (housekeeping_enabled(HK_TYPE_DOMAIN_BOOT)) { cpumask_andnot(isolated_cpus, cpu_possible_mask, housekeeping_cpumask(HK_TYPE_DOMAIN_BOOT)); - + cpumask_copy(isolated_hk_cpus, isolated_cpus); + } return 0; } =20 --=20 2.53.0 From nobody Tue Jun 16 20:36:48 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9491739DBD9 for ; Tue, 21 Apr 2026 03:07:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776740854; cv=none; b=GUJrncl3wRmH+C7JnYVIGTvxVqiFT76U5H7zUpk2atHeL/uZXBSB+hKZ/Sk4fyBdTNI6x/E0Do9s5uMhWA9RTVta/c+WBRsY+9Q0o29GqA/dD1nQf4kW/Ix023HvNkO+XQsz7d0ES4spU9Ew/Cv4uksTYW3orgidDbaM2R4CVK8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776740854; c=relaxed/simple; bh=y4yP5tRZ7eQlB15SkfEhgLy4KCCMqsQOclN9c++lXS8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IX38Y6ozJiibiidYQd5GMcsuw2hK1NcfT/6NUYbY1JYwnIdtG1NQib1Mqu1z8BlqopZAPEf5DgPtQlAjnJ8EHf8ePsDp481lxNZgbHGrVfcnKtFhorcGVXIabo8TQ5fI9nXQ+niL83iRlW6pCNu9KEPdDE7RtP/chkiK3/GWHs8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=LOELoH6H; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="LOELoH6H" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776740851; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rj/Vtbhr3JXvU2mTPHbZebZmch25NsVuRvhs8pJ62G8=; b=LOELoH6Hqx+wrUrKc/qDfcmQMfkQI/3rdEIcISnu09umJcvoqLUb9M6aoUB6ssnxeKvvKN wyo9oAfZ6TANVBR1HDSAGsbNM6qkKPABqI8hXU95vDOQUNxK1tFZ4DpmVlAMLIoTab+MqM tAw07NdeE1tWWrcG2yxKEXFF2mj2ITU= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-436-SDq97JYuPx29ycCUXIoJEQ-1; Mon, 20 Apr 2026 23:07:26 -0400 X-MC-Unique: SDq97JYuPx29ycCUXIoJEQ-1 X-Mimecast-MFC-AGG-ID: SDq97JYuPx29ycCUXIoJEQ_1776740841 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5189019560B9; Tue, 21 Apr 2026 03:07:21 +0000 (UTC) Received: from llong-thinkpadp16vgen1.westford.csb (unknown [10.22.65.81]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6E7F419560AB; Tue, 21 Apr 2026 03:07:14 +0000 (UTC) From: Waiman Long To: Tejun Heo , Johannes Weiner , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Jonathan Corbet , Shuah Khan , Catalin Marinas , Will Deacon , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li , Guenter Roeck , Frederic Weisbecker , "Paul E. McKenney" , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Boqun Feng , Uladzislau Rezki , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Zqiang , Anna-Maria Behnsen , Ingo Molnar , Thomas Gleixner , Chen Ridong , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-hwmon@vger.kernel.org, rcu@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Costa Shulyupin , Qiliang Yuan , Waiman Long Subject: [PATCH 20/23] cgroup/cpuset: Enable runtime update of HK_TYPE_{KERNEL_NOISE,MANAGED_IRQ} cpumasks Date: Mon, 20 Apr 2026 23:03:48 -0400 Message-ID: <20260421030351.281436-21-longman@redhat.com> In-Reply-To: <20260421030351.281436-1-longman@redhat.com> References: <20260421030351.281436-1-longman@redhat.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 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" One simple way to enable runtime update of HK_TYPE_KERNEL_NOISE (nohz_full) and HK_TYPE_MANAGED_IRQ cpumasks is to make use of the CPU hotplug to facilitate the transition of those CPUs that are changing states as long as CONFIG_HOTPLUG_CPU is enabled and a nohz_full boot parameter is provided. Otherwise, only HK_TYPE_DOMAIN cpumask will be updated at run time. For changes in HK_TYPE_DOMAIN cpumask, it can be done without using CPU hotplug. For changes in HK_TYPE_MANAGED_IRQ cpumask, we have to update the cpumask first and then tear down and bring up the newly isolated CPUs to migrate the managed irqs in those CPUs to other housekeeping CPUs. For changes in HK_TYPE_KERNEL_NOISE, we have to tear down all the newly isolated and de-isolated CPUs, change the cpumask and then bring all the offline CPUs back online. As it is possible that the various boot versions of the housekeeping cpumasks are different resulting in the use of different set of isolated cpumasks for calling housekeeping_update(), we may need to pre-allocate these cpumasks if necessary. Note that the use of CPU hotplug to facilitate the changing of HK_TYPE_KERNEL_NOISE and HK_TYPE_MANAGED_IRQ housekeeping cpumasks has the drawback that during the tear down of a CPU from CPUHP_TEARDOWN_CPU state to CPUHP_AP_OFFLINE, the stop_machine code will be invoked to stop all the other CPUs including all the pre-existing isolated CPUs. That will cause latency spikes on those isolated CPUs. That latency spike should only happen when the cpuset isolated partition setting is changed resulting in changes in those housekeeping cpumasks. One possible workaround that is being used right now is to pre-allocate a set of nohz_full and managed_irq CPUs at boot time. The semi-isolated CPUs are then used to create cpuset isolated partitions when needed to enable full isolation. This will likely continue even if we made the nohz_full and managed_irq CPUs runtime changeable if they can't tolerate these latency spikes. This is a problem we need to address in a future patch series. Signed-off-by: Waiman Long --- kernel/cgroup/cpuset.c | 199 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 182 insertions(+), 17 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 1b0c50b46a49..a927b9cd4f71 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -152,9 +152,17 @@ static cpumask_var_t isolated_cpus; /* CSCB */ static bool update_housekeeping; /* RWCS */ =20 /* - * Copy of isolated_cpus to be passed to housekeeping_update() + * Cpumasks to be passed to housekeeping_update() + * isolated_hk_cpus - copy of isolated_cpus for HK_TYPE_DOMAIN + * isolated_nohz_cpus - for HK_TYPE_KERNEL_NOISE + * isolated_mirq_cpus - for HK_TYPE_MANAGED_IRQ */ static cpumask_var_t isolated_hk_cpus; /* T */ +static cpumask_var_t isolated_nohz_cpus; /* T */ +static cpumask_var_t isolated_mirq_cpus; /* T */ + +static bool boot_nohz_le_domain __ro_after_init; +static bool boot_mirq_le_domain __ro_after_init; =20 /* * A flag to force sched domain rebuild at the end of an operation. @@ -1328,29 +1336,67 @@ static bool prstate_housekeeping_conflict(int prsta= te, struct cpumask *new_cpus) return false; } =20 +static int cpuset_nohz_update_cbfunc(void *arg) +{ + struct cpumask *isol_cpus =3D (struct cpumask *)arg; + + if (isol_cpus) + housekeeping_update(isol_cpus, BIT(HK_TYPE_KERNEL_NOISE)); + return 0; +} + /* - * cpuset_update_sd_hk_unlock - Rebuild sched domains, update HK & unlock - * - * Update housekeeping cpumasks and rebuild sched domains if necessary and - * then do a cpuset_full_unlock(). - * This should be called at the end of cpuset operation. */ -static void cpuset_update_sd_hk_unlock(void) - __releases(&cpuset_mutex) - __releases(&cpuset_top_mutex) +static void cpuset_update_housekeeping_unlock(void) { - update_housekeeping =3D false; + bool update_nohz, update_mirq; + cpumask_var_t cpus; + int ret; =20 - /* force_sd_rebuild will be cleared in rebuild_sched_domains_locked() */ - if (force_sd_rebuild) - rebuild_sched_domains_locked(); + if (!tick_nohz_full_enabled()) + return; =20 - if (cpumask_equal(isolated_hk_cpus, isolated_cpus)) { - /* No housekeeping cpumask update needed */ + update_nohz =3D boot_nohz_le_domain; + update_mirq =3D boot_mirq_le_domain; + + if (WARN_ON_ONCE(!alloc_cpumask_var(&cpus, GFP_KERNEL))) { cpuset_full_unlock(); return; } =20 + /* + * Update isolated_nohz_cpus/isolated_mirq_cpus if necessary + */ + if (!boot_nohz_le_domain) { + cpumask_andnot(cpus, cpu_possible_mask, + housekeeping_cpumask(HK_TYPE_KERNEL_NOISE)); + cpumask_or(cpus, cpus, isolated_cpus); + update_nohz =3D !cpumask_equal(isolated_nohz_cpus, cpus); + if (update_nohz) + cpumask_copy(isolated_nohz_cpus, cpus); + } + if (!boot_mirq_le_domain) { + cpumask_andnot(cpus, cpu_possible_mask, + housekeeping_cpumask(HK_TYPE_MANAGED_IRQ)); + cpumask_or(cpus, cpus, isolated_cpus); + update_mirq =3D !cpumask_equal(isolated_mirq_cpus, cpus); + if (update_mirq) + cpumask_copy(isolated_mirq_cpus, cpus); + } + + /* + * Compute list of CPUs to be brought offline into "cpus" + * isolated_hk_cpus - old cpumask + * isolated_cpus - new cpumask + * + * With update_nohz, we need to offline both the newly isolated + * and de-isolated CPUs. With only update_mirq, we only need to + * offline the new isolated CPUs. + */ + if (update_nohz) + cpumask_xor(cpus, isolated_hk_cpus, isolated_cpus); + else if (update_mirq) + cpumask_andnot(cpus, isolated_cpus, isolated_hk_cpus); cpumask_copy(isolated_hk_cpus, isolated_cpus); =20 /* @@ -1360,10 +1406,103 @@ static void cpuset_update_sd_hk_unlock(void) */ mutex_unlock(&cpuset_mutex); cpus_read_unlock(); - WARN_ON_ONCE(housekeeping_update(isolated_hk_cpus, BIT(HK_TYPE_DOMAIN))); + + if (!update_mirq) { + ret =3D housekeeping_update(isolated_hk_cpus, BIT(HK_TYPE_DOMAIN)); + } else if (boot_mirq_le_domain) { + ret =3D housekeeping_update(isolated_hk_cpus, + BIT(HK_TYPE_DOMAIN)|BIT(HK_TYPE_MANAGED_IRQ)); + } else { + ret =3D housekeeping_update(isolated_hk_cpus, BIT(HK_TYPE_DOMAIN)); + if (!ret) + ret =3D housekeeping_update(isolated_mirq_cpus, + BIT(HK_TYPE_MANAGED_IRQ)); + } + + if (WARN_ON_ONCE(ret)) + goto out_free; + + /* + * Calling cpuhp_offline_cb() is only needed if either + * HK_TYPE_KERNEL_NOISE and/or HK_TYPE_MANAGED_IRQ cpumasks + * needed to be updated. + * + * TODO: When tearing down a CPU from CPUHP_TEARDOWN_CPU state + * downward to CPUHP_AP_OFFLINE, the stop_machine code will be + * invoked to stop all the other CPUs in the system. This will + * cause latency spikes on existing isolated CPUs. We will need + * some new mechanism to enable us to not stop the existing + * isolated CPUs whenever possible. A possible workaround is + * to pre-allocate a set of nohz_full and manged_irq CPUs at + * boot time and use them to create isolated cpuset partitions + * so that CPU hotplug won't need to be used. + */ + if (update_mirq || update_nohz) { + struct cpumask *nohz_cpus; + + /* + * Calling housekeeping_update() is only needed if + * update_nohz is set. + */ + nohz_cpus =3D !update_nohz ? NULL : boot_nohz_le_domain + ? isolated_hk_cpus + : isolated_nohz_cpus; + /* + * Mask out offline CPUs in cpus + * If there is no online CPUs, we can call + * housekeeping_update() directly if needed. + */ + cpumask_and(cpus, cpus, cpu_online_mask); + if (!cpumask_empty(cpus)) + ret =3D cpuhp_offline_cb(cpus, cpuset_nohz_update_cbfunc, + nohz_cpus); + else if (nohz_cpus) + ret =3D housekeeping_update(nohz_cpus, BIT(HK_TYPE_KERNEL_NOISE)); + } + WARN_ON_ONCE(ret); +out_free: + free_cpumask_var(cpus); mutex_unlock(&cpuset_top_mutex); } =20 +/* + * cpuset_update_sd_hk_unlock - Rebuild sched domains, update HK & unlock + * + * Update housekeeping cpumasks and rebuild sched domains if necessary and + * then do a cpuset_full_unlock(). + * This should be called at the end of cpuset operation. + */ +static void cpuset_update_sd_hk_unlock(void) + __releases(&cpuset_mutex) + __releases(&cpuset_top_mutex) +{ + /* force_sd_rebuild will be cleared in rebuild_sched_domains_locked() */ + if (force_sd_rebuild) + rebuild_sched_domains_locked(); + + update_housekeeping =3D false; + + if (cpumask_equal(isolated_cpus, isolated_hk_cpus)) { + cpuset_full_unlock(); + return; + } + + if (!tick_nohz_full_enabled()) { + /* + * housekeeping_update() is now called without holding + * cpus_read_lock and cpuset_mutex. Only cpuset_top_mutex + * is still being held for mutual exclusion. + */ + mutex_unlock(&cpuset_mutex); + cpus_read_unlock(); + WARN_ON_ONCE(housekeeping_update(isolated_hk_cpus, + BIT(HK_TYPE_DOMAIN))); + mutex_unlock(&cpuset_top_mutex); + } else { + cpuset_update_housekeeping_unlock(); + } +} + /* * Work function to invoke cpuset_update_sd_hk_unlock() */ @@ -3700,6 +3839,29 @@ int __init cpuset_init(void) housekeeping_cpumask(HK_TYPE_DOMAIN_BOOT)); cpumask_copy(isolated_hk_cpus, isolated_cpus); } + + /* + * If nohz_full and/or managed_irq cpu list, if present, is a subset + * of the domain cpu list, i.e. HK_TYPE_DOMAIN_BOOT cpumask is a subset + * of HK_TYPE_KERNEL_NOISE_BOOT/HK_TYPE_MANAGED_IRQ_BOOT cpumask, the + * corresponding non-boot housekeeping cpumasks will follow changes + * in the HK_TYPE_DOMAIN cpumask. So we don't need to use separate + * cpumasks to isolate them. + */ + boot_nohz_le_domain =3D cpumask_subset(housekeeping_cpumask(HK_TYPE_DOMAI= N_BOOT), + housekeeping_cpumask(HK_TYPE_KERNEL_NOISE_BOOT)); + boot_mirq_le_domain =3D cpumask_subset(housekeeping_cpumask(HK_TYPE_DOMAI= N_BOOT), + housekeeping_cpumask(HK_TYPE_MANAGED_IRQ_BOOT)); + if (!boot_nohz_le_domain) { + BUG_ON(!alloc_cpumask_var(&isolated_nohz_cpus, GFP_KERNEL)); + cpumask_andnot(isolated_nohz_cpus, cpu_possible_mask, + housekeeping_cpumask(HK_TYPE_KERNEL_NOISE)); + } + if (!boot_mirq_le_domain) { + BUG_ON(!alloc_cpumask_var(&isolated_mirq_cpus, GFP_KERNEL)); + cpumask_andnot(isolated_mirq_cpus, cpu_possible_mask, + housekeeping_cpumask(HK_TYPE_MANAGED_IRQ)); + } return 0; } =20 @@ -3954,7 +4116,10 @@ static void cpuset_handle_hotplug(void) */ if (force_sd_rebuild) rebuild_sched_domains_cpuslocked(); - if (update_housekeeping) + /* + * Don't need to update housekeeping cpumasks in cpuhp_offline_cb mode. + */ + if (update_housekeeping && !cpuhp_offline_cb_mode) queue_work(system_dfl_wq, &hk_sd_work); =20 free_tmpmasks(ptmp); --=20 2.53.0 From nobody Tue Jun 16 20:36:48 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E49339F181 for ; Tue, 21 Apr 2026 03:07:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776740859; cv=none; b=BFrQht8qcCo+/RvFU0Ah5wVZOQrhmWSDdAC0m3TJd926+wQt/cTx5V5ucazVhCmQ2FFO2F1L/7Fi4eGNCVsLBOBEjAGkKUcB2ZYpGLM7mk8iysVcTYsf66TQdNDRDIYRK7Nvyf7H9ZmLQattE58Dv3c89XTqQWs+yCCtVum1kMQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776740859; c=relaxed/simple; bh=KY9RWTeYpkME766HcWMc5adAT4G/1XXfate7fAfO6ps=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Otu/OBNK04bv4Bs7GorqZSJUPv3q0awU91ukFcIhw9rQ69AMmHLqMYHNRcYQZ2i/fCkyJp2WUd1OxfrMylhCXcPWkGXiR0md2REwD3eGXaCXBPeXkX5j6xCJE+eP7+9z0bPlAKlrsj+CiEIyRcK6z37foVyhe4gIA4AlDSKxztc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=JS7Q/wv7; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="JS7Q/wv7" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776740857; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5PuhRkn96CiNoOus+r7NzZUWwV4LXmvzWiP5TcnJ3DQ=; b=JS7Q/wv74sQ99nr8jt7eLeMv7gnTV2xWPgITXxqJ2K7CUe0GK//PUSWEfi7mHYVnVnYl3z Og6K0zhQWsB5jGJtq65onOcfH6N5dQQ4B/UQs3hv+A9//zgVxnvEixu1SN3GREJIob5Jx6 khe9n4Uf2YbTVB7WGiRXNbCgz7l8oZw= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-693-vlbhX3RZO5W5EvKJ9lg_wg-1; Mon, 20 Apr 2026 23:07:34 -0400 X-MC-Unique: vlbhX3RZO5W5EvKJ9lg_wg-1 X-Mimecast-MFC-AGG-ID: vlbhX3RZO5W5EvKJ9lg_wg_1776740849 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2586F195608B; Tue, 21 Apr 2026 03:07:29 +0000 (UTC) Received: from llong-thinkpadp16vgen1.westford.csb (unknown [10.22.65.81]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8A8FA19560AB; Tue, 21 Apr 2026 03:07:21 +0000 (UTC) From: Waiman Long To: Tejun Heo , Johannes Weiner , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Jonathan Corbet , Shuah Khan , Catalin Marinas , Will Deacon , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li , Guenter Roeck , Frederic Weisbecker , "Paul E. McKenney" , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Boqun Feng , Uladzislau Rezki , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Zqiang , Anna-Maria Behnsen , Ingo Molnar , Thomas Gleixner , Chen Ridong , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-hwmon@vger.kernel.org, rcu@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Costa Shulyupin , Qiliang Yuan , Waiman Long Subject: [PATCH 21/23] cgroup/cpuset: Limit the side effect of using CPU hotplug on isolated partition Date: Mon, 20 Apr 2026 23:03:49 -0400 Message-ID: <20260421030351.281436-22-longman@redhat.com> In-Reply-To: <20260421030351.281436-1-longman@redhat.com> References: <20260421030351.281436-1-longman@redhat.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 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" CPU hotplug is used to facilitate the modification of the HK_TYPE_KERNEL_NOISE and HK_TYPE_MANAGED_IRQ cpumasks. However, tearing down and bringing up CPUs can impact the cpuset partition states as well. For instance, tearing down the last CPU of a partition can invalidate the partition with active tasks which will not happen if CPU hotplug isn't used. A workaround of this issue is disable the invalidation by pretending that the partition has no task, and making the tasks within the partition to the effective CPUs of its parent for a short while during the short transition process where the CPUs will be teared down and the brought up again. Signed-off-by: Waiman Long --- kernel/cgroup/cpuset.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index a927b9cd4f71..5f6b4e67748f 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -434,6 +434,13 @@ static inline bool partition_is_populated(struct cpuse= t *cs, struct cpuset *cp; struct cgroup_subsys_state *pos_css; =20 + /* + * Hack: In cpuhp_offline_cb_mode, pretend all partitions are empty + * to prevent unnecessary partition invalidation. + */ + if (cpuhp_offline_cb_mode) + return false; + /* * We cannot call cs_is_populated(cs) directly, as * nr_populated_domain_children may include populated @@ -3881,6 +3888,17 @@ hotplug_update_tasks(struct cpuset *cs, cs->effective_mems =3D *new_mems; spin_unlock_irq(&callback_lock); =20 + /* + * When cpuhp_offline_cb_mode is active, valid isolated partition + * with tasks may have no online CPUs available for a short while. + * In that case, we fall back to parent's effective CPUs temporarily + * which will be reset back to their rightful value once the affected + * CPUs are online again. + */ + if (cpuhp_offline_cb_mode && cpumask_empty(new_cpus) && + (cs->partition_root_state =3D=3D PRS_ISOLATED)) + cpumask_copy(new_cpus, parent_cs(cs)->effective_cpus); + if (cpus_updated) cpuset_update_tasks_cpumask(cs, new_cpus); if (mems_updated) --=20 2.53.0 From nobody Tue Jun 16 20:36:48 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E7C8737DE96 for ; Tue, 21 Apr 2026 03:07:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776740867; cv=none; b=gkJPXM/MHVSHrJ1kyoykxOxMZAUsmUcs4dHmmGq0e+ZNoVlZNR/SSSq/kvRUs3b3K1nVygFkbVaq9eFz30SDm4TLJz4jb7iektk3e9nf70LNSEuo/W5Q2Bl5lvZUoNSqlR3VMF7HQF+YVVVYDsnFPMOUZXcfQFDvfyWBpapMh1k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776740867; c=relaxed/simple; bh=Qgh3Rtjk2sr92+QFAulS1sInUiw/DjGtzsAE3YOzHGU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DEap6kQFBOhJjyxEOUc/VU99Fu6BErMkcvvxVZwS+ySb6dqYVCM655hK0wg+iE46qYh2jIfhS/eL0fSNL0XJIPcKeaN9UE1nc7HnZa08LBrbbrrjI+5VZStAl0ntN/EGHVuSKu2c9Scn3HacXntATc9ezTufsTPXVgO2BPh9xMA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=CSjJ6Nw6; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="CSjJ6Nw6" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776740865; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T0PwgcY00dmEA7hW8N56Wi13Enoq6qNEhgoYsfVh+9A=; b=CSjJ6Nw6+MkBopdqrtDyi9l7RNZfBGNU/1rjVyIPx/t4P+Ci+26yqzM9nEQobH+cQRL70w jlmjFV7/cWRX14nzH57KlnFKNrQm7d6f8jFhrBuo4cWn7JS+jUPDlPWmTEnQh9JFKrtuol 9zbiXrWBZfegWlnrMARELDOgMBfBvOI= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-660-oW13N3nrN_K8wRsUogg44g-1; Mon, 20 Apr 2026 23:07:41 -0400 X-MC-Unique: oW13N3nrN_K8wRsUogg44g-1 X-Mimecast-MFC-AGG-ID: oW13N3nrN_K8wRsUogg44g_1776740856 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A40451800358; Tue, 21 Apr 2026 03:07:36 +0000 (UTC) Received: from llong-thinkpadp16vgen1.westford.csb (unknown [10.22.65.81]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5E4F719560AB; Tue, 21 Apr 2026 03:07:29 +0000 (UTC) From: Waiman Long To: Tejun Heo , Johannes Weiner , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Jonathan Corbet , Shuah Khan , Catalin Marinas , Will Deacon , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li , Guenter Roeck , Frederic Weisbecker , "Paul E. McKenney" , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Boqun Feng , Uladzislau Rezki , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Zqiang , Anna-Maria Behnsen , Ingo Molnar , Thomas Gleixner , Chen Ridong , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-hwmon@vger.kernel.org, rcu@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Costa Shulyupin , Qiliang Yuan , Waiman Long Subject: [PATCH 22/23] cgroup/cpuset: Prevent offline_disabled CPUs from being used in isolated partition Date: Mon, 20 Apr 2026 23:03:50 -0400 Message-ID: <20260421030351.281436-23-longman@redhat.com> In-Reply-To: <20260421030351.281436-1-longman@redhat.com> References: <20260421030351.281436-1-longman@redhat.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 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" If tick_nohz_full_enabled() is true, we are going to use CPU hotplug to enable runtime changes to the HK_TYPE_KERNEL_NOISE and HK_TYPE_MANAGED_IRQ cpumasks. However, for some architectures, one or maybe more CPUs will have the offline_disabled flag set in their cpu devices. For instance, x64-64 will set this flag for its boot CPU (typically CPU 0) to disable it from going offline. Those CPUs can't be used in cpuset isolated partition, or we are going to have problem in the CPU offline process. Find out the set of CPUs with offline_disabled set in a new cpuset_init_late() helper, set the corresponding bits in offline_disabled_cpus cpumask and check it when isolated partitions are being created or modified to ensure that we will not use any of those offline disabled CPUs in an isolated partition. An error message mentioning those offline disabled CPUs will be constructed in cpuset_init_late() and shown in "cpuset.cpus.partition" when isolated creation or modification fails. Signed-off-by: Waiman Long --- kernel/cgroup/cpuset-internal.h | 1 + kernel/cgroup/cpuset.c | 89 ++++++++++++++++++++++++++++++++- 2 files changed, 88 insertions(+), 2 deletions(-) diff --git a/kernel/cgroup/cpuset-internal.h b/kernel/cgroup/cpuset-interna= l.h index fd7d19842ded..87b7411540ff 100644 --- a/kernel/cgroup/cpuset-internal.h +++ b/kernel/cgroup/cpuset-internal.h @@ -35,6 +35,7 @@ enum prs_errcode { PERR_HKEEPING, PERR_ACCESS, PERR_REMOTE, + PERR_OL_DISABLED, }; =20 /* bits in struct cpuset flags field */ diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 5f6b4e67748f..f3af8ef6c64e 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -20,6 +20,8 @@ */ #include "cpuset-internal.h" =20 +#include +#include #include #include #include @@ -48,7 +50,7 @@ DEFINE_STATIC_KEY_FALSE(cpusets_enabled_key); */ DEFINE_STATIC_KEY_FALSE(cpusets_insane_config_key); =20 -static const char * const perr_strings[] =3D { +static const char *perr_strings[] __ro_after_init =3D { [PERR_INVCPUS] =3D "Invalid cpu list in cpuset.cpus.exclusive", [PERR_INVPARENT] =3D "Parent is an invalid partition root", [PERR_NOTPART] =3D "Parent is not a partition root", @@ -59,6 +61,7 @@ static const char * const perr_strings[] =3D { [PERR_HKEEPING] =3D "partition config conflicts with housekeeping setup", [PERR_ACCESS] =3D "Enable partition not permitted", [PERR_REMOTE] =3D "Have remote partition underneath", + [PERR_OL_DISABLED] =3D "", /* To be set up later */ }; =20 /* @@ -164,6 +167,12 @@ static cpumask_var_t isolated_mirq_cpus; /* T */ static bool boot_nohz_le_domain __ro_after_init; static bool boot_mirq_le_domain __ro_after_init; =20 +/* + * Cpumask of CPUs with offline_disabled set + * The cpumask is effectively __ro_after_init. + */ +static cpumask_var_t offline_disabled_cpus; + /* * A flag to force sched domain rebuild at the end of an operation. * It can be set in @@ -1649,6 +1658,8 @@ static int remote_partition_enable(struct cpuset *cs,= int new_prs, * The effective_xcpus mask can contain offline CPUs, but there must * be at least one or more online CPUs present before it can be enabled. * + * An isolated partition cannot contain CPUs with offline disabled. + * * Note that creating a remote partition with any local partition root * above it or remote partition root underneath it is not allowed. */ @@ -1661,6 +1672,9 @@ static int remote_partition_enable(struct cpuset *cs,= int new_prs, !isolated_cpus_can_update(tmp->new_cpus, NULL)) || prstate_housekeeping_conflict(new_prs, tmp->new_cpus)) return PERR_HKEEPING; + if (tick_nohz_full_enabled() && (new_prs =3D=3D PRS_ISOLATED) && + cpumask_intersects(tmp->new_cpus, offline_disabled_cpus)) + return PERR_OL_DISABLED; =20 spin_lock_irq(&callback_lock); partition_xcpus_add(new_prs, NULL, tmp->new_cpus); @@ -1746,6 +1760,16 @@ static void remote_cpus_update(struct cpuset *cs, st= ruct cpumask *xcpus, goto invalidate; } =20 + /* + * Isolated partition cannot contains CPUs with offline_disabled + * bit set. + */ + if (tick_nohz_full_enabled() && (prs =3D=3D PRS_ISOLATED) && + cpumask_intersects(excpus, offline_disabled_cpus)) { + cs->prs_err =3D PERR_OL_DISABLED; + goto invalidate; + } + adding =3D cpumask_andnot(tmp->addmask, excpus, cs->effective_xcpus); deleting =3D cpumask_andnot(tmp->delmask, cs->effective_xcpus, excpus); =20 @@ -1913,6 +1937,11 @@ static int update_parent_effective_cpumask(struct cp= uset *cs, int cmd, if (tasks_nocpu_error(parent, cs, xcpus)) return PERR_NOCPUS; =20 + if (tick_nohz_full_enabled() && + (new_prs =3D=3D PRS_ISOLATED) && + cpumask_intersects(xcpus, offline_disabled_cpus)) + return PERR_OL_DISABLED; + /* * This function will only be called when all the preliminary * checks have passed. At this point, the following condition @@ -1979,12 +2008,21 @@ static int update_parent_effective_cpumask(struct c= puset *cs, int cmd, parent->effective_xcpus); } =20 + /* + * Isolated partition cannot contain CPUs with offline_disabled + * bit set. + */ + if (tick_nohz_full_enabled() && + ((old_prs =3D=3D PRS_ISOLATED) || + (old_prs =3D=3D PRS_INVALID_ISOLATED)) && + cpumask_intersects(newmask, offline_disabled_cpus)) { + part_error =3D PERR_OL_DISABLED; /* * TBD: Invalidate a currently valid child root partition may * still break isolated_cpus_can_update() rule if parent is an * isolated partition. */ - if (is_partition_valid(cs) && (old_prs !=3D parent_prs)) { + } else if (is_partition_valid(cs) && (old_prs !=3D parent_prs)) { if ((parent_prs =3D=3D PRS_ROOT) && /* Adding to parent means removing isolated CPUs */ !isolated_cpus_can_update(tmp->delmask, tmp->addmask)) @@ -1995,6 +2033,19 @@ static int update_parent_effective_cpumask(struct cp= uset *cs, int cmd, part_error =3D PERR_HKEEPING; } =20 + if (part_error) { + deleting =3D false; + /* + * For a previously valid partition, we need to move + * the exclusive CPUs back to its parent. + */ + if (is_partition_valid(cs) && + !cpumask_empty(cs->effective_xcpus)) { + cpumask_copy(tmp->addmask, cs->effective_xcpus); + adding =3D true; + } + } + /* * The new CPUs to be removed from parent's effective CPUs * must be present. @@ -3829,6 +3880,7 @@ int __init cpuset_init(void) BUG_ON(!zalloc_cpumask_var(&subpartitions_cpus, GFP_KERNEL)); BUG_ON(!zalloc_cpumask_var(&isolated_cpus, GFP_KERNEL)); BUG_ON(!zalloc_cpumask_var(&isolated_hk_cpus, GFP_KERNEL)); + BUG_ON(!zalloc_cpumask_var(&offline_disabled_cpus, GFP_KERNEL)); =20 cpumask_setall(top_cpuset.cpus_allowed); nodes_setall(top_cpuset.mems_allowed); @@ -4188,6 +4240,39 @@ void __init cpuset_init_smp(void) BUG_ON(!cpuset_migrate_mm_wq); } =20 +/** + * cpuset_init_late - initialize the list of CPUs with offline_disabled set + * + * Description: Initialize a cpumask with CPUs that have the offline_disab= led + * bit set. It is done in a separate initcall as cpuset_init_smp() + * is called before driver_init() where the CPU devices will be + * set up. + */ +static int __init cpuset_init_late(void) +{ + int cpu; + + if (!tick_nohz_full_enabled()) + return 0; + /* + * Iterate all the possible CPUs to see which one has offline disabled. + */ + for_each_possible_cpu(cpu) { + if (get_cpu_device(cpu)->offline_disabled) + __cpumask_set_cpu(cpu, offline_disabled_cpus); + } + if (!cpumask_empty(offline_disabled_cpus)) { + char buf[128]; + + snprintf(buf, sizeof(buf), + "CPU %*pbl with offline disabled not allowed in isolated partition", + cpumask_pr_args(offline_disabled_cpus)); + perr_strings[PERR_OL_DISABLED] =3D kstrdup(buf, GFP_KERNEL); + } + return 0; +} +pure_initcall(cpuset_init_late); + /* * Return cpus_allowed mask from a task's cpuset. */ --=20 2.53.0 From nobody Tue Jun 16 20:36:48 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0D164378D64 for ; Tue, 21 Apr 2026 03:07:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776740876; cv=none; b=bm7EEh6/n6G3FroZZ5TSIGADA9HkQVt5evmspG+tXSGHwX7XlGDq4wuwCu7/KCRAEHciBkICMIlauBixBdyOboSy+LXTLzzFVJkm2ZufZWGMWy8ebgVW1Z4pO+HgHPipBv/Wh8N3nlu+iLPGIZ2BWLuVHbWzqxSs2U1QjiDAm+c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776740876; c=relaxed/simple; bh=pdahzaI6TYYLoH1na7BPnX7x2KDai2pfXdzq/9hklYw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DNUIpv/w1Jra2kzcykmk5Ca6zystXrsKNkBfLnkf/0PEFzDYFbI21J42Mvi+hU5LocB9BdLUR07BxTSdl2JatoPzNNLqVd9PM/zvKIZ1nRkUl90hOmdoYArH8dDQyacnCoraK+LYhHY3K/2NKmLSpdJ9eMK19Ya6oH0KmU4pgC8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Bm9x71Zw; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Bm9x71Zw" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776740874; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=id5gu+CSXzoxxDihrOTSOMQURNR0EZCi73AeA6doMCM=; b=Bm9x71ZwYqhNoTiKmYPwc6BBhyIMnMlZyMS2VKu81R1meaWt5epLNi1ZgB0jBfn41au6nc whNxBb+0S5c5OeIW//tQehOFlwOLwtrvRkt7hV+XZ+Q+J8lAc9qrzWwELazeObiFFA97Pe 4qs55BOtEHNMeYjScNjONJc3UdI5PaY= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-113-eswoHUPCNHOcZgPwTq7aKQ-1; Mon, 20 Apr 2026 23:07:48 -0400 X-MC-Unique: eswoHUPCNHOcZgPwTq7aKQ-1 X-Mimecast-MFC-AGG-ID: eswoHUPCNHOcZgPwTq7aKQ_1776740863 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id AFC621800367; Tue, 21 Apr 2026 03:07:43 +0000 (UTC) Received: from llong-thinkpadp16vgen1.westford.csb (unknown [10.22.65.81]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C546C19560AB; Tue, 21 Apr 2026 03:07:36 +0000 (UTC) From: Waiman Long To: Tejun Heo , Johannes Weiner , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Jonathan Corbet , Shuah Khan , Catalin Marinas , Will Deacon , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li , Guenter Roeck , Frederic Weisbecker , "Paul E. McKenney" , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Boqun Feng , Uladzislau Rezki , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Zqiang , Anna-Maria Behnsen , Ingo Molnar , Thomas Gleixner , Chen Ridong , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-hwmon@vger.kernel.org, rcu@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, Costa Shulyupin , Qiliang Yuan , Waiman Long Subject: [PATCH 23/23] cgroup/cpuset: Documentation and kselftest updates Date: Mon, 20 Apr 2026 23:03:51 -0400 Message-ID: <20260421030351.281436-24-longman@redhat.com> In-Reply-To: <20260421030351.281436-1-longman@redhat.com> References: <20260421030351.281436-1-longman@redhat.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 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" As CPU hotplug is now being used to enable runtime update to the list of nohz_full and managed_irq CPUs, we should avoid using CPU 0 in the formation of isolated partition as CPU 0 may not be able to be brought offline like in the case of x86-64 architecture. So a number of the test cases in test_cpuset_prs.sh will have to be updated accordingly. A new test will also be run in offline isn't allowed in CPU 0 to verify that using CPU 0 as part of an isolated partition will fail. The cgroup-v2.rst is also updated to reflect the new capability of using CPU hotplug to enable run time change to the nohz_full and managed_irq CPU lists. Since there is a slight performance overhead to enable runtime changes to nohz_full CPU list, users have to explicitly opt in by adding a "nohz_ful" kernel command line parameter with or without a CPU list. Signed-off-by: Waiman Long --- Documentation/admin-guide/cgroup-v2.rst | 35 +++++++--- .../selftests/cgroup/test_cpuset_prs.sh | 70 +++++++++++++++++-- 2 files changed, 92 insertions(+), 13 deletions(-) diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-= guide/cgroup-v2.rst index 8ad0b2781317..e97fc031eb86 100644 --- a/Documentation/admin-guide/cgroup-v2.rst +++ b/Documentation/admin-guide/cgroup-v2.rst @@ -2604,11 +2604,12 @@ Cpuset Interface Files =20 It accepts only the following input values when written to. =20 - =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D "member" Non-root member of a partition "root" Partition root - "isolated" Partition root without load balancing - =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + "isolated" Partition root without load balancing and other + OS noises + =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D =20 A cpuset partition is a collection of cpuset-enabled cgroups with a partition root at the top of the hierarchy and its descendants @@ -2652,11 +2653,29 @@ Cpuset Interface Files partition or scheduling domain. The set of exclusive CPUs is determined by the value of its "cpuset.cpus.exclusive.effective". =20 - When set to "isolated", the CPUs in that partition will be in - an isolated state without any load balancing from the scheduler - and excluded from the unbound workqueues. Tasks placed in such - a partition with multiple CPUs should be carefully distributed - and bound to each of the individual CPUs for optimal performance. + When set to "isolated", the CPUs in that partition will be in an + isolated state without any load balancing from the scheduler and + excluded from the unbound workqueues as well as other OS noises. + Tasks placed in such a partition with multiple CPUs should be + carefully distributed and bound to each of the individual CPUs + for optimal performance. + + As CPU hotplug, if supported, is used to improve the degree of + CPU isolation close to the "nohz_full" kernel boot parameter. + In some architectures, like x86-64, the boot CPU (typically CPU + 0) cannot be brought offline, so the boot CPU should not be used + for forming isolated partitions. The "nohz_full" kernel boot + parameter needs to be present to enable full dynticks support + and RCU no-callback CPU mode for CPUs in isolated partitions + even if the optional cpu list isn't provided. + + Using CPU hotplug for creating or destroying an isolated + partition can cause latency spike in applications running + in other isolated partitions. A reserved list of CPUs can + optionally be put in the "nohz_full" kernel boot parameter to + alleviate this problem. When these reserved CPUs are used for + isolated partitions, CPU hotplug won't need to be invoked and + so there won't be latency spike in other isolated partitions. =20 A partition root ("root" or "isolated") can be in one of the two possible states - valid or invalid. An invalid partition diff --git a/tools/testing/selftests/cgroup/test_cpuset_prs.sh b/tools/test= ing/selftests/cgroup/test_cpuset_prs.sh index a56f4153c64d..eebb4122b581 100755 --- a/tools/testing/selftests/cgroup/test_cpuset_prs.sh +++ b/tools/testing/selftests/cgroup/test_cpuset_prs.sh @@ -67,6 +67,12 @@ then echo Y > /sys/kernel/debug/sched/verbose fi =20 +# Enable dynamic debug message if available +DYN_DEBUG=3D/proc/dynamic_debug/control +[[ -f $DYN_DEBUG ]] && { + echo "file kernel/cpu.c +p" > $DYN_DEBUG +} + cd $CGROUP2 echo +cpuset > cgroup.subtree_control =20 @@ -84,6 +90,15 @@ echo member > test/cpuset.cpus.partition echo "" > test/cpuset.cpus [[ $RESULT -eq 0 ]] && skip_test "Child cgroups are using cpuset!" =20 +# +# If nohz_full parameter is specified and nohz_full file exists, CPU hotpl= ug +# will be used to modify nohz_full cpumask to include all the isolated CPUs +# in cpuset isolated partitions. +# +NOHZ_FULL=3D/sys/devices/system/cpu/nohz_full +BOOT_NOHZ_FULL=3D$(fmt -1 /proc/cmdline | grep "^nohz_full") +[[ "$BOOT_NOHZ_FULL" =3D nohz_full ]] && CHK_NOHZ_FULL=3D1 + # # If isolated CPUs have been reserved at boot time (as shown in # cpuset.cpus.isolated), these isolated CPUs should be outside of CPUs 0-8 @@ -318,8 +333,8 @@ TEST_MATRIX=3D( # Invalid to valid local partition direct transition tests " C1-3:P2 X4:P2 . . . . . . 0 A1:1-3|XA1= :1-3|A2:1-3:XA2: A1:P2|A2:P-2 1-3" " C1-3:P2 X4:P2 . . . X3:P2 . . 0 A1:1-2|XA1= :1-3|A2:3:XA2:3 A1:P2|A2:P2 1-3" - " C0-3:P2 . . C4-6 C0-4 . . . 0 A1:0-4|B1:= 5-6 A1:P2|B1:P0" - " C0-3:P2 . . C4-6 C0-4:C0-3 . . . 0 A1:0-3|B1:= 4-6 A1:P2|B1:P0 0-3" + " C1-3:P2 . . C4-6 C1-4 . . . 0 A1:1-4|B1:= 5-6 A1:P2|B1:P0" + " C1-3:P2 . . C4-6 C1-4:C1-3 . . . 0 A1:1-3|B1:= 4-6 A1:P2|B1:P0 1-3" =20 # Local partition invalidation tests " C0-3:X1-3:P2 C1-3:X2-3:P2 C2-3:X3:P2 \ @@ -329,8 +344,8 @@ TEST_MATRIX=3D( " C0-3:X1-3:P2 C1-3:X2-3:P2 C2-3:X3:P2 \ . . C4:X . . 0 A1:1-3|A2:1-3|A3:2-3|XA2:|XA3: = A1:P2|A2:P-2|A3:P-2 1-3" # Local partition CPU change tests - " C0-5:P2 C4-5:P1 . . . C3-5 . . 0 A1:0-2|A2:= 3-5 A1:P2|A2:P1 0-2" - " C0-5:P2 C4-5:P1 . . C1-5 . . . 0 A1:1-3|A2:= 4-5 A1:P2|A2:P1 1-3" + " C1-5:P2 C4-5:P1 . . . C3-5 . . 0 A1:1-2|A2:= 3-5 A1:P2|A2:P1 1-2" + " C1-5:P2 C4-5:P1 . . C2-5 . . . 0 A1:2-3|A2:= 4-5 A1:P2|A2:P1 2-3" =20 # cpus_allowed/exclusive_cpus update tests " C0-3:X2-3 C1-3:X2-3 C2-3:X2-3 \ @@ -442,6 +457,21 @@ TEST_MATRIX=3D( " C0-3 . . C4-5 X3-5 . . . 1 A1:0-3|B1:= 4-5" ) =20 +# +# Test matrix to verify that using CPU 0 in isolated (local or remote) par= tition +# will fail when offline isn't allowed for CPU 0. +# +CPU0_ISOLCPUS_MATRIX=3D( + # old-A1 old-A2 old-A3 old-B1 new-A1 new-A2 new-A3 new-B1 fail ECPUs Pst= ate ISOLCPUS + # ------ ------ ------ ------ ------ ------ ------ ------ ---- ----- ---= --- -------- + " C0-3 . . C4-5 P2 . . . 0 A1:0-3|B1:= 4-5 A1:P-2" + " C1-3 . . . P2 . . . 0 A1:1-3 A1:= P2" + " C1-3 . . . P2:C0-3 . . . 0 A1:0-3 A1:= P-2" + " CX0-3 C0-3 . . . P2 . . 0 A1:0-3|A2:= 0-3 A2:P-2" + " CX0-3 C0-3:X1-3 . . . P2 . . 0 A1:0|A2:1-= 3 A2:P2" + " CX0-3 C0-3:X1-3 . . . P2:X0-3 . . 0 A1:0-3|A2:= 0-3 A2:P-2" +) + # # Cpuset controller remote partition test matrix. # @@ -513,7 +543,7 @@ write_cpu_online() } fi echo $VAL > $CPUFILE - pause 0.05 + pause 0.10 } =20 # @@ -654,6 +684,8 @@ dump_states() [[ -e $PCPUS ]] && echo "$PCPUS: $(cat $PCPUS)" [[ -e $ISCPUS ]] && echo "$ISCPUS: $(cat $ISCPUS)" done + # Dump nohz_full + [[ -f $NOHZ_FULL ]] && echo "nohz_full: $(cat $NOHZ_FULL)" } =20 # @@ -789,6 +821,18 @@ check_isolcpus() EXPECTED_SDOMAIN=3D$EXPECTED_ISOLCPUS fi =20 + # + # Check if nohz_full match cpuset.cpus.isolated if nohz_boot parameter + # specified with no parameter. + # + [[ -f $NOHZ_FULL && "$BOOT_NOHZ_FULL" =3D nohz_full ]] && { + NOHZ_FULL_CPUS=3D$(cat $NOHZ_FULL) + [[ "$ISOLCPUS" !=3D "$NOHZ_FULL_CPUS" ]] && { + echo "nohz_full ($NOHZ_FULL_CPUS) does not match cpuset.cpus.isolated (= $ISOLCPUS)" + return 1 + } + } + # # Appending pre-isolated CPUs # Even though CPU #8 isn't used for testing, it can't be pre-isolated @@ -1070,6 +1114,21 @@ run_remote_state_test() echo "All $I tests of $TEST PASSED." } =20 +# +# Testing CPU 0 isolated partition test when offline is disabled +# +run_cpu0_isol_test() +{ + # Skip the test if CPU0 offline is allowed or if nohz_full kernel + # boot parameter is missing. + CPU0_ONLINE=3D/sys/devices/system/cpu/cpu0/online + [[ -f $CPU0_ONLINE ]] && return + grep -q -w nohz_full /proc/cmdline + [[ $? -ne 0 ]] && return + + run_state_test CPU0_ISOLCPUS_MATRIX +} + # # Testing the new "isolated" partition root type # @@ -1207,6 +1266,7 @@ test_inotify() trap cleanup 0 2 3 6 run_state_test TEST_MATRIX run_remote_state_test REMOTE_TEST_MATRIX +run_cpu0_isol_test test_isolated test_inotify echo "All tests PASSED." --=20 2.53.0