Skip to content

Commit 257bf89

Browse files
oleg-nesterovIngo Molnar
authored andcommitted
sched/isolation: Fix boot crash when maxcpus < first housekeeping CPU
housekeeping_setup() checks cpumask_intersects(present, online) to ensure that the kernel will have at least one housekeeping CPU after smp_init(), but this doesn't work if the maxcpus= kernel parameter limits the number of processors available after bootup. For example, a kernel with "maxcpus=2 nohz_full=0-2" parameters crashes at boot time on a virtual machine with 4 CPUs. Change housekeeping_setup() to use cpumask_first_and() and check that the returned CPU number is valid and less than setup_max_cpus. Another corner case is "nohz_full=0" on a machine with a single CPU or with the maxcpus=1 kernel argument. In this case non_housekeeping_mask is empty and tick_nohz_full_setup() makes no sense. And indeed, the kernel hits the WARN_ON(tick_nohz_full_running) in tick_sched_do_timer(). And how should the kernel interpret the "nohz_full=" parameter? It should be silently ignored, but currently cpulist_parse() happily returns the empty cpumask and this leads to the same problem. Change housekeeping_setup() to check cpumask_empty(non_housekeeping_mask) and do nothing in this case. Signed-off-by: Oleg Nesterov <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Reviewed-by: Phil Auld <[email protected]> Acked-by: Frederic Weisbecker <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 5097cbc commit 257bf89

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

kernel/sched/isolation.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ static void __init housekeeping_setup_type(enum hk_type type,
118118
static int __init housekeeping_setup(char *str, unsigned long flags)
119119
{
120120
cpumask_var_t non_housekeeping_mask, housekeeping_staging;
121+
unsigned int first_cpu;
121122
int err = 0;
122123

123124
if ((flags & HK_FLAG_TICK) && !(housekeeping.flags & HK_FLAG_TICK)) {
@@ -138,7 +139,8 @@ static int __init housekeeping_setup(char *str, unsigned long flags)
138139
cpumask_andnot(housekeeping_staging,
139140
cpu_possible_mask, non_housekeeping_mask);
140141

141-
if (!cpumask_intersects(cpu_present_mask, housekeeping_staging)) {
142+
first_cpu = cpumask_first_and(cpu_present_mask, housekeeping_staging);
143+
if (first_cpu >= nr_cpu_ids || first_cpu >= setup_max_cpus) {
142144
__cpumask_set_cpu(smp_processor_id(), housekeeping_staging);
143145
__cpumask_clear_cpu(smp_processor_id(), non_housekeeping_mask);
144146
if (!housekeeping.flags) {
@@ -147,6 +149,9 @@ static int __init housekeeping_setup(char *str, unsigned long flags)
147149
}
148150
}
149151

152+
if (cpumask_empty(non_housekeeping_mask))
153+
goto free_housekeeping_staging;
154+
150155
if (!housekeeping.flags) {
151156
/* First setup call ("nohz_full=" or "isolcpus=") */
152157
enum hk_type type;

0 commit comments

Comments
 (0)