News for hackers. Stuff that matters.
Re:Committing to Rust in the Kernel by j16sdiz on Tuesday September 24, 2024 @09:55PM (#41642912)
For most driver or subsystem, maybe you don't need to know how mm works.

Rust is different. The kernel Rust teams are trying to encode some safety invariant. If any of those mismatch with the C side, it breaks. Those invariant need some non trivial knowledge of rust to understand

Re:Committing to Rust in the Kernel by nine_k on Tuesday September 24, 2024 @10:01PM (#41642957)
Is there an example of what you're describing?
Re:Committing to Rust in the Kernel by steveklabnik on Tuesday September 24, 2024 @10:07PM (#41642982)
There’s a recent drama where the Rust folks asked some people to clarify some of the semantics of some of the filesystem APIs, and this request wasn’t taken well. There’s been a bunch of hn threads about it.
Re:Committing to Rust in the Kernel by asne11 on Tuesday September 24, 2024 @10:23PM (#41643075)
like which?
Re:Committing to Rust in the Kernel by xgstation on Tuesday September 24, 2024 @10:52PM (#41643257)
not sure if this is what the op referred but like this one https://news.ycombinator.com/item?id=41450347

didn't find threads that regarding "clarify APIs semantics", but kernel docs are indeed not in a very good condition. Since C does not provide same level of soundness that Rust does, there are many hidden traps.

asahi developer had a good discuss about this https://threadreaderapp.com/thread/1829852697107055047.html

Re:Committing to Rust in the Kernel by steveklabnik on Tuesday September 24, 2024 @11:09PM (#41643331)
This overall situation is, yes. And the stuff from Lina is related, thanks for also pointing that out.
Re:Committing to Rust in the Kernel by steveklabnik on Tuesday September 24, 2024 @10:38PM (#41643174)
I apologize, I am on my phone, so rather than curating links, check out https://hn.algolia.com/?dateRange=all&page=0&prefix=false&qu..., most of which are about this situation.
Re:Committing to Rust in the Kernel by pornel on Wednesday September 25, 2024 @04:20PM (#41651440)
About invariants generally: Rust wants to know when memory behind each pointer is immutable, or mutable by Rust only, or could be mutated by something else while Rust has a pointer to it. Rust also encodes which types can't be moved to another thread, and which pointers own their memory and need to be freed by Rust.

These are part of the type system, so they need to be defined precisely. The answer to these questions can't be just "it depends". If there are run-time or config-dependent conditions when the same data is owned or not or immutable or not, Rust has enums, unions and unsafe escape hatches to guard access to it.

[dead]
Re:Committing to Rust in the Kernel by vlovich123 on Wednesday September 25, 2024 @12:33AM (#41643717)
By definition the undefined memory behavior is only in the undefined parts of the spec modulo bugs. The spec is written against an abstract virtual machine and C was one of the first to pioneer such a concept and why it was so successful at getting ported everywhere.
[dead]
Re:Committing to Rust in the Kernel by steveklabnik on Wednesday September 25, 2024 @01:15PM (#41649607)
> I was under the impression most of how c interacts with memory is part of the undefined part of the spec

For a long time, the memory model, formally speaking, was underspecified. Both C and C++ agreed on and added a memory model in C11 and C++11.

> fencing

You can add a fence via this API: https://en.cppreference.com/w/c/atomic/atomic_thread_fence

> This varies per arch

Right, so what assembly this API will emit depends on the underlying architecture details.

Notably, the Linux kernel does not use the standard C memory model, it uses its own.

Re:Committing to Rust in the Kernel by vlovich123 on Thursday September 26, 2024 @08:09AM (#41657400)
To be clear, that’s the definition of the memory model under concurrent execution. I’m pretty sure the single threaded version was well defined
Re:Committing to Rust in the Kernel by steveklabnik on Thursday September 26, 2024 @11:21AM (#41659421)
My understanding is that “memory model” is definitionaly about what happens when you add parallelism and/or concurrency.

Regardless, this isn’t a slight against C. Most languages don’t have an explicit memory model at all.

Re:Committing to Rust in the Kernel by vlovich123 on Thursday September 26, 2024 @11:59AM (#41659980)
I introduced the word memory model so that’s on me for that error - definitionally memory model does refer to concurrency.

However Op used “memory behavior”. The C standard definitely has defined and defined and undefined memory behaviors even pre C11. For example, dereferencing null is an undefined single threaded memory behavior that bit the kernel when the compilers started optimizing from assumptions about never reaching UB code. But for example there’s lots of defined behaviors like what happens when you dereference an aliased pointer.

And the Linux kernel definitely defined a memory model for itself before C and made all architectures conform to that.

Re:Committing to Rust in the Kernel by steveklabnik on Thursday September 26, 2024 @03:19PM (#41662135)
Yeah that's fair. As I said, I'm not trying to imply something was bad here before C11. I thought "underspecified" instead of "unspecified" would communicate "some of it was defined but some of it wasn't but it's been fully so for a while now" but maybe that missed the mark.