X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fpalacios%2Fvmm_direct_paging.c;h=421c3aa244f78b9861e797722ecf860a8032e048;hb=25aec1d035e5a740d8c1cb936d7633b6bb5751f1;hp=821d7b369159ca09024fdf7a88f28077f5ad94d7;hpb=1fe82881720f7f9f64f789871f763aca93b47a7e;p=palacios.git diff --git a/palacios/src/palacios/vmm_direct_paging.c b/palacios/src/palacios/vmm_direct_paging.c index 821d7b3..421c3aa 100644 --- a/palacios/src/palacios/vmm_direct_paging.c +++ b/palacios/src/palacios/vmm_direct_paging.c @@ -24,9 +24,24 @@ #include #include + +#ifndef V3_CONFIG_DEBUG_NESTED_PAGING +#undef PrintDebug +#define PrintDebug(fmt, args...) +#endif + + static addr_t create_generic_pt_page() { void * page = 0; - page = V3_VAddr(V3_AllocPages(1)); + void *temp; + + temp = V3_AllocPages(1); + if (!temp) { + PrintError("Cannot allocate page\n"); + return 0; + } + + page = V3_VAddr(temp); memset(page, 0, PAGE_SIZE); return (addr_t)page; @@ -37,13 +52,62 @@ 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()); + 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: + delete_page_tables_32((pde32_t *)V3_VAddr((void *)(core->direct_map_pt))); + break; + 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("Unknown CPU Mode\n"); + return -1; + break; + } + + return 0; +} + + +int v3_reset_passthrough_pts(struct guest_info * core) { -addr_t v3_create_direct_passthrough_pts(struct guest_info * info) { - return create_generic_pt_page(); + v3_free_passthrough_pts(core); + + // create new direct map page table + v3_init_passthrough_pts(core); + + return 0; } + + +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 + + info->ctrl_regs.cr3 = *(addr_t*)&(info->direct_map_pt); + //PrintError("Activate Passthrough Page tables not implemented\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: @@ -66,8 +130,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); switch(mode) { case REAL: @@ -88,3 +154,52 @@ int v3_handle_nested_pagefault(struct guest_info * info, addr_t fault_addr, pf_e 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: + return invalidate_addr_32(info, inv_addr); + + 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("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("Unknown CPU Mode\n"); + break; + } + + return -1; +}