From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paolo Bonzini Subject: Re: [PATCH] KVM: VMX: disable SMEP feature when guest is in non-paging mode Date: Sat, 02 Feb 2013 00:08:41 +0100 Message-ID: <510C4AF9.6010001@redhat.com> References: <1359707407-12981-1-git-send-email-dongxiao.xu@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org To: Dongxiao Xu Return-path: Received: from mail-wi0-f180.google.com ([209.85.212.180]:35588 "EHLO mail-wi0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757313Ab3BAXIt (ORCPT ); Fri, 1 Feb 2013 18:08:49 -0500 Received: by mail-wi0-f180.google.com with SMTP id hi8so664502wib.13 for ; Fri, 01 Feb 2013 15:08:48 -0800 (PST) In-Reply-To: <1359707407-12981-1-git-send-email-dongxiao.xu@intel.com> Sender: kvm-owner@vger.kernel.org List-ID: Il 01/02/2013 09:30, Dongxiao Xu ha scritto: > 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 HAP. 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. > > Signed-off-by: Dongxiao Xu > Signed-off-by: Xiantao Zhang > --- > arch/x86/kvm/vmx.c | 8 ++++++++ > 1 files changed, 8 insertions(+), 0 deletions(-) > > diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c > index 9120ae1..e82f20d 100644 > --- a/arch/x86/kvm/vmx.c > +++ b/arch/x86/kvm/vmx.c > @@ -3155,6 +3155,14 @@ 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 is disabled if CPU is in non-paging mode in > + * hardware. However KVM always uses paging mode to > + * emulate guest non-paging mode with HAP. > + * To emulate this behavior, SMEP needs to be manually > + * disabled when guest switches to non-paging mode. > + */ > + hw_cr4 &= ~X86_CR4_SMEP; > } else if (!(cr4 & X86_CR4_PAE)) { > hw_cr4 &= ~X86_CR4_PAE; > } > Reviewed-by: Paolo Bonzini