TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Linux kernel drivers in Rust might become an option in the future

372 pointsby jobstijlover 5 years ago

22 comments

geofftover 5 years ago
We&#x27;re working on it: <a href="https:&#x2F;&#x2F;github.com&#x2F;fishinabarrel&#x2F;linux-kernel-module-rust" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;fishinabarrel&#x2F;linux-kernel-module-rust</a><p>Check out the demo in PR #122, which lets you create three boolean sysctls and a character device that prints the state of those sysctls in JSON (using serde).<p>We gave a talk about it last week at Linux Security Summit, I&#x27;ll submit it once the recording is up :) Slides are at <a href="https:&#x2F;&#x2F;ldpreload.com&#x2F;p&#x2F;kernel-modules-in-rust-lssna2019.pdf" rel="nofollow">https:&#x2F;&#x2F;ldpreload.com&#x2F;p&#x2F;kernel-modules-in-rust-lssna2019.pdf</a> .
评论 #20836813 未加载
评论 #20836750 未加载
评论 #20846545 未加载
评论 #20839707 未加载
kev009over 5 years ago
Johannes Lundberg wrote a thesis on doing this with FreeBSD and has a framework <a href="https:&#x2F;&#x2F;github.com&#x2F;johalun&#x2F;rustkpi" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;johalun&#x2F;rustkpi</a><p><a href="https:&#x2F;&#x2F;kth.diva-portal.org&#x2F;smash&#x2F;get&#x2F;diva2:1238890&#x2F;FULLTEXT01.pdf%EF%BB%BF" rel="nofollow">https:&#x2F;&#x2F;kth.diva-portal.org&#x2F;smash&#x2F;get&#x2F;diva2:1238890&#x2F;FULLTEXT...</a>
ufmaceover 5 years ago
Sounds like the start of something good. Though the comments feel a bit weird. Maybe it&#x27;s just a strange day for some reason, but I feel like today, I&#x27;ve seen an awful lot of comments from people pushing rewriting things in Rust who know absolutely nothing about the code they&#x27;re asking about or the problem domain it runs in.<p>I mean, I personally think Rust is cool and all that, but come on, who does that?
评论 #20835998 未加载
评论 #20836236 未加载
评论 #20835717 未加载
评论 #20836189 未加载
评论 #20835958 未加载
评论 #20836456 未加载
评论 #20835956 未加载
ajxsover 5 years ago
If I recall correctly, Torvalds already addressed the hype around this ( totally not new ) idea by pointing out that memory errors really make up only tiny part of the intricacies of building a kernel. This idea predates Rust, and for better or worse will probably outlive it.
评论 #20837168 未加载
megousover 5 years ago
Yeah, I would not like this becomming required. Now, it&#x27;s still fairly manageable to keep developing and building my own kernels. You need binutils&#x2F;gcc for your host platforms, and that&#x27;s about all. And I have 3 architectures I build for.<p>If I also need clang and rust for all the platforms, and learn rust, for some questionable benefits... That would make things hard.
评论 #20837742 未加载
vardumpover 5 years ago
I think we should just evaluate Rust based on its merits. Ignore fanboys and ignore the opposite as well.<p>In other words, Rust is just another tool. Regard it as one without subjective emotions either way. Be constructive, don&#x27;t only look for faults, but also ways how to overcome them. But don&#x27;t close your eyes from them either. Acknowledging weaknesses is the first step to improvement.<p>Some possible questions and measures to consider below. I&#x27;m sure there&#x27;s a lot more to add on this list.<p>1) Stability. Other than for development, unstable kernels are a no go. Can possible negative effects be mitigated?<p>2) Security is often what Rust is expected to bring on the table. So is Rust actually more secure in the environment kernel requires? This could be tested by &quot;clean-room&quot; reimplementing something that is historically known to have many security issues.<p>3) Are there showstoppers for kernel builds? Interoperability, build performance, architectures unsupported by Rust, etc. If so, could these be mitigated? Conversely, is there something positive Rust could provide?<p>4) How does it affect runtime performance? Average case. Bloat issues? Any pathologic cases? Any benefits?<p>5) What other unexpected it brings on the plate? Both benefits and disadvantages. For example, could Rust types also be used to catch errors other than memory related, like invalid states?<p>6) &lt;Your consideration here or above&gt;
评论 #20838975 未加载
评论 #20842547 未加载
评论 #20837342 未加载
评论 #20837411 未加载
评论 #20839812 未加载
评论 #20837396 未加载
评论 #20839661 未加载
评论 #20837607 未加载
abcdabcd987over 5 years ago
Check out the HotOS&#x27;19 paper from our lab :) <a href="https:&#x2F;&#x2F;danyangzhuo.com&#x2F;papers&#x2F;HotOS19-Stone.pdf" rel="nofollow">https:&#x2F;&#x2F;danyangzhuo.com&#x2F;papers&#x2F;HotOS19-Stone.pdf</a>
michaelangermanover 5 years ago
Some important links that motivated this story...<p><a href="https:&#x2F;&#x2F;hub.packtpub.com&#x2F;rust-is-the-future-of-systems-programming-c-is-the-new-assembly-intel-principal-engineer-josh-triplett&#x2F;" rel="nofollow">https:&#x2F;&#x2F;hub.packtpub.com&#x2F;rust-is-the-future-of-systems-progr...</a><p><a href="https:&#x2F;&#x2F;lwn.net&#x2F;Articles&#x2F;797558&#x2F;" rel="nofollow">https:&#x2F;&#x2F;lwn.net&#x2F;Articles&#x2F;797558&#x2F;</a>
acdover 5 years ago
Could we have universal standardized hardware interfaces for basic functionality of hardware devices? For example at least get the same programming interface for basic functionality of Wifi chips. Then one could have more accelerated drivers which makes use of all the specific hardware features of chips.<p>Network chips has started to offer a common programming api as far as I understand Switch Abstraction Interface (SAI). Could one do this for more different than network hardware classes?
nindalfover 5 years ago
Existing languages in the Linux kernel - <a href="https:&#x2F;&#x2F;www.openhub.net&#x2F;p&#x2F;linux&#x2F;analyses&#x2F;latest&#x2F;languages_summary" rel="nofollow">https:&#x2F;&#x2F;www.openhub.net&#x2F;p&#x2F;linux&#x2F;analyses&#x2F;latest&#x2F;languages_su...</a><p>Unsurprisingly it&#x27;s mostly C (95.6%) with a bit of C++ (2%) and Assembly (1.6%) and tiny bits of make (0.2%), shell scripts (0.3%), Python (0.1% and Perl (0.2%). I&#x27;d guess it&#x27;d be at least half a decade before Rust cracks 1% here.
评论 #20837483 未加载
评论 #20837530 未加载
w8rbtover 5 years ago
I think setuid executables would be a good place for rust or go, but I have reservations about the kernel itself.
jjthebluntover 5 years ago
Genuine question: who restricts the sourcecode language in which a kernel driver is written?<p>I&#x27;m thinking machine opcodes in a .o file, to be linked wherever, are only of a concern if they&#x27;re doing function call linkages (and maybe kernel space vs user space transition bookkeeping) improperly?
zellyover 5 years ago
C++ written with -pedantic -Wall, smart pointers, and clang static analysis tools, ASan, valgrind, etc. enabled is just as safe as Rust. Change my mind.
评论 #20872662 未加载
评论 #20854521 未加载
评论 #20855717 未加载
stef-13013over 5 years ago
Did you talk about that to Linus :):) ?
non-entityover 5 years ago
I have Rust on a long backlist of things to check out, but the idea of writing kernel drivers in something other than C is interesting to say the least.
knownover 5 years ago
Give it as an exercise to college grads
jstewartmobileover 5 years ago
This is running MO for comp sci: adding loads of complexity for a minor gain.<p>Compile-time borrow-checking works for self-contained applications--the compiler has a complete picture of what&#x27;s going on. Move that model inside kernel space--where blobs are being mutated across separately compiled modules, different chipsets (CPU&#x2F;DMA&#x2F;GPU), sometimes even in parallel--might as well wrap the whole thing in a big `unsafe` block.<p>Somebody&#x27;s going to say &quot;<i>Oh, you&#x27;re exaggerating. It&#x27;s not that bad in Redox.</i>&quot; Redox doesn&#x27;t have to integrate with 28 years of kernel written in C.
评论 #20838806 未加载
agumonkeyover 5 years ago
Pardon the slightly fanboyish comment, but I fail to remember a single negative response regarding Rust. Considering its domain I&#x27;m more than impressed.
评论 #20836819 未加载
评论 #20837225 未加载
评论 #20836677 未加载
评论 #20836612 未加载
评论 #20838301 未加载
youdontknowthoover 5 years ago
Looking forward to enough Rust adoption that people stop seeing it as a magic bullet. Once it&#x27;s in large scale use and there are still errors that lead to security problems maybe people will get over themselves.
评论 #20838164 未加载
评论 #20839855 未加载
std_throwawayover 5 years ago
Wouldn&#x27;t modern C++ be better suited than Rust because it&#x27;s closer to C?<p>I know that old C++ got some bad reputation in the past but I think it&#x27;s time to reconsider that with the changes that started with C++11. The only area where Rust really is better is the management of lifetimes and its associated higher memory safety.
评论 #20836500 未加载
评论 #20837606 未加载
评论 #20836499 未加载
评论 #20836504 未加载
reacwebover 5 years ago
At the beginning, C was a handy language with some traps and pitfalls. Thanks to standardization committees and insane optimizers, it has become a minefield of undefined behaviors and security issues. Linux is coded in C because of the &quot;C is the desert island language&quot;. This should change and I dream to see something that will replace C at least in the kernel.
shmerlover 5 years ago
Nice development! Would be interesting to see something like amdgpu rewritten in Rust.
评论 #20836463 未加载
评论 #20837202 未加载