From 1454d33f0507cb54d62ed80f494884157c9e7130 Mon Sep 17 00:00:00 2001 From: Xiao Guangrong Date: Wed, 13 Jul 2016 12:18:05 +0800 Subject: hostmem: fix QEMU crash by 'info memdev' 'info memdev' crashes QEMU: (qemu) info memdev Unexpected error in parse_str() at qapi/string-input-visitor.c:111: Parameter 'null' expects an int64 value or range It is caused by null uint16List is returned if 'host-nodes' is the default value Return MAX_NODES under this case to fix this bug Signed-off-by: Xiao Guangrong Signed-off-by: Paolo Bonzini --- backends/hostmem.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'backends/hostmem.c') diff --git a/backends/hostmem.c b/backends/hostmem.c index 6e28be11eb..8dede4db2e 100644 --- a/backends/hostmem.c +++ b/backends/hostmem.c @@ -64,6 +64,14 @@ out: error_propagate(errp, local_err); } +static uint16List **host_memory_append_node(uint16List **node, + unsigned long value) +{ + *node = g_malloc0(sizeof(**node)); + (*node)->value = value; + return &(*node)->next; +} + static void host_memory_backend_get_host_nodes(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) @@ -74,25 +82,23 @@ host_memory_backend_get_host_nodes(Object *obj, Visitor *v, const char *name, unsigned long value; value = find_first_bit(backend->host_nodes, MAX_NODES); + + node = host_memory_append_node(node, value); + if (value == MAX_NODES) { - return; + goto out; } - *node = g_malloc0(sizeof(**node)); - (*node)->value = value; - node = &(*node)->next; - do { value = find_next_bit(backend->host_nodes, MAX_NODES, value + 1); if (value == MAX_NODES) { break; } - *node = g_malloc0(sizeof(**node)); - (*node)->value = value; - node = &(*node)->next; + node = host_memory_append_node(node, value); } while (true); +out: visit_type_uint16List(v, name, &host_nodes, errp); } -- cgit v1.2.3 From 2aece63c8a9d2c3a8ff41d2febc4cdeff2633331 Mon Sep 17 00:00:00 2001 From: Xiao Guangrong Date: Wed, 13 Jul 2016 12:18:06 +0800 Subject: hostmem: detect host backend memory is being used properly Currently, we use memory_region_is_mapped() to detect if the host backend memory is being used. This works if the memory is directly mapped into guest's address space, however, it is not true for nvdimm as it uses aliased memory region to map the memory. This is why this bug can happen: https://bugzilla.redhat.com/show_bug.cgi?id=1352769 Fix it by introduce a new filed, is_mapped, to HostMemoryBackend, we set/clear this filed accordingly when the device link/unlink to host backend memory Signed-off-by: Xiao Guangrong Signed-off-by: Paolo Bonzini --- backends/hostmem.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'backends/hostmem.c') diff --git a/backends/hostmem.c b/backends/hostmem.c index 8dede4db2e..ac802570a8 100644 --- a/backends/hostmem.c +++ b/backends/hostmem.c @@ -264,6 +264,16 @@ host_memory_backend_get_memory(HostMemoryBackend *backend, Error **errp) return memory_region_size(&backend->mr) ? &backend->mr : NULL; } +void host_memory_backend_set_mapped(HostMemoryBackend *backend, bool mapped) +{ + backend->is_mapped = mapped; +} + +bool host_memory_backend_is_mapped(HostMemoryBackend *backend) +{ + return backend->is_mapped; +} + static void host_memory_backend_memory_complete(UserCreatable *uc, Error **errp) { @@ -341,10 +351,7 @@ host_memory_backend_memory_complete(UserCreatable *uc, Error **errp) static bool host_memory_backend_can_be_deleted(UserCreatable *uc, Error **errp) { - MemoryRegion *mr; - - mr = host_memory_backend_get_memory(MEMORY_BACKEND(uc), errp); - if (memory_region_is_mapped(mr)) { + if (host_memory_backend_is_mapped(MEMORY_BACKEND(uc))) { return false; } else { return true; -- cgit v1.2.3