From nobody Thu Nov 6 12:31:54 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1540913444181639.4505062060024; Tue, 30 Oct 2018 08:30:44 -0700 (PDT) Received: from localhost ([::1]:53922 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVya-0001Br-0W for importer@patchew.org; Tue, 30 Oct 2018 11:30:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53550) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHVcn-0006Hg-Aa for qemu-devel@nongnu.org; Tue, 30 Oct 2018 11:08:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHVcj-0006kJ-10 for qemu-devel@nongnu.org; Tue, 30 Oct 2018 11:08:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58866) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gHVci-0006h9-IQ for qemu-devel@nongnu.org; Tue, 30 Oct 2018 11:08:04 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AC6A6308421B; Tue, 30 Oct 2018 15:08:03 +0000 (UTC) Received: from localhost (ovpn-112-20.ams2.redhat.com [10.36.112.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6A3E8620B8; Tue, 30 Oct 2018 15:07:56 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 19:04:53 +0400 Message-Id: <20181030150453.9344-11-marcandre.lureau@redhat.com> In-Reply-To: <20181030150453.9344-1-marcandre.lureau@redhat.com> References: <20181030150453.9344-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Tue, 30 Oct 2018 15:08:03 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 10/10] hostmem: use object id for memory region name with >= 3.1 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , Amit Shah , "Michael S. Tsirkin" , Mark Cave-Ayland , dgilbert@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Igor Mammedov , Paolo Bonzini , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Artyom Tarasenko , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" hostmem-file and hostmem-memfd use the whole object path for the memory region name, and hostname-ram uses only the path component (the object id, or canonical path basename): qemu -m 1024 -object memory-backend-file,id=3Dmem,size=3D1G,mem-path=3D/tmp= /foo -numa node,memdev=3Dmem -monitor stdio (qemu) info ramblock Block Name PSize Offset Used = Total /objects/mem 4 KiB 0x0000000000000000 0x0000000040000000 0x= 0000000040000000 qemu -m 1024 -object memory-backend-memfd,id=3Dmem,size=3D1G -numa node,mem= dev=3Dmem -monitor stdio (qemu) info ramblock Block Name PSize Offset Used = Total /objects/mem 4 KiB 0x0000000000000000 0x0000000040000000 0x= 0000000040000000 qemu -m 1024 -object memory-backend-ram,id=3Dmem,size=3D1G -numa node,memde= v=3Dmem -monitor stdio (qemu) info ramblock Block Name PSize Offset Used = Total mem 4 KiB 0x0000000000000000 0x0000000040000000 0x= 0000000040000000 Use the object id for -file and -memfd with >=3D 3.1 for consistency. Having a consistent naming allow to migrate to different hostmem backends. Signed-off-by: Marc-Andr=C3=A9 Lureau --- include/hw/compat.h | 11 ++++++++++- include/sysemu/hostmem.h | 3 ++- backends/hostmem-file.c | 8 ++++---- backends/hostmem-memfd.c | 2 +- backends/hostmem-ram.c | 9 ++++----- backends/hostmem.c | 30 ++++++++++++++++++++++++++++++ 6 files changed, 51 insertions(+), 12 deletions(-) diff --git a/include/hw/compat.h b/include/hw/compat.h index 6f4d5fc647..60f4a939a7 100644 --- a/include/hw/compat.h +++ b/include/hw/compat.h @@ -2,7 +2,16 @@ #define HW_COMPAT_H =20 #define HW_COMPAT_3_0 \ - /* empty */ + {\ + .driver =3D "memory-backend-file",\ + .property =3D "x-use-canonical-path-for-ramblock-id",\ + .value =3D "true",\ + },\ + {\ + .driver =3D "memory-backend-memfd",\ + .property =3D "x-use-canonical-path-for-ramblock-id",\ + .value =3D "true",\ + }, =20 #define HW_COMPAT_2_12 \ {\ diff --git a/include/sysemu/hostmem.h b/include/sysemu/hostmem.h index 6e6bd2c1cb..a023b372a4 100644 --- a/include/sysemu/hostmem.h +++ b/include/sysemu/hostmem.h @@ -53,7 +53,7 @@ struct HostMemoryBackend { =20 /* protected */ uint64_t size; - bool merge, dump; + bool merge, dump, use_canonical_path; bool prealloc, force_prealloc, is_mapped, share; DECLARE_BITMAP(host_nodes, MAX_NODES + 1); HostMemPolicy policy; @@ -67,5 +67,6 @@ MemoryRegion *host_memory_backend_get_memory(HostMemoryBa= ckend *backend); void host_memory_backend_set_mapped(HostMemoryBackend *backend, bool mappe= d); bool host_memory_backend_is_mapped(HostMemoryBackend *backend); size_t host_memory_backend_pagesize(HostMemoryBackend *memdev); +char *host_memory_backend_get_name(HostMemoryBackend *backend); =20 #endif diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c index 639c8d4307..c01a7cdf8d 100644 --- a/backends/hostmem-file.c +++ b/backends/hostmem-file.c @@ -55,16 +55,16 @@ file_backend_memory_alloc(HostMemoryBackend *backend, E= rror **errp) error_setg(errp, "-mem-path not supported on this host"); #else if (!host_memory_backend_mr_inited(backend)) { - gchar *path; + gchar *name; backend->force_prealloc =3D mem_prealloc; - path =3D object_get_canonical_path(OBJECT(backend)); + name =3D host_memory_backend_get_name(backend); memory_region_init_ram_from_file(&backend->mr, OBJECT(backend), - path, + name, backend->size, fb->align, (backend->share ? RAM_SHARED : 0) | (fb->is_pmem ? RAM_PMEM : 0), fb->mem_path, errp); - g_free(path); + g_free(name); } #endif } diff --git a/backends/hostmem-memfd.c b/backends/hostmem-memfd.c index b6836b28e5..c5a4a9b530 100644 --- a/backends/hostmem-memfd.c +++ b/backends/hostmem-memfd.c @@ -57,7 +57,7 @@ memfd_backend_memory_alloc(HostMemoryBackend *backend, Er= ror **errp) return; } =20 - name =3D object_get_canonical_path(OBJECT(backend)); + name =3D host_memory_backend_get_name(backend); memory_region_init_ram_from_fd(&backend->mr, OBJECT(backend), name, backend->size, true, fd, errp); g_free(name); diff --git a/backends/hostmem-ram.c b/backends/hostmem-ram.c index 7ddd08d370..24b65d9ae3 100644 --- a/backends/hostmem-ram.c +++ b/backends/hostmem-ram.c @@ -16,21 +16,20 @@ =20 #define TYPE_MEMORY_BACKEND_RAM "memory-backend-ram" =20 - static void ram_backend_memory_alloc(HostMemoryBackend *backend, Error **errp) { - char *path; + char *name; =20 if (!backend->size) { error_setg(errp, "can't create backend with size 0"); return; } =20 - path =3D object_get_canonical_path_component(OBJECT(backend)); - memory_region_init_ram_shared_nomigrate(&backend->mr, OBJECT(backend),= path, + name =3D host_memory_backend_get_name(backend); + memory_region_init_ram_shared_nomigrate(&backend->mr, OBJECT(backend),= name, backend->size, backend->share, errp); - g_free(path); + g_free(name); } =20 static void diff --git a/backends/hostmem.c b/backends/hostmem.c index 1a89342039..0032232866 100644 --- a/backends/hostmem.c +++ b/backends/hostmem.c @@ -28,6 +28,16 @@ QEMU_BUILD_BUG_ON(HOST_MEM_POLICY_BIND !=3D MPOL_BIND); QEMU_BUILD_BUG_ON(HOST_MEM_POLICY_INTERLEAVE !=3D MPOL_INTERLEAVE); #endif =20 +char * +host_memory_backend_get_name(HostMemoryBackend *self) +{ + if (!self->use_canonical_path) { + return object_get_canonical_path_component(OBJECT(self)); + } + + return object_get_canonical_path(OBJECT(self)); +} + static void host_memory_backend_get_size(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) @@ -386,6 +396,23 @@ static void host_memory_backend_set_share(Object *o, b= ool value, Error **errp) backend->share =3D value; } =20 +static bool +host_memory_backend_get_use_canonical_path(Object *obj, Error **errp) +{ + HostMemoryBackend *self =3D MEMORY_BACKEND(obj); + + return self->use_canonical_path; +} + +static void +host_memory_backend_set_use_canonical_path(Object *obj, bool value, + Error **errp) +{ + HostMemoryBackend *self =3D MEMORY_BACKEND(obj); + + self->use_canonical_path =3D value; +} + static void host_memory_backend_class_init(ObjectClass *oc, void *data) { @@ -432,6 +459,9 @@ host_memory_backend_class_init(ObjectClass *oc, void *d= ata) &error_abort); object_class_property_set_description(oc, "share", "Mark the memory as private to QEMU or shared", &error_abort); + object_class_property_add_bool(oc, "x-use-canonical-path-for-ramblock-= id", + host_memory_backend_get_use_canonical_path, + host_memory_backend_set_use_canonical_path, &error_abort); } =20 static const TypeInfo host_memory_backend_info =3D { --=20 2.19.0.271.gfe8321ec05