From: Sean Christopherson <seanjc@google.com>
To: Lai Jiangshan <laijs@linux.alibaba.com>
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
"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>,
"Radim Krčmář" <rkrcmar@redhat.com>,
kvm@vger.kernel.org, "Maxim Levitsky" <mlevitsk@redhat.com>
Subject: Re: [PATCH] KVM: X86: fix tlb_flush_guest()
Date: Fri, 28 May 2021 00:26:13 +0000 [thread overview]
Message-ID: <YLA4peMjgeVvKlEn@google.com> (raw)
In-Reply-To: <d96f8c11-19e6-2c2d-91ff-6a7a51fa1b9c@linux.alibaba.com>
On Fri, May 28, 2021, Lai Jiangshan wrote:
>
> On 2021/5/28 00:13, Sean Christopherson wrote:
> > And making a request won't work without revamping the order of request handling
> > in vcpu_enter_guest(), e.g. KVM_REQ_MMU_RELOAD and KVM_REQ_MMU_SYNC are both
> > serviced before KVM_REQ_STEAL_UPDATE.
>
> Yes, it just fixes the said problem in the simplest way.
> I copied KVM_REQ_MMU_RELOAD from kvm_handle_invpcid(INVPCID_TYPE_ALL_INCL_GLOBAL).
> (If the guest is not preempted, it will call invpcid_flush_all() and will be handled
> by this way)
The problem is that record_steal_time() is called after KVM_REQ_MMU_RELOAD
in vcpu_enter_guest() and so the reload request won't be recognized until the
next VM-Exit. It works for kvm_handle_invpcid() because vcpu_enter_guest() is
guaranteed to run between the invcpid code and VM-Enter.
> The improvement code will go later, and will not be backported.
I would argue that introducing a potential performance regression is in itself a
bug. IMO, going straight to kvm_mmu_sync_roots() is not high risk.
> The proper way to flush guest is to use code in
>
> https://lore.kernel.org/lkml/20210525213920.3340-1-jiangshanlai@gmail.com/
> as:
> + kvm_mmu_sync_roots(vcpu);
> + kvm_make_request(KVM_REQ_TLB_FLUSH_CURRENT, vcpu); //or just call flush_current directly
> + for (i = 0; i < KVM_MMU_NUM_PREV_ROOTS; i++)
> + vcpu->arch.mmu->prev_roots[i].need_sync = true;
>
> If need_sync patch is not accepted, we can just use kvm_mmu_sync_roots(vcpu)
> to keep the current pagetable and use kvm_mmu_free_roots() to free all the other
> roots in prev_roots.
I like the idea, I just haven't gotten around to reviewing that patch yet.
> > Cleaning up and documenting the MMU related requests is on my todo list, but the
> > immediate fix should be tiny and I can do my cleanups on top.
> >
> > 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);
>
> it doesn't handle prev_roots which are also needed as
> shown in kvm_handle_invpcid(INVPCID_TYPE_ALL_INCL_GLOBAL).
Ya, I belated realized this :-)
> > static_call(kvm_x86_tlb_flush_guest)(vcpu);
>
> For tdp_enabled, I think it is better to use kvm_x86_tlb_flush_current()
> to make it consistent with other shadowpage code.
>
> > }
> >
next prev parent reply other threads:[~2021-05-28 0:26 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
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 [this message]
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=YLA4peMjgeVvKlEn@google.com \
--to=seanjc@google.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=laijs@linux.alibaba.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=mlevitsk@redhat.com \
--cc=pbonzini@redhat.com \
--cc=rkrcmar@redhat.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 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.