From: "Jan Beulich" Subject: [PATCH] x86: fix determination of bit count for struct domain allocations Date: Fri, 14 Mar 2014 15:23:11 +0000 Message-ID: <53232CEF020000780012443B@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartC9FBB4CF.0__=" Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WOTwv-00024z-Gr for xen-devel@lists.xenproject.org; Fri, 14 Mar 2014 15:23:05 +0000 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 Cc: Keir Fraser 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. --=__PartC9FBB4CF.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline We can't just add in the hole shift value, as the hole may be at or above the 44-bit boundary. Instead we need to determine the total bit count until reaching 32 significant (not squashed out) bits in PFN representations. Signed-off-by: Jan Beulich --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -180,6 +180,19 @@ void dump_pageframe_info(struct domain * spin_unlock(&d->page_alloc_lock); } =20 +static unsigned int __init noinline _domain_struct_bits(void) +{ + unsigned int bits =3D 32 + PAGE_SHIFT; + unsigned int sig =3D hweight32(~pfn_hole_mask); + unsigned int mask =3D pfn_hole_mask >> 32; + + for ( ; bits < BITS_PER_LONG && sig < 32; ++bits, mask >>=3D 1 ) + if ( !(mask & 1) ) + ++sig; + + return bits; +} + struct domain *alloc_domain_struct(void) { struct domain *d; @@ -187,7 +200,10 @@ struct domain *alloc_domain_struct(void) * We pack the PDX of the domain structure into a 32-bit field within * the page_info structure. Hence the MEMF_bits() restriction. */ - unsigned int bits =3D 32 + PAGE_SHIFT + pfn_pdx_hole_shift; + static unsigned int __read_mostly bits; + + if ( unlikely(!bits) ) + bits =3D _domain_struct_bits(); =20 BUILD_BUG_ON(sizeof(*d) > PAGE_SIZE); d =3D alloc_xenheap_pages(0, MEMF_bits(bits)); --=__PartC9FBB4CF.0__= Content-Type: text/plain; name="x86-domain-struct-bits.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-domain-struct-bits.patch" x86: fix determination of bit count for struct domain allocations=0A=0AWe = can't just add in the hole shift value, as the hole may be at or=0Aabove = the 44-bit boundary. Instead we need to determine the total bit=0Acount = until reaching 32 significant (not squashed out) bits in PFN=0Arepresentati= ons.=0A=0ASigned-off-by: Jan Beulich =0A=0A--- = a/xen/arch/x86/domain.c=0A+++ b/xen/arch/x86/domain.c=0A@@ -180,6 +180,19 = @@ void dump_pageframe_info(struct domain *=0A spin_unlock(&d->page_all= oc_lock);=0A }=0A =0A+static unsigned int __init noinline _domain_struct_bi= ts(void)=0A+{=0A+ unsigned int bits =3D 32 + PAGE_SHIFT;=0A+ = unsigned int sig =3D hweight32(~pfn_hole_mask);=0A+ unsigned int mask = =3D pfn_hole_mask >> 32;=0A+=0A+ for ( ; bits < BITS_PER_LONG && sig < = 32; ++bits, mask >>=3D 1 )=0A+ if ( !(mask & 1) )=0A+ = ++sig;=0A+=0A+ return bits;=0A+}=0A+=0A struct domain *alloc_domain_stru= ct(void)=0A {=0A struct domain *d;=0A@@ -187,7 +200,10 @@ struct = domain *alloc_domain_struct(void)=0A * We pack the PDX of the domain = structure into a 32-bit field within=0A * the page_info structure. = Hence the MEMF_bits() restriction.=0A */=0A- unsigned int bits =3D = 32 + PAGE_SHIFT + pfn_pdx_hole_shift;=0A+ static unsigned int __read_mos= tly bits;=0A+=0A+ if ( unlikely(!bits) )=0A+ bits =3D _domain_st= ruct_bits();=0A =0A BUILD_BUG_ON(sizeof(*d) > PAGE_SIZE);=0A d =3D = alloc_xenheap_pages(0, MEMF_bits(bits));=0A --=__PartC9FBB4CF.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 --=__PartC9FBB4CF.0__=--