X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fpalacios%2Fvmm_direct_paging.c;h=6bf987ecb2372ccfbaeafd87bc10dc4b463eb7b3;hb=774bac9fbb03ef8bf7c2ca2c79a8b87c9bc4c526;hp=9884620f5dbbd9be98e77032209bc640968854a9;hpb=ff30ed5923877636b2b51bed0349f9b440625137;p=palacios.git diff --git a/palacios/src/palacios/vmm_direct_paging.c b/palacios/src/palacios/vmm_direct_paging.c index 9884620..6bf987e 100644 --- a/palacios/src/palacios/vmm_direct_paging.c +++ b/palacios/src/palacios/vmm_direct_paging.c @@ -23,17 +23,27 @@ #include #include #include +#include -#ifndef DEBUG_NESTED_PAGING +#ifndef V3_CONFIG_DEBUG_NESTED_PAGING #undef PrintDebug #define PrintDebug(fmt, args...) #endif -static addr_t create_generic_pt_page() { +static addr_t create_generic_pt_page(struct guest_info *core) { void * page = 0; - page = V3_VAddr(V3_AllocPages(1)); + void *temp; + + temp = V3_AllocPagesExtended(1, PAGE_SIZE_4KB, -1, 0); // no constraints + + if (!temp) { + PrintError(VM_NONE, VCORE_NONE,"Cannot allocate page\n"); + return 0; + } + + page = V3_VAddr(temp); memset(page, 0, PAGE_SIZE); return (addr_t)page; @@ -44,19 +54,72 @@ static addr_t create_generic_pt_page() { #include "vmm_direct_paging_32pae.h" #include "vmm_direct_paging_64.h" +int v3_init_passthrough_pts(struct guest_info * info) { + info->direct_map_pt = (addr_t)V3_PAddr((void *)create_generic_pt_page(info)); + return 0; +} + + +int v3_free_passthrough_pts(struct guest_info * core) { + v3_cpu_mode_t mode = v3_get_vm_cpu_mode(core); + + // Delete the old direct map page tables + switch(mode) { + case REAL: + case PROTECTED: + // Intentional fallthrough here + // There are *only* PAE tables + case PROTECTED_PAE: + case LONG: + case LONG_32_COMPAT: + // Long mode will only use 32PAE page tables... + delete_page_tables_32pae((pdpe32pae_t *)V3_VAddr((void *)(core->direct_map_pt))); + break; + default: + PrintError(core->vm_info, core, "Unknown CPU Mode\n"); + return -1; + break; + } + + return 0; +} + + +int v3_reset_passthrough_pts(struct guest_info * core) { + + v3_free_passthrough_pts(core); + + // create new direct map page table + v3_init_passthrough_pts(core); + + return 0; +} + -addr_t v3_create_direct_passthrough_pts(struct guest_info * info) { - return create_generic_pt_page(); + +int v3_activate_passthrough_pt(struct guest_info * info) { + // For now... But we need to change this.... + // As soon as shadow paging becomes active the passthrough tables are hosed + // So this will cause chaos if it is called at that time + struct cr3_32_PAE * shadow_cr3 = (struct cr3_32_PAE *) &(info->ctrl_regs.cr3); + struct cr4_32 * shadow_cr4 = (struct cr4_32 *) &(info->ctrl_regs.cr4); + addr_t shadow_pt_addr = *(addr_t*)&(info->direct_map_pt); + // Passthrough PTs will only be PAE page tables. + shadow_cr3->pdpt_base_addr = shadow_pt_addr >> 5; + shadow_cr4->pae = 1; + PrintDebug(info->vm_info, info, "Activated Passthrough Page tables\n"); + return 0; } + int v3_handle_passthrough_pagefault(struct guest_info * info, addr_t fault_addr, pf_error_t error_code) { - v3_vm_cpu_mode_t mode = v3_get_cpu_mode(info); + v3_cpu_mode_t mode = v3_get_vm_cpu_mode(info); switch(mode) { case REAL: case PROTECTED: - return handle_passthrough_pagefault_32(info, fault_addr, error_code); - + // Note intentional fallthrough here + // There are only PAE page tables now case PROTECTED_PAE: case LONG: case LONG_32_COMPAT: @@ -64,7 +127,7 @@ int v3_handle_passthrough_pagefault(struct guest_info * info, addr_t fault_addr, return handle_passthrough_pagefault_32pae(info, fault_addr, error_code); default: - PrintError("Unknown CPU Mode\n"); + PrintError(info->vm_info, info, "Unknown CPU Mode\n"); break; } return -1; @@ -73,11 +136,10 @@ int v3_handle_passthrough_pagefault(struct guest_info * info, addr_t fault_addr, int v3_handle_nested_pagefault(struct guest_info * info, addr_t fault_addr, pf_error_t error_code) { - // THIS IS VERY BAD - v3_vm_cpu_mode_t mode = LONG; + v3_cpu_mode_t mode = v3_get_host_cpu_mode(); - PrintDebug("Nested PageFault: fault_addr=%p, error_code=%u\n",(void*)fault_addr, *(uint_t *)&error_code); + PrintDebug(info->vm_info, info, "Nested PageFault: fault_addr=%p, error_code=%u\n", (void *)fault_addr, *(uint_t *)&error_code); switch(mode) { case REAL: @@ -92,9 +154,109 @@ int v3_handle_nested_pagefault(struct guest_info * info, addr_t fault_addr, pf_e return handle_passthrough_pagefault_64(info, fault_addr, error_code); default: - PrintError("Unknown CPU Mode\n"); + PrintError(info->vm_info, info, "Unknown CPU Mode\n"); break; } return -1; } +int v3_invalidate_passthrough_addr(struct guest_info * info, addr_t inv_addr) { + v3_cpu_mode_t mode = v3_get_vm_cpu_mode(info); + + switch(mode) { + case REAL: + case PROTECTED: + // Intentional fallthrough - there + // are only PAE page tables now + case PROTECTED_PAE: + case LONG: + case LONG_32_COMPAT: + // Long mode will only use 32PAE page tables... + return invalidate_addr_32pae(info, inv_addr); + + default: + PrintError(info->vm_info, info, "Unknown CPU Mode\n"); + break; + } + return -1; +} + + +int v3_invalidate_passthrough_addr_range(struct guest_info * info, + addr_t inv_addr_start, addr_t inv_addr_end) { + v3_cpu_mode_t mode = v3_get_vm_cpu_mode(info); + + switch(mode) { + case REAL: + case PROTECTED: + // Intentional fallthrough + // There are only PAE PTs now + case PROTECTED_PAE: + case LONG: + case LONG_32_COMPAT: + // Long mode will only use 32PAE page tables... + return invalidate_addr_32pae_range(info, inv_addr_start, inv_addr_end); + + default: + PrintError(info->vm_info, info, "Unknown CPU Mode\n"); + break; + } + return -1; +} + +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: + case PROTECTED: + return invalidate_addr_32(info, inv_addr); + + case PROTECTED_PAE: + return invalidate_addr_32pae(info, inv_addr); + + case LONG: + case LONG_32_COMPAT: + return invalidate_addr_64(info, inv_addr); + + default: + PrintError(info->vm_info, info, "Unknown CPU Mode\n"); + break; + } + + return -1; +} + +int v3_invalidate_nested_addr_range(struct guest_info * info, + addr_t inv_addr_start, addr_t inv_addr_end) { + +#ifdef __V3_64BIT__ + v3_cpu_mode_t mode = LONG; +#else + v3_cpu_mode_t mode = PROTECTED; +#endif + + switch(mode) { + case REAL: + case PROTECTED: + return invalidate_addr_32_range(info, inv_addr_start, inv_addr_end); + + case PROTECTED_PAE: + return invalidate_addr_32pae_range(info, inv_addr_start, inv_addr_end); + + case LONG: + case LONG_32_COMPAT: + return invalidate_addr_64_range(info, inv_addr_start, inv_addr_end); + + default: + PrintError(info->vm_info, info, "Unknown CPU Mode\n"); + break; + } + + return -1; +}