diff mbox series

[v3,08/37] KVM: VMX: Skip global INVVPID fallback if vpid==0 in vpid_sync_context()

Message ID 20200320212833.3507-9-sean.j.christopherson@intel.com (mailing list archive)
State New, archived
Headers show
Series KVM: x86: TLB flushing fixes and enhancements | expand

Commit Message

Sean Christopherson March 20, 2020, 9:28 p.m. UTC
Skip the global INVVPID in the unlikely scenario that vpid==0 and the
SINGLE_CONTEXT variant of INVVPID is unsupported.  If vpid==0, there's
no need to INVVPID as it's impossible to do VM-Enter with VPID enabled
and vmcs.VPID==0, i.e. there can't be any TLB entries for the vCPU with
vpid==0.  The fact that the SINGLE_CONTEXT variant isn't supported is
irrelevant.

Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
---
 arch/x86/kvm/vmx/ops.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Vitaly Kuznetsov March 25, 2020, 9:33 a.m. UTC | #1
Sean Christopherson <sean.j.christopherson@intel.com> writes:

> Skip the global INVVPID in the unlikely scenario that vpid==0 and the
> SINGLE_CONTEXT variant of INVVPID is unsupported.  If vpid==0, there's
> no need to INVVPID as it's impossible to do VM-Enter with VPID enabled
> and vmcs.VPID==0, i.e. there can't be any TLB entries for the vCPU with
> vpid==0.  The fact that the SINGLE_CONTEXT variant isn't supported is
> irrelevant.
>
> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
> ---
>  arch/x86/kvm/vmx/ops.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/kvm/vmx/ops.h b/arch/x86/kvm/vmx/ops.h
> index 45eaedee2ac0..33645a8e5463 100644
> --- a/arch/x86/kvm/vmx/ops.h
> +++ b/arch/x86/kvm/vmx/ops.h
> @@ -285,7 +285,7 @@ static inline void vpid_sync_context(int vpid)
>  {
>  	if (cpu_has_vmx_invvpid_single())
>  		vpid_sync_vcpu_single(vpid);
> -	else
> +	else if (vpid != 0)
>  		vpid_sync_vcpu_global();
>  }

Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com>

(personally, I also prefer 'vpid !=0' to '!vpid', however, nested.c
uses expressions like '&& !vmcs12->virtual_processor_id' instead...)
diff mbox series

Patch

diff --git a/arch/x86/kvm/vmx/ops.h b/arch/x86/kvm/vmx/ops.h
index 45eaedee2ac0..33645a8e5463 100644
--- a/arch/x86/kvm/vmx/ops.h
+++ b/arch/x86/kvm/vmx/ops.h
@@ -285,7 +285,7 @@  static inline void vpid_sync_context(int vpid)
 {
 	if (cpu_has_vmx_invvpid_single())
 		vpid_sync_vcpu_single(vpid);
-	else
+	else if (vpid != 0)
 		vpid_sync_vcpu_global();
 }