Remove unmapped/freed memory regions from the object property list.

This commit fixes the following issues:
- Any unmapped/free'd memory regions (MemoryRegion instances) are not
  removed from the object property linked list of its owner (which is
  always qdev_get_machine(uc)). This issue makes adding new memory
  mapping by calling mem_map() or mem_map_ptr() slower as more and more
  memory pages are mapped and unmapped - yes, even if those memory pages
  are unmapped, they still impact the speed of future memory page
  mappings due to this issue.
- FlatView is not reconstructed after a memory region is freed during
  unmapping, which leads to a use-after-free the next time a new memory
  region is mapped in address_space_update_topology().
This commit is contained in:
Fish 2016-10-20 03:33:37 -07:00
parent 67905ab147
commit ad7ae63e92
15 changed files with 8 additions and 15 deletions

View File

@ -2176,7 +2176,6 @@
#define object_property_allow_set_link object_property_allow_set_link_aarch64
#define object_property_del object_property_del_aarch64
#define object_property_del_all object_property_del_all_aarch64
#define object_property_del_child object_property_del_child_aarch64
#define object_property_find object_property_find_aarch64
#define object_property_get object_property_get_aarch64
#define object_property_get_bool object_property_get_bool_aarch64

View File

@ -2176,7 +2176,6 @@
#define object_property_allow_set_link object_property_allow_set_link_arm
#define object_property_del object_property_del_arm
#define object_property_del_all object_property_del_all_arm
#define object_property_del_child object_property_del_child_arm
#define object_property_find object_property_find_arm
#define object_property_get object_property_get_arm
#define object_property_get_bool object_property_get_bool_arm

View File

@ -2182,7 +2182,6 @@ symbols = (
'object_property_allow_set_link',
'object_property_del',
'object_property_del_all',
'object_property_del_child',
'object_property_find',
'object_property_get',
'object_property_get_bool',

View File

@ -810,6 +810,8 @@ ObjectProperty *object_property_add(Object *obj, const char *name,
void object_property_del(struct uc_struct *uc, Object *obj, const char *name, Error **errp);
void object_property_del_child(struct uc_struct *uc, Object *obj, Object *child, Error **errp);
/**
* object_property_find:
* @obj: the object

View File

@ -2176,7 +2176,6 @@
#define object_property_allow_set_link object_property_allow_set_link_m68k
#define object_property_del object_property_del_m68k
#define object_property_del_all object_property_del_all_m68k
#define object_property_del_child object_property_del_child_m68k
#define object_property_find object_property_find_m68k
#define object_property_get object_property_get_m68k
#define object_property_get_bool object_property_get_bool_m68k

View File

@ -66,6 +66,8 @@ MemoryRegion *memory_map_ptr(struct uc_struct *uc, hwaddr begin, size_t size, ui
return ram;
}
static void memory_region_update_container_subregions(MemoryRegion *subregion);
void memory_unmap(struct uc_struct *uc, MemoryRegion *mr)
{
int i;
@ -79,7 +81,6 @@ void memory_unmap(struct uc_struct *uc, MemoryRegion *mr)
tlb_flush_page(uc->current_cpu, addr);
}
}
mr->enabled = false;
memory_region_del_subregion(get_system_memory(uc), mr);
for (i = 0; i < uc->mapped_block_count; i++) {
@ -94,6 +95,7 @@ void memory_unmap(struct uc_struct *uc, MemoryRegion *mr)
g_free(mr->ioeventfds);
g_free((char *)mr->name);
mr->name = NULL;
object_property_del_child(mr->uc, qdev_get_machine(mr->uc), obj, &error_abort);
break;
}
}
@ -105,7 +107,6 @@ int memory_free(struct uc_struct *uc)
Object *obj;
int i;
get_system_memory(uc)->enabled = false;
for (i = 0; i < uc->mapped_block_count; i++) {
mr = uc->mapped_blocks[i];
mr->enabled = false;
@ -115,6 +116,7 @@ int memory_free(struct uc_struct *uc)
obj->ref = 1;
obj->free = g_free;
g_free(mr->ioeventfds);
object_property_del_child(mr->uc, qdev_get_machine(mr->uc), obj, &error_abort);
}
return 0;

View File

@ -2176,7 +2176,6 @@
#define object_property_allow_set_link object_property_allow_set_link_mips
#define object_property_del object_property_del_mips
#define object_property_del_all object_property_del_all_mips
#define object_property_del_child object_property_del_child_mips
#define object_property_find object_property_find_mips
#define object_property_get object_property_get_mips
#define object_property_get_bool object_property_get_bool_mips

View File

@ -2176,7 +2176,6 @@
#define object_property_allow_set_link object_property_allow_set_link_mips64
#define object_property_del object_property_del_mips64
#define object_property_del_all object_property_del_all_mips64
#define object_property_del_child object_property_del_child_mips64
#define object_property_find object_property_find_mips64
#define object_property_get object_property_get_mips64
#define object_property_get_bool object_property_get_bool_mips64

View File

@ -2176,7 +2176,6 @@
#define object_property_allow_set_link object_property_allow_set_link_mips64el
#define object_property_del object_property_del_mips64el
#define object_property_del_all object_property_del_all_mips64el
#define object_property_del_child object_property_del_child_mips64el
#define object_property_find object_property_find_mips64el
#define object_property_get object_property_get_mips64el
#define object_property_get_bool object_property_get_bool_mips64el

View File

@ -2176,7 +2176,6 @@
#define object_property_allow_set_link object_property_allow_set_link_mipsel
#define object_property_del object_property_del_mipsel
#define object_property_del_all object_property_del_all_mipsel
#define object_property_del_child object_property_del_child_mipsel
#define object_property_find object_property_find_mipsel
#define object_property_get object_property_get_mipsel
#define object_property_get_bool object_property_get_bool_mipsel

View File

@ -14,6 +14,7 @@
#define memory_map_ptr memory_map_ptr_powerpc
#define memory_unmap memory_unmap_powerpc
#define memory_free memory_free_powerpc
#define free_code_gen_buffer free_code_gen_buffer_powerpc
#define helper_raise_exception helper_raise_exception_powerpc
#define tcg_enabled tcg_enabled_powerpc
#define tcg_exec_init tcg_exec_init_powerpc
@ -2175,7 +2176,6 @@
#define object_property_allow_set_link object_property_allow_set_link_powerpc
#define object_property_del object_property_del_powerpc
#define object_property_del_all object_property_del_all_powerpc
#define object_property_del_child object_property_del_child_powerpc
#define object_property_find object_property_find_powerpc
#define object_property_get object_property_get_powerpc
#define object_property_get_bool object_property_get_bool_powerpc

View File

@ -371,7 +371,7 @@ static void object_property_del_all(struct uc_struct *uc, Object *obj)
}
}
static void object_property_del_child(struct uc_struct *uc, Object *obj, Object *child, Error **errp)
void object_property_del_child(struct uc_struct *uc, Object *obj, Object *child, Error **errp)
{
ObjectProperty *prop;

View File

@ -2176,7 +2176,6 @@
#define object_property_allow_set_link object_property_allow_set_link_sparc
#define object_property_del object_property_del_sparc
#define object_property_del_all object_property_del_all_sparc
#define object_property_del_child object_property_del_child_sparc
#define object_property_find object_property_find_sparc
#define object_property_get object_property_get_sparc
#define object_property_get_bool object_property_get_bool_sparc

View File

@ -2176,7 +2176,6 @@
#define object_property_allow_set_link object_property_allow_set_link_sparc64
#define object_property_del object_property_del_sparc64
#define object_property_del_all object_property_del_all_sparc64
#define object_property_del_child object_property_del_child_sparc64
#define object_property_find object_property_find_sparc64
#define object_property_get object_property_get_sparc64
#define object_property_get_bool object_property_get_bool_sparc64

View File

@ -2176,7 +2176,6 @@
#define object_property_allow_set_link object_property_allow_set_link_x86_64
#define object_property_del object_property_del_x86_64
#define object_property_del_all object_property_del_all_x86_64
#define object_property_del_child object_property_del_child_x86_64
#define object_property_find object_property_find_x86_64
#define object_property_get object_property_get_x86_64
#define object_property_get_bool object_property_get_bool_x86_64