diff options
| author | Shakeel Butt <shakeel.butt@linux.dev> | 2026-11-12 14:12:48 -0800 |
|---|---|---|
| committer | Andrew Morton <akpm@linux-foundation.org> | 2026-11-22 22:24:12 -0800 |
| commit | 642abe8448674a953675486596f68060bd6c7fb6 (patch) | |
| tree | 95eda110a73c7dae3244107932ac8efa8f9a6d50 /tools/perf/scripts/python/bin | |
| parent | f6ed0f2a03045e4a059a9e6c14befa40c88e68fb (diff) | |
mm: list_lru: don't use a new memcg's lists for an offline memcg
A memcg's list_lru lists are found by its kmemcg_id, which is its
private ID. Offlining a memcg moves its lists to the parent and frees
the ID right away, with no RCU grace period. The next new memcg can get
the same ID and allocate its own lists at that index.
A caller that holds only the RCU read lock, such as
__folio_unqueue_deferred_split(), can still hold the offline memcg. If
it is preempted until the ID is reused, it then locks the new memcg's
list and unlinks a folio that now sits on the parent's list, without
holding the parent's lock. A concurrent change to the parent's list can
then leave a pointer to a freed folio on it.
Users see list corruption reports, crashes or silent memory corruption
when memory cgroups are removed and created while THPs are freed, on
kernels with preemptible RCU, which is the default on x86 and arm64.
They can also see a warning from memcg_reparent_list_lru_one() when the
new memcg is removed, because the wrong unlink made its count negative.
Fix it by recording the owning memcg in each list_lru_memcg, and by
treating the index as empty when its lists belong to another memcg. The
lookup then moves up to the parent, whose list holds the folio.
[akpm@linux-foundation.org: verify memcg owner before skipping allocation]
Link: https://lore.kernel.org/20261112161502.18d9d72c0139b8f69bb88ff4@linux-foundation.org
Link: https://patch.msgid.link/20261112221248.3512447-1-shakeel.butt@linux.dev
Fixes: 28e98022b31e ("mm/list_lru: simplify reparenting and initial allocation")
Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reported-by: Chris Mason <mason@kernel.org>
Cc: Dave Chinner <david@fromorbit.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: David Hildenbrand <david@kernel.org>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Qi Zheng <qi.zheng@linux.dev>
include/linux/list_lru.h | 2 ++
mm/list_lru.c | 30 ++++++++++++++++++++++--------
2 files changed, 24 insertions(+), 8 deletions(-)
Diffstat (limited to 'tools/perf/scripts/python/bin')
0 files changed, 0 insertions, 0 deletions
