[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RFC PATCH 3/5] x86/xen: Build the initial PV direct map at PAGE_OFFSET


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx, x86@xxxxxxxxxx
  • From: Teddy Astie <teddy.astie@xxxxxxxxxx>
  • Date: Mon, 30 Nov 2026 15:36:48 +0100
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=vates.tech header.i="@vates.tech" header.h="From:Subject:Date:Message-ID:To:Cc:MIME-Version:Content-Type:In-Reply-To:References:Feedback-ID"
  • Cc: Teddy Astie <teddy.astie@xxxxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, Boris Ostrovsky <boris.ostrovsky@xxxxxxxxxx>
  • Delivery-date: Mon, 30 Nov 2026 14:37:36 +0000
  • Feedback-id: default:8631fc262581453bbf619ec5b2062170:Sweego
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

xen_setup_kernel_pagetable() unconditionally grafts the initial
physical mapping at __PAGE_OFFSET_BASE_L4 (L4[273][0]), which only
matches PAGE_OFFSET as long as it isn't randomized.

Use PAGE_OFFSET instead. As it is only PUD aligned when randomized,
also use pud_index(PAGE_OFFSET) rather than 0 for the L3 entry.

No functional change without memory randomization.

Signed-off-by: Teddy Astie <teddy.astie@xxxxxxxxxx>
Assisted-by: LLM
---
CC: Juergen Gross <jgross@xxxxxxxx>
CC: Boris Ostrovsky <boris.ostrovsky@xxxxxxxxxx>

 arch/x86/xen/mmu_pv.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/arch/x86/xen/mmu_pv.c b/arch/x86/xen/mmu_pv.c
index 377c3c0d9f20..cae5d1cf02fd 100644
--- a/arch/x86/xen/mmu_pv.c
+++ b/arch/x86/xen/mmu_pv.c
@@ -1788,18 +1788,23 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, 
unsigned long max_pfn)
        /* Zap identity mapping */
        init_top_pgt[0] = __pgd(0);
 
-       init_top_pgt[pgd_index(__PAGE_OFFSET_BASE_L4)].pgd =
+       /*
+        * PAGE_OFFSET may have been randomized (CONFIG_RANDOMIZE_MEMORY), it
+        * is PUD aligned but not necessarily PGD aligned.
+        */
+       init_top_pgt[pgd_index(PAGE_OFFSET)].pgd =
                __pa_symbol(level3_ident_pgt) + _KERNPG_TABLE_NOENC;
        init_top_pgt[pgd_index(__START_KERNEL_map)].pgd =
                __pa_symbol(level3_kernel_pgt) + _PAGE_TABLE_NOENC;
-       level3_ident_pgt[0].pud = __pa_symbol(level2_ident_pgt) + 
_KERNPG_TABLE_NOENC;
+       level3_ident_pgt[pud_index(PAGE_OFFSET)].pud =
+               __pa_symbol(level2_ident_pgt) + _KERNPG_TABLE_NOENC;
 
        /* Pre-constructed entries are in pfn, so convert to mfn */
-       /* L4[273] -> level3_ident_pgt  */
+       /* L4[pgd_index(PAGE_OFFSET)] -> level3_ident_pgt  */
        /* L4[511] -> level3_kernel_pgt */
        convert_pfn_mfn(init_top_pgt);
 
-       /* L3_i[0] -> level2_ident_pgt */
+       /* L3_i[pud_index(PAGE_OFFSET)] -> level2_ident_pgt */
        convert_pfn_mfn(level3_ident_pgt);
        /* L3_k[510] -> level2_kernel_pgt */
        /* L3_k[511] -> level2_fixmap_pgt */
@@ -1815,8 +1820,8 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, 
unsigned long max_pfn)
        addr[0] = (unsigned long)pgd;
        addr[1] = (unsigned long)l3;
        addr[2] = (unsigned long)l2;
-       /* Graft it onto L4[273][0]. Note that we creating an aliasing problem:
-        * Both L4[273][0] and L4[511][510] have entries that point to the same
+       /* Graft it onto L4[PAGE_OFFSET]. Note that we creating an aliasing 
problem:
+        * Both L4[PAGE_OFFSET] and L4[511][510] have entries that point to the 
same
         * L2 (PMD) tables. Meaning that if you modify it in __va space
         * it will be also modified in the __ka space! (But if you just
         * modify the PMD table to point to other PTE's or none, then you
-- 
2.56.1



--
Teddy Astie | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.