mm: page_alloc: add kasan hooks on alloc and free paths
[cascardo/linux.git] / mm / page_alloc.c
index 8d52ab1..a47f0b2 100644 (file)
@@ -25,6 +25,7 @@
 #include <linux/compiler.h>
 #include <linux/kernel.h>
 #include <linux/kmemcheck.h>
+#include <linux/kasan.h>
 #include <linux/module.h>
 #include <linux/suspend.h>
 #include <linux/pagevec.h>
@@ -172,7 +173,7 @@ static void __free_pages_ok(struct page *page, unsigned int order);
  *     1G machine -> (16M dma, 784M normal, 224M high)
  *     NORMAL allocation will leave 784M/256 of ram reserved in the ZONE_DMA
  *     HIGHMEM allocation will leave 224M/32 of ram reserved in ZONE_NORMAL
- *     HIGHMEM allocation will (224M+784M)/256 of ram reserved in ZONE_DMA
+ *     HIGHMEM allocation will leave (224M+784M)/256 of ram reserved in ZONE_DMA
  *
  * TBD: should special case ZONE_DMA32 machines here - in those we normally
  * don't need any ZONE_NORMAL reservation
@@ -787,6 +788,7 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
 
        trace_mm_page_free(page, order);
        kmemcheck_free_shadow(page, order);
+       kasan_free_pages(page, order);
 
        if (PageAnon(page))
                page->mapping = NULL;
@@ -970,6 +972,7 @@ static int prep_new_page(struct page *page, unsigned int order, gfp_t gfp_flags,
 
        arch_alloc_page(page, order);
        kernel_map_pages(page, 1 << order, 1);
+       kasan_alloc_pages(page, order);
 
        if (gfp_flags & __GFP_ZERO)
                prep_zero_page(page, order, gfp_flags);
@@ -3871,18 +3874,29 @@ static int __build_all_zonelists(void *data)
        return 0;
 }
 
+static noinline void __init
+build_all_zonelists_init(void)
+{
+       __build_all_zonelists(NULL);
+       mminit_verify_zonelist();
+       cpuset_init_current_mems_allowed();
+}
+
 /*
  * Called with zonelists_mutex held always
  * unless system_state == SYSTEM_BOOTING.
+ *
+ * __ref due to (1) call of __meminit annotated setup_zone_pageset
+ * [we're only called with non-NULL zone through __meminit paths] and
+ * (2) call of __init annotated helper build_all_zonelists_init
+ * [protected by SYSTEM_BOOTING].
  */
 void __ref build_all_zonelists(pg_data_t *pgdat, struct zone *zone)
 {
        set_zonelist_order();
 
        if (system_state == SYSTEM_BOOTING) {
-               __build_all_zonelists(NULL);
-               mminit_verify_zonelist();
-               cpuset_init_current_mems_allowed();
+               build_all_zonelists_init();
        } else {
 #ifdef CONFIG_MEMORY_HOTPLUG
                if (zone)