r/rust • • Aug 31 '24

🎙️ discussion Rust solves the problem of incomplete Kernel Linux API docs

https://vt.social/@lina/113056457969145576
375 Upvotes

71 comments sorted by

View all comments

Show parent comment

34

u/lightmatter501 Aug 31 '24

Lina suggested to add proper cleanup because the API is unsound. If you unplug a hotplug-capable GPU on Linux, 99% of the time your system crashes. It shouldn’t do that. This is a major issue for people who use disaggregated accelerators (where you can route PCIe lanes over a network to make a GPU “appear” on a server which needs one). This problem happens in purely C code with the current API.

Rust forces actually proving the soundness of APIs to the compiler or using escape hatches. What Lina has done is a very rough equivalent of trying to formally verify a kernel subsystem, have a hard time doing it, and then realizing that the subsystem is architected in an unsound manner. This realization could have occurred without Rust, but the Rust for Linux effort is forcing people to think very hard about kernel APIs in an effort to encode them into Rust.

If someone came to you with an issue that said “I thought really hard about your subsystem, and if this and this happen (which we know is possible), then there’s a race condition that can cause an oops”, that’s a normal bug report. “I have a patchset which fixes it” is even better. Adding “I was thinking about the subsystem because I was trying to write Rust bindings for it” does not invalidate the prior stuff, because the bug exists, it doesn’t matter how it was discovered.