From nobody Sun Nov 16 04:03:37 2025 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 1743374146785859.0951548163852; Sun, 30 Mar 2025 15:35:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tz1F6-0003oE-QG; Sun, 30 Mar 2025 18:35:03 -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 1tz1Ex-0003nq-4r; Sun, 30 Mar 2025 18:34:51 -0400 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 1tz1Ev-0002Jh-4v; Sun, 30 Mar 2025 18:34:50 -0400 Received: from zero.eik.bme.hu (localhost [127.0.0.1]) by zero.eik.bme.hu (Postfix) with ESMTP id 9BA9E4E6041; Mon, 31 Mar 2025 00:34:44 +0200 (CEST) Received: from zero.eik.bme.hu ([127.0.0.1]) by zero.eik.bme.hu (zero.eik.bme.hu [127.0.0.1]) (amavisd-new, port 10028) with ESMTP id rA3qO74CbdBC; Mon, 31 Mar 2025 00:34:42 +0200 (CEST) Received: by zero.eik.bme.hu (Postfix, from userid 432) id 930724E6036; Mon, 31 Mar 2025 00:34:42 +0200 (CEST) X-Virus-Scanned: amavisd-new at eik.bme.hu From: BALATON Zoltan Subject: [PATCH] ppc/vof: Make nextprop behave more like Open Firmware To: qemu-devel@nongnu.org, qemu-ppc@nongnu.org Cc: Nicholas Piggin , Daniel Henrique Barboza , Harsh Prateek Bora , Alexey Kardashevskiy Message-Id: <20250330223442.930724E6036@zero.eik.bme.hu> Date: Mon, 31 Mar 2025 00:34:42 +0200 (CEST) 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 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: 1743374154463019000 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The FDT does not normally store name properties but reconsrtucts it from path but each node in Open Firmware should at least have this property. This is correctly handled in getprop but nextprop should also return it even if not present as a property. This patch fixes that and also skips phandle which does not appear in Open Firmware and only added for internal use by VOF. Explicit name properties are still allowed because they are needed e.g. on the root node that guests expect to have specific names as seen on real machines instead of being empty so sometimes the node name may need to be overriden. Signed-off-by: BALATON Zoltan --- I've tested this with pegasos2 but don't know how to test spapr. hw/ppc/vof.c | 56 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 15 deletions(-) diff --git a/hw/ppc/vof.c b/hw/ppc/vof.c index 09cb77de93..2c00d11521 100644 --- a/hw/ppc/vof.c +++ b/hw/ppc/vof.c @@ -353,34 +353,60 @@ static uint32_t vof_nextprop(const void *fdt, uint32_= t phandle, { int offset, nodeoff =3D fdt_node_offset_by_phandle(fdt, phandle); char prev[OF_PROPNAME_LEN_MAX + 1]; - const char *tmp; + const char *tmp =3D NULL; =20 if (readstr(prevaddr, prev, sizeof(prev))) { return PROM_ERROR; } - - fdt_for_each_property_offset(offset, fdt, nodeoff) { - if (!fdt_getprop_by_offset(fdt, offset, &tmp, NULL)) { - return 0; + /* + * "name" may or may not be present in fdt but we should still return = it. + * Do that first and then skip it if seen later. Also skip phandle whi= ch is + * an internal value we added in vof_build_dt but should not appear he= re. + */ + if (prev[0] =3D=3D '\0') { + tmp =3D "name"; + } else { + if (strcmp(prev, "name") =3D=3D 0) { + prev[0] =3D '\0'; } - if (prev[0] =3D=3D '\0' || strcmp(prev, tmp) =3D=3D 0) { - if (prev[0] !=3D '\0') { + fdt_for_each_property_offset(offset, fdt, nodeoff) { + if (!fdt_getprop_by_offset(fdt, offset, &tmp, NULL)) { + return 0; + } + if (strcmp(tmp, "name") =3D=3D 0 || strcmp(tmp, "phandle") =3D= =3D 0) { + continue; + } + if (prev[0] =3D=3D '\0') { + break; + } + if (strcmp(prev, tmp) =3D=3D 0) { offset =3D fdt_next_property_offset(fdt, offset); - if (offset < 0) { - return 0; - } + break; } + } + if (!fdt_getprop_by_offset(fdt, offset, &tmp, NULL)) { + return 0; + } + if (strcmp(tmp, "name") =3D=3D 0 || strcmp(tmp, "phandle") =3D=3D = 0) { + offset =3D fdt_next_property_offset(fdt, offset); if (!fdt_getprop_by_offset(fdt, offset, &tmp, NULL)) { return 0; } - - if (VOF_MEM_WRITE(nameaddr, tmp, strlen(tmp) + 1) !=3D MEMTX_O= K) { - return PROM_ERROR; + } + /* name and phandle can follow each other so check again */ + if (strcmp(tmp, "name") =3D=3D 0 || strcmp(tmp, "phandle") =3D=3D = 0) { + offset =3D fdt_next_property_offset(fdt, offset); + if (!fdt_getprop_by_offset(fdt, offset, &tmp, NULL)) { + return 0; } - return 1; } } - + if (tmp) { + if (VOF_MEM_WRITE(nameaddr, tmp, strlen(tmp) + 1) !=3D MEMTX_OK) { + return PROM_ERROR; + } + return 1; + } return 0; } =20 --=20 2.41.3