Skip to content

Commit ffe0d5a

Browse files
committed
percpu: fix unit_map[] verification in pcpu_setup_first_chunk()
pcpu_setup_first_chunk() incorrectly used NR_CPUS as the impossible unit number while unit number can equal and go over NR_CPUS with sparse unit map. This triggers BUG_ON() spuriously on machines which have non-power-of-two number of cpus. Use UINT_MAX instead. Signed-off-by: Tejun Heo <[email protected]> Reported-and-tested-by: Tony Vroon <[email protected]>
1 parent 17d857b commit ffe0d5a

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

mm/percpu.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,7 +1604,7 @@ int __init pcpu_setup_first_chunk(const struct pcpu_alloc_info *ai,
16041604
unit_off = alloc_bootmem(nr_cpu_ids * sizeof(unit_off[0]));
16051605

16061606
for (cpu = 0; cpu < nr_cpu_ids; cpu++)
1607-
unit_map[cpu] = NR_CPUS;
1607+
unit_map[cpu] = UINT_MAX;
16081608
pcpu_first_unit_cpu = NR_CPUS;
16091609

16101610
for (group = 0, unit = 0; group < ai->nr_groups; group++, unit += i) {
@@ -1619,7 +1619,7 @@ int __init pcpu_setup_first_chunk(const struct pcpu_alloc_info *ai,
16191619
continue;
16201620

16211621
BUG_ON(cpu > nr_cpu_ids || !cpu_possible(cpu));
1622-
BUG_ON(unit_map[cpu] != NR_CPUS);
1622+
BUG_ON(unit_map[cpu] != UINT_MAX);
16231623

16241624
unit_map[cpu] = unit + i;
16251625
unit_off[cpu] = gi->base_offset + i * ai->unit_size;
@@ -1632,7 +1632,7 @@ int __init pcpu_setup_first_chunk(const struct pcpu_alloc_info *ai,
16321632
pcpu_nr_units = unit;
16331633

16341634
for_each_possible_cpu(cpu)
1635-
BUG_ON(unit_map[cpu] == NR_CPUS);
1635+
BUG_ON(unit_map[cpu] == UINT_MAX);
16361636

16371637
pcpu_nr_groups = ai->nr_groups;
16381638
pcpu_group_offsets = group_offsets;

0 commit comments

Comments
 (0)