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.


Avoid physical/virtual contiguity assumptions using new guest memory access functions
[palacios.git] / palacios / src / palacios / vmx_assist.c
index cd2c2b9..5766b15 100644 (file)
@@ -111,27 +111,27 @@ int v3_vmxassist_ctx_switch(struct guest_info * info) {
 
 
     if (v3_gpa_to_hva(info, VMXASSIST_START, (addr_t *)&hdr) == -1) {
-        PrintError("Could not translate address for vmxassist header\n");
+        PrintError(info->vm_info, info, "Could not translate address for vmxassist header\n");
         return -1;
     }
 
     if (hdr->magic != VMXASSIST_MAGIC) {
-        PrintError("VMXASSIST_MAGIC field is invalid\n");
+        PrintError(info->vm_info, info, "VMXASSIST_MAGIC field is invalid\n");
         return -1;
     }
 
 
     if (v3_gpa_to_hva(info, (addr_t)(hdr->old_ctx_gpa), (addr_t *)&(old_ctx)) == -1) {
-        PrintError("Could not translate address for VMXASSIST old context\n");
+        PrintError(info->vm_info, info, "Could not translate address for VMXASSIST old context\n");
         return -1;
     }
 
     if (v3_gpa_to_hva(info, (addr_t)(hdr->new_ctx_gpa), (addr_t *)&(new_ctx)) == -1) {
-        PrintError("Could not translate address for VMXASSIST new context\n");
+        PrintError(info->vm_info, info, "Could not translate address for VMXASSIST new context\n");
         return -1;
     }
 
-    if (vmx_info->assist_state == VMXASSIST_DISABLED) {
+    if (vmx_info->assist_state == VMXASSIST_OFF) {
         
         /* Save the old Context */
        vmx_save_world_ctx(info, old_ctx);
@@ -139,13 +139,13 @@ int v3_vmxassist_ctx_switch(struct guest_info * info) {
         /* restore new context, vmxassist should launch the bios the first time */
         vmx_restore_world_ctx(info, new_ctx);
 
-        vmx_info->assist_state = VMXASSIST_ENABLED;
+        vmx_info->assist_state = VMXASSIST_ON;
 
-    } else if (vmx_info->assist_state == VMXASSIST_ENABLED) {
+    } else if (vmx_info->assist_state == VMXASSIST_ON) {
         /* restore old context */
        vmx_restore_world_ctx(info, old_ctx);
 
-        vmx_info->assist_state = VMXASSIST_DISABLED;
+        vmx_info->assist_state = VMXASSIST_OFF;
     }
 
     return 0;
@@ -182,7 +182,7 @@ static void load_segment(struct vmx_assist_segment * vmx_assist_seg, struct v3_s
 static void vmx_save_world_ctx(struct guest_info * info, struct vmx_assist_context * ctx) {
     struct vmx_data * vmx_info = (struct vmx_data *)(info->vmm_data);
 
-    PrintDebug("Writing from RIP: 0x%p\n", (void *)(addr_t)info->rip);
+    PrintDebug(info->vm_info, info, "Writing from RIP: 0x%p\n", (void *)(addr_t)info->rip);
     
     ctx->eip = info->rip;
     ctx->esp = info->vm_regs.rsp;
@@ -213,7 +213,7 @@ static void vmx_save_world_ctx(struct guest_info * info, struct vmx_assist_conte
 static void vmx_restore_world_ctx(struct guest_info * info, struct vmx_assist_context * ctx) {
     struct vmx_data * vmx_info = (struct vmx_data *)(info->vmm_data);
 
-    PrintDebug("ctx rip: %p\n", (void *)(addr_t)ctx->eip);
+    PrintDebug(info->vm_info, info, "ctx rip: %p\n", (void *)(addr_t)ctx->eip);
     
     info->rip = ctx->eip;
     info->vm_regs.rsp = ctx->esp;
@@ -248,13 +248,14 @@ int v3_vmxassist_init(struct guest_info * core, struct vmx_data * vmx_state) {
     core->vm_regs.rsp = 0x80000;
     ((struct rflags *)&(core->ctrl_regs.rflags))->rsvd1 = 1;
 
-#define GUEST_CR0 0x80010031
-#define GUEST_CR4 0x00002010
-    core->ctrl_regs.cr0 = GUEST_CR0;
-    core->ctrl_regs.cr4 = GUEST_CR4;
+#define GUEST_CR0_MASK 0x80010031
+#define GUEST_CR4_MASK 0x00002010
+    core->ctrl_regs.cr0 |= GUEST_CR0_MASK;
+    core->ctrl_regs.cr4 |= GUEST_CR4_MASK;
 
     ((struct cr0_32 *)&(core->shdw_pg_state.guest_cr0))->pe = 1;
     ((struct cr0_32 *)&(core->shdw_pg_state.guest_cr0))->wp = 1;
+    ((struct cr0_32 *)&(core->shdw_pg_state.guest_cr0))->ne = 1;
    
 
     // Setup segment registers
@@ -303,14 +304,10 @@ int v3_vmxassist_init(struct guest_info * core, struct vmx_data * vmx_state) {
        };
 
 
-       addr_t vmxassist_gdt = 0;
-
-       if (v3_gpa_to_hva(core, VMXASSIST_GDT, &vmxassist_gdt) == -1) {
-           PrintError("Could not find VMXASSIST GDT destination\n");
+       if (v3_write_gpa_memory(core, VMXASSIST_GDT, sizeof(uint64_t)*5, (void*)gdt)!=sizeof(uint64_t)*5) { 
+           PrintError(core->vm_info, core, "Could not write VMXASSIST GDT\n");
            return -1;
        }
-
-       memcpy((void *)vmxassist_gdt, gdt, sizeof(uint64_t) * 5);
         
        core->segments.gdtr.base = VMXASSIST_GDT;
 
@@ -337,10 +334,10 @@ int v3_vmxassist_init(struct guest_info * core, struct vmx_data * vmx_state) {
        int i = 0;
        pde32_4MB_t * pde = NULL;
 
-       PrintError("Setting up internal VMXASSIST page tables\n");
+       V3_Print(core->vm_info, core, "Setting up internal VMXASSIST page tables\n");
 
        if (v3_gpa_to_hva(core, VMXASSIST_1to1_PT, (addr_t *)(&pde)) == -1) {
-           PrintError("Could not find VMXASSIST 1to1 PT destination\n");
+           PrintError(core->vm_info, core, "Could not find VMXASSIST 1to1 PT destination\n");
            return -1;
        }
 
@@ -353,7 +350,7 @@ int v3_vmxassist_init(struct guest_info * core, struct vmx_data * vmx_state) {
            pde[i].large_page = 1;
            pde[i].page_base_addr = PAGE_BASE_ADDR_4MB(i * PAGE_SIZE_4MB);
 
-           //      PrintError("PDE %d: %x\n", i, *(uint32_t *)&(pde[i]));
+           //      PrintError(core->vm_info, core, "PDE %d: %x\n", i, *(uint32_t *)&(pde[i]));
        }
 
        core->ctrl_regs.cr3 = VMXASSIST_1to1_PT;
@@ -365,17 +362,14 @@ int v3_vmxassist_init(struct guest_info * core, struct vmx_data * vmx_state) {
 
        extern uint8_t v3_vmxassist_start[];
        extern uint8_t v3_vmxassist_end[];
-       addr_t vmxassist_dst = 0;
 
-       if (v3_gpa_to_hva(core, VMXASSIST_START, &vmxassist_dst) == -1) {
-           PrintError("Could not find VMXASSIST destination\n");
+       if (v3_write_gpa_memory(core, VMXASSIST_START, v3_vmxassist_end-v3_vmxassist_start,v3_vmxassist_start)!=v3_vmxassist_end-v3_vmxassist_start) { 
+           PrintError(core->vm_info, core, "Could not write VMXASSIST\n");
            return -1;
        }
 
-       memcpy((void *)vmxassist_dst, v3_vmxassist_start, v3_vmxassist_end - v3_vmxassist_start);
-
 
-       vmx_state->assist_state = VMXASSIST_DISABLED;
+       vmx_state->assist_state = VMXASSIST_OFF;
     }