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

mm: kmemleak: remove kmemleak_not_leak_phys() and the min_count argument to kmemleak_alloc_phys()

Patch series "mm: kmemleak: store objects allocated with physical address
separately and check when scan", v4.

The kmemleak_*_phys() interface uses "min_low_pfn" and "max_low_pfn" to
check address. But on some architectures, kmemleak_*_phys() is called
before those two variables initialized. The following steps will be
taken:

1) Add OBJECT_PHYS flag and rbtree for the objects allocated
with physical address
2) Store physical address in objects if allocated with OBJECT_PHYS
3) Check the boundary when scan instead of in kmemleak_*_phys()

This patch set will solve:
https://lore.kernel.org/r/20220527032504.30341-1-yee.lee@mediatek.com
https://lore.kernel.org/r/9dd08bb5-f39e-53d8-f88d-bec598a08c93@gmail.com

v3: https://lore.kernel.org/r/20220609124950.1694394-1-patrick.wang.shcn@gmail.com
v2: https://lore.kernel.org/r/20220603035415.1243913-1-patrick.wang.shcn@gmail.com
v1: https://lore.kernel.org/r/20220531150823.1004101-1-patrick.wang.shcn@gmail.com


This patch (of 4):

Remove the unused kmemleak_not_leak_phys() function. And remove the
min_count argument to kmemleak_alloc_phys() function, assume it's 0.

Link: https://lkml.kernel.org/r/20220611035551.1823303-1-patrick.wang.shcn@gmail.com
Link: https://lkml.kernel.org/r/20220611035551.1823303-2-patrick.wang.shcn@gmail.com
Signed-off-by: Patrick Wang <patrick.wang.shcn@gmail.com>
Suggested-by: Catalin Marinas <catalin.marinas@arm.com>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Cc: Yee Lee <yee.lee@mediatek.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Patrick Wang and committed by
akpm
c200d900 ed913b05

+14 -33
-1
Documentation/dev-tools/kmemleak.rst
··· 174 174 175 175 - ``kmemleak_alloc_phys`` 176 176 - ``kmemleak_free_part_phys`` 177 - - ``kmemleak_not_leak_phys`` 178 177 - ``kmemleak_ignore_phys`` 179 178 180 179 Dealing with false positives/negatives
+1 -1
drivers/of/fdt.c
··· 529 529 pr_debug("Reserved memory: reserved region for node '%s': base %pa, size %lu MiB\n", 530 530 uname, &base, (unsigned long)(size / SZ_1M)); 531 531 if (!nomap) 532 - kmemleak_alloc_phys(base, size, 0, 0); 532 + kmemleak_alloc_phys(base, size, 0); 533 533 } 534 534 else 535 535 pr_info("Reserved memory: failed to reserve memory for node '%s': base %pa, size %lu MiB\n",
+2 -6
include/linux/kmemleak.h
··· 29 29 extern void kmemleak_ignore(const void *ptr) __ref; 30 30 extern void kmemleak_scan_area(const void *ptr, size_t size, gfp_t gfp) __ref; 31 31 extern void kmemleak_no_scan(const void *ptr) __ref; 32 - extern void kmemleak_alloc_phys(phys_addr_t phys, size_t size, int min_count, 32 + extern void kmemleak_alloc_phys(phys_addr_t phys, size_t size, 33 33 gfp_t gfp) __ref; 34 34 extern void kmemleak_free_part_phys(phys_addr_t phys, size_t size) __ref; 35 - extern void kmemleak_not_leak_phys(phys_addr_t phys) __ref; 36 35 extern void kmemleak_ignore_phys(phys_addr_t phys) __ref; 37 36 38 37 static inline void kmemleak_alloc_recursive(const void *ptr, size_t size, ··· 106 107 { 107 108 } 108 109 static inline void kmemleak_alloc_phys(phys_addr_t phys, size_t size, 109 - int min_count, gfp_t gfp) 110 + gfp_t gfp) 110 111 { 111 112 } 112 113 static inline void kmemleak_free_part_phys(phys_addr_t phys, size_t size) 113 - { 114 - } 115 - static inline void kmemleak_not_leak_phys(phys_addr_t phys) 116 114 { 117 115 } 118 116 static inline void kmemleak_ignore_phys(phys_addr_t phys)
+3 -17
mm/kmemleak.c
··· 1125 1125 * address argument 1126 1126 * @phys: physical address of the object 1127 1127 * @size: size of the object 1128 - * @min_count: minimum number of references to this object. 1129 - * See kmemleak_alloc() 1130 1128 * @gfp: kmalloc() flags used for kmemleak internal memory allocations 1131 1129 */ 1132 - void __ref kmemleak_alloc_phys(phys_addr_t phys, size_t size, int min_count, 1133 - gfp_t gfp) 1130 + void __ref kmemleak_alloc_phys(phys_addr_t phys, size_t size, gfp_t gfp) 1134 1131 { 1135 1132 if (PHYS_PFN(phys) >= min_low_pfn && PHYS_PFN(phys) < max_low_pfn) 1136 - kmemleak_alloc(__va(phys), size, min_count, gfp); 1133 + /* assume min_count 0 */ 1134 + kmemleak_alloc(__va(phys), size, 0, gfp); 1137 1135 } 1138 1136 EXPORT_SYMBOL(kmemleak_alloc_phys); 1139 1137 ··· 1148 1150 kmemleak_free_part(__va(phys), size); 1149 1151 } 1150 1152 EXPORT_SYMBOL(kmemleak_free_part_phys); 1151 - 1152 - /** 1153 - * kmemleak_not_leak_phys - similar to kmemleak_not_leak but taking a physical 1154 - * address argument 1155 - * @phys: physical address of the object 1156 - */ 1157 - void __ref kmemleak_not_leak_phys(phys_addr_t phys) 1158 - { 1159 - if (PHYS_PFN(phys) >= min_low_pfn && PHYS_PFN(phys) < max_low_pfn) 1160 - kmemleak_not_leak(__va(phys)); 1161 - } 1162 - EXPORT_SYMBOL(kmemleak_not_leak_phys); 1163 1153 1164 1154 /** 1165 1155 * kmemleak_ignore_phys - similar to kmemleak_ignore but taking a physical
+7 -7
mm/memblock.c
··· 1345 1345 * from the regions with mirroring enabled and then retried from any 1346 1346 * memory region. 1347 1347 * 1348 - * In addition, function sets the min_count to 0 using kmemleak_alloc_phys for 1349 - * allocated boot memory block, so that it is never reported as leaks. 1348 + * In addition, function using kmemleak_alloc_phys for allocated boot 1349 + * memory block, it is never reported as leaks. 1350 1350 * 1351 1351 * Return: 1352 1352 * Physical address of allocated memory block on success, %0 on failure. ··· 1398 1398 */ 1399 1399 if (end != MEMBLOCK_ALLOC_NOLEAKTRACE) 1400 1400 /* 1401 - * The min_count is set to 0 so that memblock allocated 1402 - * blocks are never reported as leaks. This is because many 1403 - * of these blocks are only referred via the physical 1404 - * address which is not looked up by kmemleak. 1401 + * Memblock allocated blocks are never reported as 1402 + * leaks. This is because many of these blocks are 1403 + * only referred via the physical address which is 1404 + * not looked up by kmemleak. 1405 1405 */ 1406 - kmemleak_alloc_phys(found, size, 0, 0); 1406 + kmemleak_alloc_phys(found, size, 0); 1407 1407 1408 1408 return found; 1409 1409 }
+1 -1
tools/testing/memblock/linux/kmemleak.h
··· 7 7 } 8 8 9 9 static inline void kmemleak_alloc_phys(phys_addr_t phys, size_t size, 10 - int min_count, gfp_t gfp) 10 + gfp_t gfp) 11 11 { 12 12 } 13 13