x86/xen: cleanup arch/x86/xen/mmu.c
[cascardo/linux.git] / arch / x86 / xen / mmu.c
index a8a1a3d..adca9e2 100644 (file)
@@ -387,7 +387,7 @@ static pteval_t pte_pfn_to_mfn(pteval_t val)
                unsigned long mfn;
 
                if (!xen_feature(XENFEAT_auto_translated_physmap))
-                       mfn = get_phys_to_machine(pfn);
+                       mfn = __pfn_to_mfn(pfn);
                else
                        mfn = pfn;
                /*
@@ -410,13 +410,7 @@ static pteval_t pte_pfn_to_mfn(pteval_t val)
 __visible pteval_t xen_pte_val(pte_t pte)
 {
        pteval_t pteval = pte.pte;
-#if 0
-       /* If this is a WC pte, convert back from Xen WC to Linux WC */
-       if ((pteval & (_PAGE_PAT | _PAGE_PCD | _PAGE_PWT)) == _PAGE_PAT) {
-               WARN_ON(!pat_enabled);
-               pteval = (pteval & ~_PAGE_PAT) | _PAGE_PWT;
-       }
-#endif
+
        return pte_mfn_to_pfn(pteval);
 }
 PV_CALLEE_SAVE_REGS_THUNK(xen_pte_val);
@@ -427,47 +421,8 @@ __visible pgdval_t xen_pgd_val(pgd_t pgd)
 }
 PV_CALLEE_SAVE_REGS_THUNK(xen_pgd_val);
 
-/*
- * Xen's PAT setup is part of its ABI, though I assume entries 6 & 7
- * are reserved for now, to correspond to the Intel-reserved PAT
- * types.
- *
- * We expect Linux's PAT set as follows:
- *
- * Idx  PTE flags        Linux    Xen    Default
- * 0                     WB       WB     WB
- * 1            PWT      WC       WT     WT
- * 2        PCD          UC-      UC-    UC-
- * 3        PCD PWT      UC       UC     UC
- * 4    PAT              WB       WC     WB
- * 5    PAT     PWT      WC       WP     WT
- * 6    PAT PCD          UC-      rsv    UC-
- * 7    PAT PCD PWT      UC       rsv    UC
- */
-
-void xen_set_pat(u64 pat)
-{
-       /* We expect Linux to use a PAT setting of
-        * UC UC- WC WB (ignoring the PAT flag) */
-       WARN_ON(pat != 0x0007010600070106ull);
-}
-
 __visible pte_t xen_make_pte(pteval_t pte)
 {
-#if 0
-       /* If Linux is trying to set a WC pte, then map to the Xen WC.
-        * If _PAGE_PAT is set, then it probably means it is really
-        * _PAGE_PSE, so avoid fiddling with the PAT mapping and hope
-        * things work out OK...
-        *
-        * (We should never see kernel mappings with _PAGE_PSE set,
-        * but we could see hugetlbfs mappings, I think.).
-        */
-       if (pat_enabled && !WARN_ON(pte & _PAGE_PAT)) {
-               if ((pte & (_PAGE_PCD | _PAGE_PWT)) == _PAGE_PWT)
-                       pte = (pte & ~(_PAGE_PCD | _PAGE_PWT)) | _PAGE_PAT;
-       }
-#endif
        pte = pte_pfn_to_mfn(pte);
 
        return native_make_pte(pte);
@@ -1158,20 +1113,16 @@ static void __init xen_cleanhighmap(unsigned long vaddr,
         * instead of somewhere later and be confusing. */
        xen_mc_flush();
 }
-static void __init xen_pagetable_p2m_copy(void)
+
+static void __init xen_pagetable_p2m_free(void)
 {
        unsigned long size;
        unsigned long addr;
-       unsigned long new_mfn_list;
-
-       if (xen_feature(XENFEAT_auto_translated_physmap))
-               return;
 
        size = PAGE_ALIGN(xen_start_info->nr_pages * sizeof(unsigned long));
 
-       new_mfn_list = xen_revector_p2m_tree();
        /* No memory or already called. */
-       if (!new_mfn_list || new_mfn_list == xen_start_info->mfn_list)
+       if ((unsigned long)xen_p2m_addr == xen_start_info->mfn_list)
                return;
 
        /* using __ka address and sticking INVALID_P2M_ENTRY! */
@@ -1189,8 +1140,6 @@ static void __init xen_pagetable_p2m_copy(void)
 
        size = PAGE_ALIGN(xen_start_info->nr_pages * sizeof(unsigned long));
        memblock_free(__pa(xen_start_info->mfn_list), size);
-       /* And revector! Bye bye old array */
-       xen_start_info->mfn_list = new_mfn_list;
 
        /* At this stage, cleanup_highmap has already cleaned __ka space
         * from _brk_limit way up to the max_pfn_mapped (which is the end of
@@ -1214,17 +1163,35 @@ static void __init xen_pagetable_p2m_copy(void)
 }
 #endif
 
-static void __init xen_pagetable_init(void)
+static void __init xen_pagetable_p2m_setup(void)
 {
-       paging_init();
+       if (xen_feature(XENFEAT_auto_translated_physmap))
+               return;
+
+       xen_vmalloc_p2m_tree();
+
 #ifdef CONFIG_X86_64
-       xen_pagetable_p2m_copy();
+       xen_pagetable_p2m_free();
 #endif
+       /* And revector! Bye bye old array */
+       xen_start_info->mfn_list = (unsigned long)xen_p2m_addr;
+}
+
+static void __init xen_pagetable_init(void)
+{
+       paging_init();
+       xen_post_allocator_init();
+
+       xen_pagetable_p2m_setup();
+
        /* Allocate and initialize top and mid mfn levels for p2m structure */
        xen_build_mfn_list_list();
 
+       /* Remap memory freed due to conflicts with E820 map */
+       if (!xen_feature(XENFEAT_auto_translated_physmap))
+               xen_remap_memory();
+
        xen_setup_shared_info();
-       xen_post_allocator_init();
 }
 static void xen_write_cr2(unsigned long cr2)
 {
@@ -1457,8 +1424,10 @@ static int xen_pgd_alloc(struct mm_struct *mm)
                page->private = (unsigned long)user_pgd;
 
                if (user_pgd != NULL) {
+#ifdef CONFIG_X86_VSYSCALL_EMULATION
                        user_pgd[pgd_index(VSYSCALL_ADDR)] =
                                __pgd(__pa(level3_user_vsyscall) | _PAGE_TABLE);
+#endif
                        ret = 0;
                }
 
@@ -1520,7 +1489,7 @@ static void __init xen_set_pte_init(pte_t *ptep, pte_t pte)
        native_set_pte(ptep, pte);
 }
 
-static void pin_pagetable_pfn(unsigned cmd, unsigned long pfn)
+static void __init pin_pagetable_pfn(unsigned cmd, unsigned long pfn)
 {
        struct mmuext_op op;
        op.cmd = cmd;
@@ -1688,7 +1657,7 @@ void __init xen_reserve_top(void)
  * Like __va(), but returns address in the kernel mapping (which is
  * all we have until the physical memory mapping has been set up.
  */
-static void *__ka(phys_addr_t paddr)
+static void * __init __ka(phys_addr_t paddr)
 {
 #ifdef CONFIG_X86_64
        return (void *)(paddr + __START_KERNEL_map);
@@ -1698,7 +1667,7 @@ static void *__ka(phys_addr_t paddr)
 }
 
 /* Convert a machine address to physical address */
-static unsigned long m2p(phys_addr_t maddr)
+static unsigned long __init m2p(phys_addr_t maddr)
 {
        phys_addr_t paddr;
 
@@ -1709,13 +1678,14 @@ static unsigned long m2p(phys_addr_t maddr)
 }
 
 /* Convert a machine address to kernel virtual */
-static void *m2v(phys_addr_t maddr)
+static void * __init m2v(phys_addr_t maddr)
 {
        return __ka(m2p(maddr));
 }
 
 /* Set the page permissions on an identity-mapped pages */
-static void set_page_prot_flags(void *addr, pgprot_t prot, unsigned long flags)
+static void __init set_page_prot_flags(void *addr, pgprot_t prot,
+                                      unsigned long flags)
 {
        unsigned long pfn = __pa(addr) >> PAGE_SHIFT;
        pte_t pte = pfn_pte(pfn, prot);
@@ -1727,7 +1697,7 @@ static void set_page_prot_flags(void *addr, pgprot_t prot, unsigned long flags)
        if (HYPERVISOR_update_va_mapping((unsigned long)addr, pte, flags))
                BUG();
 }
-static void set_page_prot(void *addr, pgprot_t prot)
+static void __init set_page_prot(void *addr, pgprot_t prot)
 {
        return set_page_prot_flags(addr, prot, UVMF_NONE);
 }
@@ -1764,10 +1734,8 @@ static void __init xen_map_identity_early(pmd_t *pmd, unsigned long max_pfn)
                for (pteidx = 0; pteidx < PTRS_PER_PTE; pteidx++, pfn++) {
                        pte_t pte;
 
-#ifdef CONFIG_X86_32
                        if (pfn > max_pfn_mapped)
                                max_pfn_mapped = pfn;
-#endif
 
                        if (!pte_none(pte_page[pteidx]))
                                continue;
@@ -1800,7 +1768,7 @@ void __init xen_setup_machphys_mapping(void)
 }
 
 #ifdef CONFIG_X86_64
-static void convert_pfn_mfn(void *v)
+static void __init convert_pfn_mfn(void *v)
 {
        pte_t *pte = v;
        int i;
@@ -2021,7 +1989,7 @@ static void xen_set_fixmap(unsigned idx, phys_addr_t phys, pgprot_t prot)
 # ifdef CONFIG_HIGHMEM
        case FIX_KMAP_BEGIN ... FIX_KMAP_END:
 # endif
-#else
+#elif defined(CONFIG_X86_VSYSCALL_EMULATION)
        case VSYSCALL_PAGE:
 #endif
        case FIX_TEXT_POKE0:
@@ -2060,7 +2028,7 @@ static void xen_set_fixmap(unsigned idx, phys_addr_t phys, pgprot_t prot)
 
        __native_set_fixmap(idx, pte);
 
-#ifdef CONFIG_X86_64
+#ifdef CONFIG_X86_VSYSCALL_EMULATION
        /* Replicate changes to map the vsyscall page into the user
           pagetable vsyscall mapping. */
        if (idx == VSYSCALL_PAGE) {