From: "Roger Pau Monné" <roger.pau@citrix.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
xen-devel@lists.xenproject.org
Subject: Re: [PATCH v4 8/8] x86/mm: adjust loop in arch_init_memory() to iterate over the PDX space
Date: Tue, 5 Aug 2025 17:27:39 +0200 [thread overview]
Message-ID: <aJIi6wrNZck1DSU_@macbook.local> (raw)
In-Reply-To: <31691bf7-94bf-4f73-b04c-a32f86bb0e37@suse.com>
On Tue, Aug 05, 2025 at 02:38:38PM +0200, Jan Beulich wrote:
> On 05.08.2025 11:52, Roger Pau Monne wrote:
> > --- a/xen/arch/x86/mm.c
> > +++ b/xen/arch/x86/mm.c
> > @@ -275,7 +275,7 @@ static void __init assign_io_page(struct page_info *page)
> >
> > void __init arch_init_memory(void)
> > {
> > - unsigned long i, pfn, rstart_pfn, rend_pfn, iostart_pfn, ioend_pfn;
> > + unsigned long i, pfn, rstart_pfn, rend_pfn, iostart_pfn, ioend_pfn, pdx;
> >
> > /*
> > * Basic guest-accessible flags:
> > @@ -328,9 +328,20 @@ void __init arch_init_memory(void)
> > destroy_xen_mappings((unsigned long)mfn_to_virt(iostart_pfn),
> > (unsigned long)mfn_to_virt(ioend_pfn));
> >
> > - /* Mark as I/O up to next RAM region. */
> > - for ( ; pfn < rstart_pfn; pfn++ )
> > + /*
> > + * Mark as I/O up to next RAM region. Iterate over the PDX space to
> > + * skip holes which would always fail the mfn_valid() check.
> > + *
> > + * pfn_to_pdx() requires a valid (iow: RAM) PFN to convert to PDX,
> > + * hence provide pfn - 1, which is the tailing PFN from the last RAM
> > + * range, or pdx 0 if the input pfn is 0.
> > + */
> > + for ( pdx = pfn ? pfn_to_pdx(pfn - 1) + 1 : 0;
> > + pdx < pfn_to_pdx(rstart_pfn);
> > + pdx++ )
> > {
> > + pfn = pdx_to_pfn(pdx);
> > +
> > if ( !mfn_valid(_mfn(pfn)) )
> > continue;
> >
>
> As much as I would have liked to ack this, I fear there's another caveat here:
> At the top of the loop we check not only for RAM, but also for UNUSABLE. The
> latter, like RAM, shouldn't be marked I/O, but we also can't use PFN <-> PDX
> transformations on any such page.
Right you are. I'm not sure however why we do this - won't we want
the mappings of UNUSABLE regions also be removed from the Xen
page-tables? (but not marked as IO)
I could do something like:
/* Mark as I/O up to next RAM or UNUSABLE region. */
if ( (!pfn || pdx_is_region_compressible(pfn_to_paddr(pfn - 1), 1)) &&
pdx_is_region_compressible(pfn_to_paddr(rstart_pfn), 1) )
{
/*
* Iterate over the PDX space to skip holes which would always fail
* the mfn_valid() check.
*
* pfn_to_pdx() requires a valid (iow: RAM) PFN to convert to PDX,
* hence provide pfn - 1, which is the tailing PFN from the last
* RAM range, or pdx 0 if the input pfn is 0.
*/
for ( pdx = pfn ? pfn_to_pdx(pfn - 1) + 1 : 0;
pdx < pfn_to_pdx(rstart_pfn);
pdx++ )
{
pfn = pdx_to_pfn(pdx);
if ( !mfn_valid(_mfn(pfn)) )
continue;
assign_io_page(mfn_to_page(_mfn(pfn)));
}
}
else
{
/* Slow path, iterate over the PFN space. */
for ( ; pfn < rstart_pfn; pfn++ )
{
if ( !mfn_valid(_mfn(pfn)) )
continue;
assign_io_page(mfn_to_page(_mfn(pfn)));
}
}
But I find it a bit ugly - I might send v5 without this final patch
while I see if I can find a better alternative.
Thanks, Roger.
next prev parent reply other threads:[~2025-08-05 15:27 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-05 9:52 [PATCH v4 0/8] pdx: introduce a new compression algorithm Roger Pau Monne
2025-08-05 9:52 ` [PATCH v4 1/8] kconfig: turn PDX compression into a choice Roger Pau Monne
2025-08-08 17:10 ` Julien Grall
2025-08-05 9:52 ` [PATCH v4 2/8] pdx: provide a unified set of unit functions Roger Pau Monne
2025-08-08 17:21 ` Julien Grall
2025-08-11 8:07 ` Roger Pau Monné
2025-08-11 16:42 ` Julien Grall
2025-08-05 9:52 ` [PATCH v4 3/8] pdx: introduce command line compression toggle Roger Pau Monne
2025-08-05 9:52 ` [PATCH v4 4/8] pdx: allow per-arch optimization of PDX conversion helpers Roger Pau Monne
2025-08-05 12:11 ` Jan Beulich
2025-08-05 14:20 ` Roger Pau Monné
2025-08-05 15:02 ` Jan Beulich
2025-08-05 9:52 ` [PATCH v4 5/8] test/pdx: add PDX compression unit tests Roger Pau Monne
2025-08-06 8:16 ` Anthony PERARD
2025-08-05 9:52 ` [PATCH v4 6/8] pdx: move some helpers in preparation for new compression Roger Pau Monne
2025-08-05 9:52 ` [PATCH v4 7/8] pdx: introduce a new compression algorithm based on region offsets Roger Pau Monne
2025-08-05 12:28 ` Jan Beulich
2025-08-05 14:37 ` Roger Pau Monné
2025-08-05 9:52 ` [PATCH v4 8/8] x86/mm: adjust loop in arch_init_memory() to iterate over the PDX space Roger Pau Monne
2025-08-05 12:38 ` Jan Beulich
2025-08-05 15:27 ` Roger Pau Monné [this message]
2025-08-06 8:11 ` Jan Beulich
2025-08-06 10:25 ` 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=aJIi6wrNZck1DSU_@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.