Skip to content

Commit 3be7db6

Browse files
Robert Jenningsozbenh
Robert Jennings
authored andcommitted
powerpc: VPHN topology change updates all siblings
When an associativity level change is found for one thread, the siblings threads need to be updated as well. This is done today for PRRN in stage_topology_update() but is missing for VPHN in update_cpu_associativity_changes_mask(). This patch will correctly update all thread siblings during a topology change. Without this patch a topology update can result in a CPU in init_sched_groups_power() getting stuck indefinitely in a loop. This loop is built in build_sched_groups(). As a result of the thread moving to a node separate from its siblings the struct sched_group will have its next pointer set to point to itself rather than the sched_group struct of the next thread. This happens because we have a domain without the SD_OVERLAP flag, which is correct, and a topology that doesn't conform with reality (threads on the same core assigned to different numa nodes). When this list is traversed by init_sched_groups_power() it will reach the thread's sched_group structure and loop indefinitely; the cpu will be stuck at this point. The bug was exposed when VPHN was enabled in commit b7abef0 (v3.9). Cc: <[email protected]> [v3.9+] Reported-by: Jan Stancek <[email protected]> Signed-off-by: Robert Jennings <[email protected]> Signed-off-by: Benjamin Herrenschmidt <[email protected]>
1 parent 8d7c55d commit 3be7db6

File tree

2 files changed

+48
-15
lines changed

2 files changed

+48
-15
lines changed

arch/powerpc/include/asm/smp.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ extern void __cpu_die(unsigned int cpu);
145145
#define smp_setup_cpu_maps()
146146
static inline void inhibit_secondary_onlining(void) {}
147147
static inline void uninhibit_secondary_onlining(void) {}
148+
static inline const struct cpumask *cpu_sibling_mask(int cpu)
149+
{
150+
return cpumask_of(cpu);
151+
}
148152

149153
#endif /* CONFIG_SMP */
150154

arch/powerpc/mm/numa.c

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <linux/seq_file.h>
2828
#include <linux/uaccess.h>
2929
#include <linux/slab.h>
30+
#include <asm/cputhreads.h>
3031
#include <asm/sparsemem.h>
3132
#include <asm/prom.h>
3233
#include <asm/smp.h>
@@ -1318,7 +1319,8 @@ static int update_cpu_associativity_changes_mask(void)
13181319
}
13191320
}
13201321
if (changed) {
1321-
cpumask_set_cpu(cpu, changes);
1322+
cpumask_or(changes, changes, cpu_sibling_mask(cpu));
1323+
cpu = cpu_last_thread_sibling(cpu);
13221324
}
13231325
}
13241326

@@ -1426,7 +1428,7 @@ static int update_cpu_topology(void *data)
14261428
if (!data)
14271429
return -EINVAL;
14281430

1429-
cpu = get_cpu();
1431+
cpu = smp_processor_id();
14301432

14311433
for (update = data; update; update = update->next) {
14321434
if (cpu != update->cpu)
@@ -1446,12 +1448,12 @@ static int update_cpu_topology(void *data)
14461448
*/
14471449
int arch_update_cpu_topology(void)
14481450
{
1449-
unsigned int cpu, changed = 0;
1451+
unsigned int cpu, sibling, changed = 0;
14501452
struct topology_update_data *updates, *ud;
14511453
unsigned int associativity[VPHN_ASSOC_BUFSIZE] = {0};
14521454
cpumask_t updated_cpus;
14531455
struct device *dev;
1454-
int weight, i = 0;
1456+
int weight, new_nid, i = 0;
14551457

14561458
weight = cpumask_weight(&cpu_associativity_changes_mask);
14571459
if (!weight)
@@ -1464,19 +1466,46 @@ int arch_update_cpu_topology(void)
14641466
cpumask_clear(&updated_cpus);
14651467

14661468
for_each_cpu(cpu, &cpu_associativity_changes_mask) {
1467-
ud = &updates[i++];
1468-
ud->cpu = cpu;
1469-
vphn_get_associativity(cpu, associativity);
1470-
ud->new_nid = associativity_to_nid(associativity);
1471-
1472-
if (ud->new_nid < 0 || !node_online(ud->new_nid))
1473-
ud->new_nid = first_online_node;
1469+
/*
1470+
* If siblings aren't flagged for changes, updates list
1471+
* will be too short. Skip on this update and set for next
1472+
* update.
1473+
*/
1474+
if (!cpumask_subset(cpu_sibling_mask(cpu),
1475+
&cpu_associativity_changes_mask)) {
1476+
pr_info("Sibling bits not set for associativity "
1477+
"change, cpu%d\n", cpu);
1478+
cpumask_or(&cpu_associativity_changes_mask,
1479+
&cpu_associativity_changes_mask,
1480+
cpu_sibling_mask(cpu));
1481+
cpu = cpu_last_thread_sibling(cpu);
1482+
continue;
1483+
}
14741484

1475-
ud->old_nid = numa_cpu_lookup_table[cpu];
1476-
cpumask_set_cpu(cpu, &updated_cpus);
1485+
/* Use associativity from first thread for all siblings */
1486+
vphn_get_associativity(cpu, associativity);
1487+
new_nid = associativity_to_nid(associativity);
1488+
if (new_nid < 0 || !node_online(new_nid))
1489+
new_nid = first_online_node;
1490+
1491+
if (new_nid == numa_cpu_lookup_table[cpu]) {
1492+
cpumask_andnot(&cpu_associativity_changes_mask,
1493+
&cpu_associativity_changes_mask,
1494+
cpu_sibling_mask(cpu));
1495+
cpu = cpu_last_thread_sibling(cpu);
1496+
continue;
1497+
}
14771498

1478-
if (i < weight)
1479-
ud->next = &updates[i];
1499+
for_each_cpu(sibling, cpu_sibling_mask(cpu)) {
1500+
ud = &updates[i++];
1501+
ud->cpu = sibling;
1502+
ud->new_nid = new_nid;
1503+
ud->old_nid = numa_cpu_lookup_table[sibling];
1504+
cpumask_set_cpu(sibling, &updated_cpus);
1505+
if (i < weight)
1506+
ud->next = &updates[i];
1507+
}
1508+
cpu = cpu_last_thread_sibling(cpu);
14801509
}
14811510

14821511
stop_machine(update_cpu_topology, &updates[0], &updated_cpus);

0 commit comments

Comments
 (0)