From: Peter Dinda Date: Tue, 8 Sep 2015 22:32:22 +0000 (-0500) Subject: More init checks to allow graceful fail out when VM cannot be created X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?p=palacios.git;a=commitdiff_plain;h=9d346ee2cf8a7f2a79dc4929b8e0416de7d8f8c8;hp=e2a6eba59e9be18cbf5095df4da4d716cf1cf141 More init checks to allow graceful fail out when VM cannot be created --- diff --git a/palacios/include/palacios/vmm_direct_paging.h b/palacios/include/palacios/vmm_direct_paging.h index 07aec18..fc9d924 100644 --- a/palacios/include/palacios/vmm_direct_paging.h +++ b/palacios/include/palacios/vmm_direct_paging.h @@ -40,6 +40,7 @@ struct v3_passthrough_impl_state { // The externally visible state is just the callbacks v3_rw_lock_t event_callback_lock; struct list_head event_callback_list; + int inited; }; diff --git a/palacios/include/palacios/vmm_mem_hook.h b/palacios/include/palacios/vmm_mem_hook.h index 65e3322..21d0eef 100644 --- a/palacios/include/palacios/vmm_mem_hook.h +++ b/palacios/include/palacios/vmm_mem_hook.h @@ -42,6 +42,8 @@ struct v3_mem_hooks { /* We track memory hooks via a hash table */ /* keyed to the memory region pointer */ struct hashtable * reg_table; + + int inited; // structure needs to be deinited }; diff --git a/palacios/src/palacios/vmm_direct_paging.c b/palacios/src/palacios/vmm_direct_paging.c index 7c3e72f..b747ef1 100644 --- a/palacios/src/palacios/vmm_direct_paging.c +++ b/palacios/src/palacios/vmm_direct_paging.c @@ -407,6 +407,7 @@ int v3_init_passthrough_paging(struct v3_vm_info *vm) { INIT_LIST_HEAD(&(vm->passthrough_impl.event_callback_list)); v3_rw_lock_init(&(vm->passthrough_impl.event_callback_lock)); + vm->passthrough_impl.inited=1; return 0; } @@ -415,6 +416,10 @@ int v3_deinit_passthrough_paging(struct v3_vm_info *vm) struct passthrough_event_callback *cb,*temp; addr_t flags; + if (!vm->passthrough_impl.inited) { + return 0; + } + flags=v3_write_lock_irqsave(&(vm->passthrough_impl.event_callback_lock)); list_for_each_entry_safe(cb, diff --git a/palacios/src/palacios/vmm_mem_hook.c b/palacios/src/palacios/vmm_mem_hook.c index 1d49294..e4e1d98 100644 --- a/palacios/src/palacios/vmm_mem_hook.c +++ b/palacios/src/palacios/vmm_mem_hook.c @@ -81,6 +81,8 @@ int v3_init_mem_hooks(struct v3_vm_info * vm) { hooks->reg_table = v3_create_htable(0, mem_hash_fn, mem_eq_fn); + hooks->inited=1; + return 0; } @@ -93,6 +95,10 @@ int v3_deinit_mem_hooks(struct v3_vm_info * vm) { struct mem_hook * tmp = NULL; + if (!hooks->inited) { + return 0; + } + // 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