=== Kernel Rust Support Links: + link:https://github.com/ayrtonm/freebsd-kpi-rs[rust KPI repository] URL: link:https://github.com/ayrtonm/freebsd-kpi-rs[] + link:https://github.com/ayrtonm/freebsd-src/tree/virtio_snd[virtio sound rust driver] URL: link:https://github.com/ayrtonm/freebsd-src/tree/virtio_snd[] Contact: Ayrton Muñoz I have been adding support for using rust in the kernel and writing device drivers with it. Rust is a good tool for taking existing rules about how pointers may be used and enforcing them with the type system. These rules are often implicit in C meaning additional mental bookkeeping for developers. Rust will not prevent every bug, but it lets developers avoid some of this and focus more on implementing the functionality they care about. The rust KPIs are currently under development and not very stable, but there is no dependency on the wider rust ecosystem or unstable language features/APIs. This means that they should eventually be able to provide as much stability as equivalent C KPIs and upgrading to newer rust toolchains should not introduce breakage. It also provides as much transparency as C about when allocations happen since it uses a non-allocating subset of the link:https://doc.rust-lang.org/core/[rust standard library]. Different kernel subsystems will require rust wrappers, but these can build off of the base functionality provided in the rust KPI repository. I have been experimenting on and off with this since late 2024 and development mainly happens in my rust KPI repository. This repository also has makefiles and patches for man:config[8]/build system integration. The easiest driver for developers to build and try themselves is my link:https://github.com/ayrtonm/freebsd-src/tree/virtio_snd[virtio sound driver]. Some interfaces it uses are in flux, but the driver is functional enough for music playback in link:https://www.qemu.org/docs/master/system/devices/virtio/virtio-snd.html[QEMU]. That branch also includes rust wrappers that may be reused for other virtio devices or sound/PCM drivers. Only x86-64 and aarch64 are currently supported. Other architectures supported by LLVM can be added if there is interest, but I wanted to initially focus on just a few use-cases. Aside from QEMU I have also been testing rust drivers on hardware with some drivers for link:https://github.com/ayrtonm/freebsd-src/tree/apple[ARM64 Apple machines]. This was the initial use-case and involves taking some WIP drivers I started helping with in 2024 and porting the greenfield parts to rust. This is mostly low-level drivers, but also includes the DockChannel HID driver for the keyboard on the M2 MacBook. At some point in early 2026 the rust KPIs should be stable enough for interested developers to try writing new code with them. They will not be perfect, but I want to make sure they work roughly like existing drivers expect and also fit the expectations of rust developers before asking for testers. Hopefully the Apple drivers will be back up to parity with the initial WIP in C in the first half of 2026 as well.