From nobody Sun Apr 12 04:27:13 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=1771866668; cv=none; d=zohomail.com; s=zohoarc; b=Qlvj9c/B9GCh5uOdEhP4/dOEF5b1s2Acd9blwPqcrPw8NhQoyvk8RBUYR4dimGtehGQ6bVmVIKDFiKlTKjdWrRdR5uVAVQFM6ePQq88aVwaE10Py2Bx/GDW0RFLSMHsC1M9KF6VqcVuUwnvXNg72p1pgS5xjc/9xt7DEfDNwTFc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771866668; h=Content-Type:Content-Transfer-Encoding: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:Cc; bh=mcNmYKDo1AyTBqKWkeuzf3y95VGP3Xb6elYJJZdrymY=; b=TwMpzOSLi0Jv0/Zl9WzY9ivE/v4AUNzYiSsICaKys6GVhKmeq1Szl/umfXUIc6CJcpwFeld4YYsznqnM7LRMThaVpFeGm+j5ESs4Arh/ZyufYA8n0bIAIBxUBuBVntwPJ86UorQf/vU0A00IWIq8BEhvXf91MpH3P9Fqt9qHDJE= 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 1771866668631288.183314696171; Mon, 23 Feb 2026 09:11:08 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vuZMR-0004sM-KG; Mon, 23 Feb 2026 12:04:45 -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 1vuZLE-0002vf-6b for qemu-devel@nongnu.org; Mon, 23 Feb 2026 12:03:32 -0500 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vuZL9-0000Qt-Bx for qemu-devel@nongnu.org; Mon, 23 Feb 2026 12:03:27 -0500 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-483abed83b6so14153015e9.0 for ; Mon, 23 Feb 2026 09:03:17 -0800 (PST) Received: from lanath.. (wildly.archaic.org.uk. [81.2.115.145]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-483a9b21ceasm200155625e9.0.2026.02.23.09.03.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Feb 2026 09:03:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1771866196; x=1772470996; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=mcNmYKDo1AyTBqKWkeuzf3y95VGP3Xb6elYJJZdrymY=; b=Lqw9RkMTnO/iJLUNOj5EV/tON4t6DPvUzAd58+uuM+W0AQhO0YMGw+qpe1GKi5NxuG 0XwsqlMzTJeNd1m0Xt37vCVM6gELFCHU+Y1EJOysaSB6ZtW2pfWMtSDAtglYGSrG7nQ3 ZvSb6LfzJM+Fa/zMiQo46nbQSETeq1KdUGBrL3o+XIGo+WHHSAt2UOkdRH18Dq+EHOW7 Frvd4DFqFRRZuzW+Hem3JS7JvyNDSe1UyE7cXWfvMSjKnl7NLJ8pjZ8gCSh5e9V6UMdT 7lLWhgG3E0uALPKfjZVKiC0Va93Uyy2V82lDX9RKGpYbsC+Z/Ohn7IU43e97lcBgiFe4 +33g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771866196; x=1772470996; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=mcNmYKDo1AyTBqKWkeuzf3y95VGP3Xb6elYJJZdrymY=; b=UXPr3cbd+ogQxXRb7tLPC7K+75DmW9mg9pUeB5XIXB62LThac21I/PszypxZutvRyT n8WpJkGqzo2RlxByfdfHXj2rWdO6aycaoJ/oQT8xhbvBumamENrUQm7dy/eklBaArXs4 +JA4Qw2zBxd+wVhMP9Zb2g5EZRDe/rZ2sAMYVwA3ARght+5BjHoBjVKnTdE6GlKerEBz HFBjTtQdqx6fCjpEnkmhdpe9SWodrjDQNJ1Xc0GYlTg0yYCd2vbBGS/+Mwz44lDPbc4l FnqMM3NtAcKxlMMURbkc3pEkM1MUUQTGTwE8JNfKrgWnNbZm/UpcIyyFPXTrUa3lYMql lqFg== X-Forwarded-Encrypted: i=1; AJvYcCVRWZOiacMFr7tANXUEyZK4nDzMb8LuM5QnkVmUMTL/6lgBfyMO3EUoNSQS2HOyyCCj1OUZIvvNgHU0@nongnu.org X-Gm-Message-State: AOJu0YydvJ4pWh2/Q+auJmj60SOqDnOtc8PeDoh1ByJKKWJ5vtzSteSm giHjvfyUphBql0P4UZUz9HiJRxhsQIQmDjDwlMMq+8kzVDbVR/HNPYaDjzSzs+k2fFg= X-Gm-Gg: AZuq6aKHvGliKdFT0hSx8mM6geUNAhZAsKyF6IBqNjQ55Z884FA+HE1U/1XK6Ns0d7v X/ukVlYC3m9sWRZjD2GDutOV1QKtg40Mdz/CU2BpJ6dftXCgpTxrZfTfbKJHMyFCkuB2LgU27NT PZzev/AUOSNR6siI11ZwQRoBs10x+a/L9Q999+hruyewOSiVTBp+gvasjQ5wbZW5ldkwmH68tGr eKKmaeNaVhYwLeUfiDbPrCNncNytv+ayjAuY+4mW4AVVhmDMo6HcL81Qqrs4bmujqtH9rInqREn syEraQo0j7Q+75FumytbJpqj0TiBFvjqDGhCzgB6Dv2j+MmaGR5gKJuv4tlbi4k+xCmiDlJ3YJX xKQ+WT6ISkwrzQ0aFoxjSk0gTSIrbpOltmXDt0FuWCezV/PeHwXJmDHLKhfhSfojQRjXWvNCZ8B 2n7qRvHbsyEz45XsRtCF/nLUZult1fiwrNFHk1vkForZdnpTrlXfdY3eqvjPFdfPJBbPRzJNKsu 4a5GOYdXVGzc7OuG0CeYsJmIL7yvwE= X-Received: by 2002:a05:600c:314a:b0:47e:e2eb:bc22 with SMTP id 5b1f17b1804b1-483a95b3e62mr166806815e9.5.1771866196245; Mon, 23 Feb 2026 09:03:16 -0800 (PST) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH 56/65] hw/arm/virt: Remember CPU phandles rather than looking them up by name Date: Mon, 23 Feb 2026 17:02:03 +0000 Message-ID: <20260223170212.441276-57-peter.maydell@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260223170212.441276-1-peter.maydell@linaro.org> References: <20260223170212.441276-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::334; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x334.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=unavailable 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: 1771866685766158500 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 8dc999712c..0d1032967c 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -432,13 +432,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 @@ -466,10 +466,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"); @@ -494,10 +497,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); } @@ -522,7 +524,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) { @@ -540,10 +541,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 8069422769..6b4691761e 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; hwaddr highest_gpa; DeviceState *gic; --=20 2.43.0