| e74b7a3f | 17-Apr-2026 |
Yury Norov <ynorov@nvidia.com> |
rust: tests: add Kconfig for KUnit test
There are 6 individual Rust KUnit test suites (plus the doctests one). All the tests are compiled unconditionally now, which adds ~200 kB to the kernel image
rust: tests: add Kconfig for KUnit test
There are 6 individual Rust KUnit test suites (plus the doctests one). All the tests are compiled unconditionally now, which adds ~200 kB to the kernel image for me on x86_64. As Rust matures, this bloating will inevitably grow.
Add Kconfig.test which includes a RUST_KUNIT_TESTS menu, and all individual tests under it.
As usual, new tests are all enabled if KUNIT_ALL_TESTS=y.
Suggested-by: Alice Ryhl <aliceryhl@google.com> Signed-off-by: Yury Norov <ynorov@nvidia.com> Reviewed-by: David Gow <david@davidgow.net> Acked-by: Gary Guo <gary@garyguo.net> Link: https://patch.msgid.link/20260417031531.315281-3-ynorov@nvidia.com [ Fixed capitalization. Used singular for "API" for consistency. Reworded to clarify these are suites and that there exists the doctests one (which is the biggest at the moment by far). - Miguel ] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
show more ...
|
| b91d5d4b | 03-Mar-2026 |
Andreas Hindborg <a.hindborg@kernel.org> |
rust: atomic: Update a safety comment in impl of `fetch_add()`
The safety comment used in the implementation of `fetch_add()` could be read as just saying something it is true without justifying it.
rust: atomic: Update a safety comment in impl of `fetch_add()`
The safety comment used in the implementation of `fetch_add()` could be read as just saying something it is true without justifying it. Update the safety comment to include justification.
Suggested-by: Miguel Ojeda <ojeda@kernel.org> Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org> Signed-off-by: Boqun Feng <boqun@kernel.org> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Link: https://patch.msgid.link/20260220-atomic-sub-v3-3-e63cbed1d2aa@kernel.org Link: https://patch.msgid.link/20260303201701.12204-14-boqun@kernel.org
show more ...
|
| c49cf341 | 03-Mar-2026 |
Andreas Hindborg <a.hindborg@kernel.org> |
rust: sync: atomic: Add fetch_sub()
Add `Atomic::fetch_sub()` with implementation and documentation in line with existing `Atomic::fetch_add()` implementation.
Signed-off-by: Andreas Hindborg <a.hi
rust: sync: atomic: Add fetch_sub()
Add `Atomic::fetch_sub()` with implementation and documentation in line with existing `Atomic::fetch_add()` implementation.
Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org> Signed-off-by: Boqun Feng <boqun@kernel.org> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Link: https://patch.msgid.link/20260220-atomic-sub-v3-1-e63cbed1d2aa@kernel.org Link: https://patch.msgid.link/20260303201701.12204-12-boqun@kernel.org
show more ...
|
| e2f9c86f | 03-Mar-2026 |
Boqun Feng <boqun.feng@gmail.com> |
rust: sync: atomic: Add atomic operation helpers over raw pointers
In order to synchronize with C or external memory, atomic operations over raw pointers are need. Although there is already an `Atom
rust: sync: atomic: Add atomic operation helpers over raw pointers
In order to synchronize with C or external memory, atomic operations over raw pointers are need. Although there is already an `Atomic::from_ptr()` to provide a `&Atomic<T>`, it's more convenient to have helpers that directly perform atomic operations on raw pointers. Hence a few are added, which are basically an `Atomic::from_ptr().op()` wrapper.
Note: for naming, since `atomic_xchg()` and `atomic_cmpxchg()` have a conflict naming to 32bit C atomic xchg/cmpxchg, hence the helpers are just named as `xchg()` and `cmpxchg()`. For `atomic_load()` and `atomic_store()`, their 32bit C counterparts are `atomic_read()` and `atomic_set()`, so keep the `atomic_` prefix.
[boqun: Fix typo spotted by Alice and fix broken sentence spotted by Gary]
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: Gary Guo <gary@garyguo.net> Link: https://patch.msgid.link/20260120115207.55318-3-boqun.feng@gmail.com Link: https://patch.msgid.link/20260303201701.12204-11-boqun@kernel.org
show more ...
|
| ec6fc66a | 03-Mar-2026 |
FUJITA Tomonori <fujita.tomonori@gmail.com> |
rust: sync: atomic: Add performance-optimal Flag type for atomic booleans
Add AtomicFlag type for boolean flags.
Document when AtomicFlag is generally preferable to Atomic<bool>: in particular, whe
rust: sync: atomic: Add performance-optimal Flag type for atomic booleans
Add AtomicFlag type for boolean flags.
Document when AtomicFlag is generally preferable to Atomic<bool>: in particular, when RMW operations such as xchg()/cmpxchg() may be used and minimizing memory usage is not the top priority. On some architectures without byte-sized RMW instructions, Atomic<bool> can be slower for RMW operations.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com> Signed-off-by: Boqun Feng <boqun@kernel.org> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Gary Guo <gary@garyguo.net> Link: https://patch.msgid.link/20260129122622.3896144-2-tomo@aliasing.net Link: https://patch.msgid.link/20260303201701.12204-9-boqun@kernel.org
show more ...
|
| ac8f06ad | 03-Mar-2026 |
Boqun Feng <boqun.feng@gmail.com> |
rust: sync: atomic: Add Atomic<*{mut,const} T> support
Atomic pointer support is an important piece of synchronization algorithm, e.g. RCU, hence provide the support for that.
Note that instead of
rust: sync: atomic: Add Atomic<*{mut,const} T> support
Atomic pointer support is an important piece of synchronization algorithm, e.g. RCU, hence provide the support for that.
Note that instead of relying on atomic_long or the implementation of `Atomic<usize>`, a new set of helpers (atomic_ptr_*) is introduced for atomic pointer specifically, this is because ptr2int casting would lose the provenance of a pointer and even though in theory there are a few tricks the provenance can be restored, it'll still be a simpler implementation if C could provide atomic pointers directly. The side effects of this approach are: we don't have the arithmetic and logical operations for pointers yet and the current implementation only works on ARCH_SUPPORTS_ATOMIC_RMW architectures, but these are implementation issues and can be added later.
Signed-off-by: Boqun Feng <boqun.feng@gmail.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Gary Guo <gary@garyguo.net> Reviewed-by: FUJITA Tomonori <fujita.tomonori@gmail.com> Link: https://patch.msgid.link/20260120140503.62804-3-boqun.feng@gmail.com Link: https://patch.msgid.link/20260303201701.12204-8-boqun@kernel.org
show more ...
|
| 4bac2872 | 01-Jan-2026 |
FUJITA Tomonori <fujita.tomonori@gmail.com> |
rust: sync: atomic: Add atomic bool tests
Add tests for Atomic<bool> operations.
Atomic<bool> does not fit into the existing u8/16/32/64 tests so introduce a dedicated test for it.
Signed-off-by:
rust: sync: atomic: Add atomic bool tests
Add tests for Atomic<bool> operations.
Atomic<bool> does not fit into the existing u8/16/32/64 tests so introduce a dedicated test for it.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com> Reviewed-by: Gary Guo <gary@garyguo.net> Signed-off-by: Boqun Feng <boqun.feng@gmail.com> Link: https://patch.msgid.link/20260101034922.2020334-3-fujita.tomonori@gmail.com
show more ...
|
| 06bd0e52 | 01-Jan-2026 |
FUJITA Tomonori <fujita.tomonori@gmail.com> |
rust: sync: atomic: Add atomic bool support via i8 representation
Add `bool` support, `Atomic<bool>` by using `i8` as its underlying representation.
Rust specifies that `bool` has size 1 and alignm
rust: sync: atomic: Add atomic bool support via i8 representation
Add `bool` support, `Atomic<bool>` by using `i8` as its underlying representation.
Rust specifies that `bool` has size 1 and alignment 1 [1], so it matches `i8` on layout; keep `static_assert!()` checks to enforce this assumption at build time.
[boqun: Remove the unnecessary impl AtomicImpl for bool]
Link: https://doc.rust-lang.org/reference/types/boolean.html [1] Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com> Reviewed-by: Gary Guo <gary@garyguo.net> Signed-off-by: Boqun Feng <boqun.feng@gmail.com> Link: https://patch.msgid.link/20260101034922.2020334-2-fujita.tomonori@gmail.com
show more ...
|
| 584f286f | 28-Dec-2025 |
FUJITA Tomonori <fujita.tomonori@gmail.com> |
rust: sync: atomic: Add i8/i16 xchg and cmpxchg support
Add atomic xchg and cmpxchg operation support for i8 and i16 types with tests.
Note that since the current implementation of Atomic::<{i8,i16
rust: sync: atomic: Add i8/i16 xchg and cmpxchg support
Add atomic xchg and cmpxchg operation support for i8 and i16 types with tests.
Note that since the current implementation of Atomic::<{i8,i16}>::{load,store}() is READ_ONCE()/WRITE_ONCE()-based. The atomicity between load/store and xchg/cmpxchg is only guaranteed if the architecture has native RmW support, hence i8/i16 is currently AtomicImpl only when CONFIG_ARCH_SUPPORTS_ATOMIC_RWM=y.
[boqun: Make i8/i16 AtomicImpl only when CONFIG_ARCH_SUPPORTS_ATOMIC_RWM=y]
Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com> Signed-off-by: Boqun Feng <boqun.feng@gmail.com> Link: https://patch.msgid.link/20251228120546.1602275-4-fujita.tomonori@gmail.com
show more ...
|
| 7b001c97 | 11-Dec-2025 |
FUJITA Tomonori <fujita.tomonori@gmail.com> |
rust: sync: atomic: Add store_release/load_acquire tests
Add minimum store_release/load_acquire tests.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com> Reviewed-by: Gary Guo <gary@garyguo
rust: sync: atomic: Add store_release/load_acquire tests
Add minimum store_release/load_acquire tests.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com> Reviewed-by: Gary Guo <gary@garyguo.net> Reviewed-by: Joel Fernandes <joelagnelf@nvidia.com> Signed-off-by: Boqun Feng <boqun.feng@gmail.com> Link: https://patch.msgid.link/20251211113826.1299077-5-fujita.tomonori@gmail.com
show more ...
|
| b33796d5 | 11-Dec-2025 |
FUJITA Tomonori <fujita.tomonori@gmail.com> |
rust: sync: atomic: Add i8/i16 load and store support
Add atomic operation support for i8 and i16 types using volatile read/write and smp_load_acquire/smp_store_release helpers.
[boqun: Adjust [1]
rust: sync: atomic: Add i8/i16 load and store support
Add atomic operation support for i8 and i16 types using volatile read/write and smp_load_acquire/smp_store_release helpers.
[boqun: Adjust [1] to avoid introduction of impl_atomic_only_load_and_store_ops!() in the middle]
Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com> Reviewed-by: Gary Guo <gary@garyguo.net> Reviewed-by: Joel Fernandes <joelagnelf@nvidia.com> Link: https://lore.kernel.org/all/20251228120546.1602275-1-fujita.tomonori@gmail.com/ [1] Signed-off-by: Boqun Feng <boqun.feng@gmail.com> Link: https://patch.msgid.link/20251211113826.1299077-4-fujita.tomonori@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 ...
|
| 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 ...
|