Skip to content

Commit 84c3262

Browse files
Patrick Wangakpm00
authored andcommitted
mm: kmemleak: check physical address when scan
Check the physical address of objects for its boundary when scan instead of in kmemleak_*_phys(). Link: https://lkml.kernel.org/r/[email protected] Fixes: 23c2d49 ("mm: kmemleak: take a full lowmem check in kmemleak_*_phys()") 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 0c24e06 commit 84c3262

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

mm/kmemleak.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,7 +1184,7 @@ void __ref kmemleak_alloc_phys(phys_addr_t phys, size_t size, gfp_t gfp)
11841184
{
11851185
pr_debug("%s(0x%pa, %zu)\n", __func__, &phys, size);
11861186

1187-
if (PHYS_PFN(phys) >= min_low_pfn && PHYS_PFN(phys) < max_low_pfn)
1187+
if (kmemleak_enabled)
11881188
/*
11891189
* Create object with OBJECT_PHYS flag and
11901190
* assume min_count 0.
@@ -1204,7 +1204,7 @@ void __ref kmemleak_free_part_phys(phys_addr_t phys, size_t size)
12041204
{
12051205
pr_debug("%s(0x%pa)\n", __func__, &phys);
12061206

1207-
if (PHYS_PFN(phys) >= min_low_pfn && PHYS_PFN(phys) < max_low_pfn)
1207+
if (kmemleak_enabled)
12081208
delete_object_part((unsigned long)phys, size, true);
12091209
}
12101210
EXPORT_SYMBOL(kmemleak_free_part_phys);
@@ -1218,7 +1218,7 @@ void __ref kmemleak_ignore_phys(phys_addr_t phys)
12181218
{
12191219
pr_debug("%s(0x%pa)\n", __func__, &phys);
12201220

1221-
if (PHYS_PFN(phys) >= min_low_pfn && PHYS_PFN(phys) < max_low_pfn)
1221+
if (kmemleak_enabled)
12221222
make_black_object((unsigned long)phys, true);
12231223
}
12241224
EXPORT_SYMBOL(kmemleak_ignore_phys);
@@ -1493,6 +1493,17 @@ static void kmemleak_scan(void)
14931493
dump_object_info(object);
14941494
}
14951495
#endif
1496+
1497+
/* ignore objects outside lowmem (paint them black) */
1498+
if ((object->flags & OBJECT_PHYS) &&
1499+
!(object->flags & OBJECT_NO_SCAN)) {
1500+
unsigned long phys = object->pointer;
1501+
1502+
if (PHYS_PFN(phys) < min_low_pfn ||
1503+
PHYS_PFN(phys + object->size) >= max_low_pfn)
1504+
__paint_it(object, KMEMLEAK_BLACK);
1505+
}
1506+
14961507
/* reset the reference count (whiten the object) */
14971508
object->count = 0;
14981509
if (color_gray(object) && get_object(object))

0 commit comments

Comments
 (0)