Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Now correctly boots 2, 4, 8 core kitten
[palacios.git] / palacios / src / palacios / vmx.c
index 15d108b..18d183b 100644 (file)
 #include <palacios/vmx_io.h>
 #include <palacios/vmx_msr.h>
 
+
+#ifndef CONFIG_DEBUG_VMX
+#undef PrintDebug
+#define PrintDebug(fmt, args...)
+#endif
+
+
 static addr_t host_vmcs_ptrs[CONFIG_MAX_CPUS] = { [0 ... CONFIG_MAX_CPUS - 1] = 0};
 
 
@@ -341,7 +348,7 @@ static int init_vmcs_bios(struct guest_info * info, struct vmx_data * vmx_state)
 #define VMXASSIST_GDT   0x10000
        addr_t vmxassist_gdt = 0;
 
-       if (guest_pa_to_host_va(info, VMXASSIST_GDT, &vmxassist_gdt) == -1) {
+       if (v3_gpa_to_hva(info, VMXASSIST_GDT, &vmxassist_gdt) == -1) {
            PrintError("Could not find VMXASSIST GDT destination\n");
            return -1;
        }
@@ -375,7 +382,7 @@ static int init_vmcs_bios(struct guest_info * info, struct vmx_data * vmx_state)
        extern uint8_t v3_vmxassist_end[];
        addr_t vmxassist_dst = 0;
 
-       if (guest_pa_to_host_va(info, VMXASSIST_START, &vmxassist_dst) == -1) {
+       if (v3_gpa_to_hva(info, VMXASSIST_START, &vmxassist_dst) == -1) {
            PrintError("Could not find VMXASSIST destination\n");
            return -1;
        }
@@ -494,7 +501,7 @@ static int update_irq_entry_state(struct guest_info * info) {
 
         int_info.valid = 1;
 #ifdef CONFIG_DEBUG_INTERRUPTS
-        PrintDebug("Injecting exception %d (EIP=%p)\n", int_info.vector, (void *)info->rip);
+        PrintDebug("Injecting exception %d (EIP=%p)\n", int_info.vector, (void *)(addr_t)info->rip);
 #endif
         check_vmcs_write(VMCS_ENTRY_INT_INFO, int_info.value);
 
@@ -536,7 +543,7 @@ static int update_irq_entry_state(struct guest_info * info) {
                     PrintDebug("Injecting Interrupt %d at exit %u(EIP=%p)\n", 
                               info->intr_core_state.irq_vector, 
                               (uint32_t)info->num_exits, 
-                              (void *)info->rip);
+                              (void *)(addr_t)info->rip);
 #endif
 
                     check_vmcs_write(VMCS_ENTRY_INT_INFO, ent_int.value);
@@ -644,8 +651,8 @@ int v3_vmx_enter(struct guest_info * info) {
     v3_vmx_restore_vmcs(info);
 
 
-#ifdef CONFIG_SYMBIOTIC
-    if (info->vm_info->sym_state.symcalls[info->cpu_id].sym_call_active == 0) {
+#ifdef CONFIG_SYMCALL
+    if (info->sym_core_state.symcall_state.sym_call_active == 0) {
        update_irq_entry_state(info);
     }
 #else 
@@ -658,6 +665,9 @@ int v3_vmx_enter(struct guest_info * info) {
        vmcs_write(VMCS_GUEST_CR3, guest_cr3);
     }
 
+    // We do timer injection here to track real host time.
+    rdtscll(tmp_tsc);
+    v3_update_time(info, tmp_tsc - info->time_state.cached_host_tsc);
     rdtscll(info->time_state.cached_host_tsc);
 
     if (info->vm_info->run_state == VM_STOPPED) {
@@ -678,11 +688,11 @@ int v3_vmx_enter(struct guest_info * info) {
        return -1;
     }
 
-    rdtscll(tmp_tsc);
+    //   rdtscll(tmp_tsc);
+    //    v3_update_time(info, tmp_tsc - info->time_state.cached_host_tsc);
 
     info->num_exits++;
 
-    v3_update_time(info, tmp_tsc - info->time_state.cached_host_tsc);
 
     /* Update guest state */
     v3_vmx_save_vmcs(info);
@@ -706,8 +716,8 @@ int v3_vmx_enter(struct guest_info * info) {
     exit_log[info->num_exits % 10] = exit_info;
 
 
-#ifdef CONFIG_SYMBIOTIC
-    if (info->vm_info->sym_state.symcalls[info->cpu_id].sym_call_active == 0) {
+#ifdef CONFIG_SYMCALL
+    if (info->sym_core_state.symcall_state.sym_call_active == 0) {
        update_irq_exit_state(info);
     }
 #else
@@ -794,7 +804,7 @@ void v3_init_vmx_cpu(int cpu_id) {
     uint64_t ret = 0;
 
     v3_get_msr(VMX_CR4_FIXED0_MSR,&(tmp_msr.hi),&(tmp_msr.lo));
-    
+#ifdef __V3_64BIT__
     __asm__ __volatile__ (
                          "movq %%cr4, %%rbx;"
                          "orq  $0x00002000, %%rbx;"
@@ -823,6 +833,38 @@ void v3_init_vmx_cpu(int cpu_id) {
                          :
                          : "%rbx"
                          );
+#elif __V3_32BIT__
+    __asm__ __volatile__ (
+                         "movl %%cr4, %%ecx;"
+                         "orl  $0x00002000, %%ecx;"
+                         "movl %%ecx, %0;"
+                         : "=m"(ret) 
+                         :
+                         : "%ecx"
+                         );
+
+    if ((~ret & tmp_msr.value) == 0) {
+        __asm__ __volatile__ (
+                             "movl %0, %%cr4;"
+                             :
+                             : "q"(ret)
+                             );
+    } else {
+        PrintError("Invalid CR4 Settings!\n");
+        return;
+    }
+
+    __asm__ __volatile__ (
+                         "movl %%cr0, %%ecx; "
+                         "orl  $0x00000020,%%ecx; "
+                         "movl %%ecx, %%cr0;"
+                         :
+                         :
+                         : "%ecx"
+                         );
+
+#endif
+
     //
     // Should check and return Error here....