Message ID | 20220609124950.1694394-4-patrick.wang.shcn@gmail.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | mm: kmemleak: store objects allocated with physical address separately and check when scan | expand |
On Thu, Jun 09, 2022 at 08:49:50PM +0800, Patrick Wang wrote: > Check the physical address of objects for its boundary > when scan instead of in kmemleak_*_phys(). > > Fixes: 23c2d497de21 ("mm: kmemleak: take a full lowmem check in kmemleak_*_phys()") > Suggested-by: Catalin Marinas <catalin.marinas@arm.com> > Signed-off-by: Patrick Wang <patrick.wang.shcn@gmail.com> Reviewed-by: Catalin Marinas <catalin.marinas@arm.com> The fixed commit above was cc stable, so we'll probably need all these three patches in stable. But I'd keep them a bit in -next for testing first (and I see Andrew already picked them up; we might as well merge them in 5.20 and send them to -stable after, it's not some critical feature). Thanks for the series. I don't think you need to respin unless others of comments.
On 2022/6/10 02:16, Catalin Marinas wrote: > On Thu, Jun 09, 2022 at 08:49:50PM +0800, Patrick Wang wrote: >> Check the physical address of objects for its boundary >> when scan instead of in kmemleak_*_phys(). >> >> Fixes: 23c2d497de21 ("mm: kmemleak: take a full lowmem check in kmemleak_*_phys()") >> Suggested-by: Catalin Marinas <catalin.marinas@arm.com> >> Signed-off-by: Patrick Wang <patrick.wang.shcn@gmail.com> > > Reviewed-by: Catalin Marinas <catalin.marinas@arm.com> > > The fixed commit above was cc stable, so we'll probably need all these > three patches in stable. But I'd keep them a bit in -next for testing > first (and I see Andrew already picked them up; we might as well merge > them in 5.20 and send them to -stable after, it's not some critical > feature). > > Thanks for the series. I don't think you need to respin unless others of > comments. I've received an auto build test WARNING from kernel test robot: mm/kmemleak.c: In function 'scan_object': >> arch/powerpc/include/asm/page.h:215:42: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] 215 | #define __va(x) ((void *)(unsigned long)((phys_addr_t)(x) + VIRT_PHYS_OFFSET)) | ^ mm/kmemleak.c:1403:19: note: in expansion of macro '__va' 1403 | __va((void *)object->pointer) : | ^~~~ So I will replace __va((void *)object->pointer) to __va((phys_addr_t)object->pointer) for fixing this warning, and move the prototype change and the kmemleak_not_leak_phys() removal to a separate one as you suggested at the same time. Thanks for these comments and suggestions. Thanks, Patrick
On Sat, Jun 11, 2022 at 11:46:27AM +0800, Patrick Wang wrote: > I've received an auto build test WARNING from kernel test robot: > > mm/kmemleak.c: In function 'scan_object': > >> arch/powerpc/include/asm/page.h:215:42: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] > 215 | #define __va(x) ((void *)(unsigned long)((phys_addr_t)(x) + VIRT_PHYS_OFFSET)) > | ^ > mm/kmemleak.c:1403:19: note: in expansion of macro '__va' > 1403 | __va((void *)object->pointer) : > | ^~~~ Ah, yes, arm32 has the same issue with phys_addr_t defined as u64 in some configurations while long is 32-bit. > So I will replace __va((void *)object->pointer) > to __va((phys_addr_t)object->pointer) for fixing this warning, It makes sense.
diff --git a/mm/kmemleak.c b/mm/kmemleak.c index 155f50e1a604..387d6fa402c6 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -1184,7 +1184,7 @@ void __ref kmemleak_alloc_phys(phys_addr_t phys, size_t size, gfp_t gfp) { pr_debug("%s(0x%pa, %zu)\n", __func__, &phys, size); - if (PHYS_PFN(phys) >= min_low_pfn && PHYS_PFN(phys) < max_low_pfn) + if (kmemleak_enabled) /* * Create object with OBJECT_PHYS flag and * assume min_count 0. @@ -1204,7 +1204,7 @@ void __ref kmemleak_free_part_phys(phys_addr_t phys, size_t size) { pr_debug("%s(0x%pa)\n", __func__, &phys); - if (PHYS_PFN(phys) >= min_low_pfn && PHYS_PFN(phys) < max_low_pfn) + if (kmemleak_enabled) delete_object_part((unsigned long)phys, size, true); } EXPORT_SYMBOL(kmemleak_free_part_phys); @@ -1218,7 +1218,7 @@ void __ref kmemleak_ignore_phys(phys_addr_t phys) { pr_debug("%s(0x%pa)\n", __func__, &phys); - if (PHYS_PFN(phys) >= min_low_pfn && PHYS_PFN(phys) < max_low_pfn) + if (kmemleak_enabled) make_black_object((unsigned long)phys, true); } EXPORT_SYMBOL(kmemleak_ignore_phys); @@ -1493,6 +1493,17 @@ static void kmemleak_scan(void) dump_object_info(object); } #endif + + /* ignore objects outside lowmem (paint them black) */ + if ((object->flags & OBJECT_PHYS) && + !(object->flags & OBJECT_NO_SCAN)) { + unsigned long phys = object->pointer; + + if (PHYS_PFN(phys) < min_low_pfn || + PHYS_PFN(phys + object->size) >= max_low_pfn) + __paint_it(object, KMEMLEAK_BLACK); + } + /* reset the reference count (whiten the object) */ object->count = 0; if (color_gray(object) && get_object(object))
Check the physical address of objects for its boundary when scan instead of in kmemleak_*_phys(). Fixes: 23c2d497de21 ("mm: kmemleak: take a full lowmem check in kmemleak_*_phys()") Suggested-by: Catalin Marinas <catalin.marinas@arm.com> Signed-off-by: Patrick Wang <patrick.wang.shcn@gmail.com> --- mm/kmemleak.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)