xen: refactor xen_{alloc,release}_{pt,pd}()
[sfrench/cifs-2.6.git] / arch / x86 / xen / enlighten.c
index de647bc6e74db4e8bf42169d5ae9c5f37a3ad4a5..16e2f8096a1ac68332d479ea25158cfe4def0e4c 100644 (file)
@@ -95,7 +95,7 @@ struct shared_info *HYPERVISOR_shared_info = (void *)&dummy_shared_info;
  *
  * 0: not available, 1: available
  */
-static int have_vcpu_info_placement = 0;
+static int have_vcpu_info_placement = 1;
 
 static void __init xen_vcpu_setup(int cpu)
 {
@@ -103,6 +103,7 @@ static void __init xen_vcpu_setup(int cpu)
        int err;
        struct vcpu_info *vcpup;
 
+       BUG_ON(HYPERVISOR_shared_info == &dummy_shared_info);
        per_cpu(xen_vcpu, cpu) = &HYPERVISOR_shared_info->vcpu_info[cpu];
 
        if (!have_vcpu_info_placement)
@@ -153,6 +154,7 @@ static void xen_cpuid(unsigned int *ax, unsigned int *bx,
        if (*ax == 1)
                maskedx = ~((1 << X86_FEATURE_APIC) |  /* disable APIC */
                            (1 << X86_FEATURE_ACPI) |  /* disable ACPI */
+                           (1 << X86_FEATURE_SEP)  |  /* disable SEP */
                            (1 << X86_FEATURE_ACC));   /* thermal monitoring */
 
        asm(XEN_EMULATE_PREFIX "cpuid"
@@ -665,10 +667,10 @@ static void xen_release_pt_init(u32 pfn)
        make_lowmem_page_readwrite(__va(PFN_PHYS(pfn)));
 }
 
-static void pin_pagetable_pfn(unsigned level, unsigned long pfn)
+static void pin_pagetable_pfn(unsigned cmd, unsigned long pfn)
 {
        struct mmuext_op op;
-       op.cmd = level;
+       op.cmd = cmd;
        op.arg1.mfn = pfn_to_mfn(pfn);
        if (HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF))
                BUG();
@@ -685,7 +687,10 @@ static void xen_alloc_ptpage(struct mm_struct *mm, u32 pfn, unsigned level)
 
                if (!PageHighMem(page)) {
                        make_lowmem_page_readonly(__va(PFN_PHYS(pfn)));
-                       pin_pagetable_pfn(level, pfn);
+                       if (level == PT_PTE)
+                               pin_pagetable_pfn(MMUEXT_PIN_L1_TABLE, pfn);
+                       else if (level == PT_PMD)
+                               pin_pagetable_pfn(MMUEXT_PIN_L2_TABLE, pfn);
                } else
                        /* make sure there are no stray mappings of
                           this page */
@@ -695,16 +700,16 @@ static void xen_alloc_ptpage(struct mm_struct *mm, u32 pfn, unsigned level)
 
 static void xen_alloc_pt(struct mm_struct *mm, u32 pfn)
 {
-       xen_alloc_ptpage(mm, pfn, MMUEXT_PIN_L1_TABLE);
+       xen_alloc_ptpage(mm, pfn, PT_PTE);
 }
 
 static void xen_alloc_pd(struct mm_struct *mm, u32 pfn)
 {
-       xen_alloc_ptpage(mm, pfn, MMUEXT_PIN_L2_TABLE);
+       xen_alloc_ptpage(mm, pfn, PT_PMD);
 }
 
 /* This should never happen until we're OK to use struct page */
-static void xen_release_pt(u32 pfn)
+static void xen_release_ptpage(u32 pfn, unsigned level)
 {
        struct page *page = pfn_to_page(pfn);
 
@@ -716,6 +721,16 @@ static void xen_release_pt(u32 pfn)
        }
 }
 
+static void xen_release_pt(u32 pfn)
+{
+       xen_release_ptpage(pfn, PT_PTE);
+}
+
+static void xen_release_pd(u32 pfn)
+{
+       xen_release_ptpage(pfn, PT_PMD);
+}
+
 #ifdef CONFIG_HIGHPTE
 static void *xen_kmap_atomic_pte(struct page *page, enum km_type type)
 {
@@ -798,35 +813,49 @@ static __init void xen_pagetable_setup_start(pgd_t *base)
         * added to the table can be prepared properly for Xen.
         */
        xen_write_cr3(__pa(base));
+
+       /* Unpin initial Xen pagetable */
+       pin_pagetable_pfn(MMUEXT_UNPIN_TABLE,
+                         PFN_DOWN(__pa(xen_start_info->pt_base)));
 }
 
-static __init void xen_pagetable_setup_done(pgd_t *base)
+static __init void setup_shared_info(void)
 {
-       /* This will work as long as patching hasn't happened yet
-          (which it hasn't) */
-       pv_mmu_ops.alloc_pt = xen_alloc_pt;
-       pv_mmu_ops.alloc_pd = xen_alloc_pd;
-       pv_mmu_ops.release_pt = xen_release_pt;
-       pv_mmu_ops.release_pd = xen_release_pt;
-       pv_mmu_ops.set_pte = xen_set_pte;
-
        if (!xen_feature(XENFEAT_auto_translated_physmap)) {
+               unsigned long addr = fix_to_virt(FIX_PARAVIRT_BOOTMAP);
+
                /*
                 * Create a mapping for the shared info page.
                 * Should be set_fixmap(), but shared_info is a machine
                 * address with no corresponding pseudo-phys address.
                 */
-               set_pte_mfn(fix_to_virt(FIX_PARAVIRT_BOOTMAP),
+               set_pte_mfn(addr,
                            PFN_DOWN(xen_start_info->shared_info),
                            PAGE_KERNEL);
 
-               HYPERVISOR_shared_info =
-                       (struct shared_info *)fix_to_virt(FIX_PARAVIRT_BOOTMAP);
-
+               HYPERVISOR_shared_info = (struct shared_info *)addr;
        } else
                HYPERVISOR_shared_info =
                        (struct shared_info *)__va(xen_start_info->shared_info);
 
+#ifndef CONFIG_SMP
+       /* In UP this is as good a place as any to set up shared info */
+       xen_setup_vcpu_info_placement();
+#endif
+}
+
+static __init void xen_pagetable_setup_done(pgd_t *base)
+{
+       /* This will work as long as patching hasn't happened yet
+          (which it hasn't) */
+       pv_mmu_ops.alloc_pt = xen_alloc_pt;
+       pv_mmu_ops.alloc_pd = xen_alloc_pd;
+       pv_mmu_ops.release_pt = xen_release_pt;
+       pv_mmu_ops.release_pd = xen_release_pd;
+       pv_mmu_ops.set_pte = xen_set_pte;
+
+       setup_shared_info();
+
        /* Actually pin the pagetable down, but we can't set PG_pinned
           yet because the page structures don't exist yet. */
        {
@@ -1177,15 +1206,9 @@ asmlinkage void __init xen_start_kernel(void)
        x86_write_percpu(xen_cr3, __pa(pgd));
        x86_write_percpu(xen_current_cr3, __pa(pgd));
 
-#ifdef CONFIG_SMP
        /* Don't do the full vcpu_info placement stuff until we have a
-          possible map. */
+          possible map and a non-dummy shared_info. */
        per_cpu(xen_vcpu, 0) = &HYPERVISOR_shared_info->vcpu_info[0];
-#else
-       /* May as well do it now, since there's no good time to call
-          it later on UP. */
-       xen_setup_vcpu_info_placement();
-#endif
 
        pv_info.kernel_rpl = 1;
        if (xen_feature(XENFEAT_supervisor_mode_kernel))