Reserve required memory for pKVM on Intel platform before de-privilege. It takes use of general API kvm_hyp_reserve() to do the reservation, which get pkvm reserve memory size (hyp_mem_size) from API hyp_total_reserve_pages() then record reserved physical memory base to hyp_mem_base. At the same time, register system memory block layout info to hyp_memory[] array. Signed-off-by: Jason Chen CJ <jason.cj.chen@xxxxxxxxx> --- arch/x86/include/asm/kvm_pkvm.h | 14 ++++++++++++++ arch/x86/kernel/setup.c | 3 +++ arch/x86/kvm/vmx/pkvm/Makefile | 3 +++ virt/kvm/pkvm/pkvm.c | 1 + 4 files changed, 21 insertions(+) diff --git a/arch/x86/include/asm/kvm_pkvm.h b/arch/x86/include/asm/kvm_pkvm.h index 30f7f805bcb8..3c750f1a3a2d 100644 --- a/arch/x86/include/asm/kvm_pkvm.h +++ b/arch/x86/include/asm/kvm_pkvm.h @@ -27,6 +27,11 @@ unsigned long pkvm_virt_to_phys(void *virt); #define __hyp_pa __pkvm_pa #define __hyp_va __pkvm_va +extern phys_addr_t hyp_mem_base; +extern phys_addr_t hyp_mem_size; + +void __init kvm_hyp_reserve(void); + static inline unsigned long __pkvm_pgtable_max_pages(unsigned long nr_pages) { unsigned long total = 0, i; @@ -111,7 +116,16 @@ static inline unsigned long pkvm_data_struct_pages(unsigned long global_pgs, return (percpu_pgs * num_cpus + global_pgs); } +static inline int hyp_pre_reserve_check(void) +{ + /* no necessary check yet*/ + return 0; +} + u64 hyp_total_reserve_pages(void); + +#else +static inline void kvm_hyp_reserve(void) {} #endif #endif diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index 88188549647c..1598d7235af9 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -39,6 +39,7 @@ #include <asm/cpu.h> #include <asm/efi.h> #include <asm/gart.h> +#include <asm/kvm_pkvm.h> #include <asm/hypervisor.h> #include <asm/io_apic.h> #include <asm/kasan.h> @@ -1322,6 +1323,8 @@ void __init setup_arch(char **cmdline_p) #endif unwind_init(); + + kvm_hyp_reserve(); } #ifdef CONFIG_X86_32 diff --git a/arch/x86/kvm/vmx/pkvm/Makefile b/arch/x86/kvm/vmx/pkvm/Makefile index fa90a7375f6f..12d82e889033 100644 --- a/arch/x86/kvm/vmx/pkvm/Makefile +++ b/arch/x86/kvm/vmx/pkvm/Makefile @@ -1,10 +1,13 @@ # SPDX-License-Identifier: GPL-2.0 +KVM_PKVM ?= ../../../../../virt/kvm/pkvm ccflags-y += -I $(srctree)/arch/x86/kvm ccflags-y += -I $(srctree)/arch/x86/kvm/vmx/pkvm/include pkvm-obj := pkvm_host.o +pkvm-obj += $(KVM_PKVM)/pkvm.o + obj-$(CONFIG_PKVM_INTEL) += $(pkvm-obj) obj-$(CONFIG_PKVM_INTEL) += hyp/ diff --git a/virt/kvm/pkvm/pkvm.c b/virt/kvm/pkvm/pkvm.c index 6f06a41f0e77..8a20a662b917 100644 --- a/virt/kvm/pkvm/pkvm.c +++ b/virt/kvm/pkvm/pkvm.c @@ -4,6 +4,7 @@ * Author: Quentin Perret <qperret@xxxxxxxxxx> */ +#include <linux/kvm_host.h> #include <linux/memblock.h> #include <linux/sort.h> -- 2.25.1