Skip to content

Commit c200d90

Browse files
Patrick Wangakpm00
authored andcommitted
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/[email protected] https://lore.kernel.org/r/[email protected] v3: https://lore.kernel.org/r/[email protected] v2: https://lore.kernel.org/r/[email protected] v1: https://lore.kernel.org/r/[email protected] 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/[email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Patrick Wang <[email protected]> Suggested-by: Catalin Marinas <[email protected]> Reviewed-by: Catalin Marinas <[email protected]> Cc: Yee Lee <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent ed913b0 commit c200d90

File tree

6 files changed

+14
-33
lines changed

6 files changed

+14
-33
lines changed

Documentation/dev-tools/kmemleak.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ mapping:
174174

175175
- ``kmemleak_alloc_phys``
176176
- ``kmemleak_free_part_phys``
177-
- ``kmemleak_not_leak_phys``
178177
- ``kmemleak_ignore_phys``
179178

180179
Dealing with false positives/negatives

drivers/of/fdt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ static int __init __reserved_mem_reserve_reg(unsigned long node,
529529
pr_debug("Reserved memory: reserved region for node '%s': base %pa, size %lu MiB\n",
530530
uname, &base, (unsigned long)(size / SZ_1M));
531531
if (!nomap)
532-
kmemleak_alloc_phys(base, size, 0, 0);
532+
kmemleak_alloc_phys(base, size, 0);
533533
}
534534
else
535535
pr_info("Reserved memory: failed to reserve memory for node '%s': base %pa, size %lu MiB\n",

include/linux/kmemleak.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@ extern void kmemleak_not_leak(const void *ptr) __ref;
2929
extern void kmemleak_ignore(const void *ptr) __ref;
3030
extern void kmemleak_scan_area(const void *ptr, size_t size, gfp_t gfp) __ref;
3131
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,
3333
gfp_t gfp) __ref;
3434
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;
3635
extern void kmemleak_ignore_phys(phys_addr_t phys) __ref;
3736

3837
static inline void kmemleak_alloc_recursive(const void *ptr, size_t size,
@@ -107,15 +106,12 @@ static inline void kmemleak_no_scan(const void *ptr)
107106
{
108107
}
109108
static inline void kmemleak_alloc_phys(phys_addr_t phys, size_t size,
110-
int min_count, gfp_t gfp)
109+
gfp_t gfp)
111110
{
112111
}
113112
static inline void kmemleak_free_part_phys(phys_addr_t phys, size_t size)
114113
{
115114
}
116-
static inline void kmemleak_not_leak_phys(phys_addr_t phys)
117-
{
118-
}
119115
static inline void kmemleak_ignore_phys(phys_addr_t phys)
120116
{
121117
}

mm/kmemleak.c

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,15 +1125,13 @@ EXPORT_SYMBOL(kmemleak_no_scan);
11251125
* address argument
11261126
* @phys: physical address of the object
11271127
* @size: size of the object
1128-
* @min_count: minimum number of references to this object.
1129-
* See kmemleak_alloc()
11301128
* @gfp: kmalloc() flags used for kmemleak internal memory allocations
11311129
*/
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)
11341131
{
11351132
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);
11371135
}
11381136
EXPORT_SYMBOL(kmemleak_alloc_phys);
11391137

@@ -1151,18 +1149,6 @@ void __ref kmemleak_free_part_phys(phys_addr_t phys, size_t size)
11511149
}
11521150
EXPORT_SYMBOL(kmemleak_free_part_phys);
11531151

1154-
/**
1155-
* kmemleak_not_leak_phys - similar to kmemleak_not_leak but taking a physical
1156-
* address argument
1157-
* @phys: physical address of the object
1158-
*/
1159-
void __ref kmemleak_not_leak_phys(phys_addr_t phys)
1160-
{
1161-
if (PHYS_PFN(phys) >= min_low_pfn && PHYS_PFN(phys) < max_low_pfn)
1162-
kmemleak_not_leak(__va(phys));
1163-
}
1164-
EXPORT_SYMBOL(kmemleak_not_leak_phys);
1165-
11661152
/**
11671153
* kmemleak_ignore_phys - similar to kmemleak_ignore but taking a physical
11681154
* address argument

mm/memblock.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,8 +1345,8 @@ __next_mem_pfn_range_in_zone(u64 *idx, struct zone *zone,
13451345
* from the regions with mirroring enabled and then retried from any
13461346
* memory region.
13471347
*
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.
13501350
*
13511351
* Return:
13521352
* Physical address of allocated memory block on success, %0 on failure.
@@ -1398,12 +1398,12 @@ phys_addr_t __init memblock_alloc_range_nid(phys_addr_t size,
13981398
*/
13991399
if (end != MEMBLOCK_ALLOC_NOLEAKTRACE)
14001400
/*
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.
14051405
*/
1406-
kmemleak_alloc_phys(found, size, 0, 0);
1406+
kmemleak_alloc_phys(found, size, 0);
14071407

14081408
return found;
14091409
}

tools/testing/memblock/linux/kmemleak.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ static inline void kmemleak_free_part_phys(phys_addr_t phys, size_t size)
77
}
88

99
static inline void kmemleak_alloc_phys(phys_addr_t phys, size_t size,
10-
int min_count, gfp_t gfp)
10+
gfp_t gfp)
1111
{
1212
}
1313

0 commit comments

Comments
 (0)