From: "Roger Pau Monné" <roger.pau@citrix.com>
To: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: xen-devel@lists.xenproject.org, Jan Beulich <jbeulich@suse.com>
Subject: Re: [PATCH 1/8] x86/pdx: simplify calculation of domain struct allocation boundary
Date: Thu, 12 Jun 2025 08:57:18 +0200 [thread overview]
Message-ID: <aEp6TveXYxHXFgnF@macbook.local> (raw)
In-Reply-To: <b78a4877-353d-4320-95a2-f3cefa018a61@citrix.com>
On Wed, Jun 11, 2025 at 06:58:31PM +0100, Andrew Cooper wrote:
> On 11/06/2025 6:16 pm, Roger Pau Monne wrote:
> > diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
> > index 7536b6c8717e..2f438ce367cf 100644
> > --- a/xen/arch/x86/domain.c
> > +++ b/xen/arch/x86/domain.c
> > @@ -461,30 +461,6 @@ void domain_cpu_policy_changed(struct domain *d)
> > }
> > }
> >
> > -#if !defined(CONFIG_BIGMEM) && defined(CONFIG_PDX_COMPRESSION)
> > -/*
> > - * The hole may be at or above the 44-bit boundary, so we need to determine
> > - * the total bit count until reaching 32 significant (not squashed out) bits
> > - * in PFN representations.
> > - * Note that the way "bits" gets initialized/updated/bounds-checked guarantees
> > - * that the function will never return zero, and hence will never be called
> > - * more than once (which is important due to it being deliberately placed in
> > - * .init.text).
> > - */
> > -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;
> > -
> > - return bits;
> > -}
> > -#endif
> > -
>
> I'm very happy to see this disappear. Both because of a non-__init
> function calling an __init function, and because this internal is just
> horrible.
>
> > struct domain *alloc_domain_struct(void)
> > {
> > struct domain *d;
> > @@ -498,14 +474,15 @@ struct domain *alloc_domain_struct(void)
> > * On systems with CONFIG_BIGMEM there's no packing, and so there's no
> > * such restriction.
> > */
> > -#if defined(CONFIG_BIGMEM) || !defined(CONFIG_PDX_COMPRESSION)
> > - const unsigned int bits = IS_ENABLED(CONFIG_BIGMEM) ? 0 :
> > - 32 + PAGE_SHIFT;
> > +#if defined(CONFIG_BIGMEM)
> > + const unsigned int bits = 0;
> > #else
> > - static unsigned int __read_mostly bits;
> > + static unsigned int __ro_after_init bits;
> >
> > if ( unlikely(!bits) )
> > - bits = _domain_struct_bits();
> > + bits = flsl(pfn_to_paddr(pdx_to_pfn(
> > + 1UL << (sizeof(((struct page_info *)NULL)->v.inuse._domain) * 8))))
> > + - 1;
>
> I think this would benefit greatly by not being a oneliner. There's
> sizeof_field() which helps a little.
Oh, I missed that. I was expecting to find something like
member_size() or similar.
> But, isn't this UB with CONFIG_BIGMEM? You're shifting 1UL by 64.
CONFIG_BIGMEM doesn't get here (see the #fidef above).
> When __pdx_t is unsigned long, there's no bits restriction necessary.
> Therefore, don't you want !bits && sizeof_field(...) < BYTES_PER_LONG as
> the entry criteria?
__pdx_t being unsigned long can only happen for CONFIG_BIGMEM, and
that's still handled separately using a #if defined(CONFIG_BIGMEM) ...
(which I should have converted to #ifdef instead).
Thanks, Roger.
next prev parent reply other threads:[~2025-06-12 6:57 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-11 17:16 [PATCH 0/8] pdx: introduce a new compression algorithm Roger Pau Monne
2025-06-11 17:16 ` [PATCH 1/8] x86/pdx: simplify calculation of domain struct allocation boundary Roger Pau Monne
2025-06-11 17:58 ` Andrew Cooper
2025-06-12 6:57 ` Roger Pau Monné [this message]
2025-06-12 9:03 ` Jan Beulich
2025-06-12 10:46 ` Roger Pau Monné
2025-06-12 12:00 ` Jan Beulich
2025-06-11 17:16 ` [PATCH 2/8] pdx: introduce function to calculate max PFN based on PDX compression Roger Pau Monne
2025-06-12 9:11 ` Jan Beulich
2025-06-12 10:48 ` Roger Pau Monné
2025-06-12 12:02 ` Jan Beulich
2025-06-11 17:16 ` [PATCH 3/8] kconfig: turn PDX compression into a choice Roger Pau Monne
2025-06-12 8:28 ` Jan Beulich
2025-06-11 17:16 ` [PATCH 4/8] pdx: provide a unified set of unit functions Roger Pau Monne
2025-06-12 8:32 ` Jan Beulich
2025-06-12 10:50 ` Roger Pau Monné
2025-06-12 8:36 ` Jan Beulich
2025-06-12 10:51 ` Roger Pau Monné
2025-06-12 12:03 ` Jan Beulich
2025-06-11 17:16 ` [PATCH 5/8] pdx: allow optimizing PDX conversion helpers Roger Pau Monne
2025-06-11 17:16 ` [PATCH 6/8] pdx: introduce a new compression algorithm based on offsets between regions Roger Pau Monne
2025-06-11 19:33 ` Andrew Cooper
2025-06-12 7:26 ` Roger Pau Monné
2025-06-12 7:59 ` Roger Pau Monné
2025-06-12 8:27 ` Jan Beulich
2025-06-12 14:03 ` Roger Pau Monné
2025-06-16 7:50 ` Jan Beulich
2025-06-18 13:02 ` Jan Beulich
2025-06-18 14:11 ` Roger Pau Monné
2025-06-11 17:16 ` [PATCH 7/8] pdx: introduce translation helpers for offset compression Roger Pau Monne
2025-06-11 17:16 ` [PATCH 8/8] pdx: introduce a command line option " Roger Pau Monne
2025-06-17 7:09 ` Oleksii Kurochko
2025-06-18 13:36 ` Jan Beulich
2025-06-18 14:12 ` Roger Pau Monné
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=aEp6TveXYxHXFgnF@macbook.local \
--to=roger.pau@citrix.com \
--cc=andrew.cooper3@citrix.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.