Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
powerpc/pseries: Fix cpu_hotplug_lock acquisition in resize_hpt()
The calls to arch_add_memory()/arch_remove_memory() are always made with the read-side cpu_hotplug_lock acquired via memory_hotplug_begin(). On pSeries, arch_add_memory()/arch_remove_memory() eventually call resize_hpt() which in turn calls stop_machine() which acquires the read-side cpu_hotplug_lock again, thereby resulting in the recursive acquisition of this lock. Lockdep complains as follows in these code-paths. swapper/0/1 is trying to acquire lock: (____ptrval____) (cpu_hotplug_lock.rw_sem){++++}, at: stop_machine+0x2c/0x60 but task is already holding lock: (____ptrval____) (cpu_hotplug_lock.rw_sem){++++}, at: mem_hotplug_begin+0x20/0x50 other info that might help us debug this: Possible unsafe locking scenario: CPU0 ---- lock(cpu_hotplug_lock.rw_sem); lock(cpu_hotplug_lock.rw_sem); *** DEADLOCK *** May be due to missing lock nesting notation 3 locks held by swapper/0/1: #0: (____ptrval____) (&dev->mutex){....}, at: __driver_attach+0x12c/0x1b0 #1: (____ptrval____) (cpu_hotplug_lock.rw_sem){++++}, at: mem_hotplug_begin+0x20/0x50 #2: (____ptrval____) (mem_hotplug_lock.rw_sem){++++}, at: percpu_down_write+0x54/0x1a0 stack backtrace: CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.0.0-rc5-58373-gbc99402235f3-dirty torvalds#166 Call Trace: [c0000000feb03150] [c000000000e32bd4] dump_stack+0xe8/0x164 (unreliable) [c0000000feb031a0] [c00000000020d6c0] __lock_acquire+0x1110/0x1c70 [c0000000feb03320] [c00000000020f080] lock_acquire+0x240/0x290 [c0000000feb033e0] [c00000000017f554] cpus_read_lock+0x64/0xf0 [c0000000feb03420] [c00000000029ebac] stop_machine+0x2c/0x60 [c0000000feb03460] [c0000000000d7f7c] pseries_lpar_resize_hpt+0x19c/0x2c0 [c0000000feb03500] [c0000000000788d0] resize_hpt_for_hotplug+0x70/0xd0 [c0000000feb03570] [c000000000e5d278] arch_add_memory+0x58/0xfc [c0000000feb03610] [c0000000003553a8] devm_memremap_pages+0x5e8/0x8f0 [c0000000feb036c0] [c0000000009c2394] pmem_attach_disk+0x764/0x830 [c0000000feb037d0] [c0000000009a7c38] nvdimm_bus_probe+0x118/0x240 [c0000000feb03860] [c000000000968500] really_probe+0x230/0x4b0 [c0000000feb038f0] [c000000000968aec] driver_probe_device+0x16c/0x1e0 [c0000000feb03970] [c000000000968ca8] __driver_attach+0x148/0x1b0 [c0000000feb039f0] [c0000000009650b0] bus_for_each_dev+0x90/0x130 [c0000000feb03a50] [c000000000967dd4] driver_attach+0x34/0x50 [c0000000feb03a70] [c000000000967068] bus_add_driver+0x1a8/0x360 [c0000000feb03b00] [c00000000096a498] driver_register+0x108/0x170 [c0000000feb03b70] [c0000000009a7400] __nd_driver_register+0xd0/0xf0 [c0000000feb03bd0] [c00000000128aa90] nd_pmem_driver_init+0x34/0x48 [c0000000feb03bf0] [c000000000010a10] do_one_initcall+0x1e0/0x45c [c0000000feb03cd0] [c00000000122462c] kernel_init_freeable+0x540/0x64c [c0000000feb03db0] [c00000000001110c] kernel_init+0x2c/0x160 [c0000000feb03e20] [c00000000000bed4] ret_from_kernel_thread+0x5c/0x68 Fix this issue by 1) Requiring all the calls to pseries_lpar_resize_hpt() be made with cpu_hotplug_lock held. 2) In pseries_lpar_resize_hpt() invoke stop_machine_cpuslocked() as a consequence of 1) 3) To satisfy 1), in hpt_order_set(), call mmu_hash_ops.resize_hpt() with cpu_hotplug_lock held. Reported-by: Aneesh Kumar K.V <[email protected]> Signed-off-by: Gautham R. Shenoy <[email protected]>
- Loading branch information