[rh7] mm/slab: Fix deadlock on attempt to shrink slab.

Submitted by Andrey Ryabinin on Oct. 10, 2019, 8:21 a.m.

Details

Message ID 20191010082114.28661-2-aryabinin@virtuozzo.com
State New
Series "mm/memcg: restore lost css_put() in memcg_kmem_cache_create_func()"
Headers show

Commit Message

Andrey Ryabinin Oct. 10, 2019, 8:21 a.m.
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;
 }