From: "Jan Beulich" Subject: [PATCH 3/5] x86-64: use MFN also for next_shadow link Date: Fri, 30 Jan 2009 10:37:20 +0000 Message-ID: <4982E670.76E4.0078.0@novell.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Return-path: Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org Signed-off-by: Jan Beulich --- 2009-01-30.orig/xen/arch/x86/mm/shadow/common.c 2009-01-30 = 10:17:04.000000000 +0100 +++ 2009-01-30/xen/arch/x86/mm/shadow/common.c 2009-01-30 10:19:27.0000000= 00 +0100 @@ -1489,6 +1489,22 @@ static __init int shadow_blow_tables_key __initcall(shadow_blow_tables_keyhandler_init); #endif /* !NDEBUG */ =20 +#ifdef __i386__ +# define next_shadow(pg) ((pg)->next_shadow) +# define set_next_shadow(pg, n) ((void)((pg)->next_shadow =3D (n))) +#else +static inline struct shadow_page_info * +next_shadow(const struct shadow_page_info *sp) +{ + return sp->next_shadow ? mfn_to_shadow_page(_mfn(sp->next_shadow)) : = NULL; +} +static inline void +set_next_shadow(struct shadow_page_info *sp, struct shadow_page_info = *next) +{ + sp->next_shadow =3D next ? mfn_x(shadow_page_to_mfn(next)) : 0; +} +#endif + /* Allocate another shadow's worth of (contiguous, aligned) pages, * and fill in the type and backpointer fields of their page_infos.=20 * Never fails to allocate. */ @@ -1554,7 +1570,7 @@ mfn_t shadow_alloc(struct domain *d, =20 sp[i].u.sh.pinned =3D 0; sp[i].u.sh.count =3D 0; sp[i].u.sh.back =3D backpointer; - sp[i].next_shadow =3D NULL; + set_next_shadow(&sp[i], NULL); perfc_incr(shadow_alloc_count); } return shadow_page_to_mfn(sp); @@ -1890,7 +1906,7 @@ static void sh_hash_audit_bucket(struct=20 /* Wrong bucket? */ BUG_ON( sh_hash(sp->u.sh.back, sp->u.sh.type) !=3D bucket ); /* Duplicate entry? */ - for ( x =3D sp->next_shadow; x; x =3D x->next_shadow ) + for ( x =3D next_shadow(sp); x; x =3D next_shadow(x) ) BUG_ON( x->u.sh.back =3D=3D sp->u.sh.back && x->u.sh.type =3D=3D sp->u.sh.type ); /* Follow the backpointer to the guest pagetable */ @@ -1934,7 +1950,7 @@ static void sh_hash_audit_bucket(struct=20 } } /* That entry was OK; on we go */ - sp =3D sp->next_shadow; + sp =3D next_shadow(sp); } } =20 @@ -2028,7 +2044,7 @@ mfn_t shadow_hash_lookup(struct vcpu *v, /* Delete sp from the list */ prev->next_shadow =3D sp->next_shadow; = =20 /* Re-insert it at the head of the list */ - sp->next_shadow =3D d->arch.paging.shadow.hash_table[k= ey]; + set_next_shadow(sp, d->arch.paging.shadow.hash_table[k= ey]); d->arch.paging.shadow.hash_table[key] =3D sp; } } @@ -2039,7 +2055,7 @@ mfn_t shadow_hash_lookup(struct vcpu *v, return shadow_page_to_mfn(sp); } prev =3D sp; - sp =3D sp->next_shadow; + sp =3D next_shadow(sp); } =20 perfc_incr(shadow_hash_lookup_miss); @@ -2066,7 +2082,7 @@ void shadow_hash_insert(struct vcpu *v,=20 =20 /* Insert this shadow at the top of the bucket */ sp =3D mfn_to_shadow_page(smfn); - sp->next_shadow =3D d->arch.paging.shadow.hash_table[key]; + set_next_shadow(sp, d->arch.paging.shadow.hash_table[key]); d->arch.paging.shadow.hash_table[key] =3D sp; =20 sh_hash_audit_bucket(d, key); @@ -2093,7 +2109,7 @@ void shadow_hash_delete(struct vcpu *v,=20 sp =3D mfn_to_shadow_page(smfn); if ( d->arch.paging.shadow.hash_table[key] =3D=3D sp )=20 /* Easy case: we're deleting the head item. */ - d->arch.paging.shadow.hash_table[key] =3D sp->next_shadow; + d->arch.paging.shadow.hash_table[key] =3D next_shadow(sp); else=20 { /* Need to search for the one we want */ @@ -2102,15 +2118,15 @@ void shadow_hash_delete(struct vcpu *v,=20 { ASSERT(x); /* We can't have hit the end, since our target is * still in the chain somehwere... */ - if ( x->next_shadow =3D=3D sp )=20 + if ( next_shadow(x) =3D=3D sp ) { x->next_shadow =3D sp->next_shadow; break; } - x =3D x->next_shadow; + x =3D next_shadow(x); } } - sp->next_shadow =3D NULL; + set_next_shadow(sp, NULL); =20 sh_hash_audit_bucket(d, key); } @@ -2144,7 +2160,7 @@ static void hash_foreach(struct vcpu *v, /* WARNING: This is not safe against changes to the hash table. * The callback *must* return non-zero if it has inserted or * deleted anything from the hash (lookups are OK, though). */ - for ( x =3D d->arch.paging.shadow.hash_table[i]; x; x =3D = x->next_shadow ) + for ( x =3D d->arch.paging.shadow.hash_table[i]; x; x =3D = next_shadow(x) ) { if ( callback_mask & (1 << x->u.sh.type) ) { --- 2009-01-30.orig/xen/include/asm-x86/mm.h 2009-01-30 10:14:47.0000000= 00 +0100 +++ 2009-01-30/xen/include/asm-x86/mm.h 2009-01-30 10:19:27.000000000 = +0100 @@ -139,7 +139,11 @@ struct page_info u32 shadow_flags; =20 /* When in use as a shadow, next shadow in this hash chain. */ +#ifdef __i386__ struct shadow_page_info *next_shadow; +#else + __mfn_t next_shadow; +#endif }; }; =20