Skip to content

Commit de08eaa

Browse files
yuzhaogoogleakpm00
authored andcommitted
mm: multi-gen LRU: fix crash during cgroup migration
lru_gen_migrate_mm() assumes lru_gen_add_mm() runs prior to itself. This isn't true for the following scenario: CPU 1 CPU 2 clone() cgroup_can_fork() cgroup_procs_write() cgroup_post_fork() task_lock() lru_gen_migrate_mm() task_unlock() task_lock() lru_gen_add_mm() task_unlock() And when the above happens, kernel crashes because of linked list corruption (mm_struct->lru_gen.list). Link: https://lore.kernel.org/r/[email protected]/ Link: https://lkml.kernel.org/r/[email protected] Fixes: bd74fda ("mm: multi-gen LRU: support page table walks") Signed-off-by: Yu Zhao <[email protected]> Reported-by: msizanoen <[email protected]> Tested-by: msizanoen <[email protected]> Cc: <[email protected]> [6.1+] Signed-off-by: Andrew Morton <[email protected]>
1 parent 55ab834 commit de08eaa

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

mm/vmscan.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3323,13 +3323,16 @@ void lru_gen_migrate_mm(struct mm_struct *mm)
33233323
if (mem_cgroup_disabled())
33243324
return;
33253325

3326+
/* migration can happen before addition */
3327+
if (!mm->lru_gen.memcg)
3328+
return;
3329+
33263330
rcu_read_lock();
33273331
memcg = mem_cgroup_from_task(task);
33283332
rcu_read_unlock();
33293333
if (memcg == mm->lru_gen.memcg)
33303334
return;
33313335

3332-
VM_WARN_ON_ONCE(!mm->lru_gen.memcg);
33333336
VM_WARN_ON_ONCE(list_empty(&mm->lru_gen.list));
33343337

33353338
lru_gen_del_mm(mm);

0 commit comments

Comments
 (0)