x86: init memory debugging
[sfrench/cifs-2.6.git] / arch / x86 / mm / init_32.c
index 206e3f6800b911a70608fbc3ed0c311072fc27c9..8d7f723cfc28181786f78c63c894198a6dcc0cb3 100644 (file)
@@ -211,28 +211,6 @@ static inline int page_kills_ppro(unsigned long pagenr)
        return 0;
 }
 
-int page_is_ram(unsigned long pagenr)
-{
-       int i;
-       unsigned long addr, end;
-
-       for (i = 0; i < e820.nr_map; i++) {
-
-               if (e820.map[i].type != E820_RAM)       /* not usable memory */
-                       continue;
-               /*
-                *      !!!FIXME!!! Some BIOSen report areas as RAM that
-                *      are not. Notably the 640->1Mb area. We need a sanity
-                *      check here.
-                */
-               addr = (e820.map[i].addr+PAGE_SIZE-1) >> PAGE_SHIFT;
-               end = (e820.map[i].addr+e820.map[i].size) >> PAGE_SHIFT;
-               if  ((pagenr >= addr) && (pagenr < end))
-                       return 1;
-       }
-       return 0;
-}
-
 #ifdef CONFIG_HIGHMEM
 pte_t *kmap_pte;
 pgprot_t kmap_prot;
@@ -332,9 +310,9 @@ static void __init set_highmem_pages_init(int bad_ppro)
 #define set_highmem_pages_init(bad_ppro) do { } while (0)
 #endif /* CONFIG_HIGHMEM */
 
-unsigned long long __PAGE_KERNEL = _PAGE_KERNEL;
+pteval_t __PAGE_KERNEL = _PAGE_KERNEL;
 EXPORT_SYMBOL(__PAGE_KERNEL);
-unsigned long long __PAGE_KERNEL_EXEC = _PAGE_KERNEL_EXEC;
+pteval_t __PAGE_KERNEL_EXEC = _PAGE_KERNEL_EXEC;
 
 #ifdef CONFIG_NUMA
 extern void __init remap_numa_kva(void);
@@ -429,9 +407,11 @@ static void __init pagetable_init (void)
         * Fixed mappings, only the page table structure has to be
         * created - mappings will be set by set_fixmap():
         */
+       early_ioremap_clear();
        vaddr = __fix_to_virt(__end_of_fixed_addresses - 1) & PMD_MASK;
        end = (FIXADDR_TOP + PMD_SIZE - 1) & PMD_MASK;
        page_table_range_init(vaddr, end, pgd_base);
+       early_ioremap_reset();
 
        permanent_kmaps_init(pgd_base);
 
@@ -527,35 +507,6 @@ static void __init set_nx(void)
        }
 }
 
-/*
- * Enables/disables executability of a given kernel page and
- * returns the previous setting.
- */
-int __init set_kernel_exec(unsigned long vaddr, int enable)
-{
-       pte_t *pte;
-       int ret = 1;
-       int level;
-
-       if (!nx_enabled)
-               goto out;
-
-       pte = lookup_address(vaddr, &level);
-       BUG_ON(!pte);
-
-       if (!pte_exec(*pte))
-               ret = 0;
-
-       if (enable)
-               pte->pte_high &= ~(1 << (_PAGE_BIT_NX - 32));
-       else
-               pte->pte_high |= 1 << (_PAGE_BIT_NX - 32);
-       pte_update_defer(&init_mm, vaddr, pte);
-       __flush_tlb_all();
-out:
-       return ret;
-}
-
 #endif
 
 /*
@@ -785,6 +736,8 @@ static int noinline do_test_wp_bit(void)
 }
 
 #ifdef CONFIG_DEBUG_RODATA
+const int rodata_test_data = 0xC3;
+EXPORT_SYMBOL_GPL(rodata_test_data);
 
 void mark_rodata_ro(void)
 {
@@ -797,50 +750,31 @@ void mark_rodata_ro(void)
        if (num_possible_cpus() <= 1)
 #endif
        {
-               change_page_attr(virt_to_page(start),
-                                size >> PAGE_SHIFT, PAGE_KERNEL_RX);
+               set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
                printk("Write protecting the kernel text: %luk\n", size >> 10);
 
 #ifdef CONFIG_CPA_DEBUG
-               global_flush_tlb();
-
                printk("Testing CPA: Reverting %lx-%lx\n", start, start+size);
-               change_page_attr(virt_to_page(start), size>>PAGE_SHIFT,
-                                PAGE_KERNEL_EXEC);
-               global_flush_tlb();
+               set_pages_rw(virt_to_page(start), size>>PAGE_SHIFT);
 
                printk("Testing CPA: write protecting again\n");
-               change_page_attr(virt_to_page(start), size>>PAGE_SHIFT,
-                               PAGE_KERNEL_RX);
-               global_flush_tlb();
+               set_pages_ro(virt_to_page(start), size>>PAGE_SHIFT);
 #endif
        }
 #endif
        start += size;
        size = (unsigned long)__end_rodata - start;
-       change_page_attr(virt_to_page(start),
-                        size >> PAGE_SHIFT, PAGE_KERNEL_RO);
+       set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
        printk("Write protecting the kernel read-only data: %luk\n",
               size >> 10);
-
-       /*
-        * change_page_attr() requires a global_flush_tlb() call after it.
-        * We do this after the printk so that if something went wrong in the
-        * change, the printk gets out at least to give a better debug hint
-        * of who is the culprit.
-        */
-       global_flush_tlb();
+       rodata_test();
 
 #ifdef CONFIG_CPA_DEBUG
        printk("Testing CPA: undo %lx-%lx\n", start, start + size);
-       change_page_attr(virt_to_page(start), size >> PAGE_SHIFT,
-                               PAGE_KERNEL);
-       global_flush_tlb();
+       set_pages_rw(virt_to_page(start), size >> PAGE_SHIFT);
 
        printk("Testing CPA: write protecting again\n");
-       change_page_attr(virt_to_page(start), size >> PAGE_SHIFT,
-                               PAGE_KERNEL_RO);
-       global_flush_tlb();
+       set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
 #endif
 }
 #endif
@@ -849,6 +783,23 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
 {
        unsigned long addr;
 
+#ifdef CONFIG_DEBUG_PAGEALLOC
+       /*
+        * If debugging page accesses then do not free this memory but
+        * mark them not present - any buggy init-section access will
+        * create a kernel page fault:
+        */
+       printk(KERN_INFO "debug: unmapping init memory %08lx..%08lx\n",
+               begin, PAGE_ALIGN(end));
+       set_memory_np(begin, (end - begin) >> PAGE_SHIFT);
+#else
+       /*
+        * We just marked the kernel text read only above, now that
+        * we are going to free part of that, we need to make that
+        * writeable first.
+        */
+       set_memory_rw(begin, (end - begin) >> PAGE_SHIFT);
+
        for (addr = begin; addr < end; addr += PAGE_SIZE) {
                ClearPageReserved(virt_to_page(addr));
                init_page_count(virt_to_page(addr));
@@ -857,6 +808,7 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
                totalram_pages++;
        }
        printk(KERN_INFO "Freeing %s: %luk freed\n", what, (end - begin) >> 10);
+#endif
 }
 
 void free_initmem(void)