]> nv-tegra.nvidia Code Review - linux-2.6.git/blobdiff - arch/i386/mm/pageattr.c
Remove obsolete #include <linux/config.h>
[linux-2.6.git] / arch / i386 / mm / pageattr.c
index bce06a79eafa556ecac212c3167bf02f34bce234..8564b6ae17e330aa7ca48489a3f71bbf458415ba 100644 (file)
@@ -3,7 +3,6 @@
  * Thanks to Ben LaHaise for precious feedback.
  */ 
 
-#include <linux/config.h>
 #include <linux/mm.h>
 #include <linux/sched.h>
 #include <linux/highmem.h>
@@ -12,6 +11,8 @@
 #include <asm/uaccess.h>
 #include <asm/processor.h>
 #include <asm/tlbflush.h>
+#include <asm/pgalloc.h>
+#include <asm/sections.h>
 
 static DEFINE_SPINLOCK(cpa_lock);
 static struct list_head df_list = LIST_HEAD_INIT(df_list);
@@ -35,7 +36,8 @@ pte_t *lookup_address(unsigned long address)
         return pte_offset_kernel(pmd, address);
 } 
 
-static struct page *split_large_page(unsigned long address, pgprot_t prot)
+static struct page *split_large_page(unsigned long address, pgprot_t prot,
+                                       pgprot_t ref_prot)
 { 
        int i; 
        unsigned long addr;
@@ -48,12 +50,19 @@ static struct page *split_large_page(unsigned long address, pgprot_t prot)
        if (!base) 
                return NULL;
 
+       /*
+        * page_private is used to track the number of entries in
+        * the page table page that have non standard attributes.
+        */
+       SetPagePrivate(base);
+       page_private(base) = 0;
+
        address = __pa(address);
        addr = address & LARGE_PAGE_MASK; 
        pbase = (pte_t *)page_address(base);
        for (i = 0; i < PTRS_PER_PTE; i++, addr += PAGE_SIZE) {
-               pbase[i] = pfn_pte(addr >> PAGE_SHIFT, 
-                                  addr == address ? prot : PAGE_KERNEL);
+               set_pte(&pbase[i], pfn_pte(addr >> PAGE_SHIFT,
+                                          addr == address ? prot : ref_prot));
        }
        return base;
 } 
@@ -97,11 +106,18 @@ static void set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
  */
 static inline void revert_page(struct page *kpte_page, unsigned long address)
 {
-       pte_t *linear = (pte_t *) 
+       pgprot_t ref_prot;
+       pte_t *linear;
+
+       ref_prot =
+       ((address & LARGE_PAGE_MASK) < (unsigned long)&_etext)
+               ? PAGE_KERNEL_LARGE_EXEC : PAGE_KERNEL_LARGE;
+
+       linear = (pte_t *)
                pmd_offset(pud_offset(pgd_offset_k(address), address), address);
        set_pmd_pte(linear,  address,
                    pfn_pte((__pa(address) & LARGE_PAGE_MASK) >> PAGE_SHIFT,
-                           PAGE_KERNEL_LARGE));
+                           ref_prot));
 }
 
 static int
@@ -122,16 +138,23 @@ __change_page_attr(struct page *page, pgprot_t prot)
                if ((pte_val(*kpte) & _PAGE_PSE) == 0) { 
                        set_pte_atomic(kpte, mk_pte(page, prot)); 
                } else {
-                       struct page *split = split_large_page(address, prot); 
+                       pgprot_t ref_prot;
+                       struct page *split;
+
+                       ref_prot =
+                       ((address & LARGE_PAGE_MASK) < (unsigned long)&_etext)
+                               ? PAGE_KERNEL_EXEC : PAGE_KERNEL;
+                       split = split_large_page(address, prot, ref_prot);
                        if (!split)
                                return -ENOMEM;
-                       set_pmd_pte(kpte,address,mk_pte(split, PAGE_KERNEL));
+                       set_pmd_pte(kpte,address,mk_pte(split, ref_prot));
                        kpte_page = split;
-               }       
-               get_page(kpte_page);
+               }
+               page_private(kpte_page)++;
        } else if ((pte_val(*kpte) & _PAGE_PSE) == 0) { 
                set_pte_atomic(kpte, mk_pte(page, PAGE_KERNEL));
-               __put_page(kpte_page);
+               BUG_ON(page_private(kpte_page) == 0);
+               page_private(kpte_page)--;
        } else
                BUG();
 
@@ -141,10 +164,8 @@ __change_page_attr(struct page *page, pgprot_t prot)
         * replace it with a largepage.
         */
        if (!PageReserved(kpte_page)) {
-               /* memleak and potential failed 2M page regeneration */
-               BUG_ON(!page_count(kpte_page));
-
-               if (cpu_has_pse && (page_count(kpte_page) == 1)) {
+               if (cpu_has_pse && (page_private(kpte_page) == 0)) {
+                       ClearPagePrivate(kpte_page);
                        list_add(&kpte_page->lru, &df_list);
                        revert_page(kpte_page, address);
                }
@@ -187,25 +208,29 @@ int change_page_attr(struct page *page, int numpages, pgprot_t prot)
 }
 
 void global_flush_tlb(void)
-{ 
-       LIST_HEAD(l);
+{
+       struct list_head l;
        struct page *pg, *next;
 
        BUG_ON(irqs_disabled());
 
        spin_lock_irq(&cpa_lock);
-       list_splice_init(&df_list, &l);
+       list_replace_init(&df_list, &l);
        spin_unlock_irq(&cpa_lock);
        flush_map();
        list_for_each_entry_safe(pg, next, &l, lru)
                __free_page(pg);
-} 
+}
 
 #ifdef CONFIG_DEBUG_PAGEALLOC
 void kernel_map_pages(struct page *page, int numpages, int enable)
 {
        if (PageHighMem(page))
                return;
+       if (!enable)
+               debug_check_no_locks_freed(page_address(page),
+                                          numpages * PAGE_SIZE);
+
        /* the return value is ignored - the calls cannot fail,
         * large pages are disabled at boot time.
         */