Re: [PATCH 13/22] kvm: mmu: Support invalidate range MMU notifier for TDP MMU

From: Sean Christopherson
Date: Wed Sep 30 2020 - 19:24:38 EST


On Wed, Sep 30, 2020 at 04:15:17PM -0700, Ben Gardon wrote:
> On Wed, Sep 30, 2020 at 10:04 AM Sean Christopherson
> <sean.j.christopherson@xxxxxxxxx> wrote:
> > > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
> > > index 52d661a758585..0ddfdab942554 100644
> > > --- a/arch/x86/kvm/mmu/mmu.c
> > > +++ b/arch/x86/kvm/mmu/mmu.c
> > > @@ -1884,7 +1884,14 @@ static int kvm_handle_hva(struct kvm *kvm, unsigned long hva,
> > > int kvm_unmap_hva_range(struct kvm *kvm, unsigned long start, unsigned long end,
> > > unsigned flags)
> > > {
> > > - return kvm_handle_hva_range(kvm, start, end, 0, kvm_unmap_rmapp);
> > > + int r;
> > > +
> > > + r = kvm_handle_hva_range(kvm, start, end, 0, kvm_unmap_rmapp);
> > > +
> > > + if (kvm->arch.tdp_mmu_enabled)
> > > + r |= kvm_tdp_mmu_zap_hva_range(kvm, start, end);
> >
> > Similar to an earlier question, is this intentionally additive, or can this
> > instead by:
> >
> > if (kvm->arch.tdp_mmu_enabled)
> > r = kvm_tdp_mmu_zap_hva_range(kvm, start, end);
> > else
> > r = kvm_handle_hva_range(kvm, start, end, 0, kvm_unmap_rmapp);
> >
>
> It is intentionally additive so the legacy/shadow MMU can handle nested.

Duh. Now everything makes sense. I completely spaced on nested EPT.

I wonder if would be worth adding a per-VM sticky bit that is set when an
rmap is added so that all of these flows can skip the rmap walks when using
the TDP MMU without a nested guest.