Introduce KVM_X86_QUIRK_VMCS12_FREEZE_IN_SMM_CC
Subsystems (4)
PATCH v2 1/1 Introduce KVM_X86_QUIRK_VMCS12_FREEZE_IN_SMM_CC
Add KVM_X86_QUIRK_VMCS12_FREEZE_IN_SMM_CC to allow L1 to set FREEZE_IN_SMM in vmcs12's GUEST_IA32_DEBUGCTL field, as permitted prior to commit 6b1dd26544d0 ("KVM: VMX: Preserve host's DEBUGCTLMSR_FREEZE_IN_SMM while running the guest"). The quirk is enabled by default for backwards compatibility; userspace can disable it via KVM_CAP_DISABLE_QUIRKS2 for consistency with the constraints on WRMSR(IA32_DEBUGCTL).
Note that the quirk only bypasses the consistency check. The vmcs02 bit is still owned by the host, and PMCs are not frozen during virtualized SMM. In particular, if a host administrator decides that PMCs should not be frozen during physical SMM, then L1 has no say in the matter.
--- Documentation/virt/kvm/api.rst | 10 ++++++++++ arch/x86/include/asm/kvm_host.h | 3 ++- arch/x86/include/uapi/asm/kvm.h | 1 + arch/x86/kvm/vmx/nested.c | 23 +++++++++++++++++++---- 4 files changed, 32 insertions(+), 5 deletions(-)
Documentation/virt/kvm/api.rst +10 -0
@@ -8482,6 +8482,16 @@ KVM_X86_QUIRK_IGNORE_GUEST_PAT By default, on Intel platforms, KVM ignores guest software, for example if it does not expose a bochs graphics device (which is known to have had a buggy driver). + +KVM_X86_QUIRK_VMCS12_FREEZE_IN_SMM_CC + By default, KVM relaxes the consistency + check for GUEST_IA32_DEBUGCTL in vmcb12 + to allow FREEZE_IN_SMM to be set. When + this quirk is disabled, KVM requires + this bit to be cleared. Note that the + vmcs02 bit is still completely + controlled by the host, regardless of + the quirk setting. =================================== ============================================ 7.32 KVM_CAP_MAX_VCPU_ID
arch/x86/include/asm/kvm_host.h +2 -1
@@ -2485,7 +2485,8 @@ int memslot_rmap_alloc(struct kvm_memory_slot *slot, unsigned long npages); KVM_X86_QUIRK_MWAIT_NEVER_UD_FAULTS | \ KVM_X86_QUIRK_SLOT_ZAP_ALL | \ KVM_X86_QUIRK_STUFF_FEATURE_MSRS | \ - KVM_X86_QUIRK_IGNORE_GUEST_PAT) + KVM_X86_QUIRK_IGNORE_GUEST_PAT | \ + KVM_X86_QUIRK_VMCS12_FREEZE_IN_SMM_CC)#define KVM_X86_CONDITIONAL_QUIRKS \ (KVM_X86_QUIRK_CD_NW_CLEARED | \
arch/x86/include/uapi/asm/kvm.h +1 -0
@@ -476,6 +476,7 @@ struct kvm_sync_regs {#define KVM_X86_QUIRK_SLOT_ZAP_ALL (1 << 7)#define KVM_X86_QUIRK_STUFF_FEATURE_MSRS (1 << 8)#define KVM_X86_QUIRK_IGNORE_GUEST_PAT (1 << 9) +#define KVM_X86_QUIRK_VMCS12_FREEZE_IN_SMM_CC (1 << 10)#define KVM_STATE_NESTED_FORMAT_VMX 0#define KVM_STATE_NESTED_FORMAT_SVM 1
arch/x86/kvm/vmx/nested.c +19 -4
@@ -3300,10 +3300,25 @@ static int nested_vmx_check_guest_state(struct kvm_vcpu *vcpu,if (CC (vmcs12->guest_cr4 &X86_CR4_CET && !(vmcs12->guest_cr0 &X86_CR0_WP )))return -EINVAL ; -if ((vmcs12->vm_entry_controls &VM_ENTRY_LOAD_DEBUG_CONTROLS ) && - (CC (!kvm_dr7_valid (vmcs12->guest_dr7)) || -CC (!vmx_is_valid_debugctl (vcpu, vmcs12->guest_ia32_debugctl, false)))) -return -EINVAL ; +if (vmcs12->vm_entry_controls &VM_ENTRY_LOAD_DEBUG_CONTROLS ) { +u64 debugctl = vmcs12->guest_ia32_debugctl; + +/* +* FREEZE_IN_SMM is not virtualized, but allow L1 to set it +* in VMCB12's DEBUGCTL under a quirk for backwards +* compatibility. Note that the quirk only relaxes the +* consistency check. The vmcb02 bit is still under the +* control of the host. In particular, if a host +* administrator decides to clear the bit, then L1 has no +* say in the matter. +*/ +if (kvm_check_has_quirk (vcpu->kvm,KVM_X86_QUIRK_VMCS12_FREEZE_IN_SMM_CC )) + debugctl &= ~DEBUGCTLMSR_FREEZE_IN_SMM ; + +if (CC (!kvm_dr7_valid (vmcs12->guest_dr7)) || +CC (!vmx_is_valid_debugctl (vcpu, debugctl, false))) +return -EINVAL ; + }if ((vmcs12->vm_entry_controls &VM_ENTRY_LOAD_IA32_PAT ) &&CC (!kvm_pat_valid (vmcs12->guest_ia32_pat)))
base-commit: e944fe2c09f405a2e2d147145c9b470084bc4c9a
Signature · 1 line
2.53.0.rc2.204.g2597b5adb4-goog
Sean Christopherson
maintainerQuoted 7 lines · Jim Mattson
Add
KVM_X86_QUIRK_VMCS12_FREEZE_IN_SMM_CCto allow L1 to setFREEZE_IN_SMMin vmcs12'sGUEST_IA32_DEBUGCTLfield, as permitted prior to commit6b1dd26544d0("KVM: VMX: Preserve host'sDEBUGCTLMSR_FREEZE_IN_SMMwhile running the guest"). The quirk is enabled by default for backwards compatibility; userspace can disable it viaKVM_CAP_DISABLE_QUIRKS2for consistency with the constraints onWRMSR(IA32_DEBUGCTL).
Quoted 7 lines
Note that the quirk only bypasses the consistency check. The vmcs02 bit is still owned by the host, and PMCs are not frozen during virtualized SMM. In particular, if a host administrator decides that PMCs should not be frozen during physical SMM, then L1 has no say in the matter.
Fixes 095686e6fcb4 ("KVM: nVMX: Check vmcs12->guest_ia32_debugctl on nested VM-Enter")Signed-off-by Jim Mattson <[email protected]>
I'll tag for stable, but otherwise LGTM. It's too late for 6.19, but I'll get it queued up for 6.20 after giving others a chance to react. It'll miss the initial batch of pull requests, but I'll try to send a fixes for the second half of the merge window (I just realized I need to create+send the pull requests...)
Quoted 26 lines · Jim Mattson
Add
KVM_X86_QUIRK_VMCS12_FREEZE_IN_SMM_CCto allow L1 to setFREEZE_IN_SMMin vmcs12'sGUEST_IA32_DEBUGCTLfield, as permitted prior to commit6b1dd26544d0("KVM: VMX: Preserve host'sDEBUGCTLMSR_FREEZE_IN_SMMwhile running the guest"). The quirk is enabled by default for backwards compatibility; userspace can disable it viaKVM_CAP_DISABLE_QUIRKS2for consistency with the constraints onWRMSR(IA32_DEBUGCTL).Note that the quirk only bypasses the consistency check. The vmcs02 bit is still owned by the host, and PMCs are not frozen during virtualized SMM. In particular, if a host administrator decides that PMCs should not be frozen during physical SMM, then L1 has no say in the matter.
Fixes 095686e6fcb4 ("KVM: nVMX: Check vmcs12->guest_ia32_debugctl on nested VM-Enter")Signed-off-by Jim Mattson <[email protected]>--- Documentation/virt/kvm/api.rst | 10 ++++++++++ arch/x86/include/asm/kvm_host.h | 3 ++- arch/x86/include/uapi/asm/kvm.h | 1 + arch/x86/kvm/vmx/nested.c | 23 +++++++++++++++++++---- 4 files changed, 32 insertions(+), 5 deletions(-)Documentation/virt/kvm/api.rst +0
-0
Documentation/virt/kvm/api.rst KVM_X86_QUIRK_IGNORE_GUEST_PAT By default, on Intel platforms, KVM ignores · line 8488
Quoted 7 lines
Documentation/virt/kvm/api.rst +4
-0@@ -8482,6 +8482,16 @@ KVM_X86_QUIRK_IGNORE_GUEST_PAT By default, on Intel platforms, KVM ignores guest software, for example if it does not expose a bochs graphics device (which is known to have had a buggy driver). + +KVM_X86_QUIRK_VMCS12_FREEZE_IN_SMM_CC + By default, KVM relaxes the consistency + check for GUEST_IA32_DEBUGCTL in vmcb12
vmcs12*
Quoted 43 lines
Documentation/virt/kvm/api.rst +6
-0+ to allow FREEZE_IN_SMM to be set. When + this quirk is disabled, KVM requires + this bit to be cleared. Note that the + vmcs02 bit is still completely + controlled by the host, regardless of + the quirk setting. =================================== ============================================ 7.32 KVM_CAP_MAX_VCPU_IDarch/x86/include/asm/kvm_host.h +2
-1@@ -2485,7 +2485,8 @@ int memslot_rmap_alloc(struct kvm_memory_slot *slot, unsigned long npages); KVM_X86_QUIRK_MWAIT_NEVER_UD_FAULTS | \ KVM_X86_QUIRK_SLOT_ZAP_ALL | \ KVM_X86_QUIRK_STUFF_FEATURE_MSRS | \ - KVM_X86_QUIRK_IGNORE_GUEST_PAT) + KVM_X86_QUIRK_IGNORE_GUEST_PAT | \ + KVM_X86_QUIRK_VMCS12_FREEZE_IN_SMM_CC)#define KVM_X86_CONDITIONAL_QUIRKS \ (KVM_X86_QUIRK_CD_NW_CLEARED | \arch/x86/include/uapi/asm/kvm.h +1
-0@@ -476,6 +476,7 @@ struct kvm_sync_regs {#define KVM_X86_QUIRK_SLOT_ZAP_ALL (1 << 7)#define KVM_X86_QUIRK_STUFF_FEATURE_MSRS (1 << 8)#define KVM_X86_QUIRK_IGNORE_GUEST_PAT (1 << 9) +#define KVM_X86_QUIRK_VMCS12_FREEZE_IN_SMM_CC (1 << 10)#define KVM_STATE_NESTED_FORMAT_VMX 0#define KVM_STATE_NESTED_FORMAT_SVM 1arch/x86/kvm/vmx/nested.c +0
-0@@ -3300,10 +3300,25 @@ static int nested_vmx_check_guest_state(struct kvm_vcpu *vcpu,if (CC (vmcs12->guest_cr4 &X86_CR4_CET && !(vmcs12->guest_cr0 &X86_CR0_WP )))return -EINVAL ;
arch/x86/kvm/vmx/nested.c static int nested_vmx_check_guest_state(struct kvm_vcpu *vcpu, · line 3308
Quoted 10 lines
arch/x86/kvm/vmx/nested.c +6
-4-if ((vmcs12->vm_entry_controls &VM_ENTRY_LOAD_DEBUG_CONTROLS ) && - (CC (!kvm_dr7_valid (vmcs12->guest_dr7)) || -CC (!vmx_is_valid_debugctl (vcpu, vmcs12->guest_ia32_debugctl, false)))) -return -EINVAL ; +if (vmcs12->vm_entry_controls &VM_ENTRY_LOAD_DEBUG_CONTROLS ) { +u64 debugctl = vmcs12->guest_ia32_debugctl; + +/* +* FREEZE_IN_SMM is not virtualized, but allow L1 to set it +* in VMCB12's DEBUGCTL under a quirk for backwards
VMCS12's
arch/x86/kvm/vmx/nested.c static int nested_vmx_check_guest_state(struct kvm_vcpu *vcpu, · line 3310
Quoted 2 lines
arch/x86/kvm/vmx/nested.c +2
-0+* compatibility. Note that the quirk only relaxes the +* consistency check. The vmcb02 bit is still under the
vmcs02
Quoted 19 lines
arch/x86/kvm/vmx/nested.c +11
-0+* control of the host. In particular, if a host +* administrator decides to clear the bit, then L1 has no +* say in the matter. +*/ +if (kvm_check_has_quirk (vcpu->kvm,KVM_X86_QUIRK_VMCS12_FREEZE_IN_SMM_CC )) + debugctl &= ~DEBUGCTLMSR_FREEZE_IN_SMM ; + +if (CC (!kvm_dr7_valid (vmcs12->guest_dr7)) || +CC (!vmx_is_valid_debugctl (vcpu, debugctl, false))) +return -EINVAL ; + }if ((vmcs12->vm_entry_controls &VM_ENTRY_LOAD_IA32_PAT ) &&CC (!kvm_pat_valid (vmcs12->guest_ia32_pat)))base-commit:
e944fe2c09f405a2e2d147145c9b470084bc4c9aSignature · 1 line
2.53.0.rc2.204.g2597b5adb4-goog
Quoted 94 lines · Yosry Ahmed
Quoted 26 lines · Jim Mattson
Add
KVM_X86_QUIRK_VMCS12_FREEZE_IN_SMM_CCto allow L1 to setFREEZE_IN_SMMin vmcs12'sGUEST_IA32_DEBUGCTLfield, as permitted prior to commit6b1dd26544d0("KVM: VMX: Preserve host'sDEBUGCTLMSR_FREEZE_IN_SMMwhile running the guest"). The quirk is enabled by default for backwards compatibility; userspace can disable it viaKVM_CAP_DISABLE_QUIRKS2for consistency with the constraints onWRMSR(IA32_DEBUGCTL).Note that the quirk only bypasses the consistency check. The vmcs02 bit is still owned by the host, and PMCs are not frozen during virtualized SMM. In particular, if a host administrator decides that PMCs should not be frozen during physical SMM, then L1 has no say in the matter.
Fixes 095686e6fcb4 ("KVM: nVMX: Check vmcs12->guest_ia32_debugctl on nested VM-Enter")Signed-off-by Jim Mattson <[email protected]>--- Documentation/virt/kvm/api.rst | 10 ++++++++++ arch/x86/include/asm/kvm_host.h | 3 ++- arch/x86/include/uapi/asm/kvm.h | 1 + arch/x86/kvm/vmx/nested.c | 23 +++++++++++++++++++---- 4 files changed, 32 insertions(+), 5 deletions(-)Documentation/virt/kvm/api.rst +0
-0Documentation/virt/kvm/api.rst KVM_X86_QUIRK_IGNORE_GUEST_PAT By default, on Intel platforms, KVM ignores · line 8488
Quoted 7 lines
Documentation/virt/kvm/api.rst +4
-0@@ -8482,6 +8482,16 @@ KVM_X86_QUIRK_IGNORE_GUEST_PAT By default, on Intel platforms, KVM ignores guest software, for example if it does not expose a bochs graphics device (which is known to have had a buggy driver). + +KVM_X86_QUIRK_VMCS12_FREEZE_IN_SMM_CC + By default, KVM relaxes the consistency + check for GUEST_IA32_DEBUGCTL in vmcb12vmcs12*
Quoted 43 lines
Documentation/virt/kvm/api.rst +6
-0+ to allow FREEZE_IN_SMM to be set. When + this quirk is disabled, KVM requires + this bit to be cleared. Note that the + vmcs02 bit is still completely + controlled by the host, regardless of + the quirk setting. =================================== ============================================ 7.32 KVM_CAP_MAX_VCPU_IDarch/x86/include/asm/kvm_host.h +2
-1@@ -2485,7 +2485,8 @@ int memslot_rmap_alloc(struct kvm_memory_slot *slot, unsigned long npages); KVM_X86_QUIRK_MWAIT_NEVER_UD_FAULTS | \ KVM_X86_QUIRK_SLOT_ZAP_ALL | \ KVM_X86_QUIRK_STUFF_FEATURE_MSRS | \ - KVM_X86_QUIRK_IGNORE_GUEST_PAT) + KVM_X86_QUIRK_IGNORE_GUEST_PAT | \ + KVM_X86_QUIRK_VMCS12_FREEZE_IN_SMM_CC)#define KVM_X86_CONDITIONAL_QUIRKS \ (KVM_X86_QUIRK_CD_NW_CLEARED | \arch/x86/include/uapi/asm/kvm.h +1
-0@@ -476,6 +476,7 @@ struct kvm_sync_regs {#define KVM_X86_QUIRK_SLOT_ZAP_ALL (1 << 7)#define KVM_X86_QUIRK_STUFF_FEATURE_MSRS (1 << 8)#define KVM_X86_QUIRK_IGNORE_GUEST_PAT (1 << 9) +#define KVM_X86_QUIRK_VMCS12_FREEZE_IN_SMM_CC (1 << 10)#define KVM_STATE_NESTED_FORMAT_VMX 0#define KVM_STATE_NESTED_FORMAT_SVM 1arch/x86/kvm/vmx/nested.c +0
-0@@ -3300,10 +3300,25 @@ static int nested_vmx_check_guest_state(struct kvm_vcpu *vcpu,if (CC (vmcs12->guest_cr4 &X86_CR4_CET && !(vmcs12->guest_cr0 &X86_CR0_WP )))return -EINVAL ;arch/x86/kvm/vmx/nested.c static int nested_vmx_check_guest_state(struct kvm_vcpu *vcpu, · line 3308
Quoted 10 lines
arch/x86/kvm/vmx/nested.c +6
-4-if ((vmcs12->vm_entry_controls &VM_ENTRY_LOAD_DEBUG_CONTROLS ) && - (CC (!kvm_dr7_valid (vmcs12->guest_dr7)) || -CC (!vmx_is_valid_debugctl (vcpu, vmcs12->guest_ia32_debugctl, false)))) -return -EINVAL ; +if (vmcs12->vm_entry_controls &VM_ENTRY_LOAD_DEBUG_CONTROLS ) { +u64 debugctl = vmcs12->guest_ia32_debugctl; + +/* +* FREEZE_IN_SMM is not virtualized, but allow L1 to set it +* in VMCB12's DEBUGCTL under a quirk for backwards VMCS12's
Quoted 5 lines
arch/x86/kvm/vmx/nested.c static int nested_vmx_check_guest_state(struct kvm_vcpu *vcpu, · line 3310
Quoted 2 lines
arch/x86/kvm/vmx/nested.c +2
-0+* compatibility. Note that the quirk only relaxes the +* consistency check. The vmcb02 bit is still under the vmcs02
/facepalm
Quoted 20 lines
Quoted 19 lines
arch/x86/kvm/vmx/nested.c +11
-0+* control of the host. In particular, if a host +* administrator decides to clear the bit, then L1 has no +* say in the matter. +*/ +if (kvm_check_has_quirk (vcpu->kvm,KVM_X86_QUIRK_VMCS12_FREEZE_IN_SMM_CC )) + debugctl &= ~DEBUGCTLMSR_FREEZE_IN_SMM ; + +if (CC (!kvm_dr7_valid (vmcs12->guest_dr7)) || +CC (!vmx_is_valid_debugctl (vcpu, debugctl, false))) +return -EINVAL ; + }if ((vmcs12->vm_entry_controls &VM_ENTRY_LOAD_IA32_PAT ) &&CC (!kvm_pat_valid (vmcs12->guest_ia32_pat)))base-commit:
e944fe2c09f405a2e2d147145c9b470084bc4c9a--
2.53.0.rc2.204.g2597b5adb4-goog
Quoted 8 lines · Jim Mattson
Add
KVM_X86_QUIRK_VMCS12_FREEZE_IN_SMM_CCto allow L1 to setFREEZE_IN_SMMin vmcs12'sGUEST_IA32_DEBUGCTLfield, as permitted prior to commit6b1dd26544d0("KVM: VMX: Preserve host'sDEBUGCTLMSR_FREEZE_IN_SMMwhile running the guest"). The quirk is enabled by default for backwards compatibility; userspace can disable it viaKVM_CAP_DISABLE_QUIRKS2for consistency with the constraints onWRMSR(IA32_DEBUGCTL).[...]
Applied to kvm-x86 fixes, thanks!
[1/1] Introduce KVM_X86_QUIRK_VMCS12_FREEZE_IN_SMM_CC
https://github.com/kvm-x86/linux/commit/0f70db0758be