From: Paolo Bonzini <pbonzini@redhat.com>
To: Wanpeng Li <kernellwp@gmail.com>,
linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Cc: "Radim Krčmář" <rkrcmar@redhat.com>,
"Wanpeng Li" <wanpeng.li@hotmail.com>
Subject: Re: [PATCH RESEND 3/3] KVM: Add flush_on_enter before guest enter
Date: Thu, 9 Nov 2017 11:54:01 +0100 [thread overview]
Message-ID: <cc07b143-d3ae-4ce3-fe87-73f3b3a73451@redhat.com> (raw)
In-Reply-To: <1510192934-5369-4-git-send-email-wanpeng.li@hotmail.com>
On 09/11/2017 03:02, Wanpeng Li wrote:
> From: Wanpeng Li <wanpeng.li@hotmail.com>
>
> PV-Flush guest would indicate to flush on enter, flush the TLB before
> entering and exiting the guest.
>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Radim Krčmář <rkrcmar@redhat.com>
> Signed-off-by: Wanpeng Li <wanpeng.li@hotmail.com>
> ---
> arch/x86/kvm/x86.c | 12 ++++++++++--
> 1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 1ea28a2..f295360 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -2116,7 +2116,13 @@ static void record_steal_time(struct kvm_vcpu *vcpu)
> &vcpu->arch.st.steal, sizeof(struct kvm_steal_time))))
> return;
>
> - vcpu->arch.st.steal.preempted = KVM_VCPU_NOT_PREEMPTED;
> + if (xchg(&vcpu->arch.st.steal.preempted, KVM_VCPU_NOT_PREEMPTED) ==
> + (KVM_VCPU_SHOULD_FLUSH | KVM_VCPU_PREEMPTED))
> + /*
> + * Do TLB_FLUSH before entering the guest, its passed
> + * the stage of request checking
> + */
> + kvm_x86_ops->tlb_flush(vcpu);
>
> if (vcpu->arch.st.steal.version & 1)
> vcpu->arch.st.steal.version += 1; /* first time write, random junk */
> @@ -2887,7 +2893,9 @@ static void kvm_steal_time_set_preempted(struct kvm_vcpu *vcpu)
> if (!(vcpu->arch.st.msr_val & KVM_MSR_ENABLED))
> return;
>
> - vcpu->arch.st.steal.preempted = KVM_VCPU_PREEMPTED;
> + if (xchg(&vcpu->arch.st.steal.preempted, KVM_VCPU_PREEMPTED) ==
> + KVM_VCPU_SHOULD_FLUSH)
> + kvm_make_request(KVM_REQ_TLB_FLUSH, vcpu);
This is not necessary. Instead, you can just OR the KVM_VCPU_PREEMPTED
bit; record_steal_time will pick up the request and do the TLB flush later.
Also, I think this is a case where you should prefer INVVPID to INVEP.
That's because "execution of the INVEPT instruction invalidates
guest-physical mappings and combined mappings" while "execution of the
INVVPID instruction invalidates linear mappings and combined mappings".
In this case, invalidating guest-physical mapping is unnecessary.
So you could add a new bool argument to kvm_x86_ops->tlb_flush. In
vmx.c, __vmx_flush_tlb can do invept if "enable_ept && (invalidate_gpa
|| !enable_vpid)".
If !enable_ept && !enable_vpid, the feature cannot be made available.
Thanks,
Paolo
> kvm_write_guest_offset_cached(vcpu->kvm, &vcpu->arch.st.stime,
> &vcpu->arch.st.steal.preempted,
>
next prev parent reply other threads:[~2017-11-09 10:54 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-09 2:02 [PATCH RESEND 0/3] KVM: Paravirt remote TLB flush Wanpeng Li
2017-11-09 2:02 ` [PATCH RESEND 1/3] KVM: Add vCPU running/preempted state Wanpeng Li
2017-11-09 2:02 ` [PATCH RESEND 2/3] KVM: Add paravirt remote TLB flush Wanpeng Li
2017-11-09 10:48 ` Paolo Bonzini
2017-11-09 11:01 ` Wanpeng Li
2017-11-09 11:02 ` Paolo Bonzini
2017-11-09 11:08 ` Wanpeng Li
2017-11-09 15:11 ` Radim Krčmář
2017-11-09 2:02 ` [PATCH RESEND 3/3] KVM: Add flush_on_enter before guest enter Wanpeng Li
2017-11-09 10:54 ` Paolo Bonzini [this message]
2017-11-09 12:31 ` Wanpeng Li
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=cc07b143-d3ae-4ce3-fe87-73f3b3a73451@redhat.com \
--to=pbonzini@redhat.com \
--cc=kernellwp@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rkrcmar@redhat.com \
--cc=wanpeng.li@hotmail.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).