18 ms·
An RFC that adds support for Rust to the Linux kernel
- ndesaulniers 6y agoLore link: https://lore.kernel.org/lkml/20210414184604.23473-1-ojeda@kernel.org/ https://lore.kernel.org/lkml/20210414184604.23473-1-ojeda@ke...
- steveklabnik 6y agoLinus's initial reaction: https://lkml.org/lkml/2021/4/14/1099 https://lkml.org/lkml/2021/4/14/1099 I am pleased that these are all addressable things. We'll see!
- joseluisq 6y agoYep, BTW looking forward https://lkml.org/lkml/2021/4/14/1105 https://lkml.org/lkml/2021/4/14/1105 those kind of 'real piece of code' that pleases Linus :)
- xiphias2 6y agoThey are not just addressable, but actually make Rust itself a better systems programming language.
- steveklabnik 6y agoYes, I specifically would really like to see what Josh is talking about here happen: https://lore.kernel.org/lkml/YHdSATy9am21Tj4Z@localhost/ https://lore.kernel.org/lkml/YHdSATy9am21Tj4Z@localhost/ It's kind of a funny space; right now Rust handily gives you "no allocations" (this is where I live) or "infallible + fallible allocations" (this is alloc/std by default) but not "only fallible allocations". This sort of thing is basically filling out the quadrant of options.
- hathawsh 6y agoThe most impressive part is that it's actually conceivable to implement such deep changes without a major version bump in Rust. (I hope so anyway!)
- steveklabnik 6y agoYup, it is. If this plan linked above were to be implemented, what would happen is that you would get the same behaviors by default, but with a new setting, you'd get some APIs removed. That's backwards compatible.
- tetha 6y agoI was thinking that when reading the exchanges. This is a really good interaction. Linus and the kernel have strong requirements for good reasons, and the rust teams are trying to address them in useful ways. Rust in the kernel is not a simple thing, but I think both rust and the kernel will benefit.
- dbrgn 6y agoThere's a Rust RFC and Linus doesn't hate it. Great news!
- joseluisq 6y agoYeah! Even he kind of appreciates one of my favorite Rust features. > So "Result<T, E>" is basically the way to go, and if the standard Rust library alloc() model is based on "panic!" then that kind of model must simply not be used in the kernel. https://lkml.org/lkml/2021/4/14/1131 https://lkml.org/lkml/2021/4/14/1131
- yazaddaruvala 6y agoDo you think a more ergonomic `#[no_panic]`[0] would require Rust wait for an entire effect system, or be valuable enough to add to the compiler as a one-off? [0] https://github.com/dtolnay/no-panic https://github.com/dtolnay/no-panic
- steveklabnik 6y agoI am not sure.
- pedrocr 6y agoEven for normal user space code having a way to detect panic at compile time and abort compilation would be great. Ideally together with a way to wrap functions that do panic by catching it and throwing an error instead so the panic infrastructure can still be used. I've sketched that out on HN the other day: https://news.ycombinator.com/item?id=26191644 https://news.ycombinator.com/item?id=26191644
- gpm 6y agoThis exists, provided you compile with the (default) unwinding panics https://doc.rust-lang.org/std/panic/fn.catch_unwind.html https://doc.rust-lang.org/std/panic/fn.catch_unwind.html
- estebank 6y agoThat is still something that happens at runtime, not compile-time. What the kernel would need is not only for the fallible alloc APIs (like Box::try_new) to be expanded to cover all their needs, but also to be able to remove the ability to use the infallible/panicky ones (like Box::new) to ensure, at compile time, that panic will never be called.
- chrismorgan 6y ago> Note that this function may not catch all panics in Rust. A panic in Rust is not always implemented via unwinding, but can be implemented by aborting the process as well. This function only catches unwinding panics, not those that abort the process. The most notable way this can go wrong in pure Rust code is that panic-while-panicking aborts. So you have to be careful that your destructor can never panic.
- nynx 6y agoIt's already kind of possible to statically prevent all panics: https://crates.io/crates/no-panics-whatsoever https://crates.io/crates/no-panics-whatsoever. It's pretty hacky, but it works on no_std.
- yagizdegirmenci 6y agoLinus addresses the RFC 2116[1] of Rust which aims to add support for fallible allocations to the standard collection APIs. This RFC is accepted and implemented. See the Josh's answer[2]. [1]: https://github.com/rust-lang/rfcs/blob/master/text/2116-alloc-me-maybe.md https://github.com/rust-lang/rfcs/blob/master/text/2116-allo... [2]: https://lore.kernel.org/lkml/YHdSATy9am21Tj4Z@localhost/ https://lore.kernel.org/lkml/YHdSATy9am21Tj4Z@localhost/
- JoshTriplett 6y agoRFC 2116 addresses part of the issue. The other part of the problem would be to support disabling the non-fallible APIs at compile time. Also, RFC 2116 assumes that it's sufficient to provide (for instance) Vec::try_reserve, and require callers to always call that before calling anything that might expand the Vec. That wouldn't eliminate the runtime panics. It might be necessary to go a step further, and actually provide fallible versions of individual Vec methods. (Or there may be other potential solutions.)
- Ericson2314 6y agoYeah `try_reserve` is ~~racy and~~ (edit, strikethrough) awkward to use. And having a bunch of a panics which "should" be dead code because of the proceeding `try_reserve` at best adds a bunch of noise burdening static analysis. A bunch of us, anticipating a reaction like Linus' have been arguing that we need `try_` versions of everything and* a way to prevent the other ones from being used. (Cargo features?) I sincerely hope we finally get that.
- caslon 6y agoIt's unfortunate that this might happen. Kernel compilation times were starting to become so reasonable!
- hulitu 6y agoThis is the problem with SW developers: when something starts working they want to "improve" it until it doesn't work. See firefox for a nice example (it is so sloooow). (no i do not have an SSD but earlier it was reasonable. Now the change to rust is making it slower without any visible improvement in security- still have to update every couple of weeks because of CVEs)
- caslon 6y agoNo, Rust didn't actually make it slower to run. It's likely it made it a bit faster; the code quality in Firefox isn't great. It just makes things slower to compile and less portable.
- easton 6y agoWhat does NAK mean?
- momothereal 6y agoThe opposite of ACK (Acknowledged) in many protocols. Basically Rejected.
- diamondo25 6y agoUsually Not Acknowledged.
- gnull 6y ago"Not Acknowledged", I believe [1]. [1]: https://www.kernel.org/doc/html/v4.15/process/stable-kernel-rules.html https://www.kernel.org/doc/html/v4.15/process/stable-kernel-...
- __david__ 6y agoNegatively Acknowledged, I would say. “Not acknowledged” implies no response rather than a negative response, IMO.
- deleted 6y ago[deleted]
- wahern 6y agoIt comes from the ASCII C0 [transmission] control code NAK, which means "negative acknowledgment"--something was wrong with the last transmitted data block or command, or the reception of it. As opposed to "ACK", which means a block or command was successfully received and accepted. In the original 1963 standard the mnemonic was "ERR", but changed to "NAK" for the 1965 standard. See https://en.wikipedia.org/wiki/C0_and_C1_control_codes https://en.wikipedia.org/wiki/C0_and_C1_control_codes and https://en.wikipedia.org/wiki/ASCII https://en.wikipedia.org/wiki/ASCII In programmer lingo it can means something similar to the original meaning--rejecting a request for faultiness or incompleteness--or it can mean something more like, "no"--answering in the negative.
- thayne 6y agoCould a custom panic handler ( https://doc.rust-lang.org/nomicon/panic-handler.html https://doc.rust-lang.org/nomicon/panic-handler.html) be used to handle allocation or other panics in a more graceful way?
- steveklabnik 6y agoIn theory maybe but in practice I don't think you'd want that.
- flashgordon 6y agoIs it me (and have I been hiding/asleep under a rock for a long time) or is Linus' tone vastly (and pleasantly) different from what his previous persona is known to be? I actually loved (I mean really loved) reading the response as it not only was encouraging but also highly respectful and almost glowing with a trained sort of nuance! Just wow!
- eska 6y agoNah. He took a break to reform himself, but has posted abusive messages since then again here and there.
- IntelMiner 6y agoSuch as?
- dn3500 6y agoHe's really changed. There is a subreddit /r/linusrants that documents his rants. In the last year there have been 9 posts, but most of those are reposts from previous years or not really rants or aimed at technologies, not people. Three years ago there were 27 posts.
- skinkestek 6y agoAnd what makes this even more impressive is that he managed to do it despite being - in manys eyes - a very nice and reasonable person to start with, it wasn't like everything was falling apart around him and everyone was leaving their jobs as maintainers AFAIK, he just decided it would be better for the project if he left this part of his personality behind.
- galgalesh 6y agoIn case you did not know this; he took a break a while back to work on his empathy and communication skills.
- steveklabnik 6y agoI don't read the lkml enough to truly know, but in 2018 he made a public apology and (IIRC) took some time off to go work on his behavior. So maybe that's it! I agree that I found his messages here to be quite pleasant.
- mlindner 6y agoI'm confused why this even came up? Why can't the panics just be caught at the driver interface to the kernel and kill off/unload the driver on panic?
- dochtman 6y agoThe list of unstable features they want to use is interesting: https://github.com/Rust-for-Linux/linux/issues/2 https://github.com/Rust-for-Linux/linux/issues/2
- dochtman 6y agoThe list of unstable features they want to use is interesting: https://github.com/Rust-for-Linux/linux/issues/2 https://github.com/Rust-for-Linux/linux/issues/2
- swiley 6y agoRust seems neat but one thing I've always liked about Linux is how few dependencies it needs to compile. The current rust compiler is not small and depends on LLVM which is not great.
- cbmuser 6y agoThis is why gccrs development is now backed by a company: > https://rust-gcc.github.io/ https://rust-gcc.github.io/ With gccrs, the portability issues of rustc will go away and no extra toolchain will be needed for the Rust code in the kernel either.
- amelius 6y agoWhy is LLVM a problem?
- erik_seaberg 6y agoAccording to https://www.kernel.org/doc/html/latest/kbuild/llvm.html https://www.kernel.org/doc/html/latest/kbuild/llvm.html > LLVM does not target all of the architectures that Linux supports and just because a target is supported in LLVM does not mean that the kernel will build or work without any issues.
- dleslie 6y agoLLVM is a non-starter for _many_ small embedded targets. GCC is the go-to for anything not x86 or ARM.
- alexhutcheson 6y agoARM seems to have pretty thoroughly won the category of “embedded targets that are capable enough to run Linux”, though. Other than ARM and (presumably in the future) RISC-V, what other architectures are still relevant for new embedded designs that would run Linux? Obviously there is still significantly more diversity at the low end of the embedded world, but you wouldn’t run Linux on e.g. an MSP430, even if you somehow had a compiler that would support that.
- 6y ago
- joseluisq 6y agoLatest Miguel Ojeda reply to Linus concerns https://lkml.org/lkml/2021/4/14/1130 https://lkml.org/lkml/2021/4/14/1130
- cbmuser 6y agoLuckily, the gccrs developemt work is now backed by a company who is paying the main developer: > https://rust-gcc.github.io/ https://rust-gcc.github.io/ Having Rust support directly built into GCC means Rust code in kernel will not limit portability and no additional toolchain will be needed.
- habitue 6y ago> The project is still in an early phase with the goal to compile the offical Rust test suite. There are no immediate plans for a borrow checker as this is not required to compile rust code and is the last pass in the RustC compiler. This is essentially a reimplementation of rustc. I'm not going to say "don't boil the ocean" but it will likely be a while before this is at feature parity with the main compiler. Even with a full-time developer. There is a project to use gcc as a backend for rustc, which might be a more tractable option to removing the llvm dependency in the short term: https://github.com/antoyo/rustc_codegen_gcc https://github.com/antoyo/rustc_codegen_gcc
- monoideism 6y agoAgreed. It would likely take a half-a-dozen full-time devs several years to fully re-implement Rust, if they're highly skilled. A gcc rustc backend is the way to go, clearly. That company would have been better off paying for that.
- xiphias2 6y agoThe goal for the dev is to be able to compile rust code in governmental code base. As all the static checking will still be done with rustc, it doesn't need to be a full compiler.
- monoideism 6y ago> As all the static checking will still be done with rustc, it doesn't need to be a full compiler. So then this is just a backend?
- secondcoming 6y agoCan someone expand on the debate about alloc()? Does Rust always panic on allocation failure?
- steveklabnik 6y ago> Does Rust always panic on allocation failure? No. See more below. > Can someone expand on the debate about alloc()? So the question is the one you asked above, but also, more generally, "is it possible to statically disallow panic on OOM?" and related things. Rust the language itself, that is, the language + the core library, doesn't know anything about allocations at all. There are none. Concept doesn't exist. So that's fine. Rust also provides the "alloc" library, which can be layered on top of core. This gives you standard APIs for allocation. They also contain several data structures that use allocation internally. These data structures have APIs that may panic on OOM. So, Linus saw those things, and naturally asked questions about how required they are. The answer is "not required, but it's work to get rid of them, there's a few options, and we didn't want to do that work until we got a higher-level gut check from you." Does that all make sense?
- secondcoming 6y agoSure does. Thanks!
- asimpletune 6y agoGreat explanation, thanks
- Gadiguibou 6y agoThank you for taking the time to explain this. I'm familiar with Rust, but didn't know what he was referring to.
- fuzzer37 6y agoThe one point that stuck out to me is > At the present time, we require certain nightly features. That is, features that are not available in the stable compiler. Nevertheless, we aim to remove this restriction within a year by either `rustc` landing the features in stable or removing our usage of them otherwise. Using unstable features in something like the Linux kernel just seems like a bad idea. Why not wait until Rust is a little more matured, and doesn't need to use nightly features?
- steveklabnik 6y agoThey might. There are five things that they're using that they can't work around: One is going to be stable in Rust 1.52.0, the next release of Rust. This will happen before the next kernel release, so it barely counts. It's also a documentation tooling feature. One is related to symbol mangling, and so in theory could be worked around I'd imagine, but is landing soon enough they don't think it's worth it. The final three are related to each other; two of them look like they're being stable pretty soon, and the third, while it's less clear on timeline, is one pretty small thing. So, the answer is basically that the exposure here is pretty small. How much that matters is a social question as much as a technical one. While "unstable" is a binary designation, within it is a spectrum of unstability. "This feature has no path to stabilization" to "this will be stable in the next Rust" and all things in between. Maybe allowing some unstable things that are closer to the latter is acceptable, maybe not.
- Gadiguibou 6y agoI'm curious about what those specific features are. Could you tell me their names? I'd like to go read up on them a bit more.
- hmfrh 6y agoA list is found here[1]. [1]: https://github.com/Rust-for-Linux/linux/issues/2 https://github.com/Rust-for-Linux/linux/issues/2
- 6y ago
- CyberRabbi 6y agoDoes this RFC include all the requisite “safe” interfaces to enable writing a fully featured driver in Rust? If not, is it theoretically possible to create those safe interfaces within Linux’s API driver infrastructure? Or will some unsafe API usage always be necessary in Rust? I remember there was an issue writing a rust-safe wayland compositor on top of wlroots because wlroot’s ownership model was simply not able to be cast in terms of interfaces that rust was able to prove were safe. [1] Is this not an issue in Linux? [1] http://way-cooler.org/blog/2019/04/29/rewriting-way-cooler-in-c.html http://way-cooler.org/blog/2019/04/29/rewriting-way-cooler-i...
- steveklabnik 6y agoFrom the link: "The intention is to make these as safe as possible so that modules written in Rust require the smallest amount of `unsafe` code possible." When writing a kernel, some unsafe somewhere is always required, on some level.
- CyberRabbi 6y agoYes I saw that but it wasn’t clear on whether it was possible or if there was a clear plan to make it 100% safe. You’re saying some unsafe code is always necessary, why should that be the case? I think the big issue with wlroots was its callback-based API which is common with Linux-internal APIs as well. On a theoretical basis I’m not sure what this means for Rust. Is it simply not possible in the abstract to cast these types of APIs in a form that can be statically proven to be safe? Or is this a deficiency in the current design of Rust? Are all “callback-based” APIs inherently unsafe in Rust? Is it always theoretically possible to recast those APIs in a form that Rust can prove is safe? I would just want to understand exactly why it’s possible to write 100% safe Rust programs in user space and not in Linux kernel space. These are the types of questions I would ask when evaluating whether or not it’s worth investing in and using Rust for my Linux driver.
- throwaway2048 6y agobecause you have to interact directly with hardware at a low level at some point (poking registers, implementing syscalls, implementing process and memory address space isolation, context switching between rings, etc), that will always be inherently unsafe. Userland Rust depends on these guarantees to provide safe code, something has to implement them.
- asimpletune 6y ago> We decided to go with Rust's idiomatic style, i.e. keeping `rustfmt` defaults. For instance, this means 4 spaces are used for indentation, rather than a tab. We are happy to change that if needed -- we think what is important is keeping the formatting automated. Hahaha, preemptive offering compromise on tabs vs spaces warms my soul, good stuff.
- acje 6y agoI also like the strategically elevated abstraction. Doesn't even mater how many warriors are sent into this battlefield, we're not even gonna show up. Although not really novel these days with respect to formatting. Perhaps IT is growing up?
- tomphoolery 6y agoWould this make Linux the first *NIX-based OS that is written in a language other than C? At least, with high usage...
- Gaelan 6y agoI think macOS has some C++ in the kernel, but I'm not sure. And Windows is heavily C++, if you're willing to count WSL1 as "*nix-based".
- saagarjha 6y agoThe core kernel is pretty much all C, but extensions and drivers are C++, yes.
- _joel 6y agoI'm not sure but even in the short to mid term I can't see it replacing swathes of code already written in C. Drivers and such, maybe
- _joel 6y agoQuoted from the post > "Please note that the Rust support is intended to enable writing drivers and similar "leaf" modules in Rust, at least for the foreseeable future. In particular, we do not intend to rewrite the kernel core nor the major kernel subsystems (e.g. `kernel/`, `mm/`, `sched/`...). Instead, the Rust support is built on top of those."
- yjftsjthsd-h 6y agoIf you don't qualify it with "high usage", redox is that. There's also a semantic question; is Linux with some drivers done in Rust really an OS written in a language other than C? It's not like they intend to replace all the existing C with Rust.
- Ericson2314 6y agoWell, gotta start somewhere ;)
- jeffbee 6y agoIt will be interesting if this gains traction, while C++ in the kernel never did. Many, many bugs in the Linux kernel would have been prevented with C++ (the entire class of `goto cleanup;` bugs, for example).
- joseluisq 6y agoMaybe because of this? > I think that the standard Rust API may simply not be acceptable inside the kernel, if it has similar behavior to the (completely broken) C++ "new" operator. https://lkml.org/lkml/2021/4/14/1131 https://lkml.org/lkml/2021/4/14/1131 I'm not a C++ dev BTW, so this could need more details by someone with background for it.
- jeffbee 6y agoEh, that's just Linus continuing to demonstrate how little he knows about C++.
- sinsterizme 6y agoCould you expand? Maybe steel-man what you think his argument would be and your rebuttals?
- jeffbee 6y agoI can't really do a "steel man" rebuttal because over the years Linus has argued against a language he calls C++, but which is a made up language invented for the purpose of hating it. A straw man, if you will. It is difficult and frankly not worth the trouble to try to rebut an argument that has never risen above the level of "crap", "broken", and "bullshit". In the particular case of operator new, it's clear from his cumulative statements that Linus is unaware that the programmer provides global ::new, and can make it do whatever the hell he wants it to do. You can also just forbid it and use placement new everywhere.
- ironman1478 6y ago
- deleted 6y ago[deleted]
- bjourne 6y agoMight be useful to recall that Rust's 1.0 release was in 2015. It may be a little premature to reimplement parts of Linux in such a young language... Rust may be a fad and may not catch on. I have used it a bit and I don't think it offers many significant benefits over C++. (The Rust brigade is out in force I see :))
- andrew_v4 6y agoI think there is a big ideological element to this. As a Rust outsider, I feel like it's the computer science embodiment of the current political discourse. There is something about the "one true cause" mentality, and the need to co-opt projects with other goals and steer them towards the cause. Honestly, it is a really weird experience to have around a programming language, and to me is offputting for something that otherwise could have some very interesting merits. I expect people wont agree with me, and I'm not arguing against the technical merits of the language, I'm just saying that it stands out because of the ideological following it has, and that is cause for concern if ideology is a big reason people try and push to integrate it in something as important as linux.
- roca 6y agoSome of us are mentally scarred from decades of dealing with weak type systems, undefined behavior, and general inability to be sure of what's going on in gargantuan C++ codebases. Rust was more or less specifically designed to appeal to people like us. Throw a rope to a drowning person and they'll grab onto it hard.
- otabdeveloper4 6y agoRust won't make legacy code and legacy coders go away. In fact, as time goes on the amount of crappy legacy Rust code and low-skilled legacy Rust coders will only grow. So Rust is not a solution.
- nicoburns 6y ago> In fact, as time goes on the amount of crappy legacy Rust code and low-skilled legacy Rust coders will only grow But it will make those codebases a lot easier to deal with because the Rust compiler enforces correctness in a myriad of ways that other languages don't. I would much, much rather deal with a legacy Rust codebase than a legacy C++ one.
- jasonhansel 6y agoThis is as much good news for Linux as it is for Rust. In the long run, there is a nontrivial risk that Linux could be replaced by an OS written in a safer language. Moving to a safer language within Linux is likely to ensure Linux's long-term survival in smartphones and servers alike.
- nynx 6y agoI'm not sure "risk" is the right word for it.
- jasonhansel 6y ago<rant> I say "risk" because any such OS would probably be available under a license more permissive than the GPL. The result would almost certainly be that large parts of the OS would become proprietary (NVIDIA has already tried this with Linux's limited module support). Of course, moving to Rust is also a risk in this respect, since the LLVM toolchain is BSD-licensed, but hopefully Rust support will be added to GCC in the not-too-distant future.
- SolarNet 6y agoExcept of course, the GPL is why linux remains so popular. A linux killer cannot be a linux killer unless it is GPL or similar. Or else BSD would have over taken linux a long time ago.
- anitil 6y ago</rant> phew, that was bothering me
- alkonaut 6y agoThanks, it made the rest of this whole comment section a rant.
- alrs 6y agoThe good news is that Rust is going to need to get serious about first-tier support for all architectures supported by the Linux kernel if this is to go anywhere.
- isItStill 6y agoReplace enough of the code, is it still Linux? Perl 6 or bust! https://en.m.wikipedia.org/wiki/Ship_of_Theseus https://en.m.wikipedia.org/wiki/Ship_of_Theseus
- SilverRed 6y agoIf the interface to the user space is still the same then it is. It sounds like rust will mostly be used for modules/drivers at this point anyway.
- PointyFluff 6y agoWoo-Hoo!
- alfiedotwtf 6y agoRust’s panic on `malloc()` is a sticking issue for a lot of people to adopt Rust, so I’m hoping this can be addressed in general!
- mlindner 6y agoAs explained in the thread. Rust the language itself doesn't know what the heap is. The heap is a library-level concept. You can use Rust perfectly well in heap-less/stack-only environments.
- nsajko 6y agoSure, writing kernel code in a more modern language could be a big improvement in the short run (well, as soon as one can write the code, I guess). But what about the long(er) run? By the time this project gets ready for serious consideration (no dependencies on experimental features of Rust, support for all relevant architectures), there could well be a dozen different languages available that improve greatly on Rust, and transitioning away from (a mix of C and) Rust would be difficult compared to transitioning away from C. I know that many think that Rust is the be-all and end-all of programming languages, so much so that there's this effort to put Rust into Linux despite the requirement of nightly Rust versions and Rust still having inadequate support for various architectures. But the hype regarding Rust always seemed misguided to me, Rust is a language built upon the (interesting) idea of ensuring memory safety without a garbage collector, which is cool, but I get the feeling that most Rust fans forget that the actual goal is correctness, not memory safety. On another note, using C++ in the Linux kernel could give a similar kind of improvement, but with much lesser costs than with Rust.
- steveklabnik 6y ago> (no dependencies on experimental features of Rust, Unclear if this is a hard requirement, even if it is, it's stated to be feasible on the timescale of "less than a year". > support for all relevant architectures) This is already fulfilled; this is for drivers only, which are inherently platform-specific, and so only drivers that are usable on the supported platforms would be written. > there could well be a dozen different languages available that improve greatly on Rust As mentioned above, I doubt that this is true within a year, but beyond that, any new language is also going to have all of these same growing pains, but be a decade behind. When they're ready, they should be considered, but "don't do a good thing now because maybe, some unknown amazing thing might appear" isn't usually a good way to make decisions.
- arp242 6y ago> > there could well be a dozen different languages available that improve greatly on Rust > As mentioned above, I doubt that this is true within a year, but beyond that, any new language is also going to have all of these same growing pains, but be a decade behind. When they're ready, they should be considered, but "don't do a good thing now because maybe, some unknown amazing thing might appear" isn't usually a good way to make decisions. This is true, but Linux is a long-term project, we don't know what the future will bring, but I'd be surprised if it wasn't still a mainstream kernel in 20 or even 40 years. It seems to me it would be wise to look at the future as well, and perhaps things are the wrong way around; rather than asking "what existing languages could work for the kernel?" the question should be "what would the ideal language for the kernel look like?" It always seemed to me that Rust is a bit of a strange choice for the Linux kernel; I can see why it has some appeal, but it's also a fairly large and complicated language. How "complex" or "minimal" a language should be is an old debate that we've all done at least a few times, so don't want to repeat it here; for my part, I feel comfterable with both approaches; I'm just as happy programming in Ruby as in Go for example (even though they're polar opposites in many ways), but both approaches come with their own set of advantages and downsides. I'm not so sure that a large and complex language is really the best fit for this particular purpose. For example writing a C compiler for a new architecture is comparatively easy whereas porting Rust to something new will be much harder. Given Linux's long-term prospects it might be wise to invest in an "ideal" language rather than a "it'll work" language. Then again, I don't work on Linux so what do I know :-)
- young_unixer 6y agoWhen we see more Rust implementations, are they going to inherit Rust's package manager? I like the security ideas of Rust, but I'm very much against a compiler including a package manager that points at a particular central repository by default, with all the political problems that that entails, not to mention longevity issues.
- steveklabnik 6y agoThe Rust compiler and its package manager are already separate.
- eointierney 6y agoWhat's really cool about Rust is not that it's a technical improvement on (Ada, C, Cobol, C++, Fortran, Lisp, Haskell, ...) because it isn't yet. It has some really great features, and a lot of potential. It's still young. gccrs is required. It has quite a way to go before it can rival some of the most important _languages_ we use. It's getting there. What's really cool is the humility, flexibility, and creativity, of the community who develop Rust. What's really really cool is Linus is holding a hoop into the kernel
- dodobirdlord 6y agoRust is absolutely a technical improvement on some of the listed languages (C, C++, maybe FORTRAN and COBOL). The borrow checker is truly novel outside of some research languages that precede Rust. The other languages you list are sufficiently different from Rust that it’s hard to make a comparison. Of course Rust is a technical improvement over substantially older languages. To claim otherwise is basically to claim that the twin fields of programming language theory and language design have discovered and achieved nothing in the last 40 years, which is an strange thing to believe.
- naniwaduni 6y agoSadly, we live in the world where golang is popular and backed by a megacorp.
- Gaelan 6y agowrt the discussion about colored unsafe for interrupt safety, would it be possible to have functions that sleep (or whatever) take a zero-sized struct called NotInterrupt or something? Then entry points to Rust code that are known to not be called from interrupts (unsafely) construct a NotInterrupt, and the rest of the code just passes it around. I think with some clever use of phantom references, you can convince the borrow checker to prevent a NotInterrupt from outliving the context it was created for, and as it's a ZST, it should be zero-cost.
- myrrlyn 6y agoyeah this is a common pattern in runtime permissions modelling. it's a really cool trick and i hope it gets more awareness from cases like this
- person_of_color 6y agoIs this part of Oxide Computer Co?
- steveklabnik 6y agoNo relation.
- Unklejoe 6y agoDoes Rust support every architecture that the kernel supports? Seriously asking, not rhetorical. I get that new Rust code will be limited to modules, but here's my concern: I do work for embedded systems based on the PPC architecture. I'm not sure if Rust supports PPC, but let's just assume we're talking about an architecture that's not supported. Suppose some company creates a PCIe Ethernet adapter and writes their driver in Rust. If Rust doesn't support PPC, then I won't be able to use that hardware even though there's no physical or technical reason why it wouldn't work. If it was written in C like everything else, then there's a good chance it would just work (assuming they didn't make any endianness assumptions). In fact, I'd bet that the majority of the drivers written for the kernel are really written for X86 and ARM, but just so happen to work for PPC as well for free. I'd be concerned about getting left in the dust, so to speak.
- timw4mail 6y agoRust works on 64bit little-endian PPC at least, with full standard library support.
- steveklabnik 6y agoThe current list of support: https://doc.rust-lang.org/stable/rustc/platform-support.html https://doc.rust-lang.org/stable/rustc/platform-support.html