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 ...
|
88d5d6a3 | 16-Apr-2025 |
Tamir Duberstein <tamird@gmail.com> |
rust: alloc: replace `Vec::set_len` with `inc_len`
Rename `set_len` to `inc_len` and simplify its safety contract.
Note that the usage in `CString::try_from_fmt` remains correct as the receiver is
rust: alloc: replace `Vec::set_len` with `inc_len`
Rename `set_len` to `inc_len` and simplify its safety contract.
Note that the usage in `CString::try_from_fmt` remains correct as the receiver is known to have `len == 0`.
Reviewed-by: Alice Ryhl <aliceryhl@google.com> Signed-off-by: Tamir Duberstein <tamird@gmail.com> Link: https://lore.kernel.org/r/20250416-vec-set-len-v4-4-112b222604cd@gmail.com Signed-off-by: Danilo Krummrich <dakr@kernel.org>
show more ...
|
1b04b466 | 16-Apr-2025 |
Tamir Duberstein <tamird@gmail.com> |
rust: alloc: refactor `Vec::truncate` using `dec_len`
Use `checked_sub` to satisfy the safety requirements of `dec_len` and replace nearly the whole body of `truncate` with a call to `dec_len`.
Rev
rust: alloc: refactor `Vec::truncate` using `dec_len`
Use `checked_sub` to satisfy the safety requirements of `dec_len` and replace nearly the whole body of `truncate` with a call to `dec_len`.
Reviewed-by: Andrew Ballance <andrewjballance@gmail.com> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Signed-off-by: Tamir Duberstein <tamird@gmail.com> Link: https://lore.kernel.org/r/20250416-vec-set-len-v4-3-112b222604cd@gmail.com [ Remove #[expect(unused)] from dec_len(). - Danilo ] Signed-off-by: Danilo Krummrich <dakr@kernel.org>
show more ...
|
dbb0b840 | 16-Apr-2025 |
Tamir Duberstein <tamird@gmail.com> |
rust: alloc: add `Vec::dec_len`
Add `Vec::dec_len` that reduces the length of the receiver. This method is intended to be used from methods that remove elements from `Vec` such as `truncate`, `pop`,
rust: alloc: add `Vec::dec_len`
Add `Vec::dec_len` that reduces the length of the receiver. This method is intended to be used from methods that remove elements from `Vec` such as `truncate`, `pop`, `remove`, and others. This method is intentionally not `pub`.
Reviewed-by: Alice Ryhl <aliceryhl@google.com> Signed-off-by: Tamir Duberstein <tamird@gmail.com> Link: https://lore.kernel.org/r/20250416-vec-set-len-v4-2-112b222604cd@gmail.com [ Add #[expect(unused)] to dec_len(). - Danilo ] Signed-off-by: Danilo Krummrich <dakr@kernel.org>
show more ...
|
47a17a63 | 16-Apr-2025 |
Tamir Duberstein <tamird@gmail.com> |
rust: alloc: add Vec::len() <= Vec::capacity invariant
Document the invariant that the vector's length is always less than or equal to its capacity. This is already implied by these other invariants
rust: alloc: add Vec::len() <= Vec::capacity invariant
Document the invariant that the vector's length is always less than or equal to its capacity. This is already implied by these other invariants:
- `self.len` always represents the exact number of elements stored in the vector. - `self.layout` represents the absolute number of elements that can be stored within the vector without re-allocation.
but it doesn't hurt to spell it out. Note that the language references `self.capacity` rather than `self.layout.len` as the latter is zero for a vector of ZSTs.
Update a safety comment touched by this patch to correctly reference `realloc` rather than `alloc` and replace "leaves" with "leave" to improve grammar.
Reviewed-by: Alice Ryhl <aliceryhl@google.com> Signed-off-by: Tamir Duberstein <tamird@gmail.com> Link: https://lore.kernel.org/r/20250416-vec-set-len-v4-1-112b222604cd@gmail.com Signed-off-by: Danilo Krummrich <dakr@kernel.org>
show more ...
|
85f8e98d | 12-Apr-2025 |
Alexandre Courbot <acourbot@nvidia.com> |
rust: alloc: allow coercion from `Box<T>` to `Box<dyn U>` if T implements U
This enables the creation of trait objects backed by a Box, similarly to what can be done with the standard library.
Sugg
rust: alloc: allow coercion from `Box<T>` to `Box<dyn U>` if T implements U
This enables the creation of trait objects backed by a Box, similarly to what can be done with the standard library.
Suggested-by: Benno Lossin <benno.lossin@proton.me> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Benno Lossin <benno.lossin@proton.me> Signed-off-by: Alexandre Courbot <acourbot@nvidia.com> Link: https://lore.kernel.org/r/20250412-box_trait_objs-v3-1-f67ced62d520@nvidia.com Signed-off-by: Danilo Krummrich <dakr@kernel.org>
show more ...
|
c3152988 | 18-Mar-2025 |
Tamir Duberstein <tamird@gmail.com> |
rust: alloc: use `spare_capacity_mut` to reduce unsafe
Use `spare_capacity_mut` in the implementation of `push` to reduce the use of `unsafe`. Both methods were added in commit 2aac4cd7dae3 ("rust:
rust: alloc: use `spare_capacity_mut` to reduce unsafe
Use `spare_capacity_mut` in the implementation of `push` to reduce the use of `unsafe`. Both methods were added in commit 2aac4cd7dae3 ("rust: alloc: implement kernel `Vec` type").
Reviewed-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Benno Lossin <benno.lossin@proton.me> Link: https://lore.kernel.org/r/20250318-vec-push-use-spare-v3-1-68741671d1af@gmail.com Signed-off-by: Tamir Duberstein <tamird@gmail.com> Signed-off-by: Danilo Krummrich <dakr@kernel.org>
show more ...
|
1679b715 | 16-Mar-2025 |
Andrew Ballance <andrewjballance@gmail.com> |
rust: alloc: add Vec::resize method
Implement the equivalent of the rust std's Vec::resize on the kernel's Vec type.
Reviewed-by: Benno Lossin <benno.lossin@proton.me> Reviewed-by: Tamir Duberstein
rust: alloc: add Vec::resize method
Implement the equivalent of the rust std's Vec::resize on the kernel's Vec type.
Reviewed-by: Benno Lossin <benno.lossin@proton.me> Reviewed-by: Tamir Duberstein <tamird@gmail.com> Link: https://lore.kernel.org/r/20250316111644.154602-3-andrewjballance@gmail.com Signed-off-by: Andrew Ballance <andrewjballance@gmail.com> [ Use checked_sub(), as suggested by Tamir. - Danilo ] Signed-off-by: Danilo Krummrich <dakr@kernel.org>
show more ...
|
81e1c4da | 16-Mar-2025 |
Andrew Ballance <andrewjballance@gmail.com> |
rust: alloc: add Vec::truncate method
Implement the equivalent to the std's Vec::truncate on the kernel's Vec type.
Link: https://lore.kernel.org/r/20250316111644.154602-2-andrewjballance@gmail.com
rust: alloc: add Vec::truncate method
Implement the equivalent to the std's Vec::truncate on the kernel's Vec type.
Link: https://lore.kernel.org/r/20250316111644.154602-2-andrewjballance@gmail.com Signed-off-by: Andrew Ballance <andrewjballance@gmail.com> [ Rewrote safety comment of set_len(). - Danilo ] Signed-off-by: Danilo Krummrich <dakr@kernel.org>
show more ...
|