diff mbox

[v3,5/9] x86/vvmx: make updating shadow EPTP value more efficient

Message ID 1507208685.3314.5.camel@citrix.com (mailing list archive)
State New, archived
Headers show

Commit Message

Sergey Dyasli Oct. 5, 2017, 1:04 p.m. UTC
On Thu, 2017-10-05 at 03:27 -0600, Jan Beulich wrote:
> > > > On 05.10.17 at 10:18, <sergey.dyasli@citrix.com> wrote:
> > 
> > --- a/xen/arch/x86/hvm/vmx/entry.S
> > +++ b/xen/arch/x86/hvm/vmx/entry.S
> > @@ -80,7 +80,7 @@ UNLIKELY_END(realmode)
> >          mov  %rsp,%rdi
> >          call vmx_vmenter_helper
> >          cmp  $0,%eax
> > -        jne .Lvmx_vmentry_restart
> > +        je .Lvmx_vmentry_restart
> 
> If you make the function return bool, the cmp above also needs
> changing (and then preferably to "test %al, %al", in which case
> it would then also better be "jz" instead of "je").

Here's the updated delta:


-- 
Thanks,
Sergey

Comments

Andrew Cooper Oct. 5, 2017, 1:12 p.m. UTC | #1
On 05/10/17 14:04, Sergey Dyasli wrote:
> On Thu, 2017-10-05 at 03:27 -0600, Jan Beulich wrote:
>>>>> On 05.10.17 at 10:18, <sergey.dyasli@citrix.com> wrote:
>>> --- a/xen/arch/x86/hvm/vmx/entry.S
>>> +++ b/xen/arch/x86/hvm/vmx/entry.S
>>> @@ -80,7 +80,7 @@ UNLIKELY_END(realmode)
>>>          mov  %rsp,%rdi
>>>          call vmx_vmenter_helper
>>>          cmp  $0,%eax
>>> -        jne .Lvmx_vmentry_restart
>>> +        je .Lvmx_vmentry_restart
>> If you make the function return bool, the cmp above also needs
>> changing (and then preferably to "test %al, %al", in which case
>> it would then also better be "jz" instead of "je").
> Here's the updated delta:
>
> diff --git a/xen/arch/x86/hvm/vmx/entry.S b/xen/arch/x86/hvm/vmx/entry.S
> index 9fb8f89220..47cd674260 100644
> --- a/xen/arch/x86/hvm/vmx/entry.S
> +++ b/xen/arch/x86/hvm/vmx/entry.S
> @@ -79,8 +79,8 @@ UNLIKELY_END(realmode)
>  
>          mov  %rsp,%rdi
>          call vmx_vmenter_helper
> -        cmp  $0,%eax
> -        jne .Lvmx_vmentry_restart
> +        test %al, %al
> +        jz .Lvmx_vmentry_restart
>          mov  VCPU_hvm_guest_cr2(%rbx),%rax
>  
>          pop  %r15
> diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c
> index c9a4111267..a5c2bd71cd 100644
> --- a/xen/arch/x86/hvm/vmx/vmx.c
> +++ b/xen/arch/x86/hvm/vmx/vmx.c
> @@ -4197,7 +4197,8 @@ static void lbr_fixup(void)
>          bdw_erratum_bdf14_fixup();
>  }
>  
> -int vmx_vmenter_helper(const struct cpu_user_regs *regs)
> +/* Returns false if the vmentry has to be restarted */
> +bool vmx_vmenter_helper(const struct cpu_user_regs *regs)
>  {
>      struct vcpu *curr = current;
>      u32 new_asid, old_asid;
> @@ -4206,7 +4207,7 @@ int vmx_vmenter_helper(const struct cpu_user_regs *regs)
>  
>      /* Shadow EPTP can't be updated here because irqs are disabled */
>       if ( nestedhvm_vcpu_in_guestmode(curr) && vcpu_nestedhvm(curr).stale_np2m )
> -         return 1;
> +         return false;
>  
>      if ( curr->domain->arch.hvm_domain.pi_ops.do_resume )
>          curr->domain->arch.hvm_domain.pi_ops.do_resume(curr);
> @@ -4269,7 +4270,7 @@ int vmx_vmenter_helper(const struct cpu_user_regs *regs)
>      __vmwrite(GUEST_RSP,    regs->rsp);
>      __vmwrite(GUEST_RFLAGS, regs->rflags | X86_EFLAGS_MBS);
>  
> -    return 0;
> +    return true;
>  }

With this, the whole series is Acked-by: Andrew Cooper
<andrew.cooper3@citrix.com>
Nakajima, Jun Oct. 6, 2017, 5:33 a.m. UTC | #2
On 10/5/17, 6:13 AM, "Andrew Cooper" wrote:

    On 05/10/17 14:04, Sergey Dyasli wrote:
    > On Thu, 2017-10-05 at 03:27 -0600, Jan Beulich wrote:

    >>>>> On 05.10.17 at 10:18, <sergey.dyasli@citrix.com> wrote:

    >>> --- a/xen/arch/x86/hvm/vmx/entry.S

    >>> +++ b/xen/arch/x86/hvm/vmx/entry.S

    >>> @@ -80,7 +80,7 @@ UNLIKELY_END(realmode)

    >>>          mov  %rsp,%rdi

    >>>          call vmx_vmenter_helper

    >>>          cmp  $0,%eax

    >>> -        jne .Lvmx_vmentry_restart

    >>> +        je .Lvmx_vmentry_restart

    >> If you make the function return bool, the cmp above also needs

    >> changing (and then preferably to "test %al, %al", in which case

    >> it would then also better be "jz" instead of "je").

    > Here's the updated delta:

    >

    > diff --git a/xen/arch/x86/hvm/vmx/entry.S b/xen/arch/x86/hvm/vmx/entry.S

    > index 9fb8f89220..47cd674260 100644

    > --- a/xen/arch/x86/hvm/vmx/entry.S

    > +++ b/xen/arch/x86/hvm/vmx/entry.S

    > @@ -79,8 +79,8 @@ UNLIKELY_END(realmode)

    >  

    >          mov  %rsp,%rdi

    >          call vmx_vmenter_helper

    > -        cmp  $0,%eax

    > -        jne .Lvmx_vmentry_restart

    > +        test %al, %al

    > +        jz .Lvmx_vmentry_restart

    >          mov  VCPU_hvm_guest_cr2(%rbx),%rax

    >  

    >          pop  %r15

    > diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c

    > index c9a4111267..a5c2bd71cd 100644

    > --- a/xen/arch/x86/hvm/vmx/vmx.c

    > +++ b/xen/arch/x86/hvm/vmx/vmx.c

    > @@ -4197,7 +4197,8 @@ static void lbr_fixup(void)

    >          bdw_erratum_bdf14_fixup();

    >  }

    >  

    > -int vmx_vmenter_helper(const struct cpu_user_regs *regs)

    > +/* Returns false if the vmentry has to be restarted */

    > +bool vmx_vmenter_helper(const struct cpu_user_regs *regs)

    >  {

    >      struct vcpu *curr = current;

    >      u32 new_asid, old_asid;

    > @@ -4206,7 +4207,7 @@ int vmx_vmenter_helper(const struct cpu_user_regs *regs)

    >  

    >      /* Shadow EPTP can't be updated here because irqs are disabled */

    >       if ( nestedhvm_vcpu_in_guestmode(curr) && vcpu_nestedhvm(curr).stale_np2m )

    > -         return 1;

    > +         return false;

    >  

    >      if ( curr->domain->arch.hvm_domain.pi_ops.do_resume )

    >          curr->domain->arch.hvm_domain.pi_ops.do_resume(curr);

    > @@ -4269,7 +4270,7 @@ int vmx_vmenter_helper(const struct cpu_user_regs *regs)

    >      __vmwrite(GUEST_RSP,    regs->rsp);

    >      __vmwrite(GUEST_RFLAGS, regs->rflags | X86_EFLAGS_MBS);

    >  

    > -    return 0;

    > +    return true;

    >  }

    
    With this, the whole series is Acked-by: Andrew Cooper
    <andrew.cooper3@citrix.com>

Acked-by: Jun Nakajima <jun.nakajima@intel.com>

  
---
Jun
Intel Open Source Technology Center
diff mbox

Patch

diff --git a/xen/arch/x86/hvm/vmx/entry.S b/xen/arch/x86/hvm/vmx/entry.S
index 9fb8f89220..47cd674260 100644
--- a/xen/arch/x86/hvm/vmx/entry.S
+++ b/xen/arch/x86/hvm/vmx/entry.S
@@ -79,8 +79,8 @@  UNLIKELY_END(realmode)
 
         mov  %rsp,%rdi
         call vmx_vmenter_helper
-        cmp  $0,%eax
-        jne .Lvmx_vmentry_restart
+        test %al, %al
+        jz .Lvmx_vmentry_restart
         mov  VCPU_hvm_guest_cr2(%rbx),%rax
 
         pop  %r15
diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c
index c9a4111267..a5c2bd71cd 100644
--- a/xen/arch/x86/hvm/vmx/vmx.c
+++ b/xen/arch/x86/hvm/vmx/vmx.c
@@ -4197,7 +4197,8 @@  static void lbr_fixup(void)
         bdw_erratum_bdf14_fixup();
 }
 
-int vmx_vmenter_helper(const struct cpu_user_regs *regs)
+/* Returns false if the vmentry has to be restarted */
+bool vmx_vmenter_helper(const struct cpu_user_regs *regs)
 {
     struct vcpu *curr = current;
     u32 new_asid, old_asid;
@@ -4206,7 +4207,7 @@  int vmx_vmenter_helper(const struct cpu_user_regs *regs)
 
     /* Shadow EPTP can't be updated here because irqs are disabled */
      if ( nestedhvm_vcpu_in_guestmode(curr) && vcpu_nestedhvm(curr).stale_np2m )
-         return 1;
+         return false;
 
     if ( curr->domain->arch.hvm_domain.pi_ops.do_resume )
         curr->domain->arch.hvm_domain.pi_ops.do_resume(curr);
@@ -4269,7 +4270,7 @@  int vmx_vmenter_helper(const struct cpu_user_regs *regs)
     __vmwrite(GUEST_RSP,    regs->rsp);
     __vmwrite(GUEST_RFLAGS, regs->rflags | X86_EFLAGS_MBS);
 
-    return 0;
+    return true;
 }
 
 /*