Message ID | 20240819080415.44964-1-songmuchun@bytedance.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | mm: kmem: fix split_page_memcg() | expand |
On Mon, Aug 19, 2024 at 04:04:15PM GMT, Muchun Song wrote: > split_page_memcg() does not care about the returned memcg for kmem > pages, so folio_memcg_charged() should be used, otherwise obj_cgroup_memcg > will complain about this. Basically avoid calling folio_memcg() for folio_memcg_kmem(folio), correct? > > Reported-by: syzbot+ef4ecf7b6bdc4157bfa4@syzkaller.appspotmail.com > Signed-off-by: Muchun Song <songmuchun@bytedance.com> Acked-by: Shakeel Butt <shakeel.butt@linux.dev>
> On Aug 19, 2024, at 23:37, Shakeel Butt <shakeel.butt@linux.dev> wrote: > > On Mon, Aug 19, 2024 at 04:04:15PM GMT, Muchun Song wrote: >> split_page_memcg() does not care about the returned memcg for kmem >> pages, so folio_memcg_charged() should be used, otherwise obj_cgroup_memcg >> will complain about this. > > Basically avoid calling folio_memcg() for folio_memcg_kmem(folio), > correct? Yes. Unless you hold rcu lock. > >> >> Reported-by: syzbot+ef4ecf7b6bdc4157bfa4@syzkaller.appspotmail.com >> Signed-off-by: Muchun Song <songmuchun@bytedance.com> > > Acked-by: Shakeel Butt <shakeel.butt@linux.dev> > Thanks.
diff --git a/mm/memcontrol.c b/mm/memcontrol.c index e0b3b7ee6de6e..6c84af0a9ede6 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -3018,12 +3018,11 @@ void __memcg_slab_free_hook(struct kmem_cache *s, struct slab *slab, void split_page_memcg(struct page *head, int old_order, int new_order) { struct folio *folio = page_folio(head); - struct mem_cgroup *memcg = folio_memcg(folio); int i; unsigned int old_nr = 1 << old_order; unsigned int new_nr = 1 << new_order; - if (mem_cgroup_disabled() || !memcg) + if (mem_cgroup_disabled() || !folio_memcg_charged(folio)) return; for (i = new_nr; i < old_nr; i += new_nr) @@ -3032,7 +3031,7 @@ void split_page_memcg(struct page *head, int old_order, int new_order) if (folio_memcg_kmem(folio)) obj_cgroup_get_many(__folio_objcg(folio), old_nr / new_nr - 1); else - css_get_many(&memcg->css, old_nr / new_nr - 1); + css_get_many(&folio_memcg(folio)->css, old_nr / new_nr - 1); } unsigned long mem_cgroup_usage(struct mem_cgroup *memcg, bool swap)
split_page_memcg() does not care about the returned memcg for kmem pages, so folio_memcg_charged() should be used, otherwise obj_cgroup_memcg will complain about this. Reported-by: syzbot+ef4ecf7b6bdc4157bfa4@syzkaller.appspotmail.com Signed-off-by: Muchun Song <songmuchun@bytedance.com> --- mm/memcontrol.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)