KVM: x86/mmu: Don't freak out if pml5_root is NULL on 4-level host
authorSean Christopherson <seanjc@google.com>
Tue, 24 Aug 2021 00:58:24 +0000 (17:58 -0700)
committerPaolo Bonzini <pbonzini@redhat.com>
Mon, 6 Sep 2021 09:56:38 +0000 (05:56 -0400)
commita717a780fc4e1dddd3fbf9ad08f180eec2a78194
tree7eeb7a6e4ffb8e8686152dcb91d1ff88f4721a11
parent43e540cc9f2ca12a2364ddf64e5ef929a546550d
KVM: x86/mmu: Don't freak out if pml5_root is NULL on 4-level host

Include pml5_root in the set of special roots if and only if the host,
and thus NPT, is using 5-level paging.  mmu_alloc_special_roots() expects
special roots to be allocated as a bundle, i.e. they're either all valid
or all NULL.  But for pml5_root, that expectation only holds true if the
host uses 5-level paging, which causes KVM to WARN about pml5_root being
NULL when the other special roots are valid.

The silver lining of 4-level vs. 5-level NPT being tied to the host
kernel's paging level is that KVM's shadow root level is constant; unlike
VMX's EPT, KVM can't choose 4-level NPT based on guest.MAXPHYADDR.  That
means KVM can still expect pml5_root to be bundled with the other special
roots, it just needs to be conditioned on the shadow root level.

Fixes: cb0f722aff6e ("KVM: x86/mmu: Support shadowing NPT when 5-level paging is enabled in host")
Reported-by: Maxim Levitsky <mlevitsk@redhat.com>
Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
Message-Id: <20210824005824.205536-1-seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/mmu/mmu.c