[RHEL7,COMMIT] mm/slab: Fix deadlock on attempt to shrink slab.

Submitted by Konstantin Khorenko on Oct. 15, 2019, 3:57 p.m.

Details

Message ID 201910151557.x9FFvDep020060@finist-ce7.sw.ru
State New
Series "mm/memcg: restore lost css_put() in memcg_kmem_cache_create_func()"
Headers show

Commit Message

Konstantin Khorenko Oct. 15, 2019, 3:57 p.m.
The commit is pushed to "branch-rh7-3.10.0-1062.1.2.vz7.114.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-1062.1.2.vz7.114.5
------>
commit 8bec805e4abf0d3c4548b36be5048c0200ff589c
Author: Andrey Ryabinin <aryabinin@virtuozzo.com>
Date:   Tue Oct 15 18:57:13 2019 +0300

    mm/slab: Fix deadlock on attempt to shrink slab.
    
    echo 1 > /sys/kernel/slab/<name>/shrink deadlocks as kmem_cache_shrink()
    attempts to lock slab_mutex which is already held by caller.
    
    Replace slab_mutex locking with [get,put]_online_mems(). This is what
    the sane kernel does.
    
    Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
---
 mm/slab_common.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/mm/slab_common.c b/mm/slab_common.c
index b08f48541f4a..b73b7547de36 100644
--- a/mm/slab_common.c
+++ b/mm/slab_common.c
@@ -600,10 +600,10 @@  int kmem_cache_shrink(struct kmem_cache *cachep)
 	int ret;
 
 	get_online_cpus();
-	mutex_lock(&slab_mutex);
+	get_online_mems();
 	kasan_cache_shrink(cachep);
 	ret = __kmem_cache_shrink(cachep, false);
-	mutex_unlock(&slab_mutex);
+	put_online_mems();
 	put_online_cpus();
 	return ret;
 }