Re: [TECH TOPIC] Rust for Linux

Miguel Ojeda
2021-07-06T19:43:26Z

On Tue, Jul 6, 2021 at 9:13 PM Johannes Berg <johannes@sipsolutions.net> wrote:
>
> I couldn't really find a good place too hang this question, so it's here
> now ;-)
>
> Mostly from what I've seen you've been talking about rust being the
> 'leaves' in the graph, in the sense that it consumes C APIs exposed by
> the kernel elsewhere, etc. In drivers using things, for example.

Almost! Ideally, Rust modules should consume Rust APIs, not C APIs.
Please see the other responses on the "leaf" modules I just sent and
what the "Rust abstractions" are all about.

> How about the other way around? What if we'd want to slowly replace
> (parts of) a subsystem with rust code, but leave drivers? Or let's say
> write some data structures in rust because of the stated benefits, but
> let C consumers exist?

This is definitely possible too, and I would love if that happens.
However, note two points:

- It would only net you advantages inside your implementation and
for Rust modules (both are of course important), but not on the C
drivers, of course, because you cannot expose Rust features back to C
(such as the ability to describe what is safe and what is not, types
that guarantee certain invariants, etc.).

- Currently there is no GCC codegen path for the Rust side -- so
your subsystem would not work in all architectures until
`rustc_codegen_gcc` or GCC Rust are mature enough. The former may be
ready sooner than we expect. The latter will take longer -- I was told
about 2 years for kernel compilation purposes.

Cheers,
Miguel