The patch titled Subject: mm: vmscan: fix shrinker_rwsem in free_shrinker_info() has been added to the -mm tree. Its filename is mm-vmscan-add-per-memcg-shrinker-nr_deferred-fix.patch This patch should soon appear at https://ozlabs.org/~akpm/mmots/broken-out/mm-vmscan-add-per-memcg-shrinker-nr_deferred-fix.patch and later at https://ozlabs.org/~akpm/mmotm/broken-out/mm-vmscan-add-per-memcg-shrinker-nr_deferred-fix.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Hugh Dickins <hughd@xxxxxxxxxx> Subject: mm: vmscan: fix shrinker_rwsem in free_shrinker_info() Lockdep warns mm/vmscan.c: suspicious rcu_dereference_protected() usage! when free_shrinker_info() is called from mem_cgroup_css_free(): there it is called with no locking, whereas alloc_shrinker_info() calls it with down_write of shrinker_rwsem - which seems appropriate. Rearrange that so free_shrinker_info() can manage the shrinker_rwsem for itself. Link: https://lkml.kernel.org/r/20210317140615.GB28839@xsang-OptiPlex-9020 Link: https://lkml.kernel.org/r/alpine.LSU.2.11.2103301640240.2584@eggly.anvils Reported-by: kernel test robot <oliver.sang@xxxxxxxxx> Signed-off-by: Hugh Dickins <hughd@xxxxxxxxxx> Cc: Yang Shi <shy828301@xxxxxxxxx> Cc: Roman Gushchin <guro@xxxxxx> Cc: Kirill Tkhai <ktkhai@xxxxxxxxxxxxx> Cc: Shakeel Butt <shakeelb@xxxxxxxxxx> Cc: Dave Chinner <david@xxxxxxxxxxxxx> Cc: Johannes Weiner <hannes@xxxxxxxxxxx> Cc: Michal Hocko <mhocko@xxxxxxxx> Cc: Vlastimil Babka <vbabka@xxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- mm/vmscan.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) --- a/mm/vmscan.c~mm-vmscan-add-per-memcg-shrinker-nr_deferred-fix +++ a/mm/vmscan.c @@ -249,18 +249,20 @@ void free_shrinker_info(struct mem_cgrou struct shrinker_info *info; int nid; + down_write(&shrinker_rwsem); for_each_node(nid) { pn = memcg->nodeinfo[nid]; info = shrinker_info_protected(memcg, nid); kvfree(info); rcu_assign_pointer(pn->shrinker_info, NULL); } + up_write(&shrinker_rwsem); } int alloc_shrinker_info(struct mem_cgroup *memcg) { struct shrinker_info *info; - int nid, size, ret = 0; + int nid, size; int map_size, defer_size = 0; down_write(&shrinker_rwsem); @@ -270,9 +272,9 @@ int alloc_shrinker_info(struct mem_cgrou for_each_node(nid) { info = kvzalloc_node(sizeof(*info) + size, GFP_KERNEL, nid); if (!info) { + up_write(&shrinker_rwsem); free_shrinker_info(memcg); - ret = -ENOMEM; - break; + return -ENOMEM; } info->nr_deferred = (atomic_long_t *)(info + 1); info->map = (void *)info->nr_deferred + defer_size; @@ -280,7 +282,7 @@ int alloc_shrinker_info(struct mem_cgrou } up_write(&shrinker_rwsem); - return ret; + return 0; } static inline bool need_expand(int nr_max) _ Patches currently in -mm which might be from hughd@xxxxxxxxxx are mm-vmscan-add-per-memcg-shrinker-nr_deferred-fix.patch mm-restore-node-stat-checking-in-proc-sys-vm-stat_refresh.patch mm-no-more-einval-from-proc-sys-vm-stat_refresh.patch mm-proc-sys-vm-stat_refresh-skip-checking-known-negative-stats.patch mm-proc-sys-vm-stat_refresh-stop-checking-monotonic-numa-stats.patch