Skip to content

Commit a33239b

Browse files
author
Alexander Gordeev
committed
s390/topology: honour nr_cpu_ids when adding CPUs
When SMT thread CPUs are added to CPU masks the nr_cpu_ids limit is not checked and could be exceeded. This leads to a warning for example if CONFIG_DEBUG_PER_CPU_MAPS is set and the command line parameter nr_cpus is set to 1. Reviewed-by: Heiko Carstens <[email protected]> Signed-off-by: Alexander Gordeev <[email protected]>
1 parent b1b0d5a commit a33239b

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

arch/s390/kernel/topology.c

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ static void cpu_group_map(cpumask_t *dst, struct mask_info *info, unsigned int c
9595
static void cpu_thread_map(cpumask_t *dst, unsigned int cpu)
9696
{
9797
static cpumask_t mask;
98-
int i;
98+
unsigned int max_cpu;
9999

100100
cpumask_clear(&mask);
101101
if (!cpumask_test_cpu(cpu, &cpu_setup_mask))
@@ -104,9 +104,10 @@ static void cpu_thread_map(cpumask_t *dst, unsigned int cpu)
104104
if (topology_mode != TOPOLOGY_MODE_HW)
105105
goto out;
106106
cpu -= cpu % (smp_cpu_mtid + 1);
107-
for (i = 0; i <= smp_cpu_mtid; i++) {
108-
if (cpumask_test_cpu(cpu + i, &cpu_setup_mask))
109-
cpumask_set_cpu(cpu + i, &mask);
107+
max_cpu = min(cpu + smp_cpu_mtid, nr_cpu_ids - 1);
108+
for (; cpu <= max_cpu; cpu++) {
109+
if (cpumask_test_cpu(cpu, &cpu_setup_mask))
110+
cpumask_set_cpu(cpu, &mask);
110111
}
111112
out:
112113
cpumask_copy(dst, &mask);
@@ -123,25 +124,26 @@ static void add_cpus_to_mask(struct topology_core *tl_core,
123124
unsigned int core;
124125

125126
for_each_set_bit(core, &tl_core->mask, TOPOLOGY_CORE_BITS) {
126-
unsigned int rcore;
127-
int lcpu, i;
127+
unsigned int max_cpu, rcore;
128+
int cpu;
128129

129130
rcore = TOPOLOGY_CORE_BITS - 1 - core + tl_core->origin;
130-
lcpu = smp_find_processor_id(rcore << smp_cpu_mt_shift);
131-
if (lcpu < 0)
131+
cpu = smp_find_processor_id(rcore << smp_cpu_mt_shift);
132+
if (cpu < 0)
132133
continue;
133-
for (i = 0; i <= smp_cpu_mtid; i++) {
134-
topo = &cpu_topology[lcpu + i];
134+
max_cpu = min(cpu + smp_cpu_mtid, nr_cpu_ids - 1);
135+
for (; cpu <= max_cpu; cpu++) {
136+
topo = &cpu_topology[cpu];
135137
topo->drawer_id = drawer->id;
136138
topo->book_id = book->id;
137139
topo->socket_id = socket->id;
138140
topo->core_id = rcore;
139-
topo->thread_id = lcpu + i;
141+
topo->thread_id = cpu;
140142
topo->dedicated = tl_core->d;
141-
cpumask_set_cpu(lcpu + i, &drawer->mask);
142-
cpumask_set_cpu(lcpu + i, &book->mask);
143-
cpumask_set_cpu(lcpu + i, &socket->mask);
144-
smp_cpu_set_polarization(lcpu + i, tl_core->pp);
143+
cpumask_set_cpu(cpu, &drawer->mask);
144+
cpumask_set_cpu(cpu, &book->mask);
145+
cpumask_set_cpu(cpu, &socket->mask);
146+
smp_cpu_set_polarization(cpu, tl_core->pp);
145147
}
146148
}
147149
}

0 commit comments

Comments
 (0)