Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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().

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.

Use kmemleak_ignore_phys() instead of kmemleak_free() for those
objects.

Link: https://lkml.kernel.org/r/20220705113158.127600-1-patrick.wang.shcn@gmail.com
Fixes: 0c24e061196c ("mm: kmemleak: add rbtree and store physical address for objects allocated with PA")
Signed-off-by: Patrick Wang <patrick.wang.shcn@gmail.com>
Cc: Dennis Zhou <dennis@kernel.org>
Cc: Tejun Heo <tj@kernel.org>
Cc: Christoph Lameter <cl@linux.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Patrick Wang and committed by
akpm
a317ebcc 48725bbc

+3 -3
+3 -3
mm/percpu.c
··· 3104 3104 goto out_free_areas; 3105 3105 } 3106 3106 /* kmemleak tracks the percpu allocations separately */ 3107 - kmemleak_free(ptr); 3107 + kmemleak_ignore_phys(__pa(ptr)); 3108 3108 areas[group] = ptr; 3109 3109 3110 3110 base = min(ptr, base); ··· 3304 3304 goto enomem; 3305 3305 } 3306 3306 /* kmemleak tracks the percpu allocations separately */ 3307 - kmemleak_free(ptr); 3307 + kmemleak_ignore_phys(__pa(ptr)); 3308 3308 pages[j++] = virt_to_page(ptr); 3309 3309 } 3310 3310 } ··· 3417 3417 if (!ai || !fc) 3418 3418 panic("Failed to allocate memory for percpu areas."); 3419 3419 /* kmemleak tracks the percpu allocations separately */ 3420 - kmemleak_free(fc); 3420 + kmemleak_ignore_phys(__pa(fc)); 3421 3421 3422 3422 ai->dyn_size = unit_size; 3423 3423 ai->unit_size = unit_size;