# HG changeset patch # User iap10@labyrinth.cl.cam.ac.uk # Date 1107824689 0 # Node ID 9e80fc0dcac53e51214aba0013d8811ef669aef9 # Parent ef5e5cd10778a25e5574cd80b25f3fc54665880a bitkeeper revision 1.1159.212.121 (42081031Gcfd1G5fgexBl7vd4XfmLQ) Use 1:1 pagetables used for guest physical mode emulation for doing phys_to_machine_mapping as well. Signed-off-by: Arun Sharma Signed-off-by: ian@xensource.com diff -r ef5e5cd10778 -r 9e80fc0dcac5 xen/arch/x86/domain.c --- a/xen/arch/x86/domain.c Tue Feb 08 01:03:26 2005 +0000 +++ b/xen/arch/x86/domain.c Tue Feb 08 01:04:49 2005 +0000 @@ -304,7 +304,7 @@ void arch_vmx_do_launch(struct exec_doma static void monitor_mk_pagetable(struct exec_domain *ed) { unsigned long mpfn; - l2_pgentry_t *mpl2e; + l2_pgentry_t *mpl2e, *phys_table; struct pfn_info *mpfn_info; struct domain *d = ed->domain; @@ -326,6 +326,12 @@ static void monitor_mk_pagetable(struct mk_l2_pgentry((__pa(d->arch.mm_perdomain_pt) & PAGE_MASK) | __PAGE_HYPERVISOR); + phys_table = (l2_pgentry_t *) map_domain_mem(pagetable_val( + ed->arch.phys_table)); + memcpy(d->arch.mm_perdomain_pt, phys_table, + ENTRIES_PER_L2_PAGETABLE * sizeof(l2_pgentry_t)); + + unmap_domain_mem(phys_table); unmap_domain_mem(mpl2e); } @@ -466,6 +472,7 @@ int arch_final_setup_guestos( phys_basetab = c->pt_base; d->arch.pagetable = mk_pagetable(phys_basetab); + d->arch.phys_table = d->arch.pagetable; if ( !get_page_and_type(&frame_table[phys_basetab>>PAGE_SHIFT], d->domain, PGT_base_page_table) ) return -EINVAL; @@ -749,8 +756,6 @@ static void relinquish_list(struct domai #ifdef CONFIG_VMX static void vmx_domain_relinquish_memory(struct exec_domain *ed) { - struct domain *d = ed->domain; - /* * Free VMCS */ @@ -759,22 +764,6 @@ static void vmx_domain_relinquish_memory ed->arch.arch_vmx.vmcs = 0; monitor_rm_pagetable(ed); - - if (ed == d->exec_domain[0]) { - int i; - unsigned long pfn; - - for (i = 0; i < ENTRIES_PER_L1_PAGETABLE; i++) { - unsigned long l1e; - - l1e = l1_pgentry_val(d->arch.mm_perdomain_pt[i]); - if (l1e & _PAGE_PRESENT) { - pfn = l1e >> PAGE_SHIFT; - free_domheap_page(&frame_table[pfn]); - } - } - } - } #endif diff -r ef5e5cd10778 -r 9e80fc0dcac5 xen/arch/x86/vmx_vmcs.c --- a/xen/arch/x86/vmx_vmcs.c Tue Feb 08 01:03:26 2005 +0000 +++ b/xen/arch/x86/vmx_vmcs.c Tue Feb 08 01:04:49 2005 +0000 @@ -131,52 +131,20 @@ int vmx_setup_platform(struct exec_domai } if (gpfn == 0) { - VMX_DBG_LOG(DBG_LEVEL_1, "No shared Page ?\n"); + printk("No shared Page ?\n"); + unmap_domain_mem(p); return -1; } unmap_domain_mem(p); mpfn = phys_to_machine_mapping(gpfn); p = map_domain_mem(mpfn << PAGE_SHIFT); + ASSERT(p != NULL); d->arch.arch_vmx.vmx_platform.shared_page_va = (unsigned long) p; return 0; } - -/* - * Add mapping to per-domain mapping. Full - * virtualization does not need per-domain mapping. - */ -static int add_mapping_perdomain(struct exec_domain *d, unsigned long gpfn, - unsigned long mpfn) -{ - struct pfn_info *page; - unsigned long pfn = 0; - - /* - * We support up to 4GB memory for a guest at this point - */ - if (gpfn > ENTRIES_PER_L2_PAGETABLE * ENTRIES_PER_L1_PAGETABLE) - return -1; - - if (!(l1_pgentry_val(d->domain->arch.mm_perdomain_pt[ - gpfn >> (L2_PAGETABLE_SHIFT - L1_PAGETABLE_SHIFT)]) & _PAGE_PRESENT)) - { - page = (struct pfn_info *) alloc_domheap_page(NULL); - if (!page) { - return -1; - } - - pfn = (unsigned long) (page - frame_table); - d->domain->arch.mm_perdomain_pt[gpfn >> (L2_PAGETABLE_SHIFT - L1_PAGETABLE_SHIFT)] = - mk_l1_pgentry((pfn << PAGE_SHIFT) | __PAGE_HYPERVISOR); - } - __phys_to_machine_mapping[gpfn] = mpfn; - - return 0; -} - void vmx_do_launch(struct exec_domain *ed) { /* Update CR3, GDT, LDT, TR */ @@ -204,7 +172,6 @@ void vmx_do_launch(struct exec_domain *e d->arch.min_pfn = min(d->arch.min_pfn, pfn); d->arch.max_pfn = max(d->arch.max_pfn, pfn); list_ent = frame_table[pfn].list.next; - add_mapping_perdomain(ed, i, pfn); } spin_unlock(&d->page_alloc_lock); diff -r ef5e5cd10778 -r 9e80fc0dcac5 xen/include/asm-x86/domain.h --- a/xen/include/asm-x86/domain.h Tue Feb 08 01:03:26 2005 +0000 +++ b/xen/include/asm-x86/domain.h Tue Feb 08 01:04:49 2005 +0000 @@ -96,6 +96,7 @@ struct arch_exec_domain pagetable_t pagetable; pagetable_t monitor_table; + pagetable_t phys_table; /* 1:1 pagetable */ pagetable_t shadow_table; l2_pgentry_t *vpagetable; /* virtual address of pagetable */ l2_pgentry_t *shadow_vtable; /* virtual address of shadow_table */ diff -r ef5e5cd10778 -r 9e80fc0dcac5 xen/include/asm-x86/mm.h --- a/xen/include/asm-x86/mm.h Tue Feb 08 01:03:26 2005 +0000 +++ b/xen/include/asm-x86/mm.h Tue Feb 08 01:04:49 2005 +0000 @@ -13,6 +13,7 @@ #include #include #include +#include #include @@ -245,7 +246,15 @@ void synchronise_pagetables(unsigned lon /* Returns the machine physical */ static inline unsigned long phys_to_machine_mapping(unsigned long pfn) { - return __phys_to_machine_mapping[pfn]; + unsigned long mfn; + l1_pgentry_t pte; + + if (__get_user(l1_pgentry_val(pte), (__phys_to_machine_mapping + pfn))) { + return 0; + } + + mfn = l1_pgentry_to_phys(pte) >> PAGE_SHIFT; + return mfn; } #define set_machinetophys(_mfn, _pfn) machine_to_phys_mapping[(_mfn)] = (_pfn) diff -r ef5e5cd10778 -r 9e80fc0dcac5 xen/include/asm-x86/x86_32/uaccess.h --- a/xen/include/asm-x86/x86_32/uaccess.h Tue Feb 08 01:03:26 2005 +0000 +++ b/xen/include/asm-x86/x86_32/uaccess.h Tue Feb 08 01:04:49 2005 +0000 @@ -8,7 +8,6 @@ #include #include #include -#include #define __user diff -r ef5e5cd10778 -r 9e80fc0dcac5 xen/include/asm-x86/x86_64/uaccess.h --- a/xen/include/asm-x86/x86_64/uaccess.h Tue Feb 08 01:03:26 2005 +0000 +++ b/xen/include/asm-x86/x86_64/uaccess.h Tue Feb 08 01:04:49 2005 +0000 @@ -7,7 +7,6 @@ #include #include #include -#include #include #include