KVM: VMX: Move eVMCS code to dedicated files
authorSean Christopherson <sean.j.christopherson@intel.com>
Mon, 3 Dec 2018 21:53:06 +0000 (13:53 -0800)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 14 Dec 2018 13:00:06 +0000 (14:00 +0100)
The header, evmcs.h, already exists and contains a fair amount of code,
but there are a few pieces in vmx.c that can be moved verbatim.  In
addition, move an array definition to evmcs.c to prepare for multiple
consumers of evmcs.h.

Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/Makefile
arch/x86/kvm/vmx/evmcs.c [new file with mode: 0644]
arch/x86/kvm/vmx/evmcs.h
arch/x86/kvm/vmx/vmcs.h
arch/x86/kvm/vmx/vmx.c

index 79d97d837cf3a1fc4dbae74f1bfaf2c9a01853b9..7f3f50aaa203dd8212edf4943dfe8378c5761f07 100644 (file)
@@ -16,7 +16,7 @@ kvm-y                 += x86.o mmu.o emulate.o i8259.o irq.o lapic.o \
                           i8254.o ioapic.o irq_comm.o cpuid.o pmu.o mtrr.o \
                           hyperv.o page_track.o debugfs.o
 
-kvm-intel-y            += vmx/vmx.o vmx/pmu_intel.o vmx/vmcs12.o
+kvm-intel-y            += vmx/vmx.o vmx/pmu_intel.o vmx/vmcs12.o vmx/evmcs.o
 kvm-amd-y              += svm.o pmu_amd.o
 
 obj-$(CONFIG_KVM)      += kvm.o
diff --git a/arch/x86/kvm/vmx/evmcs.c b/arch/x86/kvm/vmx/evmcs.c
new file mode 100644 (file)
index 0000000..155fb4a
--- /dev/null
@@ -0,0 +1,343 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/errno.h>
+#include <linux/smp.h>
+
+#include "evmcs.h"
+#include "vmcs.h"
+#include "vmx.h"
+
+DEFINE_STATIC_KEY_FALSE(enable_evmcs);
+
+#if IS_ENABLED(CONFIG_HYPERV)
+
+#define ROL16(val, n) ((u16)(((u16)(val) << (n)) | ((u16)(val) >> (16 - (n)))))
+#define EVMCS1_OFFSET(x) offsetof(struct hv_enlightened_vmcs, x)
+#define EVMCS1_FIELD(number, name, clean_field)[ROL16(number, 6)] = \
+               {EVMCS1_OFFSET(name), clean_field}
+
+const struct evmcs_field vmcs_field_to_evmcs_1[] = {
+       /* 64 bit rw */
+       EVMCS1_FIELD(GUEST_RIP, guest_rip,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_NONE),
+       EVMCS1_FIELD(GUEST_RSP, guest_rsp,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_BASIC),
+       EVMCS1_FIELD(GUEST_RFLAGS, guest_rflags,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_BASIC),
+       EVMCS1_FIELD(HOST_IA32_PAT, host_ia32_pat,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1),
+       EVMCS1_FIELD(HOST_IA32_EFER, host_ia32_efer,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1),
+       EVMCS1_FIELD(HOST_CR0, host_cr0,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1),
+       EVMCS1_FIELD(HOST_CR3, host_cr3,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1),
+       EVMCS1_FIELD(HOST_CR4, host_cr4,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1),
+       EVMCS1_FIELD(HOST_IA32_SYSENTER_ESP, host_ia32_sysenter_esp,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1),
+       EVMCS1_FIELD(HOST_IA32_SYSENTER_EIP, host_ia32_sysenter_eip,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1),
+       EVMCS1_FIELD(HOST_RIP, host_rip,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1),
+       EVMCS1_FIELD(IO_BITMAP_A, io_bitmap_a,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_IO_BITMAP),
+       EVMCS1_FIELD(IO_BITMAP_B, io_bitmap_b,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_IO_BITMAP),
+       EVMCS1_FIELD(MSR_BITMAP, msr_bitmap,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_MSR_BITMAP),
+       EVMCS1_FIELD(GUEST_ES_BASE, guest_es_base,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
+       EVMCS1_FIELD(GUEST_CS_BASE, guest_cs_base,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
+       EVMCS1_FIELD(GUEST_SS_BASE, guest_ss_base,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
+       EVMCS1_FIELD(GUEST_DS_BASE, guest_ds_base,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
+       EVMCS1_FIELD(GUEST_FS_BASE, guest_fs_base,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
+       EVMCS1_FIELD(GUEST_GS_BASE, guest_gs_base,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
+       EVMCS1_FIELD(GUEST_LDTR_BASE, guest_ldtr_base,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
+       EVMCS1_FIELD(GUEST_TR_BASE, guest_tr_base,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
+       EVMCS1_FIELD(GUEST_GDTR_BASE, guest_gdtr_base,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
+       EVMCS1_FIELD(GUEST_IDTR_BASE, guest_idtr_base,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
+       EVMCS1_FIELD(TSC_OFFSET, tsc_offset,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_GRP2),
+       EVMCS1_FIELD(VIRTUAL_APIC_PAGE_ADDR, virtual_apic_page_addr,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_GRP2),
+       EVMCS1_FIELD(VMCS_LINK_POINTER, vmcs_link_pointer,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1),
+       EVMCS1_FIELD(GUEST_IA32_DEBUGCTL, guest_ia32_debugctl,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1),
+       EVMCS1_FIELD(GUEST_IA32_PAT, guest_ia32_pat,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1),
+       EVMCS1_FIELD(GUEST_IA32_EFER, guest_ia32_efer,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1),
+       EVMCS1_FIELD(GUEST_PDPTR0, guest_pdptr0,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1),
+       EVMCS1_FIELD(GUEST_PDPTR1, guest_pdptr1,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1),
+       EVMCS1_FIELD(GUEST_PDPTR2, guest_pdptr2,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1),
+       EVMCS1_FIELD(GUEST_PDPTR3, guest_pdptr3,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1),
+       EVMCS1_FIELD(GUEST_PENDING_DBG_EXCEPTIONS, guest_pending_dbg_exceptions,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1),
+       EVMCS1_FIELD(GUEST_SYSENTER_ESP, guest_sysenter_esp,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1),
+       EVMCS1_FIELD(GUEST_SYSENTER_EIP, guest_sysenter_eip,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1),
+       EVMCS1_FIELD(CR0_GUEST_HOST_MASK, cr0_guest_host_mask,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_CRDR),
+       EVMCS1_FIELD(CR4_GUEST_HOST_MASK, cr4_guest_host_mask,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_CRDR),
+       EVMCS1_FIELD(CR0_READ_SHADOW, cr0_read_shadow,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_CRDR),
+       EVMCS1_FIELD(CR4_READ_SHADOW, cr4_read_shadow,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_CRDR),
+       EVMCS1_FIELD(GUEST_CR0, guest_cr0,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_CRDR),
+       EVMCS1_FIELD(GUEST_CR3, guest_cr3,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_CRDR),
+       EVMCS1_FIELD(GUEST_CR4, guest_cr4,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_CRDR),
+       EVMCS1_FIELD(GUEST_DR7, guest_dr7,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_CRDR),
+       EVMCS1_FIELD(HOST_FS_BASE, host_fs_base,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_POINTER),
+       EVMCS1_FIELD(HOST_GS_BASE, host_gs_base,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_POINTER),
+       EVMCS1_FIELD(HOST_TR_BASE, host_tr_base,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_POINTER),
+       EVMCS1_FIELD(HOST_GDTR_BASE, host_gdtr_base,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_POINTER),
+       EVMCS1_FIELD(HOST_IDTR_BASE, host_idtr_base,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_POINTER),
+       EVMCS1_FIELD(HOST_RSP, host_rsp,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_POINTER),
+       EVMCS1_FIELD(EPT_POINTER, ept_pointer,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_XLAT),
+       EVMCS1_FIELD(GUEST_BNDCFGS, guest_bndcfgs,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1),
+       EVMCS1_FIELD(XSS_EXIT_BITMAP, xss_exit_bitmap,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_GRP2),
+
+       /* 64 bit read only */
+       EVMCS1_FIELD(GUEST_PHYSICAL_ADDRESS, guest_physical_address,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_NONE),
+       EVMCS1_FIELD(EXIT_QUALIFICATION, exit_qualification,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_NONE),
+       /*
+        * Not defined in KVM:
+        *
+        * EVMCS1_FIELD(0x00006402, exit_io_instruction_ecx,
+        *              HV_VMX_ENLIGHTENED_CLEAN_FIELD_NONE);
+        * EVMCS1_FIELD(0x00006404, exit_io_instruction_esi,
+        *              HV_VMX_ENLIGHTENED_CLEAN_FIELD_NONE);
+        * EVMCS1_FIELD(0x00006406, exit_io_instruction_esi,
+        *              HV_VMX_ENLIGHTENED_CLEAN_FIELD_NONE);
+        * EVMCS1_FIELD(0x00006408, exit_io_instruction_eip,
+        *              HV_VMX_ENLIGHTENED_CLEAN_FIELD_NONE);
+        */
+       EVMCS1_FIELD(GUEST_LINEAR_ADDRESS, guest_linear_address,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_NONE),
+
+       /*
+        * No mask defined in the spec as Hyper-V doesn't currently support
+        * these. Future proof by resetting the whole clean field mask on
+        * access.
+        */
+       EVMCS1_FIELD(VM_EXIT_MSR_STORE_ADDR, vm_exit_msr_store_addr,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_ALL),
+       EVMCS1_FIELD(VM_EXIT_MSR_LOAD_ADDR, vm_exit_msr_load_addr,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_ALL),
+       EVMCS1_FIELD(VM_ENTRY_MSR_LOAD_ADDR, vm_entry_msr_load_addr,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_ALL),
+       EVMCS1_FIELD(CR3_TARGET_VALUE0, cr3_target_value0,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_ALL),
+       EVMCS1_FIELD(CR3_TARGET_VALUE1, cr3_target_value1,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_ALL),
+       EVMCS1_FIELD(CR3_TARGET_VALUE2, cr3_target_value2,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_ALL),
+       EVMCS1_FIELD(CR3_TARGET_VALUE3, cr3_target_value3,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_ALL),
+
+       /* 32 bit rw */
+       EVMCS1_FIELD(TPR_THRESHOLD, tpr_threshold,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_NONE),
+       EVMCS1_FIELD(GUEST_INTERRUPTIBILITY_INFO, guest_interruptibility_info,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_BASIC),
+       EVMCS1_FIELD(CPU_BASED_VM_EXEC_CONTROL, cpu_based_vm_exec_control,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_PROC),
+       EVMCS1_FIELD(EXCEPTION_BITMAP, exception_bitmap,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_EXCPN),
+       EVMCS1_FIELD(VM_ENTRY_CONTROLS, vm_entry_controls,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_ENTRY),
+       EVMCS1_FIELD(VM_ENTRY_INTR_INFO_FIELD, vm_entry_intr_info_field,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_EVENT),
+       EVMCS1_FIELD(VM_ENTRY_EXCEPTION_ERROR_CODE,
+                    vm_entry_exception_error_code,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_EVENT),
+       EVMCS1_FIELD(VM_ENTRY_INSTRUCTION_LEN, vm_entry_instruction_len,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_EVENT),
+       EVMCS1_FIELD(HOST_IA32_SYSENTER_CS, host_ia32_sysenter_cs,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1),
+       EVMCS1_FIELD(PIN_BASED_VM_EXEC_CONTROL, pin_based_vm_exec_control,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_GRP1),
+       EVMCS1_FIELD(VM_EXIT_CONTROLS, vm_exit_controls,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_GRP1),
+       EVMCS1_FIELD(SECONDARY_VM_EXEC_CONTROL, secondary_vm_exec_control,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_GRP1),
+       EVMCS1_FIELD(GUEST_ES_LIMIT, guest_es_limit,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
+       EVMCS1_FIELD(GUEST_CS_LIMIT, guest_cs_limit,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
+       EVMCS1_FIELD(GUEST_SS_LIMIT, guest_ss_limit,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
+       EVMCS1_FIELD(GUEST_DS_LIMIT, guest_ds_limit,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
+       EVMCS1_FIELD(GUEST_FS_LIMIT, guest_fs_limit,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
+       EVMCS1_FIELD(GUEST_GS_LIMIT, guest_gs_limit,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
+       EVMCS1_FIELD(GUEST_LDTR_LIMIT, guest_ldtr_limit,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
+       EVMCS1_FIELD(GUEST_TR_LIMIT, guest_tr_limit,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
+       EVMCS1_FIELD(GUEST_GDTR_LIMIT, guest_gdtr_limit,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
+       EVMCS1_FIELD(GUEST_IDTR_LIMIT, guest_idtr_limit,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
+       EVMCS1_FIELD(GUEST_ES_AR_BYTES, guest_es_ar_bytes,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
+       EVMCS1_FIELD(GUEST_CS_AR_BYTES, guest_cs_ar_bytes,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
+       EVMCS1_FIELD(GUEST_SS_AR_BYTES, guest_ss_ar_bytes,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
+       EVMCS1_FIELD(GUEST_DS_AR_BYTES, guest_ds_ar_bytes,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
+       EVMCS1_FIELD(GUEST_FS_AR_BYTES, guest_fs_ar_bytes,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
+       EVMCS1_FIELD(GUEST_GS_AR_BYTES, guest_gs_ar_bytes,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
+       EVMCS1_FIELD(GUEST_LDTR_AR_BYTES, guest_ldtr_ar_bytes,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
+       EVMCS1_FIELD(GUEST_TR_AR_BYTES, guest_tr_ar_bytes,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
+       EVMCS1_FIELD(GUEST_ACTIVITY_STATE, guest_activity_state,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1),
+       EVMCS1_FIELD(GUEST_SYSENTER_CS, guest_sysenter_cs,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1),
+
+       /* 32 bit read only */
+       EVMCS1_FIELD(VM_INSTRUCTION_ERROR, vm_instruction_error,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_NONE),
+       EVMCS1_FIELD(VM_EXIT_REASON, vm_exit_reason,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_NONE),
+       EVMCS1_FIELD(VM_EXIT_INTR_INFO, vm_exit_intr_info,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_NONE),
+       EVMCS1_FIELD(VM_EXIT_INTR_ERROR_CODE, vm_exit_intr_error_code,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_NONE),
+       EVMCS1_FIELD(IDT_VECTORING_INFO_FIELD, idt_vectoring_info_field,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_NONE),
+       EVMCS1_FIELD(IDT_VECTORING_ERROR_CODE, idt_vectoring_error_code,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_NONE),
+       EVMCS1_FIELD(VM_EXIT_INSTRUCTION_LEN, vm_exit_instruction_len,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_NONE),
+       EVMCS1_FIELD(VMX_INSTRUCTION_INFO, vmx_instruction_info,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_NONE),
+
+       /* No mask defined in the spec (not used) */
+       EVMCS1_FIELD(PAGE_FAULT_ERROR_CODE_MASK, page_fault_error_code_mask,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_ALL),
+       EVMCS1_FIELD(PAGE_FAULT_ERROR_CODE_MATCH, page_fault_error_code_match,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_ALL),
+       EVMCS1_FIELD(CR3_TARGET_COUNT, cr3_target_count,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_ALL),
+       EVMCS1_FIELD(VM_EXIT_MSR_STORE_COUNT, vm_exit_msr_store_count,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_ALL),
+       EVMCS1_FIELD(VM_EXIT_MSR_LOAD_COUNT, vm_exit_msr_load_count,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_ALL),
+       EVMCS1_FIELD(VM_ENTRY_MSR_LOAD_COUNT, vm_entry_msr_load_count,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_ALL),
+
+       /* 16 bit rw */
+       EVMCS1_FIELD(HOST_ES_SELECTOR, host_es_selector,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1),
+       EVMCS1_FIELD(HOST_CS_SELECTOR, host_cs_selector,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1),
+       EVMCS1_FIELD(HOST_SS_SELECTOR, host_ss_selector,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1),
+       EVMCS1_FIELD(HOST_DS_SELECTOR, host_ds_selector,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1),
+       EVMCS1_FIELD(HOST_FS_SELECTOR, host_fs_selector,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1),
+       EVMCS1_FIELD(HOST_GS_SELECTOR, host_gs_selector,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1),
+       EVMCS1_FIELD(HOST_TR_SELECTOR, host_tr_selector,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1),
+       EVMCS1_FIELD(GUEST_ES_SELECTOR, guest_es_selector,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
+       EVMCS1_FIELD(GUEST_CS_SELECTOR, guest_cs_selector,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
+       EVMCS1_FIELD(GUEST_SS_SELECTOR, guest_ss_selector,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
+       EVMCS1_FIELD(GUEST_DS_SELECTOR, guest_ds_selector,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
+       EVMCS1_FIELD(GUEST_FS_SELECTOR, guest_fs_selector,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
+       EVMCS1_FIELD(GUEST_GS_SELECTOR, guest_gs_selector,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
+       EVMCS1_FIELD(GUEST_LDTR_SELECTOR, guest_ldtr_selector,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
+       EVMCS1_FIELD(GUEST_TR_SELECTOR, guest_tr_selector,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
+       EVMCS1_FIELD(VIRTUAL_PROCESSOR_ID, virtual_processor_id,
+                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_XLAT),
+};
+const unsigned int nr_evmcs_1_fields = ARRAY_SIZE(vmcs_field_to_evmcs_1);
+
+void evmcs_sanitize_exec_ctrls(struct vmcs_config *vmcs_conf)
+{
+       vmcs_conf->pin_based_exec_ctrl &= ~EVMCS1_UNSUPPORTED_PINCTRL;
+       vmcs_conf->cpu_based_2nd_exec_ctrl &= ~EVMCS1_UNSUPPORTED_2NDEXEC;
+
+       vmcs_conf->vmexit_ctrl &= ~EVMCS1_UNSUPPORTED_VMEXIT_CTRL;
+       vmcs_conf->vmentry_ctrl &= ~EVMCS1_UNSUPPORTED_VMENTRY_CTRL;
+
+}
+#endif
+
+int nested_enable_evmcs(struct kvm_vcpu *vcpu,
+                       uint16_t *vmcs_version)
+{
+       struct vcpu_vmx *vmx = to_vmx(vcpu);
+
+       /*
+        * vmcs_version represents the range of supported Enlightened VMCS
+        * versions: lower 8 bits is the minimal version, higher 8 bits is the
+        * maximum supported version. KVM supports versions from 1 to
+        * KVM_EVMCS_VERSION.
+        */
+       if (vmcs_version)
+               *vmcs_version = (KVM_EVMCS_VERSION << 8) | 1;
+
+       /* We don't support disabling the feature for simplicity. */
+       if (vmx->nested.enlightened_vmcs_enabled)
+               return 0;
+
+       vmx->nested.enlightened_vmcs_enabled = true;
+
+       vmx->nested.msrs.pinbased_ctls_high &= ~EVMCS1_UNSUPPORTED_PINCTRL;
+       vmx->nested.msrs.entry_ctls_high &= ~EVMCS1_UNSUPPORTED_VMENTRY_CTRL;
+       vmx->nested.msrs.exit_ctls_high &= ~EVMCS1_UNSUPPORTED_VMEXIT_CTRL;
+       vmx->nested.msrs.secondary_ctls_high &= ~EVMCS1_UNSUPPORTED_2NDEXEC;
+       vmx->nested.msrs.vmfunc_controls &= ~EVMCS1_UNSUPPORTED_VMFUNC;
+
+       return 0;
+}
index 210a884090ad6eac6b078de6d8a26d0159d51ceb..1572a3759d65894a3038ff964102df7274cbfcac 100644 (file)
 #ifndef __KVM_X86_VMX_EVMCS_H
 #define __KVM_X86_VMX_EVMCS_H
 
-#include <asm/hyperv-tlfs.h>
+#include <linux/jump_label.h>
 
-#define ROL16(val, n) ((u16)(((u16)(val) << (n)) | ((u16)(val) >> (16 - (n)))))
-#define EVMCS1_OFFSET(x) offsetof(struct hv_enlightened_vmcs, x)
-#define EVMCS1_FIELD(number, name, clean_field)[ROL16(number, 6)] = \
-               {EVMCS1_OFFSET(name), clean_field}
+#include <asm/hyperv-tlfs.h>
+#include <asm/mshyperv.h>
+#include <asm/vmx.h>
+
+#include "capabilities.h"
+#include "vmcs.h"
+
+struct vmcs_config;
+
+DECLARE_STATIC_KEY_FALSE(enable_evmcs);
+
+#define current_evmcs ((struct hv_enlightened_vmcs *)this_cpu_read(current_vmcs))
+
+#define KVM_EVMCS_VERSION 1
+
+/*
+ * Enlightened VMCSv1 doesn't support these:
+ *
+ *     POSTED_INTR_NV                  = 0x00000002,
+ *     GUEST_INTR_STATUS               = 0x00000810,
+ *     APIC_ACCESS_ADDR                = 0x00002014,
+ *     POSTED_INTR_DESC_ADDR           = 0x00002016,
+ *     EOI_EXIT_BITMAP0                = 0x0000201c,
+ *     EOI_EXIT_BITMAP1                = 0x0000201e,
+ *     EOI_EXIT_BITMAP2                = 0x00002020,
+ *     EOI_EXIT_BITMAP3                = 0x00002022,
+ *     GUEST_PML_INDEX                 = 0x00000812,
+ *     PML_ADDRESS                     = 0x0000200e,
+ *     VM_FUNCTION_CONTROL             = 0x00002018,
+ *     EPTP_LIST_ADDRESS               = 0x00002024,
+ *     VMREAD_BITMAP                   = 0x00002026,
+ *     VMWRITE_BITMAP                  = 0x00002028,
+ *
+ *     TSC_MULTIPLIER                  = 0x00002032,
+ *     PLE_GAP                         = 0x00004020,
+ *     PLE_WINDOW                      = 0x00004022,
+ *     VMX_PREEMPTION_TIMER_VALUE      = 0x0000482E,
+ *      GUEST_IA32_PERF_GLOBAL_CTRL     = 0x00002808,
+ *      HOST_IA32_PERF_GLOBAL_CTRL      = 0x00002c04,
+ *
+ * Currently unsupported in KVM:
+ *     GUEST_IA32_RTIT_CTL             = 0x00002814,
+ */
+#define EVMCS1_UNSUPPORTED_PINCTRL (PIN_BASED_POSTED_INTR | \
+                                   PIN_BASED_VMX_PREEMPTION_TIMER)
+#define EVMCS1_UNSUPPORTED_2NDEXEC                                     \
+       (SECONDARY_EXEC_VIRTUAL_INTR_DELIVERY |                         \
+        SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES |                      \
+        SECONDARY_EXEC_APIC_REGISTER_VIRT |                            \
+        SECONDARY_EXEC_ENABLE_PML |                                    \
+        SECONDARY_EXEC_ENABLE_VMFUNC |                                 \
+        SECONDARY_EXEC_SHADOW_VMCS |                                   \
+        SECONDARY_EXEC_TSC_SCALING |                                   \
+        SECONDARY_EXEC_PAUSE_LOOP_EXITING)
+#define EVMCS1_UNSUPPORTED_VMEXIT_CTRL (VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL)
+#define EVMCS1_UNSUPPORTED_VMENTRY_CTRL (VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL)
+#define EVMCS1_UNSUPPORTED_VMFUNC (VMX_VMFUNC_EPTP_SWITCHING)
+
+#if IS_ENABLED(CONFIG_HYPERV)
 
 struct evmcs_field {
        u16 offset;
        u16 clean_field;
 };
 
-static const struct evmcs_field vmcs_field_to_evmcs_1[] = {
-       /* 64 bit rw */
-       EVMCS1_FIELD(GUEST_RIP, guest_rip,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_NONE),
-       EVMCS1_FIELD(GUEST_RSP, guest_rsp,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_BASIC),
-       EVMCS1_FIELD(GUEST_RFLAGS, guest_rflags,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_BASIC),
-       EVMCS1_FIELD(HOST_IA32_PAT, host_ia32_pat,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1),
-       EVMCS1_FIELD(HOST_IA32_EFER, host_ia32_efer,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1),
-       EVMCS1_FIELD(HOST_CR0, host_cr0,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1),
-       EVMCS1_FIELD(HOST_CR3, host_cr3,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1),
-       EVMCS1_FIELD(HOST_CR4, host_cr4,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1),
-       EVMCS1_FIELD(HOST_IA32_SYSENTER_ESP, host_ia32_sysenter_esp,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1),
-       EVMCS1_FIELD(HOST_IA32_SYSENTER_EIP, host_ia32_sysenter_eip,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1),
-       EVMCS1_FIELD(HOST_RIP, host_rip,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1),
-       EVMCS1_FIELD(IO_BITMAP_A, io_bitmap_a,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_IO_BITMAP),
-       EVMCS1_FIELD(IO_BITMAP_B, io_bitmap_b,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_IO_BITMAP),
-       EVMCS1_FIELD(MSR_BITMAP, msr_bitmap,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_MSR_BITMAP),
-       EVMCS1_FIELD(GUEST_ES_BASE, guest_es_base,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
-       EVMCS1_FIELD(GUEST_CS_BASE, guest_cs_base,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
-       EVMCS1_FIELD(GUEST_SS_BASE, guest_ss_base,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
-       EVMCS1_FIELD(GUEST_DS_BASE, guest_ds_base,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
-       EVMCS1_FIELD(GUEST_FS_BASE, guest_fs_base,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
-       EVMCS1_FIELD(GUEST_GS_BASE, guest_gs_base,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
-       EVMCS1_FIELD(GUEST_LDTR_BASE, guest_ldtr_base,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
-       EVMCS1_FIELD(GUEST_TR_BASE, guest_tr_base,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
-       EVMCS1_FIELD(GUEST_GDTR_BASE, guest_gdtr_base,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
-       EVMCS1_FIELD(GUEST_IDTR_BASE, guest_idtr_base,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
-       EVMCS1_FIELD(TSC_OFFSET, tsc_offset,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_GRP2),
-       EVMCS1_FIELD(VIRTUAL_APIC_PAGE_ADDR, virtual_apic_page_addr,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_GRP2),
-       EVMCS1_FIELD(VMCS_LINK_POINTER, vmcs_link_pointer,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1),
-       EVMCS1_FIELD(GUEST_IA32_DEBUGCTL, guest_ia32_debugctl,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1),
-       EVMCS1_FIELD(GUEST_IA32_PAT, guest_ia32_pat,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1),
-       EVMCS1_FIELD(GUEST_IA32_EFER, guest_ia32_efer,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1),
-       EVMCS1_FIELD(GUEST_PDPTR0, guest_pdptr0,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1),
-       EVMCS1_FIELD(GUEST_PDPTR1, guest_pdptr1,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1),
-       EVMCS1_FIELD(GUEST_PDPTR2, guest_pdptr2,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1),
-       EVMCS1_FIELD(GUEST_PDPTR3, guest_pdptr3,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1),
-       EVMCS1_FIELD(GUEST_PENDING_DBG_EXCEPTIONS, guest_pending_dbg_exceptions,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1),
-       EVMCS1_FIELD(GUEST_SYSENTER_ESP, guest_sysenter_esp,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1),
-       EVMCS1_FIELD(GUEST_SYSENTER_EIP, guest_sysenter_eip,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1),
-       EVMCS1_FIELD(CR0_GUEST_HOST_MASK, cr0_guest_host_mask,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_CRDR),
-       EVMCS1_FIELD(CR4_GUEST_HOST_MASK, cr4_guest_host_mask,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_CRDR),
-       EVMCS1_FIELD(CR0_READ_SHADOW, cr0_read_shadow,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_CRDR),
-       EVMCS1_FIELD(CR4_READ_SHADOW, cr4_read_shadow,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_CRDR),
-       EVMCS1_FIELD(GUEST_CR0, guest_cr0,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_CRDR),
-       EVMCS1_FIELD(GUEST_CR3, guest_cr3,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_CRDR),
-       EVMCS1_FIELD(GUEST_CR4, guest_cr4,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_CRDR),
-       EVMCS1_FIELD(GUEST_DR7, guest_dr7,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_CRDR),
-       EVMCS1_FIELD(HOST_FS_BASE, host_fs_base,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_POINTER),
-       EVMCS1_FIELD(HOST_GS_BASE, host_gs_base,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_POINTER),
-       EVMCS1_FIELD(HOST_TR_BASE, host_tr_base,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_POINTER),
-       EVMCS1_FIELD(HOST_GDTR_BASE, host_gdtr_base,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_POINTER),
-       EVMCS1_FIELD(HOST_IDTR_BASE, host_idtr_base,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_POINTER),
-       EVMCS1_FIELD(HOST_RSP, host_rsp,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_POINTER),
-       EVMCS1_FIELD(EPT_POINTER, ept_pointer,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_XLAT),
-       EVMCS1_FIELD(GUEST_BNDCFGS, guest_bndcfgs,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1),
-       EVMCS1_FIELD(XSS_EXIT_BITMAP, xss_exit_bitmap,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_GRP2),
-
-       /* 64 bit read only */
-       EVMCS1_FIELD(GUEST_PHYSICAL_ADDRESS, guest_physical_address,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_NONE),
-       EVMCS1_FIELD(EXIT_QUALIFICATION, exit_qualification,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_NONE),
-       /*
-        * Not defined in KVM:
-        *
-        * EVMCS1_FIELD(0x00006402, exit_io_instruction_ecx,
-        *              HV_VMX_ENLIGHTENED_CLEAN_FIELD_NONE);
-        * EVMCS1_FIELD(0x00006404, exit_io_instruction_esi,
-        *              HV_VMX_ENLIGHTENED_CLEAN_FIELD_NONE);
-        * EVMCS1_FIELD(0x00006406, exit_io_instruction_esi,
-        *              HV_VMX_ENLIGHTENED_CLEAN_FIELD_NONE);
-        * EVMCS1_FIELD(0x00006408, exit_io_instruction_eip,
-        *              HV_VMX_ENLIGHTENED_CLEAN_FIELD_NONE);
-        */
-       EVMCS1_FIELD(GUEST_LINEAR_ADDRESS, guest_linear_address,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_NONE),
-
-       /*
-        * No mask defined in the spec as Hyper-V doesn't currently support
-        * these. Future proof by resetting the whole clean field mask on
-        * access.
-        */
-       EVMCS1_FIELD(VM_EXIT_MSR_STORE_ADDR, vm_exit_msr_store_addr,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_ALL),
-       EVMCS1_FIELD(VM_EXIT_MSR_LOAD_ADDR, vm_exit_msr_load_addr,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_ALL),
-       EVMCS1_FIELD(VM_ENTRY_MSR_LOAD_ADDR, vm_entry_msr_load_addr,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_ALL),
-       EVMCS1_FIELD(CR3_TARGET_VALUE0, cr3_target_value0,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_ALL),
-       EVMCS1_FIELD(CR3_TARGET_VALUE1, cr3_target_value1,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_ALL),
-       EVMCS1_FIELD(CR3_TARGET_VALUE2, cr3_target_value2,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_ALL),
-       EVMCS1_FIELD(CR3_TARGET_VALUE3, cr3_target_value3,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_ALL),
-
-       /* 32 bit rw */
-       EVMCS1_FIELD(TPR_THRESHOLD, tpr_threshold,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_NONE),
-       EVMCS1_FIELD(GUEST_INTERRUPTIBILITY_INFO, guest_interruptibility_info,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_BASIC),
-       EVMCS1_FIELD(CPU_BASED_VM_EXEC_CONTROL, cpu_based_vm_exec_control,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_PROC),
-       EVMCS1_FIELD(EXCEPTION_BITMAP, exception_bitmap,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_EXCPN),
-       EVMCS1_FIELD(VM_ENTRY_CONTROLS, vm_entry_controls,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_ENTRY),
-       EVMCS1_FIELD(VM_ENTRY_INTR_INFO_FIELD, vm_entry_intr_info_field,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_EVENT),
-       EVMCS1_FIELD(VM_ENTRY_EXCEPTION_ERROR_CODE,
-                    vm_entry_exception_error_code,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_EVENT),
-       EVMCS1_FIELD(VM_ENTRY_INSTRUCTION_LEN, vm_entry_instruction_len,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_EVENT),
-       EVMCS1_FIELD(HOST_IA32_SYSENTER_CS, host_ia32_sysenter_cs,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1),
-       EVMCS1_FIELD(PIN_BASED_VM_EXEC_CONTROL, pin_based_vm_exec_control,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_GRP1),
-       EVMCS1_FIELD(VM_EXIT_CONTROLS, vm_exit_controls,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_GRP1),
-       EVMCS1_FIELD(SECONDARY_VM_EXEC_CONTROL, secondary_vm_exec_control,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_GRP1),
-       EVMCS1_FIELD(GUEST_ES_LIMIT, guest_es_limit,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
-       EVMCS1_FIELD(GUEST_CS_LIMIT, guest_cs_limit,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
-       EVMCS1_FIELD(GUEST_SS_LIMIT, guest_ss_limit,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
-       EVMCS1_FIELD(GUEST_DS_LIMIT, guest_ds_limit,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
-       EVMCS1_FIELD(GUEST_FS_LIMIT, guest_fs_limit,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
-       EVMCS1_FIELD(GUEST_GS_LIMIT, guest_gs_limit,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
-       EVMCS1_FIELD(GUEST_LDTR_LIMIT, guest_ldtr_limit,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
-       EVMCS1_FIELD(GUEST_TR_LIMIT, guest_tr_limit,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
-       EVMCS1_FIELD(GUEST_GDTR_LIMIT, guest_gdtr_limit,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
-       EVMCS1_FIELD(GUEST_IDTR_LIMIT, guest_idtr_limit,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
-       EVMCS1_FIELD(GUEST_ES_AR_BYTES, guest_es_ar_bytes,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
-       EVMCS1_FIELD(GUEST_CS_AR_BYTES, guest_cs_ar_bytes,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
-       EVMCS1_FIELD(GUEST_SS_AR_BYTES, guest_ss_ar_bytes,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
-       EVMCS1_FIELD(GUEST_DS_AR_BYTES, guest_ds_ar_bytes,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
-       EVMCS1_FIELD(GUEST_FS_AR_BYTES, guest_fs_ar_bytes,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
-       EVMCS1_FIELD(GUEST_GS_AR_BYTES, guest_gs_ar_bytes,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
-       EVMCS1_FIELD(GUEST_LDTR_AR_BYTES, guest_ldtr_ar_bytes,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
-       EVMCS1_FIELD(GUEST_TR_AR_BYTES, guest_tr_ar_bytes,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
-       EVMCS1_FIELD(GUEST_ACTIVITY_STATE, guest_activity_state,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1),
-       EVMCS1_FIELD(GUEST_SYSENTER_CS, guest_sysenter_cs,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1),
-
-       /* 32 bit read only */
-       EVMCS1_FIELD(VM_INSTRUCTION_ERROR, vm_instruction_error,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_NONE),
-       EVMCS1_FIELD(VM_EXIT_REASON, vm_exit_reason,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_NONE),
-       EVMCS1_FIELD(VM_EXIT_INTR_INFO, vm_exit_intr_info,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_NONE),
-       EVMCS1_FIELD(VM_EXIT_INTR_ERROR_CODE, vm_exit_intr_error_code,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_NONE),
-       EVMCS1_FIELD(IDT_VECTORING_INFO_FIELD, idt_vectoring_info_field,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_NONE),
-       EVMCS1_FIELD(IDT_VECTORING_ERROR_CODE, idt_vectoring_error_code,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_NONE),
-       EVMCS1_FIELD(VM_EXIT_INSTRUCTION_LEN, vm_exit_instruction_len,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_NONE),
-       EVMCS1_FIELD(VMX_INSTRUCTION_INFO, vmx_instruction_info,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_NONE),
-
-       /* No mask defined in the spec (not used) */
-       EVMCS1_FIELD(PAGE_FAULT_ERROR_CODE_MASK, page_fault_error_code_mask,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_ALL),
-       EVMCS1_FIELD(PAGE_FAULT_ERROR_CODE_MATCH, page_fault_error_code_match,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_ALL),
-       EVMCS1_FIELD(CR3_TARGET_COUNT, cr3_target_count,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_ALL),
-       EVMCS1_FIELD(VM_EXIT_MSR_STORE_COUNT, vm_exit_msr_store_count,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_ALL),
-       EVMCS1_FIELD(VM_EXIT_MSR_LOAD_COUNT, vm_exit_msr_load_count,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_ALL),
-       EVMCS1_FIELD(VM_ENTRY_MSR_LOAD_COUNT, vm_entry_msr_load_count,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_ALL),
-
-       /* 16 bit rw */
-       EVMCS1_FIELD(HOST_ES_SELECTOR, host_es_selector,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1),
-       EVMCS1_FIELD(HOST_CS_SELECTOR, host_cs_selector,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1),
-       EVMCS1_FIELD(HOST_SS_SELECTOR, host_ss_selector,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1),
-       EVMCS1_FIELD(HOST_DS_SELECTOR, host_ds_selector,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1),
-       EVMCS1_FIELD(HOST_FS_SELECTOR, host_fs_selector,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1),
-       EVMCS1_FIELD(HOST_GS_SELECTOR, host_gs_selector,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1),
-       EVMCS1_FIELD(HOST_TR_SELECTOR, host_tr_selector,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1),
-       EVMCS1_FIELD(GUEST_ES_SELECTOR, guest_es_selector,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
-       EVMCS1_FIELD(GUEST_CS_SELECTOR, guest_cs_selector,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
-       EVMCS1_FIELD(GUEST_SS_SELECTOR, guest_ss_selector,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
-       EVMCS1_FIELD(GUEST_DS_SELECTOR, guest_ds_selector,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
-       EVMCS1_FIELD(GUEST_FS_SELECTOR, guest_fs_selector,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
-       EVMCS1_FIELD(GUEST_GS_SELECTOR, guest_gs_selector,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
-       EVMCS1_FIELD(GUEST_LDTR_SELECTOR, guest_ldtr_selector,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
-       EVMCS1_FIELD(GUEST_TR_SELECTOR, guest_tr_selector,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2),
-       EVMCS1_FIELD(VIRTUAL_PROCESSOR_ID, virtual_processor_id,
-                    HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_XLAT),
-};
+extern const struct evmcs_field vmcs_field_to_evmcs_1[];
+extern const unsigned int nr_evmcs_1_fields;
+
+#define ROL16(val, n) ((u16)(((u16)(val) << (n)) | ((u16)(val) >> (16 - (n)))))
 
 static __always_inline int get_evmcs_offset(unsigned long field,
                                            u16 *clean_field)
@@ -305,7 +80,7 @@ static __always_inline int get_evmcs_offset(unsigned long field,
        unsigned int index = ROL16(field, 6);
        const struct evmcs_field *evmcs_field;
 
-       if (unlikely(index >= ARRAY_SIZE(vmcs_field_to_evmcs_1))) {
+       if (unlikely(index >= nr_evmcs_1_fields)) {
                WARN_ONCE(1, "KVM: accessing unsupported EVMCS field %lx\n",
                          field);
                return -ENOENT;
@@ -321,4 +96,106 @@ static __always_inline int get_evmcs_offset(unsigned long field,
 
 #undef ROL16
 
+static inline void evmcs_write64(unsigned long field, u64 value)
+{
+       u16 clean_field;
+       int offset = get_evmcs_offset(field, &clean_field);
+
+       if (offset < 0)
+               return;
+
+       *(u64 *)((char *)current_evmcs + offset) = value;
+
+       current_evmcs->hv_clean_fields &= ~clean_field;
+}
+
+static inline void evmcs_write32(unsigned long field, u32 value)
+{
+       u16 clean_field;
+       int offset = get_evmcs_offset(field, &clean_field);
+
+       if (offset < 0)
+               return;
+
+       *(u32 *)((char *)current_evmcs + offset) = value;
+       current_evmcs->hv_clean_fields &= ~clean_field;
+}
+
+static inline void evmcs_write16(unsigned long field, u16 value)
+{
+       u16 clean_field;
+       int offset = get_evmcs_offset(field, &clean_field);
+
+       if (offset < 0)
+               return;
+
+       *(u16 *)((char *)current_evmcs + offset) = value;
+       current_evmcs->hv_clean_fields &= ~clean_field;
+}
+
+static inline u64 evmcs_read64(unsigned long field)
+{
+       int offset = get_evmcs_offset(field, NULL);
+
+       if (offset < 0)
+               return 0;
+
+       return *(u64 *)((char *)current_evmcs + offset);
+}
+
+static inline u32 evmcs_read32(unsigned long field)
+{
+       int offset = get_evmcs_offset(field, NULL);
+
+       if (offset < 0)
+               return 0;
+
+       return *(u32 *)((char *)current_evmcs + offset);
+}
+
+static inline u16 evmcs_read16(unsigned long field)
+{
+       int offset = get_evmcs_offset(field, NULL);
+
+       if (offset < 0)
+               return 0;
+
+       return *(u16 *)((char *)current_evmcs + offset);
+}
+
+static inline void evmcs_touch_msr_bitmap(void)
+{
+       if (unlikely(!current_evmcs))
+               return;
+
+       if (current_evmcs->hv_enlightenments_control.msr_bitmap)
+               current_evmcs->hv_clean_fields &=
+                       ~HV_VMX_ENLIGHTENED_CLEAN_FIELD_MSR_BITMAP;
+}
+
+static inline void evmcs_load(u64 phys_addr)
+{
+       struct hv_vp_assist_page *vp_ap =
+               hv_get_vp_assist_page(smp_processor_id());
+
+       vp_ap->current_nested_vmcs = phys_addr;
+       vp_ap->enlighten_vmentry = 1;
+}
+
+void evmcs_sanitize_exec_ctrls(struct vmcs_config *vmcs_conf);
+#else /* !IS_ENABLED(CONFIG_HYPERV) */
+static inline void evmcs_write64(unsigned long field, u64 value) {}
+static inline void evmcs_write32(unsigned long field, u32 value) {}
+static inline void evmcs_write16(unsigned long field, u16 value) {}
+static inline u64 evmcs_read64(unsigned long field) { return 0; }
+static inline u32 evmcs_read32(unsigned long field) { return 0; }
+static inline u16 evmcs_read16(unsigned long field) { return 0; }
+static inline void evmcs_load(u64 phys_addr) {}
+static inline void evmcs_sanitize_exec_ctrls(struct vmcs_config *vmcs_conf) {}
+static inline void evmcs_touch_msr_bitmap(void) {}
+#endif /* IS_ENABLED(CONFIG_HYPERV) */
+
+int nested_enable_evmcs(struct kvm_vcpu *vcpu,
+                       uint16_t *vmcs_version);
+
 #endif /* __KVM_X86_VMX_EVMCS_H */
index 3b8da04203e4d46a7b5fee94fcf6f1afc172cf6e..6def3ba88e3b35109dd4688f4aad2ea72deff965 100644 (file)
@@ -22,6 +22,8 @@ struct vmcs {
        char data[0];
 };
 
+DECLARE_PER_CPU(struct vmcs *, current_vmcs);
+
 /*
  * vmcs_host_state tracks registers that are loaded from the VMCS on VMEXIT
  * and whose values change infrequently, but are not constant.  I.e. this is
index 6e3da648647192d43ba19265e36b47c22150b860..266fa6f324eb6f2b674fdd567429d0a13f1bf90a 100644 (file)
@@ -385,7 +385,7 @@ static __always_inline void vmx_disable_intercept_for_msr(unsigned long *msr_bit
                                                          u32 msr, int type);
 
 static DEFINE_PER_CPU(struct vmcs *, vmxarea);
-static DEFINE_PER_CPU(struct vmcs *, current_vmcs);
+DEFINE_PER_CPU(struct vmcs *, current_vmcs);
 /*
  * We maintain a per-CPU linked-list of VMCS loaded on that CPU. This is needed
  * when a CPU is brought down, and we need to VMCLEAR all VMCSs loaded on it.
@@ -455,155 +455,10 @@ static const u32 vmx_msr_index[] = {
        MSR_EFER, MSR_TSC_AUX, MSR_STAR,
 };
 
-DEFINE_STATIC_KEY_FALSE(enable_evmcs);
-
-#define current_evmcs ((struct hv_enlightened_vmcs *)this_cpu_read(current_vmcs))
-
-#define KVM_EVMCS_VERSION 1
-
-/*
- * Enlightened VMCSv1 doesn't support these:
- *
- *     POSTED_INTR_NV                  = 0x00000002,
- *     GUEST_INTR_STATUS               = 0x00000810,
- *     APIC_ACCESS_ADDR                = 0x00002014,
- *     POSTED_INTR_DESC_ADDR           = 0x00002016,
- *     EOI_EXIT_BITMAP0                = 0x0000201c,
- *     EOI_EXIT_BITMAP1                = 0x0000201e,
- *     EOI_EXIT_BITMAP2                = 0x00002020,
- *     EOI_EXIT_BITMAP3                = 0x00002022,
- *     GUEST_PML_INDEX                 = 0x00000812,
- *     PML_ADDRESS                     = 0x0000200e,
- *     VM_FUNCTION_CONTROL             = 0x00002018,
- *     EPTP_LIST_ADDRESS               = 0x00002024,
- *     VMREAD_BITMAP                   = 0x00002026,
- *     VMWRITE_BITMAP                  = 0x00002028,
- *
- *     TSC_MULTIPLIER                  = 0x00002032,
- *     PLE_GAP                         = 0x00004020,
- *     PLE_WINDOW                      = 0x00004022,
- *     VMX_PREEMPTION_TIMER_VALUE      = 0x0000482E,
- *      GUEST_IA32_PERF_GLOBAL_CTRL     = 0x00002808,
- *      HOST_IA32_PERF_GLOBAL_CTRL      = 0x00002c04,
- *
- * Currently unsupported in KVM:
- *     GUEST_IA32_RTIT_CTL             = 0x00002814,
- */
-#define EVMCS1_UNSUPPORTED_PINCTRL (PIN_BASED_POSTED_INTR | \
-                                   PIN_BASED_VMX_PREEMPTION_TIMER)
-#define EVMCS1_UNSUPPORTED_2NDEXEC                                     \
-       (SECONDARY_EXEC_VIRTUAL_INTR_DELIVERY |                         \
-        SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES |                      \
-        SECONDARY_EXEC_APIC_REGISTER_VIRT |                            \
-        SECONDARY_EXEC_ENABLE_PML |                                    \
-        SECONDARY_EXEC_ENABLE_VMFUNC |                                 \
-        SECONDARY_EXEC_SHADOW_VMCS |                                   \
-        SECONDARY_EXEC_TSC_SCALING |                                   \
-        SECONDARY_EXEC_PAUSE_LOOP_EXITING)
-#define EVMCS1_UNSUPPORTED_VMEXIT_CTRL (VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL)
-#define EVMCS1_UNSUPPORTED_VMENTRY_CTRL (VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL)
-#define EVMCS1_UNSUPPORTED_VMFUNC (VMX_VMFUNC_EPTP_SWITCHING)
-
 #if IS_ENABLED(CONFIG_HYPERV)
 static bool __read_mostly enlightened_vmcs = true;
 module_param(enlightened_vmcs, bool, 0444);
 
-static inline void evmcs_write64(unsigned long field, u64 value)
-{
-       u16 clean_field;
-       int offset = get_evmcs_offset(field, &clean_field);
-
-       if (offset < 0)
-               return;
-
-       *(u64 *)((char *)current_evmcs + offset) = value;
-
-       current_evmcs->hv_clean_fields &= ~clean_field;
-}
-
-static inline void evmcs_write32(unsigned long field, u32 value)
-{
-       u16 clean_field;
-       int offset = get_evmcs_offset(field, &clean_field);
-
-       if (offset < 0)
-               return;
-
-       *(u32 *)((char *)current_evmcs + offset) = value;
-       current_evmcs->hv_clean_fields &= ~clean_field;
-}
-
-static inline void evmcs_write16(unsigned long field, u16 value)
-{
-       u16 clean_field;
-       int offset = get_evmcs_offset(field, &clean_field);
-
-       if (offset < 0)
-               return;
-
-       *(u16 *)((char *)current_evmcs + offset) = value;
-       current_evmcs->hv_clean_fields &= ~clean_field;
-}
-
-static inline u64 evmcs_read64(unsigned long field)
-{
-       int offset = get_evmcs_offset(field, NULL);
-
-       if (offset < 0)
-               return 0;
-
-       return *(u64 *)((char *)current_evmcs + offset);
-}
-
-static inline u32 evmcs_read32(unsigned long field)
-{
-       int offset = get_evmcs_offset(field, NULL);
-
-       if (offset < 0)
-               return 0;
-
-       return *(u32 *)((char *)current_evmcs + offset);
-}
-
-static inline u16 evmcs_read16(unsigned long field)
-{
-       int offset = get_evmcs_offset(field, NULL);
-
-       if (offset < 0)
-               return 0;
-
-       return *(u16 *)((char *)current_evmcs + offset);
-}
-
-static inline void evmcs_touch_msr_bitmap(void)
-{
-       if (unlikely(!current_evmcs))
-               return;
-
-       if (current_evmcs->hv_enlightenments_control.msr_bitmap)
-               current_evmcs->hv_clean_fields &=
-                       ~HV_VMX_ENLIGHTENED_CLEAN_FIELD_MSR_BITMAP;
-}
-
-static void evmcs_load(u64 phys_addr)
-{
-       struct hv_vp_assist_page *vp_ap =
-               hv_get_vp_assist_page(smp_processor_id());
-
-       vp_ap->current_nested_vmcs = phys_addr;
-       vp_ap->enlighten_vmentry = 1;
-}
-
-static void evmcs_sanitize_exec_ctrls(struct vmcs_config *vmcs_conf)
-{
-       vmcs_conf->pin_based_exec_ctrl &= ~EVMCS1_UNSUPPORTED_PINCTRL;
-       vmcs_conf->cpu_based_2nd_exec_ctrl &= ~EVMCS1_UNSUPPORTED_2NDEXEC;
-
-       vmcs_conf->vmexit_ctrl &= ~EVMCS1_UNSUPPORTED_VMEXIT_CTRL;
-       vmcs_conf->vmentry_ctrl &= ~EVMCS1_UNSUPPORTED_VMENTRY_CTRL;
-
-}
-
 /* check_ept_pointer() should be under protection of ept_pointer_lock. */
 static void check_ept_pointer_match(struct kvm *kvm)
 {
@@ -650,47 +505,8 @@ static int vmx_hv_remote_flush_tlb(struct kvm *kvm)
        spin_unlock(&to_kvm_vmx(kvm)->ept_pointer_lock);
        return ret;
 }
-#else /* !IS_ENABLED(CONFIG_HYPERV) */
-static inline void evmcs_write64(unsigned long field, u64 value) {}
-static inline void evmcs_write32(unsigned long field, u32 value) {}
-static inline void evmcs_write16(unsigned long field, u16 value) {}
-static inline u64 evmcs_read64(unsigned long field) { return 0; }
-static inline u32 evmcs_read32(unsigned long field) { return 0; }
-static inline u16 evmcs_read16(unsigned long field) { return 0; }
-static inline void evmcs_load(u64 phys_addr) {}
-static inline void evmcs_sanitize_exec_ctrls(struct vmcs_config *vmcs_conf) {}
-static inline void evmcs_touch_msr_bitmap(void) {}
 #endif /* IS_ENABLED(CONFIG_HYPERV) */
 
-static int nested_enable_evmcs(struct kvm_vcpu *vcpu,
-                              uint16_t *vmcs_version)
-{
-       struct vcpu_vmx *vmx = to_vmx(vcpu);
-
-       /*
-        * vmcs_version represents the range of supported Enlightened VMCS
-        * versions: lower 8 bits is the minimal version, higher 8 bits is the
-        * maximum supported version. KVM supports versions from 1 to
-        * KVM_EVMCS_VERSION.
-        */
-       if (vmcs_version)
-               *vmcs_version = (KVM_EVMCS_VERSION << 8) | 1;
-
-       /* We don't support disabling the feature for simplicity. */
-       if (vmx->nested.enlightened_vmcs_enabled)
-               return 0;
-
-       vmx->nested.enlightened_vmcs_enabled = true;
-
-       vmx->nested.msrs.pinbased_ctls_high &= ~EVMCS1_UNSUPPORTED_PINCTRL;
-       vmx->nested.msrs.entry_ctls_high &= ~EVMCS1_UNSUPPORTED_VMENTRY_CTRL;
-       vmx->nested.msrs.exit_ctls_high &= ~EVMCS1_UNSUPPORTED_VMEXIT_CTRL;
-       vmx->nested.msrs.secondary_ctls_high &= ~EVMCS1_UNSUPPORTED_2NDEXEC;
-       vmx->nested.msrs.vmfunc_controls &= ~EVMCS1_UNSUPPORTED_VMFUNC;
-
-       return 0;
-}
-
 /*
  * Comment's format: document - errata name - stepping - processor name.
  * Refer from