X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fpalacios%2Fmmu%2Fvmm_shdw_pg_tlb.c;h=9c5545cb0d80b489cb5c1094e982189a42427545;hb=894733a198529cfaf93f4f4b68b255906154ab56;hp=050d6e7db72b40585866ae3f2d7950ccd201099c;hpb=fb16ffd793b51e356bd17a35b3929adbadd88e23;p=palacios.git diff --git a/palacios/src/palacios/mmu/vmm_shdw_pg_tlb.c b/palacios/src/palacios/mmu/vmm_shdw_pg_tlb.c index 050d6e7..9c5545c 100644 --- a/palacios/src/palacios/mmu/vmm_shdw_pg_tlb.c +++ b/palacios/src/palacios/mmu/vmm_shdw_pg_tlb.c @@ -12,6 +12,8 @@ * All rights reserved. * * Author: Jack Lange + * Author: Chunxiao Diao + * * * This is free software. You are permitted to use, * redistribute, and modify it as specified in the file "V3VEE_LICENSE". @@ -24,7 +26,7 @@ #include -#ifndef CONFIG_DEBUG_SHDW_PG_VTLB +#ifndef V3_CONFIG_DEBUG_SHDW_PG_VTLB #undef PrintDebug #define PrintDebug(fmt, ...) #endif @@ -52,6 +54,14 @@ static struct shadow_page_data * create_new_shadow_pt(struct guest_info * core); #include "vmm_shdw_pg_tlb_32pae.h" #include "vmm_shdw_pg_tlb_64.h" +static inline int get_constraints(struct guest_info *core) +{ + // the current version of VTLB does not require any constraints + // on where page tables are allocated since it will use + // 32PAE page tables on a 64 bit machine even in 32 bit mode and below + return 0; +} + static struct shadow_page_data * create_new_shadow_pt(struct guest_info * core) { struct v3_shdw_pg_state * state = &(core->shdw_pg_state); @@ -65,7 +75,7 @@ static struct shadow_page_data * create_new_shadow_pt(struct guest_info * core) if (page_tail->cr3 != cur_cr3) { - PrintDebug("Reusing old shadow Page: %p (cur_CR3=%p)(page_cr3=%p) \n", + PrintDebug(core->vm_info, core, "Reusing old shadow Page: %p (cur_CR3=%p)(page_cr3=%p) \n", (void *)(addr_t)page_tail->page_pa, (void *)(addr_t)cur_cr3, (void *)(addr_t)(page_tail->cr3)); @@ -82,9 +92,20 @@ static struct shadow_page_data * create_new_shadow_pt(struct guest_info * core) // else page_tail = (struct shadow_page_data *)V3_Malloc(sizeof(struct shadow_page_data)); - page_tail->page_pa = (addr_t)V3_AllocPages(1); - PrintDebug("Allocating new shadow Page: %p (cur_cr3=%p)\n", + if (!page_tail) { + PrintError(core->vm_info, core, "Cannot allocate\n"); + return NULL; + } + + page_tail->page_pa = (addr_t)V3_AllocPagesExtended(1,PAGE_SIZE_4KB,-1,get_constraints(core)); + + if (!page_tail->page_pa) { + PrintError(core->vm_info, core, "Cannot allocate page\n"); + return NULL; + } + + PrintDebug(core->vm_info, core, "Allocating new shadow Page: %p (cur_cr3=%p)\n", (void *)(addr_t)page_tail->page_pa, (void *)(addr_t)cur_cr3); @@ -101,23 +122,27 @@ static struct shadow_page_data * create_new_shadow_pt(struct guest_info * core) static int vtlb_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { - V3_Print("VTLB initialization\n"); + V3_Print(vm, VCORE_NONE, "VTLB initialization\n"); return 0; } static int vtlb_deinit(struct v3_vm_info * vm) { - return -1; + return 0; } static int vtlb_local_init(struct guest_info * core) { struct v3_shdw_pg_state * state = &(core->shdw_pg_state); struct vtlb_local_state * vtlb_state = NULL; - V3_Print("VTLB local initialization\n"); - + V3_Print(core->vm_info, core, "VTLB local initialization\n"); vtlb_state = (struct vtlb_local_state *)V3_Malloc(sizeof(struct vtlb_local_state)); + if (!vtlb_state) { + PrintError(core->vm_info, core, "Cannot allocate\n"); + return -1; + } + INIT_LIST_HEAD(&(vtlb_state->page_list)); state->local_impl_data = vtlb_state; @@ -126,20 +151,45 @@ static int vtlb_local_init(struct guest_info * core) { } +static int vtlb_local_deinit(struct guest_info * core) { + struct v3_shdw_pg_state * state = &(core->shdw_pg_state); + struct vtlb_local_state * vtlb_state = state->local_impl_data; + + struct shadow_page_data * shdw_pg = NULL; + struct shadow_page_data * tmp = NULL; + + // free page list... + list_for_each_entry_safe(shdw_pg, tmp, &(vtlb_state->page_list), page_list_node) { + list_del(&(shdw_pg->page_list_node)); + V3_FreePages((void *)shdw_pg->page_pa, 1); + V3_Free(shdw_pg); + } + + + V3_Free(vtlb_state); + + return 0; +} + + static int vtlb_activate_shdw_pt(struct guest_info * core) { switch (v3_get_vm_cpu_mode(core)) { case PROTECTED: return activate_shadow_pt_32(core); + break; case PROTECTED_PAE: return activate_shadow_pt_32pae(core); + break; case LONG: case LONG_32_COMPAT: case LONG_16_COMPAT: return activate_shadow_pt_64(core); + break; default: - PrintError("Invalid CPU mode: %s\n", v3_cpu_mode_to_str(v3_get_vm_cpu_mode(core))); + PrintError(core->vm_info, core, "Invalid CPU mode: %s\n", v3_cpu_mode_to_str(v3_get_vm_cpu_mode(core))); return -1; + break; } return 0; @@ -151,7 +201,7 @@ static int vtlb_invalidate_shdw_pt(struct guest_info * core) { static int vtlb_handle_pf(struct guest_info * core, addr_t fault_addr, pf_error_t error_code) { - + switch (v3_get_vm_cpu_mode(core)) { case PROTECTED: return handle_shadow_pagefault_32(core, fault_addr, error_code); @@ -164,7 +214,7 @@ static int vtlb_handle_pf(struct guest_info * core, addr_t fault_addr, pf_error_ return handle_shadow_pagefault_64(core, fault_addr, error_code); break; default: - PrintError("Unhandled CPU Mode: %s\n", v3_cpu_mode_to_str(v3_get_vm_cpu_mode(core))); + PrintError(core->vm_info, core, "Unhandled CPU Mode: %s\n", v3_cpu_mode_to_str(v3_get_vm_cpu_mode(core))); return -1; } } @@ -175,15 +225,19 @@ static int vtlb_handle_invlpg(struct guest_info * core, addr_t vaddr) { switch (v3_get_vm_cpu_mode(core)) { case PROTECTED: return handle_shadow_invlpg_32(core, vaddr); + break; case PROTECTED_PAE: return handle_shadow_invlpg_32pae(core, vaddr); + break; case LONG: case LONG_32_COMPAT: case LONG_16_COMPAT: return handle_shadow_invlpg_64(core, vaddr); + break; default: - PrintError("Invalid CPU mode: %s\n", v3_cpu_mode_to_str(v3_get_vm_cpu_mode(core))); + PrintError(core->vm_info, core, "Invalid CPU mode: %s\n", v3_cpu_mode_to_str(v3_get_vm_cpu_mode(core))); return -1; + break; } } @@ -192,6 +246,7 @@ static struct v3_shdw_pg_impl vtlb_impl = { .init = vtlb_init, .deinit = vtlb_deinit, .local_init = vtlb_local_init, + .local_deinit = vtlb_local_deinit, .handle_pagefault = vtlb_handle_pf, .handle_invlpg = vtlb_handle_invlpg, .activate_shdw_pt = vtlb_activate_shdw_pt,