From: Jack Lange Date: Wed, 12 Jan 2011 05:16:43 +0000 (-0600) Subject: uninitializing of memory hooks and host events X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=commitdiff_plain;h=2a9554f33cc3bdaab08d59ac54d6dd1f4472285d;p=palacios.git uninitializing of memory hooks and host events --- diff --git a/palacios/include/palacios/vmm_host_events.h b/palacios/include/palacios/vmm_host_events.h index c811373..15bcb7d 100644 --- a/palacios/include/palacios/vmm_host_events.h +++ b/palacios/include/palacios/vmm_host_events.h @@ -92,6 +92,7 @@ struct v3_host_events { int v3_init_host_events(struct v3_vm_info * vm); +int v3_deinit_host_events(struct v3_vm_info * vm); #define V3_HOST_EVENT_HANDLER(cb) ((union v3_host_event_handler)cb) diff --git a/palacios/include/palacios/vmm_mem_hook.h b/palacios/include/palacios/vmm_mem_hook.h index e30ecf7..7184c68 100644 --- a/palacios/include/palacios/vmm_mem_hook.h +++ b/palacios/include/palacios/vmm_mem_hook.h @@ -30,12 +30,11 @@ struct v3_mem_hooks { void * hook_hvas; // this is an array of pages, equal to the number of cores struct list_head hook_list; - }; int v3_init_mem_hooks(struct v3_vm_info * vm); - +int v3_deinit_mem_hooks(struct v3_vm_info * vm); int v3_hook_full_mem(struct v3_vm_info * vm, uint16_t core_id, addr_t guest_addr_start, addr_t guest_addr_end, diff --git a/palacios/src/palacios/vm_guest.c b/palacios/src/palacios/vm_guest.c index 92d206f..03de4f0 100644 --- a/palacios/src/palacios/vm_guest.c +++ b/palacios/src/palacios/vm_guest.c @@ -560,7 +560,15 @@ int v3_free_vm_internal(struct v3_vm_info * vm) { v3_deinit_dev_mgr(vm); - + v3_deinit_time_vm(vm); + + v3_deinit_shdw_impl(vm); + v3_deinit_mem_hooks(vm); + v3_delete_mem_map(vm); + + v3_deinit_intr_routers(vm); + v3_deinit_host_events(vm); + return 0; } diff --git a/palacios/src/palacios/vmm.c b/palacios/src/palacios/vmm.c index 580a514..13ae2ef 100644 --- a/palacios/src/palacios/vmm.c +++ b/palacios/src/palacios/vmm.c @@ -302,16 +302,14 @@ int v3_free_vm(struct v3_vm_info * vm) { v3_free_vm_devices(vm); + // free cores for (i = 0; i < vm->num_cores; i++) { - // free cores - v3_free_core(&(vm->cores[i])); - } + // free vm v3_free_vm_internal(vm); - // free vm return 0; } diff --git a/palacios/src/palacios/vmm_host_events.c b/palacios/src/palacios/vmm_host_events.c index 2f52e30..432b9fb 100644 --- a/palacios/src/palacios/vmm_host_events.c +++ b/palacios/src/palacios/vmm_host_events.c @@ -35,6 +35,48 @@ int v3_init_host_events(struct v3_vm_info * vm) { return 0; } +int v3_deinit_host_events(struct v3_vm_info * vm) { + struct v3_host_events * host_evts = &(vm->host_event_hooks); + struct v3_host_event_hook * hook = NULL; + struct v3_host_event_hook * tmp = NULL; + + list_for_each_entry_safe(hook, tmp, &(host_evts->keyboard_events), link) { + list_del(&(hook->link)); + V3_Free(hook); + } + + list_for_each_entry_safe(hook, tmp, &(host_evts->mouse_events), link) { + list_del(&(hook->link)); + V3_Free(hook); + } + + + list_for_each_entry_safe(hook, tmp, &(host_evts->timer_events), link) { + list_del(&(hook->link)); + V3_Free(hook); + } + + + list_for_each_entry_safe(hook, tmp, &(host_evts->serial_events), link) { + list_del(&(hook->link)); + V3_Free(hook); + } + + + list_for_each_entry_safe(hook, tmp, &(host_evts->console_events), link) { + list_del(&(hook->link)); + V3_Free(hook); + } + + + list_for_each_entry_safe(hook, tmp, &(host_evts->packet_events), link) { + list_del(&(hook->link)); + V3_Free(hook); + } + + return 0; +} + int v3_hook_host_event(struct v3_vm_info * vm, v3_host_evt_type_t event_type, diff --git a/palacios/src/palacios/vmm_mem_hook.c b/palacios/src/palacios/vmm_mem_hook.c index 46ee1fd..46c84cc 100644 --- a/palacios/src/palacios/vmm_mem_hook.c +++ b/palacios/src/palacios/vmm_mem_hook.c @@ -32,12 +32,16 @@ struct mem_hook { void * priv_data; addr_t hook_hva; - + struct v3_mem_region * region; + struct list_head hook_node; }; +static int free_hook(struct v3_vm_info * vm, struct mem_hook * hook); + + int v3_init_mem_hooks(struct v3_vm_info * vm) { struct v3_mem_hooks * hooks = &(vm->mem_hooks); @@ -49,6 +53,29 @@ int v3_init_mem_hooks(struct v3_vm_info * vm) { } +// We'll assume the actual hooks were either already cleared, +// or will be cleared by the memory map +int v3_deinit_mem_hooks(struct v3_vm_info * vm) { + struct v3_mem_hooks * hooks = &(vm->mem_hooks); + struct mem_hook * hook = NULL; + struct mem_hook * tmp = NULL; + + + // This is nasty... + // We delete the hook info but leave its memory region intact + // We rely on the memory map to clean up any orphaned regions as a result of this + // This needs to be fixed at some point... + list_for_each_entry_safe(hook, tmp, &(hooks->hook_list), hook_node) { + free_hook(vm, hook); + } + + + V3_FreePages(V3_PAddr(hooks->hook_hvas), vm->num_cores); + + return 0; +} + + static int handle_mem_hook(struct guest_info * info, addr_t guest_va, addr_t guest_pa, @@ -108,7 +135,7 @@ int v3_hook_write_mem(struct v3_vm_info * vm, uint16_t core_id, void * priv_data) { struct v3_mem_region * entry = NULL; struct mem_hook * hook = V3_Malloc(sizeof(struct mem_hook)); - // struct v3_mem_hooks * hooks = &(vm->mem_hooks); + struct v3_mem_hooks * hooks = &(vm->mem_hooks); memset(hook, 0, sizeof(struct mem_hook)); @@ -119,6 +146,8 @@ int v3_hook_write_mem(struct v3_vm_info * vm, uint16_t core_id, entry = v3_create_mem_region(vm, core_id, guest_addr_start, guest_addr_end); + hook->region = entry; + entry->host_addr = host_addr; entry->unhandled = handle_mem_hook; entry->priv_data = hook; @@ -133,6 +162,8 @@ int v3_hook_write_mem(struct v3_vm_info * vm, uint16_t core_id, return -1; } + list_add(&(hook->hook_node), &(hooks->hook_list)); + return 0; } @@ -146,7 +177,7 @@ int v3_hook_full_mem(struct v3_vm_info * vm, uint16_t core_id, struct v3_mem_region * entry = NULL; struct mem_hook * hook = V3_Malloc(sizeof(struct mem_hook)); - // struct v3_mem_hooks * hooks = &(vm->mem_hooks); + struct v3_mem_hooks * hooks = &(vm->mem_hooks); memset(hook, 0, sizeof(struct mem_hook)); @@ -156,6 +187,7 @@ int v3_hook_full_mem(struct v3_vm_info * vm, uint16_t core_id, hook->hook_hva = (addr_t)0xfff; entry = v3_create_mem_region(vm, core_id, guest_addr_start, guest_addr_end); + hook->region = entry; entry->unhandled = handle_mem_hook; entry->priv_data = hook; @@ -166,10 +198,22 @@ int v3_hook_full_mem(struct v3_vm_info * vm, uint16_t core_id, return -1; } + list_add(&(hook->hook_node), &(hooks->hook_list)); + + return 0; } +static int free_hook(struct v3_vm_info * vm, struct mem_hook * hook) { + v3_delete_mem_region(vm, hook->region); + list_del(&(hook->hook_node)); + + V3_Free(hook); + + return 0; +} + // This will unhook the memory hook registered at start address // We do not support unhooking subregions @@ -177,11 +221,10 @@ int v3_unhook_mem(struct v3_vm_info * vm, uint16_t core_id, addr_t guest_addr_st struct v3_mem_region * reg = v3_get_mem_region(vm, core_id, guest_addr_start); struct mem_hook * hook = reg->priv_data; - V3_Free(hook); - - v3_delete_mem_region(vm, reg); + free_hook(vm, hook); return 0; } + diff --git a/palacios/src/palacios/vmm_time.c b/palacios/src/palacios/vmm_time.c index 010a8e2..51fbba7 100644 --- a/palacios/src/palacios/vmm_time.c +++ b/palacios/src/palacios/vmm_time.c @@ -306,7 +306,7 @@ void v3_deinit_time_vm(struct v3_vm_info * vm) { v3_unhook_msr(vm, TSC_MSR); v3_unhook_msr(vm, TSC_AUX_MSR); - // v3_remove_hypercall(vm, TIME_CPUFREQ_HCALL); + v3_remove_hypercall(vm, TIME_CPUFREQ_HCALL); } void v3_init_time_core(struct guest_info * info) {