All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vitaly Kuznetsov <vkuznets@redhat.com>
To: ltykernel@gmail.com
Cc: Lan Tianyu <Tianyu.Lan@microsoft.com>,
	pbonzini@redhat.com, rkrcmar@redhat.com, tglx@linutronix.de,
	mingo@redhat.com, bp@alien8.de, hpa@zytor.com, x86@kernel.org,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	michael.h.kelley@microsoft.com, kys@microsoft.com
Subject: Re: [PATCH] KVM/VMX: Check ept_pointer before flushing ept tlb
Date: Tue, 06 Nov 2018 16:50:26 +0100	[thread overview]
Message-ID: <87lg66urwd.fsf@vitty.brq.redhat.com> (raw)
In-Reply-To: <20181106133043.83570-1-Tianyu.Lan@microsoft.com>

ltykernel@gmail.com writes:

> From: Lan Tianyu <Tianyu.Lan@microsoft.com>
>
> This patch is to initialize ept_pointer to INVALID_PAGE and check it
> before flushing ept tlb. If ept_pointer is invalidated, bypass the flush
> request.
>
> Signed-off-by: Lan Tianyu <Tianyu.Lan@microsoft.com>
> ---
>  arch/x86/kvm/vmx.c | 16 +++++++++++++---
>  1 file changed, 13 insertions(+), 3 deletions(-)
>
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index 4555077d69ce..edbc96cb990a 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -1580,14 +1580,22 @@ static int vmx_hv_remote_flush_tlb(struct kvm *kvm)
>  	/*
>  	 * FLUSH_GUEST_PHYSICAL_ADDRESS_SPACE hypercall needs the address of the
>  	 * base of EPT PML4 table, strip off EPT configuration information.
> +	 * If ept_pointer is invalid pointer, bypass the flush request.
>  	 */
>  	if (to_kvm_vmx(kvm)->ept_pointers_match != EPT_POINTERS_MATCH) {
> -		kvm_for_each_vcpu(i, vcpu, kvm)
> +		kvm_for_each_vcpu(i, vcpu, kvm) {
> +			if (!VALID_PAGE(to_vmx(vcpu)->ept_pointer))
> +				return 0;
> +

To be honest I fail to understand the reason behind the patch: instead
of doing one unneeded flush request with ept_pointer==0 (after vCPU is
initialized) we now do the check every time. Could you please elaborate
on why this is needed?


>  			ret |= hyperv_flush_guest_mapping(
> -				to_vmx(kvm_get_vcpu(kvm, i))->ept_pointer & PAGE_MASK);
> +				to_vmx(vcpu)->ept_pointer & PAGE_MASK);

I would use a local variable for 'to_vmx(vcpu)->ept_pointer' or even
'to_vmx(vcpu)->ept_pointer & PAGE_MASK' and use it in VALID_PAGE() - as
lower bits are unrelated;


> +		}
>  	} else {
> +		if (!VALID_PAGE(to_vmx(kvm_get_vcpu(kvm, 0))->ept_pointer))
> +			return 0;

Ditto.

> +
>  		ret = hyperv_flush_guest_mapping(
> -				to_vmx(kvm_get_vcpu(kvm, 0))->ept_pointer & PAGE_MASK);
> +			to_vmx(kvm_get_vcpu(kvm, 0))->ept_pointer & PAGE_MASK);

This doesn't belong to this patch.

>  	}
>  
>  	spin_unlock(&to_kvm_vmx(kvm)->ept_pointer_lock);
> @@ -11568,6 +11576,8 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id)
>  	vmx->pi_desc.nv = POSTED_INTR_VECTOR;
>  	vmx->pi_desc.sn = 1;
>  
> +	vmx->ept_pointer = INVALID_PAGE;
> +
>  	return &vmx->vcpu;
>  
>  free_vmcs:

-- 
Vitaly

  reply	other threads:[~2018-11-06 15:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-06 13:30 [PATCH] KVM/VMX: Check ept_pointer before flushing ept tlb ltykernel
2018-11-06 15:50 ` Vitaly Kuznetsov [this message]
2018-11-07  6:15   ` Tianyu Lan
2018-11-07 10:49     ` Vitaly Kuznetsov
2018-11-08  6:12       ` Tianyu Lan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87lg66urwd.fsf@vitty.brq.redhat.com \
    --to=vkuznets@redhat.com \
    --cc=Tianyu.Lan@microsoft.com \
    --cc=bp@alien8.de \
    --cc=hpa@zytor.com \
    --cc=kvm@vger.kernel.org \
    --cc=kys@microsoft.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ltykernel@gmail.com \
    --cc=michael.h.kelley@microsoft.com \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=rkrcmar@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.