| 1b1a946d | 11-Aug-2025 |
Alice Ryhl <aliceryhl@google.com> |
rust: alloc: specify the minimum alignment of each allocator
The kernel's allocators sometimes provide a higher alignment than the end-user requested, so add a new constant on the Allocator trait to
rust: alloc: specify the minimum alignment of each allocator
The kernel's allocators sometimes provide a higher alignment than the end-user requested, so add a new constant on the Allocator trait to let the allocator specify what its minimum guaranteed alignment is.
This allows the ForeignOwnable trait to provide a more accurate value of FOREIGN_ALIGN when using a pointer type such as Box, which will be useful with certain collections such as XArray that store its own data in the low bits of pointers.
Reviewed-by: Benno Lossin <lossin@kernel.org> Signed-off-by: Alice Ryhl <aliceryhl@google.com> Acked-by: Liam R. Howlett <Liam.Howlett@oracle.com> Reviewed-by: Andreas Hindborg <a.hindborg@kernel.org> Link: https://lore.kernel.org/r/20250811-align-min-allocator-v2-1-3386cc94f4fc@google.com [ Add helper for ARCH_KMALLOC_MINALIGN; remove cast to usize. - Danilo ] Signed-off-by: Danilo Krummrich <dakr@kernel.org>
show more ...
|
| f87de691 | 20-Jul-2025 |
Onur Özkan <work@onurozkan.dev> |
rust: make `kvec::Vec` functions `const fn`
Makes various `kvec::Vec` functions `const fn` to allow compile-time evaluation.
Signed-off-by: Onur Özkan <work@onurozkan.dev> Reviewed-by: Alice Ryhl <
rust: make `kvec::Vec` functions `const fn`
Makes various `kvec::Vec` functions `const fn` to allow compile-time evaluation.
Signed-off-by: Onur Özkan <work@onurozkan.dev> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Benno Lossin <lossin@kernel.org> Link: https://lore.kernel.org/r/20250720094838.29530-4-work@onurozkan.dev Signed-off-by: Danilo Krummrich <dakr@kernel.org>
show more ...
|
| 8d3e8057 | 20-Jul-2025 |
Onur Özkan <work@onurozkan.dev> |
rust: make `ArrayLayout::new_unchecked` a `const fn`
Makes `ArrayLayout::new_unchecked` a `const fn` to allow compile-time evaluation.
Signed-off-by: Onur Özkan <work@onurozkan.dev> Reviewed-by: Al
rust: make `ArrayLayout::new_unchecked` a `const fn`
Makes `ArrayLayout::new_unchecked` a `const fn` to allow compile-time evaluation.
Signed-off-by: Onur Özkan <work@onurozkan.dev> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Benno Lossin <lossin@kernel.org> Link: https://lore.kernel.org/r/20250720094838.29530-3-work@onurozkan.dev Signed-off-by: Danilo Krummrich <dakr@kernel.org>
show more ...
|
| a55498c7 | 31-Jul-2025 |
Hui Zhu <zhuhui@kylinos.cn> |
rust: alloc: kvec: simplify KUnit test module name to "rust_kvec"
Remove redundant "_kunit" suffix from test module name.
The naming is now consistent with other Rust components as the test context
rust: alloc: kvec: simplify KUnit test module name to "rust_kvec"
Remove redundant "_kunit" suffix from test module name.
The naming is now consistent with other Rust components as the test context is already implied by the #[kunit_tests] macro and test module location.
Co-developed-by: Geliang Tang <geliang@kernel.org> Signed-off-by: Geliang Tang <geliang@kernel.org> Signed-off-by: Hui Zhu <zhuhui@kylinos.cn> Reviewed-by: David Gow <davidgow@google.com> Link: https://lore.kernel.org/r/4eb554c3bf03dd4f9e6dea659497938baab61dba.1753929369.git.zhuhui@kylinos.cn Signed-off-by: Danilo Krummrich <dakr@kernel.org>
show more ...
|
| 8ecb65b7 | 15-Jul-2025 |
Miguel Ojeda <ojeda@kernel.org> |
Merge tag 'alloc-next-v6.17-2025-07-15' of https://github.com/Rust-for-Linux/linux into rust-next
Pull alloc and DMA updates from Danilo Krummrich:
Box: - Implement Borrow / BorrowMut for Box<
Merge tag 'alloc-next-v6.17-2025-07-15' of https://github.com/Rust-for-Linux/linux into rust-next
Pull alloc and DMA updates from Danilo Krummrich:
Box: - Implement Borrow / BorrowMut for Box<T, A>.
Vec: - Implement Default for Vec<T, A>.
- Implement Borrow / BorrowMut for Vec<T, A>.
DMA: - Clarify wording and be consistent in 'coherent' nomenclature.
- Convert the read!() / write!() macros to return a Result.
- Add as_slice() / write() methods in CoherentAllocation.
- Fix doc-comment of dma_handle().
- Expose count() and size() in CoherentAllocation and add the corresponding type invariants.
- Implement CoherentAllocation::dma_handle_with_offset().
- Require mutable reference for as_slice_mut() and write().
MAINTAINERS: - Add Vlastimil Babka, Liam R. Howlett, Uladzislau Rezki and Lorenzo Stoakes as reviewers (thanks everyone).
* tag 'alloc-next-v6.17-2025-07-15' of https://github.com/Rust-for-Linux/linux: MAINTAINERS: add mm folks as reviewers to rust alloc rust: dma: require mutable reference for as_slice_mut() and write() rust: dma: add dma_handle_with_offset method to CoherentAllocation rust: dma: expose the count and size of CoherentAllocation rust: dma: fix doc-comment of dma_handle() rust: dma: add as_slice/write functions for CoherentAllocation rust: dma: convert the read/write macros to return Result rust: dma: clarify wording and be consistent in `coherent` nomenclature rust: alloc: implement `Borrow` and `BorrowMut` for `KBox` rust: alloc: implement `Borrow` and `BorrowMut` for `Vec` rust: vec: impl Default for Vec with any allocator
show more ...
|
| f86c0036 | 16-Jun-2025 |
Alexandre Courbot <acourbot@nvidia.com> |
rust: alloc: implement `Borrow` and `BorrowMut` for `KBox`
Implement `Borrow<T>` and `BorrowMut<T>` for `KBox<T>`. This allows `KBox<T>` to be used in generic APIs asking for types implementing thos
rust: alloc: implement `Borrow` and `BorrowMut` for `KBox`
Implement `Borrow<T>` and `BorrowMut<T>` for `KBox<T>`. This allows `KBox<T>` to be used in generic APIs asking for types implementing those traits. `T` and `&mut T` also implement those traits allowing users to use either owned, borrowed and heap-owned values.
Reviewed-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Benno Lossin <lossin@kernel.org> Signed-off-by: Alexandre Courbot <acourbot@nvidia.com> Link: https://lore.kernel.org/r/20250616-borrow_impls-v4-3-36f9beb3fe6a@nvidia.com Signed-off-by: Danilo Krummrich <dakr@kernel.org>
show more ...
|
| c09a8ac1 | 16-Jun-2025 |
Alexandre Courbot <acourbot@nvidia.com> |
rust: alloc: implement `Borrow` and `BorrowMut` for `Vec`
Implement `Borrow<[T]>` and `BorrowMut<[T]>` for `Vec<T>`. This allows `Vec<T>` to be used in generic APIs asking for types implementing tho
rust: alloc: implement `Borrow` and `BorrowMut` for `Vec`
Implement `Borrow<[T]>` and `BorrowMut<[T]>` for `Vec<T>`. This allows `Vec<T>` to be used in generic APIs asking for types implementing those traits. `[T; N]` and `&mut [T]` also implement those traits allowing users to use either owned, borrowed and heap-owned values.
The implementation leverages `as_slice` and `as_mut_slice`.
Reviewed-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Benno Lossin <lossin@kernel.org> Signed-off-by: Alexandre Courbot <acourbot@nvidia.com> Link: https://lore.kernel.org/r/20250616-borrow_impls-v4-1-36f9beb3fe6a@nvidia.com Signed-off-by: Danilo Krummrich <dakr@kernel.org>
show more ...
|
| bb941ea7 | 20-May-2025 |
Miguel Ojeda <ojeda@kernel.org> |
rust: remove unneeded Rust 1.87.0 `allow(clippy::ptr_eq)`
For the Rust 1.87.0 release, Clippy was expected to warn with:
error: use `core::ptr::eq` when comparing raw pointers --> rust/k
rust: remove unneeded Rust 1.87.0 `allow(clippy::ptr_eq)`
For the Rust 1.87.0 release, Clippy was expected to warn with:
error: use `core::ptr::eq` when comparing raw pointers --> rust/kernel/list.rs:438:12 | 438 | if self.first == item { | ^^^^^^^^^^^^^^^^^^ help: try: `core::ptr::eq(self.first, item)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_eq = note: `-D clippy::ptr-eq` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::ptr_eq)]`
However, a backport to relax a bit the `clippy::ptr_eq` finally landed, and thus Clippy did not warn by the time the release happened.
Thus remove the `allow`s added back then, which were added just in case the backport did not land in time.
See commit a39f30870927 ("rust: allow Rust 1.87.0's `clippy::ptr_eq` lint") for details.
Link: https://github.com/rust-lang/rust/pull/140859 [1] Reviewed-by: Alice Ryhl <aliceryhl@google.com> Link: https://lore.kernel.org/r/20250520182125.806758-1-ojeda@kernel.org [ Reworded for clarity. - Miguel ] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
show more ...
|
| 22c3335c | 18-May-2025 |
Miguel Ojeda <ojeda@kernel.org> |
Merge tag 'alloc-next-v6.16-2025-05-13' of https://github.com/Rust-for-Linux/linux into rust-next
Pull alloc updates from Danilo Krummrich: "Box:
- Support for type coercion, e.g. 'Box<T>' to '
Merge tag 'alloc-next-v6.16-2025-05-13' of https://github.com/Rust-for-Linux/linux into rust-next
Pull alloc updates from Danilo Krummrich: "Box:
- Support for type coercion, e.g. 'Box<T>' to 'Box<dyn U>' if T implements U
Vec:
- Implement new methods (prerequisites for nova-core and binder) - Vec::truncate() - Vec::resize() - Vec::clear() - Vec::pop() - Vec::push_within_capacity() - New error type: PushError - Vec::drain_all() - Vec::retain() - Vec::remove() - New error type: RemoveError - Vec::insert_within_capacity - New error type: InsertError
- Simplify Vec::push() using Vec::spare_capacity_mut()
- Split Vec::set_len() into Vec::inc_len() and Vec::dec_len() - Add type invariant Vec::len() <= Vec::capacity - Simplify Vec::truncate() using Vec::dec_len()"
* tag 'alloc-next-v6.16-2025-05-13' of https://github.com/Rust-for-Linux/linux: rust: alloc: add Vec::insert_within_capacity rust: alloc: add Vec::remove rust: alloc: add Vec::retain rust: alloc: add Vec::drain_all rust: alloc: add Vec::push_within_capacity rust: alloc: add Vec::pop rust: alloc: add Vec::clear rust: alloc: replace `Vec::set_len` with `inc_len` rust: alloc: refactor `Vec::truncate` using `dec_len` rust: alloc: add `Vec::dec_len` rust: alloc: add Vec::len() <= Vec::capacity invariant rust: alloc: allow coercion from `Box<T>` to `Box<dyn U>` if T implements U rust: alloc: use `spare_capacity_mut` to reduce unsafe rust: alloc: add Vec::resize method rust: alloc: add Vec::truncate method rust: alloc: add missing invariant in Vec::set_len()
show more ...
|
| 771c5a7d | 02-May-2025 |
Alice Ryhl <aliceryhl@google.com> |
rust: alloc: add Vec::insert_within_capacity
This adds a variant of Vec::insert that does not allocate memory. This makes it safe to use this function while holding a spinlock. Rust Binder uses it f
rust: alloc: add Vec::insert_within_capacity
This adds a variant of Vec::insert that does not allocate memory. This makes it safe to use this function while holding a spinlock. Rust Binder uses it for the range allocator fast path.
Signed-off-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Reviewed-by: Benno Lossin <lossin@kernel.org> Link: https://lore.kernel.org/r/20250502-vec-methods-v5-7-06d20ad9366f@google.com Signed-off-by: Danilo Krummrich <dakr@kernel.org>
show more ...
|
| 294a7ecb | 02-May-2025 |
Alice Ryhl <aliceryhl@google.com> |
rust: alloc: add Vec::remove
This is needed by Rust Binder in the range allocator, and by upcoming GPU drivers during firmware initialization.
Panics in the kernel are best avoided when possible, s
rust: alloc: add Vec::remove
This is needed by Rust Binder in the range allocator, and by upcoming GPU drivers during firmware initialization.
Panics in the kernel are best avoided when possible, so an error is returned if the index is out of bounds. An error type is used rather than just returning Option<T> to let callers handle errors with ?.
Signed-off-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Reviewed-by: Benno Lossin <lossin@kernel.org> Link: https://lore.kernel.org/r/20250502-vec-methods-v5-6-06d20ad9366f@google.com [ Remove `# Panics` section; `Vec::remove() handles the error properly.` - Danilo ] Signed-off-by: Danilo Krummrich <dakr@kernel.org>
show more ...
|
| 9f140894 | 02-May-2025 |
Alice Ryhl <aliceryhl@google.com> |
rust: alloc: add Vec::retain
This adds a common Vec method called `retain` that removes all elements that don't match a certain condition. Rust Binder uses it to find all processes that match a give
rust: alloc: add Vec::retain
This adds a common Vec method called `retain` that removes all elements that don't match a certain condition. Rust Binder uses it to find all processes that match a given pid.
The stdlib retain method takes &T rather than &mut T and has a separate retain_mut for the &mut T case. However, this is considered an API mistake that can't be fixed now due to backwards compatibility. There's no reason for us to repeat that mistake.
Signed-off-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Reviewed-by: Benno Lossin <lossin@kernel.org> Link: https://lore.kernel.org/r/20250502-vec-methods-v5-5-06d20ad9366f@google.com Signed-off-by: Danilo Krummrich <dakr@kernel.org>
show more ...
|
| 088bf14a | 02-May-2025 |
Alice Ryhl <aliceryhl@google.com> |
rust: alloc: add Vec::drain_all
This is like the stdlib method drain, except that it's hard-coded to use the entire vector's range. Rust Binder uses it in the range allocator to take ownership of ev
rust: alloc: add Vec::drain_all
This is like the stdlib method drain, except that it's hard-coded to use the entire vector's range. Rust Binder uses it in the range allocator to take ownership of everything in a vector in a case where reusing the vector is desirable.
Implementing `DrainAll` in terms of `slice::IterMut` lets us reuse some nice optimizations in core for the case where T is a ZST.
Signed-off-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Reviewed-by: Benno Lossin <lossin@kernel.org> Link: https://lore.kernel.org/r/20250502-vec-methods-v5-4-06d20ad9366f@google.com Signed-off-by: Danilo Krummrich <dakr@kernel.org>
show more ...
|
| 9def0d0a | 02-May-2025 |
Alice Ryhl <aliceryhl@google.com> |
rust: alloc: add Vec::push_within_capacity
This introduces a new method called `push_within_capacity` for appending to a vector without attempting to allocate if the capacity is full. Rust Binder wi
rust: alloc: add Vec::push_within_capacity
This introduces a new method called `push_within_capacity` for appending to a vector without attempting to allocate if the capacity is full. Rust Binder will use this in various places to safely push to a vector while holding a spinlock.
The implementation is moved to a push_within_capacity_unchecked method. This is preferred over having push() call push_within_capacity() followed by an unwrap_unchecked() for simpler unsafe.
Panics in the kernel are best avoided when possible, so an error is returned if the vector does not have sufficient capacity. An error type is used rather than just returning Result<(),T> to make it more convenient for callers (i.e. they can use ? or unwrap).
Signed-off-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Reviewed-by: Benno Lossin <lossin@kernel.org> Link: https://lore.kernel.org/r/20250502-vec-methods-v5-3-06d20ad9366f@google.com [ Remove public visibility from `Vec::push_within_capacity_unchecked()`. - Danilo ] Signed-off-by: Danilo Krummrich <dakr@kernel.org>
show more ...
|
| f2b4dd70 | 02-May-2025 |
Alice Ryhl <aliceryhl@google.com> |
rust: alloc: add Vec::pop
This introduces a basic method that our custom Vec is missing. I expect that it will be used in many places, but at the time of writing, Rust Binder has six calls to Vec::p
rust: alloc: add Vec::pop
This introduces a basic method that our custom Vec is missing. I expect that it will be used in many places, but at the time of writing, Rust Binder has six calls to Vec::pop.
Signed-off-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Reviewed-by: Benno Lossin <lossin@kernel.org> Link: https://lore.kernel.org/r/20250502-vec-methods-v5-2-06d20ad9366f@google.com Signed-off-by: Danilo Krummrich <dakr@kernel.org>
show more ...
|
| a1e4d5c9 | 02-May-2025 |
Alice Ryhl <aliceryhl@google.com> |
rust: alloc: add Vec::clear
Our custom Vec type is missing the stdlib method `clear`, thus add it. It will be used in the miscdevice sample.
Reviewed-by: Benno Lossin <benno.lossin@proton.me> Revie
rust: alloc: add Vec::clear
Our custom Vec type is missing the stdlib method `clear`, thus add it. It will be used in the miscdevice sample.
Reviewed-by: Benno Lossin <benno.lossin@proton.me> Reviewed-by: Tamir Duberstein <tamird@gmail.com> Signed-off-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Link: https://lore.kernel.org/r/20250502-vec-methods-v5-1-06d20ad9366f@google.com Signed-off-by: Danilo Krummrich <dakr@kernel.org>
show more ...
|