VMX: don't needlessly write CR4 guest/host mask
authorJan Beulich <jbeulich@suse.com>
Mon, 2 Jul 2018 11:12:10 +0000 (13:12 +0200)
committerJan Beulich <jbeulich@suse.com>
Mon, 2 Jul 2018 11:12:10 +0000 (13:12 +0200)
In shadow mode the field never changes from ~0UL, so there's no need for
a VMWRITE (or an update of its cached value).

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Andrew Cooper <andrew.cooper@citrix.com>
Acked-by: Kevin Tian <kevin.tian@intel.com>
xen/arch/x86/hvm/vmx/vmx.c

index 20a8a69fbe412aa928c75b5d7756816bf55178fc..8e63eb78134612baf03eb6641b207b51e18c8f6d 100644 (file)
@@ -1585,14 +1585,12 @@ static void vmx_update_guest_cr(struct vcpu *v, unsigned int cr,
 
         __vmwrite(GUEST_CR4, v->arch.hvm_vcpu.hw_cr[4]);
 
-        if ( !paging_mode_hap(v->domain) )
-            /*
-             * Shadow path has not been optimized because it requires
-             * unconditionally trapping more CR4 bits, at which point the
-             * performance benefit of doing this is quite dubious.
-             */
-            v->arch.hvm_vmx.cr4_host_mask = ~0UL;
-        else
+        /*
+         * Shadow path has not been optimized because it requires
+         * unconditionally trapping more CR4 bits, at which point the
+         * performance benefit of doing this is quite dubious.
+         */
+        if ( paging_mode_hap(v->domain) )
         {
             /*
              * Update CR4 host mask to only trap when the guest tries to set
@@ -1617,8 +1615,9 @@ static void vmx_update_guest_cr(struct vcpu *v, unsigned int cr,
                 /* Add the nested host mask to get the more restrictive one. */
                 v->arch.hvm_vmx.cr4_host_mask |= get_vvmcs(v,
                                                            CR4_GUEST_HOST_MASK);
+
+            __vmwrite(CR4_GUEST_HOST_MASK, v->arch.hvm_vmx.cr4_host_mask);
         }
-        __vmwrite(CR4_GUEST_HOST_MASK, v->arch.hvm_vmx.cr4_host_mask);
 
         break;