* [PATCH] libfdt: Add FDT alignment check to fdt_check_header()
@ 2021-04-06 19:07 Rob Herring
[not found] ` <20210406190712.2118098-1-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
0 siblings, 1 reply; 8+ messages in thread
From: Rob Herring @ 2021-04-06 19:07 UTC (permalink / raw)
To: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA; +Cc: Tom Rini, Frank Rowand
Only checking the FDT alignment in fdt_ro_probe_() means that
fdt_check_header() can pass, but then subsequent API calls fail on
alignment checks. Let's add an alignment check to fdt_check_header() so
alignment errors are found up front.
Cc: Tom Rini <trini-OWPKS81ov/FWk0Htik3J/w@public.gmane.org>
Cc: Frank Rowand <frowand.list-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Signed-off-by: Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
---
For background, the new alignment check triggered a crash in the
linux kernel. Yes, we should fix the error handling, but
fdt_check_header() shouldn't tell us the FDT is valid only to fail
later on.
Maybe we should move the check instead, but fdt_ro_probe_() and
fdt_check_header() already have a lot of the same checks.
libfdt/fdt.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/libfdt/fdt.c b/libfdt/fdt.c
index 3e893073da05..9fe7cf4b747d 100644
--- a/libfdt/fdt.c
+++ b/libfdt/fdt.c
@@ -90,6 +90,10 @@ int fdt_check_header(const void *fdt)
{
size_t hdrsize;
+ /* The device tree must be at an 8-byte aligned address */
+ if ((uintptr_t)fdt & 7)
+ return -FDT_ERR_ALIGNMENT;
+
if (fdt_magic(fdt) != FDT_MAGIC)
return -FDT_ERR_BADMAGIC;
if (!can_assume(LATEST)) {
--
2.27.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] libfdt: Add FDT alignment check to fdt_check_header()
[not found] ` <20210406190712.2118098-1-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
@ 2021-04-07 2:45 ` David Gibson
2021-04-07 15:35 ` Simon Glass
1 sibling, 0 replies; 8+ messages in thread
From: David Gibson @ 2021-04-07 2:45 UTC (permalink / raw)
To: Rob Herring
Cc: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA, Tom Rini, Frank Rowand
[-- Attachment #1: Type: text/plain, Size: 1644 bytes --]
On Tue, Apr 06, 2021 at 02:07:12PM -0500, Rob Herring wrote:
> Only checking the FDT alignment in fdt_ro_probe_() means that
> fdt_check_header() can pass, but then subsequent API calls fail on
> alignment checks. Let's add an alignment check to fdt_check_header() so
> alignment errors are found up front.
>
> Cc: Tom Rini <trini-OWPKS81ov/FWk0Htik3J/w@public.gmane.org>
> Cc: Frank Rowand <frowand.list-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> Signed-off-by: Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Good catch.
Applied, thanks.
> ---
> For background, the new alignment check triggered a crash in the
> linux kernel. Yes, we should fix the error handling, but
> fdt_check_header() shouldn't tell us the FDT is valid only to fail
> later on.
>
> Maybe we should move the check instead, but fdt_ro_probe_() and
> fdt_check_header() already have a lot of the same checks.
>
> libfdt/fdt.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/libfdt/fdt.c b/libfdt/fdt.c
> index 3e893073da05..9fe7cf4b747d 100644
> --- a/libfdt/fdt.c
> +++ b/libfdt/fdt.c
> @@ -90,6 +90,10 @@ int fdt_check_header(const void *fdt)
> {
> size_t hdrsize;
>
> + /* The device tree must be at an 8-byte aligned address */
> + if ((uintptr_t)fdt & 7)
> + return -FDT_ERR_ALIGNMENT;
> +
> if (fdt_magic(fdt) != FDT_MAGIC)
> return -FDT_ERR_BADMAGIC;
> if (!can_assume(LATEST)) {
--
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 --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] libfdt: Add FDT alignment check to fdt_check_header()
[not found] ` <20210406190712.2118098-1-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2021-04-07 2:45 ` David Gibson
@ 2021-04-07 15:35 ` Simon Glass
[not found] ` <CAPnjgZ3fmzymABa4orPYxVQG4SaprSXZa+4AT9=yBYm8B6Md_Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
1 sibling, 1 reply; 8+ messages in thread
From: Simon Glass @ 2021-04-07 15:35 UTC (permalink / raw)
To: Rob Herring; +Cc: Devicetree Compiler, Tom Rini, Frank Rowand
Hi Rob,
On Wed, 7 Apr 2021 at 07:07, Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> wrote:
>
> Only checking the FDT alignment in fdt_ro_probe_() means that
> fdt_check_header() can pass, but then subsequent API calls fail on
> alignment checks. Let's add an alignment check to fdt_check_header() so
> alignment errors are found up front.
>
> Cc: Tom Rini <trini-OWPKS81ov/FWk0Htik3J/w@public.gmane.org>
> Cc: Frank Rowand <frowand.list-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> Signed-off-by: Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
> ---
> For background, the new alignment check triggered a crash in the
> linux kernel. Yes, we should fix the error handling, but
> fdt_check_header() shouldn't tell us the FDT is valid only to fail
> later on.
>
> Maybe we should move the check instead, but fdt_ro_probe_() and
> fdt_check_header() already have a lot of the same checks.
>
> libfdt/fdt.c | 4 ++++
> 1 file changed, 4 insertions(+)
At present U-Boot uses a 4-byte alignment, so far as I know, so this
will break things.
Is this because of the need to align the memory-reservation block?
>
> diff --git a/libfdt/fdt.c b/libfdt/fdt.c
> index 3e893073da05..9fe7cf4b747d 100644
> --- a/libfdt/fdt.c
> +++ b/libfdt/fdt.c
> @@ -90,6 +90,10 @@ int fdt_check_header(const void *fdt)
> {
> size_t hdrsize;
>
> + /* The device tree must be at an 8-byte aligned address */
> + if ((uintptr_t)fdt & 7)
> + return -FDT_ERR_ALIGNMENT;
> +
> if (fdt_magic(fdt) != FDT_MAGIC)
> return -FDT_ERR_BADMAGIC;
> if (!can_assume(LATEST)) {
> --
> 2.27.0
>
Regards,
Simon
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] libfdt: Add FDT alignment check to fdt_check_header()
[not found] ` <CAPnjgZ3fmzymABa4orPYxVQG4SaprSXZa+4AT9=yBYm8B6Md_Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2021-04-07 17:25 ` Rob Herring
[not found] ` <CAL_JsqK+h8v2PY9W2jzoAihFwb+7T0oqkoSKrtOSf1mgYfU1mA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2021-04-07 18:09 ` Tom Rini
1 sibling, 1 reply; 8+ messages in thread
From: Rob Herring @ 2021-04-07 17:25 UTC (permalink / raw)
To: Simon Glass; +Cc: Devicetree Compiler, Tom Rini, Frank Rowand
On Wed, Apr 7, 2021 at 10:35 AM Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org> wrote:
>
> Hi Rob,
>
> On Wed, 7 Apr 2021 at 07:07, Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> wrote:
> >
> > Only checking the FDT alignment in fdt_ro_probe_() means that
> > fdt_check_header() can pass, but then subsequent API calls fail on
> > alignment checks. Let's add an alignment check to fdt_check_header() so
> > alignment errors are found up front.
> >
> > Cc: Tom Rini <trini-OWPKS81ov/FWk0Htik3J/w@public.gmane.org>
> > Cc: Frank Rowand <frowand.list-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> > Signed-off-by: Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
> > ---
> > For background, the new alignment check triggered a crash in the
> > linux kernel. Yes, we should fix the error handling, but
> > fdt_check_header() shouldn't tell us the FDT is valid only to fail
> > later on.
> >
> > Maybe we should move the check instead, but fdt_ro_probe_() and
> > fdt_check_header() already have a lot of the same checks.
> >
> > libfdt/fdt.c | 4 ++++
> > 1 file changed, 4 insertions(+)
>
> At present U-Boot uses a 4-byte alignment, so far as I know, so this
> will break things.
It was the u-boot folks that wanted this in the first place... Look at
the recent commits from Tom and the discussion on the list about them.
> Is this because of the need to align the memory-reservation block?
But yes, the spec does require some sections to be 8-byte aligned
which implies the whole thing has to be.
Rob
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] libfdt: Add FDT alignment check to fdt_check_header()
[not found] ` <CAPnjgZ3fmzymABa4orPYxVQG4SaprSXZa+4AT9=yBYm8B6Md_Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2021-04-07 17:25 ` Rob Herring
@ 2021-04-07 18:09 ` Tom Rini
2021-04-07 18:36 ` Simon Glass
1 sibling, 1 reply; 8+ messages in thread
From: Tom Rini @ 2021-04-07 18:09 UTC (permalink / raw)
To: Simon Glass; +Cc: Rob Herring, Devicetree Compiler, Frank Rowand
On Thu, Apr 08, 2021 at 03:35:35AM +1200, Simon Glass wrote:
> Hi Rob,
>
> On Wed, 7 Apr 2021 at 07:07, Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> wrote:
> >
> > Only checking the FDT alignment in fdt_ro_probe_() means that
> > fdt_check_header() can pass, but then subsequent API calls fail on
> > alignment checks. Let's add an alignment check to fdt_check_header() so
> > alignment errors are found up front.
> >
> > Cc: Tom Rini <trini-OWPKS81ov/FWk0Htik3J/w@public.gmane.org>
> > Cc: Frank Rowand <frowand.list-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> > Signed-off-by: Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
> > ---
> > For background, the new alignment check triggered a crash in the
> > linux kernel. Yes, we should fix the error handling, but
> > fdt_check_header() shouldn't tell us the FDT is valid only to fail
> > later on.
> >
> > Maybe we should move the check instead, but fdt_ro_probe_() and
> > fdt_check_header() already have a lot of the same checks.
> >
> > libfdt/fdt.c | 4 ++++
> > 1 file changed, 4 insertions(+)
>
> At present U-Boot uses a 4-byte alignment, so far as I know, so this
> will break things.
It's 8 byte, not 4 byte and I have nothing good to say about places that
get by with 4-and-not-8 alignment.
--
Tom
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] libfdt: Add FDT alignment check to fdt_check_header()
[not found] ` <CAL_JsqK+h8v2PY9W2jzoAihFwb+7T0oqkoSKrtOSf1mgYfU1mA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2021-04-07 18:35 ` Simon Glass
0 siblings, 0 replies; 8+ messages in thread
From: Simon Glass @ 2021-04-07 18:35 UTC (permalink / raw)
To: Rob Herring; +Cc: Devicetree Compiler, Tom Rini, Frank Rowand
Hi Rob,
On Thu, 8 Apr 2021 at 05:26, Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> wrote:
>
> On Wed, Apr 7, 2021 at 10:35 AM Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org> wrote:
> >
> > Hi Rob,
> >
> > On Wed, 7 Apr 2021 at 07:07, Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> wrote:
> > >
> > > Only checking the FDT alignment in fdt_ro_probe_() means that
> > > fdt_check_header() can pass, but then subsequent API calls fail on
> > > alignment checks. Let's add an alignment check to fdt_check_header() so
> > > alignment errors are found up front.
> > >
> > > Cc: Tom Rini <trini-OWPKS81ov/FWk0Htik3J/w@public.gmane.org>
> > > Cc: Frank Rowand <frowand.list-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> > > Signed-off-by: Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
> > > ---
> > > For background, the new alignment check triggered a crash in the
> > > linux kernel. Yes, we should fix the error handling, but
> > > fdt_check_header() shouldn't tell us the FDT is valid only to fail
> > > later on.
> > >
> > > Maybe we should move the check instead, but fdt_ro_probe_() and
> > > fdt_check_header() already have a lot of the same checks.
> > >
> > > libfdt/fdt.c | 4 ++++
> > > 1 file changed, 4 insertions(+)
> >
> > At present U-Boot uses a 4-byte alignment, so far as I know, so this
> > will break things.
>
> It was the u-boot folks that wanted this in the first place... Look at
> the recent commits from Tom and the discussion on the list about them.
OK I guess I just missed that. I recall the push-back against
supporting unaligned access but not the 8-byte stuff.
>
> > Is this because of the need to align the memory-reservation block?
>
> But yes, the spec does require some sections to be 8-byte aligned
> which implies the whole thing has to be.
I was looking at that but from what I could tell it is not stated
anywhere. In fact it is, but I missed it.
I sent:
https://github.com/devicetree-org/devicetree-specification/pull/43
Regards,
Simon
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] libfdt: Add FDT alignment check to fdt_check_header()
2021-04-07 18:09 ` Tom Rini
@ 2021-04-07 18:36 ` Simon Glass
[not found] ` <CAPnjgZ2rGyCVQwQ3aP+=wF99R+2C_POV1Y=18jd8eAd+sOqSZQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
0 siblings, 1 reply; 8+ messages in thread
From: Simon Glass @ 2021-04-07 18:36 UTC (permalink / raw)
To: Tom Rini; +Cc: Rob Herring, Devicetree Compiler, Frank Rowand
Hi Tom & Rob,
On Thu, 8 Apr 2021 at 06:09, Tom Rini <trini-OWPKS81ov/FWk0Htik3J/w@public.gmane.org> wrote:
>
> On Thu, Apr 08, 2021 at 03:35:35AM +1200, Simon Glass wrote:
> > Hi Rob,
> >
> > On Wed, 7 Apr 2021 at 07:07, Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> wrote:
> > >
> > > Only checking the FDT alignment in fdt_ro_probe_() means that
> > > fdt_check_header() can pass, but then subsequent API calls fail on
> > > alignment checks. Let's add an alignment check to fdt_check_header() so
> > > alignment errors are found up front.
> > >
> > > Cc: Tom Rini <trini-OWPKS81ov/FWk0Htik3J/w@public.gmane.org>
> > > Cc: Frank Rowand <frowand.list-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> > > Signed-off-by: Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
> > > ---
> > > For background, the new alignment check triggered a crash in the
> > > linux kernel. Yes, we should fix the error handling, but
> > > fdt_check_header() shouldn't tell us the FDT is valid only to fail
> > > later on.
> > >
> > > Maybe we should move the check instead, but fdt_ro_probe_() and
> > > fdt_check_header() already have a lot of the same checks.
> > >
> > > libfdt/fdt.c | 4 ++++
> > > 1 file changed, 4 insertions(+)
> >
> > At present U-Boot uses a 4-byte alignment, so far as I know, so this
> > will break things.
>
> It's 8 byte, not 4 byte and I have nothing good to say about places that
> get by with 4-and-not-8 alignment.
I am thinking of this in arch/arm/cpu/u-boot.lds :
. = ALIGN(4);
.image_copy_end : {
At least for now, we use 4-byte alignment on 32-bit ARM, for example.
Regards,
Simon
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] libfdt: Add FDT alignment check to fdt_check_header()
[not found] ` <CAPnjgZ2rGyCVQwQ3aP+=wF99R+2C_POV1Y=18jd8eAd+sOqSZQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2021-04-07 18:39 ` Tom Rini
0 siblings, 0 replies; 8+ messages in thread
From: Tom Rini @ 2021-04-07 18:39 UTC (permalink / raw)
To: Simon Glass; +Cc: Rob Herring, Devicetree Compiler, Frank Rowand
On Thu, Apr 08, 2021 at 06:36:53AM +1200, Simon Glass wrote:
> Hi Tom & Rob,
>
> On Thu, 8 Apr 2021 at 06:09, Tom Rini <trini-OWPKS81ov/FWk0Htik3J/w@public.gmane.org> wrote:
> >
> > On Thu, Apr 08, 2021 at 03:35:35AM +1200, Simon Glass wrote:
> > > Hi Rob,
> > >
> > > On Wed, 7 Apr 2021 at 07:07, Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> wrote:
> > > >
> > > > Only checking the FDT alignment in fdt_ro_probe_() means that
> > > > fdt_check_header() can pass, but then subsequent API calls fail on
> > > > alignment checks. Let's add an alignment check to fdt_check_header() so
> > > > alignment errors are found up front.
> > > >
> > > > Cc: Tom Rini <trini-OWPKS81ov/FWk0Htik3J/w@public.gmane.org>
> > > > Cc: Frank Rowand <frowand.list-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> > > > Signed-off-by: Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
> > > > ---
> > > > For background, the new alignment check triggered a crash in the
> > > > linux kernel. Yes, we should fix the error handling, but
> > > > fdt_check_header() shouldn't tell us the FDT is valid only to fail
> > > > later on.
> > > >
> > > > Maybe we should move the check instead, but fdt_ro_probe_() and
> > > > fdt_check_header() already have a lot of the same checks.
> > > >
> > > > libfdt/fdt.c | 4 ++++
> > > > 1 file changed, 4 insertions(+)
> > >
> > > At present U-Boot uses a 4-byte alignment, so far as I know, so this
> > > will break things.
> >
> > It's 8 byte, not 4 byte and I have nothing good to say about places that
> > get by with 4-and-not-8 alignment.
>
> I am thinking of this in arch/arm/cpu/u-boot.lds :
>
> . = ALIGN(4);
>
> .image_copy_end : {
>
> At least for now, we use 4-byte alignment on 32-bit ARM, for example.
Lets move that over to the U-Boot list and see what needs whacking where
then, keeping in mind that it's where we use the DTB once it's in memory
that needs 8 byte alignment, not where it might be placed in a blob for
storage.
--
Tom
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2021-04-07 18:39 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-06 19:07 [PATCH] libfdt: Add FDT alignment check to fdt_check_header() Rob Herring
[not found] ` <20210406190712.2118098-1-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2021-04-07 2:45 ` David Gibson
2021-04-07 15:35 ` Simon Glass
[not found] ` <CAPnjgZ3fmzymABa4orPYxVQG4SaprSXZa+4AT9=yBYm8B6Md_Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2021-04-07 17:25 ` Rob Herring
[not found] ` <CAL_JsqK+h8v2PY9W2jzoAihFwb+7T0oqkoSKrtOSf1mgYfU1mA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2021-04-07 18:35 ` Simon Glass
2021-04-07 18:09 ` Tom Rini
2021-04-07 18:36 ` Simon Glass
[not found] ` <CAPnjgZ2rGyCVQwQ3aP+=wF99R+2C_POV1Y=18jd8eAd+sOqSZQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2021-04-07 18:39 ` Tom Rini
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.