Microsoft Engineer Sends Rust Linux Kernel Patches For In-Place Module Initialization

Written by Michael Larabel in Microsoft on 27 March 2024 at 06:52 AM EDT. 24 Comments
What a time we live in where Microsoft not only continues contributing significantly to the Linux kernel but doing so to further flesh out the design of the Linux kernel's Rust programming language support. A previously unimaginable combination of Microsoft, the Rust programming language, and the Linux kernel.

Microsoft engineer Wedson Almeida Filho has sent out the latest patches working on Allocation APIs for the Rust Linux kernel code and also in leveraging those proposed APIs a means of allowing in-place module initialization for Rust kernel modules. Wedson Almeida Filho has been a longtime Rust for Linux contributor going back to his Google engineering days and at Microsoft the past two years has shown no signs of slowing down on the Rust for Linux activities.

Rust for Linux logo

The second iteration of the Rust Allocation APIs for the Linux kernel:
We currently have a fork of the crate with changes to `Vec`; other changes have been upstreamed (to the Rust project). This series removes the fork and exposes all the functionality as extension traits.

Additionally, it also introduces allocation flag parameters to all functions that may result in allocations (e.g., `Box::new`, `Arc::new`, `Vec::push`, etc.) without the `try_` prefix -- the names are available because we build `alloc` with `no_global_oom_handling`.

Lastly, the series also removes our reliance on the `allocator_api` unstable feature.

Long term, we still want to make such functionality available in upstream Rust, but this allows us to make progress now and reduces our maintainance burden.

In summary:
1. Removes `alloc` fork
2. Removes use of `allocator_api` unstable feature
3. Introduces flags (e.g., GFP_KERNEL, GFP_ATOMIC) when allocating

And then building off the Allocation APIs work for Rust in the kernel, the Microsoft engineer sent out patches today as well for in-place module initialization of Rust kernel modules. Rather than modules needing to return an instance that is moved to its final memory location, the proposed patches allow modules to be initialized in-place:
"This allows us to have modules whose state hold objects that must be initialised inplace like locks. It also allows us to implement registrations (e.g., driver registration) inplace and have them similar to their C counterparts where no new allocations are needed."

The Rust for Linux kernel effort remains a very vibrant effort with a wide variety of organizations contributing, even Microsoft engineers.
Related News
About The Author
Michael Larabel

Michael Larabel is the principal author of and founded the site in 2004 with a focus on enriching the Linux hardware experience. Michael has written more than 20,000 articles covering the state of Linux hardware support, Linux performance, graphics drivers, and other topics. Michael is also the lead developer of the Phoronix Test Suite, Phoromatic, and automated benchmarking software. He can be followed via Twitter, LinkedIn, or contacted via

Popular News This Week