@@ -8423,8 +8423,10 @@ static void vmx_disable_shadow_vmcs(struct vcpu_vmx *vmx)
84238423 vmcs_write64 (VMCS_LINK_POINTER , -1ull );
84248424}
84258425
8426- static inline void nested_release_vmcs12 (struct vcpu_vmx * vmx )
8426+ static inline void nested_release_vmcs12 (struct kvm_vcpu * vcpu )
84278427{
8428+ struct vcpu_vmx * vmx = to_vmx (vcpu );
8429+
84288430 if (vmx -> nested .current_vmptr == -1ull )
84298431 return ;
84308432
@@ -8438,19 +8440,23 @@ static inline void nested_release_vmcs12(struct vcpu_vmx *vmx)
84388440 vmx -> nested .posted_intr_nv = -1 ;
84398441
84408442 /* Flush VMCS12 to guest memory */
8441- kvm_vcpu_write_guest_page (& vmx -> vcpu ,
8443+ kvm_vcpu_write_guest_page (vcpu ,
84428444 vmx -> nested .current_vmptr >> PAGE_SHIFT ,
84438445 vmx -> nested .cached_vmcs12 , 0 , VMCS12_SIZE );
84448446
8447+ kvm_mmu_free_roots (vcpu , & vcpu -> arch .guest_mmu , KVM_MMU_ROOTS_ALL );
8448+
84458449 vmx -> nested .current_vmptr = -1ull ;
84468450}
84478451
84488452/*
84498453 * Free whatever needs to be freed from vmx->nested when L1 goes down, or
84508454 * just stops using VMX.
84518455 */
8452- static void free_nested (struct vcpu_vmx * vmx )
8456+ static void free_nested (struct kvm_vcpu * vcpu )
84538457{
8458+ struct vcpu_vmx * vmx = to_vmx (vcpu );
8459+
84548460 if (!vmx -> nested .vmxon && !vmx -> nested .smm .vmxon )
84558461 return ;
84568462
@@ -8483,6 +8489,8 @@ static void free_nested(struct vcpu_vmx *vmx)
84838489 vmx -> nested .pi_desc = NULL ;
84848490 }
84858491
8492+ kvm_mmu_free_roots (vcpu , & vcpu -> arch .guest_mmu , KVM_MMU_ROOTS_ALL );
8493+
84868494 free_loaded_vmcs (& vmx -> nested .vmcs02 );
84878495}
84888496
@@ -8491,7 +8499,7 @@ static int handle_vmoff(struct kvm_vcpu *vcpu)
84918499{
84928500 if (!nested_vmx_check_permission (vcpu ))
84938501 return 1 ;
8494- free_nested (to_vmx ( vcpu ) );
8502+ free_nested (vcpu );
84958503 return nested_vmx_succeed (vcpu );
84968504}
84978505
@@ -8517,7 +8525,7 @@ static int handle_vmclear(struct kvm_vcpu *vcpu)
85178525 VMXERR_VMCLEAR_VMXON_POINTER );
85188526
85198527 if (vmptr == vmx -> nested .current_vmptr )
8520- nested_release_vmcs12 (vmx );
8528+ nested_release_vmcs12 (vcpu );
85218529
85228530 kvm_vcpu_write_guest (vcpu ,
85238531 vmptr + offsetof(struct vmcs12 , launch_state ),
@@ -8872,7 +8880,8 @@ static int handle_vmptrld(struct kvm_vcpu *vcpu)
88728880 VMXERR_VMPTRLD_INCORRECT_VMCS_REVISION_ID );
88738881 }
88748882
8875- nested_release_vmcs12 (vmx );
8883+ nested_release_vmcs12 (vcpu );
8884+
88768885 /*
88778886 * Load VMCS12 from guest memory since it is not already
88788887 * cached.
@@ -10928,12 +10937,10 @@ static void vmx_switch_vmcs(struct kvm_vcpu *vcpu, struct loaded_vmcs *vmcs)
1092810937 */
1092910938static void vmx_free_vcpu_nested (struct kvm_vcpu * vcpu )
1093010939{
10931- struct vcpu_vmx * vmx = to_vmx (vcpu );
10932-
10933- vcpu_load (vcpu );
10934- vmx_switch_vmcs (vcpu , & vmx -> vmcs01 );
10935- free_nested (vmx );
10936- vcpu_put (vcpu );
10940+ vcpu_load (vcpu );
10941+ vmx_switch_vmcs (vcpu , & to_vmx (vcpu )-> vmcs01 );
10942+ free_nested (vcpu );
10943+ vcpu_put (vcpu );
1093710944}
1093810945
1093910946static void vmx_free_vcpu (struct kvm_vcpu * vcpu )
@@ -11300,6 +11307,7 @@ static void nested_ept_init_mmu_context(struct kvm_vcpu *vcpu)
1130011307{
1130111308 WARN_ON (mmu_is_nested (vcpu ));
1130211309
11310+ vcpu -> arch .mmu = & vcpu -> arch .guest_mmu ;
1130311311 kvm_init_shadow_ept_mmu (vcpu ,
1130411312 to_vmx (vcpu )-> nested .msrs .ept_caps &
1130511313 VMX_EPT_EXECUTE_ONLY_BIT ,
@@ -11315,6 +11323,7 @@ static void nested_ept_init_mmu_context(struct kvm_vcpu *vcpu)
1131511323
1131611324static void nested_ept_uninit_mmu_context (struct kvm_vcpu * vcpu )
1131711325{
11326+ vcpu -> arch .mmu = & vcpu -> arch .root_mmu ;
1131811327 vcpu -> arch .walk_mmu = & vcpu -> arch .root_mmu ;
1131911328}
1132011329
@@ -13731,7 +13740,7 @@ static void vmx_leave_nested(struct kvm_vcpu *vcpu)
1373113740 to_vmx (vcpu )-> nested .nested_run_pending = 0 ;
1373213741 nested_vmx_vmexit (vcpu , -1 , 0 , 0 );
1373313742 }
13734- free_nested (to_vmx ( vcpu ) );
13743+ free_nested (vcpu );
1373513744}
1373613745
1373713746static int vmx_check_intercept (struct kvm_vcpu * vcpu ,
0 commit comments