News for hackers. Stuff that matters.
Re:Rust support in the Linux kernel by b20000 on Wednesday December 08, 2021 @12:00PM (#29487229)
i don’t want rust in the kernel, because it will make my job as a small device manufacturer even more complicated. it is already super hard / time consuming to understand how to build custom drivers and tune the kernel for specific applications, so i don’t need or want another language involved in there. in the end, you still need to understand what you are doing, and rust is not going to change that.

the days that linux was only used as a secure server OS are long gone. it is used everywhere for all kinds of applications and by lots of small manufacturers who are using the pi or other platforms.

also, you cannot just develop a driver in isolation, you have to take the typical use cases in mind while you make choices how to handle things.

Re:Rust support in the Linux kernel by simias on Wednesday December 08, 2021 @12:20PM (#29487538)
I understand your concern and I would definitely feel the same if some language I wasn't familiar with was suddenly introduced in the kernel. But at the same time as a big Rust enthusiast I think it's really a good idea in the long run: C is going nowhere but it's really dated, design-wise. When you've tasted the sweet nectar of type inference, strong typing, union types and of course the safety of the borrow checker, returning to C feels like banging rocks together.

The main drawback of Rust here I think is the longer compile times (I dread to imagine how long a fully Rustified kernel would take to build) and a generally more complex, but also more expressive language.

More generally I trust the kernel maintainers not to succumb to the hype and overdo it. People who still exchange patchsets over mailing lists are probably unlikely to be blinded by shiny things.

Re:Rust support in the Linux kernel by einpoklum on Wednesday December 08, 2021 @03:25PM (#29490021)
From the perspective of people who don't know Rust, it's not a sweet nectar, but a suspicious murky liquid.

From the perspective of people who don't like aspects of Rust, it's a yucky goo.

This is _not_ like with C. Few people are enamored with C, but - the language itself is relatively simple (Duff's device notwithstanding...), so in my analogy it's like water. You may not adore it, but you can see through it, and you'll be ok with gulping it down to quench your thirst.

Re:Rust support in the Linux kernel by nicoburns on Wednesday December 08, 2021 @03:57PM (#29490394)
> From the perspective of people who don't like aspects of Rust, it's a yucky goo. > This is _not_ like with C

I beg to differ. This is exactly how I feel about C. C is the language that's confusing as hell to read for anything other than really simple use cases AND makes it super easy for me to shoot myself in the foot.

Re:Rust support in the Linux kernel by b20000 on Wednesday December 08, 2021 @08:16PM (#29492676)
C is what you program is what you get. and i think that is pretty important.
Re:Rust support in the Linux kernel by kungito on Thursday December 09, 2021 @02:40AM (#29494842)
This is true for any programming language. The problem is being aware of what you really wrote
Re:Rust support in the Linux kernel by b20000 on Thursday December 09, 2021 @12:01PM (#29499872)
No, you are wrong. C++ is one example. I've been using that language now for about 20 years and I still don't use all of its features. It is possible to write code in that language that you assume will work a certain way but then in practice it does a lot of things you didn't think you signed up for. Recently I started using STL more, after having stayed away from it for most of my career, and the performance of my application went out the window, and I had to override all memory allocation related functions to fully understand where the problem was coming from. It's easy to use the STL and make assumptions about performance, then find out later you get a lot of issues that come with it that you never signed up for. And that is why I don't want rust in the kernel. If a language does a lot of stuff for you, there will be a price to pay.
Re:Rust support in the Linux kernel by nicoburns on Thursday December 09, 2021 @01:09PM (#29500826)
> It is possible to write code in that language that you assume will work a certain way but then in practice it does a lot of things you didn't think you signed up for

This is also possible for C. Most commonly around Undefined Behaviour. C only does what you expect it to do if you know the C spec inside out. Rust can have confusing behaviour too, but it is generally much better in this regard than C or C++.

You may find it easier to reason about C than Rust, but that's only because you know C better. I find it much easier to reason about Rust.

Re:Rust support in the Linux kernel by einpoklum on Thursday December 09, 2021 @02:50AM (#29494898)
With modern compilers, there is no such thing as what you program is what you get.
Re:Rust support in the Linux kernel by randomswede on Thursday December 09, 2021 @07:13AM (#29496480)
As long as you stay away from compiler-dependent, platform-dependent, and/or undefined behaviour, you should be fine. Main problem is that a surprising ab´mount of "looks normal" code is actually UB.
Re:Rust support in the Linux kernel by einpoklum on Friday December 10, 2021 @03:46AM (#29507805)
You would be "fine", but the compiler will optimize away alot of your code, and will rearrange a lot of the rest. I wasn't even talking about platform-dependent or undefined behavior.
Re:Rust support in the Linux kernel by pjmlp on Thursday December 09, 2021 @02:28AM (#29494797)
C is what you program is what you might get.

Know thy standard and thy compiler optmizations, least you be surprised by the outcome.

Re:Rust support in the Linux kernel by merb on Wednesday December 08, 2021 @04:27PM (#29490753)
> Few people are enamored with C, but - the language itself is relatively simple

if you don't use pointers, yeah. but like you can't built anything useful without pointers.

Re:Rust support in the Linux kernel by b20000 on Wednesday December 08, 2021 @08:15PM (#29492672)
if you do not understand pointers and cannot work with them, you probably should not be a software engineer.
Re:Rust support in the Linux kernel by danShumway on Thursday December 09, 2021 @12:06AM (#29494035)
I'm not sure that it's the concept of pointers that make C code harder to maintain than other languages. Lots of languages have pointers, including Rust.

It's a question of whether unguarded pointers (and a lack of language features that keep pointer math from devolving into an unreadable mess) are good to have in areas where pointer errors can result in critical bugs. We started discouraging goto statements not because developers didn't understand them, but because they did understand them, and they understood that the tools you use influence the type of code you write. And Rust doesn't even really get rid of pointers, it just adds rules around them.

We all accept some degree of abstraction/safety tradeoff, otherwise we'd program in lower-level languages than C that are even simpler and even easier to understand. C does introduce a lot of complexity over more primitive assembly languages. And Rust introduces a lot of complexity over C.

Different people pick different points where they think the tradeoffs are optimized. But we have a pretty large amount of data suggesting that even <quote>good</quote> programmers in industry make pointer errors in C. So it's pretty obviously not lack of understanding that's causing these issues, it's that unrestricted memory access and pointer math is inherently error-prone. Whether it's SO error-prone that's it's worth introducing a much more complicated, rigid language into the kernel is left as an exercise for the reader. There is a downside to introducing more complexity here, all abstractions have downsides.

But it's real dismissive to say that if everyone understood C pointers then their code wouldn't ever devolve into an unreadable mess. I just don't think that's an opinion that can be backed up by any real evidence, pretty much every org struggles to some extent with writing secure C code. And we have a lot of experience in the field of software engineering that should have taught us by now that sometimes unreadable code is the result of language affordances and patterns.

Re:Rust support in the Linux kernel by afiori on Thursday December 09, 2021 @04:31AM (#29495437)
Also there are many different ways to undestand and use pointers; there are many many programmers that are really good at using pointers and are able to engineer essentially safe architechtures, but many of those very good programmers would come up with incompatible architectures around pointer usage.

My wild guess is that most "simple" pointer errors (use-after-free, double-free, unintentionally using unitialized memory, ...) happens at interfaces where there isn't perfect comunication about what component is responsible for keeping track of each task.

Re:Rust support in the Linux kernel by danShumway on Thursday December 09, 2021 @12:19PM (#29500161)
Yeah, I think about a very offhand comment that Carmack made once that ended up resonating with me a lot, even though I don't think it's universally across the entire board true:

> "Most bugs are a result of the execution state not being exactly what you think it is."

There is an aspect of language design that is about making it hard to be surprised by things. And I vaguely suspect that a lot of pointer errors fall into this category; people assume something is being freed, they assume that a subroutine is cleaning up after itself or that it's not manipulating something, or that it doesn't need to call some setup method before it's run. These are boundary errors between interfaces where allowing users to (inadvertently) mask what is happening can lead to logic that feels very convoluted and hard to follow, and can also lead to simple errors around just forgetting to do stuff.

I wouldn't call that Carmack quote a mantra, I'm not saying it explains all programming (or that all architectural restrictions are good), it's just a lens that I keep coming back to when I think about language design and architecture; there's a real tradeoff in removing flexibility, but there is also a huge amount of value in systems/patterns that make it very hard to bury relevant information. And if a language can auto-surface some of those problems, that can lead to cleaner code.

Re:Rust support in the Linux kernel by viraptor on Thursday December 09, 2021 @07:09AM (#29496460)
It depends what level you mean. Understanding and using pointers on basic way is simple. Understanding pointer provenance, aliasing rules, etc. are a completely different level and people not very familiar with the spec (so almost everyone) do not understand a lot about pointers. http://open-std.org/JTC1/SC22/WG21/docs/papers/2019/p1434r0....
Re:Rust support in the Linux kernel by viraptor on Thursday December 09, 2021 @07:04AM (#29496427)
> The main drawback of Rust here I think is the longer compile times

The time scales with the compiled unit size. If you're compiling drivers/modules, they're going to be fairly small and not much slower than C.

Re:Rust support in the Linux kernel by raxxorrax on Thursday December 09, 2021 @08:36AM (#29497149)
I think type inference is much more important for people that used dynamically typed languages instead of C devs. You could argue that it is also much more important for Rust.
Re:Rust support in the Linux kernel by b20000 on Wednesday December 08, 2021 @12:25PM (#29487624)
the point is that you still need to know what you are doing. rust won’t change that. C is everywhere, and that is not going to change anytime soon. your time is better spent understanding more of the kernel instead of learning another tool set.

one of the biggest hurdles for me was the DTB declarative language. that was the most stupid idea ever to invent that and i lost 100s of hours trying to get my DTB files right for my hardware. so you can understand i don’t want more hipster shit to deal with.

Re:Rust support in the Linux kernel by dagmx on Wednesday December 08, 2021 @12:39PM (#29487813)
You need to know less about what you're doing with Rust at any given time versus C, for the programmer.

Also at this point, Rust isn't "hipster shit". You're just not familiar with it, and that's fine. But it's in wide use now and proven to solve major classes of recurring issues.

Re:Rust support in the Linux kernel by b20000 on Wednesday December 08, 2021 @08:17PM (#29492683)
i’ve looked at it briefly. i do not need or want it, and that is fine. what is important, is to keep the kernel tree simple and understandable. that means minimizing the number of tools and languages involved. which means not introducing rust.
Re:Rust support in the Linux kernel by dagmx on Wednesday December 08, 2021 @08:55PM (#29492919)
> keep it simple and understandable

Yes. Rust helps with that because as a language it simplifies avoiding huge classes of vulnerabilities.

Rust simplifies it for the developers by moving part of the mental model of the developer into the compiler.

Re:Rust support in the Linux kernel by b20000 on Thursday December 09, 2021 @12:36AM (#29494194)
i don’t care about vulnerabilities. it is very annoying that everyone assumes that linux is only used for applications where security matters. plenty of devices using linux do not need to be secure and forcing rust onto the entire linux kernel community because of a vulnerability argument is stupid and will only make it harder for people to use linux in a project.
Re:Rust support in the Linux kernel by dagmx on Thursday December 09, 2021 @02:46AM (#29494877)
This is just absurd. It's like arguing against seatbelts as a default in cars because you might sit in your driveway most of the time.
Re:Rust support in the Linux kernel by LtdJorge on Thursday December 09, 2021 @05:45AM (#29495958)
Most Linux installations are cloud servers. So yes, Linux really needs to be secure.
Re:Rust support in the Linux kernel by b20000 on Thursday December 09, 2021 @02:08PM (#29501538)
i think that has changed over the past 20 years. linux is now everywhere and not just on servers in data centers. and this requirement is not a valid reason to force rust onto all device creators who choose linux.
Re:Rust support in the Linux kernel by Latty on Wednesday December 08, 2021 @12:43PM (#29487862)
Assuming anything new is bad because of a bad experience seems like a poor lesson to take.

Of course you need to know what you are doing still, but pretending humans don't make mistakes even when they know what they are doing is ignoring reality.

Re:Rust support in the Linux kernel by hedgehog on Wednesday December 08, 2021 @01:18PM (#29488312)
As a counterpoint security in e.g. Bluetooth has been an ongoing problem and even "mature" code like ext4 has recurring problems. Somehow I doubt the problem is that the people involved are not smart enough or trying hard enough. Maybe it's worth revisiting what tools we use.
Re:Rust support in the Linux kernel by b20000 on Wednesday December 08, 2021 @08:20PM (#29492706)
there are many situations where security does not matter. so that is not a reason to force rust into the code base. not everyone is working on a device that needs to be secure.
Re:Rust support in the Linux kernel by msbarnett on Wednesday December 08, 2021 @08:34PM (#29492794)
> not everyone is working on a device that needs to be secure.

And those drivers can continue to be written in C. Rust is merely an option.

Re:Rust support in the Linux kernel by b20000 on Thursday December 09, 2021 @12:38AM (#29494202)
i need to be able to read and understand any driver’s source code without having to learn rust.
Re:Rust support in the Linux kernel by msbarnett on Thursday December 09, 2021 @12:52PM (#29500608)
The rubric for decision making in Linux kernel driver development is not "what HN user b20000 thinks they need", as far as I am aware.
Re:Rust support in the Linux kernel by b20000 on Thursday December 09, 2021 @02:14PM (#29501615)
this is not about me. it is about keeping the kernel tree reasonably accessible for small startups and device creators who do not have the funding of FAANGs and cannot afford to take on more complexity on top of something that is already very complex.
Re:Rust support in the Linux kernel by dagmx on Thursday December 09, 2021 @03:16AM (#29495052)
So the whole kernel should be beholden to you as the minimum viable target then? I hope you realize how self centered that outlook is.
Re:Rust support in the Linux kernel by dagmx on Wednesday December 08, 2021 @08:57PM (#29492935)
Anyone who values simplicity over security in the most used kernel in the world, has their priorities in the wrong place.
Re:Rust support in the Linux kernel by simias on Wednesday December 08, 2021 @06:53PM (#29492174)
You always need to know what you're doing, but Rust lets you encode more of what you mean in the code and the compiler checks that you're not violating your own invariants. That's the killer feature for me. I feel like I'm working with the compiler, not against it.

Sometimes I feel like C's compiler is almost adversarial, going out of its way to find small mistakes in my code and have them blow in my face at runtime instead of notifying me. I understand why it works that way of course, but usually when my Rust code compiles, it works. I can't say as much for my C code, despite nearly 20 years of practice.

I do share some of your frustrations with the DTB thing, I'm not a fan of it either, although something like that was needed and I'm sure any alternative would have its haters.

Re:Rust support in the Linux kernel by throwamon on Wednesday December 08, 2021 @02:19PM (#29489110)
> your time is better spent understanding more of the kernel instead of learning another tool set

No matter your skill level, that won't stop you from committing memory-safety mistakes that may lurk for years until they suddenly result in a catastrophic failure. Evidence for that is abundant.

Re:Rust support in the Linux kernel by duped on Wednesday December 08, 2021 @01:20PM (#29488336)
Have you tried reading or writing any Rust?
Re:Rust support in the Linux kernel by zerocount on Wednesday December 08, 2021 @02:49PM (#29489519)
I have, and it was the most frustrating language I've ever tried. You sit there staring at the code wondering what's wrong with the variable you created until you Google it and find out it's a certain type that you never heard of. It's ridiculous.

I'm sure it gets better as you memorize the millions of different types, but what benefit do you get from all this pain?

I also think it's just a boy's club at this point. Big pipe dreams of rewriting all the C++ and C code is all we here about. It's not going to happen. The language is too f*k*g hard to learn so no one will. It's like trying to make everything in Haskell, c'mon, get real.

Someone had to say it...

Re:Rust support in the Linux kernel by duped on Wednesday December 08, 2021 @06:29PM (#29491968)
How do you mean, "memorize the millions of different types" and "You sit there staring at the code wondering what's wrong with the variable you created until you Google it and find out it's a certain type that you never heard of"?

I don't think I've experienced this in any language, even ones with the most expressive type systems. More typing is better, as far as I have experienced, and as far as I have heard from people who take it up in their projects.

The compiler will tell you exactly what goes wrong if you pass the wrong type. If you mean that type inference was confusing, it's the same as `auto` in C++. Except the Rust compiler does an enormous amount of handholding with errors, often showing you exactly how to correct your code.

Re:Rust support in the Linux kernel by b20000 on Wednesday December 08, 2021 @08:23PM (#29492724)
why is this voted down? can’t we have a conversation and hear some other opinions?
Re:Rust support in the Linux kernel by kbenson on Wednesday December 08, 2021 @08:55PM (#29492918)
>> I also think it's just a boy's club at this point.

Probably mostly because of that.

Not that the other points are necessarily easy to follow since they're not well explained. If knowledge of why some type was hard to know or had to be googled (or for example noting what one of those types is) was presented, then people might have been able to respond to those points.

Instead it reads as "it's hard, I used it and it's hard, and I had to do some stuff I didn't like, and so my impression is it's just a bunch of people faffing off and it's too hard to take seriously", which isn't really useful for a discussion, and additionally is dismissive. Every one of the criticisms presented could be said about C without any change because no actual concrete details are provided.

It's not like Rust is perfect, there are many valid criticisms of it that have real examples and make useful points. Those comments probably deserve your defense more than this one.

Re:Rust support in the Linux kernel by JoelMcCracken on Wednesday December 08, 2021 @02:59PM (#29489669)
What is DTB??
Re:Rust support in the Linux kernel by xxpor on Wednesday December 08, 2021 @03:26PM (#29490025)
A file format to describe device trees, which describe the HW attached to the system. Mainly used on !x86 arches, as an alternative to ACPI-style autodiscovery:

https://en.wikipedia.org/wiki/Devicetree

Re:Rust support in the Linux kernel by structural on Wednesday December 08, 2021 @06:36PM (#29492027)
I laughed out loud reading at his devicetree frustration, because while it's pretty gross to work with at times, at least it's not ACPI!
Re:Rust support in the Linux kernel by lambda on Wednesday December 08, 2021 @03:14PM (#29489845)
Adding Rust doesn't make it harder to do any of this. When you build a custom driver, you could choose to develop it in C or in Rust. It gives you the choice, and many of us find it easier to build in Rust than in C; but even if you prefer C, you will still have that choice.

Most of "tuning the kernel for specific applications" consists of making changes to the kernel config or compiler settings. Rust won't change the kernel config system, and compiler settings for Rust are quite similar to those for C, as Rust uses LLVM as its backend, and LLVM is used by Clang which goes to a lot of effort to provide a mostly GCC compatible interface.

> in the end, you still need to understand what you are doing, and rust is not going to change that.

If think you understand what you are doing in C, you probably don't. C is a fantastically difficult language to write correct code in at scale; even the best developers make simple mistakes all the time.

I understand the frustration at seeing something else you might have to learn and deal with that might make things a bit trickier during a transition, but that's pretty much the nature of keeping up with any kind of ongoing development process. It's not like the Linux kernel sprang fully formed out of Linus's head on day one and it's just been a matter of adding drivers and making small incremental fixes. There are all kinds of changes that require you to change and adapt, like the removal of the Big Kernel Lock, or pretty much any internal API work, and yeah there can be work to keep up, but that doesn't mean you should hold back progress.

Re:Rust support in the Linux kernel by kelnos on Wednesday December 08, 2021 @02:56PM (#29489622)
That just sounds like "I don't want progress because it will mean I have to learn new things and I don't want more work for myself". Well... tough luck?

Regardless, if you want to keep using C to write your Linux drivers, the new Rust support does not change that.

Re:Rust support in the Linux kernel by mkipper on Wednesday December 08, 2021 @05:32PM (#29491429)
If you're a device manufacturer trying to manage common code for a variety of hardware platforms with subtle differences in toolchains / kernels, dealing with all that complexity can be pretty tough. If Rust drivers start popping up in the kernel, you now need to start dealing with twice as many toolchains and twice as much complexity.

One of those toolchains is used to build the bootloader, kernel and majority of userspace software for the devices. The other toolchain is used to build an I2C temperature sensor driver that was rewritten in Rust so someone could put Rust driver experience on their resume.

Dismissing this and saying "suck it up, this is the price of progress" is fine. But it doesn't change the fact that this could be a giant PITA for people making devices and developing the BSPs for them while providing almost no value. I'm not trying to argue that appeasing this group is important enough to totally reject Rust from the kernel, but as a maintainer, making life difficult for a huge number of kernel users is probably something you'd like to avoid.

I think a lot of this will come down to how Rust patches are reviewed and accepted. If Amazon or Facebook want to upstream some new Rust driver they wrote for their own hardware, there's probably no negative impact to anyone by merging it. But I'd expect maintainers will be very hesitant to accept patches that touch existing drivers. I guess time will tell.

Re:Rust support in the Linux kernel by b20000 on Thursday December 09, 2021 @12:42AM (#29494228)
amazon or facebook can afford to pay lots of developers to deal with this. i cannot, and if they force their rust code onto the community, it will close the door for lots of smaller device manufacturers including myself. and that is the main issue. linux does not exist to entertain the interests of those with more money.
Re:Rust support in the Linux kernel by raxxorrax on Thursday December 09, 2021 @08:47AM (#29497240)
Reading up on the Rust spec and concepts is fairly trivial compared to letting a lot of devices and their drivers interface each other. I don't think Rust inclusion will change that however. Time will tell, but your response is rather childish.
Re:Rust support in the Linux kernel by b20000 on Thursday December 09, 2021 @05:32PM (#29503911)
have you designed any custom hardware running linux requiring custom drivers? if you do, then you will understand my concern.
Re:Rust support in the Linux kernel by Barrin92 on Wednesday December 08, 2021 @01:31PM (#29488489)
no offense but aren't security concerns just as pressing in the world small manufacturers, embedded etc.. given that those kinds of devices are nowadays part of pretty vital infrastructure?

the lack of memory safe languages is probably the nr. 1 contributor to critical bugs in software and regardless of what we're working on we ought to learn new languages if they help to improve software quality.

Re:Rust support in the Linux kernel by ggrrhh_ta on Wednesday December 08, 2021 @02:47PM (#29489503)
I don't believe that the change to rust (and I like rust a a lot) will lead to a measurably more secure kernel in the long term, although it will mean that maintaining the kernel will require knowledge of Rust in addition to C (and some flavors of assembly, occasionally). On top of that, the Rust that can be compiled into the kernel will be a subset, or its compilation will be tuned [idiomatic and safe allocation of memory within the stack, efficient Rust/C interoperability with dynamically allocated memory, in a Rust-safe way, etc.].

Let me explain why I think that:

In the short term, having more eyes looking at and re-implementing the scaffolding for drivers and the drivers themselves will certainly lead to a very positive outcome - many potential bugs (of which, most of them will not really be exploitable, but some will) will be uncovered which couldn't have been introduced with safe Rust. However, at some point, the coolness factor will drop, drivers will become fossilized, a larger developer base that has to maintain older Rust drivers might cut corners, use more unsafe features, misunderstand/misremember the nuances of this or that, and what was once exciting is now tedious. Maybe not, maybe Rust will slowly replace the whole kernel, however, at the current stage at which Linux is, I find it unlikely (but possible).

Re:Rust support in the Linux kernel by nicoburns on Wednesday December 08, 2021 @03:12PM (#29489814)
> a larger developer base that has to maintain older Rust drivers might cut corners, use more unsafe features, misunderstand/misremember the nuances of this or that, and what was once exciting is now tedious.

The great thing about Rust is that it makes it much harder to cut corners, and much more obvious when someone does (making it easier to pick up at review stage). Invariants can be built into APIs in a way that simply can't be done in C.

Re:Rust support in the Linux kernel by tialaramex on Wednesday December 08, 2021 @03:34PM (#29490128)
But the Rust safety guarantees aren't about eyeballs, they're about boring mechanical processes, the same difference as say, having your CI run unit tests and refuse to provide artefacts if the tests fail versus telling developers "Make sure you run the tests before shipping a release" which they will promptly forget to do.

The machine doesn't get bored. The fact Rust may not be "cool" any more doesn't alter the fact that your subsystem maintainer isn't going to accept your patch that doesn't compile because you tried to take the lock for foo, but then used locked variable bar - something C has no problem with but which in Rust of course does not compile.

Re:Rust support in the Linux kernel by karmanyaahm on Wednesday December 08, 2021 @12:04PM (#29487286)
I'm pretty sure it will be totally optional to write drivers in Rust, rather than C.
Re:Rust support in the Linux kernel by megous on Wednesday December 08, 2021 @12:13PM (#29487421)
I just really hope this thing will not be a bitch to cross-compile. I'm not interested in building llvm + rust in addition to my 5 or so gcc cross-compilers, especially looking at the cadence of rust releases.

So as long as it will be possible to use the system's llvm+rust to build for all 4 CPU archs (at once) I'm currently building my kernels for, I'll probably not be too cranky about rust in the kernel.

Re:Rust support in the Linux kernel by kelnos on Wednesday December 08, 2021 @03:02PM (#29489711)
Cross-compilation with Rust is fairly trivial; it's just a matter of "rustup target add some-host-triple".

GCC's cross-compilation story is indeed a nightmare. I expect if you have to use the GCC Rust backend (after it's ready) for arches rustc/LLVM don't support, you'll have that pain, but I expect it will just be a matter of adding an "--enable-language rust" to the GCC configure script run, similar to adding C++, ObjC, etc. to a GCC build. So the cross-compiler build will take longer, but won't involve extra steps or infrastructure.

Re:Rust support in the Linux kernel by megous on Wednesday December 08, 2021 @06:56PM (#29492194)
Binutils/gcc cross-compiler can be built rather quickly, once you know the right configure flags for each. Then it's just make && make install. You can speed the buil considerably by building with -g0 and not doing a bootrstrap or building needless targets.

Then you have a cross-compiler in some --prefix that you can point the kernel build system to via some environment variables and you're done. It's a well known process.

It's basically built just like any other dependency and doesn't take much time.

Hardly a nightmare. If it would be possible to just add rust to the list of gcc languages, that would indeed be very easy.

Re:Rust support in the Linux kernel by lambda on Wednesday December 08, 2021 @03:20PM (#29489946)
Cross compilation is actually much easier with Rust than it is with gcc. Every Rust compiler is a cross-compiler for all architectures that Rust supports; all you need is the rest of the toolchain like linker and libraries. rustup handles installing the libraries, and as lld (the LLVM linker) adds support for more platforms it can also be used as a cross linker, rather than a linker per target as in the older toolchains.
Re:Rust support in the Linux kernel by floatboth on Wednesday December 08, 2021 @01:46PM (#29488683)
LLVM is always inherently a "cross-compiler". In fact having to have "5 or so compilers" is just GCC being stupid.
Re:Rust support in the Linux kernel by megous on Wednesday December 08, 2021 @03:07PM (#29489764)
Good. :)
Re:Rust support in the Linux kernel by duped on Wednesday December 08, 2021 @01:21PM (#29488354)
Cross compiling with Rust is actually not that bad.
Re:Rust support in the Linux kernel by b20000 on Wednesday December 08, 2021 @12:34PM (#29487746)
what if your driver or user space app is affected by a poorly architected driver which was written in rust? now you need to deal with that rust source code. a true nightmare.
Re:Rust support in the Linux kernel by dagmx on Wednesday December 08, 2021 @12:43PM (#29487858)
Why would that be worse than if it was written in C? A rust codebase would be much easier to find the bugs in and refactor accordingly, than in C.

Plus it's not like most people are going to dive into driver code without experience in the driver itself. So it's a niche set of folks this would affect, the majority of whom would likely be writing the rust code anyway since they're likely the ones most familiar with the driver aspects.

Re:Rust support in the Linux kernel by kbenson on Wednesday December 08, 2021 @01:00PM (#29488091)
People have said the same thing about every language. I'm positive people complained about using C over assembly (people still do for certain things).

I ask you to imagine a situation where a kernel is written in assembly, and they decide to start allowing C to be used for drivers. How would you view a change such as that?

Re:Rust support in the Linux kernel by edgyquant on Wednesday December 08, 2021 @01:45PM (#29488673)
There’s a huge difference. Rust syntax is a lot more complex than C, while this isn’t true for C v assembly.
Re:Rust support in the Linux kernel by kbenson on Wednesday December 08, 2021 @02:05PM (#29488916)
The semantics of C and how to write code that is well defined is much more complex than assembly.
Re:Rust support in the Linux kernel by edgyquant on Wednesday December 08, 2021 @09:24PM (#29493085)
I disagree. You can learn the semantics of C in a day, assembly requires a ton more memorization and a ton more code to write. C is more abstract that assembly but it is less complicated, on its face, than assembly or rust.
Re:Rust support in the Linux kernel by kbenson on Thursday December 09, 2021 @01:21AM (#29494440)
If you're familiar enough with programming to learn C in a day, you can learn assembly in a couple hours. It's really not that complicated. You can copy to/from memory addresses to local temp variable containers that are various sizes of bits (registers), you can do various math operations on those bits in those registers, you can compare those registers and test that comparison, and you can jump from the current point in the code to any other point by label or address (go-to). Sometimes operations will result in other registers you can check to see if something happened (overflow). The OS will provide some interrupts to do some base things as interrupts such as IO.

If you didn't know how to code in assembly already, you now know enough to do everything C can do with a simple reference sheet. All the extra boilerplate (such as program segments and where to store costants such as what the 'strings' program sees in a binary) you can read two to three pages to explain what you need for whatever OS you're on.

Assembly isn't hard, it's just tedious.

Re:Rust support in the Linux kernel by formerly_proven on Wednesday December 08, 2021 @02:33PM (#29489305)
C is easy to read and follow though. Rust has far more syntax and as a language is way beyond the complexity of C.
Re:Rust support in the Linux kernel by nicoburns on Wednesday December 08, 2021 @03:14PM (#29489844)
Only if you know C but not Rust. I personally find Rust fairly easy to follow and C a complete nightmare (the details in C are ok, but it's really hard to see the forest for the trees).
Re:Rust support in the Linux kernel by edgyquant on Wednesday December 08, 2021 @09:26PM (#29493094)
I know C and can get by in Rust and I disagree that rust is easier to follow. C is a simple language, the complexity comes from large systems, while Rust is just not.
Re:Rust support in the Linux kernel by nicoburns on Thursday December 09, 2021 @07:53AM (#29496795)
Well I know Rust and I can get by in C. Perhaps that makes a difference.

> C is a simple language, the complexity comes from large systems, while Rust is just not.

I mean I agree that C is simple if you're making a 50 line program that writes to stdout or something. But more often than not with C or Rust you are working with a large complex system. And I'd argue that when working with such a large system, Rust programs are less complex than C programs.

Re:Rust support in the Linux kernel by formerly_proven on Thursday December 09, 2021 @10:05AM (#29498104)
There is a huge difference between reading and writing C. C is very easy to read, but it's quite difficult to write (secure, portable, performant) C. Code is typically read a lot more than it is written. I haven't written a single line of code in torvalds/linux.git but read probably tens of thousands of lines of Linux kernel code over the years. I'd wager that for every kernel developer there are at least 10 people reading the code to figure out how something works, or how it broke.

C makes many questions when reading trivial to answer, questions like "how do I get here?", "where does it go?", "what is this type?" and "what does this code do?" are generally very easy to answer without expert-level C knowledge. From what I've seen, that's not true for rust.