Skip to contentSkip to conversation

mm: vmalloc: Add a scan area of VA only once

PATCH Applied Uladzislau Rezki (Sony) 3 participants 5 messages Feb 2, 2024 – Feb 5, 2024

Subsystems (2)
lore
Share & tools
lore

Uladzislau Rezki (Sony)

author maintainer
#0 lore raw

PATCH 1/1 mm: vmalloc: Add a scan area of VA only once

Invoke a kmemleak_scan_area() function only for newly allocated objects to add a scan area within that object. There is no reason to add a same scan area(pointer to beginning or inside the object) several times. If a VA is obtained from the cache its scan area has already been associated.

Fixes 7db166b4aa0d ("mm: vmalloc: offload free_vmap_area_lock lock")
---
 mm/vmalloc.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
mm/vmalloc.c +6 -6
index 449f45b0e474..25a8df497255 100644
@@ -1882,13 +1882,13 @@ static struct vmap_area *alloc_vmap_area(unsigned long size,
 		va = kmem_cache_alloc_node(vmap_area_cachep, gfp_mask, node);
 		if (unlikely(!va))
 			return ERR_PTR(-ENOMEM);
-	}
 
-	/*
-	 * Only scan the relevant parts containing pointers to other objects
-	 * to avoid false negatives.
-	 */
-	kmemleak_scan_area(&va->rb_node, SIZE_MAX, gfp_mask);
+		/*
+		 * Only scan the relevant parts containing pointers to other objects
+		 * to avoid false negatives.
+		 */
+		kmemleak_scan_area(&va->rb_node, SIZE_MAX, gfp_mask);
+	}
 
 retry:
 	if (addr == vend) {
Signature · 1 line
2.39.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 37 lines · Uladzislau Rezki (Sony)

Invoke a kmemleak_scan_area() function only for newly allocated objects to add a scan area within that object. There is no reason to add a same scan area(pointer to beginning or inside the object) several times. If a VA is obtained from the cache its scan area has already been associated.

Fixes 7db166b4aa0d ("mm: vmalloc: offload free_vmap_area_lock lock")
---
 mm/vmalloc.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
mm/vmalloc.c +6 -7
index 449f45b0e474..25a8df497255 100644
@@ -1882,13 +1882,13 @@ static struct vmap_area *alloc_vmap_area(unsigned long size,
 		va = kmem_cache_alloc_node(vmap_area_cachep, gfp_mask, node);
 		if (unlikely(!va))
 			return ERR_PTR(-ENOMEM);
-	}
 
-	/*
-	 * Only scan the relevant parts containing pointers to other objects
-	 * to avoid false negatives.
-	 */
-	kmemleak_scan_area(&va->rb_node, SIZE_MAX, gfp_mask);
+		/*
+		 * Only scan the relevant parts containing pointers to other objects
+		 * to avoid false negatives.
+		 */
+		kmemleak_scan_area(&va->rb_node, SIZE_MAX, gfp_mask);
+	}
 
 retry:
 	if (addr == vend) {
--
Quoted 2 lines

2.39.2

Looks good to me, feel free to add:

author maintainer
#2 lore raw
Quoted 43 lines · Lorenzo Stoakes
Quoted 37 lines · Uladzislau Rezki (Sony)

Invoke a kmemleak_scan_area() function only for newly allocated objects to add a scan area within that object. There is no reason to add a same scan area(pointer to beginning or inside the object) several times. If a VA is obtained from the cache its scan area has already been associated.

Fixes 7db166b4aa0d ("mm: vmalloc: offload free_vmap_area_lock lock")
---
 mm/vmalloc.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
mm/vmalloc.c +6 -7
index 449f45b0e474..25a8df497255 100644
@@ -1882,13 +1882,13 @@ static struct vmap_area *alloc_vmap_area(unsigned long size,
 		va = kmem_cache_alloc_node(vmap_area_cachep, gfp_mask, node);
 		if (unlikely(!va))
 			return ERR_PTR(-ENOMEM);
-	}
 
-	/*
-	 * Only scan the relevant parts containing pointers to other objects
-	 * to avoid false negatives.
-	 */
-	kmemleak_scan_area(&va->rb_node, SIZE_MAX, gfp_mask);
+		/*
+		 * Only scan the relevant parts containing pointers to other objects
+		 * to avoid false negatives.
+		 */
+		kmemleak_scan_area(&va->rb_node, SIZE_MAX, gfp_mask);
+	}
 
 retry:
 	if (addr == vend) {
--
Quoted 2 lines

2.39.2

Looks good to me, feel free to add:

Quoted 2 lines

Appreciate for review!

--
Uladzislau Rezki

#3 lore raw
In reply to Uladzislau Rezki (Sony)

mm/vmalloc.c static struct vmap_area *alloc_vmap_area(unsigned long size, · line 1887

Quoted 1 line
mm/vmalloc.c +1 -0
+		 * Only scan the relevant parts containing pointers to other objects

Please avoid the overly long line.

The rest looks fine.

Quoted 1 line
mm/vmalloc.c +1 -0
+		 * to avoid false negatives.
author maintainer
#4 lore raw
Quoted 8 lines · Christoph Hellwig

mm/vmalloc.c static struct vmap_area *alloc_vmap_area(unsigned long size, · line 1887

Quoted 1 line
mm/vmalloc.c +1 -0
+		 * Only scan the relevant parts containing pointers to other objects

Please avoid the overly long line.

The rest looks fine.

mm/vmalloc.c static struct vmap_area *alloc_vmap_area(unsigned long size, · line 1888

Quoted 1 line
mm/vmalloc.c +1 -0
+		 * to avoid false negatives.

Thanks!

--
Uladzislau Rezki