From: Tom Rini <trini-OWPKS81ov/FWk0Htik3J/w@public.gmane.org>
To: David Gibson <david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org>
Cc: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Patrice CHOTARD <patrice.chotard-qxv4g6HH51o@public.gmane.org>,
Patrick DELAUNAY <patrick.delaunay-qxv4g6HH51o@public.gmane.org>
Subject: Re: [PATCH] libfdt: Remove special handling for unaligned reads
Date: Thu, 23 Jan 2020 07:16:50 -0500 [thread overview]
Message-ID: <20200123121650.GV26536@bill-the-cat> (raw)
In-Reply-To: <20200123091440.GQ2347-K0bRW+63XPQe6aEkudXLsA@public.gmane.org>
[-- Attachment #1: Type: text/plain, Size: 4234 bytes --]
On Thu, Jan 23, 2020 at 08:14:40PM +1100, David Gibson wrote:
> On Fri, Jan 17, 2020 at 10:31:06AM -0500, Tom Rini wrote:
> > 6dcb8ba4 "libfdt: Add helpers for accessing unaligned words" introduced
> > changes to support unaligned reads for ARM platforms and 11738cf01f15
> > "libfdt: Don't use memcpy to handle unaligned reads on ARM" improved the
> > performance of these helpers.
> >
> > Ultimately however, these helpers should not exist. Unaligned access
> > only occurs when images are forced out of alignment by the user. This
> > unalignment is not supported and introduces problems later on as other
> > parts of the system image are unaligned and they too require alignment.
> >
> > Revert both of these changes.
> >
> > Signed-off-by: Tom Rini <trini-OWPKS81ov/FWk0Htik3J/w@public.gmane.org>
> > ---
> > By way of a little more explanation, looking at the archives it seems
> > that the initial bug reporter said that they had a platform that was
> > using U-Boot and had the "fdt_high=0xffffffff" set in the environment.
> > What that does is to tell U-Boot to not do any of the sanity checks and
> > relocation to ensure alignment that it would normally do because the
> > user knows best. This later came up on the U-Boot list as once the DTB
> > was loaded, Linux is unhappy because it demands correct alignment.
> >
> > I only realized libfdt had introduced changes here when it was reported
> > that boot time had gotten much slower once we merged this change in. It
> > would be best to just drop it.
>
> Hmm. I'm not sure about this. The commit message makes a case for
> why the unaligned handling isn't necessary, but not a case for why
> it's bad. Even if handling an unaligned tree isn't a common case,
> isn't it better to be able to than not?
>
> I gather from the previous discussion that there's a significant
> performance impact, but that rationale needs to go into the commit
> message for posterity.
I wanted to emphasize that the code simply isn't ever needed, not that
it's a performance problem. A performance problem implies that we would
keep this, if it was fast enough. That's why people noticed it (it
slows things down to an unusable level). But it's functionally wrong.
> [snip]
> > diff --git a/libfdt/libfdt.h b/libfdt/libfdt.h
> > index fc4c4962a01c..d4ebe915cf46 100644
> > --- a/libfdt/libfdt.h
> > +++ b/libfdt/libfdt.h
> > @@ -117,23 +117,6 @@ static inline void *fdt_offset_ptr_w(void *fdt, int offset, int checklen)
> >
> > uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset);
> >
> > -/*
> > - * Alignment helpers:
> > - * These helpers access words from a device tree blob. They're
> > - * built to work even with unaligned pointers on platforms (ike
> > - * ARM) that don't like unaligned loads and stores
> > - */
> > -
> > -static inline uint32_t fdt32_ld(const fdt32_t *p)
> > -{
> > - const uint8_t *bp = (const uint8_t *)p;
> > -
> > - return ((uint32_t)bp[0] << 24)
> > - | ((uint32_t)bp[1] << 16)
> > - | ((uint32_t)bp[2] << 8)
> > - | bp[3];
> > -}
>
> In particular, I definitely think removing the helpers entirely is a
> no go. They're now part of the published interface of the library.
Perhaps "mistakes were made" ? I don't think we need to worry about
removing an interface here as projects are avoiding upgrading libfdt
now (TF-A, formerly ATF) or reverting the change (U-Boot).
> Even if they're not used for reading the internal tags, they can be
> used to load integers from within particular properties. Those are
> frequently unaligned, since properties generally have packed
> representations.
I don't see the relevance. Go back to the initial problem report. It's
not "I have a new unique platform I'm using libfdt on and I have
problems". It's "I keep jabbing myself with a rusty nail and now I have
problems".
> How much of the performance loss would we get back if we put an actual
> conditional on an aligned address in the helpers?
I don't know but to be very clear, we don't ever need these on ARM.
Keep in mind we've been using device trees on ARM for over 10 years at
this point.
--
Tom
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2020-01-23 12:16 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-17 15:31 [PATCH] libfdt: Remove special handling for unaligned reads Tom Rini
[not found] ` <20200117153106.29909-1-trini-OWPKS81ov/FWk0Htik3J/w@public.gmane.org>
2020-01-18 0:32 ` Simon Glass
2020-01-23 9:14 ` David Gibson
[not found] ` <20200123091440.GQ2347-K0bRW+63XPQe6aEkudXLsA@public.gmane.org>
2020-01-23 12:16 ` Tom Rini [this message]
2020-01-27 3:23 ` David Gibson
[not found] ` <20200127032351.GA1818-K0bRW+63XPQe6aEkudXLsA@public.gmane.org>
2020-01-27 15:04 ` Tom Rini
2020-01-27 19:18 ` Simon Glass
2020-01-28 8:59 ` David Gibson
[not found] ` <20200128085918.GO42099-K0bRW+63XPQe6aEkudXLsA@public.gmane.org>
2020-01-28 13:43 ` Tom Rini
2020-01-28 14:08 ` Rob Herring
[not found] ` <CAL_JsqJ0Pp8e4iFOKuKESO4DJ0ky2aO+GB_HDiGcNhY1qBxgfw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2020-01-28 14:51 ` Tom Rini
2020-01-29 1:52 ` David Gibson
2020-01-29 1:49 ` David Gibson
2020-01-29 2:15 ` Ian Lepore
[not found] ` <b5e2288c5b06419fbfd057b8895ade5c5493cde5.camel-h+KGxgPPiopAfugRpC6u6w@public.gmane.org>
2020-01-29 16:05 ` Rob Herring
[not found] ` <CAL_JsqLYobRrLtF9z3eMt=YneGuxDpvpKU7DQruza-jq4n6B3Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2020-01-29 16:08 ` Ian Lepore
2020-01-30 14:44 ` Patrice CHOTARD
[not found] ` <c56c4206-1be1-1701-1423-1f74f6913bbf-qxv4g6HH51o@public.gmane.org>
2020-01-30 20:18 ` Rob Herring
[not found] ` <CAL_Jsq+43Opib7vUpZ_VxbJig3gT8crBoL6nw_yC=xOfcsbOvA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2020-01-30 20:49 ` Tom Rini
2020-01-31 3:38 ` David Gibson
[not found] ` <20200131033810.GE15210-K0bRW+63XPQe6aEkudXLsA@public.gmane.org>
2020-01-31 4:15 ` Tom Rini
2020-01-31 8:44 ` Patrice CHOTARD
[not found] ` <7bbbb5a8-8e35-e95c-8d03-6970fd6b023e-qxv4g6HH51o@public.gmane.org>
2020-02-02 6:20 ` David Gibson
[not found] ` <20200202062031.GB30687-K0bRW+63XPQe6aEkudXLsA@public.gmane.org>
2020-02-03 13:14 ` Patrice CHOTARD
[not found] ` <1f4881a0-8d52-c280-3376-d66943d489a1-qxv4g6HH51o@public.gmane.org>
2020-02-07 5:23 ` David Gibson
2020-01-29 1:29 ` 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=20200123121650.GV26536@bill-the-cat \
--to=trini-owpks81ov/fwk0htik3j/w@public.gmane.org \
--cc=david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org \
--cc=devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=patrice.chotard-qxv4g6HH51o@public.gmane.org \
--cc=patrick.delaunay-qxv4g6HH51o@public.gmane.org \
/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).