Introduce & support pKVM on Intel platform
Subsystems (4)
cover Introduce & support pKVM on Intel platform
This patch set is part-2 of this RFC patches. It introduces CONFIG_PKVM_INTEL, and do a deprivilege for native run Linux, to a host VM.
Host Linux must be trusted until pKVM got boot up, so pKVM shall be boot as early as possible. In addition, pKVM can not support deinit (e.g., return host to root mode after it got deprivileged to a VM). These disallow build KVM module (pKVM binary embedded) as a dynamic loaded module. Thus after enable CONFIG_PKVM_INTEL, the KVM module is built-in, and the Linux system running on bare-metal prepares environment to run each pCPU into vmx non-root mode - this means all pCPUs in native Linux are deprivileged to vCPUs, and the native Linux system is deprivileged to a host VM. Meanwhile pKVM is kept running under vmx root mode with an independent binary.
Host VM almost own all the hardware resources except modules owned by pKVM, like VMX, EPT and IOMMU; pKVM shall fully own VMX, EPT and IOMMU to ensure the isolation of protected VMs.
This patch set did some initial works for above:
- pKVM manages the VMX to do the host deprivilege. But there is no VMX emulation to host VM, so host VM can not run its guests base on pKVM yet.
- The EPT is disabled for host VM as no host EPT page table created in pKVM yet. And there is no MMU page table setup for pKVM either, so it reuses native Linux Kernel's CR3 page table now.
- The IOMMU is not touched by pKVM yet and directly pass-thru to host VM.
And this patch set also build pKVM as an independent binary, which make pKVM compiled with separated sections, and add prefix __pkvm for all its symbols to ensure pKVM & host Linux will not touch each other's symbols. This help to do the address space isolation for pKVM and host VM in the next patch series.
The future patch sets shall create pKVM its own CR3 page table, enable memory isolation based on EPT page table, provide emulation of VMCS and EPT for host VM, and enable DMA protection based on IOMMU & its emulation for host VM (Not in this RFC).
Jason Chen CJ (16):
pkvm: x86: Introduce CONFIG_PKVM_INTEL
KVM: VMX: Refactor for setup_vmcs_config
pkvm: x86: Add vmx capability check and vmx config setup
pkvm: x86: Add pCPU env setup
pkvm: x86: Add basic setup for host vcpu
pkvm: x86: Introduce pkvm_host_deprivilege_cpus
pkvm: x86: Allocate vmcs and msr bitmap pages for host vcpu
pkvm: x86: Initailize vmcs guest state area for host vcpu
pkvm: x86: Initialize vmcs host state area for host vcpu
pkvm: x86: Initialize vmcs control fields for host vcpu
pkvm: x86: Define empty debug functions for hypervisor
pkvm: x86: Add vmexit handler for host vcpu
pkvm: x86: Add private vmx_ops.h for pKVM
pkvm: x86: Add pKVM retpoline.S
pkvm: x86: Build pKVM runtime as an independent binary
pkvm: x86: Deprivilege host OS
Zide Chen (1):
pkvm: x86: Stub CONFIG_DEBUG_LIST in pKVM
arch/x86/include/asm/kvm_host.h | 1 + arch/x86/include/asm/pkvm_image.h | 42 ++ arch/x86/kernel/vmlinux.lds.S | 32 + arch/x86/kvm/Kconfig | 13 + arch/x86/kvm/Makefile | 1 + arch/x86/kvm/vmx/pkvm/.gitignore | 1 + arch/x86/kvm/vmx/pkvm/Makefile | 9 + arch/x86/kvm/vmx/pkvm/hyp/Makefile | 40 ++ arch/x86/kvm/vmx/pkvm/hyp/debug.h | 13 + arch/x86/kvm/vmx/pkvm/hyp/lib/list_debug.c | 17 + arch/x86/kvm/vmx/pkvm/hyp/lib/retpoline.S | 113 ++++ arch/x86/kvm/vmx/pkvm/hyp/pkvm.lds.S | 10 + arch/x86/kvm/vmx/pkvm/hyp/vmexit.c | 154 +++++ arch/x86/kvm/vmx/pkvm/hyp/vmexit.h | 11 + arch/x86/kvm/vmx/pkvm/hyp/vmx_asm.S | 186 ++++++ arch/x86/kvm/vmx/pkvm/hyp/vmx_ops.h | 185 ++++++ arch/x86/kvm/vmx/pkvm/include/pkvm.h | 54 ++ arch/x86/kvm/vmx/pkvm/pkvm_host.c | 728 +++++++++++++++++++++ arch/x86/kvm/vmx/vmx.c | 122 ++-- arch/x86/kvm/vmx/vmx.h | 22 + arch/x86/kvm/vmx/vmx_ops.h | 7 + arch/x86/kvm/x86.c | 5 + include/asm-generic/vmlinux.lds.h | 17 + 23 files changed, 1736 insertions(+), 47 deletions(-) create mode 100644 arch/x86/include/asm/pkvm_image.h create mode 100644 arch/x86/kvm/vmx/pkvm/.gitignore create mode 100644 arch/x86/kvm/vmx/pkvm/Makefile create mode 100644 arch/x86/kvm/vmx/pkvm/hyp/Makefile create mode 100644 arch/x86/kvm/vmx/pkvm/hyp/debug.h create mode 100644 arch/x86/kvm/vmx/pkvm/hyp/lib/list_debug.c create mode 100644 arch/x86/kvm/vmx/pkvm/hyp/lib/retpoline.S create mode 100644 arch/x86/kvm/vmx/pkvm/hyp/pkvm.lds.S create mode 100644 arch/x86/kvm/vmx/pkvm/hyp/vmexit.c create mode 100644 arch/x86/kvm/vmx/pkvm/hyp/vmexit.h create mode 100644 arch/x86/kvm/vmx/pkvm/hyp/vmx_asm.S create mode 100644 arch/x86/kvm/vmx/pkvm/hyp/vmx_ops.h create mode 100644 arch/x86/kvm/vmx/pkvm/include/pkvm.h create mode 100644 arch/x86/kvm/vmx/pkvm/pkvm_host.c
Signature · 1 line
2.25.1
RFC PATCH 1/17 pkvm: x86: Introduce CONFIG_PKVM_INTEL
Add CONFIG_PKVM_INTEL configuration to enable or disable pKVM feature on x86 platform (starting from Intel platform), and do pkvm_init as an extension of KVM. Now pkvm_init only reserves memory for pkvm data structure and does a quick setup for num_cpus.
New pKVM on Intel platform files are placed under arch/x86/kvm/vmx/pkvm.
--- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/Kconfig | 13 +++++++++++ arch/x86/kvm/Makefile | 1 + arch/x86/kvm/vmx/pkvm/Makefile | 7 ++++++ arch/x86/kvm/vmx/pkvm/include/pkvm.h | 15 ++++++++++++ arch/x86/kvm/vmx/pkvm/pkvm_host.c | 34 ++++++++++++++++++++++++++++ arch/x86/kvm/vmx/vmx.c | 3 +++ arch/x86/kvm/vmx/vmx.h | 4 ++++ arch/x86/kvm/x86.c | 5 ++++ 9 files changed, 83 insertions(+)
arch/x86/include/asm/kvm_host.h +1 -0
@@ -1731,6 +1731,7 @@ struct kvm_x86_nested_ops { };struct kvm_x86_init_ops { +int (*pkvm_init)(void );int (*cpu_has_kvm_support)(void );int (*disabled_by_bios)(void );int (*check_processor_compatibility)(void );
arch/x86/kvm/Kconfig +13 -0
@@ -87,6 +87,19 @@ config KVM_INTEL To compile this as a module, choose M here: the module will be called kvm-intel. +config PKVM_INTEL + bool "pKVM for Intel processors support" + depends on KVM_INTEL=y + depends on X86_64 + help + Provides support for pKVM on Intel processors. + + This will deprivilege the host as a VM running in non-root VMX + operation mode, and pKVM hypervisor will run in root VMX + operation mode. + + If unsure, say N. + config X86_SGX_KVM bool "Software Guard eXtensions (SGX) Virtualization" depends on X86_SGX && KVM_INTEL
arch/x86/kvm/Makefile +1 -0
@@ -35,6 +35,7 @@ endif obj-$(CONFIG_KVM) += kvm.o obj-$(CONFIG_KVM_INTEL) += kvm-intel.o +obj-$(CONFIG_PKVM_INTEL) += vmx/pkvm/ obj-$(CONFIG_KVM_AMD) += kvm-amd.o AFLAGS_svm/vmenter.o := -iquote $(obj)
arch/x86/kvm/vmx/pkvm/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0 + +ccflags-y += -I $(srctree)/arch/x86/kvm/vmx/pkvm/include + +pkvm-obj := pkvm_host.o + +obj-$(CONFIG_PKVM_INTEL) += $(pkvm-obj)
arch/x86/kvm/vmx/pkvm/include/pkvm.h new file +15 -0
@@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2022 Intel Corporation +*/ + +#ifndef _PKVM_H_ +#define _PKVM_H_ + +struct pkvm_hyp { +int num_cpus; +}; + +#define PKVM_PAGES (ALIGN(sizeof(struct pkvm_hyp), PAGE_SIZE) >> PAGE_SHIFT) + +#endif
arch/x86/kvm/vmx/pkvm/pkvm_host.c new file +34 -0
@@ -0,0 +1,34 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2022 Intel Corporation +*/ + +#include <linux/kernel.h> +#include <linux/module.h> + +#include <pkvm.h> + +MODULE_LICENSE ("GPL" ); + +static struct pkvm_hyp *pkvm; + +static void *pkvm_early_alloc_contig (int pages) +{ +return alloc_pages_exact (pages <<PAGE_SHIFT ,GFP_KERNEL | __GFP_ZERO); +} + +__init int pkvm_init (void ) +{ +int ret =0 ; + + pkvm =pkvm_early_alloc_contig (PKVM_PAGES ); +if (!pkvm) { + ret = -ENOMEM ; + goto out; + } + + pkvm->num_cpus =num_possible_cpus (); + +out: +return ret; +}
arch/x86/kvm/vmx/vmx.c +3 -0
@@ -8467,6 +8467,9 @@ static __init int hardware_setup(void) }static struct kvm_x86_init_ops vmx_init_ops__initdata = { +#ifdef CONFIG_PKVM_INTEL + .pkvm_init = pkvm_init, +#endif .cpu_has_kvm_support = cpu_has_kvm_support, .disabled_by_bios = vmx_disabled_by_bios, .check_processor_compatibility = vmx_check_processor_compat,
arch/x86/kvm/vmx/vmx.h +4 -0
@@ -752,4 +752,8 @@ static inline bool guest_cpuid_has_evmcs(struct kvm_vcpu *vcpu) to_vmx(vcpu)->nested.enlightened_vmcs_enabled; } +#ifdef CONFIG_PKVM_INTEL +int __init pkvm_init (void ); +#endif +#endif /* __KVM_X86_VMX_H */
arch/x86/kvm/x86.c +5 -0
@@ -9312,6 +9312,11 @@ int kvm_arch_init(void *opaque)return -EOPNOTSUPP ; } +if (ops->pkvm_init && ops->pkvm_init ()) { +pr_err_ratelimited ("kvm: pkvm init fail\n" ); +return -EOPNOTSUPP ; + } +/* * KVM explicitly assumes that the guest has an FPU and * FXSAVE/FXRSTOR. For example, the KVM_GET_FPU explicitly casts the
Signature · 1 line
2.25.1
RFC PATCH 2/17 KVM: VMX: Refactor for setup_vmcs_config
In reply to Jason Chen CJDo refactoring for setup_vmcs_config, leave its major part as setup_vmcs_config_common, which can be used by both KVM and pKVM on Intel platform.
--- arch/x86/kvm/vmx/vmx.c | 119 +++++++++++++++++++++++++---------------- arch/x86/kvm/vmx/vmx.h | 18 +++++++ 2 files changed, 90 insertions(+), 47 deletions(-)
arch/x86/kvm/vmx/vmx.c +72 -47
@@ -2593,8 +2593,9 @@ static __init u64 adjust_vmx_controls64(u64 ctl_opt, u32 msr)return ctl_opt & allowed; } -static __init int setup_vmcs_config (struct vmcs_config *vmcs_conf, -struct vmx_capability *vmx_cap) +__init int setup_vmcs_config_common (struct vmcs_config *vmcs_conf, +struct vmx_capability *vmx_cap, +struct vmcs_config_setting *setting) {u32 vmx_msr_low, vmx_msr_high;u32 _pin_based_exec_control =0 ;
@@ -2604,34 +2605,17 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf,u32 _vmexit_control =0 ;u32 _vmentry_control =0 ;u64 misc_msr; -int i; - -/* -* LOAD/SAVE_DEBUG_CONTROLS are absent because both are mandatory. -* SAVE_IA32_PAT and SAVE_IA32_EFER are absent because KVM always -* intercepts writes to PAT and EFER, i.e. never enables those controls. -*/ -struct { -u32 entry_control; -u32 exit_control; - }const vmcs_entry_exit_pairs[] = { - {VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL ,VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL }, - {VM_ENTRY_LOAD_IA32_PAT ,VM_EXIT_LOAD_IA32_PAT }, - {VM_ENTRY_LOAD_IA32_EFER ,VM_EXIT_LOAD_IA32_EFER }, - {VM_ENTRY_LOAD_BNDCFGS ,VM_EXIT_CLEAR_BNDCFGS }, - {VM_ENTRY_LOAD_IA32_RTIT_CTL ,VM_EXIT_CLEAR_IA32_RTIT_CTL }, - };memset (vmcs_conf,0 ,sizeof (*vmcs_conf)); -if (adjust_vmx_controls (KVM_REQUIRED_VMX_CPU_BASED_VM_EXEC_CONTROL , -KVM_OPTIONAL_VMX_CPU_BASED_VM_EXEC_CONTROL , +if (adjust_vmx_controls (setting->cpu_based_vm_exec_ctrl_req, + setting->cpu_based_vm_exec_ctrl_opt,MSR_IA32_VMX_PROCBASED_CTLS , &_cpu_based_exec_control))return -EIO ;if (_cpu_based_exec_control &CPU_BASED_ACTIVATE_SECONDARY_CONTROLS ) { -if (adjust_vmx_controls (KVM_REQUIRED_VMX_SECONDARY_VM_EXEC_CONTROL , -KVM_OPTIONAL_VMX_SECONDARY_VM_EXEC_CONTROL , +if (adjust_vmx_controls (setting->secondary_vm_exec_ctrl_req, + setting->secondary_vm_exec_ctrl_opt,MSR_IA32_VMX_PROCBASED_CTLS2 , &_cpu_based_2nd_exec_control))return -EIO ;
@@ -2677,17 +2661,17 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf,if (_cpu_based_exec_control &CPU_BASED_ACTIVATE_TERTIARY_CONTROLS ) _cpu_based_3rd_exec_control = -adjust_vmx_controls64 (KVM_OPTIONAL_VMX_TERTIARY_VM_EXEC_CONTROL , +adjust_vmx_controls64 (setting->tertiary_vm_exec_ctrl_opt,MSR_IA32_VMX_PROCBASED_CTLS3 ); -if (adjust_vmx_controls (KVM_REQUIRED_VMX_VM_EXIT_CONTROLS , -KVM_OPTIONAL_VMX_VM_EXIT_CONTROLS , +if (adjust_vmx_controls (setting->vmexit_ctrl_req, + setting->vmexit_ctrl_opt,MSR_IA32_VMX_EXIT_CTLS , &_vmexit_control))return -EIO ; -if (adjust_vmx_controls (KVM_REQUIRED_VMX_PIN_BASED_VM_EXEC_CONTROL , -KVM_OPTIONAL_VMX_PIN_BASED_VM_EXEC_CONTROL , +if (adjust_vmx_controls (setting->pin_based_vm_exec_ctrl_req, + setting->pin_based_vm_exec_ctrl_opt,MSR_IA32_VMX_PINBASED_CTLS , &_pin_based_exec_control))return -EIO ;
@@ -2698,29 +2682,12 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf, SECONDARY_EXEC_VIRTUAL_INTR_DELIVERY)) _pin_based_exec_control &= ~PIN_BASED_POSTED_INTR; -if (adjust_vmx_controls (KVM_REQUIRED_VMX_VM_ENTRY_CONTROLS , -KVM_OPTIONAL_VMX_VM_ENTRY_CONTROLS , +if (adjust_vmx_controls (setting->vmentry_ctrl_req, + setting->vmentry_ctrl_opt,MSR_IA32_VMX_ENTRY_CTLS , &_vmentry_control))return -EIO ; -for (i =0 ; i <ARRAY_SIZE (vmcs_entry_exit_pairs); i++) { -u32 n_ctrl = vmcs_entry_exit_pairs[i].entry_control; -u32 x_ctrl = vmcs_entry_exit_pairs[i].exit_control; - -if (!(_vmentry_control & n_ctrl) == !(_vmexit_control & x_ctrl)) -continue ; - -pr_warn_once ("Inconsistent VM-Entry/VM-Exit pair, entry = %x, exit = %x\n" , - _vmentry_control & n_ctrl, _vmexit_control & x_ctrl); - -if (error_on_inconsistent_vmcs_config) -return -EIO ; - - _vmentry_control &= ~n_ctrl; - _vmexit_control &= ~x_ctrl; - } -rdmsr (MSR_IA32_VMX_BASIC , vmx_msr_low, vmx_msr_high);/* IA-32 SDM Vol 3B: VMCS size is never greater than 4kB. */
@@ -2755,6 +2722,64 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf,return 0 ; } +static __init int setup_vmcs_config (struct vmcs_config *vmcs_conf, +struct vmx_capability *vmx_cap) +{ +int i, ret; +struct vmcs_config_setting setting = { + .cpu_based_vm_exec_ctrl_req =KVM_REQUIRED_VMX_CPU_BASED_VM_EXEC_CONTROL , + .cpu_based_vm_exec_ctrl_opt =KVM_OPTIONAL_VMX_CPU_BASED_VM_EXEC_CONTROL , + .secondary_vm_exec_ctrl_req =KVM_REQUIRED_VMX_SECONDARY_VM_EXEC_CONTROL , + .secondary_vm_exec_ctrl_opt =KVM_OPTIONAL_VMX_SECONDARY_VM_EXEC_CONTROL , + .tertiary_vm_exec_ctrl_opt =KVM_OPTIONAL_VMX_TERTIARY_VM_EXEC_CONTROL , + .pin_based_vm_exec_ctrl_req =KVM_REQUIRED_VMX_PIN_BASED_VM_EXEC_CONTROL , + .pin_based_vm_exec_ctrl_opt =KVM_OPTIONAL_VMX_PIN_BASED_VM_EXEC_CONTROL , + .vmexit_ctrl_req =KVM_REQUIRED_VMX_VM_EXIT_CONTROLS , + .vmexit_ctrl_opt =KVM_OPTIONAL_VMX_VM_EXIT_CONTROLS , + .vmentry_ctrl_req =KVM_REQUIRED_VMX_VM_ENTRY_CONTROLS , + .vmentry_ctrl_opt =KVM_OPTIONAL_VMX_VM_ENTRY_CONTROLS , + }; + +/* +* LOAD/SAVE_DEBUG_CONTROLS are absent because both are mandatory. +* SAVE_IA32_PAT and SAVE_IA32_EFER are absent because KVM always +* intercepts writes to PAT and EFER, i.e. never enables those controls. +*/ +struct { +u32 entry_control; +u32 exit_control; + }const vmcs_entry_exit_pairs[] = { + {VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL ,VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL }, + {VM_ENTRY_LOAD_IA32_PAT ,VM_EXIT_LOAD_IA32_PAT }, + {VM_ENTRY_LOAD_IA32_EFER ,VM_EXIT_LOAD_IA32_EFER }, + {VM_ENTRY_LOAD_BNDCFGS ,VM_EXIT_CLEAR_BNDCFGS }, + {VM_ENTRY_LOAD_IA32_RTIT_CTL ,VM_EXIT_CLEAR_IA32_RTIT_CTL }, + }; + + ret =setup_vmcs_config_common (vmcs_conf, vmx_cap, &setting); +if (ret) +return ret; + +for (i =0 ; i <ARRAY_SIZE (vmcs_entry_exit_pairs); i++) { +u32 n_ctrl = vmcs_entry_exit_pairs[i].entry_control; +u32 x_ctrl = vmcs_entry_exit_pairs[i].exit_control; + +if (!(vmcs_conf->vmentry_ctrl & n_ctrl) == !(vmcs_conf->vmexit_ctrl & x_ctrl)) +continue ; + +pr_warn_once ("Inconsistent VM-Entry/VM-Exit pair, entry = %x, exit = %x\n" , + vmcs_conf->vmentry_ctrl & n_ctrl, vmcs_conf->vmexit_ctrl & x_ctrl); + +if (error_on_inconsistent_vmcs_config) +return -EIO ; + + vmcs_conf->vmentry_ctrl &= ~n_ctrl; + vmcs_conf->vmexit_ctrl &= ~x_ctrl; + } + +return ret; +} +struct vmcs *alloc_vmcs_cpu (bool shadow,int cpu,gfp_t flags) {int node =cpu_to_node (cpu);
arch/x86/kvm/vmx/vmx.h +18 -0
@@ -591,6 +591,24 @@ static inline u8 vmx_get_rvi(void)#define KVM_OPTIONAL_VMX_TERTIARY_VM_EXEC_CONTROL \ (TERTIARY_EXEC_IPI_VIRT) +struct vmcs_config_setting { +u32 cpu_based_vm_exec_ctrl_req; +u32 cpu_based_vm_exec_ctrl_opt; +u32 secondary_vm_exec_ctrl_req; +u32 secondary_vm_exec_ctrl_opt; +u64 tertiary_vm_exec_ctrl_opt; +u32 pin_based_vm_exec_ctrl_req; +u32 pin_based_vm_exec_ctrl_opt; +u32 vmexit_ctrl_req; +u32 vmexit_ctrl_opt; +u32 vmentry_ctrl_req; +u32 vmentry_ctrl_opt; +}; + +int setup_vmcs_config_common (struct vmcs_config *vmcs_conf, +struct vmx_capability *vmx_cap, +struct vmcs_config_setting *setting); +#define BUILD_CONTROLS_SHADOW (lname, uname, bits) \ static inline void lname##_controls_set(struct vcpu_vmx *vmx, u##bits val) \ { \
Signature · 1 line
2.25.1
RFC PATCH 3/17 pkvm: x86: Add vmx capability check and vmx config setup
In reply to Jason Chen CJCheck minimal vmx capabilities requirement for pKVM on Intel platform. Setup vmcs config and vmx cap for later run VCPUs of deprivileged host VM.
The vmx capabilities are checked through setup_vmcs_config_common, the same API as KVM. pKVM tries to pass-thru resource to host VM as much as possible, so it does not need to do a lot of emulations; but some capabilities are still required for pKVM's emulations (e.g. EPT, SHADOW_VMCS, MSR_BITMAP etc.), so pKVM has its own different check-set from KVM.
--- arch/x86/kvm/vmx/pkvm/Makefile | 1 + arch/x86/kvm/vmx/pkvm/include/pkvm.h | 5 +++ arch/x86/kvm/vmx/pkvm/pkvm_host.c | 66 ++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+)
arch/x86/kvm/vmx/pkvm/Makefile +1 -0
@@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 +ccflags-y += -I $(srctree)/arch/x86/kvm ccflags-y += -I $(srctree)/arch/x86/kvm/vmx/pkvm/include pkvm-obj := pkvm_host.o
arch/x86/kvm/vmx/pkvm/include/pkvm.h +5 -0
@@ -6,8 +6,13 @@#ifndef _PKVM_H_#define _PKVM_H_ +#include <vmx/vmx.h> +struct pkvm_hyp {int num_cpus; + +struct vmx_capability vmx_cap; +struct vmcs_config vmcs_config; };#define PKVM_PAGES (ALIGN(sizeof(struct pkvm_hyp), PAGE_SIZE) >> PAGE_SHIFT)
arch/x86/kvm/vmx/pkvm/pkvm_host.c +66 -0
80 lines not on this page · raw message
Signature · 1 line
2.25.1
RFC PATCH 4/17 pkvm: x86: Add pCPU env setup
In reply to Jason Chen CJIntroduce pkvm_pcpu data structure, and pKVM can support up to CONFIG_NR_CPUS pCPUs.
The pkvm_pcpu contains necessary environment fields to run a physical CPU, like stack, GDT/IDT/TSS and cr3. As pKVM is isolated from host OS, it needs its own running environment for each physical CPU.
Initialize dedicated GDT/IDT/TSS for pKVM pCPU. The GDT/TSS setting is referred from host Linux, while the IDT is configured to jump to noop_handler for all exceptions as no exception support in pKVM (NMI is another story which will be added in the future).
At this moment, the pKVM still shares MMU page table with host Linux, so setup its CR3 from host setting. In the future, pKVM shall create its own MMU page table.
The pkvm_pcpu data entry is allocated according to current cpu number system running, during the new added pcpu setup logic within pkvm_init.
--- arch/x86/kvm/vmx/pkvm/include/pkvm.h | 17 ++++++ arch/x86/kvm/vmx/pkvm/pkvm_host.c | 91 +++++++++++++++++++++++++++- 2 files changed, 107 insertions(+), 1 deletion(-)
arch/x86/kvm/vmx/pkvm/include/pkvm.h +17 -0
@@ -8,13 +8,30 @@#include <vmx/vmx.h> +#define STACK_SIZE SZ_16K + +struct idt_page { +gate_desc idt[IDT_ENTRIES ]; +}__aligned(PAGE_SIZE) ; + +struct pkvm_pcpu { +u8 stack[STACK_SIZE ]__aligned(16) ; +unsigned long cr3; +struct gdt_page gdt_page; +struct idt_page idt_page; +struct tss_struct tss; +}; +struct pkvm_hyp {int num_cpus;struct vmx_capability vmx_cap;struct vmcs_config vmcs_config; + +struct pkvm_pcpu *pcpus[CONFIG_NR_CPUS ]; };#define PKVM_PAGES (ALIGN(sizeof(struct pkvm_hyp), PAGE_SIZE) >> PAGE_SHIFT) +#define PKVM_PCPU_PAGES (ALIGN(sizeof(struct pkvm_pcpu), PAGE_SIZE) >> PAGE_SHIFT)#endif
arch/x86/kvm/vmx/pkvm/pkvm_host.c +90 -1
121 lines not on this page · raw message
Signature · 1 line
2.25.1
RFC PATCH 5/17 pkvm: x86: Add basic setup for host vcpu
In reply to Jason Chen CJIntroduce pkvm_host_vm and pkvm_host_vcpu data structure. The pKVM supports one host vm with up to CONFIG_NR_CPUS host vcpus.
The pkvm_host_vcpu is the key data entry to assist running vcpu of host VM. Struct vcpu_vmx is used as its major part to allow pKVM easily sharing code logic from KVM VMX.
The pkvm_host_vcpu data entry is allocated according to the real cpu number system running, during the new added vcpu setup logic within pkvm_init.
NOTE: the vcpu of host VM is 1:1 mapping to pCPU.
--- arch/x86/kvm/vmx/pkvm/include/pkvm.h | 12 ++++++++++++ arch/x86/kvm/vmx/pkvm/pkvm_host.c | 26 ++++++++++++++++++++++++++ 2 files changed, 38 insertions(+)
arch/x86/kvm/vmx/pkvm/include/pkvm.h +12 -0
@@ -22,6 +22,15 @@ struct pkvm_pcpu {struct tss_struct tss; }; +struct pkvm_host_vcpu { +struct vcpu_vmx vmx; +struct pkvm_pcpu *pcpu; +}; + +struct pkvm_host_vm { +struct pkvm_host_vcpu *host_vcpus[CONFIG_NR_CPUS ]; +}; +struct pkvm_hyp {int num_cpus;
@@ -29,9 +38,12 @@ struct pkvm_hyp {struct vmcs_config vmcs_config;struct pkvm_pcpu *pcpus[CONFIG_NR_CPUS ]; + + struct pkvm_host_vm host_vm; };#define PKVM_PAGES (ALIGN(sizeof(struct pkvm_hyp), PAGE_SIZE) >> PAGE_SHIFT)#define PKVM_PCPU_PAGES (ALIGN(sizeof(struct pkvm_pcpu), PAGE_SIZE) >> PAGE_SHIFT) +#define PKVM_HOST_VCPU_PAGES (ALIGN(sizeof(struct pkvm_host_vcpu), PAGE_SIZE) >> PAGE_SHIFT)#endif
arch/x86/kvm/vmx/pkvm/pkvm_host.c +26 -0
@@ -151,6 +151,25 @@ static __init int pkvm_setup_pcpu(struct pkvm_hyp *pkvm, int cpu)return 0 ; } +static __init int pkvm_host_setup_vcpu (struct pkvm_hyp *pkvm,int cpu) +{ +struct pkvm_host_vcpu *pkvm_host_vcpu; + +if (cpu >=CONFIG_NR_CPUS ) +return -ENOMEM ; + + pkvm_host_vcpu =pkvm_early_alloc_contig (PKVM_HOST_VCPU_PAGES ); +if (!pkvm_host_vcpu) +return -ENOMEM ; + + pkvm_host_vcpu->pcpu = pkvm->pcpus[cpu]; + pkvm_host_vcpu->vmx.vcpu.cpu = cpu; + + pkvm->host_vm.host_vcpus[cpu] = pkvm_host_vcpu; + +return 0 ; +} +__init int pkvm_init (void ) {int ret =0 , cpu;
@@ -169,6 +188,9 @@ __init int pkvm_init(void) ret =pkvm_setup_pcpu (pkvm, cpu);if (ret) goto out_free_cpu; + ret =pkvm_host_setup_vcpu (pkvm, cpu); +if (ret) + goto out_free_cpu; } pkvm->num_cpus =num_possible_cpus ();
@@ -177,6 +199,10 @@ __init int pkvm_init(void) out_free_cpu:for_each_possible_cpu (cpu) { +if (pkvm->host_vm.host_vcpus[cpu]) { +pkvm_early_free (pkvm->host_vm.host_vcpus[cpu],PKVM_HOST_VCPU_PAGES ); + pkvm->host_vm.host_vcpus[cpu] =NULL ; + }if (pkvm->pcpus[cpu]) {pkvm_early_free (pkvm->pcpus[cpu],PKVM_PCPU_PAGES ); pkvm->pcpus[cpu] =NULL ;
Signature · 1 line
2.25.1
RFC PATCH 6/17 pkvm: x86: Introduce pkvm_host_deprivilege_cpus
In reply to Jason Chen CJAfter platform power on, the host Linux is running at VMX root mode at beginning, and finally it needs putting into VMX non-root mode while pKVM shall keep running at VMX root mode, to ensure pKVM's capability of isolating the protected guests from host OS. The process of putting host OS from VMX root mode to non-root mode is called deprivilege.
The deprivilege is triggered by pKVM's initializing code through new introduced function - pkvm_host_deprivilege_cpus(). In this function, VMX operation environment is setup for each CPU, which includes entering VMX operation by executing VMXON instruction, initializing VMCS fields for guest state, host state & vmexit/vmentry controls, setting up vmexit handlers and finally launch & run host OS as a VM through VMX instructions VMLAUNCH/VMRESUME (VMXON is done in this patch, others will be added in the following patches).
--- arch/x86/kvm/vmx/pkvm/include/pkvm.h | 1 + arch/x86/kvm/vmx/pkvm/pkvm_host.c | 163 +++++++++++++++++++++++++++ 2 files changed, 164 insertions(+)
arch/x86/kvm/vmx/pkvm/include/pkvm.h +1 -0
@@ -25,6 +25,7 @@ struct pkvm_pcpu {struct pkvm_host_vcpu {struct vcpu_vmx vmx;struct pkvm_pcpu *pcpu; +struct vmcs *vmxarea; };struct pkvm_host_vm {
arch/x86/kvm/vmx/pkvm/pkvm_host.c +163 -0
181 lines not on this page · raw message
Signature · 1 line
2.25.1
RFC PATCH 7/17 pkvm: x86: Allocate vmcs and msr bitmap pages for host vcpu
In reply to Jason Chen CJVMCS page is key control structure to do VMX operations, and allocate it with revision id (setup by __setup_vmcs_config) for host vcpu during its VMX initialization. Later VMX ops VMPTRLD makes it as current VMCS pointer to do VMCS fields setup through VMWRITE then run host VM through VMLAUNCH.
pKVM enables "use MSR bitmaps" VM-execution control to intercept and emulate necessary MSR (e,g, VMX MSR). It needs to setup a MSR bitmaps page in VMCS field, and such page is allocated during host vcpu VMX initialization in this patch as well.
Make use of vcpu_vmx->vmcs01 to record this information for host vcpu.
--- arch/x86/kvm/vmx/pkvm/pkvm_host.c | 54 ++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-)
arch/x86/kvm/vmx/pkvm/pkvm_host.c +53 -1
@@ -39,6 +39,28 @@ static void pkvm_early_free(void *ptr, int pages)free_pages_exact (ptr, pages <<PAGE_SHIFT ); } +static struct vmcs *pkvm_alloc_vmcs (struct vmcs_config *vmcs_config_ptr) +{ +struct vmcs *vmcs; +int pages =ALIGN (vmcs_config_ptr->size,PAGE_SIZE ) >>PAGE_SHIFT ; + + vmcs =pkvm_early_alloc_contig (pages); +if (!vmcs) +return NULL ; + +memset (vmcs,0 , vmcs_config_ptr->size); + vmcs->hdr.revision_id = vmcs_config_ptr->revision_id;/* vmcs revision id */ + +return vmcs; +} + +static void pkvm_free_vmcs (void *vmcs,struct vmcs_config *vmcs_config_ptr) +{ +int pages =ALIGN (vmcs_config_ptr->size,PAGE_SIZE ) >>PAGE_SHIFT ; + +pkvm_early_free (vmcs, pages); +} +static inline void vmxon_setup_revid (void *vmxon_region) {u32 rev_id =0 ;
@@ -116,12 +138,42 @@ static __init int pkvm_enable_vmx(struct pkvm_host_vcpu *vcpu)static __init int pkvm_host_init_vmx (struct pkvm_host_vcpu *vcpu) { -return pkvm_enable_vmx (vcpu); +struct vcpu_vmx *vmx = &vcpu->vmx; +int ret; + + ret =pkvm_enable_vmx (vcpu); +if (ret) +return ret; + +/* vmcs01: host vmcs in pKVM */ + vmx->vmcs01.vmcs =pkvm_alloc_vmcs (&pkvm->vmcs_config); +if (!vmx->vmcs01.vmcs) +return -ENOMEM ; + + vmx->vmcs01.msr_bitmap =pkvm_early_alloc_contig (1 ); +if (!vmx->vmcs01.msr_bitmap) { +pr_err ("%s: No page for msr_bitmap\n" , __func__); +return -ENOMEM ; + } + +return ret; }static __init void pkvm_host_deinit_vmx (struct pkvm_host_vcpu *vcpu) { +struct vcpu_vmx *vmx = &vcpu->vmx; +pkvm_cpu_vmxoff (); + +if (vmx->vmcs01.vmcs) { +pkvm_free_vmcs (vmx->vmcs01.vmcs, &pkvm->vmcs_config); + vmx->vmcs01.vmcs =NULL ; + } + +if (vmx->vmcs01.msr_bitmap) { +pkvm_early_free (vmx->vmcs01.msr_bitmap,1 ); + vmx->vmcs01.msr_bitmap =NULL ; + } }static __init int pkvm_host_check_and_setup_vmx_cap (struct pkvm_hyp *pkvm)
Signature · 1 line
2.25.1
RFC PATCH 8/17 pkvm: x86: Initailize vmcs guest state area for host vcpu
In reply to Jason Chen CJAfter deprivilege, host OS shall continue running with the state at that point, therefore the CPU just deprivileges its context from VMX root mode to non-root mode. The VMCS guest state of host vcpu is just current state of physical CPU, so directly initialize the state from native.
--- arch/x86/kvm/vmx/pkvm/pkvm_host.c | 114 +++++++++++++++++++++++++++++- 1 file changed, 112 insertions(+), 2 deletions(-)
arch/x86/kvm/vmx/pkvm/pkvm_host.c +112 -2
@@ -136,7 +136,112 @@ static __init int pkvm_enable_vmx(struct pkvm_host_vcpu *vcpu)return pkvm_cpu_vmxon (phys_addr); } -static __init int pkvm_host_init_vmx (struct pkvm_host_vcpu *vcpu) +static inline u32 get_ar (u16 sel) +{ +u32 access_rights; + +if (sel ==0 ) { + access_rights =0x10000 ; + }else { + asm ("lar %%ax, %%rax\n" + :"=a" (access_rights) :"a" (sel)); + access_rights = access_rights >>8 ; + access_rights = access_rights &0xf0ff ; + } + +return access_rights; +} + +#define init_guestsegment (seg,SEG , base, limit) \ + do { \ + u16 sel; \ + u32 ar; \ + \ + savesegment(seg, sel); \ + ar = get_ar(sel); \ + vmcs_write16(GUEST_##SEG##_SELECTOR, sel); \ + vmcs_write32(GUEST_##SEG##_AR_BYTES, ar); \ + vmcs_writel(GUEST_##SEG##_BASE, base); \ + vmcs_write32(GUEST_##SEG##_LIMIT, limit); \ + } while (0) + +static __init void init_guest_state_area_from_native (int cpu) +{ +u16 ldtr; +struct desc_ptr dt; +unsigned long msrl; +u32 high, low; + +/* load CR regiesters */ +vmcs_writel (GUEST_CR0 ,read_cr0 () & ~X86_CR0_TS ); +vmcs_writel (GUEST_CR3 ,__read_cr3 ()); +vmcs_writel (GUEST_CR4 ,native_read_cr4 ()); + +/* load cs/ss/ds/es */ +init_guestsegment (cs,CS ,0x0 ,0xffffffff ); +init_guestsegment (ss,SS ,0x0 ,0xffffffff ); +init_guestsegment (ds,DS ,0x0 ,0xffffffff ); +init_guestsegment (es,ES ,0x0 ,0xffffffff ); + +/* load fs/gs */ +rdmsrl (MSR_FS_BASE , msrl); +init_guestsegment (fs,FS , msrl,0xffffffff ); +rdmsrl (MSR_GS_BASE , msrl); +init_guestsegment (gs,GS , msrl,0xffffffff ); + +/* load GDTR */ +native_store_gdt (&dt); +vmcs_writel (GUEST_GDTR_BASE , dt.address); +vmcs_write32 (GUEST_GDTR_LIMIT , dt.size); + +/* load TR */ +vmcs_write16 (GUEST_TR_SELECTOR ,GDT_ENTRY_TSS *8 ); +vmcs_write32 (GUEST_TR_AR_BYTES ,get_ar (GDT_ENTRY_TSS *8 )); +vmcs_writel (GUEST_TR_BASE , (unsigned long )&get_cpu_entry_area (cpu)->tss.x86_tss); +vmcs_write32 (GUEST_TR_LIMIT , __KERNEL_TSS_LIMIT); + +/* load LDTR */ +store_ldt (ldtr); +vmcs_write16 (GUEST_LDTR_SELECTOR , ldtr); +vmcs_write32 (GUEST_LDTR_AR_BYTES ,0x10000 ); +vmcs_writel (GUEST_LDTR_BASE ,0x0 ); +vmcs_write32 (GUEST_LDTR_LIMIT ,0xffffffff ); + +store_idt (&dt); +vmcs_writel (GUEST_IDTR_BASE , dt.address); +vmcs_write32 (GUEST_IDTR_LIMIT , dt.size); + +/* set MSRs */ +vmcs_write64 (GUEST_IA32_DEBUGCTL ,0 ); + +rdmsr (MSR_IA32_SYSENTER_CS , low, high); +vmcs_write32 (GUEST_SYSENTER_CS , low); + +rdmsrl (MSR_IA32_SYSENTER_ESP , msrl); +vmcs_writel (GUEST_SYSENTER_ESP , msrl); + +rdmsrl (MSR_IA32_SYSENTER_EIP , msrl); +vmcs_writel (GUEST_SYSENTER_EIP , msrl); + +rdmsrl (MSR_EFER , msrl); +vmcs_write64 (GUEST_IA32_EFER , msrl); + +rdmsrl (MSR_IA32_CR_PAT , msrl); +vmcs_write64 (GUEST_IA32_PAT , msrl); +} + +static __init void init_guest_state_area (struct pkvm_host_vcpu *vcpu,int cpu) +{ +init_guest_state_area_from_native (cpu); + +/*Guest non register state*/ +vmcs_write32 (GUEST_ACTIVITY_STATE ,GUEST_ACTIVITY_ACTIVE ); +vmcs_write32 (GUEST_INTERRUPTIBILITY_INFO ,0 ); +vmcs_writel (GUEST_PENDING_DBG_EXCEPTIONS ,0 ); +vmcs_write64 (VMCS_LINK_POINTER ,-1ull ); +} + +static __init int pkvm_host_init_vmx (struct pkvm_host_vcpu *vcpu,int cpu) {struct vcpu_vmx *vmx = &vcpu->vmx;int ret;
@@ -156,6 +261,11 @@ static __init int pkvm_host_init_vmx(struct pkvm_host_vcpu *vcpu)return -ENOMEM ; } + vmx->loaded_vmcs = &vmx->vmcs01; +vmcs_load (vmx->loaded_vmcs->vmcs); + +init_guest_state_area (vcpu, cpu); +return ret; }
@@ -339,7 +449,7 @@ static __init void pkvm_host_deprivilege_cpu(void *data)enable_feature_control (); - ret =pkvm_host_init_vmx (vcpu); + ret =pkvm_host_init_vmx (vcpu, cpu);if (ret) {pr_err ("%s: init vmx failed\n" , __func__); goto out;
Signature · 1 line
2.25.1
RFC PATCH 9/17 pkvm: x86: Initialize vmcs host state area for host vcpu
In reply to Jason Chen CJThe VMCS host state shall keep the pKVM running state before switch to guest (host VM for now). Most of such states are setup by pKVM init code and can get from predefined value (e.g. CS/SS etc.) or pkvm_pcpu data structure (e.g. GDT/IDT/TSS & cr3), a few states are initialized directly from host native as they can just follow host Linux setting (e.g. EFER, PAT, CR0).
--- arch/x86/kvm/vmx/pkvm/pkvm_host.c | 40 +++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)
arch/x86/kvm/vmx/pkvm/pkvm_host.c +40 -0
@@ -241,6 +241,45 @@ static __init void init_guest_state_area(struct pkvm_host_vcpu *vcpu, int cpu)vmcs_write64 (VMCS_LINK_POINTER ,-1ull ); } +static __init void _init_host_state_area (struct pkvm_pcpu *pcpu) +{ +unsigned long a; + +vmcs_writel (HOST_CR0 ,read_cr0 () & ~X86_CR0_TS ); +vmcs_writel (HOST_CR3 , pcpu->cr3); +vmcs_writel (HOST_CR4 ,native_read_cr4 ()); + +vmcs_write16 (HOST_CS_SELECTOR , __KERNEL_CS); +vmcs_write16 (HOST_SS_SELECTOR , __KERNEL_DS); +vmcs_write16 (HOST_DS_SELECTOR , __KERNEL_DS); +vmcs_write16 (HOST_ES_SELECTOR ,0 ); +vmcs_write16 (HOST_TR_SELECTOR ,GDT_ENTRY_TSS *8 ); +vmcs_write16 (HOST_FS_SELECTOR ,0 ); +vmcs_write16 (HOST_GS_SELECTOR ,0 ); +vmcs_writel (HOST_FS_BASE ,0 ); +vmcs_writel (HOST_GS_BASE ,0 ); + +vmcs_writel (HOST_TR_BASE , (unsigned long )&pcpu->tss); +vmcs_writel (HOST_GDTR_BASE , (unsigned long )(&pcpu->gdt_page)); +vmcs_writel (HOST_IDTR_BASE , (unsigned long )(&pcpu->idt_page)); + +/* MSR area */ +rdmsrl (MSR_EFER , a); +vmcs_write64 (HOST_IA32_EFER , a); + +rdmsrl (MSR_IA32_CR_PAT , a); +vmcs_write64 (HOST_IA32_PAT , a); +} + +static __init void init_host_state_area (struct pkvm_host_vcpu *vcpu) +{ +struct pkvm_pcpu *pcpu = vcpu->pcpu; + +_init_host_state_area (pcpu); + +/*TODO: add HOST_RIP */ +} +static __init int pkvm_host_init_vmx (struct pkvm_host_vcpu *vcpu,int cpu) {struct vcpu_vmx *vmx = &vcpu->vmx;
@@ -265,6 +304,7 @@ static __init int pkvm_host_init_vmx(struct pkvm_host_vcpu *vcpu, int cpu)vmcs_load (vmx->loaded_vmcs->vmcs);init_guest_state_area (vcpu, cpu); +init_host_state_area (vcpu);return ret; }
Signature · 1 line
2.25.1
RFC PATCH 10/17 pkvm: x86: Initialize vmcs control fields for host vcpu
In reply to Jason Chen CJDo vmx execution/vmexit/vmetry control fields initialization based on vmcs_config (setup by __setup_vmcs_config) for host vcpu.
CPU_BASED_CR3_LOAD_EXITING & CPU_BASED_CR3_STORE_EXITING are always set from __setup_vmcs_config but pKVM does not want them, so clear them from cpu_based_exec_ctrl.
CPU_BASED_INTR_WINDOW_EXITING is toggled dynamically (for later nmi handling), so clear it first from cpu_based_exec_ctrl.
SECONDARY_EXEC_ENABLE_EPT & SECONDARY_EXEC_ENABLE_VPID in cpu_based_2nd_exec_ctrl are disabled before EPT page table created for host VM in pKVM.
The control field configuration in this patch also makes host VM handle its interrupt & exception directly, and fully own CR0 & CR3, for CR4, only VMXE bit is intercepted by pKVM, and the MSR intercept setting need updating to pre-allocated msr_bitmap.
--- arch/x86/kvm/vmx/pkvm/pkvm_host.c | 60 +++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+)
arch/x86/kvm/vmx/pkvm/pkvm_host.c +60 -0
@@ -280,6 +280,63 @@ static __init void init_host_state_area(struct pkvm_host_vcpu *vcpu)/*TODO: add HOST_RIP */ } +static __init void init_execution_control (struct vcpu_vmx *vmx, +struct vmcs_config *vmcs_config_ptr, +struct vmx_capability *vmx_cap) +{ +u32 cpu_based_exec_ctrl = vmcs_config_ptr->cpu_based_exec_ctrl; +u32 cpu_based_2nd_exec_ctrl = vmcs_config_ptr->cpu_based_2nd_exec_ctrl; + +pin_controls_set (vmx, vmcs_config_ptr->pin_based_exec_ctrl); + +/* +* CR3 LOAD/STORE EXITING are not used by pkvm +* INTR/NMI WINDOW EXITING are toggled dynamically +*/ + cpu_based_exec_ctrl &= ~(CPU_BASED_CR3_LOAD_EXITING | +CPU_BASED_CR3_STORE_EXITING | +CPU_BASED_INTR_WINDOW_EXITING | +CPU_BASED_NMI_WINDOW_EXITING ); +exec_controls_set (vmx, cpu_based_exec_ctrl); + +/* disable EPT/VPID first, enable after EPT pgtable created */ + cpu_based_2nd_exec_ctrl &= ~(SECONDARY_EXEC_ENABLE_EPT | +SECONDARY_EXEC_ENABLE_VPID ); +secondary_exec_controls_set (vmx, cpu_based_2nd_exec_ctrl); + +/* guest owns cr3 */ +vmcs_write32 (CR3_TARGET_COUNT ,0 ); + +/* guest handles exception directly */ +vmcs_write32 (EXCEPTION_BITMAP ,0 ); + +vmcs_write64 (MSR_BITMAP ,__pa (vmx->vmcs01.msr_bitmap)); + +/* +* guest owns cr0, and owns cr4 except VMXE bit. +* does not care about IA32_VMX_CRx_FIXED0/1 setting, so if guest modify +* cr0/cr4 conflicting with FIXED0/1, just let #GP happen. +* For example, as pKVM does not enable unrestricted guest, cr0.PE/PG +* must keep as 1 in guest. +*/ +vmcs_writel (CR0_GUEST_HOST_MASK ,0 ); +vmcs_writel (CR4_GUEST_HOST_MASK ,X86_CR4_VMXE ); +} + +static __init void init_vmexit_control (struct vcpu_vmx *vmx,struct vmcs_config *vmcs_config_ptr) +{ +vm_exit_controls_set (vmx, vmcs_config_ptr->vmexit_ctrl); +vmcs_write32 (VM_EXIT_MSR_STORE_COUNT ,0 ); +} + +static __init void init_vmentry_control (struct vcpu_vmx *vmx,struct vmcs_config *vmcs_config_ptr) +{ +vm_entry_controls_set (vmx, vmcs_config_ptr->vmentry_ctrl); +vmcs_write32 (VM_ENTRY_INTR_INFO_FIELD ,0 ); +vmcs_write32 (VM_ENTRY_MSR_LOAD_COUNT ,0 ); +vmcs_write32 (VM_ENTRY_INTR_INFO_FIELD ,0 ); +} +static __init int pkvm_host_init_vmx (struct pkvm_host_vcpu *vcpu,int cpu) {struct vcpu_vmx *vmx = &vcpu->vmx;
@@ -305,6 +362,9 @@ static __init int pkvm_host_init_vmx(struct pkvm_host_vcpu *vcpu, int cpu)init_guest_state_area (vcpu, cpu);init_host_state_area (vcpu); +init_execution_control (vmx, &pkvm->vmcs_config, &pkvm->vmx_cap); +init_vmexit_control (vmx, &pkvm->vmcs_config); +init_vmentry_control (vmx, &pkvm->vmcs_config);return ret; }
Signature · 1 line
2.25.1
RFC PATCH 11/17 pkvm: x86: Define empty debug functions for hypervisor
In reply to Jason Chen CJUse pkvm_dbg/pkvm_info/pkvm_err as debug functions for pKVM runtime.
Define all these debug functions as empty functions now, it's also the configuration of final release, as no additional debug console support in pKVM now and such runtime debug functions shall avoid to access host kernel debug APIs (e.g. printk) for isolation purpose.
Future will enable a debug mode for pKVM by taking use of linux printk with some extra addon to access host kernel code - it's a tmp quick debug method as it does not follow above rules for isolation.
--- arch/x86/kvm/vmx/pkvm/hyp/debug.h | 13 +++++++++++++ 1 file changed, 13 insertions(+)
arch/x86/kvm/vmx/pkvm/hyp/debug.h new file +13 -0
@@ -0,0 +1,13 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2022 Intel Corporation +*/ + +#ifndef _PKVM_DEBUG_H_ +#define _PKVM_DEBUG_H_ + +#define pkvm_dbg(x...) +#define pkvm_info(x...) +#define pkvm_err(x...) + +#endif
Signature · 1 line
2.25.1
RFC PATCH 12/17 pkvm: x86: Add vmexit handler for host vcpu
In reply to Jason Chen CJpKVM need to handle vmexit from host OS after it deprivilege to a VM.
Some instructions cause vmexit unconditionally, like CPUID, XSETBV, for such vmexit handlers, pKVM just do what host VM want.
Although now msr_bitmap is cleared, there is still possibility host Linux accessing unsupported MSR (e.g. MSR from AMD platform) which will cause vmexit, pKVM just simply ignore such msr writing and return 0 on such msr reading.
For MOV to CR vmexit, pKVM only take care CR4.VMXE, it allows host VM change VMXE bit by directly write host value to CR4_READ_SHADOW.
Define a pkvm_main function which do the loop handling of vmexit_handlers based on above different vmexit reason, and __pkvm_vmx_vcpu_run at the tail of loop to trigger VMLAUNCH/VMRESUME.
New pKVM on Intel platform files to support hypervisor runtime are placed under arch/x86/kvm/vmx/pkvm/hyp.
--- arch/x86/kvm/vmx/pkvm/Makefile | 1 + arch/x86/kvm/vmx/pkvm/hyp/Makefile | 8 ++ arch/x86/kvm/vmx/pkvm/hyp/vmexit.c | 154 ++++++++++++++++++++++ arch/x86/kvm/vmx/pkvm/hyp/vmexit.h | 11 ++ arch/x86/kvm/vmx/pkvm/hyp/vmx_asm.S | 186 +++++++++++++++++++++++++++ arch/x86/kvm/vmx/pkvm/include/pkvm.h | 2 + arch/x86/kvm/vmx/pkvm/pkvm_host.c | 3 +- 7 files changed, 364 insertions(+), 1 deletion(-)
arch/x86/kvm/vmx/pkvm/Makefile +1 -0
@@ -6,3 +6,4 @@ ccflags-y += -I $(srctree)/arch/x86/kvm/vmx/pkvm/include pkvm-obj := pkvm_host.o obj-$(CONFIG_PKVM_INTEL) += $(pkvm-obj) +obj-$(CONFIG_PKVM_INTEL) += hyp/
arch/x86/kvm/vmx/pkvm/hyp/Makefile new file +8 -0
@@ -0,0 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0 + +ccflags-y += -I $(srctree)/arch/x86/kvm +ccflags-y += -I $(srctree)/arch/x86/kvm/vmx/pkvm/include + +pkvm-hyp-y := vmx_asm.o vmexit.o + +obj-$(CONFIG_PKVM_INTEL) += $(pkvm-hyp-y)
arch/x86/kvm/vmx/pkvm/hyp/vmexit.c new file +154 -0
154 lines not on this page · raw message
arch/x86/kvm/vmx/pkvm/hyp/vmexit.h new file +11 -0
@@ -0,0 +1,11 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2022 Intel Corporation +*/ + +#ifndef _PKVM_VMEXIT_H_ +#define _PKVM_VMEXIT_H_ + +int __pkvm_vmx_vcpu_run (unsigned long *regs,int launch); + +#endif
arch/x86/kvm/vmx/pkvm/hyp/vmx_asm.S new file +186 -0
186 lines not on this page · raw message
arch/x86/kvm/vmx/pkvm/include/pkvm.h +2 -0
@@ -47,4 +47,6 @@ struct pkvm_hyp {#define PKVM_PCPU_PAGES (ALIGN(sizeof(struct pkvm_pcpu), PAGE_SIZE) >> PAGE_SHIFT)#define PKVM_HOST_VCPU_PAGES (ALIGN(sizeof(struct pkvm_host_vcpu), PAGE_SIZE) >> PAGE_SHIFT) +void __pkvm_vmx_vmexit (void ); +#endif
arch/x86/kvm/vmx/pkvm/pkvm_host.c +2 -1
@@ -277,7 +277,8 @@ static __init void init_host_state_area(struct pkvm_host_vcpu *vcpu)_init_host_state_area (pcpu); -/*TODO: add HOST_RIP */ +/*host RIP*/ +vmcs_writel (HOST_RIP , (unsigned long )__pkvm_vmx_vmexit); } static __init void init_execution_control(struct vcpu_vmx *vmx,
Signature · 1 line
2.25.1
RFC PATCH 13/17 pkvm: x86: Add private vmx_ops.h for pKVM
In reply to Jason Chen CJpKVM runtime need running as an independent binary, and be isolated from host OS. Such runtime routines include operations for VMX, which KVM defined in vmx/vmx_ops.h. pKVM cannot directly reuse from this file as it contains ASM_EXTABLE and static_branch which pKVM does not support. The simplest way is to create pKVM its own functions without supporting such features.
Add pKVM its own VMX ops APIs in pkvm/hyp/vmx_ops.h, and ensure this new added vmx_ops.h is used for pKVM runtime - __PKVM_HYP__ is defined to indicate the compiled code is running under pKVM runtime.
--- arch/x86/kvm/vmx/pkvm/hyp/Makefile | 1 + arch/x86/kvm/vmx/pkvm/hyp/vmx_ops.h | 185 ++++++++++++++++++++++++++++ arch/x86/kvm/vmx/vmx_ops.h | 7 ++ 3 files changed, 193 insertions(+)
arch/x86/kvm/vmx/pkvm/hyp/Makefile +1 -0
@@ -2,6 +2,7 @@ ccflags-y += -I $(srctree)/arch/x86/kvm ccflags-y += -I $(srctree)/arch/x86/kvm/vmx/pkvm/include +ccflags-y += -D__PKVM_HYP__ pkvm-hyp-y := vmx_asm.o vmexit.o
arch/x86/kvm/vmx/pkvm/hyp/vmx_ops.h new file +185 -0
185 lines not on this page · raw message
arch/x86/kvm/vmx/vmx_ops.h +7 -0
@@ -81,6 +81,12 @@ static __always_inline void vmcs_checkl(unsigned long field) "Natural width accessor invalid for 32-bit field"); } +#ifdef __PKVM_HYP__ + +#include "pkvm/hyp/vmx_ops.h" + +#else +static __always_inline unsigned long __vmcs_readl (unsigned long field) {unsigned long value;
@@ -292,6 +298,7 @@ static inline void vmcs_load(struct vmcs *vmcs) vmx_asm1(vmptrld, "m"(phys_addr), vmcs, phys_addr); } +#endif /*__PKVM_HYP__*/ static inline void __invvpid (unsigned long ext,u16 vpid,gva_t gva) {
Signature · 1 line
2.25.1
RFC PATCH 14/17 pkvm: x86: Add pKVM retpoline.S
In reply to Jason Chen CJpKVM need to compile in its own indirect thunk to avoid linking to host Linux symbols - not reusing arch/x86/lib/retpoline.S is because its implementation is based on "ALTERNATIVE" which leads to adding code in __alt_instructions section - pKVM now does not support it.
TODO: support ALTERNATIVE for pKVM, make it be able to reuse arch/x86/lib/retpoline.S and able to fixup based on HW feature during runtime.
--- arch/x86/kvm/vmx/pkvm/hyp/lib/retpoline.S | 113 ++++++++++++++++++++++ 1 file changed, 113 insertions(+)
arch/x86/kvm/vmx/pkvm/hyp/lib/retpoline.S new file +113 -0
@@ -0,0 +1,113 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#include <linux/linkage.h> +#include <asm/dwarf2.h> +#include <asm/nospec-branch.h> +#include <asm/unwind_hints.h> +#include <asm/frame.h> + + .section .text.__x86.indirect_thunk + +.macro RETPOLINE reg + ANNOTATE_INTRA_FUNCTION_CALL + call .Ldo_rop_\@ +.Lspec_trap_\@: + UNWIND_HINT_EMPTY + pause + lfence + jmp .Lspec_trap_\@ +.Ldo_rop_\@: + mov %\reg, (%_ASM_SP) + UNWIND_HINT_FUNC + RET +.endm + +.macro THUNK reg + + .align RETPOLINE_THUNK_SIZE +SYM_INNER_LABEL(__x86_indirect_thunk_\reg, SYM_L_GLOBAL) + UNWIND_HINT_EMPTY + + RETPOLINE \reg + +.endm + + .align RETPOLINE_THUNK_SIZE +SYM_CODE_START(__x86_indirect_thunk_array) + +#define GEN(reg) THUNK reg +#include <asm/GEN-for-each-reg.h> +#undef GEN + + .align RETPOLINE_THUNK_SIZE +SYM_CODE_END(__x86_indirect_thunk_array) + +/* + * This function name is magical and is used by -mfunction-return=thunk-extern + * for the compiler to generate JMPs to it. + */ +#ifdef CONFIG_RETHUNK + + .section .text.__x86.return_thunk + +/* + * Safety details here pertain to the AMD Zen{1,2} microarchitecture: + * 1) The RET at __x86_return_thunk must be on a 64 byte boundary, for + * alignment within the BTB. + * 2) The instruction at zen_untrain_ret must contain, and not + * end with, the 0xc3 byte of the RET. + * 3) STIBP must be enabled, or SMT disabled, to prevent the sibling thread + * from re-poisioning the BTB prediction. + */ + .align 64 + .skip 63, 0xcc +SYM_FUNC_START_NOALIGN(zen_untrain_ret); + + /* + * As executed from zen_untrain_ret, this is: + * + * TEST $0xcc, %bl + * LFENCE + * JMP __x86_return_thunk + * + * Executing the TEST instruction has a side effect of evicting any BTB + * prediction (potentially attacker controlled) attached to the RET, as + * __x86_return_thunk + 1 isn't an instruction boundary at the moment. + */ + .byte 0xf6 + + /* + * As executed from __x86_return_thunk, this is a plain RET. + * + * As part of the TEST above, RET is the ModRM byte, and INT3 the imm8. + * + * We subsequently jump backwards and architecturally execute the RET. + * This creates a correct BTB prediction (type=ret), but in the + * meantime we suffer Straight Line Speculation (because the type was + * no branch) which is halted by the INT3. + * + * With SMT enabled and STIBP active, a sibling thread cannot poison + * RET's prediction to a type of its choice, but can evict the + * prediction due to competitive sharing. If the prediction is + * evicted, __x86_return_thunk will suffer Straight Line Speculation + * which will be contained safely by the INT3. + */ +SYM_INNER_LABEL(__x86_return_thunk, SYM_L_GLOBAL) + ret + int3 +SYM_CODE_END(__x86_return_thunk) + + /* + * Ensure the TEST decoding / BTB invalidation is complete. + */ + lfence + + /* + * Jump back and execute the RET in the middle of the TEST instruction. + * INT3 is for SLS protection. + */ + jmp __x86_return_thunk + int3 +SYM_FUNC_END(zen_untrain_ret) + +#endif /* CONFIG_RETHUNK */
Signature · 1 line
2.25.1
RFC PATCH 15/17 pkvm: x86: Build pKVM runtime as an independent binary
In reply to Jason Chen CJpKVM runtime is running under VMX root mode, need isolating from host Linux, so it shall be built as an independent binary.
Add pKVM link script to build an independent binary with separated sections, and add prefix __pkvm for all its symbols to ensure host Linux will not touch it and meantime ensure pKVM will not touch host Linux symbols as well. For special case that Linux need to call into pKVM's functions during init time, provide macros PKVM_DECLARE & pkvm_sym to intently add __pkvm prefix.
To simplify, remove ftrace, Shadow Call Stack, CFI CFLAGS, and disable stack protector. pKVM shall not export any symbols, so disable 'EXPORT_SYMBOL'.
--- arch/x86/include/asm/pkvm_image.h | 42 ++++++++++++++++++++++++++++ arch/x86/kernel/vmlinux.lds.S | 32 +++++++++++++++++++++ arch/x86/kvm/vmx/pkvm/.gitignore | 1 + arch/x86/kvm/vmx/pkvm/hyp/Makefile | 32 ++++++++++++++++++++- arch/x86/kvm/vmx/pkvm/hyp/pkvm.lds.S | 10 +++++++ arch/x86/kvm/vmx/pkvm/include/pkvm.h | 3 +- arch/x86/kvm/vmx/pkvm/pkvm_host.c | 2 +- include/asm-generic/vmlinux.lds.h | 17 +++++++++++ 8 files changed, 136 insertions(+), 3 deletions(-)
arch/x86/include/asm/pkvm_image.h new file +42 -0
@@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: GPL-2.0 +* Copyright (C) 2022 Intel Corporation +*/ + +#ifndef __X86_INTEL_PKVM_IMAGE_H +#define __X86_INTEL_PKVM_IMAGE_H + +#ifdef __PKVM_HYP__ +/* No prefix will be added */ +#define PKVM_DECLARE (type, f) type f +#define pkvm_sym (sym) sym +#else +/* prefix is added by Makefile */ +#define PKVM_DECLARE (type, f) type __pkvm_##f +#define pkvm_sym (sym) __pkvm_##sym +#endif + +#define __PKVM_CONCAT (a, b) a ## b +#define PKVM_CONCAT (a, b) __PKVM_CONCAT(a, b) + +#ifdef LINKER_SCRIPT + +#define PKVM_SECTION_NAME (NAME ) .pkvm##NAME + +#define PKVM_SECTION_SYMBOL_NAME (NAME ) \ + PKVM_CONCAT(__pkvm_section_, PKVM_SECTION_NAME(NAME)) + +#define BEGIN_PKVM_SECTION (NAME ) \ + PKVM_SECTION_NAME(NAME) : { \ + PKVM_SECTION_SYMBOL_NAME(NAME) = .; + +#define END_PKVM_SECTION \ + } + +#define PKVM_SECTION (NAME ) \ + BEGIN_PKVM_SECTION(NAME) \ + *(NAME NAME##.*) \ + END_PKVM_SECTION + +#endif /* LINKER_SCRIPT */ + +#endif /* __X86_INTEL_PKVM_IMAGE_H */
arch/x86/kernel/vmlinux.lds.S +32 -0
@@ -111,6 +111,35 @@ PHDRS { note PT_NOTE FLAGS(0); /* ___ */ } +#ifdef CONFIG_PKVM_INTEL +#include <asm/pkvm_image.h> + +#define PKVM_TEXT \ + . = ALIGN(PAGE_SIZE); \ + __pkvm_text_start = .; \ + *(PKVM_SECTION_NAME(.text)) \ + . = ALIGN(PAGE_SIZE); \ + __pkvm_text_end = .; + +#define PKVM_BSS \ + . = ALIGN(PAGE_SIZE); \ + __pkvm_bss_start = .; \ + *(PKVM_SECTION_NAME(.bss)) \ + . = ALIGN(PAGE_SIZE); \ + __pkvm_bss_end = .; + +#define PKVM_DATA \ + . = ALIGN(PAGE_SIZE); \ + __pkvm_data_start = .; \ + *(PKVM_SECTION_NAME(.data)) \ + . = ALIGN(PAGE_SIZE); \ + __pkvm_data_end = .; +#else +#define PKVM_TEXT +#define PKVM_BSS +#define PKVM_DATA +#endif + SECTIONS { #ifdef CONFIG_X86_32
@@ -143,6 +172,7 @@ SECTIONS ALIGN_ENTRY_TEXT_BEGIN ENTRY_TEXT ALIGN_ENTRY_TEXT_END + PKVM_TEXT *(.gnu.warning) } :text =0xcccc
@@ -167,6 +197,7 @@ SECTIONS /* 32 bit has nosave before _edata */ NOSAVE_DATA #endif + PKVM_DATA PAGE_ALIGNED_DATA(PAGE_SIZE)
@@ -396,6 +427,7 @@ SECTIONS . = ALIGN(PAGE_SIZE); *(BSS_MAIN) BSS_DECRYPTED + PKVM_BSS . = ALIGN(PAGE_SIZE); __bss_stop = .; }
arch/x86/kvm/vmx/pkvm/.gitignore new file +1 -0
@@ -0,0 +1 @@ +pkvm.lds
arch/x86/kvm/vmx/pkvm/hyp/Makefile +31 -1
@@ -2,8 +2,38 @@ ccflags-y += -I $(srctree)/arch/x86/kvm ccflags-y += -I $(srctree)/arch/x86/kvm/vmx/pkvm/include +ccflags-y += -fno-stack-protector +ccflags-y += -D__DISABLE_EXPORTS ccflags-y += -D__PKVM_HYP__ +lib-dir := lib + pkvm-hyp-y := vmx_asm.o vmexit.o -obj-$(CONFIG_PKVM_INTEL) += $(pkvm-hyp-y) +pkvm-hyp-$(CONFIG_RETPOLINE) += $(lib-dir)/retpoline.o + +pkvm-obj := $(patsubst %.o,%.pkvm.o,$(pkvm-hyp-y)) +obj-$(CONFIG_PKVM_INTEL) += pkvm.o +targets += $(pkvm-obj) pkvm.tmp.o pkvm.lds + +$(obj)/%.pkvm.o: $(src)/%.c FORCE + $(call if_changed_rule,cc_o_c) +$(obj)/%.pkvm.o: $(src)/%.S FORCE + $(call if_changed_rule,as_o_S) + +$(obj)/pkvm.lds: $(src)/pkvm.lds.S FORCE + $(call if_changed_dep,cpp_lds_S) + +LDFLAGS_pkvm.tmp.o := -r -T +$(obj)/pkvm.tmp.o: $(obj)/pkvm.lds $(addprefix $(obj)/,$(pkvm-obj)) FORCE + $(call if_changed,ld) + +$(obj)/pkvm.o: $(obj)/pkvm.tmp.o FORCE + $(call if_changed,pkvmcopy) + +quiet_cmd_pkvmcopy = PKVMPCOPY $@ + cmd_pkvmcopy = $(OBJCOPY) --prefix-symbols=__pkvm_ --remove-section=.retpoline_sites --remove-section=.return_sites $< $@ + +# Remove ftrace, Shadow Call Stack, and CFI CFLAGS. +# This is equivalent to the 'notrace', '__noscs', and '__nocfi' annotations. +KBUILD_CFLAGS := $(filter-out $(CC_FLAGS_FTRACE) $(CC_FLAGS_SCS) $(CC_FLAGS_CFI), $(KBUILD_CFLAGS))
arch/x86/kvm/vmx/pkvm/hyp/pkvm.lds.S new file +10 -0
@@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#include <asm/pkvm_image.h> + +SECTIONS { + PKVM_SECTION(.text) + PKVM_SECTION(.rodata) + PKVM_SECTION(.data) + PKVM_SECTION(.bss) +}
arch/x86/kvm/vmx/pkvm/include/pkvm.h +2 -1
@@ -6,6 +6,7 @@#ifndef _PKVM_H_#define _PKVM_H_ +#include <asm/pkvm_image.h> #include <vmx/vmx.h> #define STACK_SIZE SZ_16K
@@ -47,6 +48,6 @@ struct pkvm_hyp {#define PKVM_PCPU_PAGES (ALIGN(sizeof(struct pkvm_pcpu), PAGE_SIZE) >> PAGE_SHIFT)#define PKVM_HOST_VCPU_PAGES (ALIGN(sizeof(struct pkvm_host_vcpu), PAGE_SIZE) >> PAGE_SHIFT) -void __pkvm_vmx_vmexit (void ); +PKVM_DECLARE (void,__pkvm_vmx_vmexit (void));#endif
arch/x86/kvm/vmx/pkvm/pkvm_host.c +1 -1
@@ -278,7 +278,7 @@ static __init void init_host_state_area(struct pkvm_host_vcpu *vcpu)_init_host_state_area (pcpu);/*host RIP*/ -vmcs_writel (HOST_RIP , (unsigned long )__pkvm_vmx_vmexit); +vmcs_writel (HOST_RIP , (unsigned long )pkvm_sym (__pkvm_vmx_vmexit)); } static __init void init_execution_control(struct vcpu_vmx *vmx,
include/asm-generic/vmlinux.lds.h +17 -0
@@ -441,6 +441,22 @@ __end_ro_after_init = .;#endif +#ifdef CONFIG_PKVM_INTEL +#include <asm/pkvm_image.h> +#define PKVM_RODATA \ + PKVM_SECTION_NAME(.rodata) : \ + AT(ADDR(PKVM_SECTION_NAME(.rodata)) - LOAD_OFFSET) { \ + . = ALIGN(PAGE_SIZE); \ + __pkvm_rodata_start = .; \ + *(PKVM_SECTION_NAME(.rodata)) \ + *(PKVM_SECTION_NAME(.data..ro_after_init)) \ + . = ALIGN(PAGE_SIZE); \ + __pkvm_rodata_end = .; \ + } +#else +#define PKVM_RODATA +#endif +/* * .kcfi_traps contains a list KCFI trap locations. */
@@ -543,6 +559,7 @@ \KCFI_TRAPS \ \ + PKVM_RODATA \RO_EXCEPTION_TABLE \NOTES \ BTF \
Signature · 1 line
2.25.1
RFC PATCH 16/17 pkvm: x86: Deprivilege host OS
In reply to Jason Chen CJFinally make CPUs running in host OS deprivieged to VMX non-root mode.
Add function pkvm_host_run_vcpu() to prepare host vcpu context and finally run into pkvm_main by entering the loop of vmenter to host VM and vmexit handling in pKVM.
Call pkvm_host_deprivilege_cpus() in pkvm_init to make the deprivilege take effect.
--- arch/x86/kvm/vmx/pkvm/include/pkvm.h | 1 + arch/x86/kvm/vmx/pkvm/pkvm_host.c | 91 +++++++++++++++++++++++++++- 2 files changed, 90 insertions(+), 2 deletions(-)
arch/x86/kvm/vmx/pkvm/include/pkvm.h +1 -0
@@ -49,5 +49,6 @@ struct pkvm_hyp {#define PKVM_HOST_VCPU_PAGES (ALIGN(sizeof(struct pkvm_host_vcpu), PAGE_SIZE) >> PAGE_SHIFT)PKVM_DECLARE (void,__pkvm_vmx_vmexit (void)); +PKVM_DECLARE(int, pkvm_main(struct kvm_vcpu *vcpu));#endif
arch/x86/kvm/vmx/pkvm/pkvm_host.c +89 -2
114 lines not on this page · raw message
Signature · 1 line
2.25.1
RFC PATCH 17/17 pkvm: x86: Stub CONFIG_DEBUG_LIST in pKVM
In reply to Jason Chen CJFrom: Zide Chen <[email protected]>
To work with CONFIG_DEBUG_LIST, pKVM need to have its own list_debug.c since the /lib version doesn't build into pKVM binary.
Simply return true in __list_add_valid() and __list_del_entry_valid().
--- arch/x86/kvm/vmx/pkvm/hyp/Makefile | 1 + arch/x86/kvm/vmx/pkvm/hyp/lib/list_debug.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+)
arch/x86/kvm/vmx/pkvm/hyp/Makefile +1 -0
@@ -11,6 +11,7 @@ lib-dir := lib pkvm-hyp-y := vmx_asm.o vmexit.o pkvm-hyp-$(CONFIG_RETPOLINE) += $(lib-dir)/retpoline.o +pkvm-hyp-$(CONFIG_DEBUG_LIST) += $(lib-dir)/list_debug.o pkvm-obj := $(patsubst %.o,%.pkvm.o,$(pkvm-hyp-y)) obj-$(CONFIG_PKVM_INTEL) += pkvm.o
arch/x86/kvm/vmx/pkvm/hyp/lib/list_debug.c new file +17 -0
@@ -0,0 +1,17 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2022 Intel Corporation +*/ + +#include <linux/list.h> + +bool __list_add_valid (struct list_head *new,struct list_head *prev, +struct list_head *next) +{ +return true; +} + +bool __list_del_entry_valid (struct list_head *entry) +{ +return true; +}
Signature · 1 line
2.25.1