From nobody Thu Apr 2 18:55:20 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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1774610686; cv=none; d=zohomail.com; s=zohoarc; b=YCuR4rV9M20DExKSxZ+sjaKA0d99lfZOLS8QlrwMKz372pktGvtblYJpkoLiBc6FUj6dvQnynSVn5XBxagjuiKFCzs4bfzNBgZ0hhTK7dffjb1U+Zq2i1p2CZP4EKl3j/ZPDI2xVQ/LteNYpTxmugWQG4S14qMkYTbywJEJnqrU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774610686; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=zg0JdMYpNPucplnhgObUVKgc6cBxcpxKCbSlMlmDTlo=; b=U8zC/TMboK2UnV/c8bdR4oNm89FdtaigrBlCmkeIyyZEWOgwECVAnmQ4h63IibrqeCnXbSg4lB3OmLdAVEwURYcGrizoksDdOCejq9qm2z2AgLS/B1+ofdyiwKgxEgdxe4cvbvV9BtlVo6j7RNzDO5BHGI24zzFrzwAS7Qys88Y= 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 1774610686648509.5764681683013; Fri, 27 Mar 2026 04:24:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w65DS-0000NR-PZ; Fri, 27 Mar 2026 07:19:04 -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 1w65CT-0007Rf-SU for qemu-devel@nongnu.org; Fri, 27 Mar 2026 07:18:03 -0400 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1w65CO-00006q-PL for qemu-devel@nongnu.org; Fri, 27 Mar 2026 07:17:59 -0400 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-439b2965d4bso1507057f8f.2 for ; Fri, 27 Mar 2026 04:17:56 -0700 (PDT) Received: from lanath.. (wildly.archaic.org.uk. [81.2.115.145]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43b919cf2b2sm15484227f8f.18.2026.03.27.04.17.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Mar 2026 04:17:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1774610275; x=1775215075; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zg0JdMYpNPucplnhgObUVKgc6cBxcpxKCbSlMlmDTlo=; b=j8D3pVma0SwUF2JB7puMBVFO4rnfV3/MHoBIKmRxA9YRvvMIjkKNAebiQ5mB2e9CCz FhOcMTUzURNtOmik5aZa/4opeWlB1htRHTszYds4XYJLaIvYiO/CHqkV5uA90hWDnusw Wq6z3tWAj+etEiFgxMGKYI4ZhgKSzEdef4NlH+hgb/SjfTMfXydJCyvPZWaeltbss28O wl55mvKW/og1Yi58/1vJWv3/7L7nOyp9jZO/mVuINd3UY8fUL4aHyW57/nrjmglKqAIA i79/5mykcFqcBfXWiS93nqRdhaC0MaQ9aA4+nQUHcZnMwPEEt/KuFIZDR19xKqKGpD8Q Toqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774610275; x=1775215075; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=zg0JdMYpNPucplnhgObUVKgc6cBxcpxKCbSlMlmDTlo=; b=fhp0mRFxQs3wCRXGBzAgQV2j/It6/Fs8ppF+BUOnbG7AoH5Rw1toQvqYDc5xcplz/9 yCM50O5rjxW3ObHAzIWC+EoqJh6xKG+1kVrXGQzzhz7pj7mBKNrpEOlxNMqO8X3llmbK rtgf5wqYmDHeaIVAmBcZld8gKq19AVLeXck9aXFKnYKD7O2SpBes9+1F83yhJv41wwpn wcvS3wHZJpdL5a5y33aafUj/a3cAc6wvj+tLd7s+UOTbYhz+AuHPdYztr29N8glXJqmb AH3j2bWPSjD33lcZwrydNjINJV1J2ioQFB8uR94WanDi2g6oMpPwFsHDcSufmJQiBZmW 02XA== X-Forwarded-Encrypted: i=1; AJvYcCWX0D8Z/ALpQO3RZVN/FLpX/SwkpyF97POfH+TZdXQD3xmqyUPijX7yPYmOFTbM6Qfm76DF5BZf36z0@nongnu.org X-Gm-Message-State: AOJu0YzHoSEjsTaNyE7QedW5QsV9cICOahKTliAjqT73H5EJOTz1Hr/b LiVnLfFcLYIC8rSRbiojIndq+PN7VD6pMpO8i3QZJCsvHgLFssn9OqKs9m8vLkfULpM= X-Gm-Gg: ATEYQzzywLwMpBexc8FWlCAIBHMXS1CxYvBCOO0vTpQ77gkBXVp3wNGZ8ICGvG3C46v 3+GPbmeG72fUhJlQDyio0UZ9XRoGJOBcYoMBBAt2L4mZDP7E9rN+B5IdQ6aVm4EJ8LObT3tboMh dkBjd9j8d62VWF5YaNXZPf7o3zyTJnw5G9X1796uqQ19WcyQqA4quXG7MZfS4hFniLTPYQvlCZH 4ZC9dPrN5r3h1SSEyrcGOZCSOyAMnyrVwNHlbrgyHYkTTfy1m8y0YQpht/dwBzbdsJjOTvHFbJ2 QS9AlmBj2kDKi675QNnhHWbHrkatj3EIF/UbhMIdYiP8ogQTsrtPROiYTRhmmvwmC7ZQam5CMJ/ wkMIMRKhct8JTxpVuSQmLlm7yyLLg6FDf/yPjtSTWC0+BU5tUh56FjUPSQQTAb6w3qKWxfuolax d/C+9xmGmS27qP5dg1y1aNCgzuSIZ/l303HEQXvnq6Soc5X7wIfItBPZdt9pL7b449equpPH9sE yrywbi0OwyDNUvIQmsOmk7rEt43Uk0= X-Received: by 2002:a5d:64e6:0:b0:43b:5037:7ef3 with SMTP id ffacd0b85a97d-43b9e9e8bdamr3113357f8f.20.1774610275201; Fri, 27 Mar 2026 04:17:55 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Cc: Jonathan Cameron Subject: [PATCH v2 56/65] hw/arm/virt: Remember CPU phandles rather than looking them up by name Date: Fri, 27 Mar 2026 11:16:51 +0000 Message-ID: <20260327111700.795099-57-peter.maydell@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260327111700.795099-1-peter.maydell@linaro.org> References: <20260327111700.795099-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=2a00:1450:4864:20::42d; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42d.google.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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1774610688913154100 In fdt_add_cpu_nodes(), we currently add phandles for each CPU node if we are going to add a topology description, and when we do, we re-look-up the phandle by node name when creating the topology description. For GICv5 we will also want to refer to the CPU phandles; so always add a phandle, and keep track of those phandles in the VirtMachineState so we don't have to look them up by name in the dtb every time. The phandle property is extra data in the final DTB, but only a tiny amount, so it's not worth trying to carefully track the conditions when we're going to need them so we only emit them when required. (We need to change the smp_cpus variable to unsigned because otherwise gcc thinks that we might be passing a negative number to g_new0() and produces an error: /usr/include/glib-2.0/glib/gmem.h:270:19: error: argument 1 range [18446744= 071562067968, 18446744073709551615] exceeds maximum object size 92233720368= 54775807 [-Werror=3Dalloc-size-larger-than=3D] 270 | __p =3D g_##func##_n (__n, __s); \ | ^~~~~~~~~~~~~~~~~~~~~~~ /usr/include/glib-2.0/glib/gmem.h:332:57: note: in expansion of macro =E2= =80=98_G_NEW=E2=80=99 332 | #define g_new0(struct_type, n_structs) _G_NEW (str= uct_type, n_structs, malloc0) | ^~~~~~ ../../hw/arm/virt.c:469:25: note: in expansion of macro =E2=80=98g_new0=E2= =80=99 469 | vms->cpu_phandles =3D g_new0(uint32_t, smp_cpus); | ^~~~~~ ) Signed-off-by: Peter Maydell Reviewed-by: Jonathan Cameron --- hw/arm/virt.c | 19 ++++++++++--------- include/hw/arm/virt.h | 1 + 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index ec0d8475ca..91097e25ec 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -431,13 +431,13 @@ static void fdt_add_timer_nodes(const VirtMachineStat= e *vms) } } =20 -static void fdt_add_cpu_nodes(const VirtMachineState *vms) +static void fdt_add_cpu_nodes(VirtMachineState *vms) { int cpu; int addr_cells =3D 1; const MachineState *ms =3D MACHINE(vms); const VirtMachineClass *vmc =3D VIRT_MACHINE_GET_CLASS(vms); - int smp_cpus =3D ms->smp.cpus; + unsigned int smp_cpus =3D ms->smp.cpus; =20 /* * See Linux Documentation/devicetree/bindings/arm/cpus.yaml @@ -465,10 +465,13 @@ static void fdt_add_cpu_nodes(const VirtMachineState = *vms) qemu_fdt_setprop_cell(ms->fdt, "/cpus", "#address-cells", addr_cells); qemu_fdt_setprop_cell(ms->fdt, "/cpus", "#size-cells", 0x0); =20 + vms->cpu_phandles =3D g_new0(uint32_t, smp_cpus); + for (cpu =3D smp_cpus - 1; cpu >=3D 0; cpu--) { char *nodename =3D g_strdup_printf("/cpus/cpu@%d", cpu); ARMCPU *armcpu =3D ARM_CPU(qemu_get_cpu(cpu)); CPUState *cs =3D CPU(armcpu); + uint32_t phandle; =20 qemu_fdt_add_subnode(ms->fdt, nodename); qemu_fdt_setprop_string(ms->fdt, nodename, "device_type", "cpu"); @@ -493,10 +496,9 @@ static void fdt_add_cpu_nodes(const VirtMachineState *= vms) ms->possible_cpus->cpus[cs->cpu_index].props.node_id); } =20 - if (!vmc->no_cpu_topology) { - qemu_fdt_setprop_cell(ms->fdt, nodename, "phandle", - qemu_fdt_alloc_phandle(ms->fdt)); - } + phandle =3D qemu_fdt_alloc_phandle(ms->fdt); + qemu_fdt_setprop_cell(ms->fdt, nodename, "phandle", phandle); + vms->cpu_phandles[cpu] =3D phandle; =20 g_free(nodename); } @@ -521,7 +523,6 @@ static void fdt_add_cpu_nodes(const VirtMachineState *v= ms) qemu_fdt_add_subnode(ms->fdt, "/cpus/cpu-map"); =20 for (cpu =3D smp_cpus - 1; cpu >=3D 0; cpu--) { - char *cpu_path =3D g_strdup_printf("/cpus/cpu@%d", cpu); char *map_path; =20 if (ms->smp.threads > 1) { @@ -539,10 +540,10 @@ static void fdt_add_cpu_nodes(const VirtMachineState = *vms) cpu % ms->smp.cores); } qemu_fdt_add_path(ms->fdt, map_path); - qemu_fdt_setprop_phandle(ms->fdt, map_path, "cpu", cpu_path); + qemu_fdt_setprop_cell(ms->fdt, map_path, "cpu", + vms->cpu_phandles[cpu]); =20 g_free(map_path); - g_free(cpu_path); } } } diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h index 5fcbd1c76f..22bbc34ca8 100644 --- a/include/hw/arm/virt.h +++ b/include/hw/arm/virt.h @@ -171,6 +171,7 @@ struct VirtMachineState { uint32_t gic_phandle; uint32_t msi_phandle; uint32_t iommu_phandle; + uint32_t *cpu_phandles; int psci_conduit; uint8_t virtio_transports; hwaddr highest_gpa; --=20 2.43.0