@@ -4,6 +4,11 @@
#define __head __section(".head.text")
+#define SYM_ABS_VA(sym) ({ \
+ unsigned long __v; \
+ asm("movabsq $" __stringify(sym) ", %0":"=r"(__v)); \
+ __v; })
+
struct x86_mapping_info {
void *(*alloc_pgt_page)(void *); /* allocate buf for page table */
void *context; /* context for alloc_pgt_page */
@@ -82,11 +82,6 @@ static void __head set_kernel_map_base(unsigned long text_base)
}
#endif
-#define SYM_ABS_VA(sym) ({ \
- unsigned long __v; \
- asm("movabsq $" __stringify(sym) ", %0":"=r"(__v)); \
- __v; })
-
static unsigned long __head sme_postprocess_startup(struct boot_params *bp, pmdval_t *pmd)
{
unsigned long vaddr, vaddr_end;
@@ -1,8 +1,10 @@
// SPDX-License-Identifier: GPL-2.0
#include <linux/acpi.h>
+#include <linux/pgtable.h>
#include <xen/hvc-console.h>
+#include <asm/init.h>
#include <asm/io_apic.h>
#include <asm/hypervisor.h>
#include <asm/e820/api.h>
@@ -113,6 +115,26 @@ static void __init hypervisor_specific_init(bool xen_guest)
xen_pvh_init(&pvh_bootparams);
}
+#ifdef CONFIG_PVM_GUEST
+void pvm_relocate_kernel(unsigned long physbase);
+
+void __init pvm_update_pgtable(unsigned long physbase)
+{
+ pgdval_t *pgd;
+ pudval_t *pud;
+ unsigned long base;
+
+ pvm_relocate_kernel(physbase);
+
+ pgd = (pgdval_t *)init_top_pgt;
+ base = SYM_ABS_VA(_text);
+ pgd[pgd_index(base)] = pgd[0];
+ pgd[pgd_index(page_offset_base)] = pgd[0];
+ pud = (pudval_t *)level3_ident_pgt;
+ pud[pud_index(base)] = (unsigned long)level2_ident_pgt + _KERNPG_TABLE_NOENC;
+}
+#endif
+
/*
* This routine (and those that it might call) should not use
* anything that lives in .bss since that segment will be cleared later.
@@ -109,6 +109,10 @@ SYM_CODE_START_LOCAL(pvh_start_xen)
wrmsr
#ifdef CONFIG_X86_PIE
+#ifdef CONFIG_PVM_GUEST
+ leaq _text(%rip), %rdi
+ call pvm_update_pgtable
+#endif
movabs $2f, %rax
ANNOTATE_RETPOLINE_SAFE
jmp *%rax