From: "Roger Pau Monné" <roger.pau@citrix.com>
To: Alejandro Vallejo <alejandro.vallejo@cloud.com>
Cc: xen-devel@lists.xenproject.org, Hongyan Xia <hongyxia@amazon.com>,
Jan Beulich <jbeulich@suse.com>,
Andrew Cooper <andrew.cooper3@citrix.com>,
Julien Grall <jgrall@amazon.com>,
Elias El Yandouzi <eliasely@amazon.com>
Subject: Re: [PATCH v5 11/15] x86/setup: Do not create valid mappings when directmap=no
Date: Thu, 4 Dec 2025 12:04:17 +0100 [thread overview]
Message-ID: <aTFqsYBsI5WheTX4@Mac.lan> (raw)
In-Reply-To: <20250108151822.16030-12-alejandro.vallejo@cloud.com>
On Wed, Jan 08, 2025 at 03:18:18PM +0000, Alejandro Vallejo wrote:
> From: Hongyan Xia <hongyxia@amazon.com>
>
> Create empty mappings in the second e820 pass. Also, destroy existing
> direct map mappings created in the first pass.
>
> To make xenheap pages visible in guests, it is necessary to create empty
> L3 tables in the direct map even when directmap=no, since guest cr3s
> copy idle domain's L4 entries, which means they will share mappings in
> the direct map if we pre-populate idle domain's L4 entries and L3
> tables. A helper is introduced for this.
>
> Also, after the direct map is actually gone, we need to stop updating
> the direct map in update_xen_mappings().
>
> Signed-off-by: Hongyan Xia <hongyxia@amazon.com>
> Signed-off-by: Julien Grall <jgrall@amazon.com>
> Signed-off-by: Elias El Yandouzi <eliasely@amazon.com>
> Signed-off-by: Alejandro Vallejo <alejandro.vallejo@cloud.com>
> ---
> v4->v5:
> * No changes.
> ---
> xen/arch/x86/setup.c | 73 +++++++++++++++++++++++++++++++++++++++-----
> 1 file changed, 66 insertions(+), 7 deletions(-)
>
> diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c
> index 609ec4cf07f2..23b77f13bc10 100644
> --- a/xen/arch/x86/setup.c
> +++ b/xen/arch/x86/setup.c
> @@ -1060,6 +1060,56 @@ static struct domain *__init create_dom0(struct boot_info *bi)
> return d;
> }
>
> +/*
> + * This either populates a valid direct map, or allocates empty L3 tables and
> + * creates the L4 entries for virtual address between [start, end) in the
> + * direct map depending on has_directmap();
> + *
> + * When directmap=no, we still need to populate empty L3 tables in the
> + * direct map region. The reason is that on-demand xenheap mappings are
> + * created in the idle domain's page table but must be seen by
> + * everyone. Since all domains share the direct map L4 entries, they
> + * will share xenheap mappings if we pre-populate the L4 entries and L3
> + * tables in the direct map region for all RAM. We also rely on the fact
> + * that L3 tables are never freed.
> + */
> +static void __init populate_directmap(paddr_t pstart, paddr_t pend,
> + unsigned int flags)
> +{
> + unsigned long vstart = (unsigned long)__va(pstart);
> + unsigned long vend = (unsigned long)__va(pend);
> +
> + if ( pstart >= pend )
> + return;
> +
> + BUG_ON(vstart < DIRECTMAP_VIRT_START);
> + BUG_ON(vend > DIRECTMAP_VIRT_END);
> +
> + if ( has_directmap() )
> + /* Populate valid direct map. */
> + BUG_ON(map_pages_to_xen(vstart, maddr_to_mfn(pstart),
> + PFN_DOWN(pend - pstart), flags));
> + else
> + {
> + /* Create empty L3 tables. */
> + unsigned long vaddr = vstart & ~((1UL << L4_PAGETABLE_SHIFT) - 1);
> +
> + for ( unsigned long idx = l4_table_offset(vaddr);
> + idx <= l4_table_offset(vend); idx++ )
> + {
> + l4_pgentry_t *pl4e = &idle_pg_table[l4_table_offset(idx)];
As we are attempting to integrate this series with the per-CPU
mappings work, there's an issue here. l4_table_offset() call is
duplicated, as idx is already the L4 table index:
for ( unsigned long idx = l4_table_offset(vaddr);
idx <= l4_table_offset(vend); idx++ )
{
l4_pgentry_t *pl4e = &idle_pg_table[idx];
This probably went unnoticed in small systems that can fit all the
directmap in a single L4 entry, but does explode on bigger ones.
Leaving a note here in case anyone else picks this up before a new
version is sent.
Regards, Roger.
next prev parent reply other threads:[~2025-12-04 11:04 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-08 15:18 [PATCH v5 00/15] Remove the directmap Alejandro Vallejo
2025-01-08 15:18 ` [PATCH v5 01/15] x86: Create per-domain mapping for guest_root_pt Alejandro Vallejo
2025-01-08 15:18 ` [PATCH v5 02/15] x86/pv: Use copy_domain_page() to manage domheap pages during initrd relocation Alejandro Vallejo
2025-01-08 15:18 ` [PATCH v5 03/15] x86/pv: Rewrite how building PV dom0 handles domheap mappings Alejandro Vallejo
2025-01-08 15:18 ` [PATCH v5 04/15] x86: Initialize mapcache for PV, HVM, and idle domains Alejandro Vallejo
2025-01-08 15:18 ` [PATCH v5 05/15] x86: Add a boot option to enable and disable the direct map Alejandro Vallejo
2025-01-08 15:18 ` [PATCH v5 06/15] xen/x86: Add support for the PMAP Alejandro Vallejo
2025-01-08 15:18 ` [PATCH v5 07/15] x86/domain_page: Remove the fast paths when mfn is not in the directmap Alejandro Vallejo
2025-01-08 15:18 ` [PATCH v5 08/15] xen/page_alloc: Add a path for xenheap when there is no direct map Alejandro Vallejo
2025-01-08 15:18 ` [PATCH v5 09/15] x86/setup: Leave early boot slightly earlier Alejandro Vallejo
2025-01-08 15:18 ` [PATCH v5 10/15] xen/page_alloc: vmap heap nodes when they are outside the direct map Alejandro Vallejo
2025-01-08 15:18 ` [PATCH v5 11/15] x86/setup: Do not create valid mappings when directmap=no Alejandro Vallejo
2025-12-04 11:04 ` Roger Pau Monné [this message]
2025-01-08 15:18 ` [PATCH v5 12/15] xen/arm64: mm: Use per-pCPU page-tables Alejandro Vallejo
2025-01-08 15:18 ` [PATCH v5 13/15] xen/arm32: Hardwire zeroeth_table_offset to 0 on ARM_32 Alejandro Vallejo
2025-01-08 15:18 ` [PATCH v5 14/15] xen/arm64: Implement a mapcache for arm64 Alejandro Vallejo
2025-01-08 15:18 ` [PATCH v5 15/15] xen/arm64: Allow the admin to enable/disable the directmap Alejandro Vallejo
2025-01-08 15:30 ` [PATCH v5 00/15] Remove " Alejandro Vallejo
2025-02-06 14:55 ` Alejandro Vallejo
2025-02-06 15:06 ` 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=aTFqsYBsI5WheTX4@Mac.lan \
--to=roger.pau@citrix.com \
--cc=alejandro.vallejo@cloud.com \
--cc=andrew.cooper3@citrix.com \
--cc=eliasely@amazon.com \
--cc=hongyxia@amazon.com \
--cc=jbeulich@suse.com \
--cc=jgrall@amazon.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.