| 309e4903 | 04-Dec-2025 |
Miguel Ojeda <ojeda@kernel.org> |
rust: sync: atomic: separate import "blocks"
Commit 14e9a18b07ec ("rust: sync: atomic: Make Atomic*Ops pub(crate)") added a `pub(crate)` import in the same "block" as the `pub` one, without running
rust: sync: atomic: separate import "blocks"
Commit 14e9a18b07ec ("rust: sync: atomic: Make Atomic*Ops pub(crate)") added a `pub(crate)` import in the same "block" as the `pub` one, without running `rustfmt`, which would sort them differently.
Instead of running `rustfmt` as-is, add a newline to keep the import "blocks" with different visibilities separate.
Signed-off-by: Miguel Ojeda <ojeda@kernel.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
show more ...
|
| 013f912e | 22-Oct-2025 |
Boqun Feng <boqun.feng@gmail.com> |
rust: sync: atomic: Implement Debug for Atomic<Debug>
If `Atomic<T>` is `Debug` then it's a `debugfs::Writer`, therefore make it so since 1) debugfs needs to support `Atomic<T>` and 2) it's rather t
rust: sync: atomic: Implement Debug for Atomic<Debug>
If `Atomic<T>` is `Debug` then it's a `debugfs::Writer`, therefore make it so since 1) debugfs needs to support `Atomic<T>` and 2) it's rather trivial to implement `Debug` for `Atomic<Debug>`.
Tested-by: David Gow <davidgow@google.com> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Boqun Feng <boqun.feng@gmail.com> Link: https://patch.msgid.link/20251022035324.70785-3-boqun.feng@gmail.com
show more ...
|
| 66f1ea83 | 19-Sep-2025 |
Daniel Almeida <daniel.almeida@collabora.com> |
rust: lock: Add a Pin<&mut T> accessor
In order for callers to be able to access the inner T safely if T: !Unpin, there needs to be a way to get a Pin<&mut T>. Add this accessor and a corresponding
rust: lock: Add a Pin<&mut T> accessor
In order for callers to be able to access the inner T safely if T: !Unpin, there needs to be a way to get a Pin<&mut T>. Add this accessor and a corresponding example to tell users how it works.
This requires the pin projection functionality [1] for better ergonomic.
[boqun: Apply Daniel's fix to the code example, add the reference to pin projection patch and remove out-of-date part in the commit log]
Suggested-by: Benno Lossin <lossin@kernel.org> Suggested-by: Boqun Feng <boqun.feng@gmail.com> Signed-off-by: Daniel Almeida <daniel.almeida@collabora.com> Signed-off-by: Boqun Feng <boqun.feng@gmail.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Benno Lossin <lossin@kernel.org> Link: https://github.com/Rust-for-Linux/linux/issues/1181 Link: https://lore.kernel.org/rust-for-linux/20250912174148.373530-1-lossin@kernel.org/ [1]
show more ...
|
| 2497a711 | 19-Sep-2025 |
Daniel Almeida <daniel.almeida@collabora.com> |
rust: lock: Pin the inner data
In preparation to support Lock<T> where T is pinned, the first thing that needs to be done is to structurally pin the 'data' member. This switches the 't' parameter in
rust: lock: Pin the inner data
In preparation to support Lock<T> where T is pinned, the first thing that needs to be done is to structurally pin the 'data' member. This switches the 't' parameter in Lock<T>::new() to take in an impl PinInit<T> instead of a plain T. This in turn uses the blanket implementation "impl PinInit<T> for T".
Subsequent patches will touch on Guard<T>.
Suggested-by: Benno Lossin <lossin@kernel.org> Suggested-by: Boqun Feng <boqun.feng@gmail.com> Signed-off-by: Daniel Almeida <daniel.almeida@collabora.com> Signed-off-by: Boqun Feng <boqun.feng@gmail.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Benno Lossin <lossin@kernel.org> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Link: https://github.com/Rust-for-Linux/linux/issues/1181
show more ...
|
| a307bf1d | 05-Sep-2025 |
Gary Guo <gary@garyguo.net> |
rust: block: convert `block::mq` to use `Refcount`
Currently there's a custom reference counting in `block::mq`, which uses `AtomicU64` Rust atomics, and this type doesn't exist on some 32-bit archi
rust: block: convert `block::mq` to use `Refcount`
Currently there's a custom reference counting in `block::mq`, which uses `AtomicU64` Rust atomics, and this type doesn't exist on some 32-bit architectures. We cannot just change it to use 32-bit atomics, because doing so will make it vulnerable to refcount overflow. So switch it to use the kernel refcount `kernel::sync::Refcount` instead.
There is an operation needed by `block::mq`, atomically decreasing refcount from 2 to 0, which is not available through refcount.h, so I exposed `Refcount::as_atomic` which allows accessing the refcount directly.
[boqun: Adopt the LKMM atomic API] Signed-off-by: Gary Guo <gary@garyguo.net> Signed-off-by: Boqun Feng <boqun.feng@gmail.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Benno Lossin <lossin@kernel.org> Reviewed-by: Elle Rhumsaa <elle@weathered-steel.dev> Acked-by: Andreas Hindborg <a.hindborg@kernel.org> Tested-by: David Gow <davidgow@google.com> Link: https://lore.kernel.org/r/20250723233312.3304339-5-gary@kernel.org
show more ...
|
| 076acb64 | 05-Sep-2025 |
Gary Guo <gary@garyguo.net> |
rust: convert `Arc` to use `Refcount`
With `Refcount` type created, `Arc` can use `Refcount` instead of calling into FFI directly.
Signed-off-by: Gary Guo <gary@garyguo.net> Signed-off-by: Boqun Fe
rust: convert `Arc` to use `Refcount`
With `Refcount` type created, `Arc` can use `Refcount` instead of calling into FFI directly.
Signed-off-by: Gary Guo <gary@garyguo.net> Signed-off-by: Boqun Feng <boqun.feng@gmail.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Alexandre Courbot <acourbot@nvidia.com> Reviewed-by: Benno Lossin <lossin@kernel.org> Reviewed-by: Elle Rhumsaa <elle@weathered-steel.dev> Link: https://lore.kernel.org/r/20250723233312.3304339-4-gary@kernel.org
show more ...
|
| 7487645f | 05-Sep-2025 |
Gary Guo <gary@garyguo.net> |
rust: make `Arc::into_unique_or_drop` associated function
Make `Arc::into_unique_or_drop` to become a mere associated function instead of a method (i.e. removing the `self` receiver).
It's a genera
rust: make `Arc::into_unique_or_drop` associated function
Make `Arc::into_unique_or_drop` to become a mere associated function instead of a method (i.e. removing the `self` receiver).
It's a general convention for Rust smart pointers to avoid having methods defined on them, because if the pointee type has a method of the same name, then it is shadowed. This is normally for avoiding semver breakage, which isn't an issue for kernel codebase, but it's still generally a good practice to follow this rule, so that `ptr.foo()` would always be calling a method on the pointee type.
Signed-off-by: Gary Guo <gary@garyguo.net> Signed-off-by: Boqun Feng <boqun.feng@gmail.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Benno Lossin <lossin@kernel.org> Reviewed-by: Alexandre Courbot <acourbot@nvidia.com> Reviewed-by: Elle Rhumsaa <elle@weathered-steel.dev> Link: https://lore.kernel.org/r/20250723233312.3304339-3-gary@kernel.org
show more ...
|
| bb38f35b | 05-Sep-2025 |
Gary Guo <gary@garyguo.net> |
rust: implement `kernel::sync::Refcount`
This is a wrapping layer of `include/linux/refcount.h`. Currently the kernel refcount has already been used in `Arc`, however it calls into FFI directly.
[b
rust: implement `kernel::sync::Refcount`
This is a wrapping layer of `include/linux/refcount.h`. Currently the kernel refcount has already been used in `Arc`, however it calls into FFI directly.
[boqun: Add the missing <> for the link in comment] Signed-off-by: Gary Guo <gary@garyguo.net> Signed-off-by: Boqun Feng <boqun.feng@gmail.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Boqun Feng <boqun.feng@gmail.com> Reviewed-by: Fiona Behrens <me@kloenk.dev> Reviewed-by: Benno Lossin <lossin@kernel.org> Reviewed-by: Elle Rhumsaa <elle@weathered-steel.dev> Link: https://lore.kernel.org/r/20250723233312.3304339-2-gary@kernel.org
show more ...
|
| d9ea5a41 | 05-Sep-2025 |
Boqun Feng <boqun.feng@gmail.com> |
rust: sync: Add memory barriers
Memory barriers are building blocks for concurrent code, hence provide a minimal set of them.
The compiler barrier, barrier(), is implemented in inline asm instead o
rust: sync: Add memory barriers
Memory barriers are building blocks for concurrent code, hence provide a minimal set of them.
The compiler barrier, barrier(), is implemented in inline asm instead of using core::sync::atomic::compiler_fence() because memory models are different: kernel's atomics are implemented in inline asm therefore the compiler barrier should be implemented in inline asm as well. Also it's currently only public to the kernel crate until there's a reasonable driver usage.
Signed-off-by: Boqun Feng <boqun.feng@gmail.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Elle Rhumsaa <elle@weathered-steel.dev> Link: https://lore.kernel.org/all/20250719030827.61357-10-boqun.feng@gmail.com/
show more ...
|
| 84c6d36b | 05-Sep-2025 |
Boqun Feng <boqun.feng@gmail.com> |
rust: sync: atomic: Add Atomic<{usize,isize}>
Add generic atomic support for `usize` and `isize`. Note that instead of mapping directly to `atomic_long_t`, the represention type (`AtomicType::Repr`)
rust: sync: atomic: Add Atomic<{usize,isize}>
Add generic atomic support for `usize` and `isize`. Note that instead of mapping directly to `atomic_long_t`, the represention type (`AtomicType::Repr`) is selected based on CONFIG_64BIT. This reduces the necessity of creating `atomic_long_*` helpers, which could save the binary size of kernel if inline helpers are not available. To do so, an internal type `isize_atomic_repr` is defined, it's `i32` in 32bit kernel and `i64` in 64bit kernel.
Signed-off-by: Boqun Feng <boqun.feng@gmail.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Andreas Hindborg <a.hindborg@kernel.org> Reviewed-by: Benno Lossin <lossin@kernel.org> Reviewed-by: Elle Rhumsaa <elle@weathered-steel.dev> Link: https://lore.kernel.org/all/20250719030827.61357-9-boqun.feng@gmail.com/
show more ...
|
| d6df37ba | 05-Sep-2025 |
Boqun Feng <boqun.feng@gmail.com> |
rust: sync: atomic: Add Atomic<u{32,64}>
Add generic atomic support for basic unsigned types that have an `AtomicImpl` with the same size and alignment.
Unit tests are added including Atomic<i32> a
rust: sync: atomic: Add Atomic<u{32,64}>
Add generic atomic support for basic unsigned types that have an `AtomicImpl` with the same size and alignment.
Unit tests are added including Atomic<i32> and Atomic<i64>.
Signed-off-by: Boqun Feng <boqun.feng@gmail.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Andreas Hindborg <a.hindborg@kernel.org> Reviewed-by: Benno Lossin <lossin@kernel.org> Reviewed-by: Elle Rhumsaa <elle@weathered-steel.dev> Link: https://lore.kernel.org/all/20250719030827.61357-8-boqun.feng@gmail.com/
show more ...
|
| d1320543 | 05-Sep-2025 |
Boqun Feng <boqun.feng@gmail.com> |
rust: sync: atomic: Add the framework of arithmetic operations
One important set of atomic operations is the arithmetic operations, i.e. add(), sub(), fetch_add(), add_return(), etc. However it may
rust: sync: atomic: Add the framework of arithmetic operations
One important set of atomic operations is the arithmetic operations, i.e. add(), sub(), fetch_add(), add_return(), etc. However it may not make senses for all the types that `AtomicType` to have arithmetic operations, for example a `Foo(u32)` may not have a reasonable add() or sub(), plus subword types (`u8` and `u16`) currently don't have atomic arithmetic operations even on C side and might not have them in the future in Rust (because they are usually suboptimal on a few architecures). Therefore the plan is to add a few subtraits of `AtomicType` describing which types have and can do atomic arithemtic operations.
One trait `AtomicAdd` is added, and only add() and fetch_add() are added. The rest will be added in the future.
Signed-off-by: Boqun Feng <boqun.feng@gmail.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Benno Lossin <lossin@kernel.org> Reviewed-by: Elle Rhumsaa <elle@weathered-steel.dev> Link: https://lore.kernel.org/all/20250719030827.61357-7-boqun.feng@gmail.com/
show more ...
|
| b606a532 | 05-Sep-2025 |
Boqun Feng <boqun.feng@gmail.com> |
rust: sync: atomic: Add atomic {cmp,}xchg operations
xchg() and cmpxchg() are basic operations on atomic. Provide these based on C APIs.
Note that cmpxchg() use the similar function signature as co
rust: sync: atomic: Add atomic {cmp,}xchg operations
xchg() and cmpxchg() are basic operations on atomic. Provide these based on C APIs.
Note that cmpxchg() use the similar function signature as compare_exchange() in Rust std: returning a `Result`, `Ok(old)` means the operation succeeds and `Err(old)` means the operation fails.
Signed-off-by: Boqun Feng <boqun.feng@gmail.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Benno Lossin <lossin@kernel.org> Reviewed-by: Elle Rhumsaa <elle@weathered-steel.dev> Link: https://lore.kernel.org/all/20250719030827.61357-6-boqun.feng@gmail.com/
show more ...
|
| 29c32c40 | 05-Sep-2025 |
Boqun Feng <boqun.feng@gmail.com> |
rust: sync: atomic: Add generic atomics
To provide using LKMM atomics for Rust code, a generic `Atomic<T>` is added, currently `T` needs to be Send + Copy because these are the straightforward usage
rust: sync: atomic: Add generic atomics
To provide using LKMM atomics for Rust code, a generic `Atomic<T>` is added, currently `T` needs to be Send + Copy because these are the straightforward usages and all basic types support this.
Implement `AtomicType` for `i32` and `i64`, and so far only basic operations load() and store() are introduced.
Signed-off-by: Boqun Feng <boqun.feng@gmail.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Benno Lossin <lossin@kernel.org> Reviewed-by: Elle Rhumsaa <elle@weathered-steel.dev> Link: https://lore.kernel.org/all/20250719030827.61357-5-boqun.feng@gmail.com/
show more ...
|
| b638c9bc | 05-Sep-2025 |
Boqun Feng <boqun.feng@gmail.com> |
rust: sync: atomic: Add ordering annotation types
Preparation for atomic primitives. Instead of a suffix like _acquire, a method parameter along with the corresponding generic parameter will be used
rust: sync: atomic: Add ordering annotation types
Preparation for atomic primitives. Instead of a suffix like _acquire, a method parameter along with the corresponding generic parameter will be used to specify the ordering of an atomic operations. For example, atomic load() can be defined as:
impl<T: ...> Atomic<T> { pub fn load<O: AcquireOrRelaxed>(&self, _o: O) -> T { ... } }
and acquire users would do:
let r = x.load(Acquire);
relaxed users:
let r = x.load(Relaxed);
doing the following:
let r = x.load(Release);
will cause a compiler error.
Compared to suffixes, it's easier to tell what ordering variants an operation has, and it also make it easier to unify the implementation of all ordering variants in one method via generic. The `TYPE` associate const is for generic function to pick up the particular implementation specified by an ordering annotation.
Signed-off-by: Boqun Feng <boqun.feng@gmail.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Benno Lossin <lossin@kernel.org> Reviewed-by: Elle Rhumsaa <elle@weathered-steel.dev> Link: https://lore.kernel.org/all/20250719030827.61357-4-boqun.feng@gmail.com/
show more ...
|