From patchwork Fri Aug 7 09:49:33 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joerg Roedel X-Patchwork-Id: 39841 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n779tthA031466 for ; Fri, 7 Aug 2009 09:55:57 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757309AbZHGJuu (ORCPT ); Fri, 7 Aug 2009 05:50:50 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1755933AbZHGJut (ORCPT ); Fri, 7 Aug 2009 05:50:49 -0400 Received: from sg2ehsobe004.messaging.microsoft.com ([207.46.51.78]:6763 "EHLO SG2EHSOBE004.bigfish.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1756051AbZHGJuk (ORCPT ); Fri, 7 Aug 2009 05:50:40 -0400 Received: from mail194-sin-R.bigfish.com (10.210.100.241) by SG2EHSOBE004.bigfish.com (10.210.112.24) with Microsoft SMTP Server id 8.1.340.0; Fri, 7 Aug 2009 09:50:40 +0000 Received: from mail194-sin (localhost.localdomain [127.0.0.1]) by mail194-sin-R.bigfish.com (Postfix) with ESMTP id 6E1F71180171; Fri, 7 Aug 2009 09:50:46 +0000 (UTC) X-SpamScore: 3 X-BigFish: VPS3(zzzz1202hzzz32i203h43j62h) X-Spam-TCS-SCL: 1:0 Received: by mail194-sin (MessageSwitch) id 1249638634169891_1460; Fri, 7 Aug 2009 09:50:34 +0000 (UCT) Received: from svlb1extmailp02.amd.com (unknown [139.95.251.11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail194-sin.bigfish.com (Postfix) with ESMTP id D19E3468078; Fri, 7 Aug 2009 09:50:11 +0000 (UTC) Received: from svlb1twp01.amd.com ([139.95.250.34]) by svlb1extmailp02.amd.com (Switch-3.2.7/Switch-3.2.7) with ESMTP id n779nvsg012627; Fri, 7 Aug 2009 02:50:00 -0700 X-WSS-ID: 0KO03B8-03-0WT-01 Received: from SSVLEXBH1.amd.com (ssvlexbh1.amd.com [139.95.53.182]) by svlb1twp01.amd.com (Tumbleweed MailGate 3.5.1) with ESMTP id 2EC3888494C; Fri, 7 Aug 2009 02:49:55 -0700 (PDT) Received: from SSVLEXMB1.amd.com ([139.95.53.181]) by SSVLEXBH1.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Fri, 7 Aug 2009 02:49:58 -0700 Received: from SF30EXMB1.amd.com ([172.20.6.49]) by SSVLEXMB1.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Fri, 7 Aug 2009 02:49:57 -0700 Received: from seurexmb1.amd.com ([165.204.9.130]) by SF30EXMB1.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Fri, 7 Aug 2009 11:49:52 +0200 Received: from lemmy.amd.com ([165.204.15.93]) by seurexmb1.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Fri, 7 Aug 2009 11:49:50 +0200 Received: by lemmy.amd.com (Postfix, from userid 41430) id A0835C9F97; Fri, 7 Aug 2009 11:49:50 +0200 (CEST) From: Joerg Roedel To: Avi Kivity CC: Alexander Graf , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Joerg Roedel Subject: [PATCH 06/21] kvm/svm: move nested svm state into seperate struct Date: Fri, 7 Aug 2009 11:49:33 +0200 Message-ID: <1249638588-10982-7-git-send-email-joerg.roedel@amd.com> X-Mailer: git-send-email 1.6.3.3 In-Reply-To: <1249638588-10982-1-git-send-email-joerg.roedel@amd.com> References: <1249638588-10982-1-git-send-email-joerg.roedel@amd.com> X-OriginalArrivalTime: 07 Aug 2009 09:49:50.0905 (UTC) FILETIME=[68544A90:01CA1744] MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This makes it more clear for which purpose these members in the vcpu_svm exist. Signed-off-by: Joerg Roedel Acked-by: Alexander Graf --- 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 b51d288..b4e2587 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; @@ -86,16 +98,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 */ @@ -128,7 +132,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) @@ -639,7 +643,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); @@ -702,9 +706,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); @@ -734,8 +738,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); } @@ -1561,13 +1565,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); } @@ -1607,7 +1611,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 */ @@ -1682,7 +1686,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; } @@ -1690,7 +1694,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; @@ -1706,8 +1710,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; } @@ -1716,11 +1720,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); @@ -1798,7 +1802,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; @@ -1900,7 +1904,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; @@ -2110,7 +2114,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; @@ -2196,7 +2200,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: