All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jim Mattson <jmattson@google.com>
To: kvm@vger.kernel.org
Cc: Jim Mattson <jmattson@google.com>
Subject: [PATCH 2/8] kvm: nVMX: Refactor handle_vmon()
Date: Wed, 30 Nov 2016 12:03:43 -0800	[thread overview]
Message-ID: <1480536229-11754-3-git-send-email-jmattson@google.com> (raw)
In-Reply-To: <1480536229-11754-1-git-send-email-jmattson@google.com>

Handle_vmon is split into two parts: the part that handles the VMXON
instruction, and the part that modifies the vcpu state to transition
from legacy mode to VMX operation. The latter will be used when
restoring the checkpointed state of a vCPU that was in VMX operation
when a snapshot was taken.

Signed-off-by: Jim Mattson <jmattson@google.com>
---
 arch/x86/kvm/vmx.c | 91 ++++++++++++++++++++++++++++++------------------------
 1 file changed, 51 insertions(+), 40 deletions(-)

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 22c4a12..0169120 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -6974,6 +6974,53 @@ static int nested_vmx_check_vmptr(struct kvm_vcpu *vcpu, int exit_reason,
 	return 0;
 }
 
+static int enter_vmx_operation(struct kvm_vcpu *vcpu)
+{
+	struct vcpu_vmx *vmx = to_vmx(vcpu);
+	struct vmcs *shadow_vmcs;
+
+	if (cpu_has_vmx_msr_bitmap()) {
+		vmx->nested.msr_bitmap =
+				(unsigned long *)__get_free_page(GFP_KERNEL);
+		if (!vmx->nested.msr_bitmap)
+			goto out_msr_bitmap;
+	}
+
+	vmx->nested.cached_vmcs12 = kmalloc(VMCS12_SIZE, GFP_KERNEL);
+	if (!vmx->nested.cached_vmcs12)
+		goto out_cached_vmcs12;
+
+	if (enable_shadow_vmcs) {
+		shadow_vmcs = alloc_vmcs();
+		if (!shadow_vmcs)
+			goto out_shadow_vmcs;
+		/* mark vmcs as shadow */
+		shadow_vmcs->revision_id |= (1u << 31);
+		/* init shadow vmcs */
+		vmcs_clear(shadow_vmcs);
+		vmx->vmcs01.shadow_vmcs = shadow_vmcs;
+	}
+
+	INIT_LIST_HEAD(&(vmx->nested.vmcs02_pool));
+	vmx->nested.vmcs02_num = 0;
+
+	hrtimer_init(&vmx->nested.preemption_timer, CLOCK_MONOTONIC,
+		     HRTIMER_MODE_REL_PINNED);
+	vmx->nested.preemption_timer.function = vmx_preemption_timer_fn;
+
+	vmx->nested.vmxon = true;
+	return 0;
+
+out_shadow_vmcs:
+	kfree(vmx->nested.cached_vmcs12);
+
+out_cached_vmcs12:
+	free_page((unsigned long)vmx->nested.msr_bitmap);
+
+out_msr_bitmap:
+	return -ENOMEM;
+}
+
 /*
  * Emulate the VMXON instruction.
  * Currently, we just remember that VMX is active, and do not save or even
@@ -6984,9 +7031,9 @@ static int nested_vmx_check_vmptr(struct kvm_vcpu *vcpu, int exit_reason,
  */
 static int handle_vmon(struct kvm_vcpu *vcpu)
 {
+	int ret;
 	struct kvm_segment cs;
 	struct vcpu_vmx *vmx = to_vmx(vcpu);
-	struct vmcs *shadow_vmcs;
 	const u64 VMXON_NEEDED_FEATURES = FEATURE_CONTROL_LOCKED
 		| FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX;
 
@@ -7028,49 +7075,13 @@ static int handle_vmon(struct kvm_vcpu *vcpu)
 		return 1;
 	}
 
-	if (cpu_has_vmx_msr_bitmap()) {
-		vmx->nested.msr_bitmap =
-				(unsigned long *)__get_free_page(GFP_KERNEL);
-		if (!vmx->nested.msr_bitmap)
-			goto out_msr_bitmap;
-	}
-
-	vmx->nested.cached_vmcs12 = kmalloc(VMCS12_SIZE, GFP_KERNEL);
-	if (!vmx->nested.cached_vmcs12)
-		goto out_cached_vmcs12;
-
-	if (enable_shadow_vmcs) {
-		shadow_vmcs = alloc_vmcs();
-		if (!shadow_vmcs)
-			goto out_shadow_vmcs;
-		/* mark vmcs as shadow */
-		shadow_vmcs->revision_id |= (1u << 31);
-		/* init shadow vmcs */
-		vmcs_clear(shadow_vmcs);
-		vmx->vmcs01.shadow_vmcs = shadow_vmcs;
-	}
-
-	INIT_LIST_HEAD(&(vmx->nested.vmcs02_pool));
-	vmx->nested.vmcs02_num = 0;
-
-	hrtimer_init(&vmx->nested.preemption_timer, CLOCK_MONOTONIC,
-		     HRTIMER_MODE_REL_PINNED);
-	vmx->nested.preemption_timer.function = vmx_preemption_timer_fn;
-
-	vmx->nested.vmxon = true;
+	ret = enter_vmx_operation(vcpu);
+	if (ret)
+		return ret;
 
 	skip_emulated_instruction(vcpu);
 	nested_vmx_succeed(vcpu);
 	return 1;
-
-out_shadow_vmcs:
-	kfree(vmx->nested.cached_vmcs12);
-
-out_cached_vmcs12:
-	free_page((unsigned long)vmx->nested.msr_bitmap);
-
-out_msr_bitmap:
-	return -ENOMEM;
 }
 
 /*
-- 
2.8.0.rc3.226.g39d4020


  parent reply	other threads:[~2016-11-30 20:04 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-30 20:03 [PATCH 0/8] kvm: nVMX: Checkpoint/restore support for VMX state Jim Mattson
2016-11-30 20:03 ` [PATCH 1/8] kvm: nVMX: Prepare for checkpointing L2 state Jim Mattson
2016-11-30 20:03 ` Jim Mattson [this message]
2016-11-30 20:03 ` [PATCH 3/8] kvm: nVMX: Refactor handle_vmptrld() Jim Mattson
2016-11-30 20:03 ` [PATCH 4/8] kvm: nVMX: Refactor nested_get_vmcs12_pages() Jim Mattson
2016-11-30 20:03 ` [PATCH 5/8] kvm: nVMX: Split VMCS checks from nested_vmx_run() Jim Mattson
2016-11-30 20:03 ` [PATCH 6/8] kvm: nVMX: Refactor nested_vmx_run() Jim Mattson
2016-11-30 20:03 ` [PATCH 7/8] kvm: nVMX: Introduce KVM_CAP_VMX_STATE Jim Mattson
2016-12-09 15:26   ` Paolo Bonzini
2016-12-09 15:55     ` David Hildenbrand
2016-12-09 19:26       ` Paolo Bonzini
2016-12-12 14:14         ` David Hildenbrand
2017-02-15 11:56     ` Paolo Bonzini
2017-02-15 16:06       ` Jim Mattson
2017-02-15 16:14         ` Paolo Bonzini
2017-02-15 16:58           ` Jim Mattson
2017-02-15 17:37             ` Paolo Bonzini
2017-02-15 18:19               ` Jim Mattson
2017-02-15 21:28                 ` Paolo Bonzini
2017-12-19  3:07                   ` Jim Mattson
2017-12-19 10:35                     ` David Hildenbrand
2017-12-19 17:26                       ` Jim Mattson
2017-12-19 17:33                         ` David Hildenbrand
2017-12-19 17:40                           ` David Hildenbrand
2017-12-19 19:21                             ` Jim Mattson
2017-12-19 19:52                               ` David Hildenbrand
2017-12-19 21:29                               ` Paolo Bonzini
2018-01-08 10:35                                 ` David Hildenbrand
2018-01-08 17:25                                   ` Jim Mattson
2018-01-08 17:36                                     ` Paolo Bonzini
2018-01-08 17:59                                       ` David Hildenbrand
2018-01-08 18:11                                         ` Paolo Bonzini
2018-01-08 18:23                                           ` David Hildenbrand
2018-01-08 20:19                                             ` Jim Mattson
2018-01-08 20:27                                               ` David Hildenbrand
2018-01-08 20:59                                                 ` Jim Mattson
2018-01-08 21:19                                                   ` David Hildenbrand
2018-01-08 21:40                                                     ` Jim Mattson
2018-01-08 21:46                                                       ` David Hildenbrand
2018-01-08 21:55                                                         ` Jim Mattson
2018-01-09  8:19                                                           ` David Hildenbrand
2018-01-08 18:17                                         ` Jim Mattson
2017-12-19 12:45                     ` Paolo Bonzini
2016-11-30 20:03 ` [PATCH 8/8] kvm: nVMX: Defer gpa->hpa lookups for set_vmx_state Jim Mattson
2016-12-09 15:35   ` Paolo Bonzini
2016-12-09 16:26     ` Jim Mattson
2016-12-10  7:48       ` Paolo Bonzini
2016-12-06  9:04 ` [PATCH 0/8] kvm: nVMX: Checkpoint/restore support for VMX state David Hildenbrand
2016-12-06 19:02   ` Jim Mattson
2016-12-09 15:28     ` Paolo Bonzini
2016-12-09 16:16       ` Jim Mattson
2016-12-09 19:15         ` Paolo Bonzini
2017-02-15 19:30           ` Jim Mattson
2017-02-15 21:26             ` Paolo Bonzini
2017-02-15 22:00               ` Jim Mattson
2017-02-15 22:05                 ` Paolo Bonzini
2017-02-15 22:49                   ` Jim Mattson
2017-02-15 23:09                     ` Paolo Bonzini
2017-02-08 16:24 ` Paolo Bonzini
2017-02-14 22:17   ` Jim Mattson
2017-02-15 10:15     ` Paolo Bonzini
2017-02-15 17:02       ` Jim Mattson
2017-02-15 17:31         ` Paolo Bonzini

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=1480536229-11754-3-git-send-email-jmattson@google.com \
    --to=jmattson@google.com \
    --cc=kvm@vger.kernel.org \
    /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.