|
|
Log in / Subscribe / Register

The Tower

The Tower

Posted Aug 14, 2024 18:00 UTC (Wed) by tialaramex (subscriber, #21167)
Parent article: Standards for use of unsafe Rust in the kernel

This idea of "acting outside of Rust's constraints" reminds me of Aria's "Tower of Weakenings" concept.

Aria talks about a tower - at the top of the tower are happy ordinary programmers, with a nice clean model of the world and everything works how they expected. This model is of course a lie, but it's a convenient lie and for huge numbers of software engineers it's more than adequate. In this model we never do anything "weird" like hide flag bits in a pointer, or mutate the same value from multiple threads without synchronisation, in Rust's safe subset we are prevented from doing such things by mistake by fiat.

One layer further down we've got an abstraction that's much more complicated and difficult to work with, this is where things like the Linux Kernel Memory Model and the C++ 11 Memory Model (roughly Rust's model) and such live. Aria's "Strict provenance" experiment lives in this layer, pointers have multiple components, including a "provenance" that is distinct from their physical representation on most real hardware. The compiler can't check we're obeying this model, however specialist tools can help verify our work is sound, as can review by other skilled programmers. Almost everyone who couldn't get what they needed in the simpler model above is satisfied here.

But that layer was a lie too, because beneath it there's the concrete reality of your hardware. For example "Out of Thin Air" values exist in that middle layer but not at the bottom. In the model unsynchronised arithmetic _could_ mean you get answers which depend on themselves, it's perhaps impossible to develop models that don't have this problem. But, it's also impossible to build concrete hardware with the behaviour that was so hard to eliminate in models. Down here, Aria's "Provenance" means nothing, there are no pointers, just addresses (on most hardware), and the addresses really are just bits. But also down here things like "variables" don't exist, there's no type system and Edsger Dijkstra's letter hasn't been received so they don't really have structured control flow. A total nightmare.

Clearly it's correct to strive for as many kernel programmers as possible to spend their time in the upper part of the tower, even in C this is less stressful.


to post comments

The Tower

Posted Aug 14, 2024 21:27 UTC (Wed) by ralfj (subscriber, #172874) [Link]

> But that layer was a lie too, because beneath it there's the concrete reality of your hardware.

I'm afraid you are overstretching the "layer" analogy here. Yes, this can be described as a layer, too, *but it is a very different kind of layer from what Aria describes*.

All of Aria's layers are sound abstractions you can use in Rust. If you program using only safe high-level concepts, Rust promises that the resulting program will correctly follow the things you wrote. If you program using the weak memory model and strict provenance, Rust still promises that. But programming with the hardware model *is not possible directly in Rust* (or other, similar languages such as C and C++). Between you and the hardware, there is an optimizing compiler, and this compiler makes uninitialized memory and provenance a dead-serious reality that you have to live with. It's not a lie, it's real and can make your code go wrong. It's only real as an abstraction, as emergent behavior, but when you write Rust that is the abstraction you have agreed to use, as you better treat it as real. (I have a blog post about that at https://www.ralfj.de/blog/2019/07/14/uninit.html.)

If you have to use hardware-level reasoning, that's what inline assembly is for. (But getting the two to co-exist is a complicated topic.)

I think the common sentiment in low-level programming of treating the Rust (or C) Abstract Machine as somehow "not real" is dangerous. Obviously, the kernel is very prone to this kind of thinking since it is such low-level code, and the common sentiment of language designers of treating the Rust (or C) Abstract Machine as all there is is equally dangerous. The reality of hardware and things outside Rust (such as page tables, to name but a trivial example) is omnipresent. At the same time, though, this code is being compiled by an optimizing compiler, so the Rust AM is just as real as the hardware -- neither of them can be disregarded as a "lie", and a correct kernel can only be produced by treating both of these layers as real in their own right, and carefully managing the interaction between them.

The Tower

Posted Aug 21, 2024 22:37 UTC (Wed) by jsakkine (guest, #80603) [Link]

Your suggestion is based on an imaginary topology that does not exist. Right of the bat, these attributes affecting the topology come to mind:
  • The top-most commit ID
  • Kernel config
  • CPU architecture
Subsystem maintainers will do always only what is best for that particular subsystem.

The Tower

Posted Aug 28, 2024 18:48 UTC (Wed) by amarao (guest, #87073) [Link] (1 responses)

Btw, why did she stop posting? It was really interesting blog.

The Tower

Posted Aug 29, 2024 9:18 UTC (Thu) by atnot (guest, #124910) [Link]

I think most of her blog posting energy goes into the axo.dev blog now, e.g. https://blog.axo.dev/2024/07/an-app-by-any-other-name


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds