From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Cooper Subject: Re: [PATCH] x86: fix determination of bit count for struct domain allocations Date: Fri, 14 Mar 2014 15:30:11 +0000 Message-ID: <53232083.6080502@citrix.com> References: <53232CEF020000780012443B@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============2261429659923316631==" Return-path: Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WOU4p-0003D2-E9 for xen-devel@lists.xenproject.org; Fri, 14 Mar 2014 15:31:15 +0000 In-Reply-To: <53232CEF020000780012443B@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: Jan Beulich Cc: xen-devel , Keir Fraser List-Id: xen-devel@lists.xenproject.org --===============2261429659923316631== Content-Type: multipart/alternative; boundary="------------070305010309030305060802" --------------070305010309030305060802 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7bit On 14/03/14 15:23, Jan Beulich wrote: > 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); > } > > +static unsigned int __init noinline _domain_struct_bits(void) noinline for debugging purposes? ~Andrew > +{ > + unsigned int bits = 32 + PAGE_SHIFT; > + unsigned int sig = hweight32(~pfn_hole_mask); > + unsigned int mask = pfn_hole_mask >> 32; > + > + for ( ; bits < BITS_PER_LONG && sig < 32; ++bits, mask >>= 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 = 32 + PAGE_SHIFT + pfn_pdx_hole_shift; > + static unsigned int __read_mostly bits; > + > + if ( unlikely(!bits) ) > + bits = _domain_struct_bits(); > > BUILD_BUG_ON(sizeof(*d) > PAGE_SIZE); > d = alloc_xenheap_pages(0, MEMF_bits(bits)); > > > > > > _______________________________________________ > Xen-devel mailing list > Xen-devel@lists.xen.org > http://lists.xen.org/xen-devel --------------070305010309030305060802 Content-Type: text/html; charset="ISO-8859-1" Content-Transfer-Encoding: 7bit
On 14/03/14 15:23, Jan Beulich wrote:
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 <jbeulich@suse.com>

--- 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);
 }
 
+static unsigned int __init noinline _domain_struct_bits(void)

noinline for debugging purposes?

~Andrew

+{
+    unsigned int bits = 32 + PAGE_SHIFT;
+    unsigned int sig = hweight32(~pfn_hole_mask);
+    unsigned int mask = pfn_hole_mask >> 32;
+
+    for ( ; bits < BITS_PER_LONG && sig < 32; ++bits, mask >>= 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 = 32 + PAGE_SHIFT + pfn_pdx_hole_shift;
+    static unsigned int __read_mostly bits;
+
+    if ( unlikely(!bits) )
+         bits = _domain_struct_bits();
 
     BUILD_BUG_ON(sizeof(*d) > PAGE_SIZE);
     d = alloc_xenheap_pages(0, MEMF_bits(bits));





_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

--------------070305010309030305060802-- --===============2261429659923316631== 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 --===============2261429659923316631==--