aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86
diff options
context:
space:
mode:
authorDongxiao Xu <dongxiao.xu@intel.com>2013-02-03 22:50:43 -0500
committerMarcelo Tosatti <mtosatti@redhat.com>2013-02-05 20:28:07 -0500
commitc08800a56cb8622bb61577abb4a120c6fdc4b9be (patch)
treec9195953c1e901dfa44238facd4fc1402d1b9fc8 /arch/x86
parent4293b5e5a68074431cafa74d549c1327ba1d0deb (diff)
KVM: VMX: disable SMEP feature when guest is in non-paging mode
SMEP 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 needs to be manually disabled when guest switches to non-paging mode. We met an issue that, SMP Linux guest with recent kernel (enable SMEP support, for example, 3.5.3) would crash with triple fault if setting unrestricted_guest=0. This is because KVM uses an identity mapping page table to emulate the non-paging mode, where the page table is set with USER flag. If SMEP is still enabled in this case, guest will meet unhandlable page fault and then crash. Reviewed-by: Gleb Natapov <gleb@redhat.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Dongxiao Xu <dongxiao.xu@intel.com> Signed-off-by: Xiantao Zhang <xiantao.zhang@intel.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Diffstat (limited to 'arch/x86')
-rw-r--r--arch/x86/kvm/vmx.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 0cf74a641dec..fe9a9cfadbd6 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -3227,6 +3227,14 @@ static int vmx_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)
3227 if (!is_paging(vcpu)) { 3227 if (!is_paging(vcpu)) {
3228 hw_cr4 &= ~X86_CR4_PAE; 3228 hw_cr4 &= ~X86_CR4_PAE;
3229 hw_cr4 |= X86_CR4_PSE; 3229 hw_cr4 |= X86_CR4_PSE;
3230 /*
3231 * SMEP is disabled if CPU is in non-paging mode in
3232 * hardware. However KVM always uses paging mode to
3233 * emulate guest non-paging mode with TDP.
3234 * To emulate this behavior, SMEP needs to be manually
3235 * disabled when guest switches to non-paging mode.
3236 */
3237 hw_cr4 &= ~X86_CR4_SMEP;
3230 } else if (!(cr4 & X86_CR4_PAE)) { 3238 } else if (!(cr4 & X86_CR4_PAE)) {
3231 hw_cr4 &= ~X86_CR4_PAE; 3239 hw_cr4 &= ~X86_CR4_PAE;
3232 } 3240 }