Skip to contentSkip to conversation

VMX: Disable SMAP feature when guest is in non-paging mode

PATCH In review Feng Wu 3 participants 6 messages Apr 15, 2014 – Apr 16, 2014

lore
Share & tools
lore

Feng Wu

author
#0 lore raw

PATCH 5/6 VMX: Disable SMAP feature when guest is in non-paging mode

SMAP is disabled if CPU is in non-paging mode in hardware. However Xen always uses paging mode to emulate guest non-paging mode with HAP. To emulate this behavior, SMAP needs to be manually disabled when guest switches to non-paging mode.

This logic is similiar with SMEP.

---
 xen/arch/x86/hvm/vmx/vmx.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
xen/arch/x86/hvm/vmx/vmx.c +3 -3
index 94f3db2..79dd272 100644
@@ -1310,12 +1310,12 @@ static void vmx_update_guest_cr(struct vcpu *v, unsigned int cr)
         if ( !hvm_paging_enabled(v) )
         {
             /*
-             * SMEP is disabled if CPU is in non-paging mode in hardware.
+             * SMEP/SMAP is disabled if CPU is in non-paging mode in hardware.
              * However Xen always uses paging mode to emulate guest non-paging
-             * mode. To emulate this behavior, SMEP needs to be manually
+             * mode. To emulate this behavior, SMEP/SMAP needs to be manually
              * disabled when guest VCPU is in non-paging mode.
              */
-            v->arch.hvm_vcpu.hw_cr[4] &= ~X86_CR4_SMEP;
+            v->arch.hvm_vcpu.hw_cr[4] &= ~(X86_CR4_SMEP | X86_CR4_SMAP);
         }
         __vmwrite(GUEST_CR4, v->arch.hvm_vcpu.hw_cr[4]);
         break;
Signature · 1 line
1.8.3.1
Reviewed-by on v1 5/6
#1 lore raw
Quoted 8 lines · Feng Wu

SMAP is disabled if CPU is in non-paging mode in hardware. However Xen always uses paging mode to emulate guest non-paging mode with HAP. To emulate this behavior, SMAP needs to be manually disabled when guest switches to non-paging mode.

This logic is similiar with SMEP.

Quoted 24 lines
---
 xen/arch/x86/hvm/vmx/vmx.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
xen/arch/x86/hvm/vmx/vmx.c +3 -3
index 94f3db2..79dd272 100644
@@ -1310,12 +1310,12 @@ static void vmx_update_guest_cr(struct vcpu *v, unsigned int cr)
         if ( !hvm_paging_enabled(v) )
         {
             /*
-             * SMEP is disabled if CPU is in non-paging mode in hardware.
+             * SMEP/SMAP is disabled if CPU is in non-paging mode in hardware.
              * However Xen always uses paging mode to emulate guest non-paging
-             * mode. To emulate this behavior, SMEP needs to be manually
+             * mode. To emulate this behavior, SMEP/SMAP needs to be manually
              * disabled when guest VCPU is in non-paging mode.
              */
-            v->arch.hvm_vcpu.hw_cr[4] &= ~X86_CR4_SMEP;
+            v->arch.hvm_vcpu.hw_cr[4] &= ~(X86_CR4_SMEP | X86_CR4_SMAP);
         }
         __vmwrite(GUEST_CR4, v->arch.hvm_vcpu.hw_cr[4]);
         break;
#2 lore raw
In reply to Feng Wu
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 15.04.14 at 15:02, <[email protected]> wrote:

SMAP is disabled if CPU is in non-paging mode in hardware. However Xen always uses paging mode to emulate guest non-paging mode with HAP. To emulate this behavior, SMAP needs to be manually disabled when guest switches to non-paging mode.

This logic is similiar with SMEP.

The change is certainly fine, but shouldn't this be done earlier in the series (i.e. the patch moved up)?

Jan

author
#3 lore raw
Quoted 17 lines

-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: Tuesday, April 15, 2014 7:51 PM
To: Wu, Feng
Cc: [email protected]; Dong, Eddie; Nakajima, Jun; [email protected]
Subject: Re: [PATCH v1 5/6] VMX: Disable SMAP feature when guest is in non-paging mode

Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 15.04.14 at 15:02, <[email protected]> wrote:

SMAP is disabled if CPU is in non-paging mode in hardware. However Xen always uses paging mode to emulate guest non-paging mode with HAP. To emulate this behavior, SMAP needs to be manually disabled when guest switches to non-paging mode.

Quoted 4 lines
Quoted 1 line

This logic is similiar with SMEP.

The change is certainly fine, but shouldn't this be done earlier in the series (i.e. the patch moved up)?

Yes, maybe we should put it right before "v1-0004-x86-hvm-Add-SMAP-support-to-HVM-guest.patch", since this changes is for HVM guest. what do you think of this? Thanks!

Quoted 2 lines

Jan

Thanks,
Feng

#4 lore raw
Quoted 18 lines
Quoted 18 lines
Quoted 1 line · On 16.04.14 at 04:07, <[email protected]> wrote:

-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: Tuesday, April 15, 2014 7:51 PM
To: Wu, Feng
Cc: [email protected]; Dong, Eddie; Nakajima, Jun; [email protected]
Subject: Re: [PATCH v1 5/6] VMX: Disable SMAP feature when guest is in non-paging mode

Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 15.04.14 at 15:02, <[email protected]> wrote:

SMAP is disabled if CPU is in non-paging mode in hardware. However Xen always uses paging mode to emulate guest non-paging mode with HAP. To emulate this behavior, SMAP needs to be manually disabled when guest switches to non-paging mode.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

This logic is similiar with SMEP.

The change is certainly fine, but shouldn't this be done earlier in the series (i.e. the patch moved up)?

Yes, maybe we should put it right before "v1-0004-x86-hvm-Add-SMAP-support-to-HVM-guest.patch",
since this changes is for HVM guest. what do you think of this? Thanks!

The change here needs to be done prior (or along with) the feature getting enabled for the host, whenever that is in the series.

Jan

author
#5 lore raw
Quoted 34 lines

-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: Wednesday, April 16, 2014 4:52 PM
To: Wu, Feng
Cc: [email protected]; Dong, Eddie; Nakajima, Jun; [email protected]
Subject: RE: [PATCH v1 5/6] VMX: Disable SMAP feature when guest is in non-paging mode

Quoted 23 lines
Quoted 22 lines
Quoted 1 line · On 16.04.14 at 04:07, <[email protected]> wrote:

-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: Tuesday, April 15, 2014 7:51 PM
To: Wu, Feng
Cc: [email protected]; Dong, Eddie; Nakajima, Jun; [email protected]
Subject: Re: [PATCH v1 5/6] VMX: Disable SMAP feature when guest is in non-paging mode

Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 15.04.14 at 15:02, <[email protected]> wrote:

SMAP is disabled if CPU is in non-paging mode in hardware. However Xen always uses paging mode to emulate guest non-paging mode with HAP. To emulate this behavior, SMAP needs to be manually disabled when guest switches to non-paging mode.

This logic is similiar with SMEP.

The change is certainly fine, but shouldn't this be done earlier in the series (i.e. the patch moved up)?

Quoted 6 lines
Quoted 3 lines

Yes, maybe we should put it right before "v1-0004-x86-hvm-Add-SMAP-support-to-HVM-guest.patch",
since this changes is for HVM guest. what do you think of this? Thanks!

The change here needs to be done prior (or along with) the feature getting enabled for the host, whenever that is in the series.

Okay, will change the order in the next version.

Quoted 2 lines

Jan

Thanks,
Feng