diff mbox

[01/16] x86/vmx_update_guest_cr: minor optimization

Message ID 1468037527-6474-1-git-send-email-czuzu@bitdefender.com (mailing list archive)
State New, archived
Headers show

Commit Message

Corneliu ZUZU July 9, 2016, 4:12 a.m. UTC
Minor optimization @ vmx_update_guest_cr: checks if v->arch.hvm_vmx.exec_control
was modified before actually calling vmx_update_cpu_exec_control(v).

Signed-off-by: Corneliu ZUZU <czuzu@bitdefender.com>
---
 xen/arch/x86/hvm/vmx/vmx.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Corneliu ZUZU July 11, 2016, 6:24 a.m. UTC | #1
This was 1/8 in the old v3-series "x86/vm-event: Adjustments & fixes".
Transferring code-review from "Tian, Kevin <kevin.tian@intel.com>" (July 
11, 2016).

On 7/9/2016 7:12 AM, Corneliu ZUZU wrote:
> Minor optimization @ vmx_update_guest_cr: checks if v->arch.hvm_vmx.exec_control
> was modified before actually calling vmx_update_cpu_exec_control(v).
>
> Signed-off-by: Corneliu ZUZU <czuzu@bitdefender.com>
> ---
>   xen/arch/x86/hvm/vmx/vmx.c | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c
> index 0776d12..0798245 100644
> --- a/xen/arch/x86/hvm/vmx/vmx.c
> +++ b/xen/arch/x86/hvm/vmx/vmx.c
> @@ -1433,8 +1433,10 @@ static void vmx_update_guest_cr(struct vcpu *v, unsigned int cr)
>           if ( paging_mode_hap(v->domain) )
>           {
>               /* Manage GUEST_CR3 when CR0.PE=0. */
> +            uint32_t old_ctls = v->arch.hvm_vmx.exec_control;
>               uint32_t cr3_ctls = (CPU_BASED_CR3_LOAD_EXITING |
>                                    CPU_BASED_CR3_STORE_EXITING);
> +
>               v->arch.hvm_vmx.exec_control &= ~cr3_ctls;
>               if ( !hvm_paging_enabled(v) && !vmx_unrestricted_guest(v) )
>                   v->arch.hvm_vmx.exec_control |= cr3_ctls;
> @@ -1444,7 +1446,8 @@ static void vmx_update_guest_cr(struct vcpu *v, unsigned int cr)
>                    monitor_ctrlreg_bitmask(VM_EVENT_X86_CR3) )
>                   v->arch.hvm_vmx.exec_control |= CPU_BASED_CR3_LOAD_EXITING;
>   
> -            vmx_update_cpu_exec_control(v);
> +            if ( old_ctls != v->arch.hvm_vmx.exec_control )
> +                vmx_update_cpu_exec_control(v);
>           }
>   
>           if ( !nestedhvm_vcpu_in_guestmode(v) )

[Kevin wrote]:

     Acked-by: Kevin Tian <kevin.tian@intel.com>

---

Thanks,
Zuzu C.
diff mbox

Patch

diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c
index 0776d12..0798245 100644
--- a/xen/arch/x86/hvm/vmx/vmx.c
+++ b/xen/arch/x86/hvm/vmx/vmx.c
@@ -1433,8 +1433,10 @@  static void vmx_update_guest_cr(struct vcpu *v, unsigned int cr)
         if ( paging_mode_hap(v->domain) )
         {
             /* Manage GUEST_CR3 when CR0.PE=0. */
+            uint32_t old_ctls = v->arch.hvm_vmx.exec_control;
             uint32_t cr3_ctls = (CPU_BASED_CR3_LOAD_EXITING |
                                  CPU_BASED_CR3_STORE_EXITING);
+
             v->arch.hvm_vmx.exec_control &= ~cr3_ctls;
             if ( !hvm_paging_enabled(v) && !vmx_unrestricted_guest(v) )
                 v->arch.hvm_vmx.exec_control |= cr3_ctls;
@@ -1444,7 +1446,8 @@  static void vmx_update_guest_cr(struct vcpu *v, unsigned int cr)
                  monitor_ctrlreg_bitmask(VM_EVENT_X86_CR3) )
                 v->arch.hvm_vmx.exec_control |= CPU_BASED_CR3_LOAD_EXITING;
 
-            vmx_update_cpu_exec_control(v);
+            if ( old_ctls != v->arch.hvm_vmx.exec_control )
+                vmx_update_cpu_exec_control(v);
         }
 
         if ( !nestedhvm_vcpu_in_guestmode(v) )