* [PATCH] mm: kmem: fix split_page_memcg()
@ 2024-08-19 8:04 Muchun Song
2024-08-19 15:37 ` Shakeel Butt
0 siblings, 1 reply; 3+ messages in thread
From: Muchun Song @ 2024-08-19 8:04 UTC (permalink / raw)
To: muchun.song, hannes, mhocko, roman.gushchin, shakeel.butt, akpm
Cc: cgroups, linux-mm, linux-kernel, Muchun Song,
syzbot+ef4ecf7b6bdc4157bfa4
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(-)
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)
--
2.20.1
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] mm: kmem: fix split_page_memcg()
2024-08-19 8:04 [PATCH] mm: kmem: fix split_page_memcg() Muchun Song
@ 2024-08-19 15:37 ` Shakeel Butt
2024-08-20 2:37 ` Muchun Song
0 siblings, 1 reply; 3+ messages in thread
From: Shakeel Butt @ 2024-08-19 15:37 UTC (permalink / raw)
To: Muchun Song
Cc: muchun.song, hannes, mhocko, roman.gushchin, akpm, cgroups,
linux-mm, linux-kernel, syzbot+ef4ecf7b6bdc4157bfa4
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>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] mm: kmem: fix split_page_memcg()
2024-08-19 15:37 ` Shakeel Butt
@ 2024-08-20 2:37 ` Muchun Song
0 siblings, 0 replies; 3+ messages in thread
From: Muchun Song @ 2024-08-20 2:37 UTC (permalink / raw)
To: Shakeel Butt
Cc: Muchun Song, Johannes Weiner, Michal Hocko, Roman Gushchin,
Andrew Morton, cgroups, Linux Memory Management List,
Linux Kernel Mailing List, syzbot
> 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.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-08-20 2:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-19 8:04 [PATCH] mm: kmem: fix split_page_memcg() Muchun Song
2024-08-19 15:37 ` Shakeel Butt
2024-08-20 2:37 ` Muchun Song
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox