Rust-for-Linux / linux

Adding support for the Rust language to the Linux kernel.
https://rust-for-linux.com
Other
3.95k stars 421 forks source link

Memory ordering model policy/plan #1067

Open fbq opened 7 months ago

fbq commented 7 months ago

Background: In Linux kernel, we have Linux Kernel Memory (Consistency) Model, or LKMM for short, which provides a set of atomic primitives and a (somewhat) formal model to describe their semantics. And there are couples of differences between LKMM and Rust's memory model. So when Rust comes into the picture of Linux kernel development, one thing we need to deal with is which memory model to use.

I'd like to propose that we have a place where we can document/track our current "policy" and any future plan for memory ordering models (including synchronization primitives and program-preserved ordering) used in Rust-for-Linux. Eventually, we will have in-kernel documentation for this, but let's use this issue to get things clarified in early stages.

I had a few discussions. And based on the discussions, below is the best option to start with in my opinion:

Couples of reasons here (I will provide some summary about the previous discussion in this issue in the form of comments as well):

I'm going to prepare a patchset to add initial documentation of the memory model policy and implementation of atomic APIs. Happy to hear any feedback, and tests and reviews in the future are welcome!

fbq commented 7 months ago

Here is the branch with some atomics implemented: https://github.com/fbq/linux/tree/dev/rust/atomic

ojeda commented 5 months ago

2024-03-22 23:38 [WIP 0/3] Memory model and atomic API in Rust: