kmemcheck: add hooks for the page allocator
This adds support for tracking the initializedness of memory that was allocated with the page allocator. Highmem requests are not tracked. Cc: Dave Hansen <dave@linux.vnet.ibm.com> Acked-by: Pekka Enberg <penberg@cs.helsinki.fi> [build fix for !CONFIG_KMEMCHECK] Signed-off-by: Ingo Molnar <mingo@elte.hu> [rebased for mainline inclusion] Signed-off-by: Vegard Nossum <vegard.nossum@gmail.com>
This commit is contained in:
@ -23,6 +23,7 @@
|
||||
#include <linux/bootmem.h>
|
||||
#include <linux/compiler.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/kmemcheck.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/suspend.h>
|
||||
#include <linux/pagevec.h>
|
||||
@ -546,6 +547,8 @@ static void __free_pages_ok(struct page *page, unsigned int order)
|
||||
int i;
|
||||
int bad = 0;
|
||||
|
||||
kmemcheck_free_shadow(page, order);
|
||||
|
||||
for (i = 0 ; i < (1 << order) ; ++i)
|
||||
bad += free_pages_check(page + i);
|
||||
if (bad)
|
||||
@ -994,6 +997,8 @@ static void free_hot_cold_page(struct page *page, int cold)
|
||||
struct per_cpu_pages *pcp;
|
||||
unsigned long flags;
|
||||
|
||||
kmemcheck_free_shadow(page, 0);
|
||||
|
||||
if (PageAnon(page))
|
||||
page->mapping = NULL;
|
||||
if (free_pages_check(page))
|
||||
@ -1047,6 +1052,16 @@ void split_page(struct page *page, unsigned int order)
|
||||
|
||||
VM_BUG_ON(PageCompound(page));
|
||||
VM_BUG_ON(!page_count(page));
|
||||
|
||||
#ifdef CONFIG_KMEMCHECK
|
||||
/*
|
||||
* Split shadow pages too, because free(page[0]) would
|
||||
* otherwise free the whole shadow.
|
||||
*/
|
||||
if (kmemcheck_page_is_tracked(page))
|
||||
split_page(virt_to_page(page[0].shadow), order);
|
||||
#endif
|
||||
|
||||
for (i = 1; i < (1 << order); i++)
|
||||
set_page_refcounted(page + i);
|
||||
}
|
||||
@ -1667,7 +1682,10 @@ nopage:
|
||||
dump_stack();
|
||||
show_mem();
|
||||
}
|
||||
return page;
|
||||
got_pg:
|
||||
if (kmemcheck_enabled)
|
||||
kmemcheck_pagealloc_alloc(page, order, gfp_mask);
|
||||
return page;
|
||||
}
|
||||
EXPORT_SYMBOL(__alloc_pages_internal);
|
||||
|
Reference in New Issue
Block a user