Skip to content

Commit 9f744c5

Browse files
bonzinirkrcmar
authored andcommitted
KVM: nVMX: do not pin the VMCS12
Since the current implementation of VMCS12 does a memcpy in and out of guest memory, we do not need current_vmcs12 and current_vmcs12_page anymore. current_vmptr is enough to read and write the VMCS12. And David Matlack noted: This patch also fixes dirty tracking (memslot->dirty_bitmap) of the VMCS12 page by using kvm_write_guest. nested_release_page() only marks the struct page dirty. Signed-off-by: Paolo Bonzini <[email protected]> Reviewed-by: David Hildenbrand <[email protected]> [Added David Matlack's note and nested_release_page_clean() fix.] Signed-off-by: Radim Krčmář <[email protected]>
1 parent 3898da9 commit 9f744c5

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

arch/x86/kvm/vmx.c

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -416,9 +416,6 @@ struct nested_vmx {
416416

417417
/* The guest-physical address of the current VMCS L1 keeps for L2 */
418418
gpa_t current_vmptr;
419-
/* The host-usable pointer to the above */
420-
struct page *current_vmcs12_page;
421-
struct vmcs12 *current_vmcs12;
422419
/*
423420
* Cache of the guest's VMCS, existing outside of guest memory.
424421
* Loaded from guest memory during VMPTRLD. Flushed to guest
@@ -7182,10 +7179,6 @@ static inline void nested_release_vmcs12(struct vcpu_vmx *vmx)
71827179
if (vmx->nested.current_vmptr == -1ull)
71837180
return;
71847181

7185-
/* current_vmptr and current_vmcs12 are always set/reset together */
7186-
if (WARN_ON(vmx->nested.current_vmcs12 == NULL))
7187-
return;
7188-
71897182
if (enable_shadow_vmcs) {
71907183
/* copy to memory all shadowed fields in case
71917184
they were modified */
@@ -7198,13 +7191,11 @@ static inline void nested_release_vmcs12(struct vcpu_vmx *vmx)
71987191
vmx->nested.posted_intr_nv = -1;
71997192

72007193
/* Flush VMCS12 to guest memory */
7201-
memcpy(vmx->nested.current_vmcs12, vmx->nested.cached_vmcs12,
7202-
VMCS12_SIZE);
7194+
kvm_vcpu_write_guest_page(&vmx->vcpu,
7195+
vmx->nested.current_vmptr >> PAGE_SHIFT,
7196+
vmx->nested.cached_vmcs12, 0, VMCS12_SIZE);
72037197

7204-
kunmap(vmx->nested.current_vmcs12_page);
7205-
nested_release_page(vmx->nested.current_vmcs12_page);
72067198
vmx->nested.current_vmptr = -1ull;
7207-
vmx->nested.current_vmcs12 = NULL;
72087199
}
72097200

72107201
/*
@@ -7622,14 +7613,14 @@ static int handle_vmptrld(struct kvm_vcpu *vcpu)
76227613
}
76237614

76247615
nested_release_vmcs12(vmx);
7625-
vmx->nested.current_vmcs12 = new_vmcs12;
7626-
vmx->nested.current_vmcs12_page = page;
76277616
/*
76287617
* Load VMCS12 from guest memory since it is not already
76297618
* cached.
76307619
*/
7631-
memcpy(vmx->nested.cached_vmcs12,
7632-
vmx->nested.current_vmcs12, VMCS12_SIZE);
7620+
memcpy(vmx->nested.cached_vmcs12, new_vmcs12, VMCS12_SIZE);
7621+
kunmap(page);
7622+
nested_release_page_clean(page);
7623+
76337624
set_current_vmptr(vmx, vmptr);
76347625
}
76357626

@@ -9284,7 +9275,6 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id)
92849275

92859276
vmx->nested.posted_intr_nv = -1;
92869277
vmx->nested.current_vmptr = -1ull;
9287-
vmx->nested.current_vmcs12 = NULL;
92889278

92899279
vmx->msr_ia32_feature_control_valid_bits = FEATURE_CONTROL_LOCKED;
92909280

0 commit comments

Comments
 (0)