From: <yang.yang29@zte.com.cn>
To: <tglx@linutronix.de>
Cc: <peterz@infradead.org>, <linux-kernel@vger.kernel.org>,
<jiang.xuexin@zte.com.cn>
Subject: [PATCH V2] cpu/hotplug: dont offline the last non-isolated CPU
Date: Tue, 17 Oct 2023 17:09:53 +0800 (CST) [thread overview]
Message-ID: <202310171709530660462@zte.com.cn> (raw)
In-Reply-To: <87lec9l3mi.ffs@tglx>
From: Ran Xiaokai <ran.xiaokai@zte.com.cn>
If system has some isolate cpus with "isolcpus=" parameter,
and user try to offline all the non-isolated CPUs, kernel will
first report a warning and then panic when taking the last
non-isolated CPU offline.
When offline the last non-isolate cpu,
cpuset_hotplug_workfn()
rebuild_sched_domains_locked()
ndoms = generate_sched_domains(&doms, &attr);
cpumask_and(doms[0], top_cpuset.effective_cpus,
housekeeping_cpumask(HK_FLAG_DOMAIN));
As isolated cpus are excluded, "doms" passes to partition_sched_domains_locked()
will be an empty cpumask.
WARNING: CPU: 4 PID: 80 at kernel/sched/topology.c:2366 build_sched_domains+0x120c/0x1408
Call trace:
build_sched_domains+0x120c/0x1408
partition_sched_domains_locked+0x234/0x880
rebuild_sched_domains_locked+0x37c/0x798
rebuild_sched_domains+0x30/0x58
cpuset_hotplug_workfn+0x2a8/0x930
process_scheduled_works+0x178/0x3e0
worker_thread+0x174/0x2f0
---[ end trace 0000000000000000 ]---
Unable to handle kernel paging request at virtual address fffe80027ab37080
partition_sched_domains_locked+0x318/0x880
rebuild_sched_domains_locked+0x37c/0x798
rebuild_sched_domains+0x30/0x58
cpuset_hotplug_workfn+0x2a8/0x930
process_scheduled_works+0x178/0x3e0
worker_thread+0x174/0x2f0
kthread+0x10c/0x128
ret_from_fork+0x10/0x20
Code: 1a850042 b9441883 f862dae0 8b000021 (f945003b)
Kernel should not panic when user managing CPUs with this
meaningless behavior, so we add a check for this, which
prevent user taking the last non-isolated CPU offline.
Signed-off-by: Ran Xiaokai <ran.xiaokai@zte.com.cn>
Suggested-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Yang Yang <yang.yang29@zte.com.cn>
Cc: Xuexin Jiang <jiang.xuexin@zte.com.cn>
---
kernel/cpu.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/kernel/cpu.c b/kernel/cpu.c
index 6de7c6bb74ee..94430ea8b4a5 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -1515,11 +1515,14 @@ static int cpu_down_maps_locked(unsigned int cpu, enum cpuhp_state target)
/*
* Ensure that the control task does not run on the to be offlined
* CPU to prevent a deadlock against cfs_b->period_timer.
+ * Also keep at least one housekeeping cpu onlined to avoid generating
+ * an empty sched_domain span.
*/
- cpu = cpumask_any_but(cpu_online_mask, cpu);
- if (cpu >= nr_cpu_ids)
- return -EBUSY;
- return work_on_cpu(cpu, __cpu_down_maps_locked, &work);
+ for_each_cpu_and(cpu, cpu_online_mask, housekeeping_cpumask(HK_TYPE_DOMAIN)) {
+ if (cpu != work.cpu)
+ return work_on_cpu(cpu, __cpu_down_maps_locked, &work);
+ }
+ return -EBUSY;
}
static int cpu_down(unsigned int cpu, enum cpuhp_state target)
--
2.15.2
prev parent reply other threads:[~2023-10-17 9:10 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-16 2:37 [PATCH] cpu/hotplug: dont offline the last non-isolated CPU yang.yang29
2023-10-11 12:56 ` Thomas Gleixner
2023-10-17 9:09 ` yang.yang29 [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=202310171709530660462@zte.com.cn \
--to=yang.yang29@zte.com.cn \
--cc=jiang.xuexin@zte.com.cn \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.