From nobody Sat Feb 7 05:44:15 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=eik.bme.hu Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1769366158356377.3005659302927; Sun, 25 Jan 2026 10:35:58 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vk4wH-0006kC-Md; Sun, 25 Jan 2026 13:34:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vk4wD-0006en-IJ for qemu-devel@nongnu.org; Sun, 25 Jan 2026 13:34:17 -0500 Received: from zero.eik.bme.hu ([152.66.115.2]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vk4wA-0002nQ-H8 for qemu-devel@nongnu.org; Sun, 25 Jan 2026 13:34:17 -0500 Received: from localhost (localhost [127.0.0.1]) by zero.eik.bme.hu (Postfix) with ESMTP id 077995974D7; Sun, 25 Jan 2026 19:34:12 +0100 (CET) Received: from zero.eik.bme.hu ([127.0.0.1]) by localhost (zero.eik.bme.hu [127.0.0.1]) (amavis, port 10028) with ESMTP id 00wLJb8PK9Nr; Sun, 25 Jan 2026 19:34:10 +0100 (CET) Received: by zero.eik.bme.hu (Postfix, from userid 432) id 953F45974BC; Sun, 25 Jan 2026 18:50:56 +0100 (CET) X-Virus-Scanned: amavis at eik.bme.hu Message-ID: <107f31d3312c79f46c9f4baeb247ac5120a6c6aa.1769362313.git.balaton@eik.bme.hu> In-Reply-To: References: From: BALATON Zoltan Subject: [PATCH v2 01/10] memory: Add internal memory_region_set_ops helper function MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable To: qemu-devel@nongnu.org Cc: Peter Xu , Akihiko Odaki , Paolo Bonzini , Michael S. Tsirkin , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Date: Sun, 25 Jan 2026 18:50:56 +0100 (CET) Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=152.66.115.2; envelope-from=balaton@eik.bme.hu; helo=zero.eik.bme.hu X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1769366162341158500 Content-Type: text/plain; charset="utf-8" This is a common operation used at multiple places, add a helper function for it. Signed-off-by: BALATON Zoltan --- system/memory.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/system/memory.c b/system/memory.c index 4bf00d82bc..86742557a1 100644 --- a/system/memory.c +++ b/system/memory.c @@ -1559,6 +1559,15 @@ MemTxResult memory_region_dispatch_write(MemoryRegio= n *mr, } } =20 +static void memory_region_set_ops(MemoryRegion *mr, + const MemoryRegionOps *ops, + void *opaque) +{ + mr->ops =3D ops ?: &unassigned_mem_ops; + mr->opaque =3D opaque; + mr->terminates =3D true; +} + void memory_region_init_io(MemoryRegion *mr, Object *owner, const MemoryRegionOps *ops, @@ -1567,9 +1576,7 @@ void memory_region_init_io(MemoryRegion *mr, uint64_t size) { memory_region_init(mr, owner, name, size); - mr->ops =3D ops ? ops : &unassigned_mem_ops; - mr->opaque =3D opaque; - mr->terminates =3D true; + memory_region_set_ops(mr, ops, opaque); } =20 bool memory_region_init_ram_nomigrate(MemoryRegion *mr, @@ -1710,10 +1717,8 @@ void memory_region_init_ram_device_ptr(MemoryRegion = *mr, { memory_region_init(mr, owner, name, size); mr->ram =3D true; - mr->terminates =3D true; mr->ram_device =3D true; - mr->ops =3D &ram_device_mem_ops; - mr->opaque =3D mr; + memory_region_set_ops(mr, &ram_device_mem_ops, mr); mr->destructor =3D memory_region_destructor_ram; =20 /* qemu_ram_alloc_from_ptr cannot fail with ptr !=3D NULL. */ @@ -1759,9 +1764,7 @@ bool memory_region_init_rom_device_nomigrate(MemoryRe= gion *mr, Error *err =3D NULL; assert(ops); memory_region_init(mr, owner, name, size); - mr->ops =3D ops; - mr->opaque =3D opaque; - mr->terminates =3D true; + memory_region_set_ops(mr, ops, opaque); mr->rom_device =3D true; mr->destructor =3D memory_region_destructor_ram; mr->ram_block =3D qemu_ram_alloc(size, 0, mr, &err); --=20 2.41.3 From nobody Sat Feb 7 05:44:15 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=eik.bme.hu Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1769366201698760.1547476589313; Sun, 25 Jan 2026 10:36:41 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vk4wT-0006v0-4S; Sun, 25 Jan 2026 13:34:33 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vk4wR-0006sr-3g for qemu-devel@nongnu.org; Sun, 25 Jan 2026 13:34:31 -0500 Received: from zero.eik.bme.hu ([2001:738:2001:2001::2001]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vk4wP-0002q6-80 for qemu-devel@nongnu.org; Sun, 25 Jan 2026 13:34:30 -0500 Received: from localhost (localhost [127.0.0.1]) by zero.eik.bme.hu (Postfix) with ESMTP id 2D756597500; Sun, 25 Jan 2026 19:34:28 +0100 (CET) Received: from zero.eik.bme.hu ([127.0.0.1]) by localhost (zero.eik.bme.hu [127.0.0.1]) (amavis, port 10028) with ESMTP id JIdVenrrlWcS; Sun, 25 Jan 2026 19:34:26 +0100 (CET) Received: by zero.eik.bme.hu (Postfix, from userid 432) id A102D5974BE; Sun, 25 Jan 2026 18:50:57 +0100 (CET) X-Virus-Scanned: amavis at eik.bme.hu Message-ID: <825320b3a3bd2a4286adaa56489bed83ebab4d04.1769362313.git.balaton@eik.bme.hu> In-Reply-To: References: From: BALATON Zoltan Subject: [PATCH v2 02/10] memory: Factor out common ram region initialization MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable To: qemu-devel@nongnu.org Cc: Peter Xu , Akihiko Odaki , Paolo Bonzini , Michael S. Tsirkin , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Date: Sun, 25 Jan 2026 18:50:57 +0100 (CET) Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2001:738:2001:2001::2001; envelope-from=balaton@eik.bme.hu; helo=zero.eik.bme.hu X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1769366202714154100 Content-Type: text/plain; charset="utf-8" Introduce internal memory_region_do_init_ram() function to remove duplicated code from different memory_region_init_*ram functions. Signed-off-by: BALATON Zoltan --- system/memory.c | 147 +++++++++++++++++------------------------------- 1 file changed, 53 insertions(+), 94 deletions(-) diff --git a/system/memory.c b/system/memory.c index 86742557a1..7267333e11 100644 --- a/system/memory.c +++ b/system/memory.c @@ -1579,29 +1579,12 @@ void memory_region_init_io(MemoryRegion *mr, memory_region_set_ops(mr, ops, opaque); } =20 -bool memory_region_init_ram_nomigrate(MemoryRegion *mr, - Object *owner, - const char *name, - uint64_t size, - Error **errp) -{ - return memory_region_init_ram_flags_nomigrate(mr, owner, name, - size, 0, errp); -} - -bool memory_region_init_ram_flags_nomigrate(MemoryRegion *mr, - Object *owner, - const char *name, - uint64_t size, - uint32_t ram_flags, - Error **errp) +static bool memory_region_do_init_ram(MemoryRegion *mr, + Error *err, Error **errp) { - Error *err =3D NULL; - memory_region_init(mr, owner, name, size); mr->ram =3D true; mr->terminates =3D true; mr->destructor =3D memory_region_destructor_ram; - mr->ram_block =3D qemu_ram_alloc(size, ram_flags, mr, &err); if (err) { mr->size =3D int128_zero(); object_unparent(OBJECT(mr)); @@ -1611,6 +1594,25 @@ bool memory_region_init_ram_flags_nomigrate(MemoryRe= gion *mr, return true; } =20 +bool memory_region_init_ram_flags_nomigrate(MemoryRegion *mr, Object *owne= r, + const char *name, uint64_t siz= e, + uint32_t ram_flags, Error **er= rp) +{ + Error *err =3D NULL; + + memory_region_init(mr, owner, name, size); + mr->ram_block =3D qemu_ram_alloc(size, ram_flags, mr, &err); + return memory_region_do_init_ram(mr, err, errp); +} + +bool memory_region_init_ram_nomigrate(MemoryRegion *mr, Object *owner, + const char *name, uint64_t size, + Error **errp) +{ + return memory_region_init_ram_flags_nomigrate(mr, owner, name, size, 0, + errp); +} + bool memory_region_init_resizeable_ram(MemoryRegion *mr, Object *owner, const char *name, @@ -1622,108 +1624,66 @@ bool memory_region_init_resizeable_ram(MemoryRegio= n *mr, Error **errp) { Error *err =3D NULL; + memory_region_init(mr, owner, name, size); - mr->ram =3D true; - mr->terminates =3D true; - mr->destructor =3D memory_region_destructor_ram; - mr->ram_block =3D qemu_ram_alloc_resizeable(size, max_size, resized, - mr, &err); - if (err) { - mr->size =3D int128_zero(); - object_unparent(OBJECT(mr)); - error_propagate(errp, err); - return false; - } - return true; + mr->ram_block =3D qemu_ram_alloc_resizeable(size, max_size, resized, m= r, + &err); + return memory_region_do_init_ram(mr, err, errp); } =20 #if defined(CONFIG_POSIX) && !defined(EMSCRIPTEN) -bool memory_region_init_ram_from_file(MemoryRegion *mr, - Object *owner, - const char *name, - uint64_t size, - uint64_t align, - uint32_t ram_flags, - const char *path, - ram_addr_t offset, +bool memory_region_init_ram_from_file(MemoryRegion *mr, Object *owner, + const char *name, uint64_t size, + uint64_t align, uint32_t ram_flags, + const char *path, ram_addr_t offset, Error **errp) { Error *err =3D NULL; + memory_region_init(mr, owner, name, size); - mr->ram =3D true; mr->readonly =3D !!(ram_flags & RAM_READONLY); - mr->terminates =3D true; - mr->destructor =3D memory_region_destructor_ram; mr->align =3D align; - mr->ram_block =3D qemu_ram_alloc_from_file(size, mr, ram_flags, path, - offset, &err); - if (err) { - mr->size =3D int128_zero(); - object_unparent(OBJECT(mr)); - error_propagate(errp, err); - return false; - } - return true; + mr->ram_block =3D qemu_ram_alloc_from_file(size, mr, ram_flags, path, = offset, + &err); + return memory_region_do_init_ram(mr, err, errp); } =20 -bool memory_region_init_ram_from_fd(MemoryRegion *mr, - Object *owner, - const char *name, - uint64_t size, - uint32_t ram_flags, - int fd, - ram_addr_t offset, - Error **errp) +bool memory_region_init_ram_from_fd(MemoryRegion *mr, Object *owner, + const char *name, uint64_t size, + uint32_t ram_flags, int fd, + ram_addr_t offset, Error **errp) { Error *err =3D NULL; + memory_region_init(mr, owner, name, size); - mr->ram =3D true; mr->readonly =3D !!(ram_flags & RAM_READONLY); - mr->terminates =3D true; - mr->destructor =3D memory_region_destructor_ram; mr->ram_block =3D qemu_ram_alloc_from_fd(size, size, NULL, mr, ram_fla= gs, fd, offset, false, &err); - if (err) { - mr->size =3D int128_zero(); - object_unparent(OBJECT(mr)); - error_propagate(errp, err); - return false; - } - return true; + return memory_region_do_init_ram(mr, err, errp); } #endif =20 -void memory_region_init_ram_ptr(MemoryRegion *mr, - Object *owner, - const char *name, - uint64_t size, - void *ptr) +void memory_region_init_ram_ptr(MemoryRegion *mr, Object *owner, + const char *name, uint64_t size, void *ptr) { memory_region_init(mr, owner, name, size); - mr->ram =3D true; - mr->terminates =3D true; - mr->destructor =3D memory_region_destructor_ram; - /* qemu_ram_alloc_from_ptr cannot fail with ptr !=3D NULL. */ assert(ptr !=3D NULL); mr->ram_block =3D qemu_ram_alloc_from_ptr(size, ptr, mr, &error_abort); + memory_region_do_init_ram(mr, NULL, NULL); } =20 -void memory_region_init_ram_device_ptr(MemoryRegion *mr, - Object *owner, - const char *name, - uint64_t size, +void memory_region_init_ram_device_ptr(MemoryRegion *mr, Object *owner, + const char *name, uint64_t size, void *ptr) { memory_region_init(mr, owner, name, size); - mr->ram =3D true; - mr->ram_device =3D true; memory_region_set_ops(mr, &ram_device_mem_ops, mr); - mr->destructor =3D memory_region_destructor_ram; - /* qemu_ram_alloc_from_ptr cannot fail with ptr !=3D NULL. */ assert(ptr !=3D NULL); mr->ram_block =3D qemu_ram_alloc_from_ptr(size, ptr, mr, &error_abort); + memory_region_do_init_ram(mr, NULL, NULL); + mr->ram_device =3D true; } =20 void memory_region_init_alias(MemoryRegion *mr, @@ -1762,19 +1722,18 @@ bool memory_region_init_rom_device_nomigrate(Memory= Region *mr, Error **errp) { Error *err =3D NULL; + bool ret; + assert(ops); memory_region_init(mr, owner, name, size); memory_region_set_ops(mr, ops, opaque); - mr->rom_device =3D true; - mr->destructor =3D memory_region_destructor_ram; mr->ram_block =3D qemu_ram_alloc(size, 0, mr, &err); - if (err) { - mr->size =3D int128_zero(); - object_unparent(OBJECT(mr)); - error_propagate(errp, err); - return false; + ret =3D memory_region_do_init_ram(mr, err, errp); + if (ret) { + mr->ram =3D false; + mr->rom_device =3D true; } - return true; + return ret; } =20 void memory_region_init_iommu(void *_iommu_mr, --=20 2.41.3 From nobody Sat Feb 7 05:44:15 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=eik.bme.hu Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1769366205796650.9944647174233; Sun, 25 Jan 2026 10:36:45 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vk4wT-0006wc-Pt; Sun, 25 Jan 2026 13:34:33 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vk4wS-0006te-0T for qemu-devel@nongnu.org; Sun, 25 Jan 2026 13:34:32 -0500 Received: from zero.eik.bme.hu ([152.66.115.2]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vk4wP-0002qB-RG for qemu-devel@nongnu.org; Sun, 25 Jan 2026 13:34:31 -0500 Received: from localhost (localhost [127.0.0.1]) by zero.eik.bme.hu (Postfix) with ESMTP id A73A559752F; Sun, 25 Jan 2026 19:34:28 +0100 (CET) Received: from zero.eik.bme.hu ([127.0.0.1]) by localhost (zero.eik.bme.hu [127.0.0.1]) (amavis, port 10028) with ESMTP id 0UvUQC83j0u0; Sun, 25 Jan 2026 19:34:26 +0100 (CET) Received: by zero.eik.bme.hu (Postfix, from userid 432) id AB5305974BF; Sun, 25 Jan 2026 18:50:58 +0100 (CET) X-Virus-Scanned: amavis at eik.bme.hu Message-ID: In-Reply-To: References: From: BALATON Zoltan Subject: [PATCH v2 03/10] memory: Factor out more common ram region initialization MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable To: qemu-devel@nongnu.org Cc: Peter Xu , Akihiko Odaki , Paolo Bonzini , Michael S. Tsirkin , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Date: Sun, 25 Jan 2026 18:50:58 +0100 (CET) Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=152.66.115.2; envelope-from=balaton@eik.bme.hu; helo=zero.eik.bme.hu X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1769366206381154100 Introduce internal memory_region_do_init_ram_ptr() function to remove duplicated code from different memory_region_init_ram_*ptr functions. Signed-off-by: BALATON Zoltan Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- system/memory.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/system/memory.c b/system/memory.c index 7267333e11..68dc95b9b1 100644 --- a/system/memory.c +++ b/system/memory.c @@ -1663,26 +1663,29 @@ bool memory_region_init_ram_from_fd(MemoryRegion *m= r, Object *owner, } #endif =20 -void memory_region_init_ram_ptr(MemoryRegion *mr, Object *owner, - const char *name, uint64_t size, void *ptr) +static void memory_region_do_init_ram_ptr(MemoryRegion *mr, uint64_t size, + void *ptr) { - memory_region_init(mr, owner, name, size); /* qemu_ram_alloc_from_ptr cannot fail with ptr !=3D NULL. */ assert(ptr !=3D NULL); mr->ram_block =3D qemu_ram_alloc_from_ptr(size, ptr, mr, &error_abort); memory_region_do_init_ram(mr, NULL, NULL); } =20 +void memory_region_init_ram_ptr(MemoryRegion *mr, Object *owner, + const char *name, uint64_t size, void *ptr) +{ + memory_region_init(mr, owner, name, size); + memory_region_do_init_ram_ptr(mr, size, ptr); +} + void memory_region_init_ram_device_ptr(MemoryRegion *mr, Object *owner, const char *name, uint64_t size, void *ptr) { memory_region_init(mr, owner, name, size); memory_region_set_ops(mr, &ram_device_mem_ops, mr); - /* qemu_ram_alloc_from_ptr cannot fail with ptr !=3D NULL. */ - assert(ptr !=3D NULL); - mr->ram_block =3D qemu_ram_alloc_from_ptr(size, ptr, mr, &error_abort); - memory_region_do_init_ram(mr, NULL, NULL); + memory_region_do_init_ram_ptr(mr, size, ptr); mr->ram_device =3D true; } =20 --=20 2.41.3 From nobody Sat Feb 7 05:44:15 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=eik.bme.hu Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1769366153771609.2684751948997; Sun, 25 Jan 2026 10:35:53 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vk4wL-0006nU-4Z; Sun, 25 Jan 2026 13:34:25 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vk4wJ-0006mL-MK for qemu-devel@nongnu.org; Sun, 25 Jan 2026 13:34:23 -0500 Received: from zero.eik.bme.hu ([2001:738:2001:2001::2001]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vk4wI-0002pX-7J for qemu-devel@nongnu.org; Sun, 25 Jan 2026 13:34:23 -0500 Received: from localhost (localhost [127.0.0.1]) by zero.eik.bme.hu (Postfix) with ESMTP id 11DC8597506; Sun, 25 Jan 2026 19:34:21 +0100 (CET) Received: from zero.eik.bme.hu ([127.0.0.1]) by localhost (zero.eik.bme.hu [127.0.0.1]) (amavis, port 10028) with ESMTP id Qb8DQTnV-unJ; Sun, 25 Jan 2026 19:34:19 +0100 (CET) Received: by zero.eik.bme.hu (Postfix, from userid 432) id B5ECF5974C0; Sun, 25 Jan 2026 18:50:59 +0100 (CET) X-Virus-Scanned: amavis at eik.bme.hu Message-ID: In-Reply-To: References: From: BALATON Zoltan Subject: [PATCH v2 04/10] memory: Shorten memory_region_init_rom_nomigrate MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable To: qemu-devel@nongnu.org Cc: Peter Xu , Akihiko Odaki , Paolo Bonzini , Michael S. Tsirkin , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Date: Sun, 25 Jan 2026 18:50:59 +0100 (CET) Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2001:738:2001:2001::2001; envelope-from=balaton@eik.bme.hu; helo=zero.eik.bme.hu X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1769366155728154100 Content-Type: text/plain; charset="utf-8" Use the shortcut memory_region_init_ram_nomigrate as we have no flags to pass and remove some extra line breaks to make the function occupy less lines. Also shorten some other function prototypes. Signed-off-by: BALATON Zoltan --- system/memory.c | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/system/memory.c b/system/memory.c index 68dc95b9b1..015b445ebf 100644 --- a/system/memory.c +++ b/system/memory.c @@ -1568,12 +1568,9 @@ static void memory_region_set_ops(MemoryRegion *mr, mr->terminates =3D true; } =20 -void memory_region_init_io(MemoryRegion *mr, - Object *owner, - const MemoryRegionOps *ops, - void *opaque, - const char *name, - uint64_t size) +void memory_region_init_io(MemoryRegion *mr, Object *owner, + const MemoryRegionOps *ops, void *opaque, + const char *name, uint64_t size) { memory_region_init(mr, owner, name, size); memory_region_set_ops(mr, ops, opaque); @@ -1689,30 +1686,23 @@ void memory_region_init_ram_device_ptr(MemoryRegion= *mr, Object *owner, mr->ram_device =3D true; } =20 -void memory_region_init_alias(MemoryRegion *mr, - Object *owner, - const char *name, - MemoryRegion *orig, - hwaddr offset, - uint64_t size) +void memory_region_init_alias(MemoryRegion *mr, Object *owner, + const char *name, MemoryRegion *orig, + hwaddr offset, uint64_t size) { memory_region_init(mr, owner, name, size); mr->alias =3D orig; mr->alias_offset =3D offset; } =20 -bool memory_region_init_rom_nomigrate(MemoryRegion *mr, - Object *owner, - const char *name, - uint64_t size, +bool memory_region_init_rom_nomigrate(MemoryRegion *mr, Object *owner, + const char *name, uint64_t size, Error **errp) { - if (!memory_region_init_ram_flags_nomigrate(mr, owner, name, - size, 0, errp)) { - return false; + if (!memory_region_init_ram_nomigrate(mr, owner, name, size, errp)) { + return false; } mr->readonly =3D true; - return true; } =20 --=20 2.41.3 From nobody Sat Feb 7 05:44:15 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=eik.bme.hu Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1769366093686567.2354228948774; Sun, 25 Jan 2026 10:34:53 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vk4wG-0006iV-9A; Sun, 25 Jan 2026 13:34:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vk4wE-0006gA-0Q for qemu-devel@nongnu.org; Sun, 25 Jan 2026 13:34:18 -0500 Received: from zero.eik.bme.hu ([152.66.115.2]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vk4wB-0002nW-4r for qemu-devel@nongnu.org; Sun, 25 Jan 2026 13:34:17 -0500 Received: from localhost (localhost [127.0.0.1]) by zero.eik.bme.hu (Postfix) with ESMTP id F281E597505; Sun, 25 Jan 2026 19:34:13 +0100 (CET) Received: from zero.eik.bme.hu ([127.0.0.1]) by localhost (zero.eik.bme.hu [127.0.0.1]) (amavis, port 10028) with ESMTP id YiKhCmV4D_r9; Sun, 25 Jan 2026 19:34:12 +0100 (CET) Received: by zero.eik.bme.hu (Postfix, from userid 432) id C4A125974C1; Sun, 25 Jan 2026 18:51:00 +0100 (CET) X-Virus-Scanned: amavis at eik.bme.hu Message-ID: <81ac9ae16dcb64ae070a8ad561dc0838e691e573.1769362313.git.balaton@eik.bme.hu> In-Reply-To: References: From: BALATON Zoltan Subject: [PATCH v2 05/10] memory: Add internal memory_region_register_ram function MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable To: qemu-devel@nongnu.org Cc: Peter Xu , Akihiko Odaki , Paolo Bonzini , Michael S. Tsirkin , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Date: Sun, 25 Jan 2026 18:51:00 +0100 (CET) Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=152.66.115.2; envelope-from=balaton@eik.bme.hu; helo=zero.eik.bme.hu X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1769366098310154100 Factor out common operation from memory_region_init_{ram,rom} functions to register the region for migration. This avoids duplicating the long comment in several functions. Signed-off-by: BALATON Zoltan Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- system/memory.c | 75 +++++++++++++------------------------------------ 1 file changed, 20 insertions(+), 55 deletions(-) diff --git a/system/memory.c b/system/memory.c index 015b445ebf..618d5d7f4d 100644 --- a/system/memory.c +++ b/system/memory.c @@ -3678,17 +3678,10 @@ void mtree_info(bool flatview, bool dispatch_tree, = bool owner, bool disabled) } } =20 -bool memory_region_init_ram(MemoryRegion *mr, - Object *owner, - const char *name, - uint64_t size, - Error **errp) +static void memory_region_register_ram(MemoryRegion *mr, Object *owner) { DeviceState *owner_dev; =20 - if (!memory_region_init_ram_nomigrate(mr, owner, name, size, errp)) { - return false; - } /* This will assert if owner is neither NULL nor a DeviceState. * We only want the owner here for the purposes of defining a * unique name for migration. TODO: Ideally we should implement @@ -3697,80 +3690,52 @@ bool memory_region_init_ram(MemoryRegion *mr, */ owner_dev =3D DEVICE(owner); vmstate_register_ram(mr, owner_dev); +} =20 +bool memory_region_init_ram(MemoryRegion *mr, Object *owner, + const char *name, uint64_t size, + Error **errp) +{ + if (!memory_region_init_ram_nomigrate(mr, owner, name, size, errp)) { + return false; + } + memory_region_register_ram(mr, owner); return true; } =20 -bool memory_region_init_ram_guest_memfd(MemoryRegion *mr, - Object *owner, - const char *name, - uint64_t size, +bool memory_region_init_ram_guest_memfd(MemoryRegion *mr, Object *owner, + const char *name, uint64_t size, Error **errp) { - DeviceState *owner_dev; - if (!memory_region_init_ram_flags_nomigrate(mr, owner, name, size, RAM_GUEST_MEMFD, errp)) { return false; } - /* This will assert if owner is neither NULL nor a DeviceState. - * We only want the owner here for the purposes of defining a - * unique name for migration. TODO: Ideally we should implement - * a naming scheme for Objects which are not DeviceStates, in - * which case we can relax this restriction. - */ - owner_dev =3D DEVICE(owner); - vmstate_register_ram(mr, owner_dev); - + memory_region_register_ram(mr, owner); return true; } =20 -bool memory_region_init_rom(MemoryRegion *mr, - Object *owner, - const char *name, - uint64_t size, +bool memory_region_init_rom(MemoryRegion *mr, Object *owner, + const char *name, uint64_t size, Error **errp) { - DeviceState *owner_dev; - if (!memory_region_init_rom_nomigrate(mr, owner, name, size, errp)) { return false; } - /* This will assert if owner is neither NULL nor a DeviceState. - * We only want the owner here for the purposes of defining a - * unique name for migration. TODO: Ideally we should implement - * a naming scheme for Objects which are not DeviceStates, in - * which case we can relax this restriction. - */ - owner_dev =3D DEVICE(owner); - vmstate_register_ram(mr, owner_dev); - + memory_region_register_ram(mr, owner); return true; } =20 -bool memory_region_init_rom_device(MemoryRegion *mr, - Object *owner, - const MemoryRegionOps *ops, - void *opaque, - const char *name, - uint64_t size, +bool memory_region_init_rom_device(MemoryRegion *mr, Object *owner, + const MemoryRegionOps *ops, void *opaqu= e, + const char *name, uint64_t size, Error **errp) { - DeviceState *owner_dev; - if (!memory_region_init_rom_device_nomigrate(mr, owner, ops, opaque, name, size, errp)) { return false; } - /* This will assert if owner is neither NULL nor a DeviceState. - * We only want the owner here for the purposes of defining a - * unique name for migration. TODO: Ideally we should implement - * a naming scheme for Objects which are not DeviceStates, in - * which case we can relax this restriction. - */ - owner_dev =3D DEVICE(owner); - vmstate_register_ram(mr, owner_dev); - + memory_region_register_ram(mr, owner); return true; } =20 --=20 2.41.3 From nobody Sat Feb 7 05:44:15 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=eik.bme.hu Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1769366202275700.3722016019301; Sun, 25 Jan 2026 10:36:42 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vk4wT-0006vs-KV; Sun, 25 Jan 2026 13:34:33 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vk4wQ-0006sc-U9 for qemu-devel@nongnu.org; Sun, 25 Jan 2026 13:34:30 -0500 Received: from zero.eik.bme.hu ([2001:738:2001:2001::2001]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vk4wN-0002ps-UY for qemu-devel@nongnu.org; Sun, 25 Jan 2026 13:34:30 -0500 Received: from localhost (localhost [127.0.0.1]) by zero.eik.bme.hu (Postfix) with ESMTP id B90D0597506; Sun, 25 Jan 2026 19:34:26 +0100 (CET) Received: from zero.eik.bme.hu ([127.0.0.1]) by localhost (zero.eik.bme.hu [127.0.0.1]) (amavis, port 10028) with ESMTP id CByF3cA2_ruZ; Sun, 25 Jan 2026 19:34:24 +0100 (CET) Received: by zero.eik.bme.hu (Postfix, from userid 432) id DD4555974CD; Sun, 25 Jan 2026 18:51:01 +0100 (CET) X-Virus-Scanned: amavis at eik.bme.hu Message-ID: In-Reply-To: References: From: BALATON Zoltan Subject: [PATCH v2 06/10] memory: Add memory_region_new* functions MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable To: qemu-devel@nongnu.org Cc: Peter Xu , Akihiko Odaki , Paolo Bonzini , Michael S. Tsirkin , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Date: Sun, 25 Jan 2026 18:51:01 +0100 (CET) Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2001:738:2001:2001::2001; envelope-from=balaton@eik.bme.hu; helo=zero.eik.bme.hu X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1769366206264158500 Content-Type: text/plain; charset="utf-8" These are counterparts of similar memory_region_init* functions but differ in that these allocate the memory region with object_new so the memory region will be managed by QOM and freed with the owner. This behaviour was already documented and the reference tracking is implemented but it could not be used without these functions because memory_region_init* functions call object_initialize that resets the free function of the object so it would not be freed. Signed-off-by: BALATON Zoltan --- include/system/memory.h | 360 ++++++++++++++++++++++++++++++++++++++++ system/memory.c | 212 +++++++++++++++++++++++ 2 files changed, 572 insertions(+) diff --git a/include/system/memory.h b/include/system/memory.h index 8f8725ea2d..58f66adc8f 100644 --- a/include/system/memory.h +++ b/include/system/memory.h @@ -1770,6 +1770,366 @@ bool memory_region_init_rom_device(MemoryRegion *mr, uint64_t size, Error **errp); =20 +/** + * memory_region_new: Allocate and initialize a memory region + * + * This is like memory_region_init() but allocates the #MemoryRegion and + * attaches it to the owner to free it when the owner is freed. + * + * @owner: the object that tracks the region's reference count + * @name: used for debugging; not visible to the user or ABI + * @size: size of the region; any subregions beyond this size will be clip= ped + * + * Return: Pointer to the allocated #MemoryRegion. + */ +MemoryRegion *memory_region_new(Object *owner, + const char *name, uint64_t size); + +/** + * memory_region_new_io: Allocate and initialize an I/O memory region. + * + * This is like memory_region_init_io() but allocates the #MemoryRegion and + * attaches it to the owner to free it when the owner is freed. + * + * @owner: the object that tracks the region's reference count + * @ops: a structure containing read and write callbacks to be used when + * I/O is performed on the region. + * @opaque: passed to the read and write callbacks of the @ops structure. + * @name: used for debugging; not visible to the user or ABI + * @size: size of the region. + * + * Return: Pointer to the allocated #MemoryRegion. + */ +MemoryRegion *memory_region_new_io(Object *owner, + const MemoryRegionOps *ops, void *opaqu= e, + const char *name, uint64_t size); + +/** + * memory_region_new_ram_nomigrate: Allocate and initialize RAM memory re= gion. + * + * This is like memory_region_init_ram_nomigrate() but allocates the + * #MemoryRegion and attaches is to the owner to free when the owner is fr= eed. + * + * @owner: the object that tracks the region's reference count + * @name: Region name, becomes part of RAMBlock name used in migration str= eam + * must be unique within any device + * @size: size of the region. + * @errp: pointer to Error*, to store an error if it happens. + * + * Note that this function does not do anything to cause the data in the + * RAM memory region to be migrated; that is the responsibility of the cal= ler. + * + * Return: Pointer to the allocated #MemoryRegion or NULL on error. + */ +MemoryRegion *memory_region_new_ram_nomigrate(Object *owner, + const char *name, uint64_t s= ize, + Error **errp); + +/** + * memory_region_new_ram_flags_nomigrate: Allocata and initialize RAM mem= ory + * region with flags. + * + * This is like memory_region_init_ram_flags_nomigrate() but allocates the + * #MemoryRegion and attaches is to the owner to free when the owner is fr= eed. + * + * @owner: the object that tracks the region's reference count + * @name: Region name, becomes part of RAMBlock name used in migration str= eam + * must be unique within any device + * @size: size of the region. + * @ram_flags: RamBlock flags. Supported flags: RAM_SHARED, RAM_NORESERVE, + * RAM_GUEST_MEMFD. + * @errp: pointer to Error*, to store an error if it happens. + * + * Note that this function does not do anything to cause the data in the + * RAM memory region to be migrated; that is the responsibility of the cal= ler. + * + * Return: Pointer to the allocated #MemoryRegion or NULL on error. + */ +MemoryRegion *memory_region_new_ram_flags_nomigrate(Object *owner, + const char *name, + uint64_t size, + uint32_t ram_flags, + Error **errp); + +/** + * memory_region_new_resizeable_ram: Allocate and initialize memory region + * with resizable RAM. + * + * This is like memory_region_init_resizable_ram() but allocates the + * #MemoryRegion and attaches is to the owner to free when the owner is fr= eed. + * + * @owner: the object that tracks the region's reference count + * @name: Region name, becomes part of RAMBlock name used in migration str= eam + * must be unique within any device + * @size: used size of the region. + * @max_size: max size of the region. + * @resized: callback to notify owner about used size change. + * @errp: pointer to Error*, to store an error if it happens. + * + * Note that this function does not do anything to cause the data in the + * RAM memory region to be migrated; that is the responsibility of the cal= ler. + * + * Return: Pointer to the allocated #MemoryRegion or NULL on error. + */ +MemoryRegion *memory_region_new_resizeable_ram(Object *owner, + const char *name, + uint64_t size, + uint64_t max_size, + void (*resized)(const char*, + uint64_t le= ngth, + void *host), + Error **errp); + +/** + * memory_region_new_ram_from_file: Allocate and initialize RAM memory re= gion + * with a mmap-ed backend. + * + * This is like memory_region_init_ram_from_file() but allocates the + * #MemoryRegion and attaches is to the owner to free when the owner is fr= eed. + * + * @owner: the object that tracks the region's reference count + * @name: Region name, becomes part of RAMBlock name used in migration str= eam + * must be unique within any device + * @size: size of the region. + * @align: alignment of the region base address; if 0, the default alignme= nt + * (getpagesize()) will be used. + * @ram_flags: RamBlock flags. Supported flags: RAM_SHARED, RAM_PMEM, + * RAM_NORESERVE, RAM_PROTECTED, RAM_NAMED_FILE, RAM_READONLY, + * RAM_READONLY_FD, RAM_GUEST_MEMFD + * @path: the path in which to allocate the RAM. + * @offset: offset within the file referenced by path + * @errp: pointer to Error*, to store an error if it happens. + * + * Note that this function does not do anything to cause the data in the + * RAM memory region to be migrated; that is the responsibility of the cal= ler. + * + * Return: Pointer to the allocated #MemoryRegion or NULL on error. + */ +MemoryRegion *memory_region_new_ram_from_file(Object *owner, + const char *name, + uint64_t size, + uint64_t align, + uint32_t ram_flags, + const char *path, + ram_addr_t offset, + Error **errp); + +/** + * memory_region_new_ram_from_fd: Allocate and initialize RAM memory regi= on + * with a mmap-ed backend. + * + * This is like memory_region_init_ram_from_fd() but allocates the + * #MemoryRegion and attaches is to the owner to free when the owner is fr= eed. + * + * @owner: the object that tracks the region's reference count + * @name: the name of the region. + * @size: size of the region. + * @ram_flags: RamBlock flags. Supported flags: RAM_SHARED, RAM_PMEM, + * RAM_NORESERVE, RAM_PROTECTED, RAM_NAMED_FILE, RAM_READONLY, + * RAM_READONLY_FD, RAM_GUEST_MEMFD + * @fd: the fd to mmap. + * @offset: offset within the file referenced by fd + * @errp: pointer to Error*, to store an error if it happens. + * + * Note that this function does not do anything to cause the data in the + * RAM memory region to be migrated; that is the responsibility of the cal= ler. + * + * Return: Pointer to the allocated #MemoryRegion or NULL on error. + */ +MemoryRegion *memory_region_new_ram_from_fd(Object *owner, + const char *name, uint64_t siz= e, + uint32_t ram_flags, int fd, + ram_addr_t offset, Error **err= p); + +/** + * memory_region_new_ram_ptr: Allocate and initialize RAM memory region f= rom a + * user-provided pointer. + * + * This is like memory_region_init_ram_ptr() but allocates the + * #MemoryRegion and attaches is to the owner to free when the owner is fr= eed. + * + * @owner: the object that tracks the region's reference count + * @name: Region name, becomes part of RAMBlock name used in migration str= eam + * must be unique within any device + * @size: size of the region. + * @ptr: memory to be mapped; must contain at least @size bytes. + * + * Note that this function does not do anything to cause the data in the + * RAM memory region to be migrated; that is the responsibility of the cal= ler. + * + * Return: Pointer to the allocated #MemoryRegion + */ +MemoryRegion *memory_region_new_ram_ptr(Object *owner, const char *name, + uint64_t size, void *ptr); + +/** + * memory_region_new_ram_device_ptr: Allocate and initialize RAM device m= emory + * region from a user-provided pointer. + * + * This is like memory_region_init_ram_device_ptr() but allocates the + * #MemoryRegion and attaches is to the owner to free when the owner is fr= eed. + * + * @owner: the object that tracks the region's reference count + * @name: the name of the region. + * @size: size of the region. + * @ptr: memory to be mapped; must contain at least @size bytes. + * + * Note that this function does not do anything to cause the data in the + * RAM memory region to be migrated; that is the responsibility of the cal= ler. + * (For RAM device memory regions, migrating the contents rarely makes sen= se.) + * + * Return: Pointer to the allocated #MemoryRegion + */ +MemoryRegion *memory_region_new_ram_device_ptr(Object *owner, const char *= name, + uint64_t size, void *ptr); + +/** + * memory_region_new_alias: Allocate and initialize a memory region that + * aliases all or a part of another memory regio= n. + * + * This is like memory_region_init_alias() but allocates the + * #MemoryRegion and attaches is to the owner to free when the owner is fr= eed. + * + * @owner: the object that tracks the region's reference count + * @name: used for debugging; not visible to the user or ABI + * @orig: the region to be referenced; @mr will be equivalent to + * @orig between @offset and @offset + @size - 1. + * @offset: start of the section in @orig to be referenced. + * @size: size of the region. + * + * Return: Pointer to the allocated #MemoryRegion + */ +MemoryRegion *memory_region_new_alias(Object *owner, + const char *name, MemoryRegion *orig, + hwaddr offset, uint64_t size); + +/** + * memory_region_new_rom_nomigrate: Allocate and initialize a ROM memory + * region. + * + * This is like memory_region_init_rom_nomigrate() but allocates the + * #MemoryRegion and attaches is to the owner to free when the owner is fr= eed. + * + * @owner: the object that tracks the region's reference count + * @name: Region name, becomes part of RAMBlock name used in migration str= eam + * must be unique within any device + * @size: size of the region. + * @errp: pointer to Error*, to store an error if it happens. + * + * Return: Pointer to the allocated #MemoryRegion or NULL on error. + */ +MemoryRegion *memory_region_new_rom_nomigrate(Object *owner, + const char *name, uint64_t s= ize, + Error **errp); + +/** + * memory_region_new_rom_device_nomigrate: Allocate and initialize a ROM + * device memory region. + * + * This is like memory_region_init_rom_device_nomigrate() but allocates the + * #MemoryRegion and attaches is to the owner to free when the owner is fr= eed. + * + * @owner: the object that tracks the region's reference count + * @ops: callbacks for write access handling (must not be NULL). + * @opaque: passed to the read and write callbacks of the @ops structure. + * @name: Region name, becomes part of RAMBlock name used in migration str= eam + * must be unique within any device + * @size: size of the region. + * @errp: pointer to Error*, to store an error if it happens. + * + * Note that this function does not do anything to cause the data in the + * RAM side of the memory region to be migrated; that is the responsibility + * of the caller. + * + * Return: Pointer to the allocated #MemoryRegion or NULL on error. + */ +MemoryRegion *memory_region_new_rom_device_nomigrate(Object *owner, + const MemoryRegionOps= *ops, + void *opaque, + const char *name, + uint64_t size, + Error **errp); +/** + * memory_region_new_ram - Allocate and initialize RAM memory region. + * + * This is like memory_region_init_ram() but allocates the + * #MemoryRegion and attaches is to the owner to free when the owner is fr= eed. + * + * @owner: the object that tracks the region's reference count (must be + * TYPE_DEVICE or a subclass of TYPE_DEVICE, or NULL) + * @name: name of the memory region + * @size: size of the region in bytes + * @errp: pointer to Error*, to store an error if it happens. + * + * TODO: Currently we restrict @owner to being either NULL (for + * global RAM regions with no owner) or devices, so that we can + * give the RAM block a unique name for migration purposes. + * We should lift this restriction and allow arbitrary Objects. + * If you pass a non-NULL non-device @owner then we will assert. + * + * Return: Pointer to the allocated #MemoryRegion or NULL on error. + */ +MemoryRegion *memory_region_new_ram(Object *owner, + const char *name, uint64_t size, + Error **errp); + +MemoryRegion *memory_region_new_ram_guest_memfd(Object *owner, + const char *name, + uint64_t size, + Error **errp); + +/** + * memory_region_new_rom: Allocate and initialize a ROM memory region. + * + * This is like memory_region_init_rom() but allocates the + * #MemoryRegion and attaches is to the owner to free when the owner is fr= eed. + * + * TODO: Currently we restrict @owner to being either NULL (for + * global RAM regions with no owner) or devices, so that we can + * give the RAM block a unique name for migration purposes. + * We should lift this restriction and allow arbitrary Objects. + * If you pass a non-NULL non-device @owner then we will assert. + * + * @owner: the object that tracks the region's reference count + * @name: Region name, becomes part of RAMBlock name used in migration str= eam + * must be unique within any device + * @size: size of the region. + * @errp: pointer to Error*, to store an error if it happens. + * + * Return: Pointer to the allocated #MemoryRegion or NULL on error. + */ +MemoryRegion *memory_region_new_rom(Object *owner, + const char *name, uint64_t size, + Error **errp); + +/** + * memory_region_new_rom_device: Allocate and initialize a ROM device mem= ory + * region. + * + * This is like memory_region_init_rom_device() but allocates the + * #MemoryRegion and attaches is to the owner to free when the owner is fr= eed. + * + * TODO: Currently we restrict @owner to being either NULL (for + * global RAM regions with no owner) or devices, so that we can + * give the RAM block a unique name for migration purposes. + * We should lift this restriction and allow arbitrary Objects. + * If you pass a non-NULL non-device @owner then we will assert. + * + * @owner: the object that tracks the region's reference count + * @ops: callbacks for write access handling (must not be NULL). + * @opaque: passed to the read and write callbacks of the @ops structure. + * @name: Region name, becomes part of RAMBlock name used in migration str= eam + * must be unique within any device + * @size: size of the region. + * @errp: pointer to Error*, to store an error if it happens. + * + * Return: Pointer to the allocated #MemoryRegion or NULL on error. + */ +MemoryRegion *memory_region_new_rom_device(Object *owner, + const MemoryRegionOps *ops, + void *opaque, + const char *name, uint64_t size, + Error **errp); =20 /** * memory_region_owner: get a memory region's owner. diff --git a/system/memory.c b/system/memory.c index 618d5d7f4d..b4d3ba50b9 100644 --- a/system/memory.c +++ b/system/memory.c @@ -1251,6 +1251,15 @@ void memory_region_init(MemoryRegion *mr, memory_region_do_init(mr, owner, name, size); } =20 +MemoryRegion *memory_region_new(Object *owner, const char *name, uint64_t = size) +{ + MemoryRegion *mr =3D MEMORY_REGION(object_new(TYPE_MEMORY_REGION)); + + assert(name); /* mr is attached to owner by name */ + memory_region_do_init(mr, owner, name, size); + return mr; +} + static void memory_region_get_container(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) @@ -1576,6 +1585,16 @@ void memory_region_init_io(MemoryRegion *mr, Object = *owner, memory_region_set_ops(mr, ops, opaque); } =20 +MemoryRegion *memory_region_new_io(Object *owner, + const MemoryRegionOps *ops, void *opaqu= e, + const char *name, uint64_t size) +{ + MemoryRegion *mr =3D memory_region_new(owner, name, size); + + memory_region_set_ops(mr, ops, opaque); + return mr; +} + static bool memory_region_do_init_ram(MemoryRegion *mr, Error *err, Error **errp) { @@ -1610,6 +1629,26 @@ bool memory_region_init_ram_nomigrate(MemoryRegion *= mr, Object *owner, errp); } =20 +MemoryRegion *memory_region_new_ram_flags_nomigrate(Object *owner, + const char *name, + uint64_t size, + uint32_t ram_flags, + Error **errp) +{ + MemoryRegion *mr =3D memory_region_new(owner, name, size); + Error *err =3D NULL; + + mr->ram_block =3D qemu_ram_alloc(size, ram_flags, mr, &err); + return memory_region_do_init_ram(mr, err, errp) ? mr : NULL; +} + +MemoryRegion *memory_region_new_ram_nomigrate(Object *owner, + const char *name, uint64_t s= ize, + Error **errp) +{ + return memory_region_new_ram_flags_nomigrate(owner, name, size, 0, err= p); +} + bool memory_region_init_resizeable_ram(MemoryRegion *mr, Object *owner, const char *name, @@ -1628,6 +1667,23 @@ bool memory_region_init_resizeable_ram(MemoryRegion = *mr, return memory_region_do_init_ram(mr, err, errp); } =20 +MemoryRegion *memory_region_new_resizeable_ram(Object *owner, + const char *name, + uint64_t size, + uint64_t max_size, + void (*resized)(const char*, + uint64_t le= ngth, + void *host), + Error **errp) +{ + MemoryRegion *mr =3D memory_region_new(owner, name, size); + Error *err =3D NULL; + + mr->ram_block =3D qemu_ram_alloc_resizeable(size, max_size, resized, m= r, + &err); + return memory_region_do_init_ram(mr, err, errp) ? mr : NULL; +} + #if defined(CONFIG_POSIX) && !defined(EMSCRIPTEN) bool memory_region_init_ram_from_file(MemoryRegion *mr, Object *owner, const char *name, uint64_t size, @@ -1645,6 +1701,25 @@ bool memory_region_init_ram_from_file(MemoryRegion *= mr, Object *owner, return memory_region_do_init_ram(mr, err, errp); } =20 +MemoryRegion *memory_region_new_ram_from_file(Object *owner, + const char *name, + uint64_t size, + uint64_t align, + uint32_t ram_flags, + const char *path, + ram_addr_t offset, + Error **errp) +{ + MemoryRegion *mr =3D memory_region_new(owner, name, size); + Error *err =3D NULL; + + mr->readonly =3D !!(ram_flags & RAM_READONLY); + mr->align =3D align; + mr->ram_block =3D qemu_ram_alloc_from_file(size, mr, ram_flags, path, = offset, + &err); + return memory_region_do_init_ram(mr, err, errp) ? mr : NULL; +} + bool memory_region_init_ram_from_fd(MemoryRegion *mr, Object *owner, const char *name, uint64_t size, uint32_t ram_flags, int fd, @@ -1658,6 +1733,20 @@ bool memory_region_init_ram_from_fd(MemoryRegion *mr= , Object *owner, offset, false, &err); return memory_region_do_init_ram(mr, err, errp); } + +MemoryRegion *memory_region_new_ram_from_fd(Object *owner, + const char *name, uint64_t siz= e, + uint32_t ram_flags, int fd, + ram_addr_t offset, Error **err= p) +{ + MemoryRegion *mr =3D memory_region_new(owner, name, size); + Error *err =3D NULL; + + mr->readonly =3D !!(ram_flags & RAM_READONLY); + mr->ram_block =3D qemu_ram_alloc_from_fd(size, size, NULL, mr, ram_fla= gs, fd, + offset, false, &err); + return memory_region_do_init_ram(mr, err, errp) ? mr : NULL; +} #endif =20 static void memory_region_do_init_ram_ptr(MemoryRegion *mr, uint64_t size, @@ -1676,6 +1765,15 @@ void memory_region_init_ram_ptr(MemoryRegion *mr, Ob= ject *owner, memory_region_do_init_ram_ptr(mr, size, ptr); } =20 +MemoryRegion *memory_region_new_ram_ptr(Object *owner, const char *name, + uint64_t size, void *ptr) +{ + MemoryRegion *mr =3D memory_region_new(owner, name, size); + + memory_region_do_init_ram_ptr(mr, size, ptr); + return mr; +} + void memory_region_init_ram_device_ptr(MemoryRegion *mr, Object *owner, const char *name, uint64_t size, void *ptr) @@ -1686,6 +1784,17 @@ void memory_region_init_ram_device_ptr(MemoryRegion = *mr, Object *owner, mr->ram_device =3D true; } =20 +MemoryRegion *memory_region_new_ram_device_ptr(Object *owner, const char *= name, + uint64_t size, void *ptr) +{ + MemoryRegion *mr =3D memory_region_new(owner, name, size); + + memory_region_set_ops(mr, &ram_device_mem_ops, mr); + memory_region_do_init_ram_ptr(mr, size, ptr); + mr->ram_device =3D true; + return mr; +} + void memory_region_init_alias(MemoryRegion *mr, Object *owner, const char *name, MemoryRegion *orig, hwaddr offset, uint64_t size) @@ -1695,6 +1804,17 @@ void memory_region_init_alias(MemoryRegion *mr, Obje= ct *owner, mr->alias_offset =3D offset; } =20 +MemoryRegion *memory_region_new_alias(Object *owner, + const char *name, MemoryRegion *orig, + hwaddr offset, uint64_t size) +{ + MemoryRegion *mr =3D memory_region_new(owner, name, size); + + mr->alias =3D orig; + mr->alias_offset =3D offset; + return mr; +} + bool memory_region_init_rom_nomigrate(MemoryRegion *mr, Object *owner, const char *name, uint64_t size, Error **errp) @@ -1706,6 +1826,20 @@ bool memory_region_init_rom_nomigrate(MemoryRegion *= mr, Object *owner, return true; } =20 +MemoryRegion *memory_region_new_rom_nomigrate(Object *owner, + const char *name, uint64_t s= ize, + Error **errp) +{ + MemoryRegion *mr; + + mr =3D memory_region_new_ram_nomigrate(owner, name, size, errp); + if (!mr) { + return NULL; + } + mr->readonly =3D true; + return mr; +} + bool memory_region_init_rom_device_nomigrate(MemoryRegion *mr, Object *owner, const MemoryRegionOps *ops, @@ -1729,6 +1863,27 @@ bool memory_region_init_rom_device_nomigrate(MemoryR= egion *mr, return ret; } =20 +MemoryRegion *memory_region_new_rom_device_nomigrate(Object *owner, + const MemoryRegionOps= *ops, + void *opaque, + const char *name, + uint64_t size, + Error **errp) +{ + MemoryRegion *mr =3D memory_region_new(owner, name, size); + Error *err =3D NULL; + + assert(ops); + memory_region_set_ops(mr, ops, opaque); + mr->ram_block =3D qemu_ram_alloc(size, 0, mr, &err); + if (memory_region_do_init_ram(mr, err, errp)) { + mr->ram =3D false; + mr->rom_device =3D true; + return mr; + } + return NULL; +} + void memory_region_init_iommu(void *_iommu_mr, size_t instance_size, const char *mrtypename, @@ -3703,6 +3858,19 @@ bool memory_region_init_ram(MemoryRegion *mr, Object= *owner, return true; } =20 +MemoryRegion *memory_region_new_ram(Object *owner, + const char *name, uint64_t size, + Error **errp) +{ + MemoryRegion *mr; + + mr =3D memory_region_new_ram_nomigrate(owner, name, size, errp); + if (mr) { + memory_region_register_ram(mr, owner); + } + return mr; +} + bool memory_region_init_ram_guest_memfd(MemoryRegion *mr, Object *owner, const char *name, uint64_t size, Error **errp) @@ -3715,6 +3883,21 @@ bool memory_region_init_ram_guest_memfd(MemoryRegion= *mr, Object *owner, return true; } =20 +MemoryRegion *memory_region_new_ram_guest_memfd(Object *owner, + const char *name, + uint64_t size, + Error **errp) +{ + MemoryRegion *mr; + + mr =3D memory_region_new_ram_flags_nomigrate(owner, name, size, + RAM_GUEST_MEMFD, errp); + if (mr) { + memory_region_register_ram(mr, owner); + } + return mr; +} + bool memory_region_init_rom(MemoryRegion *mr, Object *owner, const char *name, uint64_t size, Error **errp) @@ -3726,6 +3909,19 @@ bool memory_region_init_rom(MemoryRegion *mr, Object= *owner, return true; } =20 +MemoryRegion *memory_region_new_rom(Object *owner, + const char *name, uint64_t size, + Error **errp) +{ + MemoryRegion *mr; + + mr =3D memory_region_new_rom_nomigrate(owner, name, size, errp); + if (mr) { + memory_region_register_ram(mr, owner); + } + return mr; +} + bool memory_region_init_rom_device(MemoryRegion *mr, Object *owner, const MemoryRegionOps *ops, void *opaqu= e, const char *name, uint64_t size, @@ -3739,6 +3935,22 @@ bool memory_region_init_rom_device(MemoryRegion *mr,= Object *owner, return true; } =20 +MemoryRegion *memory_region_new_rom_device(Object *owner, + const MemoryRegionOps *ops, + void *opaque, + const char *name, uint64_t size, + Error **errp) +{ + MemoryRegion *mr; + + mr =3D memory_region_new_rom_device_nomigrate(owner, ops, opaque, name= , size, + errp); + if (mr) { + memory_region_register_ram(mr, owner); + } + return mr; +} + /* * Support system builds with CONFIG_FUZZ using a weak symbol and a stub f= or * the fuzz_dma_read_cb callback --=20 2.41.3 From nobody Sat Feb 7 05:44:15 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=eik.bme.hu Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1769366089161832.8157914287846; Sun, 25 Jan 2026 10:34:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vk4wE-0006gm-UU; Sun, 25 Jan 2026 13:34:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vk4wD-0006ep-Ii for qemu-devel@nongnu.org; Sun, 25 Jan 2026 13:34:17 -0500 Received: from zero.eik.bme.hu ([2001:738:2001:2001::2001]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vk4wA-0002nS-LE for qemu-devel@nongnu.org; Sun, 25 Jan 2026 13:34:17 -0500 Received: from localhost (localhost [127.0.0.1]) by zero.eik.bme.hu (Postfix) with ESMTP id 47ACF5974FC; Sun, 25 Jan 2026 19:34:12 +0100 (CET) Received: from zero.eik.bme.hu ([127.0.0.1]) by localhost (zero.eik.bme.hu [127.0.0.1]) (amavis, port 10028) with ESMTP id JWyxWWGHBb2f; Sun, 25 Jan 2026 19:34:10 +0100 (CET) Received: by zero.eik.bme.hu (Postfix, from userid 432) id E98C45974CE; Sun, 25 Jan 2026 18:51:02 +0100 (CET) X-Virus-Scanned: amavis at eik.bme.hu Message-ID: In-Reply-To: References: From: BALATON Zoltan Subject: [PATCH v2 07/10] memory: Update documentation for memory_region_new*() MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable To: qemu-devel@nongnu.org Cc: Peter Xu , Akihiko Odaki , Paolo Bonzini , Michael S. Tsirkin , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Date: Sun, 25 Jan 2026 18:51:02 +0100 (CET) Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2001:738:2001:2001::2001; envelope-from=balaton@eik.bme.hu; helo=zero.eik.bme.hu X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1769366095792158500 Content-Type: text/plain; charset="utf-8" Clarify the difference between memory_region_new() and memory_region_init() with regard to region lifecycle. Signed-off-by: BALATON Zoltan --- docs/devel/memory.rst | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/docs/devel/memory.rst b/docs/devel/memory.rst index f22146e56c..60eaea8df7 100644 --- a/docs/devel/memory.rst +++ b/docs/devel/memory.rst @@ -142,7 +142,8 @@ stability. Region lifecycle ---------------- =20 -A region is created by one of the memory_region_init*() functions and +A region is allocated by one of the memory_region_new*() functions or +pre-allocated and initialized by memory_region_init*() functions and attached to an object, which acts as its owner or parent. QEMU ensures that the owner object remains alive as long as the region is visible to the guest, or as long as the region is in use by a virtual CPU or another @@ -158,16 +159,16 @@ ioeventfd) can be changed during the region lifecycle= . They take effect as soon as the region is made visible. This can be immediately, later, or never. =20 -Destruction of a memory region happens automatically when the owner object -dies. When there are multiple memory regions under the same owner object, -the memory API will guarantee all memory regions will be properly detached -and finalized one by one. The order in which memory regions will be -finalized is not guaranteed. +Destruction of a memory region allocated with memory_region_new*() functio= ns +happens automatically when the owner object dies. When there are multiple +memory regions under the same owner object, the memory API will guarantee = all +memory regions will be properly detached and finalized one by one. The or= der +in which memory regions will be finalized is not guaranteed. =20 -If however the memory region is part of a dynamically allocated data -structure, you should free the memory region in the instance_finalize -callback. For an example see VFIOMSIXInfo and VFIOQuirk in -hw/vfio/pci.c. +If however the memory region is part of a separately allocated data struct= ure +and initialized with one of the memory_region_init*() functions, you may h= ave +to free the memory region e.g. in an instance_finalize callback. For an +example see VFIOMSIXInfo and VFIOQuirk in hw/vfio/pci.c. =20 You must not destroy a memory region as long as it may be in use by a device or CPU. In order to do this, as a general rule do not create or --=20 2.41.3 From nobody Sat Feb 7 05:44:15 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=eik.bme.hu Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1769366148286433.5112904187537; Sun, 25 Jan 2026 10:35:48 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vk4wF-0006hr-Jv; Sun, 25 Jan 2026 13:34:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vk4wD-0006f8-L1 for qemu-devel@nongnu.org; Sun, 25 Jan 2026 13:34:17 -0500 Received: from zero.eik.bme.hu ([2001:738:2001:2001::2001]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vk4wA-0002nG-GX for qemu-devel@nongnu.org; Sun, 25 Jan 2026 13:34:17 -0500 Received: from localhost (localhost [127.0.0.1]) by zero.eik.bme.hu (Postfix) with ESMTP id 755FA5974FE; Sun, 25 Jan 2026 19:34:10 +0100 (CET) Received: from zero.eik.bme.hu ([127.0.0.1]) by localhost (zero.eik.bme.hu [127.0.0.1]) (amavis, port 10028) with ESMTP id v_y9rsM8YZvB; Sun, 25 Jan 2026 19:34:08 +0100 (CET) Received: by zero.eik.bme.hu (Postfix, from userid 432) id 03ED05974CF; Sun, 25 Jan 2026 18:51:04 +0100 (CET) X-Virus-Scanned: amavis at eik.bme.hu Message-ID: In-Reply-To: References: From: BALATON Zoltan Subject: [PATCH v2 08/10] hw/ide/sii3112: Use memory_region_new to avoid leaking regions MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable To: qemu-devel@nongnu.org Cc: Peter Xu , Akihiko Odaki , Paolo Bonzini , Michael S. Tsirkin , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Date: Sun, 25 Jan 2026 18:51:04 +0100 (CET) Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2001:738:2001:2001::2001; envelope-from=balaton@eik.bme.hu; helo=zero.eik.bme.hu X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1769366153133154100 Content-Type: text/plain; charset="utf-8" Memory regions created with memory_region_init are not freed with their owner. Use memory_region_new instead to let QOM manage the lifetime of the memory regions. Signed-off-by: BALATON Zoltan --- hw/ide/sii3112.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/hw/ide/sii3112.c b/hw/ide/sii3112.c index 9b28c691fd..d2dcfc3830 100644 --- a/hw/ide/sii3112.c +++ b/hw/ide/sii3112.c @@ -31,7 +31,7 @@ typedef struct SiI3112Regs { =20 struct SiI3112PCIState { PCIIDEState i; - MemoryRegion mmio; + SiI3112Regs regs[2]; }; =20 @@ -249,39 +249,33 @@ static void sii3112_reset(DeviceState *dev) =20 static void sii3112_pci_realize(PCIDevice *dev, Error **errp) { - SiI3112PCIState *d =3D SII3112_PCI(dev); PCIIDEState *s =3D PCI_IDE(dev); DeviceState *ds =3D DEVICE(dev); - MemoryRegion *mr; - int i; + Object *o =3D OBJECT(dev); + MemoryRegion *mmio, *mr; =20 pci_config_set_interrupt_pin(dev->config, 1); pci_set_byte(dev->config + PCI_CACHE_LINE_SIZE, 8); =20 /* BAR5 is in PCI memory space */ - memory_region_init_io(&d->mmio, OBJECT(d), &sii3112_reg_ops, d, - "sii3112.bar5", 0x200); - pci_register_bar(dev, 5, PCI_BASE_ADDRESS_SPACE_MEMORY, &d->mmio); + mmio =3D memory_region_new_io(o, &sii3112_reg_ops, SII3112_PCI(dev), + "sii3112.bar5", 0x200); + pci_register_bar(dev, 5, PCI_BASE_ADDRESS_SPACE_MEMORY, mmio); =20 /* BAR0-BAR4 are PCI I/O space aliases into BAR5 */ - mr =3D g_new(MemoryRegion, 1); - memory_region_init_alias(mr, OBJECT(d), "sii3112.bar0", &d->mmio, 0x80= , 8); + mr =3D memory_region_new_alias(o, "sii3112.bar0", mmio, 0x80, 8); pci_register_bar(dev, 0, PCI_BASE_ADDRESS_SPACE_IO, mr); - mr =3D g_new(MemoryRegion, 1); - memory_region_init_alias(mr, OBJECT(d), "sii3112.bar1", &d->mmio, 0x88= , 4); + mr =3D memory_region_new_alias(o, "sii3112.bar1", mmio, 0x88, 4); pci_register_bar(dev, 1, PCI_BASE_ADDRESS_SPACE_IO, mr); - mr =3D g_new(MemoryRegion, 1); - memory_region_init_alias(mr, OBJECT(d), "sii3112.bar2", &d->mmio, 0xc0= , 8); + mr =3D memory_region_new_alias(o, "sii3112.bar2", mmio, 0xc0, 8); pci_register_bar(dev, 2, PCI_BASE_ADDRESS_SPACE_IO, mr); - mr =3D g_new(MemoryRegion, 1); - memory_region_init_alias(mr, OBJECT(d), "sii3112.bar3", &d->mmio, 0xc8= , 4); + mr =3D memory_region_new_alias(o, "sii3112.bar3", mmio, 0xc8, 4); pci_register_bar(dev, 3, PCI_BASE_ADDRESS_SPACE_IO, mr); - mr =3D g_new(MemoryRegion, 1); - memory_region_init_alias(mr, OBJECT(d), "sii3112.bar4", &d->mmio, 0, 1= 6); + mr =3D memory_region_new_alias(o, "sii3112.bar4", mmio, 0, 16); pci_register_bar(dev, 4, PCI_BASE_ADDRESS_SPACE_IO, mr); =20 qdev_init_gpio_in(ds, sii3112_set_irq, 2); - for (i =3D 0; i < 2; i++) { + for (int i =3D 0; i < 2; i++) { ide_bus_init(&s->bus[i], sizeof(s->bus[i]), ds, i, 1); ide_bus_init_output_irq(&s->bus[i], qdev_get_gpio_in(ds, i)); =20 --=20 2.41.3 From nobody Sat Feb 7 05:44:15 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=eik.bme.hu Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1769366113783188.52672363439683; Sun, 25 Jan 2026 10:35:13 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vk4wG-0006iR-4L; Sun, 25 Jan 2026 13:34:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vk4wD-0006fx-TS for qemu-devel@nongnu.org; Sun, 25 Jan 2026 13:34:17 -0500 Received: from zero.eik.bme.hu ([152.66.115.2]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vk4wA-0002nH-Gx for qemu-devel@nongnu.org; Sun, 25 Jan 2026 13:34:17 -0500 Received: from localhost (localhost [127.0.0.1]) by zero.eik.bme.hu (Postfix) with ESMTP id 5DC8A5974F8; Sun, 25 Jan 2026 19:34:10 +0100 (CET) Received: from zero.eik.bme.hu ([127.0.0.1]) by localhost (zero.eik.bme.hu [127.0.0.1]) (amavis, port 10028) with ESMTP id FZ4sAf4sXUly; Sun, 25 Jan 2026 19:34:08 +0100 (CET) Received: by zero.eik.bme.hu (Postfix, from userid 432) id 0F0745974D0; Sun, 25 Jan 2026 18:51:05 +0100 (CET) X-Virus-Scanned: amavis at eik.bme.hu Message-ID: <7005aea5c5a6d750e172ae0d3183578f066ac268.1769362313.git.balaton@eik.bme.hu> In-Reply-To: References: From: BALATON Zoltan Subject: [PATCH v2 09/10] hw/pci-host/articia: Map PCI memory windows in realize MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable To: qemu-devel@nongnu.org Cc: Peter Xu , Akihiko Odaki , Paolo Bonzini , Michael S. Tsirkin , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Date: Sun, 25 Jan 2026 18:51:05 +0100 (CET) Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=152.66.115.2; envelope-from=balaton@eik.bme.hu; helo=zero.eik.bme.hu X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1769366117125154100 These memory windows are a result of the address decoding in the Articia S north bridge so better model it there and not in board code. Suggested-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: BALATON Zoltan --- hw/pci-host/articia.c | 14 +++++++++++++- hw/ppc/amigaone.c | 28 +++++----------------------- hw/ppc/pegasos.c | 13 ------------- 3 files changed, 18 insertions(+), 37 deletions(-) diff --git a/hw/pci-host/articia.c b/hw/pci-host/articia.c index 1881e03d58..6e14604311 100644 --- a/hw/pci-host/articia.c +++ b/hw/pci-host/articia.c @@ -22,6 +22,11 @@ * Most features are missing but those are not needed by firmware and gues= ts. */ =20 +#define PCI_HIGH_ADDR 0x80000000 +#define PCI_HIGH_SIZE 0x7d000000 +#define PCI_LOW_ADDR 0xfd000000 +#define PCI_LOW_SIZE 0x1000000 + OBJECT_DECLARE_SIMPLE_TYPE(ArticiaState, ARTICIA) =20 OBJECT_DECLARE_SIMPLE_TYPE(ArticiaHostState, ARTICIA_PCI_HOST) @@ -169,6 +174,7 @@ static void articia_realize(DeviceState *dev, Error **e= rrp) { ArticiaState *s =3D ARTICIA(dev); PCIHostState *h =3D PCI_HOST_BRIDGE(dev); + MemoryRegion *mr; PCIDevice *pdev; =20 bitbang_i2c_init(&s->smbus, i2c_init_bus(dev, "smbus")); @@ -181,6 +187,13 @@ static void articia_realize(DeviceState *dev, Error **= errp) TYPE_ARTICIA, 0x1000000); memory_region_add_subregion_overlap(&s->reg, 0, &s->io, 1); =20 + mr =3D memory_region_new_alias(OBJECT(dev), "pci-mem-low", &s->mem, 0, + PCI_LOW_SIZE); + memory_region_add_subregion(get_system_memory(), PCI_LOW_ADDR, mr); + mr =3D memory_region_new_alias(OBJECT(dev), "pci-mem-high", &s->mem, + PCI_HIGH_ADDR, PCI_HIGH_SIZE); + memory_region_add_subregion(get_system_memory(), PCI_HIGH_ADDR, mr); + /* devfn_min is 8 that matches first PCI slot in AmigaOne */ h->bus =3D pci_register_root_bus(dev, NULL, articia_pcihost_set_irq, amigaone_pcihost_bus0_map_irq, dev, &s-= >mem, @@ -191,7 +204,6 @@ static void articia_realize(DeviceState *dev, Error **e= rrp) pci_create_simple(h->bus, PCI_DEVFN(0, 1), TYPE_ARTICIA_PCI_BRIDGE); =20 sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->reg); - sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->mem); qdev_init_gpio_out(dev, s->irq, ARRAY_SIZE(s->irq)); } =20 diff --git a/hw/ppc/amigaone.c b/hw/ppc/amigaone.c index 8074713fbe..17deacab44 100644 --- a/hw/ppc/amigaone.c +++ b/hw/ppc/amigaone.c @@ -35,13 +35,6 @@ #define INITRD_MIN_ADDR 0x600000 #define INIT_RAM_ADDR 0x40000000 =20 -#define PCI_HIGH_ADDR 0x80000000 -#define PCI_HIGH_SIZE 0x7d000000 -#define PCI_LOW_ADDR 0xfd000000 -#define PCI_LOW_SIZE 0xe0000 - -#define ARTICIA_ADDR 0xfe000000 - /* * Firmware binary available at * https://www.hyperion-entertainment.com/index.php/downloads?view=3Dfiles= &parent=3D28 @@ -267,7 +260,7 @@ static void amigaone_init(MachineState *machine) { PowerPCCPU *cpu; CPUPPCState *env; - MemoryRegion *rom, *pci_mem, *mr; + MemoryRegion *rom, *mr; ssize_t sz; PCIBus *pci_bus; Object *via; @@ -308,8 +301,8 @@ static void amigaone_init(MachineState *machine) qdev_prop_set_drive(dev, "drive", blk_by_legacy_dinfo(di)); } sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); - memory_region_add_subregion(get_system_memory(), NVRAM_ADDR, - sysbus_mmio_get_region(SYS_BUS_DEVICE(dev)= , 0)); + mr =3D sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 0); + memory_region_add_subregion_overlap(get_system_memory(), NVRAM_ADDR, m= r, 1); =20 /* allocate and load firmware */ rom =3D g_new(MemoryRegion, 1); @@ -329,8 +322,8 @@ static void amigaone_init(MachineState *machine) } =20 /* Articia S */ - dev =3D sysbus_create_simple(TYPE_ARTICIA, ARTICIA_ADDR, NULL); - + dev =3D sysbus_create_simple(TYPE_ARTICIA, 0xfe000000, NULL); + pci_bus =3D PCI_BUS(qdev_get_child_bus(dev, "pci.0")); i2c_bus =3D I2C_BUS(qdev_get_child_bus(dev, "smbus")); if (machine->ram_size > 512 * MiB) { spd_data =3D spd_data_generate(SDR, machine->ram_size / 2); @@ -343,17 +336,6 @@ static void amigaone_init(MachineState *machine) smbus_eeprom_init_one(i2c_bus, 0x52, spd_data); } =20 - pci_mem =3D sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 1); - mr =3D g_new(MemoryRegion, 1); - memory_region_init_alias(mr, OBJECT(dev), "pci-mem-low", pci_mem, - 0, PCI_LOW_SIZE); - memory_region_add_subregion(get_system_memory(), PCI_LOW_ADDR, mr); - mr =3D g_new(MemoryRegion, 1); - memory_region_init_alias(mr, OBJECT(dev), "pci-mem-high", pci_mem, - PCI_HIGH_ADDR, PCI_HIGH_SIZE); - memory_region_add_subregion(get_system_memory(), PCI_HIGH_ADDR, mr); - pci_bus =3D PCI_BUS(qdev_get_child_bus(dev, "pci.0")); - /* VIA VT82c686B South Bridge (multifunction PCI device) */ via =3D OBJECT(pci_create_simple_multifunction(pci_bus, PCI_DEVFN(7, 0= ), TYPE_VT82C686B_ISA)); diff --git a/hw/ppc/pegasos.c b/hw/ppc/pegasos.c index ac9fc5a654..e0e2e8815d 100644 --- a/hw/ppc/pegasos.c +++ b/hw/ppc/pegasos.c @@ -213,23 +213,10 @@ static void pegasos_init(MachineState *machine) /* north bridge */ switch (pm->type) { case PEGASOS1: - { - MemoryRegion *pci_mem, *mr; - /* Articia S */ pm->nb =3D DEVICE(sysbus_create_simple(TYPE_ARTICIA, 0xfe000000, N= ULL)); - pci_mem =3D sysbus_mmio_get_region(SYS_BUS_DEVICE(pm->nb), 1); - mr =3D g_new(MemoryRegion, 1); - memory_region_init_alias(mr, OBJECT(pm->nb), "pci-mem-low", pci_me= m, - 0, 0x1000000); - memory_region_add_subregion(get_system_memory(), 0xfd000000, mr); - mr =3D g_new(MemoryRegion, 1); - memory_region_init_alias(mr, OBJECT(pm->nb), "pci-mem-high", pci_m= em, - 0x80000000, 0x7d000000); - memory_region_add_subregion(get_system_memory(), 0x80000000, mr); pci_bus =3D PCI_BUS(qdev_get_child_bus(pm->nb, "pci.0")); break; - } case PEGASOS2: /* Marvell Discovery II system controller */ pm->nb =3D DEVICE(sysbus_create_simple(TYPE_MV64361, -1, --=20 2.41.3 From nobody Sat Feb 7 05:44:15 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=eik.bme.hu Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1769366108483384.63018789484374; Sun, 25 Jan 2026 10:35:08 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vk4wn-0007I0-LM; Sun, 25 Jan 2026 13:34:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vk4wl-0007FD-Uz for qemu-devel@nongnu.org; Sun, 25 Jan 2026 13:34:51 -0500 Received: from zero.eik.bme.hu ([152.66.115.2]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vk4wk-0002rg-Ed for qemu-devel@nongnu.org; Sun, 25 Jan 2026 13:34:51 -0500 Received: from localhost (localhost [127.0.0.1]) by zero.eik.bme.hu (Postfix) with ESMTP id 4C0585974BD; Sun, 25 Jan 2026 19:34:49 +0100 (CET) Received: from zero.eik.bme.hu ([127.0.0.1]) by localhost (zero.eik.bme.hu [127.0.0.1]) (amavis, port 10028) with ESMTP id Gub-2KzC4SUV; Sun, 25 Jan 2026 19:34:47 +0100 (CET) Received: by zero.eik.bme.hu (Postfix, from userid 432) id 1AFF85974D1; Sun, 25 Jan 2026 18:51:06 +0100 (CET) X-Virus-Scanned: amavis at eik.bme.hu Message-ID: <7fda963bf82cad6c2854f648c4205156f56cec4a.1769362313.git.balaton@eik.bme.hu> In-Reply-To: References: From: BALATON Zoltan Subject: [PATCH v2 10/10] hw/pci-host/articia: Add variable for common type cast MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable To: qemu-devel@nongnu.org Cc: Peter Xu , Akihiko Odaki , Paolo Bonzini , Michael S. Tsirkin , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Date: Sun, 25 Jan 2026 18:51:06 +0100 (CET) Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=152.66.115.2; envelope-from=balaton@eik.bme.hu; helo=zero.eik.bme.hu X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1769366111759154100 Content-Type: text/plain; charset="utf-8" We need the device casted to OBJECT often enough in realize to store it in a local variable that also makes function calls more readable. Signed-off-by: BALATON Zoltan --- hw/pci-host/articia.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/hw/pci-host/articia.c b/hw/pci-host/articia.c index 6e14604311..e418d3dac3 100644 --- a/hw/pci-host/articia.c +++ b/hw/pci-host/articia.c @@ -174,24 +174,24 @@ static void articia_realize(DeviceState *dev, Error *= *errp) { ArticiaState *s =3D ARTICIA(dev); PCIHostState *h =3D PCI_HOST_BRIDGE(dev); + Object *o =3D OBJECT(dev); MemoryRegion *mr; PCIDevice *pdev; =20 bitbang_i2c_init(&s->smbus, i2c_init_bus(dev, "smbus")); - memory_region_init_io(&s->gpio_reg, OBJECT(s), &articia_gpio_ops, s, + memory_region_init_io(&s->gpio_reg, o, &articia_gpio_ops, s, TYPE_ARTICIA, 4); =20 - memory_region_init(&s->mem, OBJECT(dev), "pci-mem", UINT64_MAX); - memory_region_init(&s->io, OBJECT(dev), "pci-io", 0xc00000); - memory_region_init_io(&s->reg, OBJECT(s), &articia_reg_ops, s, + memory_region_init(&s->mem, o, "pci-mem", UINT64_MAX); + memory_region_init(&s->io, o, "pci-io", 0xc00000); + memory_region_init_io(&s->reg, o, &articia_reg_ops, s, TYPE_ARTICIA, 0x1000000); memory_region_add_subregion_overlap(&s->reg, 0, &s->io, 1); =20 - mr =3D memory_region_new_alias(OBJECT(dev), "pci-mem-low", &s->mem, 0, - PCI_LOW_SIZE); + mr =3D memory_region_new_alias(o, "pci-mem-low", &s->mem, 0, PCI_LOW_S= IZE); memory_region_add_subregion(get_system_memory(), PCI_LOW_ADDR, mr); - mr =3D memory_region_new_alias(OBJECT(dev), "pci-mem-high", &s->mem, - PCI_HIGH_ADDR, PCI_HIGH_SIZE); + mr =3D memory_region_new_alias(o, "pci-mem-high", &s->mem, PCI_HIGH_AD= DR, + PCI_HIGH_SIZE); memory_region_add_subregion(get_system_memory(), PCI_HIGH_ADDR, mr); =20 /* devfn_min is 8 that matches first PCI slot in AmigaOne */ --=20 2.41.3