KVM: VMX: Support TscScaling and EnclsExitingBitmap with eVMCS + use vmcs_config for L1 VMX MSRs
Subsystems (9)
Vitaly Kuznetsov
maintainerv2 cover KVM: VMX: Support TscScaling and EnclsExitingBitmap with eVMCS + use vmcs_config for L1 VMX MSRs
This series combines previously sent:
- "[PATCH 00/11] KVM: VMX: Support TscScaling and EnclsExitingBitmap with eVMCS"
(https://lore.kernel.org/kvm/[email protected]/)
and
- "[PATCH 00/14] KVM: nVMX: Use vmcs_config for setting up nested VMX MSRs"
(https://lore.kernel.org/kvm/[email protected]/)
this is done to address Jim's concern that any changes to L1 VMX control MSRs will inevitably break live migration. This version should not produce changes.
Original description:
Enlightened VMCS v1 definition was updates to include fields for the following features:
- PerfGlobalCtrl
- EnclsExitingBitmap
- TSC scaling
- GuestLbrCtl
- CET
- SSP
Add support for EnclsExitingBitmap and TSC scaling to KVM. PerfGlobalCtrl doesn't work correctly with Win11, don't enable it yet. SSP, CET and GuestLbrCtl are not currently supported by KVM.
Note: adding new field for KVM on Hyper-V case is easy but adding them to Hyper-V on KVM requires some work to not break live migration as we never expected this to happen without eVMCS version update. The series introduces new KVM_CAP_HYPERV_ENLIGHTENED_VMCS2 capability and a notion of KVM internal 'Enlightened VMCS revision'.
While on it, implement Sean's idea to use vmcs_config for setting up L1 VMX control MSRs instead of re-reading host MSRs.
Sean Christopherson (1):
KVM: VMX: Clear controls obsoleted by EPT at runtime, not setup
Vitaly Kuznetsov (27):
KVM: x86: hyper-v: Expose access to debug MSRs in the partition
privilege flags
x86/hyperv: Fix 'struct hv_enlightened_vmcs' definition x86/hyperv: Update 'struct hv_enlightened_vmcs' definition
KVM: VMX: Define VMCS-to-EVMCS conversion for the new fields
KVM: nVMX: Support several new fields in eVMCSv1
KVM: nVMX: Introduce KVM_CAP_HYPERV_ENLIGHTENED_VMCS2
KVM: selftests: Switch to KVM_CAP_HYPERV_ENLIGHTENED_VMCS2
KVM: VMX: Support TSC scaling with enlightened VMCS
KVM: selftests: Add ENCLS_EXITING_BITMAP{,HIGH} VMCS fields
KVM: selftests: Switch to updated eVMCSv1 definition
KVM: selftests: Enable TSC scaling in evmcs selftest
KVM: VMX: Enable VM_{EXIT,ENTRY}_LOAD_IA32_PERF_GLOBAL_CTRL for KVM on
Hyper-V
KVM: VMX: Get rid of eVMCS specific VMX controls sanitization
KVM: VMX: Check VM_ENTRY_IA32E_MODE in setup_vmcs_config()
KVM: VMX: Check CPU_BASED_{INTR,NMI}_WINDOW_EXITING in
setup_vmcs_config()
KVM: VMX: Tweak the special handling of SECONDARY_EXEC_ENCLS_EXITING
in setup_vmcs_config()
KVM: VMX: Extend VMX controls macro shenanigans
KVM: VMX: Move CPU_BASED_CR8_{LOAD,STORE}_EXITING filtering out of
setup_vmcs_config()
KVM: VMX: Add missing VMEXIT controls to vmcs_config
KVM: VMX: Add missing VMENTRY controls to vmcs_config
KVM: VMX: Add missing CPU based VM execution controls to vmcs_config
KVM: VMX: Move LOAD_IA32_PERF_GLOBAL_CTRL errata handling out of
setup_vmcs_config()
KVM: nVMX: Use sanitized allowed-1 bits for VMX control MSRs
KVM: VMX: Store required-1 VMX controls in vmcs_config
KVM: nVMX: Use sanitized required-1 bits for VMX control MSRs
KVM: VMX: Cache MSR_IA32_VMX_MISC in vmcs_config
KVM: nVMX: Use cached host MSR_IA32_VMX_MISC value for setting up
nested MSR
Documentation/virt/kvm/api.rst | 43 ++- arch/x86/include/asm/hyperv-tlfs.h | 19 +- arch/x86/include/asm/kvm_host.h | 2 +- arch/x86/kvm/hyperv.c | 1 + arch/x86/kvm/vmx/capabilities.h | 16 +- arch/x86/kvm/vmx/evmcs.c | 135 ++++++--- arch/x86/kvm/vmx/evmcs.h | 34 ++- arch/x86/kvm/vmx/nested.c | 80 ++++-- arch/x86/kvm/vmx/nested.h | 2 +- arch/x86/kvm/vmx/vmx.c | 269 +++++++++--------- arch/x86/kvm/vmx/vmx.h | 133 ++++++++- arch/x86/kvm/x86.c | 15 +- include/asm-generic/hyperv-tlfs.h | 2 + include/uapi/linux/kvm.h | 3 +- .../selftests/kvm/include/kvm_util_base.h | 8 + .../selftests/kvm/include/x86_64/evmcs.h | 46 ++- .../selftests/kvm/include/x86_64/vmx.h | 2 + tools/testing/selftests/kvm/lib/x86_64/vmx.c | 5 +- .../testing/selftests/kvm/x86_64/evmcs_test.c | 33 ++- .../selftests/kvm/x86_64/hyperv_cpuid.c | 2 +- .../kvm/x86_64/vmx_set_nested_state_test.c | 2 +- 21 files changed, 597 insertions(+), 255 deletions(-)
Signature · 1 line
2.35.3
Vitaly Kuznetsov
maintainerPATCH v2 1/28 KVM: x86: hyper-v: Expose access to debug MSRs in the partition privilege flags
For some features, Hyper-V spec defines two separate CPUID bits: one listing whether the feature is supported or not and another one showing whether guest partition was granted access to the feature ("partition privilege mask"). 'Debug MSRs available' is one of such features. Add the missing 'access' bit.
--- arch/x86/kvm/hyperv.c | 1 + include/asm-generic/hyperv-tlfs.h | 2 ++ 2 files changed, 3 insertions(+)
arch/x86/kvm/hyperv.c +1 -0
@@ -2496,6 +2496,7 @@ int kvm_get_hv_cpuid(struct kvm_vcpu *vcpu, struct kvm_cpuid2 *cpuid, ent->eax |=HV_MSR_RESET_AVAILABLE ; ent->eax |=HV_MSR_REFERENCE_TSC_AVAILABLE ; ent->eax |=HV_ACCESS_FREQUENCY_MSRS ; + ent->eax |=HV_ACCESS_DEBUG_MSRS ; ent->eax |=HV_ACCESS_REENLIGHTENMENT ; ent->ebx |=HV_POST_MESSAGES ;
include/asm-generic/hyperv-tlfs.h +2 -0
@@ -70,6 +70,8 @@#define HV_MSR_GUEST_IDLE_AVAILABLE BIT(10)/* Partition local APIC and TSC frequency registers available */ #define HV_ACCESS_FREQUENCY_MSRS BIT(11) +/* Debug MSRs available */ +#define HV_ACCESS_DEBUG_MSRS BIT(12)/* AccessReenlightenmentControls privilege */ #define HV_ACCESS_REENLIGHTENMENT BIT(13)/* AccessTscInvariantControls privilege */
Signature · 1 line
2.35.3
Vitaly Kuznetsov
maintainerPATCH v2 2/28 x86/hyperv: Fix 'struct hv_enlightened_vmcs' definition
In reply to Vitaly KuznetsovSection 1.9 of TLFS v6.0b says:
"All structures are padded in such a way that fields are aligned naturally (that is, an 8-byte field is aligned to an offset of 8 bytes and so on)".
'struct enlightened_vmcs' has a glitch:
...
struct {
u32 nested_flush_hypercall:1; /* 836: 0 4 */
u32 msr_bitmap:1; /* 836: 1 4 */
u32 reserved:30; /* 836: 2 4 */
} hv_enlightenments_control; /* 836 4 */
u32 hv_vp_id; /* 840 4 */
u64 hv_vm_id; /* 844 8 */
u64 partition_assist_page; /* 852 8 */...
And the observed values in 'partition_assist_page' make no sense at all. Fix the layout by padding the structure properly.
--- arch/x86/include/asm/hyperv-tlfs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/include/asm/hyperv-tlfs.h +2 -2
@@ -546,7 +546,7 @@ struct hv_enlightened_vmcs {u64 guest_rip;u32 hv_clean_fields; -u32 hv_padding_32; +u32 padding32_1;u32 hv_synthetic_controls;struct {u32 nested_flush_hypercall:1 ;
@@ -554,7 +554,7 @@ struct hv_enlightened_vmcs { u32 reserved:30; }__packed hv_enlightenments_control;u32 hv_vp_id; - +u32 padding32_2;u64 hv_vm_id;u64 partition_assist_page;u64 padding64_4[4 ];
Signature · 1 line
2.35.3
Vitaly Kuznetsov
maintainerPATCH v2 3/28 x86/hyperv: Update 'struct hv_enlightened_vmcs' definition
In reply to Vitaly KuznetsovUpdated Hyper-V Enlightened VMCS specification lists several new fields for the following features:
- PerfGlobalCtrl
- EnclsExitingBitmap
- Tsc Scaling
- GuestLbrCtl
- CET
- SSP
Update the definition.
Note: The latest TLFS is available at
https://docs.microsoft.com/en-us/virtualization/hyper-v-on-windows/tlfs/tlfs
--- arch/x86/include/asm/hyperv-tlfs.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
arch/x86/include/asm/hyperv-tlfs.h +13 -2
@@ -559,9 +559,20 @@ struct hv_enlightened_vmcs {u64 partition_assist_page;u64 padding64_4[4 ];u64 guest_bndcfgs; -u64 padding64_5[7 ]; +u64 guest_ia32_perf_global_ctrl; +u64 guest_ia32_s_cet; +u64 guest_ssp; +u64 guest_ia32_int_ssp_table_addr; +u64 guest_ia32_lbr_ctl; +u64 padding64_5[2 ];u64 xss_exit_bitmap; -u64 padding64_6[7 ]; +u64 host_ia32_perf_global_ctrl; +u64 encls_exiting_bitmap; +u64 tsc_multiplier; +u64 host_ia32_s_cet; +u64 host_ssp; +u64 host_ia32_int_ssp_table_addr; +u64 padding64_6; } __packed;#define HV_VMX_ENLIGHTENED_CLEAN_FIELD_NONE 0
Signature · 1 line
2.35.3
Vitaly Kuznetsov
maintainerPATCH v2 4/28 KVM: VMX: Define VMCS-to-EVMCS conversion for the new fields
In reply to Vitaly KuznetsovEnlightened VMCS v1 definition was updated with new fields, support them in KVM by defining VMCS-to-EVMCS conversion.
Note: SSP, CET and Guest LBR features are not supported by KVM yet and the corresponding fields are not defined in 'enum vmcs_field', leave them commented out for now.
--- arch/x86/kvm/vmx/evmcs.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
arch/x86/kvm/vmx/evmcs.c +26 -0
@@ -28,6 +28,8 @@ const struct evmcs_field vmcs_field_to_evmcs_1[] = { 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_IA32_PERF_GLOBAL_CTRL , host_ia32_perf_global_ctrl, +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,
@@ -78,6 +80,8 @@ const struct evmcs_field vmcs_field_to_evmcs_1[] = { 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_IA32_PERF_GLOBAL_CTRL , guest_ia32_perf_global_ctrl, +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,
@@ -126,6 +130,28 @@ const struct evmcs_field vmcs_field_to_evmcs_1[] = { HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1),EVMCS1_FIELD (XSS_EXIT_BITMAP , xss_exit_bitmap,HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_GRP2 ), +EVMCS1_FIELD (ENCLS_EXITING_BITMAP , encls_exiting_bitmap, +HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_GRP2 ), +EVMCS1_FIELD (TSC_MULTIPLIER , tsc_multiplier, +HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_GRP2 ), +/* +* Not used by KVM: +* +* EVMCS1_FIELD(0x00006828, guest_ia32_s_cet, +* HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1), +* EVMCS1_FIELD(0x0000682A, guest_ssp, +* HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_BASIC), +* EVMCS1_FIELD(0x0000682C, guest_ia32_int_ssp_table_addr, +* HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1), +* EVMCS1_FIELD(0x00002816, guest_ia32_lbr_ctl, +* HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1), +* EVMCS1_FIELD(0x00006C18, host_ia32_s_cet, +* HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1), +* EVMCS1_FIELD(0x00006C1A, host_ssp, +* HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1), +* EVMCS1_FIELD(0x00006C1C, host_ia32_int_ssp_table_addr, +* HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1), +*/ /* 64 bit read only */ EVMCS1_FIELD(GUEST_PHYSICAL_ADDRESS, guest_physical_address,
Signature · 1 line
2.35.3
Vitaly Kuznetsov
maintainerPATCH v2 5/28 KVM: nVMX: Support several new fields in eVMCSv1
In reply to Vitaly KuznetsovEnlightened VMCS v1 definition was updated with new fields, add support for them for Hyper-V on KVM.
Note: SSP, CET and Guest LBR features are not supported by KVM yet and 'struct vmcs12' has no corresponding fields.
--- arch/x86/kvm/vmx/nested.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)
arch/x86/kvm/vmx/nested.c +31 -0
@@ -1603,6 +1603,10 @@ static void copy_enlightened_to_vmcs12(struct vcpu_vmx *vmx, u32 hv_clean_fields vmcs12->guest_rflags = evmcs->guest_rflags; vmcs12->guest_interruptibility_info = evmcs->guest_interruptibility_info; +/* +* Not present in struct vmcs12: +* vmcs12->guest_ssp = evmcs->guest_ssp; +*/ } if (unlikely(!(hv_clean_fields &
@@ -1649,6 +1653,13 @@ static void copy_enlightened_to_vmcs12(struct vcpu_vmx *vmx, u32 hv_clean_fields vmcs12->host_fs_selector = evmcs->host_fs_selector; vmcs12->host_gs_selector = evmcs->host_gs_selector; vmcs12->host_tr_selector = evmcs->host_tr_selector; + vmcs12->host_ia32_perf_global_ctrl = evmcs->host_ia32_perf_global_ctrl; +/* +* Not present in struct vmcs12: +* vmcs12->host_ia32_s_cet = evmcs->host_ia32_s_cet; +* vmcs12->host_ssp = evmcs->host_ssp; +* vmcs12->host_ia32_int_ssp_table_addr = evmcs->host_ia32_int_ssp_table_addr; +*/ } if (unlikely(!(hv_clean_fields &
@@ -1716,6 +1727,8 @@ static void copy_enlightened_to_vmcs12(struct vcpu_vmx *vmx, u32 hv_clean_fields vmcs12->tsc_offset = evmcs->tsc_offset; vmcs12->virtual_apic_page_addr = evmcs->virtual_apic_page_addr; vmcs12->xss_exit_bitmap = evmcs->xss_exit_bitmap; + vmcs12->encls_exiting_bitmap = evmcs->encls_exiting_bitmap; + vmcs12->tsc_multiplier = evmcs->tsc_multiplier; } if (unlikely(!(hv_clean_fields &
@@ -1763,6 +1776,13 @@ static void copy_enlightened_to_vmcs12(struct vcpu_vmx *vmx, u32 hv_clean_fields vmcs12->guest_bndcfgs = evmcs->guest_bndcfgs; vmcs12->guest_activity_state = evmcs->guest_activity_state; vmcs12->guest_sysenter_cs = evmcs->guest_sysenter_cs; + vmcs12->guest_ia32_perf_global_ctrl = evmcs->guest_ia32_perf_global_ctrl; +/* +* Not present in struct vmcs12: +* vmcs12->guest_ia32_s_cet = evmcs->guest_ia32_s_cet; +* vmcs12->guest_ia32_lbr_ctl = evmcs->guest_ia32_lbr_ctl; +* vmcs12->guest_ia32_int_ssp_table_addr = evmcs->guest_ia32_int_ssp_table_addr; +*/ }/*
@@ -1865,12 +1885,23 @@ static void copy_vmcs12_to_enlightened(struct vcpu_vmx *vmx)* evmcs->vm_exit_msr_store_count = vmcs12->vm_exit_msr_store_count; * evmcs->vm_exit_msr_load_count = vmcs12->vm_exit_msr_load_count; * evmcs->vm_entry_msr_load_count = vmcs12->vm_entry_msr_load_count; +* evmcs->guest_ia32_perf_global_ctrl = vmcs12->guest_ia32_perf_global_ctrl; +* evmcs->host_ia32_perf_global_ctrl = vmcs12->host_ia32_perf_global_ctrl; +* evmcs->encls_exiting_bitmap = vmcs12->encls_exiting_bitmap; +* evmcs->tsc_multiplier = vmcs12->tsc_multiplier; * * Not present in struct vmcs12: * evmcs->exit_io_instruction_ecx = vmcs12->exit_io_instruction_ecx; * evmcs->exit_io_instruction_esi = vmcs12->exit_io_instruction_esi; * evmcs->exit_io_instruction_edi = vmcs12->exit_io_instruction_edi; * evmcs->exit_io_instruction_eip = vmcs12->exit_io_instruction_eip; +* evmcs->host_ia32_s_cet = vmcs12->host_ia32_s_cet; +* evmcs->host_ssp = vmcs12->host_ssp; +* evmcs->host_ia32_int_ssp_table_addr = vmcs12->host_ia32_int_ssp_table_addr; +* evmcs->guest_ia32_s_cet = vmcs12->guest_ia32_s_cet; +* evmcs->guest_ia32_lbr_ctl = vmcs12->guest_ia32_lbr_ctl; +* evmcs->guest_ia32_int_ssp_table_addr = vmcs12->guest_ia32_int_ssp_table_addr; +* evmcs->guest_ssp = vmcs12->guest_ssp; */ evmcs->guest_es_selector = vmcs12->guest_es_selector;
Signature · 1 line
2.35.3
Vitaly Kuznetsov
maintainerPATCH v2 6/28 KVM: nVMX: Introduce KVM_CAP_HYPERV_ENLIGHTENED_VMCS2
In reply to Vitaly KuznetsovTurns out Enlightened VMCS can gain new fields without version change and KVM_CAP_HYPERV_ENLIGHTENED_VMCS which KVM currently has cant's handle this reliably. In particular, just updating the current definition of eVMCSv1 with the new fields and adjusting the VMX MSR filtering will inevitably break live migration to older KVMs. Note: enabling eVMCS and setting VMX feature MSR can happen in any order.
Introduce a notion of KVM internal "Enlightened VMCS revision" and add a new capability allowing to add fields to Enlightened VMCS while keeping its version.
--- Documentation/virt/kvm/api.rst | 43 ++++++++++++++++++++++++++++++++- arch/x86/include/asm/kvm_host.h | 2 +- arch/x86/kvm/vmx/evmcs.c | 20 ++++++++++----- arch/x86/kvm/vmx/evmcs.h | 13 ++++++++-- arch/x86/kvm/vmx/nested.c | 10 ++++---- arch/x86/kvm/vmx/vmx.c | 2 +- arch/x86/kvm/vmx/vmx.h | 15 ++++++------ arch/x86/kvm/x86.c | 15 +++++++++++- include/uapi/linux/kvm.h | 3 ++- 9 files changed, 98 insertions(+), 25 deletions(-)
Documentation/virt/kvm/api.rst +42 -1
@@ -4974,7 +4974,7 @@ version has the following quirks: - HYPERV_CPUID_NESTED_FEATURES leaf and HV_X64_ENLIGHTENED_VMCS_RECOMMENDED feature bit are only exposed when Enlightened VMCS was previously enabled - on the corresponding vCPU (KVM_CAP_HYPERV_ENLIGHTENED_VMCS). + on the corresponding vCPU (KVM_CAP_HYPERV_ENLIGHTENED_VMCS2). - HV_STIMER_DIRECT_MODE_AVAILABLE bit is only exposed with in-kernel LAPIC. (presumes KVM_CREATE_IRQCHIP has already been called).
@@ -8223,6 +8223,47 @@ The capability has no effect if the nx_huge_pages module parameter is not set. This capability may only be set before any vCPUs are created. +8.39 KVM_CAP_HYPERV_ENLIGHTENED_VMCS +------------------------------------ + +:Capability: KVM_CAP_HYPERV_ENLIGHTENED_VMCS +:Architectures: x86 +:Type: vcpu +:Parameters: arg[0] is a pointer to uint16_t where the supported Enlightened +VMCS version range will be stored by KVM. +:Returns: 0 on success, -EINVAL when Enlightened VMCS is already enabled, +-EFAULT when write to arg[0] fails. + +This capability enables Enlightened VMCS interface. Obsolete, use +KVM_CAP_HYPERV_ENLIGHTENED_VMCS2 instead. + +8.40 KVM_CAP_HYPERV_ENLIGHTENED_VMCS2 +------------------------------------- + +:Capability: KVM_CAP_HYPERV_ENLIGHTENED_VMCS2 +:Architectures: x86 +:Type: vcpu +:Parameters: arg[0] is the desired Enlightened VMCS revision (uint32_t). Special +value 'U32_MAX' indicates the latest supported revision. (Optional) arg[1] is a +pointer to 'uint16_t' where the supported Enlightened VMCS version range will be +stored by KVM. +:Returns: 0 on success, -ENOTTY on SVM, -EINVAL when Enlightened VMCS is already +enabled or the requested revision is not supported, -EFAULT when write to arg[1] +fails. + +This capability enables Hyper-V Enlightened VMCS interface as described in +Hyper-V Top Level Functional Specification (TLFS). Note: when the interface is +enabled, L1 guest doesn't necessarily have to use it, however, the exposed VMX +features will be limited to what the particular revision of the Enlightened VMCS +supports. + +Enlightened VMCS version range (optionally written to arg[1]) is encoded in the +following way: + ((uint8_t)HIGHEST_SUPPORTED_VERSION << 8) | (uint8_t)LOWEST_SUPPORTED_VERSION + +The interface is only available on VMX. Once set, changing the supported +Enlightened VMCS revision not supported. + 9. Known KVM API problems =========================
arch/x86/include/asm/kvm_host.h +1 -1
@@ -1648,7 +1648,7 @@ struct kvm_x86_nested_ops {bool (*get_nested_state_pages)(struct kvm_vcpu *vcpu);int (*write_log_dirty)(struct kvm_vcpu *vcpu,gpa_t l2_gpa); -int (*enable_evmcs)(struct kvm_vcpu *vcpu, +int (*enable_evmcs)(struct kvm_vcpu *vcpu,u32 evmcs_revision,uint16_t *vmcs_version);uint16_t (*get_evmcs_version)(struct kvm_vcpu *vcpu); };
arch/x86/kvm/vmx/evmcs.c +14 -6
@@ -362,7 +362,7 @@ uint16_t nested_get_evmcs_version(struct kvm_vcpu *vcpu)* KVM_EVMCS_VERSION. */ if (kvm_cpu_cap_get (X86_FEATURE_VMX ) && - (!vcpu ||to_vmx (vcpu)->nested.enlightened_vmcs_enabled)) + (!vcpu ||to_vmx (vcpu)->nested.active_evmcs_revision))return (KVM_EVMCS_VERSION <<8 ) |1 ;return 0 ;
@@ -453,15 +453,23 @@ int nested_evmcs_check_controls(struct vmcs12 *vmcs12)return ret; } -int nested_enable_evmcs (struct kvm_vcpu *vcpu, -uint16_t *vmcs_version) +int nested_enable_evmcs (struct kvm_vcpu *vcpu,u32 evmcs_revision,uint16_t *evmcs_version) {struct vcpu_vmx *vmx =to_vmx (vcpu); - vmx->nested.enlightened_vmcs_enabled = true; +if (evmcs_revision >KVM_EVMCS_REVISION && evmcs_revision !=U32_MAX ) +return -EINVAL ; -if (vmcs_version) - *vmcs_version =nested_get_evmcs_version (vcpu); +/* Disabling or changing active eVMCS version is not supported */ +if (vmx->nested.active_evmcs_revision) +return -EINVAL ; + +if (evmcs_revision !=U32_MAX ) + vmx->nested.active_evmcs_revision = evmcs_revision; +else + vmx->nested.active_evmcs_revision =KVM_EVMCS_REVISION ; + + *evmcs_version =nested_get_evmcs_version (vcpu);return 0 ; }
arch/x86/kvm/vmx/evmcs.h +11 -2
@@ -18,8 +18,18 @@ DECLARE_STATIC_KEY_FALSE(enable_evmcs);#define current_evmcs ((struct hv_enlightened_vmcs *)this_cpu_read(current_vmcs)) +/* +* Maximum supported eVMCS version as described in TLFS, gets reported to the +* guest. +*/ #define KVM_EVMCS_VERSION 1 +/* +* Internal KVM eVMCS revision number, gets bumped when eVMCS needs to be +* updated but its version remain intact. +*/ +#define KVM_EVMCS_REVISION 1 +/* * Enlightened VMCSv1 doesn't support these: *
@@ -241,8 +251,7 @@ enum nested_evmptrld_status {bool nested_enlightened_vmentry (struct kvm_vcpu *vcpu,u64 *evmcs_gpa);uint16_t nested_get_evmcs_version (struct kvm_vcpu *vcpu); -int nested_enable_evmcs (struct kvm_vcpu *vcpu, -uint16_t *vmcs_version); +int nested_enable_evmcs (struct kvm_vcpu *vcpu,u32 evmcs_revision,uint16_t *vmcs_version);void nested_evmcs_filter_control_msr (u32 msr_index,u64 *pdata);int nested_evmcs_check_controls (struct vmcs12 *vmcs12);
arch/x86/kvm/vmx/nested.c +5 -5
@@ -2009,7 +2009,7 @@ static enum nested_evmptrld_status nested_vmx_handle_enlightened_vmptrld(bool evmcs_gpa_changed = false;u64 evmcs_gpa; -if (likely (!vmx->nested.enlightened_vmcs_enabled)) +if (likely (!vmx->nested.active_evmcs_revision))return EVMPTRLD_DISABLED ;if (!nested_enlightened_vmentry (vcpu, &evmcs_gpa)) {
@@ -2890,7 +2890,7 @@ static int nested_vmx_check_controls(struct kvm_vcpu *vcpu, nested_check_vm_entry_controls(vcpu, vmcs12))return -EINVAL ; -if (to_vmx (vcpu)->nested.enlightened_vmcs_enabled) +if (to_vmx (vcpu)->nested.active_evmcs_revision)return nested_evmcs_check_controls (vmcs12);return 0 ;
@@ -3172,7 +3172,7 @@ static bool nested_get_evmcs_page(struct kvm_vcpu *vcpu)* L2 was running), map it here to make sure vmcs12 changes are * properly reflected. */ -if (vmx->nested.enlightened_vmcs_enabled && +if (vmx->nested.active_evmcs_revision && vmx->nested.hv_evmcs_vmptr ==EVMPTR_MAP_PENDING ) {enum nested_evmptrld_status evmptrld_status =nested_vmx_handle_enlightened_vmptrld (vcpu, false);
@@ -5110,7 +5110,7 @@ static int handle_vmclear(struct kvm_vcpu *vcpu)* state. It is possible that the area will stay mapped as * vmx->nested.hv_evmcs but this shouldn't be a problem. */ -if (likely (!vmx->nested.enlightened_vmcs_enabled || +if (likely (!vmx->nested.active_evmcs_revision || !nested_enlightened_vmentry (vcpu, &evmcs_gpa))) {if (vmptr == vmx->nested.current_vmptr)nested_release_vmcs12 (vcpu);
@@ -6399,7 +6399,7 @@ static int vmx_set_nested_state(struct kvm_vcpu *vcpu,return -EINVAL ;if ((kvm_state->flags &KVM_STATE_NESTED_EVMCS ) && - (!nested_vmx_allowed (vcpu) || !vmx->nested.enlightened_vmcs_enabled)) + (!nested_vmx_allowed (vcpu) || !vmx->nested.active_evmcs_revision))return -EINVAL ;vmx_leave_nested (vcpu);
arch/x86/kvm/vmx/vmx.c +1 -1
@@ -1857,7 +1857,7 @@ static int vmx_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)* features out. */ if (!msr_info->host_initiated && - vmx->nested.enlightened_vmcs_enabled) + vmx->nested.active_evmcs_revision)nested_evmcs_filter_control_msr (msr_info->index, &msr_info->data);break ;
arch/x86/kvm/vmx/vmx.h +8 -7
@@ -185,13 +185,6 @@ struct nested_vmx {bool update_vmcs01_cpu_dirty_logging;bool update_vmcs01_apicv_status; -/* -* Enlightened VMCS has been enabled. It does not mean that L1 has to -* use it. However, VMX features available to L1 will be limited based -* on what the enlightened VMCS supports. -*/ -bool enlightened_vmcs_enabled; -/* L2 must run next, and mustn't decide to exit to L1. */ bool nested_run_pending;
@@ -248,6 +241,14 @@ struct nested_vmx {bool guest_mode; } smm; +/* +* Enlightened VMCS revision enabled (1..KVM_EVMCS_REVISION) on the vCPU. +* When, enabled, L1 doesn't necessarily have to use eVMCS interface, +* however, the exposed VMX features will be limited to what the particular +* revision of eVMCS supports. +*/ +u32 active_evmcs_revision; +gpa_t hv_evmcs_vmptr;struct kvm_host_map hv_evmcs_map;struct hv_enlightened_vmcs *hv_evmcs;
arch/x86/kvm/x86.c +14 -1
@@ -4444,6 +4444,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) r = kvm_x86_ops.enable_direct_tlbflush !=NULL ;break ;case KVM_CAP_HYPERV_ENLIGHTENED_VMCS : +case KVM_CAP_HYPERV_ENLIGHTENED_VMCS2 : r = kvm_x86_ops.nested_ops->enable_evmcs !=NULL ;break ;case KVM_CAP_SMALLER_MAXPHYADDR :
@@ -5421,7 +5422,8 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu,case KVM_CAP_HYPERV_ENLIGHTENED_VMCS :if (!kvm_x86_ops.nested_ops->enable_evmcs)return -ENOTTY ; - r = kvm_x86_ops.nested_ops->enable_evmcs (vcpu, &vmcs_version); +/* Legacy: enable rev.1 */ + r = kvm_x86_ops.nested_ops->enable_evmcs (vcpu,1 , &vmcs_version);if (!r) { user_ptr = (void __user *)(uintptr_t )cap->args[0 ]; if (copy_to_user(user_ptr, &vmcs_version,
@@ -5429,6 +5431,17 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu, r = -EFAULT ; }return r; +case KVM_CAP_HYPERV_ENLIGHTENED_VMCS2 : +if (!kvm_x86_ops.nested_ops->enable_evmcs) +return -ENOTTY ; + r = kvm_x86_ops.nested_ops->enable_evmcs (vcpu, cap->args[0 ], &vmcs_version); +if (!r && cap->args[1 ]) { + user_ptr = (void __user *)(uintptr_t )cap->args[1 ]; +if (copy_to_user (user_ptr, &vmcs_version, +sizeof (vmcs_version))) + r = -EFAULT ; + } +return r;case KVM_CAP_HYPERV_DIRECT_TLBFLUSH :if (!kvm_x86_ops.enable_direct_tlbflush)return -ENOTTY ;
include/uapi/linux/kvm.h +2 -1
@@ -1109,7 +1109,7 @@ struct kvm_ppc_resize_hpt {#define KVM_CAP_PPC_NESTED_HV 160#define KVM_CAP_HYPERV_SEND_IPI 161#define KVM_CAP_COALESCED_PIO 162 -#define KVM_CAP_HYPERV_ENLIGHTENED_VMCS 163 +#define KVM_CAP_HYPERV_ENLIGHTENED_VMCS 163/* Obsolete */ #define KVM_CAP_EXCEPTION_PAYLOAD 164#define KVM_CAP_ARM_VM_IPA_SIZE 165#define KVM_CAP_MANUAL_DIRTY_LOG_PROTECT 166/* Obsolete */
@@ -1167,6 +1167,7 @@ struct kvm_ppc_resize_hpt {#define KVM_CAP_X86_TRIPLE_FAULT_EVENT 218#define KVM_CAP_X86_NOTIFY_VMEXIT 219#define KVM_CAP_VM_DISABLE_NX_HUGE_PAGES 220 +#define KVM_CAP_HYPERV_ENLIGHTENED_VMCS2 221#ifdef KVM_CAP_IRQ_ROUTING
Signature · 1 line
2.35.3
Vitaly Kuznetsov
maintainerPATCH v2 8/28 KVM: VMX: Support TSC scaling with enlightened VMCS
In reply to Vitaly KuznetsovEnlightened VMCS v1 now includes the required field for TSC scaling feature so SECONDARY_EXEC_TSC_SCALING doesn't need to be filtered out, both for KVM on Hyper-V and Hyper-V on KVM cases.
Note: Hyper-V on KVM case requires bumping KVM_EVMCS_REVISION revision so VMMs can specify if SECONDARY_EXEC_TSC_SCALING needs to be filtered out or not, this is required to support live migration.
While on it, update the comment why VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL/ VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL are kept filtered out and add missing spaces in trace_kvm_nested_vmenter_failed() strings making the output ugly.
--- arch/x86/kvm/vmx/evmcs.c | 70 +++++++++++++++++++++++++++++---------- arch/x86/kvm/vmx/evmcs.h | 17 ++++------ arch/x86/kvm/vmx/nested.c | 2 +- arch/x86/kvm/vmx/vmx.c | 2 +- 4 files changed, 62 insertions(+), 29 deletions(-)
arch/x86/kvm/vmx/evmcs.c +53 -17
@@ -368,7 +368,42 @@ uint16_t nested_get_evmcs_version(struct kvm_vcpu *vcpu)return 0 ; } -void nested_evmcs_filter_control_msr (u32 msr_index,u64 *pdata) +enum evmcs_unsupported_ctrl_type { +EVMCS_EXIT_CTLS , +EVMCS_ENTRY_CTLS , +EVMCS_2NDEXEC , +EVMCS_PINCTRL , +EVMCS_VMFUNC , +}; + +static u32 evmcs_get_unsupported_ctls (struct kvm_vcpu *vcpu, +enum evmcs_unsupported_ctrl_type ctrl_type) +{ +u32 evmcs_rev =to_vmx (vcpu)->nested.active_evmcs_revision; + +if (!evmcs_rev) +return 0 ; + +switch (ctrl_type) { +case EVMCS_EXIT_CTLS : +return EVMCS1_UNSUPPORTED_VMEXIT_CTRL ; +case EVMCS_ENTRY_CTLS : +return EVMCS1_UNSUPPORTED_VMENTRY_CTRL ; +case EVMCS_2NDEXEC : +if (evmcs_rev ==1 ) +return EVMCS1_UNSUPPORTED_2NDEXEC |SECONDARY_EXEC_TSC_SCALING ; +else +return EVMCS1_UNSUPPORTED_2NDEXEC ; +case EVMCS_PINCTRL : +return EVMCS1_UNSUPPORTED_PINCTRL ; +case EVMCS_VMFUNC : +return EVMCS1_UNSUPPORTED_VMFUNC ; + } + +return 0 ; +} + +void nested_evmcs_filter_control_msr (struct kvm_vcpu *vcpu,u32 msr_index,u64 *pdata) {u32 ctl_low = (u32)*pdata;u32 ctl_high = (u32)(*pdata >>32 );
@@ -380,72 +415,73 @@ void nested_evmcs_filter_control_msr(u32 msr_index, u64 *pdata)switch (msr_index) {case MSR_IA32_VMX_EXIT_CTLS :case MSR_IA32_VMX_TRUE_EXIT_CTLS : - ctl_high &= ~EVMCS1_UNSUPPORTED_VMEXIT_CTRL ; + ctl_high &= ~evmcs_get_unsupported_ctls (vcpu,EVMCS_EXIT_CTLS );break ;case MSR_IA32_VMX_ENTRY_CTLS :case MSR_IA32_VMX_TRUE_ENTRY_CTLS : - ctl_high &= ~EVMCS1_UNSUPPORTED_VMENTRY_CTRL ; + ctl_high &= ~evmcs_get_unsupported_ctls (vcpu,EVMCS_ENTRY_CTLS );break ;case MSR_IA32_VMX_PROCBASED_CTLS2 : - ctl_high &= ~EVMCS1_UNSUPPORTED_2NDEXEC ; + ctl_high &= ~evmcs_get_unsupported_ctls (vcpu,EVMCS_2NDEXEC );break ;case MSR_IA32_VMX_TRUE_PINBASED_CTLS :case MSR_IA32_VMX_PINBASED_CTLS : - ctl_high &= ~EVMCS1_UNSUPPORTED_PINCTRL ; + ctl_high &= ~evmcs_get_unsupported_ctls (vcpu,EVMCS_PINCTRL );break ;case MSR_IA32_VMX_VMFUNC : - ctl_low &= ~EVMCS1_UNSUPPORTED_VMFUNC ; + ctl_low &= ~evmcs_get_unsupported_ctls (vcpu,EVMCS_VMFUNC );break ; } *pdata = ctl_low | ((u64 )ctl_high <<32 ); } -int nested_evmcs_check_controls (struct vmcs12 *vmcs12) +int nested_evmcs_check_controls (struct kvm_vcpu *vcpu,struct vmcs12 *vmcs12) {int ret =0 ;u32 unsupp_ctl; unsupp_ctl = vmcs12->pin_based_vm_exec_control & -EVMCS1_UNSUPPORTED_PINCTRL ; +evmcs_get_unsupported_ctls (vcpu,EVMCS_PINCTRL );if (unsupp_ctl) {trace_kvm_nested_vmenter_failed ( -"eVMCS: unsupported pin-based VM-execution controls" , +"eVMCS: unsupported pin-based VM-execution controls: " , unsupp_ctl); ret = -EINVAL ; } unsupp_ctl = vmcs12->secondary_vm_exec_control & -EVMCS1_UNSUPPORTED_2NDEXEC ; +evmcs_get_unsupported_ctls (vcpu,EVMCS_2NDEXEC );if (unsupp_ctl) {trace_kvm_nested_vmenter_failed ( -"eVMCS: unsupported secondary VM-execution controls" , +"eVMCS: unsupported secondary VM-execution controls: " , unsupp_ctl); ret = -EINVAL ; } unsupp_ctl = vmcs12->vm_exit_controls & -EVMCS1_UNSUPPORTED_VMEXIT_CTRL ; +evmcs_get_unsupported_ctls (vcpu,EVMCS_EXIT_CTLS );if (unsupp_ctl) {trace_kvm_nested_vmenter_failed ( -"eVMCS: unsupported VM-exit controls" , +"eVMCS: unsupported VM-exit controls: " , unsupp_ctl); ret = -EINVAL ; } unsupp_ctl = vmcs12->vm_entry_controls & -EVMCS1_UNSUPPORTED_VMENTRY_CTRL ; +evmcs_get_unsupported_ctls (vcpu,EVMCS_ENTRY_CTLS );if (unsupp_ctl) {trace_kvm_nested_vmenter_failed ( -"eVMCS: unsupported VM-entry controls" , +"eVMCS: unsupported VM-entry controls: " , unsupp_ctl); ret = -EINVAL ; } - unsupp_ctl = vmcs12->vm_function_control &EVMCS1_UNSUPPORTED_VMFUNC ; + unsupp_ctl = vmcs12->vm_function_control & +evmcs_get_unsupported_ctls (vcpu,EVMCS_VMFUNC );if (unsupp_ctl) {trace_kvm_nested_vmenter_failed ( -"eVMCS: unsupported VM-function controls" , +"eVMCS: unsupported VM-function controls: " , unsupp_ctl); ret = -EINVAL ; }
arch/x86/kvm/vmx/evmcs.h +7 -10
@@ -28,7 +28,7 @@ DECLARE_STATIC_KEY_FALSE(enable_evmcs);* Internal KVM eVMCS revision number, gets bumped when eVMCS needs to be * updated but its version remain intact. */ -#define KVM_EVMCS_REVISION 1 +#define KVM_EVMCS_REVISION 2/* * Enlightened VMCSv1 doesn't support these:
@@ -47,16 +47,14 @@ DECLARE_STATIC_KEY_FALSE(enable_evmcs);* 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, +* While GUEST_IA32_PERF_GLOBAL_CTRL and HOST_IA32_PERF_GLOBAL_CTRL +* are present in eVMCSv1, Windows 11 still has issues booting when +* VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL/VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL +* are exposed to it, keep them filtered out. */ #define EVMCS1_UNSUPPORTED_PINCTRL (PIN_BASED_POSTED_INTR | \ PIN_BASED_VMX_PREEMPTION_TIMER)
@@ -68,7 +66,6 @@ DECLARE_STATIC_KEY_FALSE(enable_evmcs); 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 | \
@@ -252,7 +249,7 @@ enum nested_evmptrld_status {bool nested_enlightened_vmentry (struct kvm_vcpu *vcpu,u64 *evmcs_gpa);uint16_t nested_get_evmcs_version (struct kvm_vcpu *vcpu);int nested_enable_evmcs (struct kvm_vcpu *vcpu,u32 evmcs_revision,uint16_t *vmcs_version); -void nested_evmcs_filter_control_msr (u32 msr_index,u64 *pdata); -int nested_evmcs_check_controls (struct vmcs12 *vmcs12); +void nested_evmcs_filter_control_msr (struct kvm_vcpu *vcpu,u32 msr_index,u64 *pdata); +int nested_evmcs_check_controls (struct kvm_vcpu *vcpu,struct vmcs12 *vmcs12);#endif /* __KVM_X86_VMX_EVMCS_H */
arch/x86/kvm/vmx/nested.c +1 -1
@@ -2891,7 +2891,7 @@ static int nested_vmx_check_controls(struct kvm_vcpu *vcpu,return -EINVAL ;if (to_vmx (vcpu)->nested.active_evmcs_revision) -return nested_evmcs_check_controls (vmcs12); +return nested_evmcs_check_controls (vcpu, vmcs12);return 0 ; }
arch/x86/kvm/vmx/vmx.c +1 -1
@@ -1858,7 +1858,7 @@ static int vmx_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)*/ if (!msr_info->host_initiated && vmx->nested.active_evmcs_revision) -nested_evmcs_filter_control_msr (msr_info->index, +nested_evmcs_filter_control_msr (vcpu, msr_info->index, &msr_info->data);break ;case MSR_IA32_RTIT_CTL :
Signature · 1 line
2.35.3
Vitaly Kuznetsov
maintainerPATCH v2 7/28 KVM: selftests: Switch to KVM_CAP_HYPERV_ENLIGHTENED_VMCS2
In reply to Vitaly KuznetsovKVM_CAP_HYPERV_ENLIGHTENED_VMCS was obsoleted by KVM_CAP_HYPERV_ENLIGHTENED_VMCS2, use it in selftests.
--- tools/testing/selftests/kvm/include/kvm_util_base.h | 8 ++++++++ tools/testing/selftests/kvm/include/x86_64/evmcs.h | 1 + tools/testing/selftests/kvm/lib/x86_64/vmx.c | 5 +++-- tools/testing/selftests/kvm/x86_64/evmcs_test.c | 2 +- tools/testing/selftests/kvm/x86_64/hyperv_cpuid.c | 2 +- .../selftests/kvm/x86_64/vmx_set_nested_state_test.c | 2 +- 6 files changed, 15 insertions(+), 5 deletions(-)
tools/testing/selftests/kvm/include/kvm_util_base.h +8 -0
@@ -406,6 +406,14 @@ static inline void vcpu_enable_cap(struct kvm_vcpu *vcpu, uint32_t cap,vcpu_ioctl (vcpu,KVM_ENABLE_CAP , &enable_cap); } +static inline void vcpu_enable_cap2 (struct kvm_vcpu *vcpu,uint32_t cap, +uint64_t arg0,uint64_t arg1) +{ +struct kvm_enable_cap enable_cap = { .cap = cap, .args = { arg0, arg1 } }; + +vcpu_ioctl (vcpu,KVM_ENABLE_CAP , &enable_cap); +} +static inline void vcpu_guest_debug_set (struct kvm_vcpu *vcpu,struct kvm_guest_debug *debug) {
tools/testing/selftests/kvm/include/x86_64/evmcs.h +1 -0
@@ -17,6 +17,7 @@#define u64 uint64_t#define EVMCS_VERSION 1 +#define EVMCS_REVISION 1extern bool enable_evmcs;
tools/testing/selftests/kvm/lib/x86_64/vmx.c +3 -2
@@ -42,12 +42,13 @@ struct eptPageTablePointer { uint64_t address:40; uint64_t reserved_63_52:12; }; +int vcpu_enable_evmcs (struct kvm_vcpu *vcpu) {uint16_t evmcs_ver; -vcpu_enable_cap (vcpu,KVM_CAP_HYPERV_ENLIGHTENED_VMCS , - (unsigned long )&evmcs_ver); +vcpu_enable_cap2 (vcpu,KVM_CAP_HYPERV_ENLIGHTENED_VMCS2 , +EVMCS_REVISION , (unsigned long )&evmcs_ver);/* KVM should return supported EVMCS version range */ TEST_ASSERT(((evmcs_ver >> 8) >= (evmcs_ver & 0xff)) &&
tools/testing/selftests/kvm/x86_64/evmcs_test.c +1 -1
@@ -210,7 +210,7 @@ int main(int argc, char *argv[])TEST_REQUIRE (nested_vmx_supported ());TEST_REQUIRE (kvm_has_cap (KVM_CAP_NESTED_STATE )); -TEST_REQUIRE (kvm_has_cap (KVM_CAP_HYPERV_ENLIGHTENED_VMCS )); +TEST_REQUIRE (kvm_has_cap (KVM_CAP_HYPERV_ENLIGHTENED_VMCS2 ));vcpu_set_hv_cpuid (vcpu);vcpu_enable_evmcs (vcpu);
tools/testing/selftests/kvm/x86_64/hyperv_cpuid.c +1 -1
@@ -149,7 +149,7 @@ int main(int argc, char *argv[])free (hv_cpuid_entries);if (!nested_vmx_supported () || - !kvm_has_cap (KVM_CAP_HYPERV_ENLIGHTENED_VMCS )) { + !kvm_has_cap (KVM_CAP_HYPERV_ENLIGHTENED_VMCS2 )) {print_skip ("Enlightened VMCS is unsupported" ); goto do_sys; }
tools/testing/selftests/kvm/x86_64/vmx_set_nested_state_test.c +1 -1
@@ -265,7 +265,7 @@ int main(int argc, char *argv[])struct kvm_nested_state state;struct kvm_vcpu *vcpu; - have_evmcs =kvm_check_cap (KVM_CAP_HYPERV_ENLIGHTENED_VMCS ); + have_evmcs =kvm_check_cap (KVM_CAP_HYPERV_ENLIGHTENED_VMCS2 );TEST_REQUIRE (kvm_has_cap (KVM_CAP_NESTED_STATE ));
Signature · 1 line
2.35.3
Vitaly Kuznetsov
maintainerPATCH v2 9/28 KVM: selftests: Add ENCLS_EXITING_BITMAP{,HIGH} VMCS fields
In reply to Vitaly KuznetsovThe updated Enlightened VMCS definition has 'encls_exiting_bitmap' field which needs mapping to VMCS, add the missing encoding.
--- tools/testing/selftests/kvm/include/x86_64/vmx.h | 2 ++ 1 file changed, 2 insertions(+)
tools/testing/selftests/kvm/include/x86_64/vmx.h +2 -0
@@ -208,6 +208,8 @@ enum vmcs_field {VMWRITE_BITMAP_HIGH =0x00002029 ,XSS_EXIT_BITMAP =0x0000202C ,XSS_EXIT_BITMAP_HIGH =0x0000202D , +ENCLS_EXITING_BITMAP =0x0000202E , +ENCLS_EXITING_BITMAP_HIGH =0x0000202F ,TSC_MULTIPLIER =0x00002032 ,TSC_MULTIPLIER_HIGH =0x00002033 , GUEST_PHYSICAL_ADDRESS = 0x00002400,
Signature · 1 line
2.35.3
Vitaly Kuznetsov
maintainerPATCH v2 10/28 KVM: selftests: Switch to updated eVMCSv1 definition
In reply to Vitaly KuznetsovUpdate Enlightened VMCS definition in selftests from KVM and switch to using EVMCS_REVISION 2 which supports these new fields.
--- .../selftests/kvm/include/x86_64/evmcs.h | 47 +++++++++++++++++-- 1 file changed, 43 insertions(+), 4 deletions(-)
tools/testing/selftests/kvm/include/x86_64/evmcs.h +43 -4
@@ -17,7 +17,7 @@#define u64 uint64_t#define EVMCS_VERSION 1 -#define EVMCS_REVISION 1 +#define EVMCS_REVISION 2extern bool enable_evmcs;
@@ -204,14 +204,25 @@ struct hv_enlightened_vmcs { u32 reserved:30; } hv_enlightenments_control;u32 hv_vp_id; - +u32 padding32_2;u64 hv_vm_id;u64 partition_assist_page;u64 padding64_4[4 ];u64 guest_bndcfgs; -u64 padding64_5[7 ]; +u64 guest_ia32_perf_global_ctrl; +u64 guest_ia32_s_cet; +u64 guest_ssp; +u64 guest_ia32_int_ssp_table_addr; +u64 guest_ia32_lbr_ctl; +u64 padding64_5[2 ];u64 xss_exit_bitmap; -u64 padding64_6[7 ]; +u64 host_ia32_perf_global_ctrl; +u64 encls_exiting_bitmap; +u64 tsc_multiplier; +u64 host_ia32_s_cet; +u64 host_ssp; +u64 host_ia32_int_ssp_table_addr; +u64 padding64_6; };#define HV_VMX_ENLIGHTENED_CLEAN_FIELD_NONE 0
@@ -657,6 +668,18 @@ static inline int evmcs_vmread(uint64_t encoding, uint64_t *value)case VIRTUAL_PROCESSOR_ID : *value = current_evmcs->virtual_processor_id;break ; +case HOST_IA32_PERF_GLOBAL_CTRL : + *value = current_evmcs->host_ia32_perf_global_ctrl; +break ; +case GUEST_IA32_PERF_GLOBAL_CTRL : + *value = current_evmcs->guest_ia32_perf_global_ctrl; +break ; +case ENCLS_EXITING_BITMAP : + *value = current_evmcs->encls_exiting_bitmap; +break ; +case TSC_MULTIPLIER : + *value = current_evmcs->tsc_multiplier; +break ;default :return 1 ; }
@@ -1170,6 +1193,22 @@ static inline int evmcs_vmwrite(uint64_t encoding, uint64_t value) current_evmcs->virtual_processor_id = value; current_evmcs->hv_clean_fields &= ~HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_XLAT ;break ; +case HOST_IA32_PERF_GLOBAL_CTRL : + current_evmcs->host_ia32_perf_global_ctrl = value; + current_evmcs->hv_clean_fields &= ~HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1 ; +break ; +case GUEST_IA32_PERF_GLOBAL_CTRL : + current_evmcs->guest_ia32_perf_global_ctrl = value; + current_evmcs->hv_clean_fields &= ~HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1 ; +break ; +case ENCLS_EXITING_BITMAP : + current_evmcs->encls_exiting_bitmap = value; + current_evmcs->hv_clean_fields &= ~HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_GRP2 ; +break ; +case TSC_MULTIPLIER : + current_evmcs->tsc_multiplier = value; + current_evmcs->hv_clean_fields &= ~HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_GRP2 ; +break ;default :return 1 ; }
Signature · 1 line
2.35.3
Vitaly Kuznetsov
maintainerPATCH v2 11/28 KVM: selftests: Enable TSC scaling in evmcs selftest
In reply to Vitaly KuznetsovThe updated Enlightened VMCS v1 definition enables TSC scaling, test that SECONDARY_EXEC_TSC_SCALING can now be enabled.
--- .../testing/selftests/kvm/x86_64/evmcs_test.c | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-)
tools/testing/selftests/kvm/x86_64/evmcs_test.c +29 -2
@@ -18,6 +18,9 @@#include "vmx.h" +/* Test flags */ +#define HOST_HAS_TSC_SCALING BIT(0) +static int ud_count;static void guest_ud_handler (struct ex_regs *regs)
@@ -64,11 +67,14 @@ void l2_guest_code(void)vmcall ();rdmsr_gs_base ();/* intercepted */ +/* TSC scaling */ +vmcall (); +/* Done, exit to L1 and never come back. */ vmcall (); } -void guest_code (struct vmx_pages *vmx_pages) +void guest_code (struct vmx_pages *vmx_pages,u64 test_flags) {#define L2_GUEST_STACK_SIZE 64unsigned long l2_guest_stack[L2_GUEST_STACK_SIZE ];
@@ -150,6 +156,18 @@ void guest_code(struct vmx_pages *vmx_pages)GUEST_ASSERT (vmreadz (VM_EXIT_REASON ) ==EXIT_REASON_VMCALL );GUEST_SYNC (11 ); +if (test_flags &HOST_HAS_TSC_SCALING ) { +GUEST_ASSERT ((rdmsr (MSR_IA32_VMX_PROCBASED_CTLS2 ) >>32 ) & +SECONDARY_EXEC_TSC_SCALING ); +/* Try enabling TSC scaling */ +vmwrite (SECONDARY_VM_EXEC_CONTROL ,vmreadz (SECONDARY_VM_EXEC_CONTROL ) | +SECONDARY_EXEC_TSC_SCALING ); +vmwrite (TSC_MULTIPLIER ,1 ); + } +GUEST_ASSERT (!vmresume ()); +GUEST_ASSERT (vmreadz (VM_EXIT_REASON ) ==EXIT_REASON_VMCALL ); +GUEST_SYNC (12 ); +/* Try enlightened vmptrld with an incorrect GPA */ evmcs_vmptrld (0xdeadbeef , vmx_pages->enlightened_vmcs);GUEST_ASSERT (vmlaunch ());
@@ -204,6 +222,7 @@ int main(int argc, char *argv[])struct kvm_vm *vm;struct kvm_run *run;struct ucall uc; +u64 test_flags =0 ;int stage; vm =vm_create_with_one_vcpu (&vcpu, guest_code);
@@ -212,11 +231,19 @@ int main(int argc, char *argv[])TEST_REQUIRE (kvm_has_cap (KVM_CAP_NESTED_STATE ));TEST_REQUIRE (kvm_has_cap (KVM_CAP_HYPERV_ENLIGHTENED_VMCS2 )); +if ((kvm_get_feature_msr (MSR_IA32_VMX_PROCBASED_CTLS2 ) >>32 ) & +SECONDARY_EXEC_TSC_SCALING ) { + test_flags |=HOST_HAS_TSC_SCALING ; +pr_info ("TSC scaling is supported, adding to test\n" ); + }else { +pr_info ("TSC scaling is not supported\n" ); + } +vcpu_set_hv_cpuid (vcpu);vcpu_enable_evmcs (vcpu);vcpu_alloc_vmx (vm, &vmx_pages_gva); -vcpu_args_set (vcpu,1 , vmx_pages_gva); +vcpu_args_set (vcpu,2 , vmx_pages_gva, test_flags);vm_init_descriptor_tables (vm);vcpu_init_descriptor_tables (vcpu);
Signature · 1 line
2.35.3
Vitaly Kuznetsov
maintainerPATCH v2 12/28 KVM: VMX: Enable VM_{EXIT,ENTRY}_LOAD_IA32_PERF_GLOBAL_CTRL for KVM on Hyper-V
In reply to Vitaly KuznetsovThe updated Enlightened VMCS v1 specification gained {guest,host}_ia32_perf_global_ctrl fields so there's no need to filter VM_{EXIT,ENTRY}_LOAD_IA32_PERF_GLOBAL_CTRL out. Unfortunately, enabling these controls for Hyper-V on KVM results in boot time crashes and the exact reason is not clear yet. It is, however, possible to enable the feature for KVM on Hyper-V as it seems to work.
--- arch/x86/kvm/vmx/evmcs.c | 10 ++++++++-- arch/x86/kvm/vmx/evmcs.h | 5 ++--- 2 files changed, 10 insertions(+), 5 deletions(-)
arch/x86/kvm/vmx/evmcs.c +8 -2
@@ -384,11 +384,17 @@ static u32 evmcs_get_unsupported_ctls(struct kvm_vcpu *vcpu,if (!evmcs_rev)return 0 ; +/* +* While GUEST_IA32_PERF_GLOBAL_CTRL and HOST_IA32_PERF_GLOBAL_CTRL +* are present in eVMCSv1, Windows 11 still has issues booting when +* VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL/VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL +* are exposed to it, keep them filtered out. +*/ switch (ctrl_type) {case EVMCS_EXIT_CTLS : -return EVMCS1_UNSUPPORTED_VMEXIT_CTRL ; +return EVMCS1_UNSUPPORTED_VMEXIT_CTRL |VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL ;case EVMCS_ENTRY_CTLS : -return EVMCS1_UNSUPPORTED_VMENTRY_CTRL ; +return EVMCS1_UNSUPPORTED_VMENTRY_CTRL |VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL ;case EVMCS_2NDEXEC :if (evmcs_rev ==1 )return EVMCS1_UNSUPPORTED_2NDEXEC |SECONDARY_EXEC_TSC_SCALING ;
arch/x86/kvm/vmx/evmcs.h +2 -3
@@ -68,9 +68,8 @@ DECLARE_STATIC_KEY_FALSE(enable_evmcs); SECONDARY_EXEC_SHADOW_VMCS | \ SECONDARY_EXEC_PAUSE_LOOP_EXITING)#define EVMCS1_UNSUPPORTED_VMEXIT_CTRL \ - (VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL | \ - VM_EXIT_SAVE_VMX_PREEMPTION_TIMER) -#define EVMCS1_UNSUPPORTED_VMENTRY_CTRL (VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL) + (VM_EXIT_SAVE_VMX_PREEMPTION_TIMER) +#define EVMCS1_UNSUPPORTED_VMENTRY_CTRL (0)#define EVMCS1_UNSUPPORTED_VMFUNC (VMX_VMFUNC_EPTP_SWITCHING)struct evmcs_field {
Signature · 1 line
2.35.3
Vitaly Kuznetsov
maintainerPATCH v2 13/28 KVM: VMX: Get rid of eVMCS specific VMX controls sanitization
In reply to Vitaly KuznetsovWith the updated eVMCSv1 definition, there's no known 'problematic' controls which are exposed in VMX control MSRs but are not present in eVMCSv1. Get rid of the filtering.
--- arch/x86/kvm/vmx/evmcs.c | 13 ------------- arch/x86/kvm/vmx/evmcs.h | 1 - arch/x86/kvm/vmx/vmx.c | 5 ----- 3 files changed, 19 deletions(-)
arch/x86/kvm/vmx/evmcs.c +0 -13
@@ -320,19 +320,6 @@ const struct evmcs_field vmcs_field_to_evmcs_1[] = { };const unsigned int nr_evmcs_1_fields =ARRAY_SIZE (vmcs_field_to_evmcs_1); -#if IS_ENABLED (CONFIG_HYPERV ) -__init void evmcs_sanitize_exec_ctrls (struct vmcs_config *vmcs_conf) -{ - vmcs_conf->cpu_based_exec_ctrl &= ~EVMCS1_UNSUPPORTED_EXEC_CTRL ; - vmcs_conf->pin_based_exec_ctrl &= ~EVMCS1_UNSUPPORTED_PINCTRL ; - vmcs_conf->cpu_based_2nd_exec_ctrl &= ~EVMCS1_UNSUPPORTED_2NDEXEC ; - vmcs_conf->cpu_based_3rd_exec_ctrl =0 ; - - vmcs_conf->vmexit_ctrl &= ~EVMCS1_UNSUPPORTED_VMEXIT_CTRL ; - vmcs_conf->vmentry_ctrl &= ~EVMCS1_UNSUPPORTED_VMENTRY_CTRL ; -} -#endif -bool nested_enlightened_vmentry (struct kvm_vcpu *vcpu,u64 *evmcs_gpa) {struct hv_vp_assist_page assist_page;
arch/x86/kvm/vmx/evmcs.h +0 -1
@@ -218,7 +218,6 @@ static inline void evmcs_load(u64 phys_addr) vp_ap->enlighten_vmentry =1 ; } -__init void evmcs_sanitize_exec_ctrls (struct vmcs_config *vmcs_conf);#else /* !IS_ENABLED(CONFIG_HYPERV) */ static __always_inline void evmcs_write64(unsigned long field, u64 value) {}static inline void evmcs_write32 (unsigned long field,u32 value) {}
arch/x86/kvm/vmx/vmx.c +0 -5
@@ -2689,11 +2689,6 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf, vmcs_conf->vmexit_ctrl = _vmexit_control; vmcs_conf->vmentry_ctrl = _vmentry_control; -#if IS_ENABLED (CONFIG_HYPERV ) -if (enlightened_vmcs) -evmcs_sanitize_exec_ctrls (vmcs_conf); -#endif -return 0 ; }
Signature · 1 line
2.35.3
Vitaly Kuznetsov
maintainerPATCH v2 14/28 KVM: VMX: Check VM_ENTRY_IA32E_MODE in setup_vmcs_config()
In reply to Vitaly KuznetsovVM_ENTRY_IA32E_MODE control is toggled dynamically by vmx_set_efer() and setup_vmcs_config() doesn't check its existence. On the contrary, nested_vmx_setup_ctls_msrs() doesn set it on x86_64. Add the missing check and filter the bit out in vmx_vmentry_ctrl().
No (real) functional change intended as all existing CPUs supporting long mode and VMX are supposed to have it.
--- arch/x86/kvm/vmx/vmx.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
arch/x86/kvm/vmx/vmx.c +12 -3
@@ -2610,6 +2610,9 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf, _pin_based_exec_control &= ~PIN_BASED_POSTED_INTR ; min =VM_ENTRY_LOAD_DEBUG_CONTROLS ; +#ifdef CONFIG_X86_64 + min |=VM_ENTRY_IA32E_MODE ; +#endif opt =VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL |VM_ENTRY_LOAD_IA32_PAT | VM_ENTRY_LOAD_IA32_EFER |
@@ -4242,9 +4245,15 @@ static u32 vmx_vmentry_ctrl(void)if (vmx_pt_mode_is_system ()) vmentry_ctrl &= ~(VM_ENTRY_PT_CONCEAL_PIP |VM_ENTRY_LOAD_IA32_RTIT_CTL ); -/* Loading of EFER and PERF_GLOBAL_CTRL are toggled dynamically */ -return vmentry_ctrl & - ~(VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL |VM_ENTRY_LOAD_IA32_EFER ); +/* +* Loading of EFER, VM_ENTRY_IA32E_MODE, and PERF_GLOBAL_CTRL +* are toggled dynamically. +*/ + vmentry_ctrl &= ~(VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL | +VM_ENTRY_LOAD_IA32_EFER | +VM_ENTRY_IA32E_MODE ); + +return vmentry_ctrl; }static u32 vmx_vmexit_ctrl (void )
Signature · 1 line
2.35.3
Vitaly Kuznetsov
maintainerPATCH v2 16/28 KVM: VMX: Tweak the special handling of SECONDARY_EXEC_ENCLS_EXITING in setup_vmcs_config()
In reply to Vitaly KuznetsovSECONDARY_EXEC_ENCLS_EXITING is conditionally added to the 'optional' checklist in setup_vmcs_config() but there's little value in doing so. First, as the control is optional, we can always check for its presence, no harm done. Second, the only real value cpu_has_sgx() check gives is that on the CPUs which support SECONDARY_EXEC_ENCLS_EXITING but don't support SGX, the control is not getting enabled. It's highly unlikely such CPUs exist but it's possible that some hypervisors expose broken vCPU models.
Preserve cpu_has_sgx() check but filter the result of adjust_vmx_controls() instead of the input.
--- arch/x86/kvm/vmx/vmx.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
arch/x86/kvm/vmx/vmx.c +6 -3
@@ -2528,9 +2528,9 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf,SECONDARY_EXEC_PT_CONCEAL_VMX |SECONDARY_EXEC_ENABLE_VMFUNC |SECONDARY_EXEC_BUS_LOCK_DETECTION | -SECONDARY_EXEC_NOTIFY_VM_EXITING ; -if (cpu_has_sgx ()) - opt2 |=SECONDARY_EXEC_ENCLS_EXITING ; +SECONDARY_EXEC_NOTIFY_VM_EXITING | +SECONDARY_EXEC_ENCLS_EXITING ; +if (adjust_vmx_controls (min2, opt2,MSR_IA32_VMX_PROCBASED_CTLS2 , &_cpu_based_2nd_exec_control) <0 )
@@ -2577,6 +2577,9 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf, vmx_cap->vpid =0 ; } +if (!cpu_has_sgx ()) + _cpu_based_2nd_exec_control &= ~SECONDARY_EXEC_ENCLS_EXITING ; +if (_cpu_based_exec_control &CPU_BASED_ACTIVATE_TERTIARY_CONTROLS ) {u64 opt3 =TERTIARY_EXEC_IPI_VIRT ;
Signature · 1 line
2.35.3
Vitaly Kuznetsov
maintainerPATCH v2 17/28 KVM: VMX: Extend VMX controls macro shenanigans
In reply to Vitaly KuznetsovWhen VMX controls macros are used to set or clear a control bit, make sure that this bit was checked in setup_vmcs_config() and thus is properly reflected in vmcs_config.
No functional change intended.
--- arch/x86/kvm/vmx/vmx.c | 99 +++++++------------------------------ arch/x86/kvm/vmx/vmx.h | 109 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+), 81 deletions(-)
arch/x86/kvm/vmx/vmx.c +18 -81
@@ -2448,7 +2448,6 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf, struct vmx_capability *vmx_cap) {u32 vmx_msr_low, vmx_msr_high; -u32 min, opt, min2, opt2;u32 _pin_based_exec_control =0 ;u32 _cpu_based_exec_control =0 ;u32 _cpu_based_2nd_exec_control =0 ;
@@ -2474,28 +2473,10 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf, };memset (vmcs_conf,0 ,sizeof (*vmcs_conf)); - min = CPU_BASED_HLT_EXITING | -#ifdef CONFIG_X86_64 -CPU_BASED_CR8_LOAD_EXITING | -CPU_BASED_CR8_STORE_EXITING | -#endif -CPU_BASED_CR3_LOAD_EXITING | -CPU_BASED_CR3_STORE_EXITING | -CPU_BASED_UNCOND_IO_EXITING | -CPU_BASED_MOV_DR_EXITING | -CPU_BASED_USE_TSC_OFFSETTING | -CPU_BASED_MWAIT_EXITING | -CPU_BASED_MONITOR_EXITING | -CPU_BASED_INVLPG_EXITING | -CPU_BASED_RDPMC_EXITING | -CPU_BASED_INTR_WINDOW_EXITING | -CPU_BASED_NMI_WINDOW_EXITING ; - - opt =CPU_BASED_TPR_SHADOW | -CPU_BASED_USE_MSR_BITMAPS | -CPU_BASED_ACTIVATE_SECONDARY_CONTROLS | -CPU_BASED_ACTIVATE_TERTIARY_CONTROLS ; -if (adjust_vmx_controls (min, opt,MSR_IA32_VMX_PROCBASED_CTLS , + +if (adjust_vmx_controls (KVM_REQ_VMX_CPU_BASED_VM_EXEC_CONTROL , +KVM_OPT_VMX_CPU_BASED_VM_EXEC_CONTROL , +MSR_IA32_VMX_PROCBASED_CTLS , &_cpu_based_exec_control) <0 )return -EIO ;#ifdef CONFIG_X86_64
@@ -2504,34 +2485,8 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf, ~CPU_BASED_CR8_STORE_EXITING ;#endif if (_cpu_based_exec_control &CPU_BASED_ACTIVATE_SECONDARY_CONTROLS ) { - min2 =0 ; - opt2 =SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES | -SECONDARY_EXEC_VIRTUALIZE_X2APIC_MODE | -SECONDARY_EXEC_WBINVD_EXITING | -SECONDARY_EXEC_ENABLE_VPID | -SECONDARY_EXEC_ENABLE_EPT | -SECONDARY_EXEC_UNRESTRICTED_GUEST | -SECONDARY_EXEC_PAUSE_LOOP_EXITING | -SECONDARY_EXEC_DESC | -SECONDARY_EXEC_ENABLE_RDTSCP | -SECONDARY_EXEC_ENABLE_INVPCID | -SECONDARY_EXEC_APIC_REGISTER_VIRT | -SECONDARY_EXEC_VIRTUAL_INTR_DELIVERY | -SECONDARY_EXEC_SHADOW_VMCS | -SECONDARY_EXEC_XSAVES | -SECONDARY_EXEC_RDSEED_EXITING | -SECONDARY_EXEC_RDRAND_EXITING | -SECONDARY_EXEC_ENABLE_PML | -SECONDARY_EXEC_TSC_SCALING | -SECONDARY_EXEC_ENABLE_USR_WAIT_PAUSE | -SECONDARY_EXEC_PT_USE_GPA | -SECONDARY_EXEC_PT_CONCEAL_VMX | -SECONDARY_EXEC_ENABLE_VMFUNC | -SECONDARY_EXEC_BUS_LOCK_DETECTION | -SECONDARY_EXEC_NOTIFY_VM_EXITING | -SECONDARY_EXEC_ENCLS_EXITING ; - -if (adjust_vmx_controls (min2, opt2, +if (adjust_vmx_controls (KVM_REQ_VMX_SECONDARY_VM_EXEC_CONTROL , +KVM_OPT_VMX_SECONDARY_VM_EXEC_CONTROL ,MSR_IA32_VMX_PROCBASED_CTLS2 , &_cpu_based_2nd_exec_control) <0 )return -EIO ;
@@ -2581,30 +2536,20 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf, _cpu_based_2nd_exec_control &= ~SECONDARY_EXEC_ENCLS_EXITING ;if (_cpu_based_exec_control &CPU_BASED_ACTIVATE_TERTIARY_CONTROLS ) { -u64 opt3 =TERTIARY_EXEC_IPI_VIRT ; - - _cpu_based_3rd_exec_control =adjust_vmx_controls64 (opt3, -MSR_IA32_VMX_PROCBASED_CTLS3 ); + _cpu_based_3rd_exec_control = +adjust_vmx_controls64 (KVM_OPT_VMX_TERTIARY_VM_EXEC_CONTROL , +MSR_IA32_VMX_PROCBASED_CTLS3 ); } - min =VM_EXIT_SAVE_DEBUG_CONTROLS |VM_EXIT_ACK_INTR_ON_EXIT ; -#ifdef CONFIG_X86_64 - min |=VM_EXIT_HOST_ADDR_SPACE_SIZE ; -#endif - opt =VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL | -VM_EXIT_LOAD_IA32_PAT | -VM_EXIT_LOAD_IA32_EFER | -VM_EXIT_CLEAR_BNDCFGS | -VM_EXIT_PT_CONCEAL_PIP | -VM_EXIT_CLEAR_IA32_RTIT_CTL ; -if (adjust_vmx_controls (min, opt,MSR_IA32_VMX_EXIT_CTLS , +if (adjust_vmx_controls (KVM_REQ_VMX_VM_EXIT_CONTROLS , +KVM_OPT_VMX_VM_EXIT_CONTROLS , +MSR_IA32_VMX_EXIT_CTLS , &_vmexit_control) <0 )return -EIO ; - min =PIN_BASED_EXT_INTR_MASK |PIN_BASED_NMI_EXITING ; - opt =PIN_BASED_VIRTUAL_NMIS |PIN_BASED_POSTED_INTR | -PIN_BASED_VMX_PREEMPTION_TIMER ; -if (adjust_vmx_controls (min, opt,MSR_IA32_VMX_PINBASED_CTLS , +if (adjust_vmx_controls (KVM_REQ_VMX_PIN_BASED_VM_EXEC_CONTROL , +KVM_OPT_VMX_PIN_BASED_VM_EXEC_CONTROL , +MSR_IA32_VMX_PINBASED_CTLS , &_pin_based_exec_control) <0 )return -EIO ;
@@ -2614,17 +2559,9 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf, SECONDARY_EXEC_VIRTUAL_INTR_DELIVERY)) _pin_based_exec_control &= ~PIN_BASED_POSTED_INTR; - min =VM_ENTRY_LOAD_DEBUG_CONTROLS ; -#ifdef CONFIG_X86_64 - min |=VM_ENTRY_IA32E_MODE ; -#endif - opt =VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL | -VM_ENTRY_LOAD_IA32_PAT | -VM_ENTRY_LOAD_IA32_EFER | -VM_ENTRY_LOAD_BNDCFGS | -VM_ENTRY_PT_CONCEAL_PIP | -VM_ENTRY_LOAD_IA32_RTIT_CTL ; -if (adjust_vmx_controls (min, opt,MSR_IA32_VMX_ENTRY_CTLS , +if (adjust_vmx_controls (KVM_REQ_VMX_VM_ENTRY_CONTROLS , +KVM_OPT_VMX_VM_ENTRY_CONTROLS , +MSR_IA32_VMX_ENTRY_CTLS , &_vmentry_control) <0 )return -EIO ;
arch/x86/kvm/vmx/vmx.h +109 -0
125 lines not on this page · raw message
Signature · 1 line
2.35.3
Vitaly Kuznetsov
maintainerPATCH v2 18/28 KVM: VMX: Move CPU_BASED_CR8_{LOAD,STORE}_EXITING filtering out of setup_vmcs_config()
In reply to Vitaly KuznetsovAs a preparation to reusing the result of setup_vmcs_config() in nested VMX MSR setup, move CPU_BASED_CR8_{LOAD,STORE}_EXITING filtering to vmx_exec_control().
No functional change intended.
--- arch/x86/kvm/vmx/vmx.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
arch/x86/kvm/vmx/vmx.c +6 -7
@@ -2479,11 +2479,6 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf, MSR_IA32_VMX_PROCBASED_CTLS, &_cpu_based_exec_control) < 0)return -EIO ; -#ifdef CONFIG_X86_64 -if (_cpu_based_exec_control &CPU_BASED_TPR_SHADOW ) - _cpu_based_exec_control &= ~CPU_BASED_CR8_LOAD_EXITING & - ~CPU_BASED_CR8_STORE_EXITING ; -#endif if (_cpu_based_exec_control &CPU_BASED_ACTIVATE_SECONDARY_CONTROLS ) { if (adjust_vmx_controls(KVM_REQ_VMX_SECONDARY_VM_EXEC_CONTROL, KVM_OPT_VMX_SECONDARY_VM_EXEC_CONTROL,
@@ -4249,13 +4244,17 @@ static u32 vmx_exec_control(struct vcpu_vmx *vmx)if (vmx->vcpu.arch.switch_db_regs &KVM_DEBUGREG_WONT_EXIT ) exec_control &= ~CPU_BASED_MOV_DR_EXITING ; -if (!cpu_need_tpr_shadow (&vmx->vcpu)) { +if (!cpu_need_tpr_shadow (&vmx->vcpu)) exec_control &= ~CPU_BASED_TPR_SHADOW ; +#ifdef CONFIG_X86_64 +if (exec_control &CPU_BASED_TPR_SHADOW ) + exec_control &= ~(CPU_BASED_CR8_LOAD_EXITING | +CPU_BASED_CR8_STORE_EXITING ); +else exec_control |=CPU_BASED_CR8_STORE_EXITING |CPU_BASED_CR8_LOAD_EXITING ;#endif - }if (!enable_ept) exec_control |=CPU_BASED_CR3_STORE_EXITING | CPU_BASED_CR3_LOAD_EXITING |
Signature · 1 line
2.35.3
Vitaly Kuznetsov
maintainerPATCH v2 20/28 KVM: VMX: Add missing VMENTRY controls to vmcs_config
In reply to Vitaly KuznetsovAs a preparation to reusing the result of setup_vmcs_config() in nested VMX MSR setup, add the VMENTRY controls which KVM doesn't use but supports for nVMX to KVM_OPT_VMX_VM_ENTRY_CONTROLS and filter them out in vmx_vmentry_ctrl().
No functional change intended.
--- arch/x86/kvm/vmx/vmx.c | 3 +++ arch/x86/kvm/vmx/vmx.h | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-)
arch/x86/kvm/vmx/vmx.c +3 -0
@@ -4179,6 +4179,9 @@ static u32 vmx_vmentry_ctrl(void) {u32 vmentry_ctrl = vmcs_config.vmentry_ctrl; +/* Not used by KVM but supported for nesting. */ + vmentry_ctrl &= ~(VM_ENTRY_SMM |VM_ENTRY_DEACT_DUAL_MONITOR ); +if (vmx_pt_mode_is_system ()) vmentry_ctrl &= ~(VM_ENTRY_PT_CONCEAL_PIP |VM_ENTRY_LOAD_IA32_RTIT_CTL );
arch/x86/kvm/vmx/vmx.h +3 -1
@@ -479,7 +479,9 @@ static inline u8 vmx_get_rvi(void) __KVM_REQ_VMX_VM_ENTRY_CONTROLS#endif #define KVM_OPT_VMX_VM_ENTRY_CONTROLS \ - (VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL | \ + (VM_ENTRY_SMM | \ + VM_ENTRY_DEACT_DUAL_MONITOR | \ + VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL | \ VM_ENTRY_LOAD_IA32_PAT | \ VM_ENTRY_LOAD_IA32_EFER | \ VM_ENTRY_LOAD_BNDCFGS | \
Signature · 1 line
2.35.3
Vitaly Kuznetsov
maintainerPATCH v2 21/28 KVM: VMX: Add missing CPU based VM execution controls to vmcs_config
In reply to Vitaly KuznetsovAs a preparation to reusing the result of setup_vmcs_config() in nested VMX MSR setup, add the CPU based VM execution controls which KVM doesn't use but supports for nVMX to KVM_OPT_VMX_CPU_BASED_VM_EXEC_CONTROL and filter them out in vmx_exec_control().
No functional change intended.
--- arch/x86/kvm/vmx/vmx.c | 6 ++++++ arch/x86/kvm/vmx/vmx.h | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-)
arch/x86/kvm/vmx/vmx.c +6 -0
@@ -4244,6 +4244,12 @@ static u32 vmx_exec_control(struct vcpu_vmx *vmx) {u32 exec_control = vmcs_config.cpu_based_exec_ctrl; +/* Not used by KVM but supported for nesting. */ + exec_control &= ~(CPU_BASED_RDTSC_EXITING | +CPU_BASED_USE_IO_BITMAPS | +CPU_BASED_MONITOR_TRAP_FLAG | +CPU_BASED_PAUSE_EXITING ); +/* INTR_WINDOW_EXITING and NMI_WINDOW_EXITING are toggled dynamically */ exec_control &= ~(CPU_BASED_INTR_WINDOW_EXITING |CPU_BASED_NMI_WINDOW_EXITING );
arch/x86/kvm/vmx/vmx.h +5 -1
@@ -543,8 +543,12 @@ static inline u8 vmx_get_rvi(void)#endif #define KVM_OPT_VMX_CPU_BASED_VM_EXEC_CONTROL \ - (CPU_BASED_TPR_SHADOW | \ + (CPU_BASED_RDTSC_EXITING | \ + CPU_BASED_TPR_SHADOW | \ + CPU_BASED_USE_IO_BITMAPS | \ + CPU_BASED_MONITOR_TRAP_FLAG | \ CPU_BASED_USE_MSR_BITMAPS | \ + CPU_BASED_PAUSE_EXITING | \ CPU_BASED_ACTIVATE_SECONDARY_CONTROLS | \ CPU_BASED_ACTIVATE_TERTIARY_CONTROLS)
Signature · 1 line
2.35.3
Vitaly Kuznetsov
maintainerPATCH v2 15/28 KVM: VMX: Check CPU_BASED_{INTR,NMI}_WINDOW_EXITING in setup_vmcs_config()
In reply to Vitaly KuznetsovCPU_BASED_{INTR,NMI}_WINDOW_EXITING controls are toggled dynamically by vmx_enable_{irq,nmi}_window, handle_interrupt_window(), handle_nmi_window() but setup_vmcs_config() doesn't check their existence. Add the check and filter the controls out in vmx_exec_control().
No (real) functional change intended as all existing CPUs supporting VMX are supposed to have these controls.
--- arch/x86/kvm/vmx/vmx.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
arch/x86/kvm/vmx/vmx.c +7 -1
@@ -2487,7 +2487,9 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf,CPU_BASED_MWAIT_EXITING |CPU_BASED_MONITOR_EXITING |CPU_BASED_INVLPG_EXITING | -CPU_BASED_RDPMC_EXITING ; +CPU_BASED_RDPMC_EXITING | +CPU_BASED_INTR_WINDOW_EXITING | +CPU_BASED_NMI_WINDOW_EXITING ; opt =CPU_BASED_TPR_SHADOW | CPU_BASED_USE_MSR_BITMAPS |
@@ -4300,6 +4302,10 @@ static u32 vmx_exec_control(struct vcpu_vmx *vmx) {u32 exec_control = vmcs_config.cpu_based_exec_ctrl; +/* INTR_WINDOW_EXITING and NMI_WINDOW_EXITING are toggled dynamically */ + exec_control &= ~(CPU_BASED_INTR_WINDOW_EXITING | +CPU_BASED_NMI_WINDOW_EXITING ); +if (vmx->vcpu.arch.switch_db_regs &KVM_DEBUGREG_WONT_EXIT ) exec_control &= ~CPU_BASED_MOV_DR_EXITING ;
Signature · 1 line
2.35.3
Vitaly Kuznetsov
maintainerPATCH v2 22/28 KVM: VMX: Clear controls obsoleted by EPT at runtime, not setup
In reply to Vitaly KuznetsovFrom: Sean Christopherson <[email protected]>
Clear the CR3 and INVLPG interception controls at runtime based on whether or not EPT is being _used_, as opposed to clearing the bits at setup if EPT is _supported_ in hardware, and then restoring them when EPT is not used. Not mucking with the base config will allow using the base config as the starting point for emulating the VMX capability MSRs.
--- arch/x86/kvm/vmx/vmx.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-)
arch/x86/kvm/vmx/vmx.c +7 -11
@@ -2501,13 +2501,8 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf,rdmsr_safe (MSR_IA32_VMX_EPT_VPID_CAP , &vmx_cap->ept, &vmx_cap->vpid); -if (_cpu_based_2nd_exec_control &SECONDARY_EXEC_ENABLE_EPT ) { -/* CR3 accesses and invlpg don't need to cause VM Exits when EPT -enabled */ - _cpu_based_exec_control &= ~(CPU_BASED_CR3_LOAD_EXITING | -CPU_BASED_CR3_STORE_EXITING | -CPU_BASED_INVLPG_EXITING ); - }else if (vmx_cap->ept) { +if (!(_cpu_based_2nd_exec_control &SECONDARY_EXEC_ENABLE_EPT ) && + vmx_cap->ept) {pr_warn_once ("EPT CAP should not exist if not support " "1-setting enable EPT VM-execution control\n" );
@@ -4268,10 +4263,11 @@ static u32 vmx_exec_control(struct vcpu_vmx *vmx) exec_control |=CPU_BASED_CR8_STORE_EXITING |CPU_BASED_CR8_LOAD_EXITING ;#endif -if (!enable_ept) - exec_control |=CPU_BASED_CR3_STORE_EXITING | -CPU_BASED_CR3_LOAD_EXITING | -CPU_BASED_INVLPG_EXITING ; +/* No need to intercept CR3 access or INVPLG when using EPT. */ +if (enable_ept) + exec_control &= ~(CPU_BASED_CR3_LOAD_EXITING | +CPU_BASED_CR3_STORE_EXITING | +CPU_BASED_INVLPG_EXITING );if (kvm_mwait_in_guest (vmx->vcpu.kvm)) exec_control &= ~(CPU_BASED_MWAIT_EXITING |CPU_BASED_MONITOR_EXITING );
Signature · 1 line
2.35.3
Vitaly Kuznetsov
maintainerPATCH v2 19/28 KVM: VMX: Add missing VMEXIT controls to vmcs_config
In reply to Vitaly KuznetsovAs a preparation to reusing the result of setup_vmcs_config() in nested VMX MSR setup, add the VMEXIT controls which KVM doesn't use but supports for nVMX to KVM_OPT_VMX_VM_EXIT_CONTROLS and filter them out in vmx_vmexit_ctrl().
No functional change intended.
--- arch/x86/kvm/vmx/vmx.c | 4 ++++ arch/x86/kvm/vmx/vmx.h | 3 +++ 2 files changed, 7 insertions(+)
arch/x86/kvm/vmx/vmx.c +4 -0
@@ -4197,6 +4197,10 @@ static u32 vmx_vmexit_ctrl(void) {u32 vmexit_ctrl = vmcs_config.vmexit_ctrl; +/* Not used by KVM but supported for nesting. */ + vmexit_ctrl &= ~(VM_EXIT_SAVE_IA32_PAT |VM_EXIT_SAVE_IA32_EFER | +VM_EXIT_SAVE_VMX_PREEMPTION_TIMER ); +if (vmx_pt_mode_is_system ()) vmexit_ctrl &= ~(VM_EXIT_PT_CONCEAL_PIP |VM_EXIT_CLEAR_IA32_RTIT_CTL );
arch/x86/kvm/vmx/vmx.h +3 -0
@@ -499,8 +499,11 @@ static inline u8 vmx_get_rvi(void)#endif #define KVM_OPT_VMX_VM_EXIT_CONTROLS \ (VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL | \ + VM_EXIT_SAVE_IA32_PAT | \ VM_EXIT_LOAD_IA32_PAT | \ + VM_EXIT_SAVE_IA32_EFER | \ VM_EXIT_LOAD_IA32_EFER | \ + VM_EXIT_SAVE_VMX_PREEMPTION_TIMER | \ VM_EXIT_CLEAR_BNDCFGS | \ VM_EXIT_PT_CONCEAL_PIP | \ VM_EXIT_CLEAR_IA32_RTIT_CTL)
Signature · 1 line
2.35.3
Vitaly Kuznetsov
maintainerPATCH v2 23/28 KVM: VMX: Move LOAD_IA32_PERF_GLOBAL_CTRL errata handling out of setup_vmcs_config()
In reply to Vitaly KuznetsovAs a preparation to reusing the result of setup_vmcs_config() for setting up nested VMX control MSRs, move LOAD_IA32_PERF_GLOBAL_CTRL errata handling to vmx_vmexit_ctrl()/vmx_vmentry_ctrl() and print the warning from hardware_setup(). While it seems reasonable to not expose LOAD_IA32_PERF_GLOBAL_CTRL controls to L1 hypervisor on buggy CPUs, such change would inevitably break live migration from older KVMs where the controls are exposed. Keep the status quo for know, L1 hypervisor itself is supposed to take care of the errata.
--- arch/x86/kvm/vmx/vmx.c | 62 ++++++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 24 deletions(-)
arch/x86/kvm/vmx/vmx.c +38 -24
@@ -2416,6 +2416,31 @@ static bool cpu_has_sgx(void)return cpuid_eax (0 ) >=0x12 && (cpuid_eax (0x12 ) &BIT (0 )); } +/* +* Some cpus support VM_{ENTRY,EXIT}_IA32_PERF_GLOBAL_CTRL but they +* can't be used due to an errata where VM Exit may incorrectly clear +* IA32_PERF_GLOBAL_CTRL[34:32]. Workaround the errata by using the +* MSR load mechanism to switch IA32_PERF_GLOBAL_CTRL. +*/ +static bool cpu_has_perf_global_ctrl_bug (void ) +{ +if (boot_cpu_data.x86 ==0x6 ) { +switch (boot_cpu_data.x86_model) { +case 26 :/* AAK155 */ +case 30 :/* AAP115 */ +case 37 :/* AAT100 */ +case 44 :/* BC86,AAY89,BD102 */ +case 46 :/* BA97 */ +return true; +default : +break ; + } + } + +return false; +} + +static __init int adjust_vmx_controls (u32 ctl_min,u32 ctl_opt,u32 msr,u32 *result) {
@@ -2572,30 +2597,6 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf, _vmexit_control &= ~x_ctrl; } -/* -* Some cpus support VM_{ENTRY,EXIT}_IA32_PERF_GLOBAL_CTRL but they -* can't be used due to an errata where VM Exit may incorrectly clear -* IA32_PERF_GLOBAL_CTRL[34:32]. Workaround the errata by using the -* MSR load mechanism to switch IA32_PERF_GLOBAL_CTRL. -*/ -if (boot_cpu_data.x86 ==0x6 ) { -switch (boot_cpu_data.x86_model) { -case 26 :/* AAK155 */ -case 30 :/* AAP115 */ -case 37 :/* AAT100 */ -case 44 :/* BC86,AAY89,BD102 */ -case 46 :/* BA97 */ - _vmentry_control &= ~VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL ; - _vmexit_control &= ~VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL ; -pr_warn_once ("kvm: VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL " -"does not work properly. Using workaround\n" ); -break ; -default : -break ; - } - } - -rdmsr (MSR_IA32_VMX_BASIC , vmx_msr_low, vmx_msr_high);/* IA-32 SDM Vol 3B: VMCS size is never greater than 4kB. */
@@ -4188,6 +4189,10 @@ static u32 vmx_vmentry_ctrl(void)VM_ENTRY_LOAD_IA32_EFER | VM_ENTRY_IA32E_MODE); + +if (cpu_has_perf_global_ctrl_bug ()) + vmentry_ctrl &= ~VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL ; +return vmentry_ctrl; }
@@ -4202,6 +4207,10 @@ static u32 vmx_vmexit_ctrl(void)if (vmx_pt_mode_is_system ()) vmexit_ctrl &= ~(VM_EXIT_PT_CONCEAL_PIP |VM_EXIT_CLEAR_IA32_RTIT_CTL ); + +if (cpu_has_perf_global_ctrl_bug ()) + vmexit_ctrl &= ~VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL ; +/* Loading of EFER and PERF_GLOBAL_CTRL are toggled dynamically */ return vmexit_ctrl & ~(VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL |VM_EXIT_LOAD_IA32_EFER );
@@ -8117,6 +8126,11 @@ static __init int hardware_setup(void)if (setup_vmcs_config (&vmcs_config, &vmx_capability) <0 )return -EIO ; +if (cpu_has_perf_global_ctrl_bug ()) { +pr_warn_once ("kvm: VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL " +"does not work properly. Using workaround\n" ); + } +if (boot_cpu_has (X86_FEATURE_NX ))kvm_enable_efer_bits (EFER_NX );
Signature · 1 line
2.35.3
Vitaly Kuznetsov
maintainerPATCH v2 25/28 KVM: VMX: Store required-1 VMX controls in vmcs_config
In reply to Vitaly KuznetsovWhile constructing nested VMX MSRs values, nested_vmx_setup_ctls_msrs() has to re-read host VMX control MSRs to get required-1 bits which are not stored anywhre. Add this missing information to vmcs_config.
No functional change intended.
--- arch/x86/kvm/vmx/capabilities.h | 5 +++++ arch/x86/kvm/vmx/vmx.c | 28 +++++++++++++++++++++------- 2 files changed, 26 insertions(+), 7 deletions(-)
arch/x86/kvm/vmx/capabilities.h +5 -0
@@ -60,11 +60,16 @@ struct vmcs_config {u32 basic_cap;u32 revision_id;u32 pin_based_exec_ctrl; +u32 pin_based_exec_ctrl_req1;u32 cpu_based_exec_ctrl; +u32 cpu_based_exec_ctrl_req1;u32 cpu_based_2nd_exec_ctrl; +u32 cpu_based_2nd_exec_ctrl_req1;u64 cpu_based_3rd_exec_ctrl;u32 vmexit_ctrl; +u32 vmexit_ctrl_req1;u32 vmentry_ctrl; +u32 vmentry_ctrl_req1;struct nested_vmx_msrs nested; };extern struct vmcs_config vmcs_config;
arch/x86/kvm/vmx/vmx.c +21 -7
@@ -2442,7 +2442,7 @@ static bool cpu_has_perf_global_ctrl_bug(void)static __init int adjust_vmx_controls (u32 ctl_min,u32 ctl_opt, -u32 msr,u32 *result) +u32 msr,u32 *result_high,u32 *result_low) {u32 vmx_msr_low, vmx_msr_high;u32 ctl = ctl_min | ctl_opt;
@@ -2456,7 +2456,8 @@ static __init int adjust_vmx_controls(u32 ctl_min, u32 ctl_opt,if (ctl_min & ~ctl)return -EIO ; - *result = ctl; + *result_high = ctl; + *result_low = vmx_msr_low;return 0 ; }
@@ -2479,6 +2480,11 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf,u64 _cpu_based_3rd_exec_control =0 ;u32 _vmexit_control =0 ;u32 _vmentry_control =0 ; +u32 _pin_based_exec_control_low =0 ; +u32 _cpu_based_exec_control_low =0 ; +u32 _cpu_based_2nd_exec_control_low =0 ; +u32 _vmexit_control_low =0 ; +u32 _vmentry_control_low =0 ;int i;/*
@@ -2502,13 +2508,15 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf,if (adjust_vmx_controls (KVM_REQ_VMX_CPU_BASED_VM_EXEC_CONTROL ,KVM_OPT_VMX_CPU_BASED_VM_EXEC_CONTROL ,MSR_IA32_VMX_PROCBASED_CTLS , - &_cpu_based_exec_control) <0 ) + &_cpu_based_exec_control, + &_cpu_based_exec_control_low) <0 )return -EIO ;if (_cpu_based_exec_control &CPU_BASED_ACTIVATE_SECONDARY_CONTROLS ) {if (adjust_vmx_controls (KVM_REQ_VMX_SECONDARY_VM_EXEC_CONTROL ,KVM_OPT_VMX_SECONDARY_VM_EXEC_CONTROL ,MSR_IA32_VMX_PROCBASED_CTLS2 , - &_cpu_based_2nd_exec_control) <0 ) + &_cpu_based_2nd_exec_control, + &_cpu_based_2nd_exec_control_low) <0 )return -EIO ; }#ifndef CONFIG_X86_64
@@ -2559,13 +2567,14 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf,if (adjust_vmx_controls (KVM_REQ_VMX_VM_EXIT_CONTROLS ,KVM_OPT_VMX_VM_EXIT_CONTROLS ,MSR_IA32_VMX_EXIT_CTLS , - &_vmexit_control) <0 ) + &_vmexit_control, &_vmexit_control_low) <0 )return -EIO ;if (adjust_vmx_controls (KVM_REQ_VMX_PIN_BASED_VM_EXEC_CONTROL ,KVM_OPT_VMX_PIN_BASED_VM_EXEC_CONTROL ,MSR_IA32_VMX_PINBASED_CTLS , - &_pin_based_exec_control) <0 ) + &_pin_based_exec_control, + &_pin_based_exec_control_low) <0 )return -EIO ;if (cpu_has_broken_vmx_preemption_timer ())
@@ -2577,7 +2586,7 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf,if (adjust_vmx_controls (KVM_REQ_VMX_VM_ENTRY_CONTROLS ,KVM_OPT_VMX_VM_ENTRY_CONTROLS ,MSR_IA32_VMX_ENTRY_CTLS , - &_vmentry_control) <0 ) + &_vmentry_control, &_vmentry_control_low) <0 )return -EIO ;for (i =0 ; i <ARRAY_SIZE (vmcs_entry_exit_pairs); i++) {
@@ -2619,11 +2628,16 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf, vmcs_conf->revision_id = vmx_msr_low; vmcs_conf->pin_based_exec_ctrl = _pin_based_exec_control; + vmcs_conf->pin_based_exec_ctrl_req1 = _pin_based_exec_control_low; vmcs_conf->cpu_based_exec_ctrl = _cpu_based_exec_control; + vmcs_conf->cpu_based_exec_ctrl_req1 = _cpu_based_exec_control_low; vmcs_conf->cpu_based_2nd_exec_ctrl = _cpu_based_2nd_exec_control; + vmcs_conf->cpu_based_2nd_exec_ctrl_req1 = _cpu_based_2nd_exec_control_low; vmcs_conf->cpu_based_3rd_exec_ctrl = _cpu_based_3rd_exec_control; vmcs_conf->vmexit_ctrl = _vmexit_control; + vmcs_conf->vmexit_ctrl_req1 = _vmexit_control_low; vmcs_conf->vmentry_ctrl = _vmentry_control; + vmcs_conf->vmentry_ctrl_req1 = _vmentry_control_low;return 0 ; }
Signature · 1 line
2.35.3
Vitaly Kuznetsov
maintainerPATCH v2 27/28 KVM: VMX: Cache MSR_IA32_VMX_MISC in vmcs_config
In reply to Vitaly KuznetsovLike other host VMX control MSRs, MSR_IA32_VMX_MISC can be cached in vmcs_config to avoid the need to re-read it later, e.g. from cpu_has_vmx_intel_pt() or cpu_has_vmx_shadow_vmcs().
No (real) functional change intended.
--- arch/x86/kvm/vmx/capabilities.h | 11 +++-------- arch/x86/kvm/vmx/vmx.c | 8 +++++--- 2 files changed, 8 insertions(+), 11 deletions(-)
arch/x86/kvm/vmx/capabilities.h +3 -8
@@ -70,6 +70,7 @@ struct vmcs_config {u32 vmexit_ctrl_req1;u32 vmentry_ctrl;u32 vmentry_ctrl_req1; +u64 misc;struct nested_vmx_msrs nested; };extern struct vmcs_config vmcs_config;
@@ -229,11 +230,8 @@ static inline bool cpu_has_vmx_vmfunc(void)static inline bool cpu_has_vmx_shadow_vmcs (void ) { -u64 vmx_msr; -/* check if the cpu supports writing r/o exit information fields */ -rdmsrl (MSR_IA32_VMX_MISC , vmx_msr); -if (!(vmx_msr &MSR_IA32_VMX_MISC_VMWRITE_SHADOW_RO_FIELDS )) +if (!(vmcs_config.misc &MSR_IA32_VMX_MISC_VMWRITE_SHADOW_RO_FIELDS ))return false; return vmcs_config.cpu_based_2nd_exec_ctrl &
@@ -375,10 +373,7 @@ static inline bool cpu_has_vmx_invvpid_global(void)static inline bool cpu_has_vmx_intel_pt (void ) { -u64 vmx_msr; - -rdmsrl (MSR_IA32_VMX_MISC , vmx_msr); -return (vmx_msr &MSR_IA32_VMX_MISC_INTEL_PT ) && +return (vmcs_config.misc &MSR_IA32_VMX_MISC_INTEL_PT ) && (vmcs_config.cpu_based_2nd_exec_ctrl &SECONDARY_EXEC_PT_USE_GPA ) && (vmcs_config.vmentry_ctrl &VM_ENTRY_LOAD_IA32_RTIT_CTL ); }
arch/x86/kvm/vmx/vmx.c +5 -3
@@ -2485,6 +2485,7 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf,u32 _cpu_based_2nd_exec_control_low =0 ;u32 _vmexit_control_low =0 ;u32 _vmentry_control_low =0 ; +u64 misc_msr;int i;/*
@@ -2622,6 +2623,8 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf,if (((vmx_msr_high >>18 ) &15 ) !=6 )return -EIO ; +rdmsrl (MSR_IA32_VMX_MISC , misc_msr); + vmcs_conf->size = vmx_msr_high &0x1fff ; vmcs_conf->basic_cap = vmx_msr_high & ~0x1fff ;
@@ -2638,6 +2641,7 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf, vmcs_conf->vmexit_ctrl_req1 = _vmexit_control_low; vmcs_conf->vmentry_ctrl = _vmentry_control; vmcs_conf->vmentry_ctrl_req1 = _vmentry_control_low; + vmcs_conf->misc = misc_msr;return 0 ; }
@@ -8259,11 +8263,9 @@ static __init int hardware_setup(void)if (enable_preemption_timer) {u64 use_timer_freq =5000ULL *1000 *1000 ; -u64 vmx_msr; -rdmsrl (MSR_IA32_VMX_MISC , vmx_msr); cpu_preemption_timer_multi = - vmx_msr &VMX_MISC_PREEMPTION_TIMER_RATE_MASK ; + vmcs_config.misc &VMX_MISC_PREEMPTION_TIMER_RATE_MASK ;if (tsc_khz) use_timer_freq = (u64 )tsc_khz *1000 ;
Signature · 1 line
2.35.3
Vitaly Kuznetsov
maintainerPATCH v2 24/28 KVM: nVMX: Use sanitized allowed-1 bits for VMX control MSRs
In reply to Vitaly KuznetsovUsing raw host MSR values for setting up nested VMX control MSRs is incorrect as some features need to disabled, e.g. when KVM runs as a nested hypervisor on Hyper-V and uses Enlightened VMCS or when a workaround for IA32_PERF_GLOBAL_CTRL is applied. For non-nested VMX, this is done in setup_vmcs_config() and the result is stored in vmcs_config. Use it for setting up allowed-1 bits in nested VMX MSRs too.
--- arch/x86/kvm/vmx/nested.c | 34 ++++++++++++++++------------------ arch/x86/kvm/vmx/nested.h | 2 +- arch/x86/kvm/vmx/vmx.c | 5 ++--- 3 files changed, 19 insertions(+), 22 deletions(-)
arch/x86/kvm/vmx/nested.c +16 -18
@@ -6565,8 +6565,13 @@ static u64 nested_vmx_calc_vmcs_enum_msr(void)* bit in the high half is on if the corresponding bit in the control field * may be on. See also vmx_control_verify(). */ -void nested_vmx_setup_ctls_msrs (struct nested_vmx_msrs *msrs,u32 ept_caps) +void nested_vmx_setup_ctls_msrs (struct vmcs_config *vmcs_conf,u32 ept_caps) { +struct nested_vmx_msrs *msrs = &vmcs_conf->nested; + +/* Take the allowed-1 bits from KVM's sanitized VMCS configuration. */ +u32 ignore_high; +/* * Note that as a general rule, the high half of the MSRs (bits in * the control fields which may be 1) should be initialized by the
@@ -6583,11 +6588,11 @@ void nested_vmx_setup_ctls_msrs(struct nested_vmx_msrs *msrs, u32 ept_caps)*/ /* pin-based controls */ -rdmsr (MSR_IA32_VMX_PINBASED_CTLS , - msrs->pinbased_ctls_low, - msrs->pinbased_ctls_high); +rdmsr (MSR_IA32_VMX_PINBASED_CTLS , msrs->pinbased_ctls_low, ignore_high); msrs->pinbased_ctls_low |=PIN_BASED_ALWAYSON_WITHOUT_TRUE_MSR ; + + msrs->pinbased_ctls_high = vmcs_conf->pin_based_exec_ctrl; msrs->pinbased_ctls_high &=PIN_BASED_EXT_INTR_MASK | PIN_BASED_NMI_EXITING |
@@ -6598,12 +6603,10 @@ void nested_vmx_setup_ctls_msrs(struct nested_vmx_msrs *msrs, u32 ept_caps)PIN_BASED_VMX_PREEMPTION_TIMER ;/* exit controls */ -rdmsr (MSR_IA32_VMX_EXIT_CTLS , - msrs->exit_ctls_low, - msrs->exit_ctls_high); msrs->exit_ctls_low =VM_EXIT_ALWAYSON_WITHOUT_TRUE_MSR ; + msrs->exit_ctls_high = vmcs_conf->vmexit_ctrl; msrs->exit_ctls_high &=#ifdef CONFIG_X86_64 VM_EXIT_HOST_ADDR_SPACE_SIZE |
@@ -6619,11 +6622,10 @@ void nested_vmx_setup_ctls_msrs(struct nested_vmx_msrs *msrs, u32 ept_caps) msrs->exit_ctls_low &= ~VM_EXIT_SAVE_DEBUG_CONTROLS ;/* entry controls */ -rdmsr (MSR_IA32_VMX_ENTRY_CTLS , - msrs->entry_ctls_low, - msrs->entry_ctls_high); msrs->entry_ctls_low =VM_ENTRY_ALWAYSON_WITHOUT_TRUE_MSR ; + + msrs->entry_ctls_high = vmcs_conf->vmentry_ctrl; msrs->entry_ctls_high &=#ifdef CONFIG_X86_64 VM_ENTRY_IA32E_MODE |
@@ -6637,11 +6639,10 @@ void nested_vmx_setup_ctls_msrs(struct nested_vmx_msrs *msrs, u32 ept_caps) msrs->entry_ctls_low &= ~VM_ENTRY_LOAD_DEBUG_CONTROLS ;/* cpu-based controls */ -rdmsr (MSR_IA32_VMX_PROCBASED_CTLS , - msrs->procbased_ctls_low, - msrs->procbased_ctls_high); msrs->procbased_ctls_low =CPU_BASED_ALWAYSON_WITHOUT_TRUE_MSR ; + + msrs->procbased_ctls_high = vmcs_conf->cpu_based_exec_ctrl; msrs->procbased_ctls_high &=CPU_BASED_INTR_WINDOW_EXITING | CPU_BASED_NMI_WINDOW_EXITING | CPU_BASED_USE_TSC_OFFSETTING |
@@ -6675,12 +6676,9 @@ void nested_vmx_setup_ctls_msrs(struct nested_vmx_msrs *msrs, u32 ept_caps)* depend on CPUID bits, they are added later by * vmx_vcpu_after_set_cpuid. */ -if (msrs->procbased_ctls_high &CPU_BASED_ACTIVATE_SECONDARY_CONTROLS ) -rdmsr (MSR_IA32_VMX_PROCBASED_CTLS2 , - msrs->secondary_ctls_low, - msrs->secondary_ctls_high); - msrs->secondary_ctls_low =0 ; + + msrs->secondary_ctls_high = vmcs_conf->cpu_based_2nd_exec_ctrl; msrs->secondary_ctls_high &=SECONDARY_EXEC_DESC | SECONDARY_EXEC_ENABLE_RDTSCP |
arch/x86/kvm/vmx/nested.h +1 -1
@@ -17,7 +17,7 @@ enum nvmx_vmentry_status { };void vmx_leave_nested (struct kvm_vcpu *vcpu); -void nested_vmx_setup_ctls_msrs (struct nested_vmx_msrs *msrs,u32 ept_caps); +void nested_vmx_setup_ctls_msrs (struct vmcs_config *vmcs_conf,u32 ept_caps);void nested_vmx_hardware_unsetup (void );__init int nested_vmx_hardware_setup (int (*exit_handlers[])(struct kvm_vcpu *));void nested_vmx_set_vmcs_shadowing_bitmap (void );
arch/x86/kvm/vmx/vmx.c +2 -3
@@ -7310,7 +7310,7 @@ static int __init vmx_check_processor_compat(void)if (setup_vmcs_config (&vmcs_conf, &vmx_cap) <0 )return -EIO ;if (nested) -nested_vmx_setup_ctls_msrs (&vmcs_conf.nested, vmx_cap.ept); +nested_vmx_setup_ctls_msrs (&vmcs_conf, vmx_cap.ept);if (memcmp (&vmcs_config, &vmcs_conf,sizeof (struct vmcs_config )) !=0 ) {printk (KERN_ERR "kvm: CPU %d feature inconsistency!\n" ,smp_processor_id ());
@@ -8285,8 +8285,7 @@ static __init int hardware_setup(void)setup_default_sgx_lepubkeyhash ();if (nested) { -nested_vmx_setup_ctls_msrs (&vmcs_config.nested, - vmx_capability.ept); +nested_vmx_setup_ctls_msrs (&vmcs_config, vmx_capability.ept); r =nested_vmx_hardware_setup (kvm_vmx_exit_handlers);if (r)
Signature · 1 line
2.35.3
Vitaly Kuznetsov
maintainerPATCH v2 28/28 KVM: nVMX: Use cached host MSR_IA32_VMX_MISC value for setting up nested MSR
In reply to Vitaly Kuznetsovvmcs_config has cased host MSR_IA32_VMX_MISC value, use it for setting up nested MSR_IA32_VMX_MISC in nested_vmx_setup_ctls_msrs() and avoid the redundant rdmsr().
No (real) functional change intended.
--- arch/x86/kvm/vmx/nested.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
arch/x86/kvm/vmx/nested.c +1 -4
@@ -6754,10 +6754,7 @@ void nested_vmx_setup_ctls_msrs(struct vmcs_config *vmcs_conf, u32 ept_caps) msrs->secondary_ctls_high |=SECONDARY_EXEC_ENCLS_EXITING ;/* miscellaneous data */ -rdmsr (MSR_IA32_VMX_MISC , - msrs->misc_low, - msrs->misc_high); - msrs->misc_low &=VMX_MISC_SAVE_EFER_LMA ; + msrs->misc_low = (u32 )vmcs_conf->misc &VMX_MISC_SAVE_EFER_LMA ; msrs->misc_low |=MSR_IA32_VMX_MISC_VMWRITE_SHADOW_RO_FIELDS | VMX_MISC_EMULATED_PREEMPTION_TIMER_RATE |
Signature · 1 line
2.35.3
Vitaly Kuznetsov
maintainerPATCH v2 26/28 KVM: nVMX: Use sanitized required-1 bits for VMX control MSRs
In reply to Vitaly Kuznetsovvmcs_config has the required information for setting up required-1 bits of nested VMCS control MSRs, use it to avoid redundant rdmsr()s.
--- arch/x86/kvm/vmx/nested.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
arch/x86/kvm/vmx/nested.c +1 -5
@@ -6569,9 +6569,6 @@ void nested_vmx_setup_ctls_msrs(struct vmcs_config *vmcs_conf, u32 ept_caps) {struct nested_vmx_msrs *msrs = &vmcs_conf->nested; -/* Take the allowed-1 bits from KVM's sanitized VMCS configuration. */ -u32 ignore_high; -/* * Note that as a general rule, the high half of the MSRs (bits in * the control fields which may be 1) should be initialized by the
@@ -6588,8 +6585,7 @@ void nested_vmx_setup_ctls_msrs(struct vmcs_config *vmcs_conf, u32 ept_caps)*/ /* pin-based controls */ -rdmsr (MSR_IA32_VMX_PINBASED_CTLS , msrs->pinbased_ctls_low, ignore_high); - msrs->pinbased_ctls_low |= + msrs->pinbased_ctls_low = vmcs_conf->pin_based_exec_ctrl_req1 |PIN_BASED_ALWAYSON_WITHOUT_TRUE_MSR ; msrs->pinbased_ctls_high = vmcs_conf->pin_based_exec_ctrl;
Signature · 1 line
2.35.3
Re: [PATCH v2 27/28] KVM: VMX: Cache MSR_IA32_VMX_MISC in vmcs_config
In reply to Vitaly KuznetsovQuoted 8 lines · Vitaly Kuznetsov
Like other host VMX control MSRs,
MSR_IA32_VMX_MISCcan be cached invmcs_configto avoid the need to re-read it later, e.g. fromcpu_has_vmx_intel_pt()orcpu_has_vmx_shadow_vmcs().No (real) functional change intended.
Signed-off-by Vitaly Kuznetsov <[email protected]>
Re: [PATCH v2 28/28] KVM: nVMX: Use cached host MSR_IA32_VMX_MISC value for setting up nested MSR
In reply to Vitaly KuznetsovQuoted 6 lines · Vitaly Kuznetsov
vmcs_confighas cased hostMSR_IA32_VMX_MISCvalue, use it for setting up nestedMSR_IA32_VMX_MISCinnested_vmx_setup_ctls_msrs()and avoid the redundantrdmsr().No (real) functional change intended.
Just imaginary functional change? :-)
Quoted 2 lines
Signed-off-by Vitaly Kuznetsov <[email protected]>
Re: [PATCH v2 16/28] KVM: VMX: Tweak the special handling of SECONDARY_EXEC_ENCLS_EXITING in setup_vmcs_config()
In reply to Vitaly KuznetsovQuoted 36 lines · Vitaly Kuznetsov
SECONDARY_EXEC_ENCLS_EXITINGis conditionally added to the 'optional' checklist insetup_vmcs_config()but there's little value in doing so. First, as the control is optional, we can always check for its presence, no harm done. Second, the only real valuecpu_has_sgx()check gives is that on the CPUs which supportSECONDARY_EXEC_ENCLS_EXITINGbut don't support SGX, the control is not getting enabled. It's highly unlikely such CPUs exist but it's possible that some hypervisors expose broken vCPU models.Preserve
cpu_has_sgx()check but filter the result ofadjust_vmx_controls()instead of the input.Signed-off-by Vitaly Kuznetsov <[email protected]>--- arch/x86/kvm/vmx/vmx.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)arch/x86/kvm/vmx/vmx.c +3
-3@@ -2528,9 +2528,9 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf,SECONDARY_EXEC_PT_CONCEAL_VMX |SECONDARY_EXEC_ENABLE_VMFUNC |SECONDARY_EXEC_BUS_LOCK_DETECTION | -SECONDARY_EXEC_NOTIFY_VM_EXITING ; -if (cpu_has_sgx ()) - opt2 |=SECONDARY_EXEC_ENCLS_EXITING ; +SECONDARY_EXEC_NOTIFY_VM_EXITING | +SECONDARY_EXEC_ENCLS_EXITING ; +if (adjust_vmx_controls (min2, opt2,MSR_IA32_VMX_PROCBASED_CTLS2 , &_cpu_based_2nd_exec_control) <0 )
arch/x86/kvm/vmx/vmx.c static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf, · line 2581
Quoted 5 lines
arch/x86/kvm/vmx/vmx.c +2
-0@@ -2577,6 +2577,9 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf, vmx_cap->vpid =0 ; } +if (!cpu_has_sgx ()) + _cpu_based_2nd_exec_control &= ~SECONDARY_EXEC_ENCLS_EXITING ;
NYC, but why is there a leading underscore here?
Quoted 6 lines
arch/x86/kvm/vmx/vmx.c +0
-1if (_cpu_based_exec_control &CPU_BASED_ACTIVATE_TERTIARY_CONTROLS ) {u64 opt3 =TERTIARY_EXEC_IPI_VIRT ; --2.35.3
Re: [PATCH v2 14/28] KVM: VMX: Check VM_ENTRY_IA32E_MODE in setup_vmcs_config()
In reply to Vitaly KuznetsovQuoted 29 lines · Vitaly Kuznetsov
VM_ENTRY_IA32E_MODEcontrol is toggled dynamically byvmx_set_efer()andsetup_vmcs_config()doesn't check its existence. On the contrary,nested_vmx_setup_ctls_msrs()doesn set it onx86_64. Add the missing check and filter the bit out invmx_vmentry_ctrl().No (real) functional change intended as all existing CPUs supporting long mode and VMX are supposed to have it.
Signed-off-by Vitaly Kuznetsov <[email protected]>--- arch/x86/kvm/vmx/vmx.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)arch/x86/kvm/vmx/vmx.c +3
-0@@ -2610,6 +2610,9 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf, _pin_based_exec_control &= ~PIN_BASED_POSTED_INTR ; min =VM_ENTRY_LOAD_DEBUG_CONTROLS ; +#ifdef CONFIG_X86_64 + min |=VM_ENTRY_IA32E_MODE ; +#endif opt =VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL |VM_ENTRY_LOAD_IA32_PAT | VM_ENTRY_LOAD_IA32_EFER |
arch/x86/kvm/vmx/vmx.c static u32 vmx_vmentry_ctrl(void) · line 4251
Quoted 10 lines
arch/x86/kvm/vmx/vmx.c +4
-3@@ -4242,9 +4245,15 @@ static u32 vmx_vmentry_ctrl(void)if (vmx_pt_mode_is_system ()) vmentry_ctrl &= ~(VM_ENTRY_PT_CONCEAL_PIP |VM_ENTRY_LOAD_IA32_RTIT_CTL ); -/* Loading of EFER and PERF_GLOBAL_CTRL are toggled dynamically */ -return vmentry_ctrl & - ~(VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL |VM_ENTRY_LOAD_IA32_EFER ); +/* +* Loading of EFER, VM_ENTRY_IA32E_MODE, and PERF_GLOBAL_CTRL +* are toggled dynamically. +*/
Nit: Previously, this could be read as "loading of (EFER and PERF_GLOBAL_CTRL)." Since "loading" doesn't apply to IA32e mode, you've lost "loading" of PERF_GLOBAL_CONTROL. Also, why drop the VM_ENTRY prefix from the MSRs and not from IA32e mode? Perhaps:
/*
* IA32e mode, and loading of EFER and PERF_GLOBAL_CTRL are toggled dynamically. */
Quoted 11 lines
arch/x86/kvm/vmx/vmx.c +5
-1+ vmentry_ctrl &= ~(VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL | +VM_ENTRY_LOAD_IA32_EFER | +VM_ENTRY_IA32E_MODE ); + +return vmentry_ctrl; }static u32 vmx_vmexit_ctrl (void ) --2.35.3
Vitaly Kuznetsov
maintainerRe: [PATCH v2 16/28] KVM: VMX: Tweak the special handling of SECONDARY_EXEC_ENCLS_EXITING in setup_vmcs_config()
In reply to Jim MattsonQuoted 40 lines · Jim Mattson
Quoted 39 lines · Vitaly Kuznetsov
SECONDARY_EXEC_ENCLS_EXITINGis conditionally added to the 'optional' checklist insetup_vmcs_config()but there's little value in doing so. First, as the control is optional, we can always check for its presence, no harm done. Second, the only real valuecpu_has_sgx()check gives is that on the CPUs which supportSECONDARY_EXEC_ENCLS_EXITINGbut don't support SGX, the control is not getting enabled. It's highly unlikely such CPUs exist but it's possible that some hypervisors expose broken vCPU models.Preserve
cpu_has_sgx()check but filter the result ofadjust_vmx_controls()instead of the input.Signed-off-by Vitaly Kuznetsov <[email protected]>--- arch/x86/kvm/vmx/vmx.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)arch/x86/kvm/vmx/vmx.c +3
-3@@ -2528,9 +2528,9 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf,SECONDARY_EXEC_PT_CONCEAL_VMX |SECONDARY_EXEC_ENABLE_VMFUNC |SECONDARY_EXEC_BUS_LOCK_DETECTION | -SECONDARY_EXEC_NOTIFY_VM_EXITING ; -if (cpu_has_sgx ()) - opt2 |=SECONDARY_EXEC_ENCLS_EXITING ; +SECONDARY_EXEC_NOTIFY_VM_EXITING | +SECONDARY_EXEC_ENCLS_EXITING ; +if (adjust_vmx_controls (min2, opt2,MSR_IA32_VMX_PROCBASED_CTLS2 , &_cpu_based_2nd_exec_control) <0 )@@ -2577,6 +2577,9 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf, vmx_cap->vpid =0 ; }
Quoted 4 lines
arch/x86/kvm/vmx/vmx.c static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf, · line 2581
Quoted 2 lines
arch/x86/kvm/vmx/vmx.c +2
-0+if (!cpu_has_sgx ()) + _cpu_based_2nd_exec_control &= ~SECONDARY_EXEC_ENCLS_EXITING ;NYC, but why is there a leading underscore here?
No idea to be honest, this goes way back to 2007 when setup_vmcs_config() was introduced:
commit 1c3d14fe0ab75337a3f6c06b6bc18bcbc2b3d0bc
Author: Yang, Sheng <[email protected]> Date: Sun Jul 29 11:07:42 2007 +0300
KVM: VMX: Improve the method of writing vmcs control
Quoted 9 lines
Quoted 7 lines
arch/x86/kvm/vmx/vmx.c +0
-1if (_cpu_based_exec_control &CPU_BASED_ACTIVATE_TERTIARY_CONTROLS ) {u64 opt3 =TERTIARY_EXEC_IPI_VIRT ; --2.35.3
Reviewed-by Jim Mattson <[email protected]>
Thanks!
Signature · 1 line
Vitaly
Vitaly Kuznetsov
maintainerRe: [PATCH v2 28/28] KVM: nVMX: Use cached host MSR_IA32_VMX_MISC value for setting up nested MSR
In reply to Jim MattsonQuoted 10 lines · Jim Mattson
Quoted 6 lines · Vitaly Kuznetsov
vmcs_confighas cased hostMSR_IA32_VMX_MISCvalue, use it for setting up nestedMSR_IA32_VMX_MISCinnested_vmx_setup_ctls_msrs()and avoid the redundantrdmsr().No (real) functional change intended.
Just imaginary functional change? :-)
Well, yea) The assumption here is that MSR_IA32_VMX_MISC's value doesn't change underneath KVM, caching doesn't change anything then. It is, of course, possible that when KVM runs as a nested hypervisor on top of something else, it will observe different values. I truly hope this is purely imaginary :-)
Quoted 4 lines
Quoted 2 lines
Signed-off-by Vitaly Kuznetsov <[email protected]>Reviewed-by Jim Mattson <[email protected]>
Thanks!
Signature · 1 line
Vitaly
Re: [PATCH v2 28/28] KVM: nVMX: Use cached host MSR_IA32_VMX_MISC value for setting up nested MSR
Quoted 11 lines · Vitaly Kuznetsov
Quoted 8 lines · Jim Mattson
Quoted 6 lines · Vitaly Kuznetsov
vmcs_confighas cased hostMSR_IA32_VMX_MISCvalue, use it for setting up nestedMSR_IA32_VMX_MISCinnested_vmx_setup_ctls_msrs()and avoid the redundantrdmsr().No (real) functional change intended.
Quoted 8 lines
Quoted 2 lines
Just imaginary functional change? :-)
Well, yea) The assumption here is that MSR_IA32_VMX_MISC's value doesn't change underneath KVM, caching doesn't change anything then. It is, of course, possible that when KVM runs as a nested hypervisor on top of something else, it will observe different values. I truly hope this is purely imaginary :-)
It is also theoretically possible that a late-loadable microcode patch could change the value of the MSR, but Intel wouldn't do that to us, would they?
Re: [PATCH v2 15/28] KVM: VMX: Check CPU_BASED_{INTR,NMI}_WINDOW_EXITING in setup_vmcs_config()
In reply to Vitaly KuznetsovQuoted 8 lines · Vitaly Kuznetsov
CPU_BASED_{INTR,NMI}_WINDOW_EXITING controls are toggled dynamically by vmx_enable_{irq,nmi}_window,
handle_interrupt_window(),handle_nmi_window()butsetup_vmcs_config()doesn't check their existence. Add the check and filter the controls out invmx_exec_control().No (real) functional change intended as all existing CPUs supporting VMX are supposed to have these controls.
I'm pretty sure vIrtual NMIs and NMI-window exiting are not available on Prescott or Yonah.
Quoted 1 line
Signed-off-by Vitaly Kuznetsov <[email protected]>
Re: [PATCH v2 18/28] KVM: VMX: Move CPU_BASED_CR8_{LOAD,STORE}_EXITING filtering out of setup_vmcs_config()
In reply to Vitaly KuznetsovQuoted 8 lines · Vitaly Kuznetsov
As a preparation to reusing the result of
setup_vmcs_config()in nested VMX MSR setup, move CPU_BASED_CR8_{LOAD,STORE}_EXITING filtering tovmx_exec_control().No functional change intended.
Signed-off-by Vitaly Kuznetsov <[email protected]>
Vitaly Kuznetsov
maintainerRe: [PATCH v2 15/28] KVM: VMX: Check CPU_BASED_{INTR,NMI}_WINDOW_EXITING in setup_vmcs_config()
In reply to Jim MattsonQuoted 7 lines · Jim Mattson
Quoted 6 lines · Vitaly Kuznetsov
CPU_BASED_{INTR,NMI}_WINDOW_EXITING controls are toggled dynamically by vmx_enable_{irq,nmi}_window,
handle_interrupt_window(),handle_nmi_window()butsetup_vmcs_config()doesn't check their existence. Add the check and filter the controls out invmx_exec_control().
Quoted 6 lines
Quoted 2 lines
No (real) functional change intended as all existing CPUs supporting VMX are supposed to have these controls.
I'm pretty sure vIrtual NMIs and NMI-window exiting are not available on Prescott or Yonah.
I seemed to have questioned their existence :-) But you're right, I should've said something like "all CPUs supported by KVM" instead (as pre-patch KVM toggles these controls unconditionally).
Quoted 3 lines
Quoted 1 line
Signed-off-by Vitaly Kuznetsov <[email protected]>Reviewed-by Jim Mattson <[email protected]>
Thanks!
Signature · 1 line
Vitaly
Re: [PATCH v2 20/28] KVM: VMX: Add missing VMENTRY controls to vmcs_config
In reply to Vitaly KuznetsovQuoted 19 lines · Vitaly Kuznetsov
As a preparation to reusing the result of
setup_vmcs_config()in nested VMX MSR setup, add the VMENTRY controls which KVM doesn't use but supports for nVMX toKVM_OPT_VMX_VM_ENTRY_CONTROLSand filter them out invmx_vmentry_ctrl().No functional change intended.
Signed-off-by Vitaly Kuznetsov <[email protected]>--- arch/x86/kvm/vmx/vmx.c | 3 +++ arch/x86/kvm/vmx/vmx.h | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-)arch/x86/kvm/vmx/vmx.c +0
-0
arch/x86/kvm/vmx/vmx.c static u32 vmx_vmentry_ctrl(void) · line 4184
Quoted 6 lines
arch/x86/kvm/vmx/vmx.c +3
-0@@ -4179,6 +4179,9 @@ static u32 vmx_vmentry_ctrl(void) {u32 vmentry_ctrl = vmcs_config.vmentry_ctrl; +/* Not used by KVM but supported for nesting. */ + vmentry_ctrl &= ~(VM_ENTRY_SMM |VM_ENTRY_DEACT_DUAL_MONITOR ); +
LOL! KVM does not emulate the dual-monitor treatment of SMIs and SMM. Do we actually claim to support these VM-entry controls today?!?
Quoted 21 lines
arch/x86/kvm/vmx/vmx.c +0
-0if (vmx_pt_mode_is_system ()) vmentry_ctrl &= ~(VM_ENTRY_PT_CONCEAL_PIP |VM_ENTRY_LOAD_IA32_RTIT_CTL );arch/x86/kvm/vmx/vmx.h +3
-2@@ -479,7 +479,9 @@ static inline u8 vmx_get_rvi(void) __KVM_REQ_VMX_VM_ENTRY_CONTROLS#endif #define KVM_OPT_VMX_VM_ENTRY_CONTROLS \ - (VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL | \ + (VM_ENTRY_SMM | \ + VM_ENTRY_DEACT_DUAL_MONITOR | \ + VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL | \ VM_ENTRY_LOAD_IA32_PAT | \ VM_ENTRY_LOAD_IA32_EFER | \ VM_ENTRY_LOAD_BNDCFGS | \ --2.35.3
Re: [PATCH v2 19/28] KVM: VMX: Add missing VMEXIT controls to vmcs_config
In reply to Vitaly KuznetsovQuoted 9 lines · Vitaly Kuznetsov
As a preparation to reusing the result of
setup_vmcs_config()in nested VMX MSR setup, add the VMEXIT controls which KVM doesn't use but supports for nVMX toKVM_OPT_VMX_VM_EXIT_CONTROLSand filter them out invmx_vmexit_ctrl().No functional change intended.
Signed-off-by Vitaly Kuznetsov <[email protected]>
Re: [PATCH v2 21/28] KVM: VMX: Add missing CPU based VM execution controls to vmcs_config
In reply to Vitaly KuznetsovQuoted 9 lines · Vitaly Kuznetsov
As a preparation to reusing the result of
setup_vmcs_config()in nested VMX MSR setup, add the CPU based VM execution controls which KVM doesn't use but supports for nVMX toKVM_OPT_VMX_CPU_BASED_VM_EXEC_CONTROLand filter them out invmx_exec_control().No functional change intended.
Signed-off-by Vitaly Kuznetsov <[email protected]>
Re: [PATCH v2 22/28] KVM: VMX: Clear controls obsoleted by EPT at runtime, not setup
In reply to Vitaly KuznetsovQuoted 11 lines · Vitaly Kuznetsov
From: Sean Christopherson <[email protected]>
Clear the CR3 and INVLPG interception controls at runtime based on whether or not EPT is being _used_, as opposed to clearing the bits at setup if EPT is _supported_ in hardware, and then restoring them when EPT is not used. Not mucking with the base config will allow using the base config as the starting point for emulating the VMX capability MSRs.
Signed-off-by Sean Christopherson <[email protected]>Signed-off-by Vitaly Kuznetsov <[email protected]>
Nit: These controls aren't "obsoleted" by EPT; they're just no longer required.
Re: [PATCH v2 23/28] KVM: VMX: Move LOAD_IA32_PERF_GLOBAL_CTRL errata handling out of setup_vmcs_config()
In reply to Vitaly KuznetsovQuoted 9 lines · Vitaly Kuznetsov
As a preparation to reusing the result of
setup_vmcs_config()for setting up nested VMX control MSRs, moveLOAD_IA32_PERF_GLOBAL_CTRLerrata handling to vmx_vmexit_ctrl()/vmx_vmentry_ctrl() and print the warning fromhardware_setup(). While it seems reasonable to not exposeLOAD_IA32_PERF_GLOBAL_CTRLcontrols to L1 hypervisor on buggy CPUs, such change would inevitably break live migration from older KVMs where the controls are exposed. Keep the status quo for know, L1 hypervisor itself is supposed to take care of the errata.
It can only do that if L1 doesn't lie about the model. This is why F/M/S checks are, in general, evil.
Quoted 10 lines
Signed-off-by Vitaly Kuznetsov <[email protected]>--- arch/x86/kvm/vmx/vmx.c | 62 ++++++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 24 deletions(-)arch/x86/kvm/vmx/vmx.c +0
-0
arch/x86/kvm/vmx/vmx.c static bool cpu_has_sgx(void) · line 2421
Quoted 6 lines
arch/x86/kvm/vmx/vmx.c +3
-0@@ -2416,6 +2416,31 @@ static bool cpu_has_sgx(void)return cpuid_eax (0 ) >=0x12 && (cpuid_eax (0x12 ) &BIT (0 )); } +/* +* Some cpus support VM_{ENTRY,EXIT}_IA32_PERF_GLOBAL_CTRL but they +* can't be used due to an errata where VM Exit may incorrectly clear
Nit: erratum (singular), or drop the 'an' to refer to errata (plural).
arch/x86/kvm/vmx/vmx.c static bool cpu_has_sgx(void) · line 2422
Quoted 1 line
arch/x86/kvm/vmx/vmx.c +1
-0+* IA32_PERF_GLOBAL_CTRL[34:32]. Workaround the errata by using the
Nit: workaround (one word) is a noun. The verb form is "work around."
arch/x86/kvm/vmx/vmx.c static bool cpu_has_sgx(void) · line 2433
Quoted 11 lines
arch/x86/kvm/vmx/vmx.c +11
-0+* MSR load mechanism to switch IA32_PERF_GLOBAL_CTRL. +*/ +static bool cpu_has_perf_global_ctrl_bug (void ) +{ +if (boot_cpu_data.x86 ==0x6 ) { +switch (boot_cpu_data.x86_model) { +case 26 :/* AAK155 */ +case 30 :/* AAP115 */ +case 37 :/* AAT100 */ +case 44 :/* BC86,AAY89,BD102 */ +case 46 :/* BA97 */
Nit: Replace decimal model numbers with mnemonics. See
https://lore.kernel.org/kvm/[email protected]/.
arch/x86/kvm/vmx/vmx.c static bool cpu_has_sgx(void) · line 2441
Quoted 8 lines
arch/x86/kvm/vmx/vmx.c +8
-0+return true; +default : +break ; + } + } + +return false; +}
Is it worth either (a) memoizing the result, or (b) toggling a static branch? Or am I prematurely optimizing?
Quoted 73 lines
arch/x86/kvm/vmx/vmx.c +15
-25+ +static __init int adjust_vmx_controls (u32 ctl_min,u32 ctl_opt,u32 msr,u32 *result) {@@ -2572,30 +2597,6 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf, _vmexit_control &= ~x_ctrl; } -/* -* Some cpus support VM_{ENTRY,EXIT}_IA32_PERF_GLOBAL_CTRL but they -* can't be used due to an errata where VM Exit may incorrectly clear -* IA32_PERF_GLOBAL_CTRL[34:32]. Workaround the errata by using the -* MSR load mechanism to switch IA32_PERF_GLOBAL_CTRL. -*/ -if (boot_cpu_data.x86 ==0x6 ) { -switch (boot_cpu_data.x86_model) { -case 26 :/* AAK155 */ -case 30 :/* AAP115 */ -case 37 :/* AAT100 */ -case 44 :/* BC86,AAY89,BD102 */ -case 46 :/* BA97 */ - _vmentry_control &= ~VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL ; - _vmexit_control &= ~VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL ; -pr_warn_once ("kvm: VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL " -"does not work properly. Using workaround\n" ); -break ; -default : -break ; - } - } - -rdmsr (MSR_IA32_VMX_BASIC , vmx_msr_low, vmx_msr_high);/* IA-32 SDM Vol 3B: VMCS size is never greater than 4kB. */ @@ -4188,6 +4189,10 @@ static u32 vmx_vmentry_ctrl(void)VM_ENTRY_LOAD_IA32_EFER | VM_ENTRY_IA32E_MODE); + +if (cpu_has_perf_global_ctrl_bug ()) + vmentry_ctrl &= ~VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL ; +return vmentry_ctrl; }@@ -4202,6 +4207,10 @@ static u32 vmx_vmexit_ctrl(void)if (vmx_pt_mode_is_system ()) vmexit_ctrl &= ~(VM_EXIT_PT_CONCEAL_PIP |VM_EXIT_CLEAR_IA32_RTIT_CTL ); + +if (cpu_has_perf_global_ctrl_bug ()) + vmexit_ctrl &= ~VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL ; +/* Loading of EFER and PERF_GLOBAL_CTRL are toggled dynamically */ return vmexit_ctrl & ~(VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL |VM_EXIT_LOAD_IA32_EFER );@@ -8117,6 +8126,11 @@ static __init int hardware_setup(void)if (setup_vmcs_config (&vmcs_config, &vmx_capability) <0 )return -EIO ; +if (cpu_has_perf_global_ctrl_bug ()) { +pr_warn_once ("kvm: VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL " +"does not work properly. Using workaround\n" ); + } +if (boot_cpu_has (X86_FEATURE_NX ))kvm_enable_efer_bits (EFER_NX ); --2.35.3
Re: [PATCH v2 24/28] KVM: nVMX: Use sanitized allowed-1 bits for VMX control MSRs
In reply to Vitaly KuznetsovQuoted 22 lines · Vitaly Kuznetsov
Using raw host MSR values for setting up nested VMX control MSRs is incorrect as some features need to disabled, e.g. when KVM runs as a nested hypervisor on Hyper-V and uses Enlightened VMCS or when a workaround for
IA32_PERF_GLOBAL_CTRLis applied. For non-nested VMX, this is done insetup_vmcs_config()and the result is stored invmcs_config. Use it for setting up allowed-1 bits in nested VMX MSRs too.Suggested-by Sean Christopherson <[email protected]>Signed-off-by Vitaly Kuznetsov <[email protected]>--- arch/x86/kvm/vmx/nested.c | 34 ++++++++++++++++------------------ arch/x86/kvm/vmx/nested.h | 2 +- arch/x86/kvm/vmx/vmx.c | 5 ++--- 3 files changed, 19 insertions(+), 22 deletions(-)arch/x86/kvm/vmx/nested.c +0
-0@@ -6565,8 +6565,13 @@ static u64 nested_vmx_calc_vmcs_enum_msr(void)* bit in the high half is on if the corresponding bit in the control field
arch/x86/kvm/vmx/nested.c static u64 nested_vmx_calc_vmcs_enum_msr(void) · line 6574
Quoted 10 lines
arch/x86/kvm/vmx/nested.c +6
-1* may be on. See also vmx_control_verify(). */ -void nested_vmx_setup_ctls_msrs (struct nested_vmx_msrs *msrs,u32 ept_caps) +void nested_vmx_setup_ctls_msrs (struct vmcs_config *vmcs_conf,u32 ept_caps) { +struct nested_vmx_msrs *msrs = &vmcs_conf->nested; + +/* Take the allowed-1 bits from KVM's sanitized VMCS configuration. */ +u32 ignore_high; +
Giving this object a name seems gauche.
arch/x86/kvm/vmx/nested.c void nested_vmx_setup_ctls_msrs(struct nested_vmx_msrs *msrs, u32 ept_caps) · line 6591
Quoted 11 lines
arch/x86/kvm/vmx/nested.c +1
-3/* * Note that as a general rule, the high half of the MSRs (bits in * the control fields which may be 1) should be initialized by the @@ -6583,11 +6588,11 @@ void nested_vmx_setup_ctls_msrs(struct nested_vmx_msrs *msrs, u32 ept_caps)*/ /* pin-based controls */ -rdmsr (MSR_IA32_VMX_PINBASED_CTLS , - msrs->pinbased_ctls_low, - msrs->pinbased_ctls_high); +rdmsr (MSR_IA32_VMX_PINBASED_CTLS , msrs->pinbased_ctls_low, ignore_high);
Perhaps "(u32){0}" rather than "ignore_high"?
arch/x86/kvm/vmx/nested.c void nested_vmx_setup_ctls_msrs(struct nested_vmx_msrs *msrs, u32 ept_caps) · line 6593
Quoted 2 lines
arch/x86/kvm/vmx/nested.c +0
-0msrs->pinbased_ctls_low |=PIN_BASED_ALWAYSON_WITHOUT_TRUE_MSR ;
NYC, but why is this one '|=', and the rest just '='? Does there exist a CPU that requires more than PIN_BASED_ALWAYSON_WITHOUT_TRUE_MSR?
Quoted 101 lines
arch/x86/kvm/vmx/nested.c +9
-14+ + msrs->pinbased_ctls_high = vmcs_conf->pin_based_exec_ctrl; msrs->pinbased_ctls_high &=PIN_BASED_EXT_INTR_MASK | PIN_BASED_NMI_EXITING |@@ -6598,12 +6603,10 @@ void nested_vmx_setup_ctls_msrs(struct nested_vmx_msrs *msrs, u32 ept_caps)PIN_BASED_VMX_PREEMPTION_TIMER ;/* exit controls */ -rdmsr (MSR_IA32_VMX_EXIT_CTLS , - msrs->exit_ctls_low, - msrs->exit_ctls_high); msrs->exit_ctls_low =VM_EXIT_ALWAYSON_WITHOUT_TRUE_MSR ; + msrs->exit_ctls_high = vmcs_conf->vmexit_ctrl; msrs->exit_ctls_high &=#ifdef CONFIG_X86_64 VM_EXIT_HOST_ADDR_SPACE_SIZE |@@ -6619,11 +6622,10 @@ void nested_vmx_setup_ctls_msrs(struct nested_vmx_msrs *msrs, u32 ept_caps) msrs->exit_ctls_low &= ~VM_EXIT_SAVE_DEBUG_CONTROLS ;/* entry controls */ -rdmsr (MSR_IA32_VMX_ENTRY_CTLS , - msrs->entry_ctls_low, - msrs->entry_ctls_high); msrs->entry_ctls_low =VM_ENTRY_ALWAYSON_WITHOUT_TRUE_MSR ; + + msrs->entry_ctls_high = vmcs_conf->vmentry_ctrl; msrs->entry_ctls_high &=#ifdef CONFIG_X86_64 VM_ENTRY_IA32E_MODE |@@ -6637,11 +6639,10 @@ void nested_vmx_setup_ctls_msrs(struct nested_vmx_msrs *msrs, u32 ept_caps) msrs->entry_ctls_low &= ~VM_ENTRY_LOAD_DEBUG_CONTROLS ;/* cpu-based controls */ -rdmsr (MSR_IA32_VMX_PROCBASED_CTLS , - msrs->procbased_ctls_low, - msrs->procbased_ctls_high); msrs->procbased_ctls_low =CPU_BASED_ALWAYSON_WITHOUT_TRUE_MSR ; + + msrs->procbased_ctls_high = vmcs_conf->cpu_based_exec_ctrl; msrs->procbased_ctls_high &=CPU_BASED_INTR_WINDOW_EXITING | CPU_BASED_NMI_WINDOW_EXITING | CPU_BASED_USE_TSC_OFFSETTING |@@ -6675,12 +6676,9 @@ void nested_vmx_setup_ctls_msrs(struct nested_vmx_msrs *msrs, u32 ept_caps)* depend on CPUID bits, they are added later by * vmx_vcpu_after_set_cpuid. */ -if (msrs->procbased_ctls_high &CPU_BASED_ACTIVATE_SECONDARY_CONTROLS ) -rdmsr (MSR_IA32_VMX_PROCBASED_CTLS2 , - msrs->secondary_ctls_low, - msrs->secondary_ctls_high); - msrs->secondary_ctls_low =0 ; + + msrs->secondary_ctls_high = vmcs_conf->cpu_based_2nd_exec_ctrl; msrs->secondary_ctls_high &=SECONDARY_EXEC_DESC | SECONDARY_EXEC_ENABLE_RDTSCP |arch/x86/kvm/vmx/nested.h +1
-1@@ -17,7 +17,7 @@ enum nvmx_vmentry_status { };void vmx_leave_nested (struct kvm_vcpu *vcpu); -void nested_vmx_setup_ctls_msrs (struct nested_vmx_msrs *msrs,u32 ept_caps); +void nested_vmx_setup_ctls_msrs (struct vmcs_config *vmcs_conf,u32 ept_caps);void nested_vmx_hardware_unsetup (void );__init int nested_vmx_hardware_setup (int (*exit_handlers[])(struct kvm_vcpu *));void nested_vmx_set_vmcs_shadowing_bitmap (void );arch/x86/kvm/vmx/vmx.c +2
-4@@ -7310,7 +7310,7 @@ static int __init vmx_check_processor_compat(void)if (setup_vmcs_config (&vmcs_conf, &vmx_cap) <0 )return -EIO ;if (nested) -nested_vmx_setup_ctls_msrs (&vmcs_conf.nested, vmx_cap.ept); +nested_vmx_setup_ctls_msrs (&vmcs_conf, vmx_cap.ept);if (memcmp (&vmcs_config, &vmcs_conf,sizeof (struct vmcs_config )) !=0 ) {printk (KERN_ERR "kvm: CPU %d feature inconsistency!\n" ,smp_processor_id ());@@ -8285,8 +8285,7 @@ static __init int hardware_setup(void)setup_default_sgx_lepubkeyhash ();if (nested) { -nested_vmx_setup_ctls_msrs (&vmcs_config.nested, - vmx_capability.ept); +nested_vmx_setup_ctls_msrs (&vmcs_config, vmx_capability.ept); r =nested_vmx_hardware_setup (kvm_vmx_exit_handlers);if (r) --2.35.3
Sean Christopherson
maintainerRe: [PATCH v2 15/28] KVM: VMX: Check CPU_BASED_{INTR,NMI}_WINDOW_EXITING in setup_vmcs_config()
In reply to Vitaly KuznetsovQuoted 18 lines · Vitaly Kuznetsov
CPU_BASED_{INTR,NMI}_WINDOW_EXITING controls are toggled dynamically by vmx_enable_{irq,nmi}_window,
handle_interrupt_window(),handle_nmi_window()butsetup_vmcs_config()doesn't check their existence. Add the check and filter the controls out invmx_exec_control().No (real) functional change intended as all existing CPUs supporting VMX are supposed to have these controls.
Signed-off-by Vitaly Kuznetsov <[email protected]>--- arch/x86/kvm/vmx/vmx.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)arch/x86/kvm/vmx/vmx.c +0
-0
arch/x86/kvm/vmx/vmx.c static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf, · line 2492
Quoted 7 lines
arch/x86/kvm/vmx/vmx.c +3
-1@@ -2487,7 +2487,9 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf,CPU_BASED_MWAIT_EXITING |CPU_BASED_MONITOR_EXITING |CPU_BASED_INVLPG_EXITING | -CPU_BASED_RDPMC_EXITING ; +CPU_BASED_RDPMC_EXITING | +CPU_BASED_INTR_WINDOW_EXITING | +CPU_BASED_NMI_WINDOW_EXITING ;
Requiring NMI_WINDOW_EXITING is wrong, KVM doesn't use NMI_WINDOW_EXITING if enable_vnmi == false:
if (!enable_vnmi ||
vmcs_read32(GUEST_INTERRUPTIBILITY_INFO) & GUEST_INTR_STATE_STI) {
vmx_enable_irq_window(vcpu);
return;
}
exec_controls_setbit(to_vmx(vcpu), CPU_BASED_NMI_WINDOW_EXITING);And enable_vnmi is cleared if PIN_BASED_VIRTUAL_NMIS are unsupported:
if (!cpu_has_virtual_nmis()) enable_vnmi = 0;
I suspect CPUs that don't support VIRTUAL_NMIS also don't support NMI_WINDOW_EXITING, and KVM explicitly supports such CPUs. See commit 8a1b43922d0d ("kvm: vmx: Reinstate support for CPUs without virtual NMI").
Making NMI_WINDOW_EXITING optional and then adding it to cpu_has_virtual_nmis() seems like the correct approach.
arch/x86/kvm/vmx/capabilities.h +2 -1
@@ -82,7 +82,8 @@ static inline bool cpu_has_vmx_basic_inout(void)static inline bool cpu_has_virtual_nmis (void ) { -return vmcs_config.pin_based_exec_ctrl &PIN_BASED_VIRTUAL_NMIS ; +return vmcs_config.pin_based_exec_ctrl &PIN_BASED_VIRTUAL_NMIS && + vmcs_config.cpu_based_exec_ctrl &CPU_BASED_NMI_WINDOW_EXITING ; }static inline bool cpu_has_vmx_preemption_timer (void )
Quoted 16 lines
arch/x86/kvm/vmx/vmx.c +4
-0opt =CPU_BASED_TPR_SHADOW | CPU_BASED_USE_MSR_BITMAPS |@@ -4300,6 +4302,10 @@ static u32 vmx_exec_control(struct vcpu_vmx *vmx) {u32 exec_control = vmcs_config.cpu_based_exec_ctrl; +/* INTR_WINDOW_EXITING and NMI_WINDOW_EXITING are toggled dynamically */ + exec_control &= ~(CPU_BASED_INTR_WINDOW_EXITING | +CPU_BASED_NMI_WINDOW_EXITING ); +if (vmx->vcpu.arch.switch_db_regs &KVM_DEBUGREG_WONT_EXIT ) exec_control &= ~CPU_BASED_MOV_DR_EXITING ;Signature · 1 line
2.35.3
Sean Christopherson
maintainerRe: [PATCH v2 06/28] KVM: nVMX: Introduce KVM_CAP_HYPERV_ENLIGHTENED_VMCS2
In reply to Vitaly KuznetsovQuoted 10 lines · Vitaly Kuznetsov
Turns out Enlightened VMCS can gain new fields without version change and
KVM_CAP_HYPERV_ENLIGHTENED_VMCSwhich KVM currently has cant's handle this reliably. In particular, just updating the current definition of eVMCSv1 with the new fields and adjusting the VMX MSR filtering will inevitably break live migration to older KVMs. Note: enabling eVMCS and setting VMX feature MSR can happen in any order.Introduce a notion of KVM internal "Enlightened VMCS revision" and add a new capability allowing to add fields to Enlightened VMCS while keeping its version.
Bumping a "minor" version number in KVM is going to be a nightmare. KVM is going to be stuck "supporting" old revisions in perpetuity, and userspace will be forced to keep track of which features are available with which arbitrary revision (is that information even communicated to userspace?).
I think a more maintainable approach would be to expose the "filtered" VMX MSRs to userspace, e.g. add KVM_GET_EVMCS_VMX_MSRS. Then KVM just needs to document what the "filters" are for KVM versions that don't support KVM_GET_EVMCS_VMX_MSRS. KVM itself doesn't need to maintain version information because it's userspace's responsibility to ensure that userspace doesn't try to migrate to a KVM that doesn't support the desired feature set.
That also avoids messes like unnecessarily blocking migration from "incompatible" revisions when running on hardware that doesn't even support the control.
Sean Christopherson
maintainerRe: [PATCH v2 13/28] KVM: VMX: Get rid of eVMCS specific VMX controls sanitization
In reply to Vitaly KuznetsovQuoted 3 lines · Vitaly Kuznetsov
With the updated eVMCSv1 definition, there's no known 'problematic' controls which are exposed in VMX control MSRs but are not present in eVMCSv1. Get rid of the filtering.
Ah, this patch is confusing until one realizes that this is dropping the "filtering" for what controls/features _KVM_ uses, whereas nested_evmcs_filter_control_msr() filters controls that are presented to L1.
Can you add something to clarify that in the changelog?
Vitaly Kuznetsov
maintainerRe: [PATCH v2 06/28] KVM: nVMX: Introduce KVM_CAP_HYPERV_ENLIGHTENED_VMCS2
In reply to Sean ChristophersonQuoted 8 lines · Sean Christopherson
Quoted 7 lines · Vitaly Kuznetsov
Turns out Enlightened VMCS can gain new fields without version change and
KVM_CAP_HYPERV_ENLIGHTENED_VMCSwhich KVM currently has cant's handle this reliably. In particular, just updating the current definition of eVMCSv1 with the new fields and adjusting the VMX MSR filtering will inevitably break live migration to older KVMs. Note: enabling eVMCS and setting VMX feature MSR can happen in any order.
Quoted 8 lines
Quoted 3 lines
Introduce a notion of KVM internal "Enlightened VMCS revision" and add a new capability allowing to add fields to Enlightened VMCS while keeping its version.
Bumping a "minor" version number in KVM is going to be a nightmare. KVM is going to be stuck "supporting" old revisions in perpetuity, and userspace will be forced to keep track of which features are available with which arbitrary revision (is that information even communicated to userspace?).
My brain is certainly tainted with how we enable this in QEMU but why would userspace be interested in which features are actually filtered out?
Currently (again, by QEMU), eVMCS is treated as a purely software feature. When enabled, certain controls are filtered out "under the hood" as VMX MSRs reported to VMM remain unfiltered (see '!msr_info->host_initiated' in vmx_get_msr()). Same stays true with any new revision: VMM's job is just to check that a) all hardware features are supported on both source and destination and b) the requested 'eVMCS revision' is supported by both. No need to know what's filtered out and what isn't.
Quoted 7 lines
I think a more maintainable approach would be to expose the "filtered" VMX MSRs to userspace, e.g. add
KVM_GET_EVMCS_VMX_MSRS. Then KVM just needs to document what the "filters" are for KVM versions that don't supportKVM_GET_EVMCS_VMX_MSRS. KVM itself doesn't need to maintain version information because it's userspace's responsibility to ensure that userspace doesn't try to migrate to a KVM that doesn't support the desired feature set.
That would be a reasonable (but complex for VMM) approach too but I don't think we need this (and this patch introducing 'eVMCS revisions' to this matter): luckily, Microsoft added a new PV CPUID feature bit inidicating the support for the new features in eVMCSv1 so KVM can just observe whether the bit was set by VMM or not and filter accordingly.
Quoted 3 lines
That also avoids messes like unnecessarily blocking migration from "incompatible" revisions when running on hardware that doesn't even support the control.
Well yea, in case the difference between 'eVMCS revisions' is void because the hardware doesn't support these, it would still be possible to migrate to an older KVM which doesn't support the new revision but I'd stay strict: if a newer revision was requested it must be supported, no matter the hardware.
Signature · 1 line
Vitaly
Vitaly Kuznetsov
maintainerRe: [PATCH v2 08/28] KVM: VMX: Support TSC scaling with enlightened VMCS
In reply to Vitaly KuznetsovVitaly Kuznetsov <[email protected]> writes:
...
Quoted 3 lines
While on it, update the comment why VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL/
VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRLare kept filtered out
...
Quoted 4 lines
+ * While
GUEST_IA32_PERF_GLOBAL_CTRLandHOST_IA32_PERF_GLOBAL_CTRL
+ * are present in eVMCSv1, Windows 11 still has issues booting when
+ * VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL/VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL
+ * are exposed to it, keep them filtered out.
Finally, I got a piece of information from Microsoft on what's going on and it solves a lot of our problems. They did introduce a new PV feature bit indicating support for these new fields in eVMCSv1 and Win11 checks for its presence. This means that we do not need to play the 'eVMCS revisions' trick as CPUID information from VMM is enough.
Signature · 1 line
Vitaly
Vitaly Kuznetsov
maintainerRe: [PATCH v2 13/28] KVM: VMX: Get rid of eVMCS specific VMX controls sanitization
In reply to Sean ChristophersonQuoted 10 lines · Sean Christopherson
Quoted 3 lines · Vitaly Kuznetsov
With the updated eVMCSv1 definition, there's no known 'problematic' controls which are exposed in VMX control MSRs but are not present in eVMCSv1. Get rid of the filtering.
Ah, this patch is confusing until one realizes that this is dropping the "filtering" for what controls/features _KVM_ uses, whereas
nested_evmcs_filter_control_msr()filters controls that are presented to L1.Can you add something to clarify that in the changelog?
Yea, this is for KVM-on-Hyper-V only, I'll fix the changelog.
Signature · 1 line
Vitaly
Vitaly Kuznetsov
maintainerRe: [PATCH v2 20/28] KVM: VMX: Add missing VMENTRY controls to vmcs_config
In reply to Jim MattsonQuoted 23 lines · Jim Mattson
Quoted 22 lines · Vitaly Kuznetsov
As a preparation to reusing the result of
setup_vmcs_config()in nested VMX MSR setup, add the VMENTRY controls which KVM doesn't use but supports for nVMX toKVM_OPT_VMX_VM_ENTRY_CONTROLSand filter them out invmx_vmentry_ctrl().No functional change intended.
Signed-off-by Vitaly Kuznetsov <[email protected]>--- arch/x86/kvm/vmx/vmx.c | 3 +++ arch/x86/kvm/vmx/vmx.h | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-)arch/x86/kvm/vmx/vmx.c +0
-0@@ -4179,6 +4179,9 @@ static u32 vmx_vmentry_ctrl(void) {u32 vmentry_ctrl = vmcs_config.vmentry_ctrl;
Quoted 7 lines
arch/x86/kvm/vmx/vmx.c static u32 vmx_vmentry_ctrl(void) · line 4184
Quoted 3 lines
arch/x86/kvm/vmx/vmx.c +3
-0+/* Not used by KVM but supported for nesting. */ + vmentry_ctrl &= ~(VM_ENTRY_SMM |VM_ENTRY_DEACT_DUAL_MONITOR ); +LOL! KVM does not emulate the dual-monitor treatment of SMIs and SMM. Do we actually claim to support these VM-entry controls today?!?
No, just a brainfart on my side, nested_vmx_setup_ctls_msrs() filters them out too. I'll drop the patch.
Quoted 22 lines
Quoted 21 lines
arch/x86/kvm/vmx/vmx.c +0
-0if (vmx_pt_mode_is_system ()) vmentry_ctrl &= ~(VM_ENTRY_PT_CONCEAL_PIP |VM_ENTRY_LOAD_IA32_RTIT_CTL );arch/x86/kvm/vmx/vmx.h +3
-2@@ -479,7 +479,9 @@ static inline u8 vmx_get_rvi(void) __KVM_REQ_VMX_VM_ENTRY_CONTROLS#endif #define KVM_OPT_VMX_VM_ENTRY_CONTROLS \ - (VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL | \ + (VM_ENTRY_SMM | \ + VM_ENTRY_DEACT_DUAL_MONITOR | \ + VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL | \ VM_ENTRY_LOAD_IA32_PAT | \ VM_ENTRY_LOAD_IA32_EFER | \ VM_ENTRY_LOAD_BNDCFGS | \ --2.35.3
Signature · 1 line
Vitaly
Vitaly Kuznetsov
maintainerRe: [PATCH v2 23/28] KVM: VMX: Move LOAD_IA32_PERF_GLOBAL_CTRL errata handling out of setup_vmcs_config()
In reply to Jim MattsonQuoted 33 lines · Jim Mattson
Quoted 9 lines · Vitaly Kuznetsov
As a preparation to reusing the result of
setup_vmcs_config()for setting up nested VMX control MSRs, moveLOAD_IA32_PERF_GLOBAL_CTRLerrata handling to vmx_vmexit_ctrl()/vmx_vmentry_ctrl() and print the warning fromhardware_setup(). While it seems reasonable to not exposeLOAD_IA32_PERF_GLOBAL_CTRLcontrols to L1 hypervisor on buggy CPUs, such change would inevitably break live migration from older KVMs where the controls are exposed. Keep the status quo for know, L1 hypervisor itself is supposed to take care of the errata.It can only do that if L1 doesn't lie about the model. This is why F/M/S checks are, in general, evil.
Quoted 10 lines
Signed-off-by Vitaly Kuznetsov <[email protected]>--- arch/x86/kvm/vmx/vmx.c | 62 ++++++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 24 deletions(-)arch/x86/kvm/vmx/vmx.c +0
-0arch/x86/kvm/vmx/vmx.c static bool cpu_has_sgx(void) · line 2421
Quoted 6 lines
arch/x86/kvm/vmx/vmx.c +3
-0@@ -2416,6 +2416,31 @@ static bool cpu_has_sgx(void)return cpuid_eax (0 ) >=0x12 && (cpuid_eax (0x12 ) &BIT (0 )); } +/* +* Some cpus support VM_{ENTRY,EXIT}_IA32_PERF_GLOBAL_CTRL but they +* can't be used due to an errata where VM Exit may incorrectly clear Nit: erratum (singular), or drop the 'an' to refer to errata (plural).
Quoted 4 lines
arch/x86/kvm/vmx/vmx.c static bool cpu_has_sgx(void) · line 2422
Quoted 1 line
arch/x86/kvm/vmx/vmx.c +1
-0+* IA32_PERF_GLOBAL_CTRL[34:32]. Workaround the errata by using the Nit: workaround (one word) is a noun. The verb form is "work around."
Sure, but I'm not exactly certain which commit to blame here as I have options:
where it was introduced or
where it was preserved :-)
Quoted 6 lines
Quoted 6 lines
arch/x86/kvm/vmx/vmx.c +6
-0+* MSR load mechanism to switch IA32_PERF_GLOBAL_CTRL. +*/ +static bool cpu_has_perf_global_ctrl_bug (void ) +{ +if (boot_cpu_data.x86 ==0x6 ) { +switch (boot_cpu_data.x86_model) {
Quoted 9 lines
arch/x86/kvm/vmx/vmx.c static bool cpu_has_sgx(void) · line 2433
Quoted 5 lines
arch/x86/kvm/vmx/vmx.c +5
-0+case 26 :/* AAK155 */ +case 30 :/* AAP115 */ +case 37 :/* AAT100 */ +case 44 :/* BC86,AAY89,BD102 */ +case 46 :/* BA97 */ Nit: Replace decimal model numbers with mnemonics. See
https://lore.kernel.org/kvm/[email protected]/.
I'm going to steal your patch and put it to my series (as I don't see it in kvm/queue yet).
Quoted 12 lines
arch/x86/kvm/vmx/vmx.c static bool cpu_has_sgx(void) · line 2441
Quoted 8 lines
arch/x86/kvm/vmx/vmx.c +8
-0+return true; +default : +break ; + } + } + +return false; +}Is it worth either (a) memoizing the result, or (b) toggling a static branch? Or am I prematurely optimizing?
(Unless I missed something) besides hardware_setup(), cpu_has_perf_global_ctrl_bug() is only called (twice) from:
vmx_vcpu_reset()
__vmx_vcpu_reset() init_vmcs() vmx_vmentry_ctrl() vmx_vmexit_ctrl()
this shouldn't happen very often so I guess we can leave it un-optimized. Also, we're only reading boot_cpu_data.x86/ boot_cpu_data.x86_model here, this should be cheap).
Quoted 74 lines
Quoted 73 lines
arch/x86/kvm/vmx/vmx.c +15
-25+ +static __init int adjust_vmx_controls (u32 ctl_min,u32 ctl_opt,u32 msr,u32 *result) {@@ -2572,30 +2597,6 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf, _vmexit_control &= ~x_ctrl; } -/* -* Some cpus support VM_{ENTRY,EXIT}_IA32_PERF_GLOBAL_CTRL but they -* can't be used due to an errata where VM Exit may incorrectly clear -* IA32_PERF_GLOBAL_CTRL[34:32]. Workaround the errata by using the -* MSR load mechanism to switch IA32_PERF_GLOBAL_CTRL. -*/ -if (boot_cpu_data.x86 ==0x6 ) { -switch (boot_cpu_data.x86_model) { -case 26 :/* AAK155 */ -case 30 :/* AAP115 */ -case 37 :/* AAT100 */ -case 44 :/* BC86,AAY89,BD102 */ -case 46 :/* BA97 */ - _vmentry_control &= ~VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL ; - _vmexit_control &= ~VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL ; -pr_warn_once ("kvm: VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL " -"does not work properly. Using workaround\n" ); -break ; -default : -break ; - } - } - -rdmsr (MSR_IA32_VMX_BASIC , vmx_msr_low, vmx_msr_high);/* IA-32 SDM Vol 3B: VMCS size is never greater than 4kB. */ @@ -4188,6 +4189,10 @@ static u32 vmx_vmentry_ctrl(void)VM_ENTRY_LOAD_IA32_EFER | VM_ENTRY_IA32E_MODE); + +if (cpu_has_perf_global_ctrl_bug ()) + vmentry_ctrl &= ~VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL ; +return vmentry_ctrl; }@@ -4202,6 +4207,10 @@ static u32 vmx_vmexit_ctrl(void)if (vmx_pt_mode_is_system ()) vmexit_ctrl &= ~(VM_EXIT_PT_CONCEAL_PIP |VM_EXIT_CLEAR_IA32_RTIT_CTL ); + +if (cpu_has_perf_global_ctrl_bug ()) + vmexit_ctrl &= ~VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL ; +/* Loading of EFER and PERF_GLOBAL_CTRL are toggled dynamically */ return vmexit_ctrl & ~(VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL |VM_EXIT_LOAD_IA32_EFER );@@ -8117,6 +8126,11 @@ static __init int hardware_setup(void)if (setup_vmcs_config (&vmcs_config, &vmx_capability) <0 )return -EIO ; +if (cpu_has_perf_global_ctrl_bug ()) { +pr_warn_once ("kvm: VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL " +"does not work properly. Using workaround\n" ); + } +if (boot_cpu_has (X86_FEATURE_NX ))kvm_enable_efer_bits (EFER_NX ); --2.35.3
Signature · 1 line
Vitaly
Vitaly Kuznetsov
maintainerRe: [PATCH v2 24/28] KVM: nVMX: Use sanitized allowed-1 bits for VMX control MSRs
In reply to Jim MattsonQuoted 42 lines · Jim Mattson
Quoted 22 lines · Vitaly Kuznetsov
Using raw host MSR values for setting up nested VMX control MSRs is incorrect as some features need to disabled, e.g. when KVM runs as a nested hypervisor on Hyper-V and uses Enlightened VMCS or when a workaround for
IA32_PERF_GLOBAL_CTRLis applied. For non-nested VMX, this is done insetup_vmcs_config()and the result is stored invmcs_config. Use it for setting up allowed-1 bits in nested VMX MSRs too.Suggested-by Sean Christopherson <[email protected]>Signed-off-by Vitaly Kuznetsov <[email protected]>--- arch/x86/kvm/vmx/nested.c | 34 ++++++++++++++++------------------ arch/x86/kvm/vmx/nested.h | 2 +- arch/x86/kvm/vmx/vmx.c | 5 ++--- 3 files changed, 19 insertions(+), 22 deletions(-)arch/x86/kvm/vmx/nested.c +0
-0@@ -6565,8 +6565,13 @@ static u64 nested_vmx_calc_vmcs_enum_msr(void)* bit in the high half is on if the corresponding bit in the control field arch/x86/kvm/vmx/nested.c static u64 nested_vmx_calc_vmcs_enum_msr(void) · line 6574
Quoted 10 lines
arch/x86/kvm/vmx/nested.c +6
-1* may be on. See also vmx_control_verify(). */ -void nested_vmx_setup_ctls_msrs (struct nested_vmx_msrs *msrs,u32 ept_caps) +void nested_vmx_setup_ctls_msrs (struct vmcs_config *vmcs_conf,u32 ept_caps) { +struct nested_vmx_msrs *msrs = &vmcs_conf->nested; + +/* Take the allowed-1 bits from KVM's sanitized VMCS configuration. */ +u32 ignore_high; +Giving this object a name seems gauche.
Quoted 6 lines
arch/x86/kvm/vmx/nested.c +0
-0/* * Note that as a general rule, the high half of the MSRs (bits in * the control fields which may be 1) should be initialized by the @@ -6583,11 +6588,11 @@ void nested_vmx_setup_ctls_msrs(struct nested_vmx_msrs *msrs, u32 ept_caps)*/
Quoted 8 lines
arch/x86/kvm/vmx/nested.c void nested_vmx_setup_ctls_msrs(struct nested_vmx_msrs *msrs, u32 ept_caps) · line 6591
Quoted 5 lines
arch/x86/kvm/vmx/nested.c +1
-3/* pin-based controls */ -rdmsr (MSR_IA32_VMX_PINBASED_CTLS , - msrs->pinbased_ctls_low, - msrs->pinbased_ctls_high); +rdmsr (MSR_IA32_VMX_PINBASED_CTLS , msrs->pinbased_ctls_low, ignore_high);Perhaps "(u32){0}" rather than "
ignore_high"?
While this certainly looks like a cool trick (thanks!), both rdmsr() and 'ignore_high' are gone later in the series. I will, however, adopt the change, even if just to show off)
Quoted 6 lines
arch/x86/kvm/vmx/nested.c void nested_vmx_setup_ctls_msrs(struct nested_vmx_msrs *msrs, u32 ept_caps) · line 6593
Quoted 2 lines
arch/x86/kvm/vmx/nested.c +0
-0msrs->pinbased_ctls_low |=PIN_BASED_ALWAYSON_WITHOUT_TRUE_MSR ;NYC, but why is this one '|=', and the rest just '='? Does there exist a CPU that requires more than
PIN_BASED_ALWAYSON_WITHOUT_TRUE_MSR?
Looking at the commit which introduced this,
commit eabeaaccfca0ed61b8e00a09b8cfa703c4f11b59
Author: Jan Kiszka <[email protected]> Date: Wed Mar 13 11:30:50 2013 +0100
KVM: nVMX: Clean up and fix pin-based execution controls
I don't think '|=' is needed. It is, of course, possible that when KVM is running nested, required-1 bits are mangled by the underlying hypervisor but this is a) unlikely b) will only be observed by KVM's L1 (which means we're talking about 3-level nesting here).
Let's be brave and 'fix' '|=' here.
Quoted 102 lines
Quoted 101 lines
arch/x86/kvm/vmx/nested.c +9
-14+ + msrs->pinbased_ctls_high = vmcs_conf->pin_based_exec_ctrl; msrs->pinbased_ctls_high &=PIN_BASED_EXT_INTR_MASK | PIN_BASED_NMI_EXITING |@@ -6598,12 +6603,10 @@ void nested_vmx_setup_ctls_msrs(struct nested_vmx_msrs *msrs, u32 ept_caps)PIN_BASED_VMX_PREEMPTION_TIMER ;/* exit controls */ -rdmsr (MSR_IA32_VMX_EXIT_CTLS , - msrs->exit_ctls_low, - msrs->exit_ctls_high); msrs->exit_ctls_low =VM_EXIT_ALWAYSON_WITHOUT_TRUE_MSR ; + msrs->exit_ctls_high = vmcs_conf->vmexit_ctrl; msrs->exit_ctls_high &=#ifdef CONFIG_X86_64 VM_EXIT_HOST_ADDR_SPACE_SIZE |@@ -6619,11 +6622,10 @@ void nested_vmx_setup_ctls_msrs(struct nested_vmx_msrs *msrs, u32 ept_caps) msrs->exit_ctls_low &= ~VM_EXIT_SAVE_DEBUG_CONTROLS ;/* entry controls */ -rdmsr (MSR_IA32_VMX_ENTRY_CTLS , - msrs->entry_ctls_low, - msrs->entry_ctls_high); msrs->entry_ctls_low =VM_ENTRY_ALWAYSON_WITHOUT_TRUE_MSR ; + + msrs->entry_ctls_high = vmcs_conf->vmentry_ctrl; msrs->entry_ctls_high &=#ifdef CONFIG_X86_64 VM_ENTRY_IA32E_MODE |@@ -6637,11 +6639,10 @@ void nested_vmx_setup_ctls_msrs(struct nested_vmx_msrs *msrs, u32 ept_caps) msrs->entry_ctls_low &= ~VM_ENTRY_LOAD_DEBUG_CONTROLS ;/* cpu-based controls */ -rdmsr (MSR_IA32_VMX_PROCBASED_CTLS , - msrs->procbased_ctls_low, - msrs->procbased_ctls_high); msrs->procbased_ctls_low =CPU_BASED_ALWAYSON_WITHOUT_TRUE_MSR ; + + msrs->procbased_ctls_high = vmcs_conf->cpu_based_exec_ctrl; msrs->procbased_ctls_high &=CPU_BASED_INTR_WINDOW_EXITING | CPU_BASED_NMI_WINDOW_EXITING | CPU_BASED_USE_TSC_OFFSETTING |@@ -6675,12 +6676,9 @@ void nested_vmx_setup_ctls_msrs(struct nested_vmx_msrs *msrs, u32 ept_caps)* depend on CPUID bits, they are added later by * vmx_vcpu_after_set_cpuid. */ -if (msrs->procbased_ctls_high &CPU_BASED_ACTIVATE_SECONDARY_CONTROLS ) -rdmsr (MSR_IA32_VMX_PROCBASED_CTLS2 , - msrs->secondary_ctls_low, - msrs->secondary_ctls_high); - msrs->secondary_ctls_low =0 ; + + msrs->secondary_ctls_high = vmcs_conf->cpu_based_2nd_exec_ctrl; msrs->secondary_ctls_high &=SECONDARY_EXEC_DESC | SECONDARY_EXEC_ENABLE_RDTSCP |arch/x86/kvm/vmx/nested.h +1
-1@@ -17,7 +17,7 @@ enum nvmx_vmentry_status { };void vmx_leave_nested (struct kvm_vcpu *vcpu); -void nested_vmx_setup_ctls_msrs (struct nested_vmx_msrs *msrs,u32 ept_caps); +void nested_vmx_setup_ctls_msrs (struct vmcs_config *vmcs_conf,u32 ept_caps);void nested_vmx_hardware_unsetup (void );__init int nested_vmx_hardware_setup (int (*exit_handlers[])(struct kvm_vcpu *));void nested_vmx_set_vmcs_shadowing_bitmap (void );arch/x86/kvm/vmx/vmx.c +2
-4@@ -7310,7 +7310,7 @@ static int __init vmx_check_processor_compat(void)if (setup_vmcs_config (&vmcs_conf, &vmx_cap) <0 )return -EIO ;if (nested) -nested_vmx_setup_ctls_msrs (&vmcs_conf.nested, vmx_cap.ept); +nested_vmx_setup_ctls_msrs (&vmcs_conf, vmx_cap.ept);if (memcmp (&vmcs_config, &vmcs_conf,sizeof (struct vmcs_config )) !=0 ) {printk (KERN_ERR "kvm: CPU %d feature inconsistency!\n" ,smp_processor_id ());@@ -8285,8 +8285,7 @@ static __init int hardware_setup(void)setup_default_sgx_lepubkeyhash ();if (nested) { -nested_vmx_setup_ctls_msrs (&vmcs_config.nested, - vmx_capability.ept); +nested_vmx_setup_ctls_msrs (&vmcs_config, vmx_capability.ept); r =nested_vmx_hardware_setup (kvm_vmx_exit_handlers);if (r) --2.35.3
Signature · 1 line
Vitaly
Vitaly Kuznetsov
maintainerRe: [PATCH v2 22/28] KVM: VMX: Clear controls obsoleted by EPT at runtime, not setup
In reply to Jim MattsonQuoted 10 lines · Jim Mattson
Quoted 9 lines · Vitaly Kuznetsov
From: Sean Christopherson <[email protected]>
Clear the CR3 and INVLPG interception controls at runtime based on whether or not EPT is being _used_, as opposed to clearing the bits at setup if EPT is _supported_ in hardware, and then restoring them when EPT is not used. Not mucking with the base config will allow using the base config as the starting point for emulating the VMX capability MSRs.
Quoted 4 lines
Quoted 2 lines
Signed-off-by Sean Christopherson <[email protected]>Signed-off-by Vitaly Kuznetsov <[email protected]>Nit: These controls aren't "obsoleted" by EPT; they're just no longer required.
Sean,
I'm going to update the subject line to "KVM: VMX: Clear controls unneded with EPT at runtime, not setup" retaining your authorship in v3 (if there are no objections, of course).
Quoted 3 lines
Reviewed-by Jim Mattson <[email protected]>
Thanks!
Signature · 1 line
Vitaly
Sean Christopherson
maintainerRe: [PATCH v2 06/28] KVM: nVMX: Introduce KVM_CAP_HYPERV_ENLIGHTENED_VMCS2
In reply to Vitaly KuznetsovQuoted 14 lines · Vitaly Kuznetsov
Quoted 12 lines · Sean Christopherson
Quoted 10 lines · Vitaly Kuznetsov
Turns out Enlightened VMCS can gain new fields without version change and
KVM_CAP_HYPERV_ENLIGHTENED_VMCSwhich KVM currently has cant's handle this reliably. In particular, just updating the current definition of eVMCSv1 with the new fields and adjusting the VMX MSR filtering will inevitably break live migration to older KVMs. Note: enabling eVMCS and setting VMX feature MSR can happen in any order.Introduce a notion of KVM internal "Enlightened VMCS revision" and add a new capability allowing to add fields to Enlightened VMCS while keeping its version.
Quoted 8 lines
Quoted 4 lines
Bumping a "minor" version number in KVM is going to be a nightmare. KVM is going to be stuck "supporting" old revisions in perpetuity, and userspace will be forced to keep track of which features are available with which arbitrary revision (is that information even communicated to userspace?).
My brain is certainly tainted with how we enable this in QEMU but why would userspace be interested in which features are actually filtered out?
For all the same reasons userspace wants to know what hardware features are supported by hardware and KVM.
Quoted 8 lines
Currently (again, by QEMU), eVMCS is treated as a purely software feature. When enabled, certain controls are filtered out "under the hood" as VMX MSRs reported to VMM remain unfiltered (see '!msr_info->host_initiated' in
vmx_get_msr()). Same stays true with any new revision: VMM's job is just to check that a) all hardware features are supported on both source and destination and b) the requested 'eVMCS revision' is supported by both. No need to know what's filtered out and what isn't.
But users will inevitably want to know exactly what features a platform supports for a given configuration. E.g. if KVM only supported pre-configured CPU models, KVM would need to document what features are supported by each model, and userspace would have very little flexibility in terms of what features are exposed to the guest. That's an exaggerated example as there are far more CPUID features than eVMCS features, but it's the same underlying concept.
Quoted 10 lines
Quoted 6 lines
I think a more maintainable approach would be to expose the "filtered" VMX MSRs to userspace, e.g. add
KVM_GET_EVMCS_VMX_MSRS. Then KVM just needs to document what the "filters" are for KVM versions that don't supportKVM_GET_EVMCS_VMX_MSRS. KVM itself doesn't need to maintain version information because it's userspace's responsibility to ensure that userspace doesn't try to migrate to a KVM that doesn't support the desired feature set.That would be a reasonable (but complex for VMM) approach too but I don't think we need this (and this patch introducing 'eVMCS revisions' to this matter):
But userspace already has to deal with that complexity in raw VMX MSRs. The filtered values will always be a subset of the unfiltered values, so if eVMCS will be exposed to the guest, userspace can simply treat the filtered set as the baseline supported set, i.e. the userspace logic could simply be:
if (expose_evmcs) get_evmcs_vmx_msrs(&msrs); else get_vmx_msrs(&msrs);
Userspace will need to take on more complexity if userspace wants to expose features that are supported in hardware but not with eVMCS active, but I don't see the point in doing so because AFAICT KVM will just override and filter the VMX MSRs anyways when eVMCS is enabled, i.e. userspace _can't_ expose the unfiltered VMX MSRs to the guest when eVMCS is enabled.
Quoted 3 lines
luckily, Microsoft added a new PV CPUID feature bit inidicating the support for the new features in eVMCSv1 so KVM can just observe whether the bit was set by VMM or not and filter accordingly.
If there's a CPUID feature bit, why does KVM need to invent its own revision scheme?
Quoted 8 lines
Quoted 2 lines
That also avoids messes like unnecessarily blocking migration from "incompatible" revisions when running on hardware that doesn't even support the control.
Well yea, in case the difference between 'eVMCS revisions' is void because the hardware doesn't support these, it would still be possible to migrate to an older KVM which doesn't support the new revision but I'd stay strict: if a newer revision was requested it must be supported, no matter the hardware.
Sean Christopherson
maintainerRe: [PATCH v2 06/28] KVM: nVMX: Introduce KVM_CAP_HYPERV_ENLIGHTENED_VMCS2
Quoted 6 lines · Sean Christopherson
Quoted 3 lines · Vitaly Kuznetsov
luckily, Microsoft added a new PV CPUID feature bit inidicating the support for the new features in eVMCSv1 so KVM can just observe whether the bit was set by VMM or not and filter accordingly.
If there's a CPUID feature bit, why does KVM need to invent its own revision scheme?
Doh, just saw your other mail.
Sean Christopherson
maintainerRe: [PATCH v2 22/28] KVM: VMX: Clear controls obsoleted by EPT at runtime, not setup
In reply to Vitaly KuznetsovQuoted 12 lines · Vitaly Kuznetsov
Quoted 10 lines · Jim Mattson
Quoted 9 lines · Vitaly Kuznetsov
From: Sean Christopherson <[email protected]>
Clear the CR3 and INVLPG interception controls at runtime based on whether or not EPT is being _used_, as opposed to clearing the bits at setup if EPT is _supported_ in hardware, and then restoring them when EPT is not used. Not mucking with the base config will allow using the base config as the starting point for emulating the VMX capability MSRs.
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
Signed-off-by Sean Christopherson <[email protected]>Signed-off-by Vitaly Kuznetsov <[email protected]>Nit: These controls aren't "obsoleted" by EPT; they're just no longer required.
Isn't that the definition of "obsolete"? They're "no longer in use" when KVM enables EPT.
Quoted 2 lines
I'm going to update the subject line to "KVM: VMX: Clear controls unneded with EPT at runtime, not setup" retaining your authorship in v3
That's fine, though s/unneded/unneeded.
Re: [PATCH v2 22/28] KVM: VMX: Clear controls obsoleted by EPT at runtime, not setup
Quoted 14 lines · Sean Christopherson
Quoted 12 lines · Vitaly Kuznetsov
Quoted 10 lines · Jim Mattson
Quoted 9 lines · Vitaly Kuznetsov
From: Sean Christopherson <[email protected]>
Clear the CR3 and INVLPG interception controls at runtime based on whether or not EPT is being _used_, as opposed to clearing the bits at setup if EPT is _supported_ in hardware, and then restoring them when EPT is not used. Not mucking with the base config will allow using the base config as the starting point for emulating the VMX capability MSRs.
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
Signed-off-by Sean Christopherson <[email protected]>Signed-off-by Vitaly Kuznetsov <[email protected]>Nit: These controls aren't "obsoleted" by EPT; they're just no longer required.
Isn't that the definition of "obsolete"? They're "no longer in use" when KVM enables EPT.
There are still reasons to use them aside from shadow page table maintenance. For example, malware analysis may be interested in intercepting CR3 changes to track process context (and to enable/disable costly monitoring). EPT doesn't render these events "obsolete," because you can't intercept these events using EPT.
Quoted 4 lines
Quoted 2 lines
I'm going to update the subject line to "KVM: VMX: Clear controls unneded with EPT at runtime, not setup" retaining your authorship in v3
That's fine, though s/unneded/unneeded.
Sean Christopherson
maintainerRe: [PATCH v2 22/28] KVM: VMX: Clear controls obsoleted by EPT at runtime, not setup
Quoted 15 lines · Jim Mattson
Quoted 14 lines · Sean Christopherson
Quoted 12 lines · Vitaly Kuznetsov
Quoted 10 lines · Jim Mattson
Quoted 9 lines · Vitaly Kuznetsov
From: Sean Christopherson <[email protected]>
Clear the CR3 and INVLPG interception controls at runtime based on whether or not EPT is being _used_, as opposed to clearing the bits at setup if EPT is _supported_ in hardware, and then restoring them when EPT is not used. Not mucking with the base config will allow using the base config as the starting point for emulating the VMX capability MSRs.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
Signed-off-by Sean Christopherson <[email protected]>Signed-off-by Vitaly Kuznetsov <[email protected]>Nit: These controls aren't "obsoleted" by EPT; they're just no longer required.
Actually, they're still required if unrestricted guest isn't supported.
Quoted 8 lines
Quoted 2 lines
Isn't that the definition of "obsolete"? They're "no longer in use" when KVM enables EPT.
There are still reasons to use them aside from shadow page table maintenance. For example, malware analysis may be interested in intercepting CR3 changes to track process context (and to enable/disable costly monitoring). EPT doesn't render these events "obsolete," because you can't intercept these events using EPT.
Fair enough, I was using "EPT" in the "KVM is using EPT" sense. But even that's wrong as KVM intercepts CR3 accesses when EPT is enabled, but unrestricted guest is disabled and the guest disables paging.
Vitaly, since the CR3 fields are still technically "needed", maybe just be explicit?
KVM: VMX: Adjust CR3/INVPLG interception for EPT=y at runtime, not setup
Re: [PATCH v2 22/28] KVM: VMX: Clear controls obsoleted by EPT at runtime, not setup
Quoted 33 lines · Sean Christopherson
Quoted 15 lines · Jim Mattson
Quoted 14 lines · Sean Christopherson
Quoted 12 lines · Vitaly Kuznetsov
Quoted 10 lines · Jim Mattson
Quoted 9 lines · Vitaly Kuznetsov
From: Sean Christopherson <[email protected]>
Clear the CR3 and INVLPG interception controls at runtime based on whether or not EPT is being _used_, as opposed to clearing the bits at setup if EPT is _supported_ in hardware, and then restoring them when EPT is not used. Not mucking with the base config will allow using the base config as the starting point for emulating the VMX capability MSRs.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
Signed-off-by Sean Christopherson <[email protected]>Signed-off-by Vitaly Kuznetsov <[email protected]>Nit: These controls aren't "obsoleted" by EPT; they're just no longer required.
Actually, they're still required if unrestricted guest isn't supported.
Quoted 8 lines
Quoted 2 lines
Isn't that the definition of "obsolete"? They're "no longer in use" when KVM enables EPT.
There are still reasons to use them aside from shadow page table maintenance. For example, malware analysis may be interested in intercepting CR3 changes to track process context (and to enable/disable costly monitoring). EPT doesn't render these events "obsolete," because you can't intercept these events using EPT.
Quoted 3 lines
Fair enough, I was using "EPT" in the "KVM is using EPT" sense. But even that's wrong as KVM intercepts CR3 accesses when EPT is enabled, but unrestricted guest is disabled and the guest disables paging.
MOV-to-CR3 is also a required intercept for allow_smaller_maxphyaddr, when the guest is in PAE mode. So, that one, at least, isn't anywhere near obsolete. :-)
Quoted 4 lines
Vitaly, since the CR3 fields are still technically "needed", maybe just be explicit?
KVM: VMX: Adjust CR3/INVPLG interception for EPT=y at runtime, not setup
Vitaly Kuznetsov
maintainerRe: [PATCH v2 22/28] KVM: VMX: Clear controls obsoleted by EPT at runtime, not setup
In reply to Sean ChristophersonQuoted 32 lines · Sean Christopherson
Quoted 15 lines · Jim Mattson
Quoted 14 lines · Sean Christopherson
Quoted 12 lines · Vitaly Kuznetsov
Quoted 10 lines · Jim Mattson
Quoted 9 lines · Vitaly Kuznetsov
From: Sean Christopherson <[email protected]>
Clear the CR3 and INVLPG interception controls at runtime based on whether or not EPT is being _used_, as opposed to clearing the bits at setup if EPT is _supported_ in hardware, and then restoring them when EPT is not used. Not mucking with the base config will allow using the base config as the starting point for emulating the VMX capability MSRs.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
Signed-off-by Sean Christopherson <[email protected]>Signed-off-by Vitaly Kuznetsov <[email protected]>Nit: These controls aren't "obsoleted" by EPT; they're just no longer required.
Actually, they're still required if unrestricted guest isn't supported.
Quoted 8 lines
Quoted 2 lines
Isn't that the definition of "obsolete"? They're "no longer in use" when KVM enables EPT.
There are still reasons to use them aside from shadow page table maintenance. For example, malware analysis may be interested in intercepting CR3 changes to track process context (and to enable/disable costly monitoring). EPT doesn't render these events "obsolete," because you can't intercept these events using EPT.
Quoted 9 lines
Fair enough, I was using "EPT" in the "KVM is using EPT" sense. But even that's wrong as KVM intercepts CR3 accesses when EPT is enabled, but unrestricted guest is disabled and the guest disables paging.
Vitaly, since the CR3 fields are still technically "needed", maybe just be explicit?
KVM: VMX: Adjust CR3/INVPLG interception for EPT=y at runtime, not setup
Sounds good, adjusted!
Signature · 1 line
Vitaly