Re: [PATCH v2 1/1] mm/shmem: don't use the memcg of an uncharged folio
From: David Hildenbrand (Arm)
Date: Sat Nov 21 2026 - 08:01:51 EST
On 11/21/26 14:00, David Hildenbrand (Arm) wrote:
> On 11/21/26 13:59, Gregory Price (Meta) wrote:
>> On 2026-11-20 14:50 -0500, Chris Mason wrote:
>>> The shrinker for unused huge tmpfs folios can dereference a NULL memcg
>>> if it races with the migration of the folio at the end of a file.
>>>
>>> folio_memcg_list_lru_alloc() assumes that folio_memcg() is never NULL.
>>> But it is NULL until the folio is charged, and a migration target can be
>>> in the page cache before charging.
>>>
>>> shmem_unused_huge_shrink() looks the folio up without the folio lock,
>>> so we can race with migration:
>>>
>>> __migrate_folio() shmem_unused_huge_shrink()
>>> ================= ==========================
>>> __folio_migrate_mapping()
>>> xas_store(newfolio)
>>> filemap_get_entry()
>>> returns newfolio
>>> folio_trylock() fails
>>> shmem_unused_huge_requeue()
>>> folio_memcg_list_lru_alloc()
>>> folio_memcg() is NULL
>>> memcg->kmemcg_id
>>> folio_migrate_flags()
>>> mem_cgroup_migrate()
>>> commit_charge(newfolio)
>>>
>>> Fix it by keeping the original objcg around while the inode is isolated.
>>>
>>> Fixes: 743e7d025d2f ("mm: shmem: make unused huge shrinker memcg aware")
>>> Suggested-by: Qi Zheng <qi.zheng@xxxxxxxxx>
>>> Signed-off-by: Chris Mason <mason@xxxxxxxxxx>
>>
>> Reproduced and validated the fix. Changes look ok.
>
> Thanks, I'll throw this into for-next-fixes right away and cc stable.
scrap the latter ... just a hotfix.
--
Cheers,
David