From nobody Sat Nov 8 05:53:06 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1550153329449467.27755752781934; Thu, 14 Feb 2019 06:08:49 -0800 (PST) Received: from localhost ([127.0.0.1]:49232 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guHgv-0000eR-JV for importer@patchew.org; Thu, 14 Feb 2019 09:08:41 -0500 Received: from eggs.gnu.org ([209.51.188.92]:38705) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guHfy-0000Ho-Cz for qemu-devel@nongnu.org; Thu, 14 Feb 2019 09:07:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1guHfr-0004OJ-BS for qemu-devel@nongnu.org; Thu, 14 Feb 2019 09:07:42 -0500 Received: from mx1.redhat.com ([209.132.183.28]:3131) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1guHfh-0004CE-4Y; Thu, 14 Feb 2019 09:07:26 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2ABF189AF3; Thu, 14 Feb 2019 14:07:20 +0000 (UTC) Received: from dell-r430-03.lab.eng.brq.redhat.com (dell-r430-03.lab.eng.brq.redhat.com [10.37.153.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 40D87277CF; Thu, 14 Feb 2019 14:07:18 +0000 (UTC) From: Igor Mammedov To: qemu-devel@nongnu.org Date: Thu, 14 Feb 2019 09:07:14 -0500 Message-Id: <20190214140714.15738-1-imammedo@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 14 Feb 2019 14:07:20 +0000 (UTC) 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] [RFC] memory: use memory_region_init_ram() instead of memory_region_allocate_system_memory() 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: peter.maydell@linaro.org, ehabkost@redhat.com, mark.cave-ayland@ilande.co.uk, qemu-arm@nongnu.org, jan.kiszka@web.de, pbonzini@redhat.com, atar4qemu@gmail.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" I'm considering to deprecating -mem-path/prealloc CLI options and replacing them with a single memdev Machine property to allow interested users to pick used backend for initial RAM (fixes mixed -mem-path+hostmem backends issues) and as a transition step to modeling initial as a Device instead of (ab)usi= ng MemoryRegion APIs. Currently most boards use memory_region_allocate_system_memory() to allocate RAM and the interface tied up too much to MemoryRegion that makes changing = API to hostmem across tree is quite a bit of work sometimes requiring logic rew= rite to do it cleanly and I'm not sure it's worth the effort and that it really = has a merit to do in case of TCG only boards. I suggest to get rid memory_region_allocate_system_memory() on TCG only boa= rds since most of them don't really need NUMA features provided by this API and= /or probably won't noticeably benefit from -mem-path/prealloc backed memory if = at all and replacing memory allocation with plain memory_region_init_ram() API. It won't require extensive changes in TCG only boards we have now, since th= ey would continue to use MemoryRegion based API approach. And the boards, that reall= y need to use hugepages or numa features, could be amended to use new machine memd= ev property and/or initial RAM being allocated by implictly (-m) using hostmem= -ram backend. Also some boards (ab)use memory_region_allocate_system_memory(), calling it= several times to allocate various fixed sized chunks of RAM and ROMs, which is prob= lematic to map to a single initial RAM Machine::memdev backend and is currently bro= ken if -mem-path points to a not hugepage pool. This RFC attempts to cleanup things a bit on TCG only boards (only several = ones) side and test waters if it's acceptable approach. If it looks acceptable, = I'll send a proper series to make usage of memory_region_allocate_system_memory() min= imal across the codebase and then convert boards that actually use numa/hugepages to in= itial RAM memdev model (arm/virt, spapr, s390x, pc/q35). Signed-off-by: Igor Mammedov --- hw/arm/musicpal.c | 4 ++-- hw/arm/vexpress.c | 4 ++-- hw/sparc64/niagara.c | 30 +++++++++++++++--------------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/hw/arm/musicpal.c b/hw/arm/musicpal.c index d22532a11c..197e7d1282 100644 --- a/hw/arm/musicpal.c +++ b/hw/arm/musicpal.c @@ -1592,8 +1592,8 @@ static void musicpal_init(MachineState *machine) cpu =3D ARM_CPU(cpu_create(machine->cpu_type)); =20 /* For now we use a fixed - the original - RAM size */ - memory_region_allocate_system_memory(ram, NULL, "musicpal.ram", - MP_RAM_DEFAULT_SIZE); + memory_region_init_ram(ram, NULL, "musicpal.ram", MP_RAM_DEFAULT_SIZE, + &error_fatal); memory_region_add_subregion(address_space_mem, 0, ram); =20 memory_region_init_ram(sram, NULL, "musicpal.sram", MP_SRAM_SIZE, diff --git a/hw/arm/vexpress.c b/hw/arm/vexpress.c index c02d18ee61..a2cf5c0af2 100644 --- a/hw/arm/vexpress.c +++ b/hw/arm/vexpress.c @@ -280,8 +280,8 @@ static void a9_daughterboard_init(const VexpressMachine= State *vms, exit(1); } =20 - memory_region_allocate_system_memory(ram, NULL, "vexpress.highmem", - ram_size); + memory_region_init_ram(ram, NULL, "vexpress.highmem", ram_size, + &error_fatal); low_ram_size =3D ram_size; if (low_ram_size > 0x4000000) { low_ram_size =3D 0x4000000; diff --git a/hw/sparc64/niagara.c b/hw/sparc64/niagara.c index f8a856f611..62e0348d5f 100644 --- a/hw/sparc64/niagara.c +++ b/hw/sparc64/niagara.c @@ -37,6 +37,7 @@ #include "sysemu/block-backend.h" #include "qemu/error-report.h" #include "sysemu/qtest.h" +#include "qapi/error.h" =20 =20 typedef struct NiagaraBoardState { @@ -108,27 +109,26 @@ static void niagara_init(MachineState *machine) /* init CPUs */ sparc64_cpu_devinit(machine->cpu_type, NIAGARA_PROM_BASE); /* set up devices */ - memory_region_allocate_system_memory(&s->hv_ram, NULL, "sun4v-hv.ram", - NIAGARA_HV_RAM_SIZE); + memory_region_init_ram(&s->hv_ram, NULL, "sun4v-hv.ram", + NIAGARA_HV_RAM_SIZE, &error_fatal= ); memory_region_add_subregion(sysmem, NIAGARA_HV_RAM_BASE, &s->hv_ram); =20 - memory_region_allocate_system_memory(&s->partition_ram, NULL, - "sun4v-partition.ram", - machine->ram_size); + memory_region_init_ram(&s->partition_ram, NULL, "sun4v-partition.ram", + machine->ram_size, &error_fatal); memory_region_add_subregion(sysmem, NIAGARA_PARTITION_RAM_BASE, &s->partition_ram); =20 - memory_region_allocate_system_memory(&s->nvram, NULL, - "sun4v.nvram", NIAGARA_NVRAM_SIZE= ); + memory_region_init_ram(&s->nvram, NULL, "sun4v.nvram", NIAGARA_NVRAM_S= IZE, + &error_fatal); memory_region_add_subregion(sysmem, NIAGARA_NVRAM_BASE, &s->nvram); - memory_region_allocate_system_memory(&s->md_rom, NULL, - "sun4v-md.rom", NIAGARA_MD_ROM_SI= ZE); + memory_region_init_ram(&s->md_rom, NULL, "sun4v-md.rom", + NIAGARA_MD_ROM_SIZE, &error_fatal); memory_region_add_subregion(sysmem, NIAGARA_MD_ROM_BASE, &s->md_rom); - memory_region_allocate_system_memory(&s->hv_rom, NULL, - "sun4v-hv.rom", NIAGARA_HV_ROM_SI= ZE); + memory_region_init_ram(&s->hv_rom, NULL, "sun4v-hv.rom", + NIAGARA_HV_ROM_SIZE, &error_fatal); memory_region_add_subregion(sysmem, NIAGARA_HV_ROM_BASE, &s->hv_rom); - memory_region_allocate_system_memory(&s->prom, NULL, - "sun4v.prom", PROM_SIZE_MAX); + memory_region_init_ram(&s->prom, NULL, "sun4v.prom", + PROM_SIZE_MAX, &error_fatal); memory_region_add_subregion(sysmem, NIAGARA_PROM_BASE, &s->prom); =20 add_rom_or_fail("nvram1", NIAGARA_NVRAM_BASE); @@ -145,8 +145,8 @@ static void niagara_init(MachineState *machine) BlockBackend *blk =3D blk_by_legacy_dinfo(dinfo); int size =3D blk_getlength(blk); if (size > 0) { - memory_region_allocate_system_memory(&s->vdisk_ram, NULL, - "sun4v_vdisk.ram", size); + memory_region_init_ram(&s->vdisk_ram, NULL, "sun4v_vdisk.ram",= size, + &error_fatal); memory_region_add_subregion(get_system_memory(), NIAGARA_VDISK_BASE, &s->vdisk_ram); dinfo->is_default =3D 1; --=20 2.18.1