Skip to content

Commit 814bc1d

Browse files
yuzhaogoogleakpm00
authored andcommitted
mm/mglru: make memcg_lru->lock irq safe
lru_gen_rotate_memcg() can happen in softirq if memory.soft_limit_in_bytes is set. This requires memcg_lru->lock to be irq safe. Lockdep warns on this. This problem only affects memcg v1. Link: https://lkml.kernel.org/r/20230619193821.2710944-1-yuzhao@google.com Fixes: e4dde56 ("mm: multi-gen LRU: per-node lru_gen_folio lists") Signed-off-by: Yu Zhao <yuzhao@google.com> Reported-by: syzbot+87c490fd2be656269b6a@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=87c490fd2be656269b6a Reviewed-by: Yosry Ahmed <yosryahmed@google.com> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 0518dbe commit 814bc1d

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

mm/vmscan.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4728,10 +4728,11 @@ static void lru_gen_rotate_memcg(struct lruvec *lruvec, int op)
47284728
{
47294729
int seg;
47304730
int old, new;
4731+
unsigned long flags;
47314732
int bin = get_random_u32_below(MEMCG_NR_BINS);
47324733
struct pglist_data *pgdat = lruvec_pgdat(lruvec);
47334734

4734-
spin_lock(&pgdat->memcg_lru.lock);
4735+
spin_lock_irqsave(&pgdat->memcg_lru.lock, flags);
47354736

47364737
VM_WARN_ON_ONCE(hlist_nulls_unhashed(&lruvec->lrugen.list));
47374738

@@ -4766,7 +4767,7 @@ static void lru_gen_rotate_memcg(struct lruvec *lruvec, int op)
47664767
if (!pgdat->memcg_lru.nr_memcgs[old] && old == get_memcg_gen(pgdat->memcg_lru.seq))
47674768
WRITE_ONCE(pgdat->memcg_lru.seq, pgdat->memcg_lru.seq + 1);
47684769

4769-
spin_unlock(&pgdat->memcg_lru.lock);
4770+
spin_unlock_irqrestore(&pgdat->memcg_lru.lock, flags);
47704771
}
47714772

47724773
void lru_gen_online_memcg(struct mem_cgroup *memcg)
@@ -4779,7 +4780,7 @@ void lru_gen_online_memcg(struct mem_cgroup *memcg)
47794780
struct pglist_data *pgdat = NODE_DATA(nid);
47804781
struct lruvec *lruvec = get_lruvec(memcg, nid);
47814782

4782-
spin_lock(&pgdat->memcg_lru.lock);
4783+
spin_lock_irq(&pgdat->memcg_lru.lock);
47834784

47844785
VM_WARN_ON_ONCE(!hlist_nulls_unhashed(&lruvec->lrugen.list));
47854786

@@ -4790,7 +4791,7 @@ void lru_gen_online_memcg(struct mem_cgroup *memcg)
47904791

47914792
lruvec->lrugen.gen = gen;
47924793

4793-
spin_unlock(&pgdat->memcg_lru.lock);
4794+
spin_unlock_irq(&pgdat->memcg_lru.lock);
47944795
}
47954796
}
47964797

@@ -4814,7 +4815,7 @@ void lru_gen_release_memcg(struct mem_cgroup *memcg)
48144815
struct pglist_data *pgdat = NODE_DATA(nid);
48154816
struct lruvec *lruvec = get_lruvec(memcg, nid);
48164817

4817-
spin_lock(&pgdat->memcg_lru.lock);
4818+
spin_lock_irq(&pgdat->memcg_lru.lock);
48184819

48194820
VM_WARN_ON_ONCE(hlist_nulls_unhashed(&lruvec->lrugen.list));
48204821

@@ -4826,7 +4827,7 @@ void lru_gen_release_memcg(struct mem_cgroup *memcg)
48264827
if (!pgdat->memcg_lru.nr_memcgs[gen] && gen == get_memcg_gen(pgdat->memcg_lru.seq))
48274828
WRITE_ONCE(pgdat->memcg_lru.seq, pgdat->memcg_lru.seq + 1);
48284829

4829-
spin_unlock(&pgdat->memcg_lru.lock);
4830+
spin_unlock_irq(&pgdat->memcg_lru.lock);
48304831
}
48314832
}
48324833

0 commit comments

Comments
 (0)