From: "Jan Beulich" Subject: [PATCH v2 3/3] x86: use linear L1 page table for map_domain_page() page table manipulation Date: Tue, 26 Feb 2013 16:07:22 +0000 Message-ID: <512CEBCA02000078000C127E@nat28.tlf.novell.com> References: <512CE92B02000078000C1256@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part625212AA.0__=" Return-path: In-Reply-To: <512CE92B02000078000C1256@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. --=__Part625212AA.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline This saves allocation of a Xen heap page for tracking the L1 page table pointers. Signed-off-by: Jan Beulich --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -585,7 +585,6 @@ int arch_domain_create(struct domain *d, free_xenheap_page(d->shared_info); if ( paging_initialised ) paging_final_teardown(d); - mapcache_domain_exit(d); free_perdomain_mappings(d); if ( !is_hvm_domain(d) ) free_xenheap_page(d->arch.pv_domain.gdt_ldt_l1tab); @@ -605,8 +604,6 @@ void arch_domain_destroy(struct domain * =20 paging_final_teardown(d); =20 - mapcache_domain_exit(d); - free_perdomain_mappings(d); if ( !is_hvm_domain(d) ) free_xenheap_page(d->arch.pv_domain.gdt_ldt_l1tab); --- a/xen/arch/x86/domain_page.c +++ b/xen/arch/x86/domain_page.c @@ -53,9 +53,8 @@ void __init mapcache_override_current(st =20 #define mapcache_l2_entry(e) ((e) >> PAGETABLE_ORDER) #define MAPCACHE_L2_ENTRIES (mapcache_l2_entry(MAPCACHE_ENTRIES - 1) + 1) -#define DCACHE_L1ENT(dc, idx) \ - ((dc)->l1tab[(idx) >> PAGETABLE_ORDER] \ - [(idx) & ((1 << PAGETABLE_ORDER) - 1)]) +#define MAPCACHE_L1ENT(idx) \ + __linear_l1_table[l1_linear_offset(MAPCACHE_VIRT_START + pfn_to_paddr(= idx))] =20 void *map_domain_page(unsigned long mfn) { @@ -77,7 +76,7 @@ void *map_domain_page(unsigned long mfn) =20 dcache =3D &v->domain->arch.pv_domain.mapcache; vcache =3D &v->arch.pv_vcpu.mapcache; - if ( !dcache->l1tab ) + if ( !dcache->inuse ) return mfn_to_virt(mfn); =20 perfc_incr(map_domain_page_count); @@ -91,7 +90,7 @@ void *map_domain_page(unsigned long mfn) ASSERT(idx < dcache->entries); hashent->refcnt++; ASSERT(hashent->refcnt); - ASSERT(l1e_get_pfn(DCACHE_L1ENT(dcache, idx)) =3D=3D mfn); + ASSERT(l1e_get_pfn(MAPCACHE_L1ENT(idx)) =3D=3D mfn); goto out; } =20 @@ -131,9 +130,8 @@ void *map_domain_page(unsigned long mfn) if ( hashent->idx !=3D MAPHASHENT_NOTINUSE && !hashent->re= fcnt ) { idx =3D hashent->idx; - ASSERT(l1e_get_pfn(DCACHE_L1ENT(dcache, idx)) =3D=3D - hashent->mfn); - l1e_write(&DCACHE_L1ENT(dcache, idx), l1e_empty()); + ASSERT(l1e_get_pfn(MAPCACHE_L1ENT(idx)) =3D=3D = hashent->mfn); + l1e_write(&MAPCACHE_L1ENT(idx), l1e_empty()); hashent->idx =3D MAPHASHENT_NOTINUSE; hashent->mfn =3D ~0UL; break; @@ -156,8 +154,7 @@ void *map_domain_page(unsigned long mfn) =20 spin_unlock(&dcache->lock); =20 - l1e_write(&DCACHE_L1ENT(dcache, idx), - l1e_from_pfn(mfn, __PAGE_HYPERVISOR)); + l1e_write(&MAPCACHE_L1ENT(idx), l1e_from_pfn(mfn, __PAGE_HYPERVISOR));= =20 out: local_irq_restore(flags); @@ -181,10 +178,10 @@ void unmap_domain_page(const void *ptr) ASSERT(v && !is_hvm_vcpu(v)); =20 dcache =3D &v->domain->arch.pv_domain.mapcache; - ASSERT(dcache->l1tab); + ASSERT(dcache->inuse); =20 idx =3D PFN_DOWN(va - MAPCACHE_VIRT_START); - mfn =3D l1e_get_pfn(DCACHE_L1ENT(dcache, idx)); + mfn =3D l1e_get_pfn(MAPCACHE_L1ENT(idx)); hashent =3D &v->arch.pv_vcpu.mapcache.hash[MAPHASH_HASHFN(mfn)]; =20 local_irq_save(flags); @@ -200,9 +197,9 @@ void unmap_domain_page(const void *ptr) if ( hashent->idx !=3D MAPHASHENT_NOTINUSE ) { /* /First/, zap the PTE. */ - ASSERT(l1e_get_pfn(DCACHE_L1ENT(dcache, hashent->idx)) =3D=3D + ASSERT(l1e_get_pfn(MAPCACHE_L1ENT(hashent->idx)) =3D=3D hashent->mfn); - l1e_write(&DCACHE_L1ENT(dcache, hashent->idx), l1e_empty()); + l1e_write(&MAPCACHE_L1ENT(hashent->idx), l1e_empty()); /* /Second/, mark as garbage. */ set_bit(hashent->idx, dcache->garbage); } @@ -214,7 +211,7 @@ void unmap_domain_page(const void *ptr) else { /* /First/, zap the PTE. */ - l1e_write(&DCACHE_L1ENT(dcache, idx), l1e_empty()); + l1e_write(&MAPCACHE_L1ENT(idx), l1e_empty()); /* /Second/, mark as garbage. */ set_bit(idx, dcache->garbage); } @@ -253,10 +250,6 @@ int mapcache_domain_init(struct domain * return 0; #endif =20 - dcache->l1tab =3D xzalloc_array(l1_pgentry_t *, MAPCACHE_L2_ENTRIES); - if ( !dcache->l1tab ) - return -ENOMEM; - BUILD_BUG_ON(MAPCACHE_VIRT_END + PAGE_SIZE * (3 + 2 * PFN_UP(BITS_TO_LONGS(MAPCACHE_ENTRIES) * sizeof(long)= )) > MAPCACHE_VIRT_START + (PERDOMAIN_SLOT_MBYTES << 20)); @@ -272,16 +265,6 @@ int mapcache_domain_init(struct domain * NIL(l1_pgentry_t *), NULL); } =20 -void mapcache_domain_exit(struct domain *d) -{ - struct mapcache_domain *dcache =3D &d->arch.pv_domain.mapcache; - - if ( is_hvm_domain(d) ) - return; - - xfree(dcache->l1tab); -} - int mapcache_vcpu_init(struct vcpu *v) { struct domain *d =3D v->domain; @@ -290,7 +273,7 @@ int mapcache_vcpu_init(struct vcpu *v) unsigned int ents =3D d->max_vcpus * MAPCACHE_VCPU_ENTRIES; unsigned int nr =3D PFN_UP(BITS_TO_LONGS(ents) * sizeof(long)); =20 - if ( is_hvm_vcpu(v) || !dcache->l1tab ) + if ( is_hvm_vcpu(v) || !dcache->inuse ) return 0; =20 if ( ents > dcache->entries ) @@ -298,7 +281,7 @@ int mapcache_vcpu_init(struct vcpu *v) /* Populate page tables. */ int rc =3D create_perdomain_mapping(d, MAPCACHE_VIRT_START, d->max_vcpus * MAPCACHE_VCPU_ENT= RIES, - dcache->l1tab, NULL); + NIL(l1_pgentry_t *), NULL); =20 /* Populate bit maps. */ if ( !rc ) --- a/xen/include/asm-x86/domain.h +++ b/xen/include/asm-x86/domain.h @@ -53,8 +53,7 @@ struct mapcache_vcpu { }; =20 struct mapcache_domain { - /* The PTEs that provide the mappings, and a cursor into the array. = */ - l1_pgentry_t **l1tab; + /* The number of array entries, and a cursor into the array. */ unsigned int entries; unsigned int cursor; =20 @@ -71,7 +70,6 @@ struct mapcache_domain { }; =20 int mapcache_domain_init(struct domain *); -void mapcache_domain_exit(struct domain *); int mapcache_vcpu_init(struct vcpu *); void mapcache_override_current(struct vcpu *); =20 --=__Part625212AA.0__= Content-Type: text/plain; name="x86-map-domain-page-use-linear-l1.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-map-domain-page-use-linear-l1.patch" x86: use linear L1 page table for map_domain_page() page table manipulation= =0A=0AThis saves allocation of a Xen heap page for tracking the L1 page = table=0Apointers.=0A=0ASigned-off-by: Jan Beulich =0A=0A= --- a/xen/arch/x86/domain.c=0A+++ b/xen/arch/x86/domain.c=0A@@ -585,7 = +585,6 @@ int arch_domain_create(struct domain *d,=0A free_xenheap_page= (d->shared_info);=0A if ( paging_initialised )=0A paging_final_= teardown(d);=0A- mapcache_domain_exit(d);=0A free_perdomain_mappings= (d);=0A if ( !is_hvm_domain(d) )=0A free_xenheap_page(d->arch.p= v_domain.gdt_ldt_l1tab);=0A@@ -605,8 +604,6 @@ void arch_domain_destroy(str= uct domain *=0A =0A paging_final_teardown(d);=0A =0A- mapcache_domai= n_exit(d);=0A-=0A free_perdomain_mappings(d);=0A if ( !is_hvm_domai= n(d) )=0A free_xenheap_page(d->arch.pv_domain.gdt_ldt_l1tab);=0A---= a/xen/arch/x86/domain_page.c=0A+++ b/xen/arch/x86/domain_page.c=0A@@ = -53,9 +53,8 @@ void __init mapcache_override_current(st=0A =0A #define = mapcache_l2_entry(e) ((e) >> PAGETABLE_ORDER)=0A #define MAPCACHE_L2_ENTRIE= S (mapcache_l2_entry(MAPCACHE_ENTRIES - 1) + 1)=0A-#define DCACHE_L1ENT(dc,= idx) \=0A- ((dc)->l1tab[(idx) >> PAGETABLE_ORDER] \=0A- = [(idx) & ((1 << PAGETABLE_ORDER) - 1)])=0A+#define MAPCACHE_L1ENT(idx) = \=0A+ __linear_l1_table[l1_linear_offset(MAPCACHE_VIRT_START + = pfn_to_paddr(idx))]=0A =0A void *map_domain_page(unsigned long mfn)=0A = {=0A@@ -77,7 +76,7 @@ void *map_domain_page(unsigned long mfn)=0A =0A = dcache =3D &v->domain->arch.pv_domain.mapcache;=0A vcache =3D = &v->arch.pv_vcpu.mapcache;=0A- if ( !dcache->l1tab )=0A+ if ( = !dcache->inuse )=0A return mfn_to_virt(mfn);=0A =0A perfc_incr(= map_domain_page_count);=0A@@ -91,7 +90,7 @@ void *map_domain_page(unsigned = long mfn)=0A ASSERT(idx < dcache->entries);=0A hashent->ref= cnt++;=0A ASSERT(hashent->refcnt);=0A- ASSERT(l1e_get_pfn(DC= ACHE_L1ENT(dcache, idx)) =3D=3D mfn);=0A+ ASSERT(l1e_get_pfn(MAPCACH= E_L1ENT(idx)) =3D=3D mfn);=0A goto out;=0A }=0A =0A@@ -131,9 = +130,8 @@ void *map_domain_page(unsigned long mfn)=0A if ( = hashent->idx !=3D MAPHASHENT_NOTINUSE && !hashent->refcnt )=0A = {=0A idx =3D hashent->idx;=0A- = ASSERT(l1e_get_pfn(DCACHE_L1ENT(dcache, idx)) =3D=3D=0A- = hashent->mfn);=0A- l1e_write(&DCACHE_L1ENT(dcach= e, idx), l1e_empty());=0A+ ASSERT(l1e_get_pfn(MAPCACHE_L= 1ENT(idx)) =3D=3D hashent->mfn);=0A+ l1e_write(&MAPCACHE= _L1ENT(idx), l1e_empty());=0A hashent->idx =3D = MAPHASHENT_NOTINUSE;=0A hashent->mfn =3D ~0UL;=0A = break;=0A@@ -156,8 +154,7 @@ void *map_domain_page(unsigned = long mfn)=0A =0A spin_unlock(&dcache->lock);=0A =0A- l1e_write(&DCAC= HE_L1ENT(dcache, idx),=0A- l1e_from_pfn(mfn, __PAGE_HYPERVISOR= ));=0A+ l1e_write(&MAPCACHE_L1ENT(idx), l1e_from_pfn(mfn, __PAGE_HYPERVI= SOR));=0A =0A out:=0A local_irq_restore(flags);=0A@@ -181,10 +178,10 = @@ void unmap_domain_page(const void *ptr)=0A ASSERT(v && !is_hvm_vcpu(= v));=0A =0A dcache =3D &v->domain->arch.pv_domain.mapcache;=0A- = ASSERT(dcache->l1tab);=0A+ ASSERT(dcache->inuse);=0A =0A idx =3D = PFN_DOWN(va - MAPCACHE_VIRT_START);=0A- mfn =3D l1e_get_pfn(DCACHE_L1ENT= (dcache, idx));=0A+ mfn =3D l1e_get_pfn(MAPCACHE_L1ENT(idx));=0A = hashent =3D &v->arch.pv_vcpu.mapcache.hash[MAPHASH_HASHFN(mfn)];=0A =0A = local_irq_save(flags);=0A@@ -200,9 +197,9 @@ void unmap_domain_page(const = void *ptr)=0A if ( hashent->idx !=3D MAPHASHENT_NOTINUSE )=0A = {=0A /* /First/, zap the PTE. */=0A- ASSERT(l1e_g= et_pfn(DCACHE_L1ENT(dcache, hashent->idx)) =3D=3D=0A+ ASSERT(l1e= _get_pfn(MAPCACHE_L1ENT(hashent->idx)) =3D=3D=0A = hashent->mfn);=0A- l1e_write(&DCACHE_L1ENT(dcache, hashent->idx)= , l1e_empty());=0A+ l1e_write(&MAPCACHE_L1ENT(hashent->idx), = l1e_empty());=0A /* /Second/, mark as garbage. */=0A = set_bit(hashent->idx, dcache->garbage);=0A }=0A@@ -214,7 +211,7 = @@ void unmap_domain_page(const void *ptr)=0A else=0A {=0A = /* /First/, zap the PTE. */=0A- l1e_write(&DCACHE_L1ENT(dcache, = idx), l1e_empty());=0A+ l1e_write(&MAPCACHE_L1ENT(idx), l1e_empty())= ;=0A /* /Second/, mark as garbage. */=0A set_bit(idx, = dcache->garbage);=0A }=0A@@ -253,10 +250,6 @@ int mapcache_domain_init(= struct domain *=0A return 0;=0A #endif=0A =0A- dcache->l1tab = =3D xzalloc_array(l1_pgentry_t *, MAPCACHE_L2_ENTRIES);=0A- if ( = !dcache->l1tab )=0A- return -ENOMEM;=0A-=0A BUILD_BUG_ON(MAPCACH= E_VIRT_END + PAGE_SIZE * (3 +=0A 2 * PFN_UP(BITS_TO_LONGS(= MAPCACHE_ENTRIES) * sizeof(long))) >=0A MAPCACHE_VIRT_STAR= T + (PERDOMAIN_SLOT_MBYTES << 20));=0A@@ -272,16 +265,6 @@ int mapcache_dom= ain_init(struct domain *=0A NIL(l1_pgen= try_t *), NULL);=0A }=0A =0A-void mapcache_domain_exit(struct domain = *d)=0A-{=0A- struct mapcache_domain *dcache =3D &d->arch.pv_domain.mapca= che;=0A-=0A- if ( is_hvm_domain(d) )=0A- return;=0A-=0A- = xfree(dcache->l1tab);=0A-}=0A-=0A int mapcache_vcpu_init(struct vcpu = *v)=0A {=0A struct domain *d =3D v->domain;=0A@@ -290,7 +273,7 @@ int = mapcache_vcpu_init(struct vcpu *v)=0A unsigned int ents =3D d->max_vcpu= s * MAPCACHE_VCPU_ENTRIES;=0A unsigned int nr =3D PFN_UP(BITS_TO_LONGS(= ents) * sizeof(long));=0A =0A- if ( is_hvm_vcpu(v) || !dcache->l1tab = )=0A+ if ( is_hvm_vcpu(v) || !dcache->inuse )=0A return 0;=0A = =0A if ( ents > dcache->entries )=0A@@ -298,7 +281,7 @@ int mapcache_vc= pu_init(struct vcpu *v)=0A /* Populate page tables. */=0A = int rc =3D create_perdomain_mapping(d, MAPCACHE_VIRT_START,=0A = d->max_vcpus * MAPCACHE_VCPU_ENTRIES,=0A- = dcache->l1tab, NULL);=0A+ = NIL(l1_pgentry_t *), NULL);=0A =0A = /* Populate bit maps. */=0A if ( !rc )=0A--- a/xen/include/asm-x86/= domain.h=0A+++ b/xen/include/asm-x86/domain.h=0A@@ -53,8 +53,7 @@ struct = mapcache_vcpu {=0A };=0A =0A struct mapcache_domain {=0A- /* The PTEs = that provide the mappings, and a cursor into the array. */=0A- = l1_pgentry_t **l1tab;=0A+ /* The number of array entries, and a cursor = into the array. */=0A unsigned int entries;=0A unsigned int = cursor;=0A =0A@@ -71,7 +70,6 @@ struct mapcache_domain {=0A };=0A =0A int = mapcache_domain_init(struct domain *);=0A-void mapcache_domain_exit(struct = domain *);=0A int mapcache_vcpu_init(struct vcpu *);=0A void mapcache_overr= ide_current(struct vcpu *);=0A =0A --=__Part625212AA.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 --=__Part625212AA.0__=--