From nobody Sun Feb 8 23:05:16 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1687524483; cv=none; d=zohomail.com; s=zohoarc; b=Ty89jlT9vYHb31YT/DgT3FU3jihrirXeznSlDnCS8OC5CgUBkW34/xSQG+PIz+RibI1VVPCtkqI0aCZqsrKDoWtOk0wqfUQH54ePmRPBHLnXjhmtCbDz27wn242ITksrK/t16bGyC/DcKD4D8AuDHdmyM9+4tcI8tN5qPtBCxKo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687524483; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=DpY+YdyZgMDc1cbYNJcvvVMtZKgCSiKfLNMocUDN0eU=; b=gBTmvmB4gkRID9U5Vi5Mtq09fQBnHAC+rGzqKA9t2ZOniOqOzE+5m4D/5I7g53sO9+MZabZOgz+MwWppa8EOTsRAxja2ntjfCZ72PriNJBqSYJ3ENh/nY/kq1hlwJ5tRN3Ju9RQcf65bsiiiHWUR8Cv6hDcfBxjXRV1eNTRJir8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1687524483180549.7377893612346; Fri, 23 Jun 2023 05:48:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qCgBD-0001fb-42; Fri, 23 Jun 2023 08:46:23 -0400 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 1qCgBA-0001cj-QX for qemu-devel@nongnu.org; Fri, 23 Jun 2023 08:46:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qCgB9-0000oN-4f for qemu-devel@nongnu.org; Fri, 23 Jun 2023 08:46:20 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-248-5zrWeMCiM8WKzYq_l65fIg-1; Fri, 23 Jun 2023 08:46:15 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6B6AD3C11A1C; Fri, 23 Jun 2023 12:46:14 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.22.32.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id 82DF21121314; Fri, 23 Jun 2023 12:46:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687524378; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DpY+YdyZgMDc1cbYNJcvvVMtZKgCSiKfLNMocUDN0eU=; b=aCwmeomGoEeIM0E0guhMKnMClprCKM+Qsv9IJw12isJpRsKx9JStwMScezjRUZuLbvjV+u lVKkjLMYdWfaDXZKfkyRWtWAs5wGKMWpU3tKs8J+IFCldUImq6a6ggl8JFqAeY7Xu9KaLX E0to+EP3MD11hlVvGTyHuR8qDSPudmI= X-MC-Unique: 5zrWeMCiM8WKzYq_l65fIg-1 From: David Hildenbrand To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, qemu-ppc@nongnu.org, Igor Mammedov , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Xiao Guangrong , David Hildenbrand , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Daniel Henrique Barboza , David Gibson , Eduardo Habkost , Greg Kurz , Harsh Prateek Bora , Marcel Apfelbaum , "Michael S. Tsirkin" , Paolo Bonzini , Peter Maydell , Richard Henderson , Song Gao , Xiaojuan Yang Subject: [PATCH v4 04/10] hw/ppc/spapr: Use machine_memory_devices_init() Date: Fri, 23 Jun 2023 14:45:47 +0200 Message-Id: <20230623124553.400585-5-david@redhat.com> In-Reply-To: <20230623124553.400585-1-david@redhat.com> References: <20230623124553.400585-1-david@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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=170.10.133.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: 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-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1687524484451100001 Let's use our new helper and stop always allocating ms->device_memory. There is no difference in common memory-device code anymore between ms->device_memory being NULL or the size being 0. So we only have to teach spapr code that ms->device_memory isn't always around. We can now modify two maxram_size checks to rely on ms->device_memory for detecting whether we have memory devices. Cc: Daniel Henrique Barboza Cc: "C=C3=A9dric Le Goater" Cc: David Gibson Cc: Greg Kurz Cc: Harsh Prateek Bora Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: David Hildenbrand --- hw/ppc/spapr.c | 37 +++++++++++++++++++------------------ hw/ppc/spapr_hcall.c | 2 +- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index dcb7f1c70a..b53aa4b5a8 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -546,10 +546,8 @@ static int spapr_dt_dynamic_reconfiguration_memory(Spa= prMachineState *spapr, cpu_to_be32(lmb_size & 0xffffffff)}; MemoryDeviceInfoList *dimms =3D NULL; =20 - /* - * Don't create the node if there is no device memory - */ - if (machine->ram_size =3D=3D machine->maxram_size) { + /* Don't create the node if there is no device memory. */ + if (!machine->device_memory) { return 0; } =20 @@ -859,16 +857,23 @@ static void spapr_dt_rtas(SpaprMachineState *spapr, v= oid *fdt) int rtas; GString *hypertas =3D g_string_sized_new(256); GString *qemu_hypertas =3D g_string_sized_new(256); - uint64_t max_device_addr =3D MACHINE(spapr)->device_memory->base + - memory_region_size(&MACHINE(spapr)->device_memory->mr); uint32_t lrdr_capacity[] =3D { - cpu_to_be32(max_device_addr >> 32), - cpu_to_be32(max_device_addr & 0xffffffff), + 0, + 0, cpu_to_be32(SPAPR_MEMORY_BLOCK_SIZE >> 32), cpu_to_be32(SPAPR_MEMORY_BLOCK_SIZE & 0xffffffff), cpu_to_be32(ms->smp.max_cpus / ms->smp.threads), }; =20 + /* Do we have device memory? */ + if (MACHINE(spapr)->device_memory) { + uint64_t max_device_addr =3D MACHINE(spapr)->device_memory->base + + memory_region_size(&MACHINE(spapr)->device_memory->mr); + + lrdr_capacity[0] =3D cpu_to_be32(max_device_addr >> 32); + lrdr_capacity[1] =3D cpu_to_be32(max_device_addr & 0xffffffff); + } + _FDT(rtas =3D fdt_add_subnode(fdt, 0, "rtas")); =20 /* hypertas */ @@ -2454,6 +2459,7 @@ static void spapr_create_lmb_dr_connectors(SpaprMachi= neState *spapr) uint32_t nr_lmbs =3D (machine->maxram_size - machine->ram_size)/lmb_si= ze; int i; =20 + g_assert(!nr_lmbs || machine->device_memory); for (i =3D 0; i < nr_lmbs; i++) { uint64_t addr; =20 @@ -2866,12 +2872,11 @@ static void spapr_machine_init(MachineState *machin= e) /* map RAM */ memory_region_add_subregion(sysmem, 0, machine->ram); =20 - /* always allocate the device memory information */ - machine->device_memory =3D g_malloc0(sizeof(*machine->device_memory)); - /* initialize hotplug memory address space */ if (machine->ram_size < machine->maxram_size) { ram_addr_t device_mem_size =3D machine->maxram_size - machine->ram= _size; + hwaddr device_mem_base; + /* * Limit the number of hotpluggable memory slots to half the number * slots that KVM supports, leaving the other half for PCI and oth= er @@ -2890,12 +2895,8 @@ static void spapr_machine_init(MachineState *machine) exit(1); } =20 - machine->device_memory->base =3D ROUND_UP(machine->ram_size, - SPAPR_DEVICE_MEM_ALIGN); - memory_region_init(&machine->device_memory->mr, OBJECT(spapr), - "device-memory", device_mem_size); - memory_region_add_subregion(sysmem, machine->device_memory->base, - &machine->device_memory->mr); + device_mem_base =3D ROUND_UP(machine->ram_size, SPAPR_DEVICE_MEM_A= LIGN); + machine_memory_devices_init(machine, device_mem_base, device_mem_s= ize); } =20 if (smc->dr_lmb_enabled) { @@ -5109,7 +5110,7 @@ static bool phb_placement_2_7(SpaprMachineState *spap= r, uint32_t index, int i; =20 /* Do we have device memory? */ - if (MACHINE(spapr)->maxram_size > ram_top) { + if (MACHINE(spapr)->device_memory) { /* Can't just use maxram_size, because there may be an * alignment gap between normal and device memory regions */ diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c index b904755575..1dd32f340f 100644 --- a/hw/ppc/spapr_hcall.c +++ b/hw/ppc/spapr_hcall.c @@ -31,7 +31,7 @@ bool is_ram_address(SpaprMachineState *spapr, hwaddr addr) if (addr < machine->ram_size) { return true; } - if ((addr >=3D dms->base) + if (dms && (addr >=3D dms->base) && ((addr - dms->base) < memory_region_size(&dms->mr))) { return true; } --=20 2.40.1