Re: [PATCH 5/9] KVM: x86: Pull the PGD's level from the MMU instead of recalculating it

From: Sean Christopherson
Date: Fri Jul 31 2020 - 12:14:22 EST


On Wed, Jul 22, 2020 at 07:11:26PM +0200, Vitaly Kuznetsov wrote:
> Sean Christopherson <sean.j.christopherson@xxxxxxxxx> writes:
> > diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
> > index 4d561edf6f9ca..50b56622e16a6 100644
> > --- a/arch/x86/kvm/vmx/nested.c
> > +++ b/arch/x86/kvm/vmx/nested.c
> > @@ -2162,7 +2162,7 @@ static void prepare_vmcs02_constant_state(struct vcpu_vmx *vmx)
> > * consistency checks.
> > */
> > if (enable_ept && nested_early_check)
> > - vmcs_write64(EPT_POINTER, construct_eptp(&vmx->vcpu, 0));
> > + vmcs_write64(EPT_POINTER, construct_eptp(&vmx->vcpu, 0, 4));
>
> Nit: could we use MMU's PT64_ROOT_4LEVEL instead of '4' here?

My strategy of procrastinating until Paolo queued the series paid off.

Short answer, yes, that could be done. But to be consistent we'd want to
change vmx_get_max_tdp_level() and kvm_mmu_get_tdp_level() to also use
PT64_ROOT_4LEVEL and PT64_ROOT_5LEVEL, and for me at least that doesn't
improve readability.