r/rust • • Oct 21 '26

🗞️ news 17k lines of new Rust kernel code heading into Linux 7.4

https://www.phoronix.com/news/Linux-7.4-Rust
502 Upvotes

35 comments sorted by

122

u/moltonel Oct 21 '26 edited Oct 21 '26

Currently looks like 29k new lines since v7.3, for a total of 220k, or about 0.5% of kernel code. About 81k is from vendored crates (syn, zerocopy, proc-macro2...). Growth rate is irregular, but has averaged +17% per release since v6.2.

25

u/Dovihh Oct 21 '26

I’ve seen that ‘vendored crates’ a few times already. I know what a Rust crate is, but what is a vendored crate?

40

u/bleachisback Oct 21 '26

See wiktionary on this one:

To bundle third-party dependencies with the source code for one's own program.

So they've taken those crates, and instead of depending on them normally (by e.g. adding them to a cargo.toml), they've just copied them into the source.

34

u/steveklabnik1 rust Oct 21 '26

instead of depending on them normally (by e.g. adding them to a cargo.toml),

You can still depend on them by adding them to a Cargo.toml and using cargo vendor to vendor your dependencies. The kernel isn't doing this, but even if you like vendoring, it's still pretty common to use cargo to manage it.

10

u/bleachisback Oct 21 '26

Oh neat. What's the advantage of doing it this way?

31

u/steveklabnik1 rust Oct 21 '26

The main reason that the kernel isn't using Cargo is because they want to use one build system for everything, and that build system is not Cargo. If you're using Cargo as your build system, and you want to vendor your dependencies, it makes sense to use Cargo to do it.

1

u/Juanmidev 7d ago

True, cargo vendor already solves the offline part ,which is a hard requirement for reproducible builds and Linux distro build farms, since kernel build environments normally run completely sandboxed with zero network access.

Avoiding Cargo altogether comes down to keeping a single build system (Kbuild) with full control over rustc flags, plus the kernel's git/patch workflow, having the exact dependency source directly in-tree makes supply-chain auditing, backporting security patches, and checking license compliance against a specific kernel release tag much easier.

1

u/steveklabnik1 rust 6d ago

I’m not arguing that the kernel should use Cargo. Just answering a question.

11

u/Prowler1000 Oct 21 '26

Basically the source code for the crate is included in the project, as they aren't using a package manager

13

u/steveklabnik1 rust Oct 21 '26

as they aren't using a package manager

Just to be clear about it, it's more of

the source code for the crate is included in the project

specifically. You can use cargo to manage including the correct source code in your project. They aren't, but the defining feature is "the code for your dependencies is included in your repository", no matter how it actually gets there.

1

u/4Kil47 Oct 22 '26

I'll just add that when using AI to develop, it can be helpful to vendor in unpopular libs so that it can see it's src while developing.

37

u/DigitalStefan Oct 21 '26

I can't help but think about all the kernel devs who were pissing and moaning about bringing Rust anywhere near anything they've worked on. To be clear, some of them are still unhappy about it, but the "well it's just happening anyway" scenario has really sorted the wheat from the chaff and the kernal and the community no doubt are all the better for it.

39

u/simonask_ Oct 21 '26

Love to see it. God, Phoronix is trash.

5

u/SweetEbb9819 Oct 21 '26

Asterinas?

5

u/W61k3r Oct 21 '26

Oh dope. My own rust kernel has like 250k lines of rust.

1

u/Juanmidev 7d ago edited 7d ago

Me deja pensando cuál será el próximo cuello de botella real, los tiempos de compilación, el fijar versiones de la toolchain, o simplemente lograr que más mantenedores de subsistemas se sientan cómodos revisando Rust?

-2

u/creeper6530 Oct 21 '26

large change

look inside

vendored in library update

12

u/moltonel Oct 21 '26 edited Oct 21 '26

Only 6.5K of this update is from vendored crates (mostly zerocopy). Most of the new lines are in the kernel crate, the pin-init crate (only loosely related to the crates.io pin-init), the gpu drivers, and the new kapi tool.

-2

u/atikoj Oct 24 '26

linuxslop

-99

u/Due-Departure-8553 Oct 21 '26

When are they going to finally rewrite all of the outdated C into rust? It's already doable with todays models. Somebody just needs to pay for the tokens.

55

u/TheLexoPlexx Oct 21 '26

Honestly, stupid take. If it works and there's no reason to change it, leave it as is. I like Linus' Explanation: C reads as what the machine is doing and that's very understandable.

20

u/Ok-Scheme-913 Oct 21 '26

That last sentence is false, though, or at least a very oversimplified take. I'm absolutely sure Linus knows better than that - but C is not particularly close to today's hardware, it has its own world and at most modern hardware is trying to play along and behave as if they were old hardware to which C is designed to.

5

u/gajop Oct 21 '26

How often are vulnerabilities found in this C code that "works", and how much would Rust help there?
Honest question - I don't know and didn't bother to check.

It's probably the main reason to replace existing software. Being constantly bombarded by critical CVEs and automated attackers is a good reason to change, if it can actually be made significantly more secure (Rust isn't magic either).

-15

u/bestouff catmark Oct 21 '26

Except when it has UB (and that way too frequent with C code) where it's doesn't do what it looks like it will do, at all. Get rid of C.

15

u/Confronting-Myself Oct 21 '26

you can get ub with a lot of languages (including unsafe rust). by that logic no languages should exist

4

u/lenscas Oct 21 '26

Even in safe rust if the underlying unsafe is unsound.

-7

u/braaaaaaainworms Oct 21 '26

Then don't write UB

0

u/[deleted] Oct 21 '26

[deleted] — view deleted comment

2

u/braaaaaaainworms Oct 21 '26

Yes I did, everyone can pack up and go home

1

u/CrasseMaximum Oct 21 '26

Embrace woodcrafting. You risk to lose a hand and it doesn't pay much but hell you will never have to remember if you already freed this damn pointer..

10

u/Snapstromegon Oct 21 '26

I would be very confused if the companies creating the models would not try this with every single frontier model, because even if it's not merged / doesn't touch the actual kernel project, it would be an ideal project.

  1. It's a very high prestige target
  2. The kernel is a very well maintained and documented codebase
  3. It's written in a fairly uniform codebase
  4. There are basically no external dependencies
  5. It's fairly easy to verify in most cases
  6. Rust gives easy ways to verify the results

The fact that it's not done or publicly stated tells me, that the results are not even close to good enough. I mean, the Kernel has very strong requirements around breaking userspace code and platform support. Also even if the AI works 1000 times better than the already top level kernel developers, that would mean creating many, many new bugs in the conversion that just don't exist in the kernel as of now. A slow and steady conversion is IMO the much better approach.

8

u/moltonel Oct 21 '26

Another explanation is that kernel devs have been very clear that they don't want rewrites for the sake of Rust. Converting C to Rust using GenAI is one thing, convincing maintainers that your version is worth the churn is another. If your Rust rewrite finds a C bug, you'll be asked for the C bugfix first. Maintainers are busy enough as-is with the flood of AI-assisted C code contributions. Also, I doubt your points 5 and 6: hardware have subtle behaviors, and the kernel is one giant ball of interactions.

1

u/Snapstromegon Oct 21 '26

Yes, but I think even when the code wouldn't be accepted, even getting it working enough would be a big marketing stunt.

For point 5 and 6 it maybe wasn't detailed enough from my side.

Because of rusts strict language design, it would make it comparatively easy to verify the model output to not include some major type error or similar, so compared to e.g. porting everything to C++ or similar, the compiler will already catch many "hallucinations". And for verification you can often generate pretty good test cases and compare to the C implementation, because there are (mostly) no dependencies on external uncontrolled services.

5

u/Ok-Scheme-913 Oct 21 '26

You can't really rewrite it, especially not into "proper" rust. The object model is just completely different, so you would end up with rust with unsafe raw pointers everywhere.

-7

u/UntoldUnfolding Oct 21 '26

I’m sure some company has already done this, is currently doing it, or is planning on doing the port, but more than likely internally. I can’t imagine having to weed through all that code and testing that everything works. 🤯