KVM: VMX: fix SMEP and SMAP without EPT
Subsystems (4)
PATCH 1/1 KVM: VMX: fix SMEP and SMAP without EPT
The comment in code had it mostly right, but we enable paging for emulated real mode regardless of EPT.
Without EPT (which implies emulated real mode), secondary VCPUs won't start unless we disable SM[AE]P when the guest doesn't use paging.
Signed-off-by Radim Krčmář <[email protected]>
--- arch/x86/kvm/vmx.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
arch/x86/kvm/vmx.c +10 -9
@@ -3788,20 +3788,21 @@ static int vmx_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)if (!is_paging (vcpu)) { hw_cr4 &= ~X86_CR4_PAE ; hw_cr4 |=X86_CR4_PSE ; -/* -* SMEP/SMAP is disabled if CPU is in non-paging mode -* in hardware. However KVM always uses paging mode to -* emulate guest non-paging mode with TDP. -* To emulate this behavior, SMEP/SMAP needs to be -* manually disabled when guest switches to non-paging -* mode. -*/ - hw_cr4 &= ~(X86_CR4_SMEP |X86_CR4_SMAP ); }else if (!(cr4 &X86_CR4_PAE )) { hw_cr4 &= ~X86_CR4_PAE ; } } +if (!enable_unrestricted_guest && !is_paging (vcpu)) +/* +* SMEP/SMAP is disabled if CPU is in non-paging mode in +* hardware. However KVM always uses paging mode without +* unrestricted guest. +* To emulate this behavior, SMEP/SMAP needs to be manually +* disabled when guest switches to non-paging mode. +*/ + hw_cr4 &= ~(X86_CR4_SMEP |X86_CR4_SMAP ); +vmcs_writel (CR4_READ_SHADOW , cr4);vmcs_writel (GUEST_CR4 , hw_cr4);return 0 ;
Signature · 1 line
2.5.3
Paolo Bonzini
maintainerQuoted 37 lines · Radim Krčmář
The comment in code had it mostly right, but we enable paging for emulated real mode regardless of EPT.
Without EPT (which implies emulated real mode), secondary VCPUs won't start unless we disable SM[AE]P when the guest doesn't use paging.
Signed-off-by Radim Krčmář <[email protected]>--- arch/x86/kvm/vmx.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)arch/x86/kvm/vmx.c +3
-9@@ -3788,20 +3788,21 @@ static int vmx_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)if (!is_paging (vcpu)) { hw_cr4 &= ~X86_CR4_PAE ; hw_cr4 |=X86_CR4_PSE ; -/* -* SMEP/SMAP is disabled if CPU is in non-paging mode -* in hardware. However KVM always uses paging mode to -* emulate guest non-paging mode with TDP. -* To emulate this behavior, SMEP/SMAP needs to be -* manually disabled when guest switches to non-paging -* mode. -*/ - hw_cr4 &= ~(X86_CR4_SMEP |X86_CR4_SMAP ); }else if (!(cr4 &X86_CR4_PAE )) { hw_cr4 &= ~X86_CR4_PAE ; } } +if (!enable_unrestricted_guest && !is_paging (vcpu)) +/* +* SMEP/SMAP is disabled if CPU is in non-paging mode in
arch/x86/kvm/vmx.c static int vmx_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4) · line 3808
Quoted 10 lines
arch/x86/kvm/vmx.c +7
-0+* hardware. However KVM always uses paging mode without +* unrestricted guest. +* To emulate this behavior, SMEP/SMAP needs to be manually +* disabled when guest switches to non-paging mode. +*/ + hw_cr4 &= ~(X86_CR4_SMEP |X86_CR4_SMAP ); +vmcs_writel (CR4_READ_SHADOW , cr4);vmcs_writel (GUEST_CR4 , hw_cr4);return 0 ;
Applied with Cc: [email protected].
Paolo