diff mbox series

[-rfc,1/3] mm: kasan: shadow: add cond_resched() in kasan_populate_vmalloc_pte()

Message ID 20230906124234.134200-2-wangkefeng.wang@huawei.com (mailing list archive)
State New
Headers show
Series mm: kasan: fix softlock when populate or depopulate pte | expand

Commit Message

Kefeng Wang Sept. 6, 2023, 12:42 p.m. UTC
The kasan_populate_vmalloc() will cost a lot of time when populate
large size, it will cause soft lockup,

  watchdog: BUG: soft lockup - CPU#3 stuck for 26s! [insmod:458]
  _raw_spin_unlock_irqrestore+0x50/0xb8
  rmqueue_bulk+0x434/0x6b8
  get_page_from_freelist+0xdd4/0x1680
  __alloc_pages+0x244/0x508
  alloc_pages+0xf0/0x218
  __get_free_pages+0x1c/0x50
  kasan_populate_vmalloc_pte+0x30/0x188
  __apply_to_page_range+0x3ec/0x650
  apply_to_page_range+0x1c/0x30
  kasan_populate_vmalloc+0x60/0x70
  alloc_vmap_area.part.67+0x328/0xe50
  alloc_vmap_area+0x4c/0x78
  __get_vm_area_node.constprop.76+0x130/0x240
  __vmalloc_node_range+0x12c/0x340
  __vmalloc_node+0x8c/0xb0
  vmalloc+0x2c/0x40

Fix it by adding a cond_resched().

Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 mm/kasan/shadow.c | 2 ++
 1 file changed, 2 insertions(+)
diff mbox series

Patch

diff --git a/mm/kasan/shadow.c b/mm/kasan/shadow.c
index dd772f9d0f08..fd15e38ff80e 100644
--- a/mm/kasan/shadow.c
+++ b/mm/kasan/shadow.c
@@ -317,6 +317,8 @@  static int kasan_populate_vmalloc_pte(pte_t *ptep, unsigned long addr,
 	unsigned long page;
 	pte_t pte;
 
+	cond_resched();
+
 	if (likely(!pte_none(ptep_get(ptep))))
 		return 0;