Skip to contentSkip to conversation

mm/migrate: fix softlockup in do_pages_move() with huge page arrays

PATCH Superseded [email protected] 3 participants 5 messages Nov 7 – Nov 8

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/migrate: fix softlockup in do_pages_move() with huge page arrays

From: Shao Mingyin <[email protected]>

mm/migrate: fix softlockup in do_pages_move() with huge page arrays

do_pages_move() walks the user page array one page at a time. For each entry it performs two get_user() calls, an mmap_read_lock()/unlock() around a folio walk, and an optional store_status(); none of them has to sleep when the arrays stay resident and the rwsem is uncontended. move_pages_and_store_status() returns early while the page list is empty, so an array whose entries all resolve to the same node can run the whole loop without any scheduling point. nr_pages comes straight from move_pages(), so a huge array can hold a CPU past the watchdog threshold on a non-preemptible kernel; with KASAN and function tracing enabled, ten million entries can exceed it.

Add cond_resched() so that long calls yield periodically. do_pages_stat() has the same problem and is being fixed separately. In current mainline only alpha, hexagon and classic m68k can still select PREEMPT_NONE, and they cannot enable CONFIG_NUMA, so this mainly targets pre-v7.0 stable kernels.

Fixes a49bd4d71637 ("mm, numa: rework do_pages_move")
---
 mm/migrate.c | 2 ++
 1 file changed, 2 insertions(+)
mm/migrate.c +2 -0
index 875079464930..3122ecb85270 100644
@@ -2372,6 +2372,8 @@ static int do_pages_move(struct mm_struct *mm, nodemask_t task_nodes,
 		const void __user *p;
 		int node;
 
+		cond_resched();
+
 		err = -EFAULT;
 		if (in_compat_syscall()) {
 			compat_uptr_t cp;
#1 lore raw
Quoted 15 lines · On 11/7/26 14:38, [email protected] wrote:

From: Shao Mingyin <[email protected]>

mm/migrate: fix softlockup in do_pages_move() with huge page arrays

do_pages_move() walks the user page array one page at a time. For each entry it performs two get_user() calls, an mmap_read_lock()/unlock() around a folio walk, and an optional store_status(); none of them has to sleep when the arrays stay resident and the rwsem is uncontended. move_pages_and_store_status() returns early while the page list is empty, so an array whose entries all resolve to the same node can run the whole loop without any scheduling point. nr_pages comes straight from move_pages(), so a huge array can hold a CPU past the watchdog threshold on a non-preemptible kernel; with KASAN and function tracing enabled, ten million entries can exceed it.

Quoted 5 lines

Add cond_resched() so that long calls yield periodically. do_pages_stat() has the same problem and is being fixed separately. In current mainline only alpha, hexagon and classic m68k can still select PREEMPT_NONE, and they cannot enable CONFIG_NUMA, so this mainly targets pre-v7.0 stable kernels.

Please share a real kernel splat from a real system.

Signature · 3 lines
Cheers,

David
reviewer
#2 lore raw
In reply to [email protected]
Quoted 15 lines · EST,

From: Shao Mingyin <[email protected]>

mm/migrate: fix softlockup in do_pages_move() with huge page arrays

do_pages_move() walks the user page array one page at a time. For each entry it performs two get_user() calls, an mmap_read_lock()/unlock() around a folio walk, and an optional store_status(); none of them has to sleep when the arrays stay resident and the rwsem is uncontended. move_pages_and_store_status() returns early while the page list is empty, so an array whose entries all resolve to the same node can run the whole loop without any scheduling point. nr_pages comes straight from move_pages(), so a huge array can hold a CPU past the watchdog threshold on a non-preemptible kernel; with KASAN and function tracing enabled, ten million entries can exceed it.

Quoted 5 lines

Add cond_resched() so that long calls yield periodically. do_pages_stat() has the same problem and is being fixed separately. In current mainline only alpha, hexagon and classic m68k can still select PREEMPT_NONE, and they cannot enable CONFIG_NUMA, so this mainly targets pre-v7.0 stable kernels.

This is probably in the same spirit as the do_pages_stat() patch[1][2].

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/

Quoted 21 lines
Fixes a49bd4d71637 ("mm, numa: rework do_pages_move")
---
 mm/migrate.c | 2 ++
 1 file changed, 2 insertions(+)
mm/migrate.c +2 -0
index 875079464930..3122ecb85270 100644
@@ -2372,6 +2372,8 @@ static int do_pages_move(struct mm_struct *mm, nodemask_t task_nodes,
 		const void __user *p;
 		int node;
 
+		cond_resched();
+
 		err = -EFAULT;
 		if (in_compat_syscall()) {
 			compat_uptr_t cp;
Signature · 2 lines
Best Regards,
Yan, Zi
#3 lore raw
Quoted 16 lines · Zi Yan
Quoted 15 lines · EST,

From: Shao Mingyin <[email protected]>

mm/migrate: fix softlockup in do_pages_move() with huge page arrays

do_pages_move() walks the user page array one page at a time. For each entry it performs two get_user() calls, an mmap_read_lock()/unlock() around a folio walk, and an optional store_status(); none of them has to sleep when the arrays stay resident and the rwsem is uncontended. move_pages_and_store_status() returns early while the page list is empty, so an array whose entries all resolve to the same node can run the whole loop without any scheduling point. nr_pages comes straight from move_pages(), so a huge array can hold a CPU past the watchdog threshold on a non-preemptible kernel; with KASAN and function tracing enabled, ten million entries can exceed it.

Quoted 7 lines
Quoted 5 lines

Add cond_resched() so that long calls yield periodically. do_pages_stat() has the same problem and is being fixed separately. In current mainline only alpha, hexagon and classic m68k can still select PREEMPT_NONE, and they cannot enable CONFIG_NUMA, so this mainly targets pre-v7.0 stable kernels.

This is probably in the same spirit as the do_pages_stat() patch[1][2].

Right, and I'd like to see an actual reproducer, because we sure have a bunch of cond_resched() already in migration code.

Signature · 3 lines
Cheers,

David
#4 lore raw
Quoted 2 lines · David Hildenbrand

Right, and I'd like to see an actual reproducer, because we sure have a bunch of cond_resched() already in migration code.

The existing cond_resched() calls are in migrate_hugetlbs(), migrate_folios_move() and migrate_pages_batch(). All three only run when the pagelist is non-empty, i.e. after add_folio_for_migration() has isolated a folio. For an array of addresses that are already on the target node, add_folio_for_migration() returns 0, the folio is never queued, and move_pages_and_store_status() returns at its list_empty() check. The loop body (two get_user(), mmap_read_lock()/unlock(), folio walk, put_user()) therefore runs without a voluntary preemption point on PREEMPT_NONE.

I reproduced it on 6.6.60, x86_64, CONFIG_PREEMPT_NONE=y, CONFIG_NUMA=y, under QEMU TCG (no KVM, 2 vCPUs, 3 GiB; I do not have a bare-metal machine that can still select PREEMPT_NONE). move_pages() with 50 million entries pointing at one page, all already on node 0, keeps CPU#1 in kernel_move_pages() for 42.9 s and trips the watchdog:

  watchdog: BUG: soft lockup - CPU#1 stuck for 26s! [init:1]
  RIP: 0010:kernel_move_pages+0x424/0x820
  Call Trace:
   <IRQ>
   ? watchdog_timer_fn+0x1ad/0x210
   </IRQ>
   <TASK>
   ? kernel_move_pages+0x424/0x820
   __x64_sys_move_pages+0x24/0x30
   entry_SYSCALL_64_after_hwframe+0x78/0xe2

(do_pages_move() is inlined into kernel_move_pages() in this build; it is followed by an rcu_sched self-detected stall on the same CPU.)

With this patch applied to the same tree and the same initramfs, the same 50M-entry call completes in 44.3 s with no softlockup and no RCU stall (ret=0, all status entries 0).

The 10M figure in the v1 changelog is from the do_pages_stat() report (6.6-based arm64 with KASAN and function tracing). Without that instrumentation this TCG guest needs about 50M entries to stay in the loop for 20 s; 10M finishes in 8.5 s here. Same code path, only the machine speed and instrumentation differ.

I will send a v2 that only describes this reproduction in the changelog and keeps the code as is, the same treatment 8e934ab44389 got for do_pages_stat(). If you would rather not carry this in mm at all, say so and I will withdraw it; a stable-only submission would also fit the reachability.

Thanks,
Shao