From 9122c69c8d3080fe7ef63aa1a2d9f2f290962ee5 Mon Sep 17 00:00:00 2001 From: Eddie Dong Date: Thu, 9 Jun 2011 16:24:09 +0800 Subject: [PATCH] Nested VMX: Add APIs for nestedhvm_ops. Signed-off-by: Qing He Signed-off-by: Eddie Dong Acked-by: Tim Deegan Committed-by: Tim Deegan --- xen/arch/x86/hvm/hvm.c | 2 +- xen/arch/x86/hvm/vmx/Makefile | 1 + xen/arch/x86/hvm/vmx/vmx.c | 8 ++- xen/arch/x86/hvm/vmx/vvmx.c | 88 ++++++++++++++++++++++++++++++ xen/include/asm-x86/hvm/vmx/vvmx.h | 8 +++ 5 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 xen/arch/x86/hvm/vmx/vvmx.c diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 95e5561d77..98b40f7a4f 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -3526,7 +3526,7 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE(void) arg) /* Remove the check below once we have * shadow-on-shadow. */ - if ( !paging_mode_hap(d) && a.value ) + if ( cpu_has_svm && !paging_mode_hap(d) && a.value ) rc = -EINVAL; /* Set up NHVM state for any vcpus that are already up */ if ( !d->arch.hvm_domain.params[HVM_PARAM_NESTEDHVM] ) diff --git a/xen/arch/x86/hvm/vmx/Makefile b/xen/arch/x86/hvm/vmx/Makefile index ce06568304..373b3d91f5 100644 --- a/xen/arch/x86/hvm/vmx/Makefile +++ b/xen/arch/x86/hvm/vmx/Makefile @@ -4,3 +4,4 @@ obj-y += realmode.o obj-y += vmcs.o obj-y += vmx.o obj-y += vpmu_core2.o +obj-y += vvmx.o diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index ab07ae9942..d9b93e7ed2 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -1404,7 +1404,13 @@ static struct hvm_function_table __read_mostly vmx_function_table = { .invlpg_intercept = vmx_invlpg_intercept, .set_uc_mode = vmx_set_uc_mode, .set_info_guest = vmx_set_info_guest, - .set_rdtsc_exiting = vmx_set_rdtsc_exiting + .set_rdtsc_exiting = vmx_set_rdtsc_exiting, + .nhvm_vcpu_initialise = nvmx_vcpu_initialise, + .nhvm_vcpu_destroy = nvmx_vcpu_destroy, + .nhvm_vcpu_reset = nvmx_vcpu_reset, + .nhvm_vcpu_guestcr3 = nvmx_vcpu_guestcr3, + .nhvm_vcpu_hostcr3 = nvmx_vcpu_hostcr3, + .nhvm_vcpu_asid = nvmx_vcpu_asid }; struct hvm_function_table * __init start_vmx(void) diff --git a/xen/arch/x86/hvm/vmx/vvmx.c b/xen/arch/x86/hvm/vmx/vvmx.c new file mode 100644 index 0000000000..5295133960 --- /dev/null +++ b/xen/arch/x86/hvm/vmx/vvmx.c @@ -0,0 +1,88 @@ +/* + * vvmx.c: Support virtual VMX for nested virtualization. + * + * Copyright (c) 2010, Intel Corporation. + * Author: Qing He + * Eddie Dong + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple + * Place - Suite 330, Boston, MA 02111-1307 USA. + * + */ + +#include +#include +#include +#include +#include + +int nvmx_vcpu_initialise(struct vcpu *v) +{ + struct nestedvmx *nvmx = &vcpu_2_nvmx(v); + struct nestedvcpu *nvcpu = &vcpu_nestedhvm(v); + + nvcpu->nv_n2vmcx = alloc_xenheap_page(); + if ( !nvcpu->nv_n2vmcx ) + { + gdprintk(XENLOG_ERR, "nest: allocation for shadow vmcs failed\n"); + goto out; + } + nvmx->vmxon_region_pa = 0; + nvcpu->nv_vvmcx = NULL; + nvcpu->nv_vvmcxaddr = VMCX_EADDR; + nvmx->intr.intr_info = 0; + nvmx->intr.error_code = 0; + nvmx->iobitmap[0] = NULL; + nvmx->iobitmap[1] = NULL; + return 0; +out: + return -ENOMEM; +} + +void nvmx_vcpu_destroy(struct vcpu *v) +{ + struct nestedvcpu *nvcpu = &vcpu_nestedhvm(v); + + if ( nvcpu->nv_n2vmcx ) { + __vmpclear(virt_to_maddr(nvcpu->nv_n2vmcx)); + free_xenheap_page(nvcpu->nv_n2vmcx); + nvcpu->nv_n2vmcx = NULL; + } +} + +int nvmx_vcpu_reset(struct vcpu *v) +{ + return 0; +} + +uint64_t nvmx_vcpu_guestcr3(struct vcpu *v) +{ + /* TODO */ + ASSERT(0); + return 0; +} + +uint64_t nvmx_vcpu_hostcr3(struct vcpu *v) +{ + /* TODO */ + ASSERT(0); + return 0; +} + +uint32_t nvmx_vcpu_asid(struct vcpu *v) +{ + /* TODO */ + ASSERT(0); + return 0; +} + diff --git a/xen/include/asm-x86/hvm/vmx/vvmx.h b/xen/include/asm-x86/hvm/vmx/vvmx.h index d4b9579a83..6dc701dab9 100644 --- a/xen/include/asm-x86/hvm/vmx/vvmx.h +++ b/xen/include/asm-x86/hvm/vmx/vvmx.h @@ -34,5 +34,13 @@ struct nestedvmx { }; #define vcpu_2_nvmx(v) (vcpu_nestedhvm(v).u.nvmx) + +int nvmx_vcpu_initialise(struct vcpu *v); +void nvmx_vcpu_destroy(struct vcpu *v); +int nvmx_vcpu_reset(struct vcpu *v); +uint64_t nvmx_vcpu_guestcr3(struct vcpu *v); +uint64_t nvmx_vcpu_hostcr3(struct vcpu *v); +uint32_t nvmx_vcpu_asid(struct vcpu *v); + #endif /* __ASM_X86_HVM_VVMX_H__ */ -- 2.30.2