Re: C aggregate passing (Rust kernel policy)

Kent Overstreet
2025-02-27T19:55:19Z

On Thu, Feb 27, 2025 at 11:15:54AM -0800, Linus Torvalds wrote:
> On Thu, 27 Feb 2025 at 10:33, Ralf Jung <post@ralfj.de> wrote:
> >
> > The way you do global flags in Rust is like this:
>
> Note that I was really talking mainly about the unsafe cases, an din
> particular when interfacing with C code.

For simple bitflags (i.e. code where we use test_bit()/set_bit() we'd
probably just export it as a standard Rust atomic, no new unsafe {}
required.

>
> Also, honestly:
>
> > FLAG.store(true, Ordering::SeqCst); // or release/acquire/relaxed
>
> I suspect in reality it would be hidden as accessor functions, or
> people just continue to write things in C.
>
> Yes, I know all about the C++ memory ordering. It's not only a
> standards mess, it's all very illegible code too.

It's more explicit, and that's probably not a bad thing - compare it to
our smp_mb__after_atomic(), it's not uncommon to find code where the
barriers are missing because the person who wrote the code was assuming
x86.