]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - arch/x86/mm/init_64.c
x86: mark the .rodata section also NX
[linux-2.6-omap-h63xx.git] / arch / x86 / mm / init_64.c
index bb732bb79b4a073d1b42392d43399e100d16271c..9b61c75a23556f76898ca2f8b1d26d71b206ca26 100644 (file)
 #include <asm/kdebug.h>
 #include <asm/numa.h>
 
-#ifndef Dprintk
-# define Dprintk(x...)
-#endif
-
 const struct dma_mapping_ops *dma_ops;
 EXPORT_SYMBOL(dma_ops);
 
@@ -119,7 +115,7 @@ static __init void *spp_getpage(void)
                        after_bootmem ? "after bootmem" : "");
        }
 
-       Dprintk("spp_getpage %p\n", ptr);
+       pr_debug("spp_getpage %p\n", ptr);
 
        return ptr;
 }
@@ -132,11 +128,12 @@ set_pte_phys(unsigned long vaddr, unsigned long phys, pgprot_t prot)
        pmd_t *pmd;
        pte_t *pte, new_pte;
 
-       Dprintk("set_pte_phys %lx to %lx\n", vaddr, phys);
+       pr_debug("set_pte_phys %lx to %lx\n", vaddr, phys);
 
        pgd = pgd_offset_k(vaddr);
        if (pgd_none(*pgd)) {
-               printk("PGD FIXMAP MISSING, it should be setup in head.S!\n");
+               printk(KERN_ERR
+                       "PGD FIXMAP MISSING, it should be setup in head.S!\n");
                return;
        }
        pud = pud_offset(pgd, vaddr);
@@ -144,7 +141,7 @@ set_pte_phys(unsigned long vaddr, unsigned long phys, pgprot_t prot)
                pmd = (pmd_t *) spp_getpage();
                set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE | _PAGE_USER));
                if (pmd != pmd_offset(pud, 0)) {
-                       printk("PAGETABLE BUG #01! %p <-> %p\n",
+                       printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
                                pmd, pmd_offset(pud, 0));
                        return;
                }
@@ -154,7 +151,7 @@ set_pte_phys(unsigned long vaddr, unsigned long phys, pgprot_t prot)
                pte = (pte_t *) spp_getpage();
                set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE | _PAGE_USER));
                if (pte != pte_offset_kernel(pmd, 0)) {
-                       printk("PAGETABLE BUG #02!\n");
+                       printk(KERN_ERR "PAGETABLE BUG #02!\n");
                        return;
                }
        }
@@ -180,7 +177,7 @@ __set_fixmap(enum fixed_addresses idx, unsigned long phys, pgprot_t prot)
        unsigned long address = __fix_to_virt(idx);
 
        if (idx >= __end_of_fixed_addresses) {
-               printk("Invalid __set_fixmap\n");
+               printk(KERN_ERR "Invalid __set_fixmap\n");
                return;
        }
        set_pte_phys(address, phys, prot);
@@ -246,7 +243,7 @@ __meminit void *early_ioremap(unsigned long addr, unsigned long size)
 continue_outer_loop:
                ;
        }
-       printk("early_ioremap(0x%lx, %lu) failed\n", addr, size);
+       printk(KERN_ERR "early_ioremap(0x%lx, %lu) failed\n", addr, size);
 
        return NULL;
 }
@@ -276,7 +273,6 @@ phys_pmd_init(pmd_t *pmd_page, unsigned long address, unsigned long end)
        int i = pmd_index(address);
 
        for (; i < PTRS_PER_PMD; i++, address += PMD_SIZE) {
-               unsigned long entry;
                pmd_t *pmd = pmd_page + pmd_index(address);
 
                if (address >= end) {
@@ -290,9 +286,8 @@ phys_pmd_init(pmd_t *pmd_page, unsigned long address, unsigned long end)
                if (pmd_val(*pmd))
                        continue;
 
-               entry = __PAGE_KERNEL_LARGE|_PAGE_GLOBAL|address;
-               entry &= __supported_pte_mask;
-               set_pmd(pmd, __pmd(entry));
+               set_pte((pte_t *)pmd,
+                       pfn_pte(address >> PAGE_SHIFT, PAGE_KERNEL_LARGE));
        }
 }
 
@@ -357,7 +352,7 @@ static void __init find_early_table_space(unsigned long end)
         * need roughly 0.5KB per GB.
         */
        start = 0x8000;
-       table_start = find_e820_area(start, end, tables);
+       table_start = find_e820_area(start, end, tables, PAGE_SIZE);
        if (table_start == -1UL)
                panic("Cannot find space for the kernel page tables");
 
@@ -378,7 +373,7 @@ void __init_refok init_memory_mapping(unsigned long start, unsigned long end)
 {
        unsigned long next;
 
-       Dprintk("init_memory_mapping\n");
+       pr_debug("init_memory_mapping\n");
 
        /*
         * Find space for the kernel direct mapping tables.
@@ -416,7 +411,9 @@ void __init_refok init_memory_mapping(unsigned long start, unsigned long end)
                mmu_cr4_features = read_cr4();
        __flush_tlb_all();
 
-       reserve_early(table_start << PAGE_SHIFT, table_end << PAGE_SHIFT);
+       if (!after_bootmem)
+               reserve_early(table_start << PAGE_SHIFT,
+                                table_end << PAGE_SHIFT, "PGTABLE");
 }
 
 #ifndef CONFIG_NUMA
@@ -435,49 +432,6 @@ void __init paging_init(void)
 }
 #endif
 
-/*
- * Unmap a kernel mapping if it exists. This is useful to avoid
- * prefetches from the CPU leading to inconsistent cache lines.
- * address and size must be aligned to 2MB boundaries.
- * Does nothing when the mapping doesn't exist.
- */
-void __init clear_kernel_mapping(unsigned long address, unsigned long size)
-{
-       unsigned long end = address + size;
-
-       BUG_ON(address & ~LARGE_PAGE_MASK);
-       BUG_ON(size & ~LARGE_PAGE_MASK);
-
-       for (; address < end; address += LARGE_PAGE_SIZE) {
-               pgd_t *pgd = pgd_offset_k(address);
-               pud_t *pud;
-               pmd_t *pmd;
-
-               if (pgd_none(*pgd))
-                       continue;
-
-               pud = pud_offset(pgd, address);
-               if (pud_none(*pud))
-                       continue;
-
-               pmd = pmd_offset(pud, address);
-               if (!pmd || pmd_none(*pmd))
-                       continue;
-
-               if (!(pmd_val(*pmd) & _PAGE_PSE)) {
-                       /*
-                        * Could handle this, but it should not happen
-                        * currently:
-                        */
-                       printk(KERN_ERR "clear_kernel_mapping: "
-                               "mapping has been split. will leak memory\n");
-                       pmd_ERROR(*pmd);
-               }
-               set_pmd(pmd, __pmd(0));
-       }
-       __flush_tlb_all();
-}
-
 /*
  * Memory hotplug specific functions
  */
@@ -506,8 +460,7 @@ int arch_add_memory(int nid, u64 start, u64 size)
        init_memory_mapping(start, start + size-1);
 
        ret = __add_pages(zone, start_pfn, nr_pages);
-       if (ret)
-               printk("%s: Problem encountered in __add_pages!\n", __func__);
+       WARN_ON(1);
 
        return ret;
 }
@@ -567,7 +520,7 @@ void __init mem_init(void)
        kclist_add(&kcore_vsyscall, (void *)VSYSCALL_START,
                                 VSYSCALL_END - VSYSCALL_START);
 
-       printk("Memory: %luk/%luk available (%ldk kernel code, "
+       printk(KERN_INFO "Memory: %luk/%luk available (%ldk kernel code, "
                                "%ldk reserved, %ldk data, %ldk init)\n",
                (unsigned long) nr_free_pages() << (PAGE_SHIFT-10),
                end_pfn << (PAGE_SHIFT-10),
@@ -638,18 +591,25 @@ void mark_rodata_ro(void)
        if (end <= start)
                return;
 
-       set_memory_ro(start, (end - start) >> PAGE_SHIFT);
 
        printk(KERN_INFO "Write protecting the kernel read-only data: %luk\n",
               (end - start) >> 10);
+       set_memory_ro(start, (end - start) >> PAGE_SHIFT);
+
+       /*
+        * The rodata section (but not the kernel text!) should also be
+        * not-executable.
+        */
+       start = ((unsigned long)__start_rodata + PAGE_SIZE - 1) & PAGE_MASK;
+       set_memory_nx(start, (end - start) >> PAGE_SHIFT);
 
        rodata_test();
 
 #ifdef CONFIG_CPA_DEBUG
-       printk("Testing CPA: undo %lx-%lx\n", start, end);
+       printk(KERN_INFO "Testing CPA: undo %lx-%lx\n", start, end);
        set_memory_rw(start, (end-start) >> PAGE_SHIFT);
 
-       printk("Testing CPA: again\n");
+       printk(KERN_INFO "Testing CPA: again\n");
        set_memory_ro(start, (end-start) >> PAGE_SHIFT);
 #endif
 }