Skip to contentSkip to conversation

mm: percpu: use kmemleak_ignore_phys() instead of kmemleak_free()

PATCH Applied Patrick Wang 3 participants 4 messages Jul 5, 2022 – Jul 12, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm: percpu: use kmemleak_ignore_phys() instead of kmemleak_free()

Kmemleak recently added a rbtree to store the objects allocted with physical address. Those objects can't be freed with kmemleak_free(). Use kmemleak_ignore_phys() instead of kmemleak_free() for those objects.

---
Similar to:
https://lkml.kernel.org/r/[email protected]

 mm/percpu.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
mm/percpu.c +3 -3
index 3633eeefaa0d..27697b2429c2 100644
@@ -3104,7 +3104,7 @@ int __init pcpu_embed_first_chunk(size_t reserved_size, size_t dyn_size,
 			goto out_free_areas;
 		}
 		/* kmemleak tracks the percpu allocations separately */
-		kmemleak_free(ptr);
+		kmemleak_ignore_phys(__pa(ptr));
 		areas[group] = ptr;
 
 		base = min(ptr, base);
@@ -3304,7 +3304,7 @@ int __init pcpu_page_first_chunk(size_t reserved_size, pcpu_fc_cpu_to_node_fn_t
 				goto enomem;
 			}
 			/* kmemleak tracks the percpu allocations separately */
-			kmemleak_free(ptr);
+			kmemleak_ignore_phys(__pa(ptr));
 			pages[j++] = virt_to_page(ptr);
 		}
 	}
@@ -3417,7 +3417,7 @@ void __init setup_per_cpu_areas(void)
 	if (!ai || !fc)
 		panic("Failed to allocate memory for percpu areas.");
 	/* kmemleak tracks the percpu allocations separately */
-	kmemleak_free(fc);
+	kmemleak_ignore_phys(__pa(fc));
 
 	ai->dyn_size = unit_size;
 	ai->unit_size = unit_size;
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 4 lines · On Tue, 5 Jul 2022 19:31:58 +0800 Patrick Wang <[email protected]>…

Kmemleak recently added a rbtree to store the objects allocted with physical address. Those objects can't be freed with kmemleak_free(). Use kmemleak_ignore_phys() instead of kmemleak_free() for those objects.

Thanks. What are the user-visible runtime effects of this?

And are we able to identify a commit for the Fixes: line?

#2 lore raw
Quoted 9 lines · Andrew Morton
Quoted 4 lines · On Tue, 5 Jul 2022 19:31:58 +0800 Patrick Wang <[email protected]>…

Kmemleak recently added a rbtree to store the objects allocted with physical address. Those objects can't be freed with kmemleak_free(). Use kmemleak_ignore_phys() instead of kmemleak_free() for those objects.

Thanks. What are the user-visible runtime effects of this?

According to the comments, percpu allocations are tracked by kmemleak separately. Kmemleak_free() was used to avoid the unnecessary tracking. If kmemleak_free() fails, those objects would be scanned by kmemleak, which is unnecessary but shouldn't lead to other effects.

I didn't observe any anomaly without this commit on riscv and arm64.

Quoted 2 lines

And are we able to identify a commit for the Fixes: line?

0c24e061196c (mm: kmemleak: add rbtree and store physical address for objects allocated with PA)
Current in mm-stable.

Thanks,
Patrick

Reviewed-by
#3 lore raw
Quoted 11 lines · patrick wang
Quoted 9 lines · Andrew Morton
Quoted 4 lines · On Tue, 5 Jul 2022 19:31:58 +0800 Patrick Wang <[email protected]>…

Kmemleak recently added a rbtree to store the objects allocted with physical address. Those objects can't be freed with kmemleak_free(). Use kmemleak_ignore_phys() instead of kmemleak_free() for those objects.

Thanks. What are the user-visible runtime effects of this?

Quoted 8 lines

According to the comments, percpu allocations are tracked by kmemleak separately. Kmemleak_free() was used to avoid the unnecessary tracking. If kmemleak_free() fails, those objects would be scanned by kmemleak, which is unnecessary but shouldn't lead to other effects.

I didn't observe any anomaly without this commit on riscv and arm64.

What could happen is an increased rate of false negatives as it scans more than necessary.

Quoted 5 lines
Quoted 1 line

And are we able to identify a commit for the Fixes: line?

0c24e061196c (mm: kmemleak: add rbtree and store physical address for objects allocated with PA)
Current in mm-stable.

I think we could add a Fixes line for the above. For the patch: