aboutsummaryrefslogtreecommitdiff
path: root/backends/hostmem.c
diff options
context:
space:
mode:
authorXiao Guangrong <guangrong.xiao@linux.intel.com>2016-07-13 12:18:06 +0800
committerPaolo Bonzini <pbonzini@redhat.com>2016-07-13 13:30:04 +0200
commit2aece63c8a9d2c3a8ff41d2febc4cdeff2633331 (patch)
tree02964fa0c17b241f41f4be55d1381eb8f2b24018 /backends/hostmem.c
parent1454d33f0507cb54d62ed80f494884157c9e7130 (diff)
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 <guangrong.xiao@linux.intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'backends/hostmem.c')
-rw-r--r--backends/hostmem.c15
1 files changed, 11 insertions, 4 deletions
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;