public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: kvm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 17/47] KVM: SVM: move nested svm state into seperate struct
Date: Wed, 26 Aug 2009 13:29:39 +0300	[thread overview]
Message-ID: <1251282609-12835-18-git-send-email-avi@redhat.com> (raw)
In-Reply-To: <1251282609-12835-1-git-send-email-avi@redhat.com>

From: Joerg Roedel <joerg.roedel@amd.com>

This makes it more clear for which purpose these members in the vcpu_svm
exist.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Acked-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Avi Kivity <avi@redhat.com>
---
 arch/x86/kvm/svm.c |   62 +++++++++++++++++++++++++++------------------------
 1 files changed, 33 insertions(+), 29 deletions(-)

diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index 825b825..fbadaa7 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -70,6 +70,18 @@ static const u32 host_save_user_msrs[] = {
 
 struct kvm_vcpu;
 
+struct nested_state {
+	struct vmcb *hsave;
+	u64 hsave_msr;
+	u64 vmcb;
+
+	/* These are the merged vectors */
+	u32 *msrpm;
+
+	/* gpa pointers to the real vectors */
+	u64 vmcb_msrpm;
+};
+
 struct vcpu_svm {
 	struct kvm_vcpu vcpu;
 	struct vmcb *vmcb;
@@ -85,16 +97,8 @@ struct vcpu_svm {
 	u64 host_gs_base;
 
 	u32 *msrpm;
-	struct vmcb *hsave;
-	u64 hsave_msr;
-
-	u64 nested_vmcb;
 
-	/* These are the merged vectors */
-	u32 *nested_msrpm;
-
-	/* gpa pointers to the real vectors */
-	u64 nested_vmcb_msrpm;
+	struct nested_state nested;
 };
 
 /* enable NPT for AMD64 and X86 with PAE */
@@ -127,7 +131,7 @@ static inline struct vcpu_svm *to_svm(struct kvm_vcpu *vcpu)
 
 static inline bool is_nested(struct vcpu_svm *svm)
 {
-	return svm->nested_vmcb;
+	return svm->nested.vmcb;
 }
 
 static inline void enable_gif(struct vcpu_svm *svm)
@@ -636,7 +640,7 @@ static void init_vmcb(struct vcpu_svm *svm)
 	}
 	force_new_asid(&svm->vcpu);
 
-	svm->nested_vmcb = 0;
+	svm->nested.vmcb = 0;
 	svm->vcpu.arch.hflags = 0;
 
 	enable_gif(svm);
@@ -699,9 +703,9 @@ static struct kvm_vcpu *svm_create_vcpu(struct kvm *kvm, unsigned int id)
 	hsave_page = alloc_page(GFP_KERNEL);
 	if (!hsave_page)
 		goto uninit;
-	svm->hsave = page_address(hsave_page);
+	svm->nested.hsave = page_address(hsave_page);
 
-	svm->nested_msrpm = page_address(nested_msrpm_pages);
+	svm->nested.msrpm = page_address(nested_msrpm_pages);
 
 	svm->vmcb = page_address(page);
 	clear_page(svm->vmcb);
@@ -731,8 +735,8 @@ static void svm_free_vcpu(struct kvm_vcpu *vcpu)
 
 	__free_page(pfn_to_page(svm->vmcb_pa >> PAGE_SHIFT));
 	__free_pages(virt_to_page(svm->msrpm), MSRPM_ALLOC_ORDER);
-	__free_page(virt_to_page(svm->hsave));
-	__free_pages(virt_to_page(svm->nested_msrpm), MSRPM_ALLOC_ORDER);
+	__free_page(virt_to_page(svm->nested.hsave));
+	__free_pages(virt_to_page(svm->nested.msrpm), MSRPM_ALLOC_ORDER);
 	kvm_vcpu_uninit(vcpu);
 	kmem_cache_free(kvm_vcpu_cache, svm);
 }
@@ -1558,13 +1562,13 @@ static int nested_svm_exit_handled(struct vcpu_svm *svm, bool kvm_override)
 
 	switch (svm->vmcb->control.exit_code) {
 	case SVM_EXIT_MSR:
-		return nested_svm_do(svm, svm->nested_vmcb,
-				     svm->nested_vmcb_msrpm, NULL,
+		return nested_svm_do(svm, svm->nested.vmcb,
+				     svm->nested.vmcb_msrpm, NULL,
 				     nested_svm_exit_handled_msr);
 	default: break;
 	}
 
-	return nested_svm_do(svm, svm->nested_vmcb, 0, &k,
+	return nested_svm_do(svm, svm->nested.vmcb, 0, &k,
 			     nested_svm_exit_handled_real);
 }
 
@@ -1604,7 +1608,7 @@ static int nested_svm_vmexit_real(struct vcpu_svm *svm, void *arg1,
 				  void *arg2, void *opaque)
 {
 	struct vmcb *nested_vmcb = (struct vmcb *)arg1;
-	struct vmcb *hsave = svm->hsave;
+	struct vmcb *hsave = svm->nested.hsave;
 	struct vmcb *vmcb = svm->vmcb;
 
 	/* Give the current vmcb to the guest */
@@ -1679,7 +1683,7 @@ static int nested_svm_vmexit_real(struct vcpu_svm *svm, void *arg1,
 	svm->vmcb->control.exit_int_info = 0;
 
 	/* Exit nested SVM mode */
-	svm->nested_vmcb = 0;
+	svm->nested.vmcb = 0;
 
 	return 0;
 }
@@ -1687,7 +1691,7 @@ static int nested_svm_vmexit_real(struct vcpu_svm *svm, void *arg1,
 static int nested_svm_vmexit(struct vcpu_svm *svm)
 {
 	nsvm_printk("VMexit\n");
-	if (nested_svm_do(svm, svm->nested_vmcb, 0,
+	if (nested_svm_do(svm, svm->nested.vmcb, 0,
 			  NULL, nested_svm_vmexit_real))
 		return 1;
 
@@ -1703,8 +1707,8 @@ static int nested_svm_vmrun_msrpm(struct vcpu_svm *svm, void *arg1,
 	int i;
 	u32 *nested_msrpm = (u32*)arg1;
 	for (i=0; i< PAGE_SIZE * (1 << MSRPM_ALLOC_ORDER) / 4; i++)
-		svm->nested_msrpm[i] = svm->msrpm[i] | nested_msrpm[i];
-	svm->vmcb->control.msrpm_base_pa = __pa(svm->nested_msrpm);
+		svm->nested.msrpm[i] = svm->msrpm[i] | nested_msrpm[i];
+	svm->vmcb->control.msrpm_base_pa = __pa(svm->nested.msrpm);
 
 	return 0;
 }
@@ -1713,11 +1717,11 @@ static int nested_svm_vmrun(struct vcpu_svm *svm, void *arg1,
 			    void *arg2, void *opaque)
 {
 	struct vmcb *nested_vmcb = (struct vmcb *)arg1;
-	struct vmcb *hsave = svm->hsave;
+	struct vmcb *hsave = svm->nested.hsave;
 	struct vmcb *vmcb = svm->vmcb;
 
 	/* nested_vmcb is our indicator if nested SVM is activated */
-	svm->nested_vmcb = svm->vmcb->save.rax;
+	svm->nested.vmcb = svm->vmcb->save.rax;
 
 	/* Clear internal status */
 	kvm_clear_exception_queue(&svm->vcpu);
@@ -1795,7 +1799,7 @@ static int nested_svm_vmrun(struct vcpu_svm *svm, void *arg1,
 
 	svm->vmcb->control.intercept |= nested_vmcb->control.intercept;
 
-	svm->nested_vmcb_msrpm = nested_vmcb->control.msrpm_base_pa;
+	svm->nested.vmcb_msrpm = nested_vmcb->control.msrpm_base_pa;
 
 	force_new_asid(&svm->vcpu);
 	svm->vmcb->control.exit_int_info = nested_vmcb->control.exit_int_info;
@@ -1897,7 +1901,7 @@ static int vmrun_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run)
 			  NULL, nested_svm_vmrun))
 		return 1;
 
-	if (nested_svm_do(svm, svm->nested_vmcb_msrpm, 0,
+	if (nested_svm_do(svm, svm->nested.vmcb_msrpm, 0,
 		      NULL, nested_svm_vmrun_msrpm))
 		return 1;
 
@@ -2107,7 +2111,7 @@ static int svm_get_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 *data)
 		*data = svm->vmcb->save.last_excp_to;
 		break;
 	case MSR_VM_HSAVE_PA:
-		*data = svm->hsave_msr;
+		*data = svm->nested.hsave_msr;
 		break;
 	case MSR_VM_CR:
 		*data = 0;
@@ -2195,7 +2199,7 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 data)
 			svm_disable_lbrv(svm);
 		break;
 	case MSR_VM_HSAVE_PA:
-		svm->hsave_msr = data;
+		svm->nested.hsave_msr = data;
 		break;
 	case MSR_VM_CR:
 	case MSR_VM_IGNNE:
-- 
1.6.4.1


  parent reply	other threads:[~2009-08-26 10:38 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-26 10:29 [PATCH 00/47] KVM updates for 2.6.32 merge window (4/4) Avi Kivity
2009-08-26 10:29 ` [PATCH 01/47] KVM: remove superfluous NULL pointer check in kvm_inject_pit_timer_irqs() Avi Kivity
2009-08-26 10:29 ` [PATCH 02/47] KVM: MMU: make __kvm_mmu_free_some_pages handle empty list Avi Kivity
2009-08-26 10:29 ` [PATCH 03/47] KVM: MMU: fix bogus alloc_mmu_pages assignment Avi Kivity
2009-08-26 10:29 ` [PATCH 04/47] KVM: x86: Disallow hypercalls for guest callers in rings > 0 Avi Kivity
2009-08-26 10:29 ` [PATCH 05/47] KVM: VMX: Optimize vmx_get_cpl() Avi Kivity
2009-08-26 14:15   ` Roel Kluin
2009-08-26 14:33     ` Avi Kivity
2009-08-26 10:29 ` [PATCH 06/47] KVM: ignore reads to perfctr msrs Avi Kivity
2009-08-26 10:29 ` [PATCH 07/47] KVM: fix EFER read buffer overflow Avi Kivity
2009-08-26 10:29 ` [PATCH 08/47] KVM: Call kvm_vcpu_kick() inside pic spinlock Avi Kivity
2009-08-26 10:29 ` [PATCH 09/47] KVM: Call ack notifiers from PIC when guest OS acks an IRQ Avi Kivity
2009-08-26 10:29 ` [PATCH 10/47] KVM: Replace pic_lock()/pic_unlock() with direct call to spinlock functions Avi Kivity
2009-08-26 10:29 ` [PATCH 11/47] x86: Export kmap_atomic_to_page() Avi Kivity
2009-08-26 10:29 ` [PATCH 12/47] KVM: SVM: add helper functions for global interrupt flag Avi Kivity
2009-08-26 10:29 ` [PATCH 13/47] KVM: SVM: optimize nested #vmexit Avi Kivity
2009-08-26 10:29 ` [PATCH 14/47] KVM: SVM: optimize nested vmrun Avi Kivity
2009-08-26 10:29 ` [PATCH 15/47] KVM: SVM: copy only necessary parts of the control area on vmrun/vmexit Avi Kivity
2009-08-26 10:29 ` [PATCH 16/47] KVM: SVM: complete interrupts after handling nested exits Avi Kivity
2009-08-26 10:29 ` Avi Kivity [this message]
2009-08-26 10:29 ` [PATCH 18/47] KVM: SVM: cache nested intercepts Avi Kivity
2009-08-26 10:29 ` [PATCH 19/47] KVM: SVM: consolidate nested_svm_exit_handled Avi Kivity
2009-08-26 10:29 ` [PATCH 20/47] KVM: SVM: do nested vmexit in nested_svm_exit_handled Avi Kivity
2009-08-26 10:29 ` [PATCH 21/47] KVM: SVM: simplify nested_svm_check_exception Avi Kivity
2009-08-26 10:29 ` [PATCH 22/47] KVM: SVM: get rid of nested_svm_vmexit_real Avi Kivity
2009-08-26 10:29 ` [PATCH 23/47] KVM: SVM: clean up nested_svm_exit_handled_msr Avi Kivity
2009-08-26 10:29 ` [PATCH 24/47] KVM: SVM: clean up nestec vmload/vmsave paths Avi Kivity
2009-08-26 10:29 ` [PATCH 25/47] KVM: SVM: clean up nested vmrun path Avi Kivity
2009-08-26 10:29 ` [PATCH 26/47] KVM: SVM: remove nested_svm_do and helper functions Avi Kivity
2009-08-26 10:29 ` [PATCH 27/47] KVM: SVM: handle errors in vmrun emulation path appropriatly Avi Kivity
2009-08-26 10:29 ` [PATCH 28/47] KVM: SVM: move special nested exit handling to separate function Avi Kivity
2009-08-26 10:29 ` [PATCH 29/47] KVM: SVM: remove unnecessary is_nested check from svm_cpu_run Avi Kivity
2009-08-26 10:29 ` [PATCH 30/47] KVM: SVM: move nested_svm_intr main logic out of if-clause Avi Kivity
2009-08-26 10:29 ` [PATCH 31/47] KVM: SVM: check for nested VINTR flag in svm_interrupt_allowed Avi Kivity
2009-08-26 10:29 ` [PATCH 32/47] KVM: SVM: enable nested svm by default Avi Kivity
2009-08-26 10:29 ` [PATCH 33/47] KVM: Update cr8 intercept when APIC TPR is changed by userspace Avi Kivity
2009-08-26 10:29 ` [PATCH 34/47] KVM: SVM: Drop tlb flush workaround in npt Avi Kivity
2009-08-26 10:29 ` [PATCH 35/47] KVM: Move #endif KVM_CAP_IRQ_ROUTING to correct place Avi Kivity
2009-08-26 10:29 ` [PATCH 36/47] KVM: VMX: Adjust rflags if in real mode emulation Avi Kivity
2009-08-26 10:29 ` [PATCH 37/47] KVM: When switching to a vm8086 task, load segments as 16-bit Avi Kivity
2009-08-26 10:30 ` [PATCH 38/47] KVM: Rename x86_emulate.c to emulate.c Avi Kivity
2009-08-26 10:30 ` [PATCH 39/47] Documentation: Update KVM list email address Avi Kivity
2009-08-26 10:30 ` [PATCH 40/47] KVM: export kvm_para.h Avi Kivity
2009-08-26 10:30 ` [PATCH 41/47] KVM: Add __KERNEL__ guards to exported headers Avi Kivity
2009-08-26 10:30 ` [PATCH 42/47] KVM: Add missing #include Avi Kivity
2009-08-26 10:30 ` [PATCH 43/47] KVM: x86 emulator: Add adc and sbb missing decoder flags Avi Kivity
2009-08-26 10:30 ` [PATCH 44/47] KVM: Use kvm_{read,write}_guest_virt() to read and write segment descriptors Avi Kivity
2009-08-26 10:30 ` [PATCH 45/47] KVM: VMX: Fix EPT with WP bit change during paging Avi Kivity
2009-08-26 10:30 ` [PATCH 46/47] KVM: Protect update_cr8_intercept() when running without an apic Avi Kivity
2009-08-26 10:30 ` [PATCH 47/47] KVM: Document KVM_CAP_IRQCHIP Avi Kivity

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=1251282609-12835-18-git-send-email-avi@redhat.com \
    --to=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox