devicetree-compiler.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Cc: Yves-Alexis Perez <corsac@debian.org>,
	devicetree-compiler@vger.kernel.org, entwicklung@pengutronix.de
Subject: Re: [PATCH v3] libfdt: overlay: ensure that existing phandles are not overwritten
Date: Thu, 14 Mar 2024 15:43:13 +1100	[thread overview]
Message-ID: <ZfKAYQ7sNYLpJOps@zatzit> (raw)
In-Reply-To: <mpmdkpzzfpw6vrgvpd3e324zouwd4u3oxq7rpmc2sktxjtojj7@gauowuw3mug5>

[-- Attachment #1: Type: text/plain, Size: 3575 bytes --]

On Sun, Mar 10, 2024 at 09:30:31AM +0100, Uwe Kleine-König wrote:
> Hello David,
> 
> On Mon, Feb 26, 2024 at 04:53:53PM +1100, David Gibson wrote:
> > On Sun, Feb 25, 2024 at 06:54:23PM +0100, Uwe Kleine-König wrote:
> > > A phandle in an overlay is not supposed to overwrite a phandle that
> > > already exists in the base dtb as this breaks references to the
> > > respective node in the base.
> > > 
> > > So add another iteration over the fdto that checks for such overwrites
> > > and fixes the fdto phandle's value to match the fdt's.
> > > 
> > > A test is added that checks that newly added phandles and existing
> > > phandles work as expected.
> > > 
> > > Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> > > ---
> > > Hello,
> > > 
> > > here comes the next iteration of the patch that fixes overlay
> > > application to not overwrite existing phandles.
> > > 
> > > It is rebased to current main branch. The changes since v2 are:
> > > 
> > >  - Add documentation
> > >  - Apply the simplification from 24f60011fd43 ("libfdt: Simplify
> > >    adjustment of values for local fixups") in the functions added here.
> > >  - Rename functions using shorter and better names
> > >  - Changed the test device trees to yield a hole in the phandle space
> > >  - Checked each phandle value not being overwritten separately
> > > 
> > > Note I didn't switch the order of overlay_prevent_phandle_overwrite() and
> > > overlay_fixup_phandles() because the overlay's phandles must be resolved
> > > before I can do the recursion needed in
> > > overlay_prevent_phandle_overwrite().
> > 
> > I'm not following what you mean here.  IIUC, conflicts of the sort
> > you're handling can only arise when the overlay describes a phandle
> > for the target node of the reference - and therefore that target is in
> > the overlay.  In that case all references to it in the overlay should
> > be encoded in __local_fixups__ rather than __fixups__.  __fixups__, in
> > contrast describes references to nodes that aren't in the overlay, and
> > so can't be filled in - even with a tentative value - until the
> > overlay is applied.
> > 
> > So, I'm not seeing how fixing these conflicts depends on resolution of
> > those "external" fixups, rather than just the "local" fixups.  Am I
> > missing something?
> 
> yupp, look at the overlay dts I added in tests/. It has
> 
> 	&node_a {
> 		value = <32>;
> 	};
> 
> which is translated to:
> 
> 	fragment@1 {
> 	    target = <0xffffffff>;
> 	    __overlay__ {
> 	        value = <0x00000020>;
> 	    };
> 	};
> 	...
> 	__fixups__ {
> 	    node_a = ..., "/fragment@1:target:0"
> 	};
> 
> Before I can recurse over fragment@1 and the matching base dtb node to
> check for phandle conflicts, I need /fragment@1:target resolved;
> otherwise I don't know where to look in the base dtb.
> 
> So if I switch the order, fdtoverlay reports
> 
> 	Failed to apply 'overlay_overlay_phandle.test.dtb': FDT_ERR_BADPHANDLE
> 
> in make check.

Ah, right.  It's specifically that we need to resolve the fragment
targets (including via external symbols) before we can resolve this.
Do you have a test case for this specific problem?  If not, I'd be
worried, that I or someone else might forget the subtletey and try to
re-order at some point in the future.

-- 
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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2024-03-14  5:07 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-25 17:54 [PATCH v3] libfdt: overlay: ensure that existing phandles are not overwritten Uwe Kleine-König
2024-02-26  5:53 ` David Gibson
2024-03-10  8:30   ` Uwe Kleine-König
2024-03-14  4:43     ` David Gibson [this message]
2024-03-14  9:06       ` Uwe Kleine-König
2024-03-14 10:40 ` David Gibson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZfKAYQ7sNYLpJOps@zatzit \
    --to=david@gibson.dropbear.id.au \
    --cc=corsac@debian.org \
    --cc=devicetree-compiler@vger.kernel.org \
    --cc=entwicklung@pengutronix.de \
    --cc=u.kleine-koenig@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).