Skip to content

Commit 3e401f7

Browse files
bauermannKAGA-KOKO
authored andcommitted
powerpc: Only obtain cpu_hotplug_lock if called by rtasd
Calling arch_update_cpu_topology from a CPU hotplug state machine callback hits a deadlock because the function tries to get a read lock on cpu_hotplug_lock while the state machine still holds a write lock on it. Since all callers of arch_update_cpu_topology except rtasd already hold cpu_hotplug_lock, this patch changes the function to use stop_machine_cpuslocked and creates a separate function for rtasd which still tries to obtain the lock. Michael Bringmann investigated the bug and provided a detailed analysis of the deadlock on this previous RFC for an alternate solution: Signed-off-by: Thiago Jung Bauermann <bauerman@linux.vnet.ibm.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Acked-by: Michael Ellerman <mpe@ellerman.id.au> Cc: John Allen <jallen@linux.vnet.ibm.com> Cc: Michael Bringmann <mwb@linux.vnet.ibm.com> Cc: Nathan Fontenot <nfont@linux.vnet.ibm.com> Cc: linuxppc-dev@lists.ozlabs.org Link: http://lkml.kernel.org/r/1497996510-4032-1-git-send-email-bauerman@linux.vnet.ibm.com Link: https://patchwork.ozlabs.org/patch/771293/
1 parent 1b3b225 commit 3e401f7

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

arch/powerpc/include/asm/topology.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ extern void __init dump_numa_cpu_topology(void);
4343

4444
extern int sysfs_add_device_to_node(struct device *dev, int nid);
4545
extern void sysfs_remove_device_from_node(struct device *dev, int nid);
46+
extern int numa_update_cpu_topology(bool cpus_locked);
4647

4748
#else
4849

@@ -57,6 +58,11 @@ static inline void sysfs_remove_device_from_node(struct device *dev,
5758
int nid)
5859
{
5960
}
61+
62+
static inline int numa_update_cpu_topology(bool cpus_locked)
63+
{
64+
return 0;
65+
}
6066
#endif /* CONFIG_NUMA */
6167

6268
#if defined(CONFIG_NUMA) && defined(CONFIG_PPC_SPLPAR)

arch/powerpc/kernel/rtasd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ static void prrn_work_fn(struct work_struct *work)
283283
* the RTAS event.
284284
*/
285285
pseries_devicetree_update(-prrn_update_scope);
286-
arch_update_cpu_topology();
286+
numa_update_cpu_topology(false);
287287
}
288288

289289
static DECLARE_WORK(prrn_work, prrn_work_fn);

arch/powerpc/mm/numa.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,8 +1311,10 @@ static int update_lookup_table(void *data)
13111311
/*
13121312
* Update the node maps and sysfs entries for each cpu whose home node
13131313
* has changed. Returns 1 when the topology has changed, and 0 otherwise.
1314+
*
1315+
* cpus_locked says whether we already hold cpu_hotplug_lock.
13141316
*/
1315-
int arch_update_cpu_topology(void)
1317+
int numa_update_cpu_topology(bool cpus_locked)
13161318
{
13171319
unsigned int cpu, sibling, changed = 0;
13181320
struct topology_update_data *updates, *ud;
@@ -1400,15 +1402,23 @@ int arch_update_cpu_topology(void)
14001402
if (!cpumask_weight(&updated_cpus))
14011403
goto out;
14021404

1403-
stop_machine(update_cpu_topology, &updates[0], &updated_cpus);
1405+
if (cpus_locked)
1406+
stop_machine_cpuslocked(update_cpu_topology, &updates[0],
1407+
&updated_cpus);
1408+
else
1409+
stop_machine(update_cpu_topology, &updates[0], &updated_cpus);
14041410

14051411
/*
14061412
* Update the numa-cpu lookup table with the new mappings, even for
14071413
* offline CPUs. It is best to perform this update from the stop-
14081414
* machine context.
14091415
*/
1410-
stop_machine(update_lookup_table, &updates[0],
1416+
if (cpus_locked)
1417+
stop_machine_cpuslocked(update_lookup_table, &updates[0],
14111418
cpumask_of(raw_smp_processor_id()));
1419+
else
1420+
stop_machine(update_lookup_table, &updates[0],
1421+
cpumask_of(raw_smp_processor_id()));
14121422

14131423
for (ud = &updates[0]; ud; ud = ud->next) {
14141424
unregister_cpu_under_node(ud->cpu, ud->old_nid);
@@ -1426,6 +1436,12 @@ int arch_update_cpu_topology(void)
14261436
return changed;
14271437
}
14281438

1439+
int arch_update_cpu_topology(void)
1440+
{
1441+
lockdep_assert_cpus_held();
1442+
return numa_update_cpu_topology(true);
1443+
}
1444+
14291445
static void topology_work_fn(struct work_struct *work)
14301446
{
14311447
rebuild_sched_domains();

0 commit comments

Comments
 (0)