Skip to contentSkip to conversation

mm/vmalloc: Take vmap_purge_lock in shrinker

PATCH Applied Uladzislau Rezki (Sony) 2 participants 2 messages Apr 13 – Apr 14

Subsystems (3)
lore
Share & tools
lore

Uladzislau Rezki (Sony)

author maintainer
#0 lore raw

PATCH 1/1 mm/vmalloc: Take vmap_purge_lock in shrinker

decay_va_pool_node() can be invoked concurrently from two paths:
__purge_vmap_area_lazy() when pools are being purged, and the shrinker via vmap_node_shrink_scan().

However, decay_va_pool_node() is not safe to run concurrently, and the shrinker path currently lacks serialization, leading to races and possible leaks.

Protect decay_va_pool_node() by taking vmap_purge_lock in the shrinker path to ensure serialization with purge users.

Cc chenyichong <[email protected]>
Fixes 7679ba6b36db ("mm: vmalloc: add a shrinker to drain vmap pools")
---
 mm/vmalloc.c | 1 +
 1 file changed, 1 insertion(+)
mm/vmalloc.c +1 -0
index 61caa55a4402..676851d5cfe7 100644
@@ -5416,6 +5416,7 @@ vmap_node_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
 {
 	struct vmap_node *vn;
 
+	guard(mutex)(&vmap_purge_lock);
 	for_each_vmap_node(vn)
 		decay_va_pool_node(vn, true);
 
Signature · 1 line
2.47.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 24 lines · Uladzislau Rezki (Sony)

decay_va_pool_node() can be invoked concurrently from two paths:
__purge_vmap_area_lazy() when pools are being purged, and the shrinker via vmap_node_shrink_scan().

However, decay_va_pool_node() is not safe to run concurrently, and the shrinker path currently lacks serialization, leading to races and possible leaks.

Protect decay_va_pool_node() by taking vmap_purge_lock in the shrinker path to ensure serialization with purge users.

Cc chenyichong <[email protected]>
Fixes 7679ba6b36db ("mm: vmalloc: add a shrinker to drain vmap pools")
---
 mm/vmalloc.c | 1 +
 1 file changed, 1 insertion(+)
mm/vmalloc.c +0 -0
index 61caa55a4402..676851d5cfe7 100644

mm/vmalloc.c vmap_node_shrink_scan(struct shrinker *shrink, struct shrink_control *sc) · line 5421

Quoted 6 lines
mm/vmalloc.c +1 -0
@@ -5416,6 +5416,7 @@ vmap_node_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
 {
 	struct vmap_node *vn;
 
+	guard(mutex)(&vmap_purge_lock);
 	for_each_vmap_node(vn)
 		decay_va_pool_node(vn, true);

LGTM,