Re: [PATCH v2] mm: memcontrol: fix rcu unbalance in get_non_dying_memcg_end()

From: Qi Zheng

Date: Tue Apr 28 2026 - 22:48:51 EST




On 4/29/26 6:12 AM, Andrew Morton wrote:
On Tue, 28 Apr 2026 18:31:08 +0800 Qi Zheng <qi.zheng@xxxxxxxxx> wrote:

Currently, get_non_dying_memcg_start() and get_non_dying_memcg_end() both
evaluate cgroup_subsys_on_dfl(memory_cgrp_subsys) independently to
determine whether to acquire or release the RCU read lock.

Sashiko review
(https://sashiko.dev/#/patchset/20260428103108.45719-1-qi.zheng@xxxxxxxxx)
is correct.

mm/memcontrol.c: In function 'mod_memcg_state':
mm/memcontrol.c:881:9: error: 'rcu_locked' is used uninitialized [-Werror=uninitialized]
881 | get_non_dying_memcg_end(rcu_locked);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mm/memcontrol.c:874:14: note: 'rcu_locked' was declared here
874 | bool rcu_locked;
| ^~~~~~~~~~
In function 'mod_memcg_lruvec_state',
inlined from 'mod_lruvec_state' at mm/memcontrol.c:973:3:
mm/memcontrol.c:952:9: error: 'rcu_locked' is used uninitialized [-Werror=uninitialized]
952 | get_non_dying_memcg_end(rcu_locked);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mm/memcontrol.c:944:14: note: 'rcu_locked' was declared here
944 | bool rcu_locked;
| ^~~~~~~~~~
In function 'mod_memcg_state',
inlined from 'mem_cgroup_sk_uncharge' at mm/memcontrol.c:5392:2:
mm/memcontrol.c:881:9: error: 'rcu_locked' is used uninitialized [-Werror=uninitialized]
881 | get_non_dying_memcg_end(rcu_locked);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mm/memcontrol.c:874:14: note: 'rcu_locked' was declared here
874 | bool rcu_locked;
| ^~~~~~~~~~

In v1, I explicitly set rcu_locked in get_non_dying_memcg_start() to
avoid the uninitialized warning. However, I noticed that even if I drop
it, the warning doesn't actually trigger -- probably due to some GCC
optimiztions.

Anyway, let's explicitly initialize rcu_locked in both
mod_memcg_state() and mod_memcg_lruvec_state(). Will do it in v3.

Thanks!