Subject: [PATCH] powerpc/book3s64/hash: Add cond_resched to avoid soft lockup warning

From: "Aneesh Kumar K.V" <[email-masked]>
Date: Tue, 1 Oct 2019 14:16:56 +0530

With large memory (8TB and more) hotplug, we can get soft lockup warnings
as below. These were caused by a long loop without any explicit cond_resched
which is a problem for !PREEMPT kernels.

Avoid the using cond_resched() while inserting hash page table entries. We
already do similar cond_resched() in __add_pages() (
commit: f64ac5e6e306 ("mm, memory_hotplug: add scheduling point to __add_pages"))

 rcu:     3-....: (24002 ticks this GP) idle=13e/1/0x4000000000000002 softirq=722/722 fqs=12001
  (t=24003 jiffies g=4285 q=2002)
 NMI backtrace for cpu 3
 CPU: 3 PID: 3870 Comm: ndctl Not tainted 5.3.0-197.18-default+ #2
 Call Trace:
 [c0000000692b3040] [c000000000f759fc] dump_stack+0xb0/0xf4 (unreliable)
 [c0000000692b3080] [c000000000f80ee4] nmi_cpu_backtrace+0x124/0x130
 [c0000000692b3100] [c000000000f8109c] nmi_trigger_cpumask_backtrace+0x1ac/0x1f0
 [c0000000692b31a0] [c00000000006c2f8] arch_trigger_cpumask_backtrace+0x28/0x3c
 [c0000000692b31c0] [c0000000001eb1e4] rcu_dump_cpu_stacks+0xf8/0x154
 [c0000000692b3210] [c0000000001e9e88] rcu_sched_clock_irq+0x878/0xb40
 [c0000000692b32f0] [c0000000001fe878] update_process_times+0x48/0x90
 [c0000000692b3320] [c000000000217a6c] tick_sched_handle.isra.16+0x4c/0x80
 [c0000000692b3340] [c000000000217f08] tick_sched_timer+0x68/0xe0
 [c0000000692b3380] [c0000000001ffee0] __hrtimer_run_queues+0x180/0x430
 [c0000000692b3400] [c000000000200bd0] hrtimer_interrupt+0x110/0x300
 [c0000000692b34b0] [c00000000002c128] timer_interrupt+0x108/0x2f0
 [c0000000692b3510] [c000000000009194] decrementer_common+0x114/0x120
 --- interrupt: 901 at arch_add_memory+0xc0/0x130
     LR = arch_add_memory+0x74/0x130
 [c0000000692b38b0] [c0000000004646b4] memremap_pages+0x494/0x650
 [c0000000692b3960] [c0000000004648ac] devm_memremap_pages+0x3c/0xa0
 [c0000000692b39a0] [c000000000b3f4e8] pmem_attach_disk+0x188/0x750
 [c0000000692b3aa0] [c000000000b2506c] nvdimm_bus_probe+0xac/0x2c0
 [c0000000692b3b30] [c000000000aeb218] really_probe+0x148/0x570
 [c0000000692b3bc0] [c000000000aeba1c] driver_probe_device+0x19c/0x1d0
 [c0000000692b3c40] [c000000000aebe5c] device_driver_attach+0xcc/0x100
 [c0000000692b3c80] [c000000000ae8a14] bind_store+0x134/0x1c0
 [c0000000692b3cd0] [c000000000ae7824] drv_attr_store+0x44/0x60
 [c0000000692b3cf0] [c00000000055e3f4] sysfs_kf_write+0x64/0x90
 [c0000000692b3d10] [c00000000055d8f0] kernfs_fop_write+0x1a0/0x270
 [c0000000692b3d60] [c0000000004698ec] __vfs_write+0x3c/0x70
 [c0000000692b3d80] [c00000000046d260] vfs_write+0xd0/0x260
 [c0000000692b3dd0] [c00000000046d6ac] ksys_write+0xdc/0x130
 [c0000000692b3e20] [c00000000000b278] system_call+0x5c/0x68

Signed-off-by: Aneesh Kumar K.V <[email-masked]>
---
 arch/powerpc/mm/book3s64/hash_utils.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/powerpc/mm/book3s64/hash_utils.c b/arch/powerpc/mm/book3s64/hash_utils.c
index a9d1f72de848..b30435c7d804 100644
--- a/arch/powerpc/mm/book3s64/hash_utils.c
+++ b/arch/powerpc/mm/book3s64/hash_utils.c
@@ -316,6 +316,7 @@ int htab_bolt_mapping(unsigned long vstart, unsigned long vend,
 		if (ret < 0)
 			break;
 
+		cond_resched();
 #ifdef CONFIG_DEBUG_PAGEALLOC
 		if (debug_pagealloc_enabled() &&
 			(paddr >> PAGE_SHIFT) < linear_map_hash_count)
-- 
2.21.0