From cc57501dee37376d0a2fbc5921e0f3a9ed4b117d Mon Sep 17 00:00:00 2001 From: Igor Mammedov Date: Mon, 19 Oct 2015 19:11:11 +0200 Subject: file_ram_alloc: propagate error to caller instead of terminating QEMU QEMU shouldn't exits from file_ram_alloc() if -mem-prealloc option is specified and "object_add memory-backend-file,..." fails allocation during memory hotplug. Propagate error to a caller and let it decide what to do with allocation failure. That leaves QEMU alive if it can't create backend during hotplug time and kills QEMU at startup time if backends or initial memory were misconfigured/ too large. Signed-off-by: Igor Mammedov Message-Id: <1445274671-17704-1-git-send-email-imammedo@redhat.com> Signed-off-by: Paolo Bonzini --- exec.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'exec.c') diff --git a/exec.c b/exec.c index 8af2570579..7431f2f449 100644 --- a/exec.c +++ b/exec.c @@ -1282,10 +1282,6 @@ static void *file_ram_alloc(RAMBlock *block, return area; error: - if (mem_prealloc) { - error_report("%s", error_get_pretty(*errp)); - exit(1); - } return NULL; } #endif -- cgit v1.2.3-55-g7522 From 680a4783dc13f1059c03d11da58193d76c19ead6 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Mon, 2 Nov 2015 09:23:52 +0100 Subject: memory: call begin, log_start and commit when registering a new listener This ensures that cpu_reload_memory_map() is called as soon as tcg_cpu_address_space_init() is called, and before cpu->memory_dispatch is used. qemu-system-s390x never changes the address spaces after tcg_cpu_address_space_init() is called, and thus tcg_commit() is never called. This causes a SIGSEGV. Because memory_map_init() will now call mem_commit(), we have to initialize io_mem_* before address_space_memory and friends. Reported-by: Philipp Kern Reviewed-by: Peter Maydell Fixes: 0a1c71cec63e95f9b8d0dc96d049d2daa00c5210 Signed-off-by: Paolo Bonzini --- exec.c | 2 +- memory.c | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'exec.c') diff --git a/exec.c b/exec.c index 7431f2f449..819ecc3d64 100644 --- a/exec.c +++ b/exec.c @@ -2694,8 +2694,8 @@ void cpu_register_map_client(QEMUBH *bh) void cpu_exec_init_all(void) { qemu_mutex_init(&ram_list.mutex); - memory_map_init(); io_mem_init(); + memory_map_init(); qemu_mutex_init(&map_client_list_lock); } diff --git a/memory.c b/memory.c index 2eb1597518..c435c8827a 100644 --- a/memory.c +++ b/memory.c @@ -2036,6 +2036,9 @@ static void listener_add_address_space(MemoryListener *listener, return; } + if (listener->begin) { + listener->begin(listener); + } if (global_dirty_log) { if (listener->log_global_start) { listener->log_global_start(listener); @@ -2052,10 +2055,16 @@ static void listener_add_address_space(MemoryListener *listener, .offset_within_address_space = int128_get64(fr->addr.start), .readonly = fr->readonly, }; + if (fr->dirty_log_mask && listener->log_start) { + listener->log_start(listener, §ion, 0, fr->dirty_log_mask); + } if (listener->region_add) { listener->region_add(listener, §ion); } } + if (listener->commit) { + listener->commit(listener); + } flatview_unref(view); } -- cgit v1.2.3-55-g7522 From 8d31d6b65a7448582c7bd320fd1b8cfc6cca2720 Mon Sep 17 00:00:00 2001 From: Pavel Fedin Date: Wed, 28 Oct 2015 12:54:07 +0300 Subject: backends/hostmem-file: Allow to specify full pathname for backing file This allows to explicitly specify file name to use with the backend. This is important when using it together with ivshmem in order to make it backed by hugetlbfs. By default filename is autogenerated using mkstemp(), and the file is unlink()ed after creation, effectively making it anonymous. This is not very useful with ivshmem because it ends up in a memory which cannot be accessed by something else. Distinction between directory and file name is done by stat() check. If an existing directory is given, the code keeps old behavior. Otherwise it creates or opens a file with the given pathname. Signed-off-by: Pavel Fedin Tested-by: Igor Skalkin Message-Id: <004301d11166$9672fe30$c358fa90$@samsung.com> Signed-off-by: Paolo Bonzini --- exec.c | 34 +++++++++++++++++++++------------- qemu-doc.texi | 2 +- 2 files changed, 22 insertions(+), 14 deletions(-) (limited to 'exec.c') diff --git a/exec.c b/exec.c index 819ecc3d64..1e8b51b48b 100644 --- a/exec.c +++ b/exec.c @@ -1205,6 +1205,7 @@ static void *file_ram_alloc(RAMBlock *block, const char *path, Error **errp) { + struct stat st; char *filename; char *sanitized_name; char *c; @@ -1233,26 +1234,33 @@ static void *file_ram_alloc(RAMBlock *block, goto error; } - /* Make name safe to use with mkstemp by replacing '/' with '_'. */ - sanitized_name = g_strdup(memory_region_name(block->mr)); - for (c = sanitized_name; *c != '\0'; c++) { - if (*c == '/') - *c = '_'; - } + if (!stat(path, &st) && S_ISDIR(st.st_mode)) { + /* Make name safe to use with mkstemp by replacing '/' with '_'. */ + sanitized_name = g_strdup(memory_region_name(block->mr)); + for (c = sanitized_name; *c != '\0'; c++) { + if (*c == '/') { + *c = '_'; + } + } - filename = g_strdup_printf("%s/qemu_back_mem.%s.XXXXXX", path, - sanitized_name); - g_free(sanitized_name); + filename = g_strdup_printf("%s/qemu_back_mem.%s.XXXXXX", path, + sanitized_name); + g_free(sanitized_name); + + fd = mkstemp(filename); + if (fd >= 0) { + unlink(filename); + } + g_free(filename); + } else { + fd = open(path, O_RDWR | O_CREAT, 0644); + } - fd = mkstemp(filename); if (fd < 0) { error_setg_errno(errp, errno, "unable to create backing store for hugepages"); - g_free(filename); goto error; } - unlink(filename); - g_free(filename); memory = ROUND_UP(memory, hpagesize); diff --git a/qemu-doc.texi b/qemu-doc.texi index 3126abdcd3..460ab716ac 100644 --- a/qemu-doc.texi +++ b/qemu-doc.texi @@ -1299,7 +1299,7 @@ Instead of specifying the using POSIX shm, you may specify a memory backend that has hugepage support: @example -qemu-system-i386 -object memory-backend-file,size=1G,mem-path=/mnt/hugepages,id=mb1 +qemu-system-i386 -object memory-backend-file,size=1G,mem-path=/mnt/hugepages/my-shmem-file,id=mb1 -device ivshmem,memdev=mb1 @end example -- cgit v1.2.3-55-g7522