[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] x86, hvm: Config option to allow vmxassist to be disabled.



# HG changeset patch
# User Keir Fraser <keir@xxxxxxxxxxxxx>
# Date 1195910602 0
# Node ID 0814fb0f8a4debac73c97a55affed02a07767bcc
# Parent  dc9246357cdbe27655fd0ac7ef229d25b00c628c
x86, hvm: Config option to allow vmxassist to be disabled.
hvmloader is modified to dynamically detect this, allowing possibility
of optional full vmxassist replacement in 3.2 stable branch in future.
Currently 'vmxassist=y' is not much use since no replacement is
implemented.

Signed-off-by: Keir Fraser <keir.fraser@xxxxxxxxxx>
---
 tools/firmware/hvmloader/hvmloader.c |   13 ++++++++--
 xen/arch/x86/Rules.mk                |    5 +++
 xen/arch/x86/hvm/vmx/vmx.c           |   44 +++++++++++++++++++++++++++++++----
 xen/arch/x86/hvm/vpic.c              |    2 -
 xen/include/asm-x86/hvm/vmx/vmcs.h   |    6 +++-
 5 files changed, 62 insertions(+), 8 deletions(-)

diff -r dc9246357cdb -r 0814fb0f8a4d tools/firmware/hvmloader/hvmloader.c
--- a/tools/firmware/hvmloader/hvmloader.c      Fri Nov 23 16:42:44 2007 +0000
+++ b/tools/firmware/hvmloader/hvmloader.c      Sat Nov 24 13:23:22 2007 +0000
@@ -40,6 +40,7 @@ asm(
     "    cli                         \n"
     "    movl $stack_top,%esp        \n"
     "    movl %esp,%ebp              \n"
+    "    movl %eax,initial_eax       \n"
     "    call main                   \n"
     /* Relocate real-mode trampoline to 0x0. */
     "    mov  $trampoline_start,%esi \n"
@@ -97,6 +98,8 @@ asm(
     "stack_top:                      \n"
     );
 
+static unsigned int initial_eax;
+
 void create_mp_tables(void);
 int hvm_write_smbios_tables(void);
 
@@ -119,6 +122,12 @@ check_amd(void)
         "=d" (*(int *)(&id[4]))
         : "a" (0) );
     return __builtin_memcmp(id, "AuthenticAMD", 12) == 0;
+}
+
+static int
+use_vmxassist(void)
+{
+    return !check_amd() && !initial_eax;
 }
 
 static void
@@ -407,7 +416,7 @@ int main(void)
         printf(" %05x-%05x: Etherboot ROM\n",
                ETHERBOOT_PHYSICAL_ADDRESS,
                ETHERBOOT_PHYSICAL_ADDRESS + etherboot_sz - 1);
-    if ( !check_amd() )
+    if ( use_vmxassist() )
         printf(" %05x-%05x: VMXAssist\n",
                VMXASSIST_PHYSICAL_ADDRESS,
                VMXASSIST_PHYSICAL_ADDRESS + sizeof(vmxassist) - 1);
@@ -424,7 +433,7 @@ int main(void)
                ROMBIOS_PHYSICAL_ADDRESS,
                ROMBIOS_PHYSICAL_ADDRESS + rombios_sz - 1);
 
-    if ( !check_amd() )
+    if ( use_vmxassist() )
     {
         printf("Loading VMXAssist ...\n");
         memcpy((void *)VMXASSIST_PHYSICAL_ADDRESS,
diff -r dc9246357cdb -r 0814fb0f8a4d xen/arch/x86/Rules.mk
--- a/xen/arch/x86/Rules.mk     Fri Nov 23 16:42:44 2007 +0000
+++ b/xen/arch/x86/Rules.mk     Sat Nov 24 13:23:22 2007 +0000
@@ -11,6 +11,11 @@ xenoprof := y
 #
 pae ?= n
 supervisor_mode_kernel ?= n
+vmxassist ?= y
+
+ifeq ($(vmxassist),y)
+CFLAGS += -DVMXASSIST
+endif
 
 # Solaris grabs stdarg.h and friends from the system include directory.
 ifneq ($(XEN_OS),SunOS)
diff -r dc9246357cdb -r 0814fb0f8a4d xen/arch/x86/hvm/vmx/vmx.c
--- a/xen/arch/x86/hvm/vmx/vmx.c        Fri Nov 23 16:42:44 2007 +0000
+++ b/xen/arch/x86/hvm/vmx/vmx.c        Sat Nov 24 13:23:22 2007 +0000
@@ -92,6 +92,11 @@ static int vmx_vcpu_initialise(struct vc
 
     vmx_install_vlapic_mapping(v);
 
+#ifndef VMXASSIST
+    if ( v->vcpu_id == 0 )
+        v->arch.guest_context.user_regs.eax = 1;
+#endif
+
     return 0;
 }
 
@@ -701,7 +706,9 @@ static void vmx_load_cpu_state(struct vc
     v->arch.hvm_vmx.shadow_gs = data->shadow_gs;
 #endif
 
+#ifdef VMXASSIST
     v->arch.hvm_vmx.vmxassist_enabled = !(data->cr0 & X86_CR0_PE);
+#endif
 
     hvm_set_guest_time(v, data->tsc);
 
@@ -961,9 +968,11 @@ static void vmx_init_ap_context(
     struct vcpu_guest_context *ctxt, int vcpuid, int trampoline_vector)
 {
     memset(ctxt, 0, sizeof(*ctxt));
+#ifdef VMXASSIST
     ctxt->user_regs.eip = VMXASSIST_BASE;
     ctxt->user_regs.edx = vcpuid;
     ctxt->user_regs.ebx = trampoline_vector;
+#endif
 }
 
 void do_nmi(struct cpu_user_regs *);
@@ -1045,7 +1054,10 @@ static void vmx_update_guest_cr(struct v
 
         v->arch.hvm_vcpu.hw_cr[0] =
             v->arch.hvm_vcpu.guest_cr[0] |
-            X86_CR0_PE | X86_CR0_NE | X86_CR0_PG | X86_CR0_WP;
+            X86_CR0_NE | X86_CR0_PG | X86_CR0_WP;
+#ifdef VMXASSIST
+        v->arch.hvm_vcpu.hw_cr[0] |= X86_CR0_PE;
+#endif
         __vmwrite(GUEST_CR0, v->arch.hvm_vcpu.hw_cr[0]);
         __vmwrite(CR0_READ_SHADOW, v->arch.hvm_vcpu.guest_cr[0]);
         break;
@@ -1246,6 +1258,7 @@ static void vmx_do_cpuid(struct cpu_user
     unsigned int input = regs->eax;
     unsigned int eax, ebx, ecx, edx;
 
+#ifdef VMXASSIST
     if ( input == 0x40000003 )
     {
         /*
@@ -1280,6 +1293,7 @@ static void vmx_do_cpuid(struct cpu_user
         regs->edx = (u32)(value >> 32);
         return;
     }
+#endif
 
     hvm_cpuid(input, &eax, &ebx, &ecx, &edx);
 
@@ -1816,6 +1830,8 @@ static void vmx_io_instruction(unsigned 
     }
 }
 
+#ifdef VMXASSIST
+
 static void vmx_world_save(struct vcpu *v, struct vmx_assist_context *c)
 {
     struct cpu_user_regs *regs = guest_cpu_user_regs();
@@ -2057,6 +2073,19 @@ static int vmx_set_cr0(unsigned long val
 
     return 1;
 }
+
+#else /* !defined(VMXASSIST) */
+
+#define vmx_set_cr0(v) hvm_set_cr0(v)
+
+static int vmx_realmode(struct cpu_user_regs *regs)
+{
+    gdprintk(XENLOG_ERR, "Attempt to enter real mode on VCPU %d\n",
+             current->vcpu_id);
+    return -EINVAL;
+}
+
+#endif
 
 #define CASE_SET_REG(REG, reg)      \
     case REG_ ## REG: regs->reg = value; break
@@ -2677,9 +2706,16 @@ static void vmx_failed_vmentry(unsigned 
                                struct cpu_user_regs *regs)
 {
     unsigned int failed_vmentry_reason = (uint16_t)exit_reason;
-    unsigned long exit_qualification;
-
-    exit_qualification = __vmread(EXIT_QUALIFICATION);
+    unsigned long exit_qualification = __vmread(EXIT_QUALIFICATION);
+
+#ifndef VMXASSIST
+    if ( (failed_vmentry_reason == EXIT_REASON_INVALID_GUEST_STATE) &&
+         (exit_qualification == 0) &&
+         !(current->arch.hvm_vcpu.hw_cr[0] & X86_CR0_PE) &&
+         (vmx_realmode(regs) == 0) )
+        return;
+#endif
+
     printk("Failed vm entry (exit reason 0x%x) ", exit_reason);
     switch ( failed_vmentry_reason )
     {
diff -r dc9246357cdb -r 0814fb0f8a4d xen/arch/x86/hvm/vpic.c
--- a/xen/arch/x86/hvm/vpic.c   Fri Nov 23 16:42:44 2007 +0000
+++ b/xen/arch/x86/hvm/vpic.c   Sat Nov 24 13:23:22 2007 +0000
@@ -271,7 +271,7 @@ static void vpic_ioport_write(
             vpic->imr = val;
             break;
         case 1:
-#if 1 /* Delete me when vmxassist is retired. */
+#ifdef VMXASSIST
             /* Which mode is irqbase programmed in? */
             current->arch.hvm_vmx.irqbase_mode =
                 current->arch.hvm_vmx.vmxassist_enabled;
diff -r dc9246357cdb -r 0814fb0f8a4d xen/include/asm-x86/hvm/vmx/vmcs.h
--- a/xen/include/asm-x86/hvm/vmx/vmcs.h        Fri Nov 23 16:42:44 2007 +0000
+++ b/xen/include/asm-x86/hvm/vmx/vmcs.h        Sat Nov 24 13:23:22 2007 +0000
@@ -22,7 +22,10 @@
 #include <asm/config.h>
 #include <asm/hvm/io.h>
 #include <asm/hvm/vmx/cpu.h>
+
+#ifdef VMXASSIST
 #include <public/hvm/vmx_assist.h>
+#endif
 
 extern void start_vmx(void);
 extern void vmcs_dump_vcpu(void);
@@ -85,10 +88,11 @@ struct arch_vmx_struct {
     unsigned int         host_msr_count;
     struct vmx_msr_entry *host_msr_area;
 
-    /* Following fields are all specific to vmxassist. */
+#ifdef VMXASSIST
     unsigned long        vmxassist_enabled:1;
     unsigned long        irqbase_mode:1;
     unsigned char        pm_irqbase[2];
+#endif
 };
 
 int vmx_create_vmcs(struct vcpu *v);

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.