From: Jack Lange Date: Fri, 29 Apr 2011 19:22:04 +0000 (-0500) Subject: can now boot linux (slowly) with EPT enabled X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=commitdiff_plain;h=40d79cccadcdeb5b4744bf965030b40b0d5cb1fb;p=palacios.git can now boot linux (slowly) with EPT enabled --- diff --git a/palacios/include/palacios/vmx_assist.h b/palacios/include/palacios/vmx_assist.h index e97f0dd..5a38743 100644 --- a/palacios/include/palacios/vmx_assist.h +++ b/palacios/include/palacios/vmx_assist.h @@ -26,6 +26,10 @@ #include +#define VMXASSIST_GDT 0x10000 +#define VMXASSIST_TSS 0x40000 +#define VMXASSIST_START 0xd0000 +#define VMXASSIST_1to1_PT 0xde000 // We'll shove this at the end, and pray to god VMXASSIST doesn't mess with it int v3_vmxassist_ctx_switch(struct guest_info * info); diff --git a/palacios/src/palacios/vmm_config_class.h b/palacios/src/palacios/vmm_config_class.h index 0c7ef4c..df42ea6 100644 --- a/palacios/src/palacios/vmm_config_class.h +++ b/palacios/src/palacios/vmm_config_class.h @@ -77,21 +77,12 @@ static int post_config_pc(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { } - if (vm->num_cores>1 && !v3_find_dev(vm,"apic")) { - PrintError("palacios: VM has more than one core, but no device named \"apic\"!\n"); - return -1; - } - - if (v3_find_dev(vm,"apic")) { - if (!v3_find_dev(vm,"ioapic")) { - PrintError("palacios: VM cores have apics, but there is no device named \"ioapic\"!\n"); - } + if (vm->num_cores > 1) { if (v3_inject_mptable(vm) == -1) { PrintError("Failed to inject mptable during configuration\n"); return -1; - } + } } - return 0; } diff --git a/palacios/src/palacios/vmm_direct_paging.c b/palacios/src/palacios/vmm_direct_paging.c index 6040e81..ca5b38a 100644 --- a/palacios/src/palacios/vmm_direct_paging.c +++ b/palacios/src/palacios/vmm_direct_paging.c @@ -169,7 +169,12 @@ int v3_invalidate_passthrough_addr(struct guest_info * info, addr_t inv_addr) { int v3_invalidate_nested_addr(struct guest_info * info, addr_t inv_addr) { + +#ifdef __V3_64BIT__ v3_cpu_mode_t mode = LONG; +#else + v3_cpu_mode_t mode = PROTECTED; +#endif switch(mode) { case REAL: diff --git a/palacios/src/palacios/vmm_direct_paging_32.h b/palacios/src/palacios/vmm_direct_paging_32.h index b211ad9..e90c3da 100644 --- a/palacios/src/palacios/vmm_direct_paging_32.h +++ b/palacios/src/palacios/vmm_direct_paging_32.h @@ -129,12 +129,16 @@ static inline int invalidate_addr_32(struct guest_info * info, addr_t inv_addr) return 0; } else if (pde[pde_index].large_page) { pde[pde_index].present = 0; + pde[pde_index].writable = 0; + pde[pde_index].user_page = 0; return 0; } pte = V3_VAddr((void*)BASE_TO_PAGE_ADDR(pde[pde_index].pt_base_addr)); pte[pte_index].present = 0; + pte[pte_index].writable = 0; + pte[pte_index].user_page = 0; return 0; } diff --git a/palacios/src/palacios/vmm_direct_paging_64.h b/palacios/src/palacios/vmm_direct_paging_64.h index baae5d5..c428352 100644 --- a/palacios/src/palacios/vmm_direct_paging_64.h +++ b/palacios/src/palacios/vmm_direct_paging_64.h @@ -218,6 +218,8 @@ static inline int invalidate_addr_64(struct guest_info * core, addr_t inv_addr) return 0; } else if (pdpe[pdpe_index].large_page == 1) { // 1GiB pdpe[pdpe_index].present = 0; + pdpe[pdpe_index].writable = 0; + pdpe[pdpe_index].user_page = 0; return 0; } @@ -227,12 +229,16 @@ static inline int invalidate_addr_64(struct guest_info * core, addr_t inv_addr) return 0; } else if (pde[pde_index].large_page == 1) { // 2MiB pde[pde_index].present = 0; + pde[pde_index].writable = 0; + pde[pde_index].user_page = 0; return 0; } pte = V3_VAddr((void*)BASE_TO_PAGE_ADDR(pde[pde_index].pt_base_addr)); pte[pte_index].present = 0; // 4KiB + pte[pte_index].writable = 0; + pte[pte_index].user_page = 0; return 0; } diff --git a/palacios/src/palacios/vmx.c b/palacios/src/palacios/vmx.c index a525e87..c4b951f 100644 --- a/palacios/src/palacios/vmx.c +++ b/palacios/src/palacios/vmx.c @@ -189,9 +189,9 @@ static int init_vmcs_bios(struct guest_info * core, struct vmx_data * vmx_state) vmx_state->pri_proc_ctrls.hlt_exit = 1; - vmx_state->pri_proc_ctrls.invlpg_exit = 1; - vmx_state->pri_proc_ctrls.pause_exit = 1; + + vmx_state->pri_proc_ctrls.pause_exit = 0; vmx_state->pri_proc_ctrls.tsc_offset = 1; #ifdef CONFIG_TIME_VIRTUALIZE_TSC vmx_state->pri_proc_ctrls.rdtsc_exit = 1; @@ -249,6 +249,8 @@ static int init_vmcs_bios(struct guest_info * core, struct vmx_data * vmx_state) vmx_state->pri_proc_ctrls.cr3_ld_exit = 1; vmx_state->pri_proc_ctrls.cr3_str_exit = 1; + vmx_state->pri_proc_ctrls.invlpg_exit = 1; + /* Add page fault exits */ vmx_state->excp_bmap.pf = 1; @@ -267,12 +269,14 @@ static int init_vmcs_bios(struct guest_info * core, struct vmx_data * vmx_state) // vmx_state->pinbased_ctrls |= NMI_EXIT; - /* Add CR exits */ - //vmx_state->pri_proc_ctrls.cr3_ld_exit = 1; - //vmx_state->pri_proc_ctrls.cr3_str_exit = 1; + /* Disable CR exits */ + vmx_state->pri_proc_ctrls.cr3_ld_exit = 0; + vmx_state->pri_proc_ctrls.cr3_str_exit = 0; + + vmx_state->pri_proc_ctrls.invlpg_exit = 0; /* Add page fault exits */ - vmx_state->excp_bmap.pf = 1; // This should never happen..., enabled to catch bugs + // vmx_state->excp_bmap.pf = 1; // This should never happen..., enabled to catch bugs // Setup VMX Assist v3_vmxassist_init(core, vmx_state); @@ -297,6 +301,7 @@ static int init_vmcs_bios(struct guest_info * core, struct vmx_data * vmx_state) int i = 0; // For now we will assume that unrestricted guest mode is assured w/ EPT + core->vm_regs.rsp = 0x00; core->rip = 0xfff0; core->vm_regs.rdx = 0x00000f00; @@ -368,6 +373,12 @@ static int init_vmcs_bios(struct guest_info * core, struct vmx_data * vmx_state) vmx_state->exit_ctrls.ld_efer = 1; vmx_state->exit_ctrls.save_efer = 1; + /* Disable shadow paging stuff */ + vmx_state->pri_proc_ctrls.cr3_ld_exit = 0; + vmx_state->pri_proc_ctrls.cr3_str_exit = 0; + + vmx_state->pri_proc_ctrls.invlpg_exit = 0; + if (v3_init_ept(core, &hw_info) == -1) { PrintError("Error initializing EPT\n"); diff --git a/palacios/src/palacios/vmx_assist.c b/palacios/src/palacios/vmx_assist.c index d7d84ea..cfea9bb 100644 --- a/palacios/src/palacios/vmx_assist.c +++ b/palacios/src/palacios/vmx_assist.c @@ -28,10 +28,7 @@ #define PrintDebug(fmt, args...) #endif -#define VMXASSIST_GDT 0x10000 -#define VMXASSIST_TSS 0x40000 -#define VMXASSIST_START 0xd0000 -#define VMXASSIST_1to1_PT 0xde000 // We'll shove this at the end, and pray to god VMXASSIST doesn't mess with it + #define VMXASSIST_MAGIC 0x17101966 diff --git a/palacios/src/palacios/vmx_ctrl_regs.c b/palacios/src/palacios/vmx_ctrl_regs.c index 685de90..7aa7361 100644 --- a/palacios/src/palacios/vmx_ctrl_regs.c +++ b/palacios/src/palacios/vmx_ctrl_regs.c @@ -27,10 +27,12 @@ #include #include +#if 0 #ifndef CONFIG_DEBUG_VMX #undef PrintDebug #define PrintDebug(fmt, args...) #endif +#endif static v3_reg_t * get_reg_ptr(struct guest_info * info, struct vmx_exit_cr_qual * cr_qual); static int handle_mov_to_cr0(struct guest_info * info, v3_reg_t * new_val, struct vmx_exit_info * exit_info); @@ -192,7 +194,7 @@ static int handle_mov_to_cr0(struct guest_info * info, v3_reg_t * new_cr0, struc guest_cr0->pg = 1; guest_cr0->ne = 1; - if (paging_transition) { + if ((paging_transition)) { // Paging transition if (v3_get_vm_mem_mode(info) == VIRTUAL_MEM) { @@ -209,14 +211,24 @@ static int handle_mov_to_cr0(struct guest_info * info, v3_reg_t * new_cr0, struc // PrintDebug("Activating Shadow Page tables\n"); - if (v3_activate_shadow_pt(info) == -1) { - PrintError("Failed to activate shadow page tables\n"); - return -1; + if (info->shdw_pg_mode == SHADOW_PAGING) { + if (v3_activate_shadow_pt(info) == -1) { + PrintError("Failed to activate shadow page tables\n"); + return -1; + } } - } else if (v3_activate_passthrough_pt(info) == -1) { - PrintError("Failed to activate passthrough page tables\n"); - return -1; + } else { + + if (info->shdw_pg_mode == SHADOW_PAGING) { + if (v3_activate_passthrough_pt(info) == -1) { + PrintError("Failed to activate passthrough page tables\n"); + return -1; + } + } else { + // This is hideous... Let's hope that the 1to1 page table has not been nuked... + info->ctrl_regs.cr3 = VMXASSIST_1to1_PT; + } } } }