[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <f562193c-c4fe-334e-8d70-9fe949c9da2f@linux-m68k.org>
Date: Fri, 17 Oct 2025 09:14:09 +1100 (AEDT)
From: Finn Thain <fthain@...ux-m68k.org>
To: Arnd Bergmann <arnd@...db.de>
cc: Peter Zijlstra <peterz@...radead.org>, Will Deacon <will@...nel.org>,
Andrew Morton <akpm@...ux-foundation.org>,
Boqun Feng <boqun.feng@...il.com>, Jonathan Corbet <corbet@....net>,
Mark Rutland <mark.rutland@....com>, linux-kernel@...r.kernel.org,
Linux-Arch <linux-arch@...r.kernel.org>,
Geert Uytterhoeven <geert@...ux-m68k.org>, linux-m68k@...r.kernel.org,
linux-doc@...r.kernel.org
Subject: Re: [RFC v3 1/5] documentation: Discourage alignment assumptions
On Thu, 16 Oct 2025, Arnd Bergmann wrote:
> On Wed, Oct 8, 2025, at 00:19, Finn Thain wrote:
> > Discourage assumptions that simply don't hold for all Linux ABIs.
> > Exceptions to the natural alignment rule for scalar types include
> > long long on i386 and sh.
> > ---
>
> I think both of the paragraphs you remove are still correct and I
> would not remove them:
>
Yes -- correct in some obscure sense, but misleading at face value.
Hence this patch.
> > Documentation/core-api/unaligned-memory-access.rst | 7 -------
> > 1 file changed, 7 deletions(-)
> >
> > diff --git a/Documentation/core-api/unaligned-memory-access.rst
> > b/Documentation/core-api/unaligned-memory-access.rst
> > index 5ceeb80eb539..1390ce2b7291 100644
> > --- a/Documentation/core-api/unaligned-memory-access.rst
> > +++ b/Documentation/core-api/unaligned-memory-access.rst
> >
> > -When writing code, assume the target architecture has natural alignment
> > -requirements.
> > -
>
> It is clearly important to not intentionally misalign variables
> because that breaks on hardware that requires aligned data.
>
> Assuming natural alignment is the safe choice here, but you
> could change 'architecture' to 'hardware' here if you
> think that is otherwise ambiguous.
>
Do you know of any hardware that has "natural alignment requirements" in
the completely unqualified sense in which that the claim is made? i.e.
considering all of its native vector and scalar types.
That's a rhetorical question. I'm not trying to provide an exhaustive and
up-to-date list of platform quirks. With this patch, I'm merely trying to
discourage faulty assumptions.
> > -Similarly, you can also rely on the compiler to align variables and function
> > -parameters to a naturally aligned scheme, based on the size of the type of
> > -the variable.
>
> This also seems to refer to something else: even on m68k and i386,
> scalar stack and .data variables have natural alignment even though the
> ABI does not require that.
>
Then it is doubly misleading.
There is value in explaining what the compiler can and cannot be relied
upon to deliver, but I think the myfunc() example already serves that
purpose. Don't you agree?
> It's probably a good idea to list the specific exceptions to
> the struct layout rules in the previous paragraph, e.g.
>
> [
> Fortunately, the compiler understands the alignment constraints, so in the
> above case it would insert 2 bytes of padding in between field1 and field2.
> Therefore, for standard structure types you can always rely on the compiler
> -to pad structures so that accesses to fields are suitably aligned (assuming
> -you do not cast the field to a type of different length).
> +to pad structures so that accesses to fields are suitably aligned for
> +the CPU hardware.
> +On all 64-bit architectures,
The poor reader: "I wonder what '64-bit architecture' means in this
context..."
> this means that all scalar struct members
> +are naturally aligned. However, some 32-bit ABIs including i386
> +only align 64-bit members on 32-bit offsets, and m68k uses at most
> +16-bit alignment. ]
"... oh, okay, so anything that naturally aligns a 64-bit word is a
"64-bit architecture". I get it. Oh, hang-on, that doesn't make sense...
Why would any 32-bit architecture be expected to naturally align 64-bit
members? What is he talking about? CONFIG_64BIT maybe??"
Moreover, you have digressed into a discussion of the ABI. The aim of this
document is to avoid the performance penalty for unaligned accesses.
Whereas, ABI traits would seem to be relevant to a discussion about memory
efficiency, like I said to David.
Powered by blists - more mailing lists