* [PATCH] KVM: VMX: disable SMEP feature when guest is in non-paging mode
@ 2013-02-01 8:30 Dongxiao Xu
2013-02-01 23:08 ` Paolo Bonzini
2013-02-03 13:56 ` Gleb Natapov
0 siblings, 2 replies; 4+ messages in thread
From: Dongxiao Xu @ 2013-02-01 8:30 UTC (permalink / raw)
To: kvm
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 <dongxiao.xu@intel.com>
Signed-off-by: Xiantao Zhang <xiantao.zhang@intel.com>
---
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;
}
--
1.7.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] KVM: VMX: disable SMEP feature when guest is in non-paging mode
2013-02-01 8:30 [PATCH] KVM: VMX: disable SMEP feature when guest is in non-paging mode Dongxiao Xu
@ 2013-02-01 23:08 ` Paolo Bonzini
2013-02-03 13:56 ` Gleb Natapov
1 sibling, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2013-02-01 23:08 UTC (permalink / raw)
To: Dongxiao Xu; +Cc: kvm
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 <dongxiao.xu@intel.com>
> Signed-off-by: Xiantao Zhang <xiantao.zhang@intel.com>
> ---
> 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 <pbonzini@redhat.com>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: KVM: VMX: disable SMEP feature when guest is in non-paging mode
2013-02-01 8:30 [PATCH] KVM: VMX: disable SMEP feature when guest is in non-paging mode Dongxiao Xu
2013-02-01 23:08 ` Paolo Bonzini
@ 2013-02-03 13:56 ` Gleb Natapov
2013-02-04 4:02 ` Xu, Dongxiao
1 sibling, 1 reply; 4+ messages in thread
From: Gleb Natapov @ 2013-02-03 13:56 UTC (permalink / raw)
To: Dongxiao; +Cc: kvm
On Fri, Feb 01, 2013 at 08:30:07AM -0000, Xu wrote:
> 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.
Not always, only if unrestricted mode is disabled, since vm86 mode, that
is used otherwise, requires paging.
> 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 <dongxiao.xu@intel.com>
> Signed-off-by: Xiantao Zhang <xiantao.zhang@intel.com>
Reviewed-by: Gleb Natapov <gleb@redhat.com>
But HAP is XEN terminology AFAIK. KVM speak is tdp (two dimensional
paging). If would be nice to change it in the commit message and the
comment before committing.
>
> ---
> 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;
> }
--
Gleb.
^ permalink raw reply [flat|nested] 4+ messages in thread* RE: KVM: VMX: disable SMEP feature when guest is in non-paging mode
2013-02-03 13:56 ` Gleb Natapov
@ 2013-02-04 4:02 ` Xu, Dongxiao
0 siblings, 0 replies; 4+ messages in thread
From: Xu, Dongxiao @ 2013-02-04 4:02 UTC (permalink / raw)
To: Gleb Natapov; +Cc: kvm@vger.kernel.org
> -----Original Message-----
> From: Gleb Natapov [mailto:gleb@redhat.com]
> Sent: Sunday, February 03, 2013 9:57 PM
> To: Xu, Dongxiao
> Cc: kvm@vger.kernel.org
> Subject: Re: KVM: VMX: disable SMEP feature when guest is in non-paging
> mode
>
> On Fri, Feb 01, 2013 at 08:30:07AM -0000, Xu wrote:
> > 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.
> Not always, only if unrestricted mode is disabled, since vm86 mode, that
> is used otherwise, requires paging.
>
> > 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 <dongxiao.xu@intel.com>
> > Signed-off-by: Xiantao Zhang <xiantao.zhang@intel.com>
> Reviewed-by: Gleb Natapov <gleb@redhat.com>
>
> But HAP is XEN terminology AFAIK. KVM speak is tdp (two dimensional
> paging). If would be nice to change it in the commit message and the
> comment before committing.
Thanks for reminding this. I've sent out the v2 patch to address this issue.
Thanks,
Dongxiao
>
> >
> > ---
> > 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;
> > }
>
> --
> Gleb.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-02-04 4:02 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-02-01 8:30 [PATCH] KVM: VMX: disable SMEP feature when guest is in non-paging mode Dongxiao Xu
2013-02-01 23:08 ` Paolo Bonzini
2013-02-03 13:56 ` Gleb Natapov
2013-02-04 4:02 ` Xu, Dongxiao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox