<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux/rust/kernel/alloc/kvec.rs, branch v6.17</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/
</subtitle>
<id>https://git.shady.money/linux/atom?h=v6.17</id>
<link rel='self' href='https://git.shady.money/linux/atom?h=v6.17'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/'/>
<updated>2025-07-15T21:42:55Z</updated>
<entry>
<title>Merge tag 'alloc-next-v6.17-2025-07-15' of https://github.com/Rust-for-Linux/linux into rust-next</title>
<updated>2025-07-15T21:42:55Z</updated>
<author>
<name>Miguel Ojeda</name>
<email>ojeda@kernel.org</email>
</author>
<published>2025-07-15T21:42:55Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=8ecb65b7b68ea48350833ba59c1257718e859768'/>
<id>urn:sha1:8ecb65b7b68ea48350833ba59c1257718e859768</id>
<content type='text'>
Pull alloc and DMA updates from Danilo Krummrich:

  Box:
   - Implement Borrow / BorrowMut for Box&lt;T, A&gt;.

  Vec:
   - Implement Default for Vec&lt;T, A&gt;.

   - Implement Borrow / BorrowMut for Vec&lt;T, A&gt;.

  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
</content>
</entry>
<entry>
<title>rust: enable `clippy::ptr_as_ptr` lint</title>
<updated>2025-06-22T21:08:42Z</updated>
<author>
<name>Tamir Duberstein</name>
<email>tamird@gmail.com</email>
</author>
<published>2025-06-15T20:55:05Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=fcad9bbf9e1a7de6c53908954ba1b1a1ab11ef1e'/>
<id>urn:sha1:fcad9bbf9e1a7de6c53908954ba1b1a1ab11ef1e</id>
<content type='text'>
In Rust 1.51.0, Clippy introduced the `ptr_as_ptr` lint [1]:

&gt; Though `as` casts between raw pointers are not terrible,
&gt; `pointer::cast` is safer because it cannot accidentally change the
&gt; pointer's mutability, nor cast the pointer to other types like `usize`.

There are a few classes of changes required:
- Modules generated by bindgen are marked
  `#[allow(clippy::ptr_as_ptr)]`.
- Inferred casts (` as _`) are replaced with `.cast()`.
- Ascribed casts (` as *... T`) are replaced with `.cast::&lt;T&gt;()`.
- Multistep casts from references (` as *const _ as *const T`) are
  replaced with `core::ptr::from_ref(&amp;x).cast()` with or without `::&lt;T&gt;`
  according to the previous rules. The `core::ptr::from_ref` call is
  required because `(x as *const _).cast::&lt;T&gt;()` results in inference
  failure.
- Native literal C strings are replaced with `c_str!().as_char_ptr()`.
- `*mut *mut T as _` is replaced with `let *mut *const T = (*mut *mut
  T)`.cast();` since pointer to pointer can be confusing.

Apply these changes and enable the lint -- no functional change
intended.

Link: https://rust-lang.github.io/rust-clippy/master/index.html#ptr_as_ptr [1]
Reviewed-by: Benno Lossin &lt;benno.lossin@proton.me&gt;
Reviewed-by: Boqun Feng &lt;boqun.feng@gmail.com&gt;
Signed-off-by: Tamir Duberstein &lt;tamird@gmail.com&gt;
Acked-by: Viresh Kumar &lt;viresh.kumar@linaro.org&gt;
Acked-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
Acked-by: Tejun Heo &lt;tj@kernel.org&gt;
Acked-by: Danilo Krummrich &lt;dakr@kernel.org&gt;
Link: https://lore.kernel.org/r/20250615-ptr-as-ptr-v12-1-f43b024581e8@gmail.com
[ Added `.cast()` for `opp`. - Miguel ]
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: alloc: implement `Borrow` and `BorrowMut` for `Vec`</title>
<updated>2025-06-18T21:09:21Z</updated>
<author>
<name>Alexandre Courbot</name>
<email>acourbot@nvidia.com</email>
</author>
<published>2025-06-16T03:34:05Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=c09a8ac1cd560c8f944611045841fed99790116b'/>
<id>urn:sha1:c09a8ac1cd560c8f944611045841fed99790116b</id>
<content type='text'>
Implement `Borrow&lt;[T]&gt;` and `BorrowMut&lt;[T]&gt;` for `Vec&lt;T&gt;`. This allows
`Vec&lt;T&gt;` to be used in generic APIs asking for types implementing those
traits. `[T; N]` and `&amp;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 &lt;aliceryhl@google.com&gt;
Reviewed-by: Benno Lossin &lt;lossin@kernel.org&gt;
Signed-off-by: Alexandre Courbot &lt;acourbot@nvidia.com&gt;
Link: https://lore.kernel.org/r/20250616-borrow_impls-v4-1-36f9beb3fe6a@nvidia.com
Signed-off-by: Danilo Krummrich &lt;dakr@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: vec: impl Default for Vec with any allocator</title>
<updated>2025-06-11T14:35:10Z</updated>
<author>
<name>Alice Ryhl</name>
<email>aliceryhl@google.com</email>
</author>
<published>2025-06-10T10:31:56Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=47d8101924b58e03bfd065c972172e6b69331397'/>
<id>urn:sha1:47d8101924b58e03bfd065c972172e6b69331397</id>
<content type='text'>
The implementation of Default is restricted to only work with kmalloc
vectors for no good reason. This means I have to use

	mem::replace(&amp;mut my_vec, KVVec::new())

in Rust Binder instead of `mem::take(&amp;mut my_vec)`. Thus, expand the
impl of Default to work with any allocator including kvmalloc.

Signed-off-by: Alice Ryhl &lt;aliceryhl@google.com&gt;
Reviewed-by: Benno Lossin &lt;lossin@kernel.org&gt;
Link: https://lore.kernel.org/r/20250610-vec-default-v1-1-7bb2c97d75a0@google.com
Signed-off-by: Danilo Krummrich &lt;dakr@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: remove unneeded Rust 1.87.0 `allow(clippy::ptr_eq)`</title>
<updated>2025-05-22T09:46:50Z</updated>
<author>
<name>Miguel Ojeda</name>
<email>ojeda@kernel.org</email>
</author>
<published>2025-05-20T18:21:25Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=bb941ea789f803cce766ca1e0f7c59a362aaf99a'/>
<id>urn:sha1:bb941ea789f803cce766ca1e0f7c59a362aaf99a</id>
<content type='text'>
For the Rust 1.87.0 release, Clippy was expected to warn with:

    error: use `core::ptr::eq` when comparing raw pointers
       --&gt; 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 &lt;aliceryhl@google.com&gt;
Link: https://lore.kernel.org/r/20250520182125.806758-1-ojeda@kernel.org
[ Reworded for clarity. - Miguel ]
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>Merge tag 'alloc-next-v6.16-2025-05-13' of https://github.com/Rust-for-Linux/linux into rust-next</title>
<updated>2025-05-18T18:56:03Z</updated>
<author>
<name>Miguel Ojeda</name>
<email>ojeda@kernel.org</email>
</author>
<published>2025-05-18T18:56:03Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=22c3335c5dcd33063fe1894676a3a6ff1008d506'/>
<id>urn:sha1:22c3335c5dcd33063fe1894676a3a6ff1008d506</id>
<content type='text'>
Pull alloc updates from Danilo Krummrich:
 "Box:

   - Support for type coercion, e.g. 'Box&lt;T&gt;' to 'Box&lt;dyn U&gt;' 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() &lt;= 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() &lt;= Vec::capacity invariant
  rust: alloc: allow coercion from `Box&lt;T&gt;` to `Box&lt;dyn U&gt;` 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()
</content>
</entry>
<entry>
<title>rust: alloc: add Vec::insert_within_capacity</title>
<updated>2025-05-07T16:40:45Z</updated>
<author>
<name>Alice Ryhl</name>
<email>aliceryhl@google.com</email>
</author>
<published>2025-05-02T13:19:35Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=771c5a7d9843643b035938624050e7769133b9cc'/>
<id>urn:sha1:771c5a7d9843643b035938624050e7769133b9cc</id>
<content type='text'>
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 &lt;aliceryhl@google.com&gt;
Reviewed-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
Reviewed-by: Benno Lossin &lt;lossin@kernel.org&gt;
Link: https://lore.kernel.org/r/20250502-vec-methods-v5-7-06d20ad9366f@google.com
Signed-off-by: Danilo Krummrich &lt;dakr@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: alloc: add Vec::remove</title>
<updated>2025-05-07T16:40:02Z</updated>
<author>
<name>Alice Ryhl</name>
<email>aliceryhl@google.com</email>
</author>
<published>2025-05-02T13:19:34Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=294a7ecbdf0a5d65c6df1287c5d56241e9331cf2'/>
<id>urn:sha1:294a7ecbdf0a5d65c6df1287c5d56241e9331cf2</id>
<content type='text'>
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&lt;T&gt; to let callers handle errors with ?.

Signed-off-by: Alice Ryhl &lt;aliceryhl@google.com&gt;
Reviewed-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
Reviewed-by: Benno Lossin &lt;lossin@kernel.org&gt;
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 &lt;dakr@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: alloc: add Vec::retain</title>
<updated>2025-05-07T16:39:39Z</updated>
<author>
<name>Alice Ryhl</name>
<email>aliceryhl@google.com</email>
</author>
<published>2025-05-02T13:19:33Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=9f140894e72735f034fdc0e963d0550ef03c6f44'/>
<id>urn:sha1:9f140894e72735f034fdc0e963d0550ef03c6f44</id>
<content type='text'>
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 &amp;T rather than &amp;mut T and has a separate
retain_mut for the &amp;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 &lt;aliceryhl@google.com&gt;
Reviewed-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
Reviewed-by: Benno Lossin &lt;lossin@kernel.org&gt;
Link: https://lore.kernel.org/r/20250502-vec-methods-v5-5-06d20ad9366f@google.com
Signed-off-by: Danilo Krummrich &lt;dakr@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: alloc: add Vec::drain_all</title>
<updated>2025-05-07T16:39:22Z</updated>
<author>
<name>Alice Ryhl</name>
<email>aliceryhl@google.com</email>
</author>
<published>2025-05-02T13:19:32Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=088bf14a886e1e746c961a862ebccbb76d7cbd4e'/>
<id>urn:sha1:088bf14a886e1e746c961a862ebccbb76d7cbd4e</id>
<content type='text'>
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 &lt;aliceryhl@google.com&gt;
Reviewed-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
Reviewed-by: Benno Lossin &lt;lossin@kernel.org&gt;
Link: https://lore.kernel.org/r/20250502-vec-methods-v5-4-06d20ad9366f@google.com
Signed-off-by: Danilo Krummrich &lt;dakr@kernel.org&gt;
</content>
</entry>
</feed>
