From: Keir Fraser <keir.xen@gmail.com>
To: Jan Beulich <JBeulich@suse.com>
Cc: xen-devel <xen-devel@lists.xenproject.org>
Subject: Re: [PATCH] x86: fix determination of bit count for struct domain allocations
Date: Mon, 24 Mar 2014 08:56:51 +0000 [thread overview]
Message-ID: <532FF353.20203@gmail.com> (raw)
In-Reply-To: <53232CEF020000780012443B@nat28.tlf.novell.com>
[-- Attachment #1.1: Type: text/plain, Size: 1873 bytes --]
> Jan Beulich <mailto:JBeulich@suse.com>
> 14 March 2014 15:23
> 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)
> +{
> + 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;
This logic took a few looks to be sure what it was doing, let alone
correct. Without the patch comment I'd be even a bit more lost. I think
the changeset comment, or similar, should be included as a code comment
for this new function.
I'm sure given there is only one hole there is a simpler form of this
based on checking whether bottom_shift > 44. But this is more general I
suppose, so probably better despite being harder to understand.
Acked-by: Keir Fraser <keir@xen.org>
> + 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));
>
>
>
[-- Attachment #1.2.1: Type: text/html, Size: 3725 bytes --]
[-- Attachment #1.2.2: compose-unknown-contact.jpg --]
[-- Type: image/jpeg, Size: 770 bytes --]
[-- Attachment #2: Type: text/plain, Size: 126 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
next prev parent reply other threads:[~2014-03-24 8:56 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-14 15:23 [PATCH] x86: fix determination of bit count for struct domain allocations Jan Beulich
2014-03-14 15:30 ` Andrew Cooper
2014-03-14 15:46 ` Jan Beulich
2014-03-14 15:51 ` Andrew Cooper
2014-03-14 16:12 ` Jan Beulich
2014-03-14 16:18 ` Andrew Cooper
2014-03-24 8:56 ` Keir Fraser [this message]
2014-03-24 9:39 ` Jan Beulich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=532FF353.20203@gmail.com \
--to=keir.xen@gmail.com \
--cc=JBeulich@suse.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.