From: "Jan Beulich" Subject: [PATCH 06/11] x86: properly use map_domain_page() during domain creation/destruction Date: Tue, 22 Jan 2013 10:53:19 +0000 Message-ID: <50FE7DAF02000078000B8327@nat28.tlf.novell.com> References: <50FE7BF502000078000B82F8@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part2617858F.0__=" Return-path: In-Reply-To: <50FE7BF502000078000B82F8@nat28.tlf.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part2617858F.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline This involves no longer storing virtual addresses of the per-domain mapping L2 and L3 page tables. Signed-off-by: Jan Beulich --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -289,9 +289,10 @@ static int setup_compat_l4(struct vcpu * /* This page needs to look like a pagetable so that it can be = shadowed */ pg->u.inuse.type_info =3D PGT_l4_page_table|PGT_validated|1; =20 - l4tab =3D page_to_virt(pg); + l4tab =3D __map_domain_page(pg); clear_page(l4tab); init_guest_l4_table(l4tab, v->domain); + unmap_domain_page(l4tab); =20 v->arch.guest_table =3D pagetable_from_page(pg); v->arch.guest_table_user =3D v->arch.guest_table; @@ -383,17 +384,22 @@ int vcpu_initialise(struct vcpu *v) =20 v->arch.flags =3D TF_kernel_mode; =20 - idx =3D perdomain_pt_pgidx(v); - if ( !perdomain_pt_page(d, idx) ) + idx =3D perdomain_pt_idx(v); + if ( !d->arch.perdomain_pts[idx] ) { - struct page_info *pg; - pg =3D alloc_domheap_page(NULL, MEMF_node(vcpu_to_node(v))); - if ( !pg ) + void *pt; + l2_pgentry_t *l2tab; + + pt =3D alloc_xenheap_pages(0, MEMF_node(vcpu_to_node(v))); + if ( !pt ) return -ENOMEM; - clear_page(page_to_virt(pg)); - perdomain_pt_page(d, idx) =3D pg; - d->arch.mm_perdomain_l2[0][l2_table_offset(PERDOMAIN_VIRT_START)+i= dx] - =3D l2e_from_page(pg, __PAGE_HYPERVISOR); + clear_page(pt); + d->arch.perdomain_pts[idx] =3D pt; + + l2tab =3D __map_domain_page(d->arch.perdomain_l2_pg[0]); + l2tab[l2_table_offset(PERDOMAIN_VIRT_START) + idx] + =3D l2e_from_paddr(__pa(pt), __PAGE_HYPERVISOR); + unmap_domain_page(l2tab); } =20 rc =3D mapcache_vcpu_init(v); @@ -484,6 +490,7 @@ void vcpu_destroy(struct vcpu *v) int arch_domain_create(struct domain *d, unsigned int domcr_flags) { struct page_info *pg; + l3_pgentry_t *l3tab; int i, paging_initialised =3D 0; int rc =3D -ENOMEM; =20 @@ -514,28 +521,29 @@ int arch_domain_create(struct domain *d, d->domain_id); } =20 - BUILD_BUG_ON(PDPT_L2_ENTRIES * sizeof(*d->arch.mm_perdomain_pt_pages) + BUILD_BUG_ON(PDPT_L2_ENTRIES * sizeof(*d->arch.perdomain_pts) !=3D PAGE_SIZE); - pg =3D alloc_domheap_page(NULL, MEMF_node(domain_to_node(d))); - if ( !pg ) + d->arch.perdomain_pts =3D + alloc_xenheap_pages(0, MEMF_node(domain_to_node(d))); + if ( !d->arch.perdomain_pts ) goto fail; - d->arch.mm_perdomain_pt_pages =3D page_to_virt(pg); - clear_page(d->arch.mm_perdomain_pt_pages); + clear_page(d->arch.perdomain_pts); =20 pg =3D alloc_domheap_page(NULL, MEMF_node(domain_to_node(d))); if ( pg =3D=3D NULL ) goto fail; - d->arch.mm_perdomain_l2[0] =3D page_to_virt(pg); - clear_page(d->arch.mm_perdomain_l2[0]); + d->arch.perdomain_l2_pg[0] =3D pg; + clear_domain_page(page_to_mfn(pg)); =20 pg =3D alloc_domheap_page(NULL, MEMF_node(domain_to_node(d))); if ( pg =3D=3D NULL ) goto fail; - d->arch.mm_perdomain_l3 =3D page_to_virt(pg); - clear_page(d->arch.mm_perdomain_l3); - d->arch.mm_perdomain_l3[l3_table_offset(PERDOMAIN_VIRT_START)] =3D - l3e_from_pfn(virt_to_mfn(d->arch.mm_perdomain_l2[0]), - __PAGE_HYPERVISOR); + d->arch.perdomain_l3_pg =3D pg; + l3tab =3D __map_domain_page(pg); + clear_page(l3tab); + l3tab[l3_table_offset(PERDOMAIN_VIRT_START)] =3D + l3e_from_page(d->arch.perdomain_l2_pg[0], __PAGE_HYPERVISOR); + unmap_domain_page(l3tab); =20 mapcache_domain_init(d); =20 @@ -611,12 +619,12 @@ int arch_domain_create(struct domain *d, if ( paging_initialised ) paging_final_teardown(d); mapcache_domain_exit(d); - if ( d->arch.mm_perdomain_l2[0] ) - free_domheap_page(virt_to_page(d->arch.mm_perdomain_l2[0])); - if ( d->arch.mm_perdomain_l3 ) - free_domheap_page(virt_to_page(d->arch.mm_perdomain_l3)); - if ( d->arch.mm_perdomain_pt_pages ) - free_domheap_page(virt_to_page(d->arch.mm_perdomain_pt_pages)); + for ( i =3D 0; i < PERDOMAIN_SLOTS; ++i) + if ( d->arch.perdomain_l2_pg[i] ) + free_domheap_page(d->arch.perdomain_l2_pg[i]); + if ( d->arch.perdomain_l3_pg ) + free_domheap_page(d->arch.perdomain_l3_pg); + free_xenheap_page(d->arch.perdomain_pts); return rc; } =20 @@ -638,13 +646,12 @@ void arch_domain_destroy(struct domain * mapcache_domain_exit(d); =20 for ( i =3D 0; i < PDPT_L2_ENTRIES; ++i ) - { - if ( perdomain_pt_page(d, i) ) - free_domheap_page(perdomain_pt_page(d, i)); - } - free_domheap_page(virt_to_page(d->arch.mm_perdomain_pt_pages)); - free_domheap_page(virt_to_page(d->arch.mm_perdomain_l2[0])); - free_domheap_page(virt_to_page(d->arch.mm_perdomain_l3)); + free_xenheap_page(d->arch.perdomain_pts[i]); + free_xenheap_page(d->arch.perdomain_pts); + for ( i =3D 0; i < PERDOMAIN_SLOTS; ++i) + if ( d->arch.perdomain_l2_pg[i] ) + free_domheap_page(d->arch.perdomain_l2_pg[i]); + free_domheap_page(d->arch.perdomain_l3_pg); =20 free_xenheap_page(d->shared_info); cleanup_domain_irq_mapping(d); @@ -810,9 +817,10 @@ int arch_set_info_guest( fail |=3D xen_pfn_to_cr3(pfn) !=3D c.nat->ctrlreg[1]; } } else { - l4_pgentry_t *l4tab =3D __va(pfn_to_paddr(pfn)); + l4_pgentry_t *l4tab =3D map_domain_page(pfn); =20 pfn =3D l4e_get_pfn(*l4tab); + unmap_domain_page(l4tab); fail =3D compat_pfn_to_cr3(pfn) !=3D c.cmp->ctrlreg[3]; } =20 @@ -951,9 +959,10 @@ int arch_set_info_guest( return -EINVAL; } =20 - l4tab =3D __va(pagetable_get_paddr(v->arch.guest_table)); + l4tab =3D map_domain_page(pagetable_get_pfn(v->arch.guest_table));= *l4tab =3D l4e_from_pfn(page_to_mfn(cr3_page), _PAGE_PRESENT|_PAGE_RW|_PAGE_USER|_PAGE_ACCESSED); + unmap_domain_page(l4tab); } =20 if ( v->vcpu_id =3D=3D 0 ) @@ -1971,12 +1980,13 @@ static int relinquish_memory( static void vcpu_destroy_pagetables(struct vcpu *v) { struct domain *d =3D v->domain; - unsigned long pfn; + unsigned long pfn =3D pagetable_get_pfn(v->arch.guest_table); =20 if ( is_pv_32on64_vcpu(v) ) { - pfn =3D l4e_get_pfn(*(l4_pgentry_t *) - __va(pagetable_get_paddr(v->arch.guest_table)));= + l4_pgentry_t *l4tab =3D map_domain_page(pfn); + + pfn =3D l4e_get_pfn(*l4tab); =20 if ( pfn !=3D 0 ) { @@ -1986,15 +1996,12 @@ static void vcpu_destroy_pagetables(stru put_page_and_type(mfn_to_page(pfn)); } =20 - l4e_write( - (l4_pgentry_t *)__va(pagetable_get_paddr(v->arch.guest_table))= , - l4e_empty()); + l4e_write(l4tab, l4e_empty()); =20 v->arch.cr3 =3D 0; return; } =20 - pfn =3D pagetable_get_pfn(v->arch.guest_table); if ( pfn !=3D 0 ) { if ( paging_mode_refcounts(d) ) --- a/xen/arch/x86/domain_page.c +++ b/xen/arch/x86/domain_page.c @@ -241,6 +241,8 @@ void copy_domain_page(unsigned long dmfn int mapcache_domain_init(struct domain *d) { struct mapcache_domain *dcache =3D &d->arch.pv_domain.mapcache; + l3_pgentry_t *l3tab; + l2_pgentry_t *l2tab; unsigned int i, bitmap_pages, memf =3D MEMF_node(domain_to_node(d)); unsigned long *end; =20 @@ -251,14 +253,18 @@ int mapcache_domain_init(struct domain * return 0; =20 dcache->l1tab =3D xzalloc_array(l1_pgentry_t *, MAPCACHE_L2_ENTRIES + = 1); - d->arch.mm_perdomain_l2[MAPCACHE_SLOT] =3D alloc_xenheap_pages(0, = memf); - if ( !dcache->l1tab || !d->arch.mm_perdomain_l2[MAPCACHE_SLOT] ) + d->arch.perdomain_l2_pg[MAPCACHE_SLOT] =3D alloc_domheap_page(NULL, = memf); + if ( !dcache->l1tab || !d->arch.perdomain_l2_pg[MAPCACHE_SLOT] ) return -ENOMEM; =20 - clear_page(d->arch.mm_perdomain_l2[MAPCACHE_SLOT]); - d->arch.mm_perdomain_l3[l3_table_offset(MAPCACHE_VIRT_START)] =3D - l3e_from_paddr(__pa(d->arch.mm_perdomain_l2[MAPCACHE_SLOT]), - __PAGE_HYPERVISOR); + clear_domain_page(page_to_mfn(d->arch.perdomain_l2_pg[MAPCACHE_SLOT]))= ; + l3tab =3D __map_domain_page(d->arch.perdomain_l3_pg); + l3tab[l3_table_offset(MAPCACHE_VIRT_START)] =3D + l3e_from_page(d->arch.perdomain_l2_pg[MAPCACHE_SLOT], + __PAGE_HYPERVISOR); + unmap_domain_page(l3tab); + + l2tab =3D __map_domain_page(d->arch.perdomain_l2_pg[MAPCACHE_SLOT]); =20 BUILD_BUG_ON(MAPCACHE_VIRT_END + 3 + 2 * PFN_UP(BITS_TO_LONGS(MAPCACHE_ENTRIES) * sizeof(long)= ) > @@ -275,12 +281,16 @@ int mapcache_domain_init(struct domain * ASSERT(i <=3D MAPCACHE_L2_ENTRIES); dcache->l1tab[i] =3D alloc_xenheap_pages(0, memf); if ( !dcache->l1tab[i] ) + { + unmap_domain_page(l2tab); return -ENOMEM; + } clear_page(dcache->l1tab[i]); - d->arch.mm_perdomain_l2[MAPCACHE_SLOT][i] =3D - l2e_from_paddr(__pa(dcache->l1tab[i]), __PAGE_HYPERVISOR); + l2tab[i] =3D l2e_from_paddr(__pa(dcache->l1tab[i]), __PAGE_HYPERVI= SOR); } =20 + unmap_domain_page(l2tab); + spin_lock_init(&dcache->lock); =20 return 0; @@ -315,19 +325,21 @@ void mapcache_domain_exit(struct domain=20 =20 xfree(dcache->l1tab); } - free_xenheap_page(d->arch.mm_perdomain_l2[MAPCACHE_SLOT]); } =20 int mapcache_vcpu_init(struct vcpu *v) { struct domain *d =3D v->domain; struct mapcache_domain *dcache =3D &d->arch.pv_domain.mapcache; + l2_pgentry_t *l2tab; unsigned long i; unsigned int memf =3D MEMF_node(vcpu_to_node(v)); =20 if ( is_hvm_vcpu(v) || !dcache->l1tab ) return 0; =20 + l2tab =3D __map_domain_page(d->arch.perdomain_l2_pg[MAPCACHE_SLOT]); + while ( dcache->entries < d->max_vcpus * MAPCACHE_VCPU_ENTRIES ) { unsigned int ents =3D dcache->entries + MAPCACHE_VCPU_ENTRIES; @@ -338,10 +350,13 @@ int mapcache_vcpu_init(struct vcpu *v) { dcache->l1tab[i] =3D alloc_xenheap_pages(0, memf); if ( !dcache->l1tab[i] ) + { + unmap_domain_page(l2tab); return -ENOMEM; + } clear_page(dcache->l1tab[i]); - d->arch.mm_perdomain_l2[MAPCACHE_SLOT][i] =3D - l2e_from_paddr(__pa(dcache->l1tab[i]), __PAGE_HYPERVISOR);= + l2tab[i] =3D l2e_from_paddr(__pa(dcache->l1tab[i]), + __PAGE_HYPERVISOR); } =20 /* Populate bit maps. */ @@ -351,18 +366,22 @@ int mapcache_vcpu_init(struct vcpu *v) { struct page_info *pg =3D alloc_domheap_page(NULL, memf); =20 + if ( pg ) + { + clear_domain_page(page_to_mfn(pg)); + *pl1e =3D l1e_from_page(pg, __PAGE_HYPERVISOR); + pg =3D alloc_domheap_page(NULL, memf); + } if ( !pg ) + { + unmap_domain_page(l2tab); return -ENOMEM; - clear_domain_page(page_to_mfn(pg)); - *pl1e =3D l1e_from_page(pg, __PAGE_HYPERVISOR); + } =20 i =3D (unsigned long)(dcache->garbage + BITS_TO_LONGS(ents)); pl1e =3D &dcache->l1tab[l2_table_offset(i)][l1_table_offset(i)= ]; ASSERT(!l1e_get_flags(*pl1e)); =20 - pg =3D alloc_domheap_page(NULL, memf); - if ( !pg ) - return -ENOMEM; clear_domain_page(page_to_mfn(pg)); *pl1e =3D l1e_from_page(pg, __PAGE_HYPERVISOR); } @@ -370,6 +389,8 @@ int mapcache_vcpu_init(struct vcpu *v) dcache->entries =3D ents; } =20 + unmap_domain_page(l2tab); + /* Mark all maphash entries as not in use. */ BUILD_BUG_ON(MAPHASHENT_NOTINUSE < MAPCACHE_ENTRIES); for ( i =3D 0; i < MAPHASH_ENTRIES; i++ ) --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -1322,9 +1322,9 @@ void init_guest_l4_table(l4_pgentry_t l4 &idle_pg_table[ROOT_PAGETABLE_FIRST_XEN_SLOT], ROOT_PAGETABLE_XEN_SLOTS * sizeof(l4_pgentry_t)); l4tab[l4_table_offset(LINEAR_PT_VIRT_START)] =3D - l4e_from_pfn(virt_to_mfn(l4tab), __PAGE_HYPERVISOR); + l4e_from_pfn(domain_page_map_to_mfn(l4tab), __PAGE_HYPERVISOR); l4tab[l4_table_offset(PERDOMAIN_VIRT_START)] =3D - l4e_from_pfn(virt_to_mfn(d->arch.mm_perdomain_l3), __PAGE_HYPERVIS= OR); + l4e_from_page(d->arch.perdomain_l3_pg, __PAGE_HYPERVISOR); } =20 static int alloc_l4_table(struct page_info *page, int preemptible) --- a/xen/arch/x86/mm/hap/hap.c +++ b/xen/arch/x86/mm/hap/hap.c @@ -369,7 +369,7 @@ static void hap_install_xen_entries_in_l =20 /* Install the per-domain mappings for this domain */ l4e[l4_table_offset(PERDOMAIN_VIRT_START)] =3D - l4e_from_pfn(mfn_x(page_to_mfn(virt_to_page(d->arch.mm_perdomain_l= 3))), + l4e_from_pfn(mfn_x(page_to_mfn(d->arch.perdomain_l3_pg)), __PAGE_HYPERVISOR); =20 /* Install a linear mapping */ --- a/xen/arch/x86/mm/shadow/multi.c +++ b/xen/arch/x86/mm/shadow/multi.c @@ -1449,7 +1449,7 @@ void sh_install_xen_entries_in_l4(struct =20 /* Install the per-domain mappings for this domain */ sl4e[shadow_l4_table_offset(PERDOMAIN_VIRT_START)] =3D - shadow_l4e_from_mfn(page_to_mfn(virt_to_page(d->arch.mm_perdomain_= l3)), + shadow_l4e_from_mfn(page_to_mfn(d->arch.perdomain_l3_pg), __PAGE_HYPERVISOR); =20 /* Shadow linear mapping for 4-level shadows. N.B. for 3-level --- a/xen/arch/x86/x86_64/mm.c +++ b/xen/arch/x86/x86_64/mm.c @@ -823,9 +823,8 @@ void __init setup_idle_pagetable(void) { /* Install per-domain mappings for idle domain. */ l4e_write(&idle_pg_table[l4_table_offset(PERDOMAIN_VIRT_START)], - l4e_from_page( - virt_to_page(idle_vcpu[0]->domain->arch.mm_perdomain_l3)= , - __PAGE_HYPERVISOR)); + l4e_from_page(idle_vcpu[0]->domain->arch.perdomain_l3_pg, + __PAGE_HYPERVISOR)); } =20 void __init zap_low_mappings(void) @@ -850,21 +849,18 @@ void *compat_arg_xlat_virt_base(void) int setup_compat_arg_xlat(struct vcpu *v) { unsigned int order =3D get_order_from_bytes(COMPAT_ARG_XLAT_SIZE); - struct page_info *pg; =20 - pg =3D alloc_domheap_pages(NULL, order, 0); - if ( pg =3D=3D NULL ) - return -ENOMEM; + v->arch.compat_arg_xlat =3D alloc_xenheap_pages(order, + MEMF_node(vcpu_to_node(v= ))); =20 - v->arch.compat_arg_xlat =3D page_to_virt(pg); - return 0; + return v->arch.compat_arg_xlat ? 0 : -ENOMEM; } =20 void free_compat_arg_xlat(struct vcpu *v) { unsigned int order =3D get_order_from_bytes(COMPAT_ARG_XLAT_SIZE); - if ( v->arch.compat_arg_xlat !=3D NULL ) - free_domheap_pages(virt_to_page(v->arch.compat_arg_xlat), order); + + free_xenheap_pages(v->arch.compat_arg_xlat, order); v->arch.compat_arg_xlat =3D NULL; } =20 --- a/xen/include/asm-x86/domain.h +++ b/xen/include/asm-x86/domain.h @@ -241,9 +241,9 @@ struct pv_domain =20 struct arch_domain { - struct page_info **mm_perdomain_pt_pages; - l2_pgentry_t *mm_perdomain_l2[PERDOMAIN_SLOTS]; - l3_pgentry_t *mm_perdomain_l3; + void **perdomain_pts; + struct page_info *perdomain_l2_pg[PERDOMAIN_SLOTS]; + struct page_info *perdomain_l3_pg; =20 unsigned int hv_compat_vstart; =20 @@ -318,13 +318,11 @@ struct arch_domain #define has_arch_pdevs(d) (!list_empty(&(d)->arch.pdev_list)) #define has_arch_mmios(d) (!rangeset_is_empty((d)->iomem_caps)) =20 -#define perdomain_pt_pgidx(v) \ +#define perdomain_pt_idx(v) \ ((v)->vcpu_id >> (PAGETABLE_ORDER - GDT_LDT_VCPU_SHIFT)) #define perdomain_ptes(d, v) \ - ((l1_pgentry_t *)page_to_virt((d)->arch.mm_perdomain_pt_pages \ - [perdomain_pt_pgidx(v)]) + (((v)->vcpu_id << GDT_LDT_VCPU_SHIFT) & = \ - (L1_PAGETABLE_ENTRIES - 1))) -#define perdomain_pt_page(d, n) ((d)->arch.mm_perdomain_pt_pages[n]) + ((l1_pgentry_t *)(d)->arch.perdomain_pts[perdomain_pt_idx(v)] + \ + (((v)->vcpu_id << GDT_LDT_VCPU_SHIFT) & (L1_PAGETABLE_ENTRIES - 1))) =20 struct pv_vcpu { --=__Part2617858F.0__= Content-Type: text/plain; name="x86-map-domain-create.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-map-domain-create.patch" x86: properly use map_domain_page() during domain creation/destruction=0A= =0AThis involves no longer storing virtual addresses of the per-domain=0Ama= pping L2 and L3 page tables.=0A=0ASigned-off-by: Jan Beulich =0A=0A--- a/xen/arch/x86/domain.c=0A+++ b/xen/arch/x86/domain.c=0A@@ = -289,9 +289,10 @@ static int setup_compat_l4(struct vcpu *=0A /* This = page needs to look like a pagetable so that it can be shadowed */=0A = pg->u.inuse.type_info =3D PGT_l4_page_table|PGT_validated|1;=0A =0A- = l4tab =3D page_to_virt(pg);=0A+ l4tab =3D __map_domain_page(pg);=0A = clear_page(l4tab);=0A init_guest_l4_table(l4tab, v->domain);=0A+ = unmap_domain_page(l4tab);=0A =0A v->arch.guest_table =3D pagetable_from= _page(pg);=0A v->arch.guest_table_user =3D v->arch.guest_table;=0A@@ = -383,17 +384,22 @@ int vcpu_initialise(struct vcpu *v)=0A =0A = v->arch.flags =3D TF_kernel_mode;=0A =0A- idx =3D perdomain_pt_pgidx(v);= =0A- if ( !perdomain_pt_page(d, idx) )=0A+ idx =3D perdomain_pt_idx(v= );=0A+ if ( !d->arch.perdomain_pts[idx] )=0A {=0A- struct = page_info *pg;=0A- pg =3D alloc_domheap_page(NULL, MEMF_node(vcpu_to= _node(v)));=0A- if ( !pg )=0A+ void *pt;=0A+ = l2_pgentry_t *l2tab;=0A+=0A+ pt =3D alloc_xenheap_pages(0, = MEMF_node(vcpu_to_node(v)));=0A+ if ( !pt )=0A return = -ENOMEM;=0A- clear_page(page_to_virt(pg));=0A- perdomain_pt_p= age(d, idx) =3D pg;=0A- d->arch.mm_perdomain_l2[0][l2_table_offset(P= ERDOMAIN_VIRT_START)+idx]=0A- =3D l2e_from_page(pg, __PAGE_HYPER= VISOR);=0A+ clear_page(pt);=0A+ d->arch.perdomain_pts[idx] = =3D pt;=0A+=0A+ l2tab =3D __map_domain_page(d->arch.perdomain_l2_pg[= 0]);=0A+ l2tab[l2_table_offset(PERDOMAIN_VIRT_START) + idx]=0A+ = =3D l2e_from_paddr(__pa(pt), __PAGE_HYPERVISOR);=0A+ = unmap_domain_page(l2tab);=0A }=0A =0A rc =3D mapcache_vcpu_init(v);= =0A@@ -484,6 +490,7 @@ void vcpu_destroy(struct vcpu *v)=0A int arch_domain= _create(struct domain *d, unsigned int domcr_flags)=0A {=0A struct = page_info *pg;=0A+ l3_pgentry_t *l3tab;=0A int i, paging_initialised= =3D 0;=0A int rc =3D -ENOMEM;=0A =0A@@ -514,28 +521,29 @@ int = arch_domain_create(struct domain *d,=0A d->domain_id);=0A = }=0A =0A- BUILD_BUG_ON(PDPT_L2_ENTRIES * sizeof(*d->arch.mm_perdomain_= pt_pages)=0A+ BUILD_BUG_ON(PDPT_L2_ENTRIES * sizeof(*d->arch.perdomain_p= ts)=0A !=3D PAGE_SIZE);=0A- pg =3D alloc_domheap_page(N= ULL, MEMF_node(domain_to_node(d)));=0A- if ( !pg )=0A+ d->arch.perdom= ain_pts =3D=0A+ alloc_xenheap_pages(0, MEMF_node(domain_to_node(d)))= ;=0A+ if ( !d->arch.perdomain_pts )=0A goto fail;=0A- = d->arch.mm_perdomain_pt_pages =3D page_to_virt(pg);=0A- clear_page(d->ar= ch.mm_perdomain_pt_pages);=0A+ clear_page(d->arch.perdomain_pts);=0A = =0A pg =3D alloc_domheap_page(NULL, MEMF_node(domain_to_node(d)));=0A = if ( pg =3D=3D NULL )=0A goto fail;=0A- d->arch.mm_perdomain_= l2[0] =3D page_to_virt(pg);=0A- clear_page(d->arch.mm_perdomain_l2[0]);= =0A+ d->arch.perdomain_l2_pg[0] =3D pg;=0A+ clear_domain_page(page_to= _mfn(pg));=0A =0A pg =3D alloc_domheap_page(NULL, MEMF_node(domain_to_n= ode(d)));=0A if ( pg =3D=3D NULL )=0A goto fail;=0A- = d->arch.mm_perdomain_l3 =3D page_to_virt(pg);=0A- clear_page(d->arch.mm_= perdomain_l3);=0A- d->arch.mm_perdomain_l3[l3_table_offset(PERDOMAIN_VIR= T_START)] =3D=0A- l3e_from_pfn(virt_to_mfn(d->arch.mm_perdomain_l2[0= ]),=0A- __PAGE_HYPERVISOR);=0A+ d->arch.perdomain_l3= _pg =3D pg;=0A+ l3tab =3D __map_domain_page(pg);=0A+ clear_page(l3tab= );=0A+ l3tab[l3_table_offset(PERDOMAIN_VIRT_START)] =3D=0A+ = l3e_from_page(d->arch.perdomain_l2_pg[0], __PAGE_HYPERVISOR);=0A+ = unmap_domain_page(l3tab);=0A =0A mapcache_domain_init(d);=0A =0A@@ = -611,12 +619,12 @@ int arch_domain_create(struct domain *d,=0A if ( = paging_initialised )=0A paging_final_teardown(d);=0A mapcache_d= omain_exit(d);=0A- if ( d->arch.mm_perdomain_l2[0] )=0A- = free_domheap_page(virt_to_page(d->arch.mm_perdomain_l2[0]));=0A- if ( = d->arch.mm_perdomain_l3 )=0A- free_domheap_page(virt_to_page(d->arch= .mm_perdomain_l3));=0A- if ( d->arch.mm_perdomain_pt_pages )=0A- = free_domheap_page(virt_to_page(d->arch.mm_perdomain_pt_pages));=0A+ for = ( i =3D 0; i < PERDOMAIN_SLOTS; ++i)=0A+ if ( d->arch.perdomain_l2_p= g[i] )=0A+ free_domheap_page(d->arch.perdomain_l2_pg[i]);=0A+ = if ( d->arch.perdomain_l3_pg )=0A+ free_domheap_page(d->arch.perdom= ain_l3_pg);=0A+ free_xenheap_page(d->arch.perdomain_pts);=0A return = rc;=0A }=0A =0A@@ -638,13 +646,12 @@ void arch_domain_destroy(struct = domain *=0A mapcache_domain_exit(d);=0A =0A for ( i =3D 0; i < = PDPT_L2_ENTRIES; ++i )=0A- {=0A- if ( perdomain_pt_page(d, i) = )=0A- free_domheap_page(perdomain_pt_page(d, i));=0A- }=0A- = free_domheap_page(virt_to_page(d->arch.mm_perdomain_pt_pages));=0A- = free_domheap_page(virt_to_page(d->arch.mm_perdomain_l2[0]));=0A- = free_domheap_page(virt_to_page(d->arch.mm_perdomain_l3));=0A+ = free_xenheap_page(d->arch.perdomain_pts[i]);=0A+ free_xenheap_page(d->ar= ch.perdomain_pts);=0A+ for ( i =3D 0; i < PERDOMAIN_SLOTS; ++i)=0A+ = if ( d->arch.perdomain_l2_pg[i] )=0A+ free_domheap_page(d->ar= ch.perdomain_l2_pg[i]);=0A+ free_domheap_page(d->arch.perdomain_l3_pg);= =0A =0A free_xenheap_page(d->shared_info);=0A cleanup_domain_irq_ma= pping(d);=0A@@ -810,9 +817,10 @@ int arch_set_info_guest(=0A = fail |=3D xen_pfn_to_cr3(pfn) !=3D c.nat->ctrlreg[1];=0A = }=0A } else {=0A- l4_pgentry_t *l4tab =3D __va(pfn_to_pa= ddr(pfn));=0A+ l4_pgentry_t *l4tab =3D map_domain_page(pfn);=0A = =0A pfn =3D l4e_get_pfn(*l4tab);=0A+ unmap_domain_pa= ge(l4tab);=0A fail =3D compat_pfn_to_cr3(pfn) !=3D c.cmp->ctrlr= eg[3];=0A }=0A =0A@@ -951,9 +959,10 @@ int arch_set_info_guest(=0A = return -EINVAL;=0A }=0A =0A- l4tab =3D = __va(pagetable_get_paddr(v->arch.guest_table));=0A+ l4tab =3D = map_domain_page(pagetable_get_pfn(v->arch.guest_table));=0A *l4tab = =3D l4e_from_pfn(page_to_mfn(cr3_page),=0A _PAGE_PRESENT|_PAGE_= RW|_PAGE_USER|_PAGE_ACCESSED);=0A+ unmap_domain_page(l4tab);=0A = }=0A =0A if ( v->vcpu_id =3D=3D 0 )=0A@@ -1971,12 +1980,13 @@ static = int relinquish_memory(=0A static void vcpu_destroy_pagetables(struct vcpu = *v)=0A {=0A struct domain *d =3D v->domain;=0A- unsigned long = pfn;=0A+ unsigned long pfn =3D pagetable_get_pfn(v->arch.guest_table);= =0A =0A if ( is_pv_32on64_vcpu(v) )=0A {=0A- pfn =3D = l4e_get_pfn(*(l4_pgentry_t *)=0A- __va(pagetable_g= et_paddr(v->arch.guest_table)));=0A+ l4_pgentry_t *l4tab =3D = map_domain_page(pfn);=0A+=0A+ pfn =3D l4e_get_pfn(*l4tab);=0A =0A = if ( pfn !=3D 0 )=0A {=0A@@ -1986,15 +1996,12 @@ static void = vcpu_destroy_pagetables(stru=0A put_page_and_type(mfn_to_pa= ge(pfn));=0A }=0A =0A- l4e_write(=0A- (l4_pgentry= _t *)__va(pagetable_get_paddr(v->arch.guest_table)),=0A- = l4e_empty());=0A+ l4e_write(l4tab, l4e_empty());=0A =0A = v->arch.cr3 =3D 0;=0A return;=0A }=0A =0A- pfn =3D = pagetable_get_pfn(v->arch.guest_table);=0A if ( pfn !=3D 0 )=0A = {=0A if ( paging_mode_refcounts(d) )=0A--- a/xen/arch/x86/domain_pa= ge.c=0A+++ b/xen/arch/x86/domain_page.c=0A@@ -241,6 +241,8 @@ void = copy_domain_page(unsigned long dmfn=0A int mapcache_domain_init(struct = domain *d)=0A {=0A struct mapcache_domain *dcache =3D &d->arch.pv_domai= n.mapcache;=0A+ l3_pgentry_t *l3tab;=0A+ l2_pgentry_t *l2tab;=0A = unsigned int i, bitmap_pages, memf =3D MEMF_node(domain_to_node(d));=0A = unsigned long *end;=0A =0A@@ -251,14 +253,18 @@ int mapcache_domain_init(s= truct domain *=0A return 0;=0A =0A dcache->l1tab =3D xzalloc_ar= ray(l1_pgentry_t *, MAPCACHE_L2_ENTRIES + 1);=0A- d->arch.mm_perdomain_l= 2[MAPCACHE_SLOT] =3D alloc_xenheap_pages(0, memf);=0A- if ( !dcache->l1t= ab || !d->arch.mm_perdomain_l2[MAPCACHE_SLOT] )=0A+ d->arch.perdomain_l2= _pg[MAPCACHE_SLOT] =3D alloc_domheap_page(NULL, memf);=0A+ if ( = !dcache->l1tab || !d->arch.perdomain_l2_pg[MAPCACHE_SLOT] )=0A = return -ENOMEM;=0A =0A- clear_page(d->arch.mm_perdomain_l2[MAPCACHE_SLOT= ]);=0A- d->arch.mm_perdomain_l3[l3_table_offset(MAPCACHE_VIRT_START)] = =3D=0A- l3e_from_paddr(__pa(d->arch.mm_perdomain_l2[MAPCACHE_SLOT]),= =0A- __PAGE_HYPERVISOR);=0A+ clear_domain_page(pag= e_to_mfn(d->arch.perdomain_l2_pg[MAPCACHE_SLOT]));=0A+ l3tab =3D = __map_domain_page(d->arch.perdomain_l3_pg);=0A+ l3tab[l3_table_offset(MA= PCACHE_VIRT_START)] =3D=0A+ l3e_from_page(d->arch.perdomain_l2_pg[MA= PCACHE_SLOT],=0A+ __PAGE_HYPERVISOR);=0A+ = unmap_domain_page(l3tab);=0A+=0A+ l2tab =3D __map_domain_page(d->arch.pe= rdomain_l2_pg[MAPCACHE_SLOT]);=0A =0A BUILD_BUG_ON(MAPCACHE_VIRT_END + = 3 +=0A 2 * PFN_UP(BITS_TO_LONGS(MAPCACHE_ENTRIES) * = sizeof(long)) >=0A@@ -275,12 +281,16 @@ int mapcache_domain_init(struct = domain *=0A ASSERT(i <=3D MAPCACHE_L2_ENTRIES);=0A = dcache->l1tab[i] =3D alloc_xenheap_pages(0, memf);=0A if ( = !dcache->l1tab[i] )=0A+ {=0A+ unmap_domain_page(l2tab);= =0A return -ENOMEM;=0A+ }=0A clear_page(dcache->= l1tab[i]);=0A- d->arch.mm_perdomain_l2[MAPCACHE_SLOT][i] =3D=0A- = l2e_from_paddr(__pa(dcache->l1tab[i]), __PAGE_HYPERVISOR);=0A+ = l2tab[i] =3D l2e_from_paddr(__pa(dcache->l1tab[i]), __PAGE_HYPERVISOR);= =0A }=0A =0A+ unmap_domain_page(l2tab);=0A+=0A spin_lock_init(&d= cache->lock);=0A =0A return 0;=0A@@ -315,19 +325,21 @@ void mapcache_do= main_exit(struct domain =0A =0A xfree(dcache->l1tab);=0A }=0A- = free_xenheap_page(d->arch.mm_perdomain_l2[MAPCACHE_SLOT]);=0A }=0A =0A = int mapcache_vcpu_init(struct vcpu *v)=0A {=0A struct domain *d =3D = v->domain;=0A struct mapcache_domain *dcache =3D &d->arch.pv_domain.map= cache;=0A+ l2_pgentry_t *l2tab;=0A unsigned long i;=0A unsigned = int memf =3D MEMF_node(vcpu_to_node(v));=0A =0A if ( is_hvm_vcpu(v) || = !dcache->l1tab )=0A return 0;=0A =0A+ l2tab =3D __map_domain_pag= e(d->arch.perdomain_l2_pg[MAPCACHE_SLOT]);=0A+=0A while ( dcache->entri= es < d->max_vcpus * MAPCACHE_VCPU_ENTRIES )=0A {=0A unsigned = int ents =3D dcache->entries + MAPCACHE_VCPU_ENTRIES;=0A@@ -338,10 +350,13 = @@ int mapcache_vcpu_init(struct vcpu *v)=0A {=0A = dcache->l1tab[i] =3D alloc_xenheap_pages(0, memf);=0A if ( = !dcache->l1tab[i] )=0A+ {=0A+ unmap_domain_page(l= 2tab);=0A return -ENOMEM;=0A+ }=0A = clear_page(dcache->l1tab[i]);=0A- d->arch.mm_perdomain_l2[MAPCAC= HE_SLOT][i] =3D=0A- l2e_from_paddr(__pa(dcache->l1tab[i]), = __PAGE_HYPERVISOR);=0A+ l2tab[i] =3D l2e_from_paddr(__pa(dcache-= >l1tab[i]),=0A+ __PAGE_HYPERVISOR);=0A= }=0A =0A /* Populate bit maps. */=0A@@ -351,18 +366,22 @@ = int mapcache_vcpu_init(struct vcpu *v)=0A {=0A struct = page_info *pg =3D alloc_domheap_page(NULL, memf);=0A =0A+ if ( = pg )=0A+ {=0A+ clear_domain_page(page_to_mfn(pg))= ;=0A+ *pl1e =3D l1e_from_page(pg, __PAGE_HYPERVISOR);=0A+ = pg =3D alloc_domheap_page(NULL, memf);=0A+ }=0A = if ( !pg )=0A+ {=0A+ unmap_domain_page(l= 2tab);=0A return -ENOMEM;=0A- clear_domain_page(= page_to_mfn(pg));=0A- *pl1e =3D l1e_from_page(pg, __PAGE_HYPERVI= SOR);=0A+ }=0A =0A i =3D (unsigned long)(dcache->gar= bage + BITS_TO_LONGS(ents));=0A pl1e =3D &dcache->l1tab[l2_tabl= e_offset(i)][l1_table_offset(i)];=0A ASSERT(!l1e_get_flags(*pl1= e));=0A =0A- pg =3D alloc_domheap_page(NULL, memf);=0A- = if ( !pg )=0A- return -ENOMEM;=0A clear_domai= n_page(page_to_mfn(pg));=0A *pl1e =3D l1e_from_page(pg, = __PAGE_HYPERVISOR);=0A }=0A@@ -370,6 +389,8 @@ int mapcache_vcpu_in= it(struct vcpu *v)=0A dcache->entries =3D ents;=0A }=0A =0A+ = unmap_domain_page(l2tab);=0A+=0A /* Mark all maphash entries as not = in use. */=0A BUILD_BUG_ON(MAPHASHENT_NOTINUSE < MAPCACHE_ENTRIES);=0A = for ( i =3D 0; i < MAPHASH_ENTRIES; i++ )=0A--- a/xen/arch/x86/mm.c=0A+= ++ b/xen/arch/x86/mm.c=0A@@ -1322,9 +1322,9 @@ void init_guest_l4_table(l4_= pgentry_t l4=0A &idle_pg_table[ROOT_PAGETABLE_FIRST_XEN_SLOT],= =0A ROOT_PAGETABLE_XEN_SLOTS * sizeof(l4_pgentry_t));=0A = l4tab[l4_table_offset(LINEAR_PT_VIRT_START)] =3D=0A- l4e_from_pfn(vi= rt_to_mfn(l4tab), __PAGE_HYPERVISOR);=0A+ l4e_from_pfn(domain_page_m= ap_to_mfn(l4tab), __PAGE_HYPERVISOR);=0A l4tab[l4_table_offset(PERDOMAI= N_VIRT_START)] =3D=0A- l4e_from_pfn(virt_to_mfn(d->arch.mm_perdomain= _l3), __PAGE_HYPERVISOR);=0A+ l4e_from_page(d->arch.perdomain_l3_pg,= __PAGE_HYPERVISOR);=0A }=0A =0A static int alloc_l4_table(struct = page_info *page, int preemptible)=0A--- a/xen/arch/x86/mm/hap/hap.c=0A+++ = b/xen/arch/x86/mm/hap/hap.c=0A@@ -369,7 +369,7 @@ static void hap_install_x= en_entries_in_l=0A =0A /* Install the per-domain mappings for this = domain */=0A l4e[l4_table_offset(PERDOMAIN_VIRT_START)] =3D=0A- = l4e_from_pfn(mfn_x(page_to_mfn(virt_to_page(d->arch.mm_perdomain_l3))),=0A+= l4e_from_pfn(mfn_x(page_to_mfn(d->arch.perdomain_l3_pg)),=0A = __PAGE_HYPERVISOR);=0A =0A /* Install a linear mapping = */=0A--- a/xen/arch/x86/mm/shadow/multi.c=0A+++ b/xen/arch/x86/mm/shadow/mu= lti.c=0A@@ -1449,7 +1449,7 @@ void sh_install_xen_entries_in_l4(struct=0A = =0A /* Install the per-domain mappings for this domain */=0A = sl4e[shadow_l4_table_offset(PERDOMAIN_VIRT_START)] =3D=0A- = shadow_l4e_from_mfn(page_to_mfn(virt_to_page(d->arch.mm_perdomain_l3)),=0A+= shadow_l4e_from_mfn(page_to_mfn(d->arch.perdomain_l3_pg),=0A = __PAGE_HYPERVISOR);=0A =0A /* Shadow linear = mapping for 4-level shadows. N.B. for 3-level=0A--- a/xen/arch/x86/x86_64/= mm.c=0A+++ b/xen/arch/x86/x86_64/mm.c=0A@@ -823,9 +823,8 @@ void __init = setup_idle_pagetable(void)=0A {=0A /* Install per-domain mappings for = idle domain. */=0A l4e_write(&idle_pg_table[l4_table_offset(PERDOMAIN_V= IRT_START)],=0A- l4e_from_page(=0A- = virt_to_page(idle_vcpu[0]->domain->arch.mm_perdomain_l3),=0A- = __PAGE_HYPERVISOR));=0A+ l4e_from_page(idle_vcpu[0]->domai= n->arch.perdomain_l3_pg,=0A+ __PAGE_HYPERVISOR))= ;=0A }=0A =0A void __init zap_low_mappings(void)=0A@@ -850,21 +849,18 @@ = void *compat_arg_xlat_virt_base(void)=0A int setup_compat_arg_xlat(struct = vcpu *v)=0A {=0A unsigned int order =3D get_order_from_bytes(COMPAT_ARG= _XLAT_SIZE);=0A- struct page_info *pg;=0A =0A- pg =3D alloc_domheap_p= ages(NULL, order, 0);=0A- if ( pg =3D=3D NULL )=0A- return = -ENOMEM;=0A+ v->arch.compat_arg_xlat =3D alloc_xenheap_pages(order,=0A+ = MEMF_node(vcpu_to_node(v))= );=0A =0A- v->arch.compat_arg_xlat =3D page_to_virt(pg);=0A- return = 0;=0A+ return v->arch.compat_arg_xlat ? 0 : -ENOMEM;=0A }=0A =0A void = free_compat_arg_xlat(struct vcpu *v)=0A {=0A unsigned int order =3D = get_order_from_bytes(COMPAT_ARG_XLAT_SIZE);=0A- if ( v->arch.compat_arg_= xlat !=3D NULL )=0A- free_domheap_pages(virt_to_page(v->arch.compat_= arg_xlat), order);=0A+=0A+ free_xenheap_pages(v->arch.compat_arg_xlat, = order);=0A v->arch.compat_arg_xlat =3D NULL;=0A }=0A =0A--- a/xen/inclu= de/asm-x86/domain.h=0A+++ b/xen/include/asm-x86/domain.h=0A@@ -241,9 = +241,9 @@ struct pv_domain=0A =0A struct arch_domain=0A {=0A- struct = page_info **mm_perdomain_pt_pages;=0A- l2_pgentry_t *mm_perdomain_l2[PER= DOMAIN_SLOTS];=0A- l3_pgentry_t *mm_perdomain_l3;=0A+ void **perdomai= n_pts;=0A+ struct page_info *perdomain_l2_pg[PERDOMAIN_SLOTS];=0A+ = struct page_info *perdomain_l3_pg;=0A =0A unsigned int hv_compat_vstart= ;=0A =0A@@ -318,13 +318,11 @@ struct arch_domain=0A #define has_arch_pdevs(= d) (!list_empty(&(d)->arch.pdev_list))=0A #define has_arch_mmios(d) = (!rangeset_is_empty((d)->iomem_caps))=0A =0A-#define perdomain_pt_pgidx(v) = \=0A+#define perdomain_pt_idx(v) \=0A ((v)->vcpu_id >> (PAGETABLE_ORD= ER - GDT_LDT_VCPU_SHIFT))=0A #define perdomain_ptes(d, v) \=0A- = ((l1_pgentry_t *)page_to_virt((d)->arch.mm_perdomain_pt_pages \=0A- = [perdomain_pt_pgidx(v)]) + (((v)->vcpu_id << GDT_LDT_VCPU_SHIFT) & \=0A- = (L1_PAGETABLE_ENTRIES - 1)))=0A-#define = perdomain_pt_page(d, n) ((d)->arch.mm_perdomain_pt_pages[n])=0A+ = ((l1_pgentry_t *)(d)->arch.perdomain_pts[perdomain_pt_idx(v)] + \=0A+ = (((v)->vcpu_id << GDT_LDT_VCPU_SHIFT) & (L1_PAGETABLE_ENTRIES - 1)))=0A = =0A struct pv_vcpu=0A {=0A --=__Part2617858F.0__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__Part2617858F.0__=--