[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250226225412.35133185@pumpkin>
Date: Wed, 26 Feb 2025 22:54:12 +0000
From: David Laight <david.laight.linux@...il.com>
To: Linus Torvalds <torvalds@...ux-foundation.org>
Cc: Martin Uecker <uecker@...raz.at>, Ralf Jung <post@...fj.de>, "Paul E.
McKenney" <paulmck@...nel.org>, Alice Ryhl <aliceryhl@...gle.com>, Ventura
Jack <venturajack85@...il.com>, Kent Overstreet
<kent.overstreet@...ux.dev>, Gary Guo <gary@...yguo.net>,
airlied@...il.com, boqun.feng@...il.com, ej@...i.de,
gregkh@...uxfoundation.org, hch@...radead.org, hpa@...or.com,
ksummit@...ts.linux.dev, linux-kernel@...r.kernel.org,
miguel.ojeda.sandonis@...il.com, rust-for-linux@...r.kernel.org
Subject: Re: C aggregate passing (Rust kernel policy)
On Wed, 26 Feb 2025 13:21:41 -0800
Linus Torvalds <torvalds@...ux-foundation.org> wrote:
> On Wed, 26 Feb 2025 at 13:14, Linus Torvalds
> <torvalds@...ux-foundation.org> wrote:
> >
> > That "single read done as multiple reads" is sadly still accepted by
> > the C standard, as far as I can tell. Because the standard still
> > considers it "unobservable" unless I've missed some update.
>
> I want to clarify that I'm talking about perfectly normal and entirely
> unannotated variable accesses.
>
> Don't say "programmers should annotate their special accesses with
> volatile if they want to avoid compiler-introduced TOCTOU issues".
>
> Having humans have to work around failures in the language is not the way to go.
>
> Particularly when there isn't even any advantage to it. I'm pretty
> sure neither clang nor gcc actually rematerialize reads from memory,
I thought some of the very early READ_ONCE() were added because there
was an actual problem with the generated code.
But it has got entirely silly.
In many cases gcc will generate an extra register-register transfer
for a volatile read - I've seen it do a byte read, register move and
then and with 0xff.
I think adding a separate memory barrier would stop the read being
rematerialized - but you also need to stop it doing (for example)
two byte accesses for a 16bit variable - arm32 has a limited offset
for 16bit memory accesses, so the compiler might be tempted to do
two byte writes.
David
Powered by blists - more mailing lists