[Devel] [PATCH RHEL8 COMMIT] mm: check shrinker is memcg-aware in register_shrinker_prepared()

Konstantin Khorenko khorenko at virtuozzo.com
Thu Apr 2 17:14:37 MSK 2020


The commit is pushed to "branch-rh8-4.18.0-80.1.2.vz8.3.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-80.1.2.vz8.3.4
------>
commit 7923340ba9ba37cd29d9609544799aa6048443f1
Author: Kirill Tkhai <ktkhai at virtuozzo.com>
Date:   Thu Apr 2 17:14:37 2020 +0300

    mm: check shrinker is memcg-aware in register_shrinker_prepared()
    
    There is a sad BUG introduced in patch adding SHRINKER_REGISTERING.
    shrinker_idr business is only for memcg-aware shrinkers.  Only such type
    of shrinkers have id and they must be finaly installed via idr_replace()
    in this function.  For !memcg-aware shrinkers we never initialize
    shrinker->id field.
    
    But there are all types of shrinkers passed to idr_replace(), and every
    !memcg-aware shrinker with random ID (most probably, its id is 0)
    replaces memcg-aware shrinker pointed by the ID in IDR.
    
    This patch fixes the problem.
    
    Link: http://lkml.kernel.org/r/8ff8a793-8211-713a-4ed9-d6e52390c2fc@virtuozzo.com
    Fixes: 7e010df53c80 "mm: use special value SHRINKER_REGISTERING instead of list_empty() check"
    Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
    
    Reported-by: <syzbot+d5f648a1bfe15678786b at syzkaller.appspotmail.com>
    Cc: Andrey Ryabinin <aryabinin at virtuozzo.com>
    Cc: Johannes Weiner <hannes at cmpxchg.org>
    Cc: Josef Bacik <jbacik at fb.com>
    Cc: Mel Gorman <mgorman at techsingularity.net>
    Cc: Michal Hocko <mhocko at suse.com>
    Cc: Tetsuo Handa <penguin-kernel at I-love.SAKURA.ne.jp>
    Cc: Shakeel Butt <shakeelb at google.com>
    Cc: <syzkaller-bugs at googlegroups.com>
    Cc: Huang Ying <ying.huang at intel.com>
    Signed-off-by: Andrew Morton <akpm at linux-foundation.org>
    Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>
    (cherry picked from commit 8df4a44cc46bf9dcfb80a37a59ae5dea2232dc58)
    Signed-off-by: Andrey Ryabinin <aryabinin at virtuozzo.com>
---
 mm/vmscan.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mm/vmscan.c b/mm/vmscan.c
index 580c8c6843b9..52f5e9203ebe 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -376,7 +376,8 @@ void register_shrinker_prepared(struct shrinker *shrinker)
 	down_write(&shrinker_rwsem);
 	list_add_tail(&shrinker->list, &shrinker_list);
 #ifdef CONFIG_MEMCG_KMEM
-	idr_replace(&shrinker_idr, shrinker, shrinker->id);
+	if (shrinker->flags & SHRINKER_MEMCG_AWARE)
+		idr_replace(&shrinker_idr, shrinker, shrinker->id);
 #endif
 	up_write(&shrinker_rwsem);
 }


More information about the Devel mailing list