From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 711DBC433B4 for ; Mon, 19 Apr 2021 03:10:59 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EDF3661077 for ; Mon, 19 Apr 2021 03:10:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EDF3661077 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:57376 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lYKJN-0000IE-TA for qemu-devel@archiver.kernel.org; Sun, 18 Apr 2021 23:10:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44602) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lYKGP-0006rR-Fb; Sun, 18 Apr 2021 23:07:53 -0400 Received: from ozlabs.org ([203.11.71.1]:52311) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lYKGL-00051c-Pv; Sun, 18 Apr 2021 23:07:53 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 4FNsFD25l3z9vFw; Mon, 19 Apr 2021 13:07:44 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1618801664; bh=w2UaCUrwMSDTeRtzF21Fd2RxFtLOu1xUGwpvcG2RF2o=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=hd5dC4rMMSiD5WlJK+uZ7FgCOAbseeKpfaDowCWZeWafQh1tYvgOFOJ0QFwQt4Pi3 O6Ee6qnQeTLGaR/SeI0OoWVkswZwUh8cKZgqKCSiDgpljNHz+C4EnPH25SAQ4yhB+0 n+cRlT0vpjbCTIJXTj0utbjfGzi/PRtW0vrPRWlA= Date: Mon, 19 Apr 2021 11:13:10 +1000 From: David Gibson To: "wangyanan (Y)" Subject: Re: [RFC PATCH v2 1/6] device_tree: Add qemu_fdt_add_path Message-ID: References: <20210413080745.33004-1-wangyanan55@huawei.com> <20210413080745.33004-2-wangyanan55@huawei.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="8G0E95ZjzJYq2SwN" Content-Disposition: inline In-Reply-To: Received-SPF: pass client-ip=203.11.71.1; envelope-from=dgibson@ozlabs.org; helo=ozlabs.org X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Andrew Jones , "Michael S . Tsirkin" , wanghaibin.wang@huawei.com, qemu-devel@nongnu.org, Shannon Zhao , qemu-arm@nongnu.org, Alistair Francis , prime.zeng@hisilicon.com, yangyicong@huawei.com, yuzenghui@huawei.com, Igor Mammedov , zhukeqian1@huawei.com, Jiajie Li Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" --8G0E95ZjzJYq2SwN Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Apr 17, 2021 at 10:36:20AM +0800, wangyanan (Y) wrote: > Hi David, >=20 > On 2021/4/16 12:52, David Gibson wrote: > > On Tue, Apr 13, 2021 at 04:07:40PM +0800, Yanan Wang wrote: > > > From: Andrew Jones > > >=20 > > > qemu_fdt_add_path() works like qemu_fdt_add_subnode(), except > > > it also adds any missing subnodes in the path. We also tweak > > > an error message of qemu_fdt_add_subnode(). > > >=20 > > > We'll make use of this new function in a coming patch. > > >=20 > > > Signed-off-by: Andrew Jones > > > Signed-off-by: Yanan Wang > > > --- > > > include/sysemu/device_tree.h | 1 + > > > softmmu/device_tree.c | 45 +++++++++++++++++++++++++++++++++= +-- > > > 2 files changed, 44 insertions(+), 2 deletions(-) > > >=20 > > > diff --git a/include/sysemu/device_tree.h b/include/sysemu/device_tre= e.h > > > index 8a2fe55622..ef060a9759 100644 > > > --- a/include/sysemu/device_tree.h > > > +++ b/include/sysemu/device_tree.h > > > @@ -121,6 +121,7 @@ uint32_t qemu_fdt_get_phandle(void *fdt, const ch= ar *path); > > > uint32_t qemu_fdt_alloc_phandle(void *fdt); > > > int qemu_fdt_nop_node(void *fdt, const char *node_path); > > > int qemu_fdt_add_subnode(void *fdt, const char *name); > > > +int qemu_fdt_add_path(void *fdt, const char *path); > > > #define qemu_fdt_setprop_cells(fdt, node_path, property, ...) = \ > > > do { = \ > > > diff --git a/softmmu/device_tree.c b/softmmu/device_tree.c > > > index 2691c58cf6..8592c7aa1b 100644 > > > --- a/softmmu/device_tree.c > > > +++ b/softmmu/device_tree.c > > > @@ -541,8 +541,8 @@ int qemu_fdt_add_subnode(void *fdt, const char *n= ame) > > > retval =3D fdt_add_subnode(fdt, parent, basename); > > > if (retval < 0) { > > > - error_report("FDT: Failed to create subnode %s: %s", name, > > > - fdt_strerror(retval)); > > > + error_report("%s: Failed to create subnode %s: %s", > > > + __func__, name, fdt_strerror(retval)); > > > exit(1); > > > } > > > @@ -550,6 +550,47 @@ int qemu_fdt_add_subnode(void *fdt, const char *= name) > > > return retval; > > > } > > > +/* > > > + * Like qemu_fdt_add_subnode(), but will add all missing > > > + * subnodes in the path. > > > + */ > > > +int qemu_fdt_add_path(void *fdt, const char *path) > > > +{ > > > + char *dupname, *basename, *p; > > > + int parent, retval =3D -1; > > > + > > > + if (path[0] !=3D '/') { > > > + return retval; > > > + } > > > + > > > + parent =3D fdt_path_offset(fdt, "/"); > > Getting the offset for "/" is never needed - it's always 0. > Thanks, will fix it. > > > + p =3D dupname =3D g_strdup(path); > > You shouldn't need the strdup(), see below. > >=20 > > > + > > > + while (p) { > > > + *p =3D '/'; > > > + basename =3D p + 1; > > > + p =3D strchr(p + 1, '/'); > > > + if (p) { > > > + *p =3D '\0'; > > > + } > > > + retval =3D fdt_path_offset(fdt, dupname); > > The fdt_path_offset_namelen() function exists *exactly* so that you > > can look up partial parths without having to mangle your input > > string. Just set the namelen right, and it will ignore anything to > > the right of that. > Function fdt_path_offset_namelen() seems more reasonable. >=20 > After we call qemu_fdt_add_path() to add "/cpus/cpu-map/socket0/core0" > successfully, > if we want to add another path like "/cpus/cpu-map/socket0/core1" we will > get the error > -FDT_ERR_NOTFOUND for each partial path. But actually > "/cpus/cpu-map/socket0" > already exists, so by using fdt_path_offset_namelen() with right namelen = we > can avoid > the error retval for this part. I don't quite follow what you're saying here. AFAICT your logic was correct - it just involved a lot of mangling the given path (adding and removing \0s) which becomes unnecessary with fdt_path_offset_namelen(). > > > + if (retval < 0 && retval !=3D -FDT_ERR_NOTFOUND) { > > > + error_report("%s: Invalid path %s: %s", > > > + __func__, path, fdt_strerror(retval)); > > If you're getting an error other than FDT_ERR_NOTFOUND here, chances > > are it's not an invalid path, but a corrupted fdt blob or something > > else. >=20 > Right, there can be variable reasons for the fail in addition to the inva= lid > path. >=20 > > > + exit(1); > > > + } else if (retval =3D=3D -FDT_ERR_NOTFOUND) { > > > + retval =3D fdt_add_subnode(fdt, parent, basename); > > > + if (retval < 0) { > > > + break; > > > + } > I found another question here. If path "/cpus/cpu-map/socket0/core0" has > already > been added, when we want to add another path "/cpus/cpu-map/socket0/core1" > and go here with retval =3D fdt_add_subnode(fdt, parent, "cpus"), then re= tval > will > be -FDT_ERR_EXISTS, but we can't just break the loop in this case. >=20 > Am I right of the explanation ? Not exactly. If you called that fdt_add_subnode() in that case you would get FDT_ERR_EXISTS. However, because the previous fdt_path_offset() has returned -FDT_ERR_NOTFOUND, you've already established that the partial path doesn't exist, so if you got an FDT_ERR_EXISTS here something has gone very strangely wrong (such as concurrent access to the flat tree, which would very likely corrupt it). Note that the repeated use of fdt_path_offset() in this function will repeatedly rescan the whole fdt from the beginning. If you're concerned about performance (which you might well not be), then a more efficient approach would be to take your input path component by component and use fdt_subnode_offset() directly. --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --8G0E95ZjzJYq2SwN Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEdfRlhq5hpmzETofcbDjKyiDZs5IFAmB82SQACgkQbDjKyiDZ s5JDGQ/7Bw68dswDolWwWE40+GPvT7OzbEAkm4mLenyi/WZblSUwG7adnvjJJcd9 DbfhR3L8z+NwfkklduAqkE8iVzMZJwfZmuB78p7aZ4JwllaZUP8CN2GkSFdY92mg luFThSxNbXOzksvDi9ou1QawrAAeRNiQmNVpNM33veoT59+3CRikeNCL7x+4HTpB CmyETwb1+FhraVhG98DMswj5pjtzt8cdqks4hwg9dKmr/I43N1c+pfcfjPe2h0on Uoe+Le8bEGG4t0a7wpD/pJD1s5tK2umKtACTHaNzzLea+uaGUTLBXJBUgQEwmkcS ojCVrVVtxr9FYdQkTVdsqPE324eYFRQuOByulpB66jHirCxGwQA9qmnozj2XjZ4h VJdDWWarbu+mTmysey3wAKg9nsOLuNWnUn6jSj6GQHdKUpX1fJwNR3xu8Kx7Wt62 SdYt/D/vlPINQeagL34ptVEAQTkirhiXf5uHoREqEFb4EcW3PzjJCoStWAj89htd lsEcdNqHD4MXCNtHYT3La+yVqKpq20+gsRl/1Zoa/BmS3KJMfRhdTsWOTEcGBY0S DsGkJLUAT+fZfHzv7c4MhUaJ6j0zm5fuTGRzLnPhELWJDL/gdAdnHRDetU9p0LaK EG7EwjIDIG+doSqf2vBkCGfSudv4HfSADGylwUv+oNt6KX6ehh8= =Y8lR -----END PGP SIGNATURE----- --8G0E95ZjzJYq2SwN--