[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250226182809.5027e483@gandalf.local.home>
Date: Wed, 26 Feb 2025 18:28:09 -0500
From: Steven Rostedt <rostedt@...dmis.org>
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, david.laight.linux@...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 15:18:48 -0800
Linus Torvalds <torvalds@...ux-foundation.org> wrote:
> On Wed, 26 Feb 2025 at 14:34, Steven Rostedt <rostedt@...dmis.org> wrote:
> >
> > Correct, but if the variable had some other protection, like a lock held
> > when this function was called, it is fine to do and the compiler may
> > optimize it or not and still have the same result.
>
> Sure.
>
> But locking isn't always there. And shouldn't always be there. Lots of
> lockless algorithms exist, and some of them are very simple indeed ("I
> set a flag, you read a flag, you get one or the other value")
Yes, for the case of:
r = READ_ONCE(global);
if (r > 1000)
goto out;
x = r;
As I've done that in my code without locks, as I just need a consistent
value not necessarily the "current" value.
I was talking for the case the code has (not the compiler creating):
if (global > 1000)
goto out;
x = global;
Because without a lock or some other protection, that's likely a bug.
My point is that the compiler is free to turn that into:
r = READ_ONCE(global);
if (r > 1000)
goto out;
x = r;
and not change the expected result.
-- Steve
Powered by blists - more mailing lists