kvm: Nested KVM MMUs need PAE root too
Vitaly Kuznetsov
Reviewed-byQuoted 1 line · Jiří Paleček
Your Subject line needs to be 'PATCH v2' as you're sending an updated version.
Quoted 16 lines
On AMD processors, in PAE 32bit mode, nested KVM instances don't work. The L0 host get a kernel OOPS, which is related to
arch.mmu->pae_rootbeing NULL.The reason for this is that when running nested KVM instance, arch.mmu is set to &arch.guest_mmu (while normally, it would be &arch.root_mmu). However, the initialization and allocation of
pae_rootonly creates it inroot_mmu. KVM code (ie. inmmu_alloc_shadow_roots) then accessesarch.mmu->pae_root, which is the unallocatedarch.guest_mmu->pae_root.This fix just allocates (and frees)
pae_rootin bothguest_mmuandroot_mmu(and alsolm_rootif it was allocated). The allocation is subject to previous restrictions ie. it won't allocate anything on 64-bit and AFAIK not on Intel.
Quoted 5 lines
See https://bugzilla.kernel.org/show_bug.cgi?id=203923 for details.
Fixes 14c07ad89f4d ("x86/kvm/mmu: introduce guest_mmu")Signed-off-by Jiri Palecek <[email protected]>Tested-by Jiri Palecek <[email protected]>
Well, this was commented on in v1 :-)
Quoted 75 lines
--- arch/x86/kvm/mmu.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-)arch/x86/kvm/mmu.c +19
-9@@ -5592,13 +5592,13 @@ slot_handle_leaf(struct kvm *kvm, struct kvm_memory_slot *memslot, PT_PAGE_TABLE_LEVEL, lock_flush_tlb); } -static void free_mmu_pages (struct kvm_vcpu *vcpu) +static void free_mmu_pages (struct kvm_mmu *mmu) { -free_page ((unsigned long )vcpu->arch.mmu->pae_root); -free_page ((unsigned long )vcpu->arch.mmu->lm_root); +free_page ((unsigned long )mmu->pae_root); +free_page ((unsigned long )mmu->lm_root); } -static int alloc_mmu_pages (struct kvm_vcpu *vcpu) +static int alloc_mmu_pages (struct kvm_vcpu *vcpu,struct kvm_mmu *mmu) {struct page *page;int i;@@ -5619,9 +5619,9 @@ static int alloc_mmu_pages(struct kvm_vcpu *vcpu)if (!page)return -ENOMEM ; - vcpu->arch.mmu->pae_root =page_address (page); + mmu->pae_root =page_address (page);for (i =0 ; i <4 ; ++i) - vcpu->arch.mmu->pae_root[i] =INVALID_PAGE ; + mmu->pae_root[i] =INVALID_PAGE ;return 0 ; }@@ -5629,6 +5629,7 @@ static int alloc_mmu_pages(struct kvm_vcpu *vcpu)int kvm_mmu_create (struct kvm_vcpu *vcpu) {uint i; +int ret; vcpu->arch.mmu = &vcpu->arch.root_mmu; vcpu->arch.walk_mmu = &vcpu->arch.root_mmu;@@ -5646,7 +5647,16 @@ int kvm_mmu_create(struct kvm_vcpu *vcpu) vcpu->arch.guest_mmu.prev_roots[i] =KVM_MMU_ROOT_INFO_INVALID ; vcpu->arch.nested_mmu.translate_gpa = translate_nested_gpa; -return alloc_mmu_pages (vcpu); + + ret =alloc_mmu_pages (vcpu, &vcpu->arch.guest_mmu); +if (ret) +return ret; + + ret =alloc_mmu_pages (vcpu, &vcpu->arch.root_mmu); +if (ret) +free_mmu_pages (&vcpu->arch.guest_mmu); + +return ret; } static void kvm_mmu_invalidate_zap_pages_in_memslot(struct kvm *kvm,@@ -6102,7 +6112,8 @@ unsigned long kvm_mmu_calculate_default_mmu_pages(struct kvm *kvm)void kvm_mmu_destroy (struct kvm_vcpu *vcpu) {kvm_mmu_unload (vcpu); -free_mmu_pages (vcpu); +free_mmu_pages (&vcpu->arch.root_mmu); +free_mmu_pages (&vcpu->arch.guest_mmu);mmu_free_memory_caches (vcpu); } --
Quoted 2 lines
2.23.0.rc1
Signature · 1 line
Vitaly
Quoted 4 lines · Vitaly Kuznetsov
Jiří Paleček <[email protected]> writes:
Your Subject line needs to be 'PATCH v2' as you're sending an updated version.
Yes, I wanted to make it v1.1 but forgot. Sorry
Regards
Jiri Palecek