From: Lai Jiangshan <laijs@linux.alibaba.com>
To: Sean Christopherson <seanjc@google.com>,
Paolo Bonzini <pbonzini@redhat.com>
Cc: Lai Jiangshan <jiangshanlai@gmail.com>,
linux-kernel@vger.kernel.org,
Vitaly Kuznetsov <vkuznets@redhat.com>,
Wanpeng Li <wanpengli@tencent.com>,
Jim Mattson <jmattson@google.com>, Joerg Roedel <joro@8bytes.org>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
Maxim Levitsky <mlevitsk@redhat.com>,
kvm@vger.kernel.org
Subject: Re: [PATCH] KVM: X86: fix tlb_flush_guest()
Date: Fri, 28 May 2021 09:13:08 +0800 [thread overview]
Message-ID: <fc0f8b39-11a9-da21-dc5b-fc9695292556@linux.alibaba.com> (raw)
In-Reply-To: <YK/y3QgSg+aYk9Z+@google.com>
On 2021/5/28 03:28, Sean Christopherson wrote:
> On Thu, May 27, 2021, Sean Christopherson wrote:
>>> KVM_REQ_MMU_RELOAD is overkill, nuking the shadow page tables will completely
>>> offset the performance gains of the paravirtualized flush.
>
> Argh, I take that back. The PV KVM_VCPU_FLUSH_TLB flag doesn't distinguish
> between flushing a specific mm and flushing the entire TLB. The HyperV usage
> (via KVM_REQ) also throws everything into a single bucket. A full RELOAD still
> isn't necessary as KVM just needs to sync all roots, not blast them away. For
> previous roots, KVM doesn't have a mechanism to defer the sync, so the immediate
> fix will need to unload those roots.
>
> And looking at KVM's other flows, __kvm_mmu_new_pgd() and kvm_set_cr3() are also
> broken with respect to previous roots. E.g. if the guest does a MOV CR3 that
> flushes the entire TLB, followed by a MOV CR3 with PCID_NOFLUSH=1, KVM will fail
> to sync the MMU on the second flush even though the guest can technically rely
> on the first MOV CR3 to have synchronized any previous changes relative to the
> fisrt MOV CR3.
Could you elaborate the problem please?
When can a MOV CR3 that needs to flush the entire TLB if PCID is enabled?
If CR4.PCIDE = 1 and bit 63 of the instruction’s source operand is 0, the instruction invalidates all TLB entries
associated with the PCID specified in bits 11:0 of the instruction’s source operand except those for global pages. It
also invalidates all entries in all paging-structure caches associated with that PCID. It is not required to invalidate
entries in the TLBs and paging-structure caches that are associated with other PCIDs.
>
> Lai, if it's ok with you, I'll massage this patch as discussed and fold it into
> a larger series to fix the other bugs and do additional cleanup/improvements.
>
>>> I believe the minimal fix is:
>>>
>>> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
>>> index 81ab3b8f22e5..b0072063f9bf 100644
>>> --- a/arch/x86/kvm/x86.c
>>> +++ b/arch/x86/kvm/x86.c
>>> @@ -3072,6 +3072,9 @@ static void kvm_vcpu_flush_tlb_all(struct kvm_vcpu *vcpu)
>>> static void kvm_vcpu_flush_tlb_guest(struct kvm_vcpu *vcpu)
>>> {
>>> ++vcpu->stat.tlb_flush;
>>> +
>>> + if (!tdp_enabled)
>>> + kvm_mmu_sync_roots(vcpu);
>>> static_call(kvm_x86_tlb_flush_guest)(vcpu);
>>> }
next prev parent reply other threads:[~2021-05-28 1:13 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-27 2:39 [PATCH] KVM: X86: fix tlb_flush_guest() Lai Jiangshan
2021-05-27 12:55 ` Paolo Bonzini
2021-05-27 16:13 ` Sean Christopherson
2021-05-27 16:14 ` Sean Christopherson
2021-05-27 19:28 ` Sean Christopherson
2021-05-28 1:13 ` Lai Jiangshan [this message]
2021-06-02 15:09 ` Sean Christopherson
2021-06-02 22:07 ` Sean Christopherson
2021-05-28 0:18 ` Lai Jiangshan
2021-05-28 0:26 ` Sean Christopherson
2021-05-28 1:29 ` Lai Jiangshan
2021-06-02 15:01 ` Sean Christopherson
2021-06-02 8:13 ` Lai Jiangshan
2021-05-29 22:12 ` Maxim Levitsky
2021-05-31 17:22 ` [PATCH V2] " Lai Jiangshan
2021-06-02 15:39 ` Sean Christopherson
2021-06-07 22:38 ` Maxim Levitsky
2021-06-08 0:03 ` Sean Christopherson
2021-06-08 14:01 ` Lai Jiangshan
2021-06-08 17:36 ` Paolo Bonzini
2021-06-08 21:31 ` Maxim Levitsky
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=fc0f8b39-11a9-da21-dc5b-fc9695292556@linux.alibaba.com \
--to=laijs@linux.alibaba.com \
--cc=bp@alien8.de \
--cc=hpa@zytor.com \
--cc=jiangshanlai@gmail.com \
--cc=jmattson@google.com \
--cc=joro@8bytes.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=mlevitsk@redhat.com \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=tglx@linutronix.de \
--cc=vkuznets@redhat.com \
--cc=wanpengli@tencent.com \
--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 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).