diff mbox series

[V4,14/15] KVM/VMX: Change hv flush logic when ept tables are mismatched.

Message ID 20181013145406.4911-15-Tianyu.Lan@microsoft.com (mailing list archive)
State New, archived
Headers show
Series x86/KVM/Hyper-v: Add HV ept tlb range flush hypercall support in KVM | expand

Commit Message

Tianyu Lan Oct. 13, 2018, 2:54 p.m. UTC
From: Lan Tianyu <Tianyu.Lan@microsoft.com>

If ept table pointers are mismatched, flushing tlb for each vcpus via
hv flush interface still helps to reduce vmexits which are triggered
by IPI and INEPT emulation.

Signed-off-by: Lan Tianyu <Tianyu.Lan@microsoft.com>
---
 arch/x86/kvm/vmx.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

Comments

Paolo Bonzini Oct. 15, 2018, 11:15 a.m. UTC | #1
On 13/10/2018 16:54, lantianyu1986@gmail.com wrote:
> From: Lan Tianyu <Tianyu.Lan@microsoft.com>
> 
> If ept table pointers are mismatched, flushing tlb for each vcpus via
> hv flush interface still helps to reduce vmexits which are triggered
> by IPI and INEPT emulation.
> 
> Signed-off-by: Lan Tianyu <Tianyu.Lan@microsoft.com>
> ---
>  arch/x86/kvm/vmx.c | 15 ++++++++-------
>  1 file changed, 8 insertions(+), 7 deletions(-)
> 
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index 6f44d3a63434..8ff13f3aed11 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -1571,7 +1571,8 @@ static void check_ept_pointer_match(struct kvm *kvm)
>  
>  static int vmx_hv_remote_flush_tlb(struct kvm *kvm)
>  {
> -	int ret;
> +	struct kvm_vcpu *vcpu;
> +	int ret = -ENOTSUPP, i;
>  
>  	spin_lock(&to_kvm_vmx(kvm)->ept_pointer_lock);
>  
> @@ -1579,14 +1580,14 @@ static int vmx_hv_remote_flush_tlb(struct kvm *kvm)
>  		check_ept_pointer_match(kvm);
>  
>  	if (to_kvm_vmx(kvm)->ept_pointers_match != EPT_POINTERS_MATCH) {
> -		ret = -ENOTSUPP;
> -		goto out;
> +		kvm_for_each_vcpu(i, vcpu, kvm)
> +			ret |= hyperv_flush_guest_mapping(
> +				to_vmx(kvm_get_vcpu(kvm, i))->ept_pointer);
> +	} else {
> +		ret = hyperv_flush_guest_mapping(
> +				to_vmx(kvm_get_vcpu(kvm, 0))->ept_pointer);
>  	}
>  
> -	ret = hyperv_flush_guest_mapping(
> -			to_vmx(kvm_get_vcpu(kvm, 0))->ept_pointer);
> -
> -out:
>  	spin_unlock(&to_kvm_vmx(kvm)->ept_pointer_lock);
>  	return ret;
>  }
> 

I think this is an independent change that can be applied separately?

Thanks,

Paolo
diff mbox series

Patch

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 6f44d3a63434..8ff13f3aed11 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -1571,7 +1571,8 @@  static void check_ept_pointer_match(struct kvm *kvm)
 
 static int vmx_hv_remote_flush_tlb(struct kvm *kvm)
 {
-	int ret;
+	struct kvm_vcpu *vcpu;
+	int ret = -ENOTSUPP, i;
 
 	spin_lock(&to_kvm_vmx(kvm)->ept_pointer_lock);
 
@@ -1579,14 +1580,14 @@  static int vmx_hv_remote_flush_tlb(struct kvm *kvm)
 		check_ept_pointer_match(kvm);
 
 	if (to_kvm_vmx(kvm)->ept_pointers_match != EPT_POINTERS_MATCH) {
-		ret = -ENOTSUPP;
-		goto out;
+		kvm_for_each_vcpu(i, vcpu, kvm)
+			ret |= hyperv_flush_guest_mapping(
+				to_vmx(kvm_get_vcpu(kvm, i))->ept_pointer);
+	} else {
+		ret = hyperv_flush_guest_mapping(
+				to_vmx(kvm_get_vcpu(kvm, 0))->ept_pointer);
 	}
 
-	ret = hyperv_flush_guest_mapping(
-			to_vmx(kvm_get_vcpu(kvm, 0))->ept_pointer);
-
-out:
 	spin_unlock(&to_kvm_vmx(kvm)->ept_pointer_lock);
 	return ret;
 }