This patch adds a nickname parameter to qemu_anon_ram_alloc, which passes it to qemu_ram_mmap, which passes it in turn to mmap_activate, where it is used to name the region being allocated.
Signed-off-by: John Snow <[email protected]> Reviewed-by: Daniel P. Berrangé <[email protected]> --- include/qemu/mmap-alloc.h | 3 ++- include/qemu/osdep.h | 2 +- hw/display/virtio-gpu-gl.c | 2 +- migration/ram.c | 3 ++- system/physmem.c | 7 +++++-- target/i386/kvm/tdx.c | 3 ++- util/mmap-alloc.c | 10 +++++++--- util/oslib-posix.c | 4 ++-- util/oslib-win32.c | 2 +- 9 files changed, 23 insertions(+), 13 deletions(-) diff --git a/include/qemu/mmap-alloc.h b/include/qemu/mmap-alloc.h index 8344daaa03f..c34587179b6 100644 --- a/include/qemu/mmap-alloc.h +++ b/include/qemu/mmap-alloc.h @@ -36,7 +36,8 @@ void *qemu_ram_mmap(int fd, size_t size, size_t align, uint32_t qemu_map_flags, - off_t map_offset); + off_t map_offset, + const char *nickname); void qemu_ram_munmap(int fd, void *ptr, size_t size); diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index b27d159d5bb..5e712ff1c6c 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -552,7 +552,7 @@ void QEMU_ERROR("code path is reachable") int qemu_daemon(int nochdir, int noclose); void *qemu_anon_ram_alloc(size_t size, uint64_t *align, bool shared, - bool noreserve); + bool noreserve, const char *nickname); void qemu_anon_ram_free(void *ptr, size_t size); int qemu_shm_alloc(size_t size, Error **errp); diff --git a/hw/display/virtio-gpu-gl.c b/hw/display/virtio-gpu-gl.c index 2b7a41c4664..66c302315c5 100644 --- a/hw/display/virtio-gpu-gl.c +++ b/hw/display/virtio-gpu-gl.c @@ -145,7 +145,7 @@ static void virtio_gpu_gl_device_realize(DeviceState *qdev, Error **errp) #if !defined(CONFIG_WIN32) if (virtio_gpu_hostmem_enabled(b->conf)) { map = qemu_ram_mmap(-1, b->conf.hostmem, qemu_real_host_page_size(), - 0, 0); + 0, 0, "virgl-hostmem"); if (map == MAP_FAILED) { error_setg_errno(errp, errno, "virgl hostmem region could not be initialized"); diff --git a/migration/ram.c b/migration/ram.c index e6db3bf5238..c48e05078d1 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -3720,7 +3720,8 @@ int colo_init_ram_cache(Error **errp) WITH_RCU_READ_LOCK_GUARD() { RAMBLOCK_FOREACH_NOT_IGNORED(block) { block->colo_cache = qemu_anon_ram_alloc(block->used_length, - NULL, false, false); + NULL, false, false, + "colo cache"); if (!block->colo_cache) { error_setg(errp, "Can't alloc memory for COLO cache of " "block %s, size 0x" RAM_ADDR_FMT, diff --git a/system/physmem.c b/system/physmem.c index a7300bb9d97..202e3a5cd00 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -1767,7 +1767,8 @@ static void *file_ram_alloc(RAMBlock *block, qemu_map_flags |= (block->flags & RAM_SHARED) ? QEMU_MAP_SHARED : 0; qemu_map_flags |= (block->flags & RAM_PMEM) ? QEMU_MAP_SYNC : 0; qemu_map_flags |= (block->flags & RAM_NORESERVE) ? QEMU_MAP_NORESERVE : 0; - area = qemu_ram_mmap(fd, memory, block->mr->align, qemu_map_flags, offset); + area = qemu_ram_mmap(fd, memory, block->mr->align, qemu_map_flags, offset, + "file_ram_alloc"); if (area == MAP_FAILED) { error_setg_errno(errp, errno, "unable to map backing store for guest RAM"); @@ -2169,7 +2170,9 @@ static void ram_block_add(RAMBlock *new_block, Error **errp) } else { new_block->host = qemu_anon_ram_alloc(new_block->max_length, &new_block->mr->align, - shared, noreserve); + shared, noreserve, + new_block->mr->name); + if (!new_block->host) { g_autofree char *size_s = size_to_str(new_block->max_length); error_setg_errno(errp, errno, diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index 52bb2ec6ced..e4d589fc950 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -354,7 +354,8 @@ static void tdx_finalize_vm(Notifier *notifier, void *unused) case TDVF_SECTION_TYPE_TD_HOB: case TDVF_SECTION_TYPE_TEMP_MEM: entry->mem_ptr = qemu_ram_mmap(-1, entry->size, - qemu_real_host_page_size(), 0, 0); + qemu_real_host_page_size(), 0, 0, + "tdx"); if (entry->mem_ptr == MAP_FAILED) { error_report("Failed to mmap memory for TDVF section %d", entry->type); diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c index 2133b2c9bda..f0b903dfdbe 100644 --- a/util/mmap-alloc.c +++ b/util/mmap-alloc.c @@ -187,7 +187,8 @@ static void *mmap_reserve(size_t size, int fd) * it accessible. */ static void *mmap_activate(void *ptr, size_t size, int fd, - uint32_t qemu_map_flags, off_t map_offset) + uint32_t qemu_map_flags, off_t map_offset, + const char *nickname) { const bool noreserve = qemu_map_flags & QEMU_MAP_NORESERVE; const bool readonly = qemu_map_flags & QEMU_MAP_READONLY; @@ -236,6 +237,8 @@ static void *mmap_activate(void *ptr, size_t size, int fd, */ activated_ptr = mmap(ptr, size, prot, flags, fd, map_offset); } + + qemu_name_vma(ptr, size, "%s", nickname); return activated_ptr; } @@ -253,7 +256,8 @@ void *qemu_ram_mmap(int fd, size_t size, size_t align, uint32_t qemu_map_flags, - off_t map_offset) + off_t map_offset, + const char *nickname) { const size_t guard_pagesize = mmap_guard_pagesize(fd); size_t offset, total; @@ -277,7 +281,7 @@ void *qemu_ram_mmap(int fd, offset = QEMU_ALIGN_UP((uintptr_t)guardptr, align) - (uintptr_t)guardptr; ptr = mmap_activate(guardptr + offset, size, fd, qemu_map_flags, - map_offset); + map_offset, nickname); if (ptr == MAP_FAILED) { munmap(guardptr, total); return MAP_FAILED; diff --git a/util/oslib-posix.c b/util/oslib-posix.c index 454579c72df..ba3ebb52eb5 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -207,13 +207,13 @@ fail_close: /* alloc shared memory pages */ void *qemu_anon_ram_alloc(size_t size, uint64_t *alignment, bool shared, - bool noreserve) + bool noreserve, const char *nickname) { const uint32_t qemu_map_flags = (shared ? QEMU_MAP_SHARED : 0) | (noreserve ? QEMU_MAP_NORESERVE : 0); size_t align = QEMU_VMALLOC_ALIGN; #ifndef EMSCRIPTEN - void *ptr = qemu_ram_mmap(-1, size, align, qemu_map_flags, 0); + void *ptr = qemu_ram_mmap(-1, size, align, qemu_map_flags, 0, nickname); if (ptr == MAP_FAILED) { return NULL; diff --git a/util/oslib-win32.c b/util/oslib-win32.c index 5f3e8f4d980..52c6335995c 100644 --- a/util/oslib-win32.c +++ b/util/oslib-win32.c @@ -45,7 +45,7 @@ static int get_allocation_granularity(void) } void *qemu_anon_ram_alloc(size_t size, uint64_t *align, bool shared, - bool noreserve) + bool noreserve, const char *nickname) { void *ptr; -- 2.56.1
