Skip to content

Commit

Permalink
mm/mglru: make memcg_lru->lock irq safe
Browse files Browse the repository at this point in the history
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/[email protected]
Fixes: e4dde56 ("mm: multi-gen LRU: per-node lru_gen_folio lists")
Signed-off-by: Yu Zhao <[email protected]>
Reported-by: [email protected]
Closes: https://syzkaller.appspot.com/bug?extid=87c490fd2be656269b6a
Reviewed-by: Yosry Ahmed <[email protected]>
Cc: <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
  • Loading branch information
yuzhaogoogle authored and akpm00 committed Jun 23, 2023
1 parent 0518dbe commit 814bc1d
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions mm/vmscan.c
Original file line number Diff line number Diff line change
Expand Up @@ -4728,10 +4728,11 @@ static void lru_gen_rotate_memcg(struct lruvec *lruvec, int op)
{
int seg;
int old, new;
unsigned long flags;
int bin = get_random_u32_below(MEMCG_NR_BINS);
struct pglist_data *pgdat = lruvec_pgdat(lruvec);

spin_lock(&pgdat->memcg_lru.lock);
spin_lock_irqsave(&pgdat->memcg_lru.lock, flags);

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

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

spin_unlock(&pgdat->memcg_lru.lock);
spin_unlock_irqrestore(&pgdat->memcg_lru.lock, flags);
}

void lru_gen_online_memcg(struct mem_cgroup *memcg)
Expand All @@ -4779,7 +4780,7 @@ void lru_gen_online_memcg(struct mem_cgroup *memcg)
struct pglist_data *pgdat = NODE_DATA(nid);
struct lruvec *lruvec = get_lruvec(memcg, nid);

spin_lock(&pgdat->memcg_lru.lock);
spin_lock_irq(&pgdat->memcg_lru.lock);

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

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

lruvec->lrugen.gen = gen;

spin_unlock(&pgdat->memcg_lru.lock);
spin_unlock_irq(&pgdat->memcg_lru.lock);
}
}

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

spin_lock(&pgdat->memcg_lru.lock);
spin_lock_irq(&pgdat->memcg_lru.lock);

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

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

spin_unlock(&pgdat->memcg_lru.lock);
spin_unlock_irq(&pgdat->memcg_lru.lock);
}
}

Expand Down

0 comments on commit 814bc1d

Please sign in to comment.