Re: [RFC PATCH 2/3] kmemleak: Add callbacks to the bootmemallocator

From: Catalin Marinas
Date: Wed Jul 08 2009 - 05:44:19 EST


On Wed, 2009-07-08 at 09:48 +0300, Pekka Enberg wrote:
> On Tue, 2009-07-07 at 23:09 +0100, Catalin Marinas wrote:
> > On Tue, 2009-07-07 at 18:53 +0200, Johannes Weiner wrote:
> > > On Tue, Jul 07, 2009 at 10:08:50AM +0300, Pekka Enberg wrote:
> > > > On Mon, 2009-07-06 at 11:51 +0100, Catalin Marinas wrote:
> > > > > @@ -597,7 +601,9 @@ restart:
> > > > > void * __init __alloc_bootmem_nopanic(unsigned long size, unsigned long align,
> > > > > unsigned long goal)
> > > > > {
> > > > > - return ___alloc_bootmem_nopanic(size, align, goal, 0);
> > > > > + void *ptr = ___alloc_bootmem_nopanic(size, align, goal, 0);
> > > > > + kmemleak_alloc(ptr, size, 1, GFP_KERNEL);
> > > > > + return ptr;
> > >
> > > You may get an object from kzalloc() here, I don't think you want to
> > > track that (again), right?
> >
> > You are write, I missed the alloc_arch_preferred_bootmem() function
> > which may call kzalloc().
> >
> > > Pekka already worked out all the central places to catch 'slab already
> > > available' allocations, they can probably help you place the hooks.
> >
> > It seems that alloc_bootmem_core() is central to all the bootmem
> > allocations. Is it OK to place the kmemleak_alloc hook only in this
> > function?
>
> I think so. Johannes?

To get a better view, here's the complete patch:


kmemleak: Add callbacks to the bootmem allocator

From: Catalin Marinas <catalin.marinas@xxxxxxx>

This patch adds kmemleak_alloc/free callbacks to the bootmem allocator.
This would allow scanning of such blocks and help avoiding a whole class
of false positives and more kmemleak annotations.

Signed-off-by: Catalin Marinas <catalin.marinas@xxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxx>
Cc: Pekka Enberg <penberg@xxxxxxxxxxxxxx>
---
mm/bootmem.c | 5 +++++
1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/mm/bootmem.c b/mm/bootmem.c
index d2a9ce9..90f3ed0 100644
--- a/mm/bootmem.c
+++ b/mm/bootmem.c
@@ -335,6 +335,8 @@ void __init free_bootmem_node(pg_data_t *pgdat, unsigned long physaddr,
{
unsigned long start, end;

+ kmemleak_free_part(__va(physaddr), size);
+
start = PFN_UP(physaddr);
end = PFN_DOWN(physaddr + size);

@@ -354,6 +356,8 @@ void __init free_bootmem(unsigned long addr, unsigned long size)
{
unsigned long start, end;

+ kmemleak_free_part(__va(addr), size);
+
start = PFN_UP(addr);
end = PFN_DOWN(addr + size);

@@ -516,6 +520,7 @@ find_block:
region = phys_to_virt(PFN_PHYS(bdata->node_min_pfn) +
start_off);
memset(region, 0, size);
+ kmemleak_alloc(region, size, 1, 0);
return region;
}


--
Catalin

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/