Alexander Graf 4829c2
From: David Hildenbrand <david@redhat.com>
Alexander Graf 4829c2
Date: Thu, 24 Aug 2017 20:51:34 +0200
Alexander Graf 4829c2
Subject: KVM: VMX: cleanup init_rmode_identity_map()
Alexander Graf 4829c2
MIME-Version: 1.0
Alexander Graf 4829c2
Content-Type: text/plain; charset=UTF-8
Alexander Graf 4829c2
Content-Transfer-Encoding: 8bit
Alexander Graf 4829c2
Patch-mainline: v4.15-rc1
Alexander Graf 4829c2
Git-commit: d8a6e365b208a36f9e789ee50c55096b71367431
Alexander Graf 4829c2
References: bsc#1077761
Alexander Graf 4829c2
Alexander Graf 4829c2
No need for another enable_ept check. kvm->arch.ept_identity_map_addr
Alexander Graf 4829c2
only has to be inititalized once. Having alloc_identity_pagetable() is
Alexander Graf 4829c2
overkill and dropping BUG_ONs is always nice.
Alexander Graf 4829c2
Alexander Graf 4829c2
Reviewed-by: Radim Krčmář <rkrcmar@redhat.com>
Alexander Graf 4829c2
Signed-off-by: David Hildenbrand <david@redhat.com>
Alexander Graf 4829c2
Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
Alexander Graf 4829c2
Acked-by: Alexander Graf <agraf@suse.de>
Alexander Graf 4829c2
---
Alexander Graf 4829c2
 arch/x86/kvm/vmx.c |   26 ++++----------------------
Alexander Graf 4829c2
 1 file changed, 4 insertions(+), 22 deletions(-)
Alexander Graf 4829c2
Alexander Graf 4829c2
--- a/arch/x86/kvm/vmx.c
Alexander Graf 4829c2
+++ b/arch/x86/kvm/vmx.c
Alexander Graf 4829c2
@@ -904,7 +904,6 @@
Alexander Graf 4829c2
 static bool guest_state_valid(struct kvm_vcpu *vcpu);
Alexander Graf 4829c2
 static u32 vmx_segment_access_rights(struct kvm_segment *var);
Alexander Graf 4829c2
 static void copy_shadow_to_vmcs12(struct vcpu_vmx *vmx);
Alexander Graf 4829c2
-static int alloc_identity_pagetable(struct kvm *kvm);
Alexander Graf 4829c2
 static bool vmx_get_nmi_mask(struct kvm_vcpu *vcpu);
Alexander Graf 4829c2
 static void vmx_set_nmi_mask(struct kvm_vcpu *vcpu, bool masked);
Alexander Graf 4829c2
 static bool nested_vmx_is_page_fault_vmexit(struct vmcs12 *vmcs12,
Alexander Graf 4829c2
@@ -4772,18 +4771,18 @@
Alexander Graf 4829c2
 	kvm_pfn_t identity_map_pfn;
Alexander Graf 4829c2
 	u32 tmp;
Alexander Graf 4829c2
 
Alexander Graf 4829c2
-	if (!enable_ept)
Alexander Graf 4829c2
-		return 0;
Alexander Graf 4829c2
-
Alexander Graf 4829c2
 	/* Protect kvm->arch.ept_identity_pagetable_done. */
Alexander Graf 4829c2
 	mutex_lock(&kvm->slots_lock);
Alexander Graf 4829c2
 
Alexander Graf 4829c2
 	if (likely(kvm->arch.ept_identity_pagetable_done))
Alexander Graf 4829c2
 		goto out2;
Alexander Graf 4829c2
 
Alexander Graf 4829c2
+	if (!kvm->arch.ept_identity_map_addr)
Alexander Graf 4829c2
+		kvm->arch.ept_identity_map_addr = VMX_EPT_IDENTITY_PAGETABLE_ADDR;
Alexander Graf 4829c2
 	identity_map_pfn = kvm->arch.ept_identity_map_addr >> PAGE_SHIFT;
Alexander Graf 4829c2
 
Alexander Graf 4829c2
-	r = alloc_identity_pagetable(kvm);
Alexander Graf 4829c2
+	r = __x86_set_memory_region(kvm, IDENTITY_PAGETABLE_PRIVATE_MEMSLOT,
Alexander Graf 4829c2
+				    kvm->arch.ept_identity_map_addr, PAGE_SIZE);
Alexander Graf 4829c2
 	if (r < 0)
Alexander Graf 4829c2
 		goto out2;
Alexander Graf 4829c2
 
Alexander Graf 4829c2
@@ -4855,20 +4854,6 @@
Alexander Graf 4829c2
 	return r;
Alexander Graf 4829c2
 }
Alexander Graf 4829c2
 
Alexander Graf 4829c2
-static int alloc_identity_pagetable(struct kvm *kvm)
Alexander Graf 4829c2
-{
Alexander Graf 4829c2
-	/* Called with kvm->slots_lock held. */
Alexander Graf 4829c2
-
Alexander Graf 4829c2
-	int r = 0;
Alexander Graf 4829c2
-
Alexander Graf 4829c2
-	BUG_ON(kvm->arch.ept_identity_pagetable_done);
Alexander Graf 4829c2
-
Alexander Graf 4829c2
-	r = __x86_set_memory_region(kvm, IDENTITY_PAGETABLE_PRIVATE_MEMSLOT,
Alexander Graf 4829c2
-				    kvm->arch.ept_identity_map_addr, PAGE_SIZE);
Alexander Graf 4829c2
-
Alexander Graf 4829c2
-	return r;
Alexander Graf 4829c2
-}
Alexander Graf 4829c2
-
Alexander Graf 4829c2
 static int allocate_vpid(void)
Alexander Graf 4829c2
 {
Alexander Graf 4829c2
 	int vpid;
Alexander Graf 4829c2
@@ -9546,9 +9531,6 @@
Alexander Graf 4829c2
 	}
Alexander Graf 4829c2
 
Alexander Graf 4829c2
 	if (enable_ept) {
Alexander Graf 4829c2
-		if (!kvm->arch.ept_identity_map_addr)
Alexander Graf 4829c2
-			kvm->arch.ept_identity_map_addr =
Alexander Graf 4829c2
-				VMX_EPT_IDENTITY_PAGETABLE_ADDR;
Alexander Graf 4829c2
 		err = init_rmode_identity_map(kvm);
Alexander Graf 4829c2
 		if (err)
Alexander Graf 4829c2
 			goto free_vmcs;