Re: [RFC 11/19] KVM: x86/mmu: Factor shadow_zero_check out of make_spte

From: Ben Gardon
Date: Wed Nov 10 2021 - 18:49:59 EST


On Wed, Nov 10, 2021 at 2:45 PM Paolo Bonzini <pbonzini@xxxxxxxxxx> wrote:
>
> On 11/10/21 23:30, Ben Gardon wrote:
> > - WARN_ONCE(is_rsvd_spte(&vcpu->arch.mmu->shadow_zero_check, spte, level),
> > + WARN_ONCE(is_rsvd_spte(shadow_zero_check, spte, level),
> > "spte = 0x%llx, level = %d, rsvd bits = 0x%llx", spte, level,
> > - get_rsvd_bits(&vcpu->arch.mmu->shadow_zero_check, spte, level));
> > + get_rsvd_bits(shadow_zero_check, spte, level));
>
> Hmm, there is a deeper issue here, in that when using EPT/NPT (on either
> the legacy aka shadow or the TDP MMU) large parts of vcpu->arch.mmu are
> really the same for all vCPUs. The only thing that varies is those
> parts that actually depend on the guest's paging mode---the extended
> role, the reserved bits, etc. Those are needed by the emulator, but
> don't really belong in vcpu->arch.mmu when EPT/NPT is in use.
>
> I wonder if there's room for splitting kvm_mmu in two parts, such as
> kvm_mmu and kvm_guest_paging_context, and possibly change the walk_mmu
> pointer into a pointer to kvm_guest_paging_context. This way the
> EPT/NPT MMU (again either shadow or TDP) can be moved to kvm->arch. It
> should simplify this series and also David's work on eager page splitting.
>
> I'm not asking you to do this, of course, but perhaps I can trigger
> Sean's itch to refactor stuff. :)
>
> Paolo
>

I think that's a great idea. I'm frequently confused as to why the
struct kvm_mmu is a per-vcpu construct as opposed to being VM-global.
Moving part of the struct to be a member for struct kvm would also
open the door to formalizing the MMU interface a little better and
perhaps even reveal more MMU code that can be consolidated across
architectures.