Skip to content

Commit 0d17e13

Browse files
committed
mm: kmemleak: check physical address when scan
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2151065 Conflicts: A minor context diff due to the presence of a later upstream commit 6edda04 ("mm/kmemleak: prevent soft lockup in first object iteration loop of kmemleak_scan()"). commit 84c3262 Author: Patrick Wang <patrick.wang.shcn@gmail.com> Date: Sat, 11 Jun 2022 11:55:51 +0800 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/20220611035551.1823303-5-patrick.wang.shcn@gmail.com Fixes: 23c2d49 ("mm: kmemleak: take a full lowmem check in kmemleak_*_phys()") 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> Signed-off-by: Waiman Long <longman@redhat.com>
1 parent e489114 commit 0d17e13

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);
@@ -1516,6 +1516,17 @@ static void kmemleak_scan(void)
15161516
dump_object_info(object);
15171517
}
15181518
#endif
1519+
1520+
/* ignore objects outside lowmem (paint them black) */
1521+
if ((object->flags & OBJECT_PHYS) &&
1522+
!(object->flags & OBJECT_NO_SCAN)) {
1523+
unsigned long phys = object->pointer;
1524+
1525+
if (PHYS_PFN(phys) < min_low_pfn ||
1526+
PHYS_PFN(phys + object->size) >= max_low_pfn)
1527+
__paint_it(object, KMEMLEAK_BLACK);
1528+
}
1529+
15191530
/* reset the reference count (whiten the object) */
15201531
object->count = 0;
15211532
if (color_gray(object) && get_object(object)) {

0 commit comments

Comments
 (0)