From 06329ccecfa022494fdba288b3ab5bcb8dff4159 Mon Sep 17 00:00:00 2001 From: Marcel Apfelbaum Date: Wed, 13 Dec 2017 16:37:37 +0200 Subject: mem: add share parameter to memory-backend-ram Currently only file backed memory backend can be created with a "share" flag in order to allow sharing guest RAM with other processes in the host. Add the "share" flag also to RAM Memory Backend in order to allow remapping parts of the guest RAM to different host virtual addresses. This is needed by the RDMA devices in order to remap non-contiguous QEMU virtual addresses to a contiguous virtual address range. Moved the "share" flag to the Host Memory base class, modified phys_mem_alloc to include the new parameter and a new interface memory_region_init_ram_shared_nomigrate. There are no functional changes if the new flag is not used. Reviewed-by: Eduardo Habkost Signed-off-by: Marcel Apfelbaum --- backends/hostmem-file.c | 25 +------------------------ backends/hostmem-ram.c | 4 ++-- backends/hostmem.c | 21 +++++++++++++++++++++ 3 files changed, 24 insertions(+), 26 deletions(-) (limited to 'backends') diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c index e319ec1..134b08d 100644 --- a/backends/hostmem-file.c +++ b/backends/hostmem-file.c @@ -31,7 +31,6 @@ typedef struct HostMemoryBackendFile HostMemoryBackendFile; struct HostMemoryBackendFile { HostMemoryBackend parent_obj; - bool share; bool discard_data; char *mem_path; uint64_t align; @@ -59,7 +58,7 @@ file_backend_memory_alloc(HostMemoryBackend *backend, Error **errp) path = object_get_canonical_path(OBJECT(backend)); memory_region_init_ram_from_file(&backend->mr, OBJECT(backend), path, - backend->size, fb->align, fb->share, + backend->size, fb->align, backend->share, fb->mem_path, errp); g_free(path); } @@ -86,25 +85,6 @@ static void set_mem_path(Object *o, const char *str, Error **errp) fb->mem_path = g_strdup(str); } -static bool file_memory_backend_get_share(Object *o, Error **errp) -{ - HostMemoryBackendFile *fb = MEMORY_BACKEND_FILE(o); - - return fb->share; -} - -static void file_memory_backend_set_share(Object *o, bool value, Error **errp) -{ - HostMemoryBackend *backend = MEMORY_BACKEND(o); - HostMemoryBackendFile *fb = MEMORY_BACKEND_FILE(o); - - if (host_memory_backend_mr_inited(backend)) { - error_setg(errp, "cannot change property value"); - return; - } - fb->share = value; -} - static bool file_memory_backend_get_discard_data(Object *o, Error **errp) { return MEMORY_BACKEND_FILE(o)->discard_data; @@ -171,9 +151,6 @@ file_backend_class_init(ObjectClass *oc, void *data) bc->alloc = file_backend_memory_alloc; oc->unparent = file_backend_unparent; - object_class_property_add_bool(oc, "share", - file_memory_backend_get_share, file_memory_backend_set_share, - &error_abort); object_class_property_add_bool(oc, "discard-data", file_memory_backend_get_discard_data, file_memory_backend_set_discard_data, &error_abort); diff --git a/backends/hostmem-ram.c b/backends/hostmem-ram.c index 38977be..7ddd08d 100644 --- a/backends/hostmem-ram.c +++ b/backends/hostmem-ram.c @@ -28,8 +28,8 @@ ram_backend_memory_alloc(HostMemoryBackend *backend, Error **errp) } path = object_get_canonical_path_component(OBJECT(backend)); - memory_region_init_ram_nomigrate(&backend->mr, OBJECT(backend), path, - backend->size, errp); + memory_region_init_ram_shared_nomigrate(&backend->mr, OBJECT(backend), path, + backend->size, backend->share, errp); g_free(path); } diff --git a/backends/hostmem.c b/backends/hostmem.c index 81d1455..8aa0412 100644 --- a/backends/hostmem.c +++ b/backends/hostmem.c @@ -368,6 +368,24 @@ static void set_id(Object *o, const char *str, Error **errp) backend->id = g_strdup(str); } +static bool host_memory_backend_get_share(Object *o, Error **errp) +{ + HostMemoryBackend *backend = MEMORY_BACKEND(o); + + return backend->share; +} + +static void host_memory_backend_set_share(Object *o, bool value, Error **errp) +{ + HostMemoryBackend *backend = MEMORY_BACKEND(o); + + if (host_memory_backend_mr_inited(backend)) { + error_setg(errp, "cannot change property value"); + return; + } + backend->share = value; +} + static void host_memory_backend_class_init(ObjectClass *oc, void *data) { @@ -398,6 +416,9 @@ host_memory_backend_class_init(ObjectClass *oc, void *data) host_memory_backend_get_policy, host_memory_backend_set_policy, &error_abort); object_class_property_add_str(oc, "id", get_id, set_id, &error_abort); + object_class_property_add_bool(oc, "share", + host_memory_backend_get_share, host_memory_backend_set_share, + &error_abort); } static void host_memory_backend_finalize(Object *o) -- cgit v1.1