All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: kvm@vger.kernel.org
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
	"Radim Krčmář" <rkrcmar@redhat.com>,
	david@redhat.com
Subject: [PATCH v2 12/15] KVM: VMX: cleanup init_rmode_identity_map()
Date: Thu, 24 Aug 2017 20:51:34 +0200	[thread overview]
Message-ID: <20170824185137.6253-13-david@redhat.com> (raw)
In-Reply-To: <20170824185137.6253-1-david@redhat.com>

No need for another enable_ept check. kvm->arch.ept_identity_map_addr
only has to be inititalized once. Having alloc_identity_pagetable() is
overkill and dropping BUG_ONs is always nice.

Reviewed-by: Radim Krčmář <rkrcmar@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 arch/x86/kvm/vmx.c | 26 ++++----------------------
 1 file changed, 4 insertions(+), 22 deletions(-)

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index f96755762fcc..5625a99aff7a 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -905,7 +905,6 @@ static void vmx_get_segment(struct kvm_vcpu *vcpu,
 static bool guest_state_valid(struct kvm_vcpu *vcpu);
 static u32 vmx_segment_access_rights(struct kvm_segment *var);
 static void copy_shadow_to_vmcs12(struct vcpu_vmx *vmx);
-static int alloc_identity_pagetable(struct kvm *kvm);
 static bool vmx_get_nmi_mask(struct kvm_vcpu *vcpu);
 static void vmx_set_nmi_mask(struct kvm_vcpu *vcpu, bool masked);
 static bool nested_vmx_is_page_fault_vmexit(struct vmcs12 *vmcs12,
@@ -4769,18 +4768,18 @@ static int init_rmode_identity_map(struct kvm *kvm)
 	kvm_pfn_t identity_map_pfn;
 	u32 tmp;
 
-	if (!enable_ept)
-		return 0;
-
 	/* Protect kvm->arch.ept_identity_pagetable_done. */
 	mutex_lock(&kvm->slots_lock);
 
 	if (likely(kvm->arch.ept_identity_pagetable_done))
 		goto out2;
 
+	if (!kvm->arch.ept_identity_map_addr)
+		kvm->arch.ept_identity_map_addr = VMX_EPT_IDENTITY_PAGETABLE_ADDR;
 	identity_map_pfn = kvm->arch.ept_identity_map_addr >> PAGE_SHIFT;
 
-	r = alloc_identity_pagetable(kvm);
+	r = __x86_set_memory_region(kvm, IDENTITY_PAGETABLE_PRIVATE_MEMSLOT,
+				    kvm->arch.ept_identity_map_addr, PAGE_SIZE);
 	if (r < 0)
 		goto out2;
 
@@ -4852,20 +4851,6 @@ static int alloc_apic_access_page(struct kvm *kvm)
 	return r;
 }
 
-static int alloc_identity_pagetable(struct kvm *kvm)
-{
-	/* Called with kvm->slots_lock held. */
-
-	int r = 0;
-
-	BUG_ON(kvm->arch.ept_identity_pagetable_done);
-
-	r = __x86_set_memory_region(kvm, IDENTITY_PAGETABLE_PRIVATE_MEMSLOT,
-				    kvm->arch.ept_identity_map_addr, PAGE_SIZE);
-
-	return r;
-}
-
 static int allocate_vpid(void)
 {
 	int vpid;
@@ -9461,9 +9446,6 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id)
 	}
 
 	if (enable_ept) {
-		if (!kvm->arch.ept_identity_map_addr)
-			kvm->arch.ept_identity_map_addr =
-				VMX_EPT_IDENTITY_PAGETABLE_ADDR;
 		err = init_rmode_identity_map(kvm);
 		if (err)
 			goto free_vmcs;
-- 
2.13.5

  parent reply	other threads:[~2017-08-24 18:52 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-24 18:51 [PATCH v2 00/15] KVM x86/VMX cleanups David Hildenbrand
2017-08-24 18:51 ` [PATCH v2 01/15] KVM: x86: mmu: returning void in a void function is strange David Hildenbrand
2017-08-24 18:51 ` [PATCH v2 02/15] KVM: x86: mmu: free_page can handle NULL David Hildenbrand
2017-08-24 18:51 ` [PATCH v2 03/15] KVM: x86: drop BUG_ON(vcpu->kvm) David Hildenbrand
2017-08-24 18:51 ` [PATCH v2 04/15] KVM: VMX: vmx_vcpu_setup() cannot fail David Hildenbrand
2017-08-24 18:51 ` [PATCH v2 05/15] KVM: x86: no need to inititalize vcpu members to 0 David Hildenbrand
2017-08-24 18:51 ` [PATCH v2 06/15] KVM: VMX: drop enable_ept check from ept_sync_context() David Hildenbrand
2017-08-24 18:51 ` [PATCH v2 07/15] KVM: VMX: call ept_sync_global() with enable_ept only David Hildenbrand
2017-08-24 18:51 ` [PATCH v2 08/15] KVM: VMX: require INVEPT GLOBAL for EPT David Hildenbrand
2017-08-24 18:51 ` [PATCH v2 09/15] KVM: VMX: drop unnecessary function declarations David Hildenbrand
2017-08-24 18:51 ` [PATCH v2 10/15] KVM: nVMX: no need to set vcpu->cpu when switching vmcs David Hildenbrand
2017-08-24 18:51 ` [PATCH v2 11/15] KVM: nVMX: no need to set ept/vpid caps to 0 David Hildenbrand
2017-08-24 18:51 ` David Hildenbrand [this message]
2017-08-24 18:51 ` [PATCH v2 13/15] KVM: x86: document special identity map address value David Hildenbrand
2017-08-24 18:51 ` [PATCH v2 14/15] KVM: x86: allow setting identity map addr with no vcpus only David Hildenbrand
2017-08-24 18:51 ` [PATCH v2 15/15] KVM: VMX: rename RDSEED and RDRAND vmx ctrls to reflect exiting David Hildenbrand
2017-08-24 20:39   ` Jim Mattson
2017-08-28 14:55     ` David Hildenbrand
2017-08-28 15:50       ` Jim Mattson
2017-09-19 12:42 ` [PATCH v2 00/15] KVM x86/VMX cleanups David Hildenbrand
2017-09-19 12:57   ` Paolo Bonzini
2017-10-06 18:11 ` Radim Krčmář

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170824185137.6253-13-david@redhat.com \
    --to=david@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=rkrcmar@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.