<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux/rust/kernel/alloc, 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-08-16T23:29:21Z</updated>
<entry>
<title>rust: alloc: fix `rusttest` by providing `Cmalloc::aligned_layout` too</title>
<updated>2025-08-16T23:29:21Z</updated>
<author>
<name>Miguel Ojeda</name>
<email>ojeda@kernel.org</email>
</author>
<published>2025-08-16T20:42:15Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=0f580d5d3d9d9cd0953695cd32e43aac3a946338'/>
<id>urn:sha1:0f580d5d3d9d9cd0953695cd32e43aac3a946338</id>
<content type='text'>
Commit fde578c86281 ("rust: alloc: replace aligned_size() with
Kmalloc::aligned_layout()") provides a public `aligned_layout` function
in `Kamlloc`, but not in `Cmalloc`, and thus uses of it will trigger an
error in `rusttest`.

Such a user appeared in the following commit 22ab0641b939 ("rust: drm:
ensure kmalloc() compatible Layout"):

    error[E0599]: no function or associated item named `aligned_layout` found for struct `alloc::allocator_test::Cmalloc` in the current scope
       --&gt; rust/kernel/drm/device.rs:100:31
        |
    100 |         let layout = Kmalloc::aligned_layout(Layout::new::&lt;Self&gt;());
        |                               ^^^^^^^^^^^^^^ function or associated item not found in `Cmalloc`
        |
       ::: rust/kernel/alloc/allocator_test.rs:19:1
        |
    19  | pub struct Cmalloc;
        | ------------------ function or associated item `aligned_layout` not found for this struct

Thus add an equivalent one for `Cmalloc`.

Fixes: fde578c86281 ("rust: alloc: replace aligned_size() with Kmalloc::aligned_layout()")
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
Link: https://lore.kernel.org/r/20250816204215.2719559-1-ojeda@kernel.org
Signed-off-by: Danilo Krummrich &lt;dakr@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: alloc: replace aligned_size() with Kmalloc::aligned_layout()</title>
<updated>2025-08-11T21:20:53Z</updated>
<author>
<name>Danilo Krummrich</name>
<email>dakr@kernel.org</email>
</author>
<published>2025-07-31T15:48:06Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=fde578c86281f27b182680c7642836a0dbbd0be7'/>
<id>urn:sha1:fde578c86281f27b182680c7642836a0dbbd0be7</id>
<content type='text'>
aligned_size() dates back to when Rust did support kmalloc() only, but
is now used in ReallocFunc::call() and hence for all allocators.

However, the additional padding applied by aligned_size() is only
required by the kmalloc() allocator backend.

Hence, replace aligned_size() with Kmalloc::aligned_layout() and use it
for the affected allocators, i.e. kmalloc() and kvmalloc(), only.

While at it, make Kmalloc::aligned_layout() public, such that Rust
abstractions, which have to call subsystem specific kmalloc() based
allocation primitives directly, can make use of it.

Fixes: 8a799831fc63 ("rust: alloc: implement `ReallocFunc`")
Reviewed-by: Alice Ryhl &lt;aliceryhl@google.com&gt;
Link: https://lore.kernel.org/r/20250731154919.4132-2-dakr@kernel.org
[ Remove `const` from Kmalloc::aligned_layout(). - Danilo ]
Signed-off-by: Danilo Krummrich &lt;dakr@kernel.org&gt;
</content>
</entry>
<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: types: add FOREIGN_ALIGN to ForeignOwnable</title>
<updated>2025-07-14T21:55:24Z</updated>
<author>
<name>Andreas Hindborg</name>
<email>a.hindborg@kernel.org</email>
</author>
<published>2025-06-12T13:09:43Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=12717ebeffcf3e34063dbc1e1b7f34924150c7c9'/>
<id>urn:sha1:12717ebeffcf3e34063dbc1e1b7f34924150c7c9</id>
<content type='text'>
The current implementation of `ForeignOwnable` is leaking the type of the
opaque pointer to consumers of the API. This allows consumers of the opaque
pointer to rely on the information that can be extracted from the pointer
type.

To prevent this, change the API to the version suggested by Maira
Canal (link below): Remove `ForeignOwnable::PointedTo` in favor of a
constant, which specifies the alignment of the pointers returned by
`into_foreign`.

With this change, `ArcInner` no longer needs `pub` visibility, so change it
to private.

Suggested-by: Alice Ryhl &lt;aliceryhl@google.com&gt;
Suggested-by: Maíra Canal &lt;mcanal@igalia.com&gt;
Link: https://lore.kernel.org/r/20240309235927.168915-3-mcanal@igalia.com
Acked-by: Danilo Krummrich &lt;dakr@kernel.org&gt;
Reviewed-by: Benno Lossin &lt;lossin@kernel.org&gt;
Signed-off-by: Andreas Hindborg &lt;a.hindborg@kernel.org&gt;
Reviewed-by: Alice Ryhl &lt;aliceryhl@google.com&gt;
Link: https://lore.kernel.org/r/20250612-pointed-to-v3-1-b009006d86a1@kernel.org
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</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 `KBox`</title>
<updated>2025-06-18T21:09:41Z</updated>
<author>
<name>Alexandre Courbot</name>
<email>acourbot@nvidia.com</email>
</author>
<published>2025-06-16T03:34:07Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=f86c0036c7de5fc379115809c653dfd57c453330'/>
<id>urn:sha1:f86c0036c7de5fc379115809c653dfd57c453330</id>
<content type='text'>
Implement `Borrow&lt;T&gt;` and `BorrowMut&lt;T&gt;` for `KBox&lt;T&gt;`. This allows
`KBox&lt;T&gt;` to be used in generic APIs asking for types implementing those
traits. `T` and `&amp;mut T` also implement those traits allowing users to
use either owned, borrowed and heap-owned values.

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-3-36f9beb3fe6a@nvidia.com
Signed-off-by: Danilo Krummrich &lt;dakr@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: alloc: add missing Markdown code span</title>
<updated>2025-05-25T20:58:35Z</updated>
<author>
<name>Miguel Ojeda</name>
<email>ojeda@kernel.org</email>
</author>
<published>2025-03-24T21:03:51Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=abd21a163d4188c180cabb6747b1d94e3c0586b9'/>
<id>urn:sha1:abd21a163d4188c180cabb6747b1d94e3c0586b9</id>
<content type='text'>
Add missing Markdown code span.

This was found using the Clippy `doc_markdown` lint, which we may want
to enable.

Fixes: dd09538fb409 ("rust: alloc: implement `Cmalloc` in module allocator_test")
Reviewed-by: Benno Lossin &lt;benno.lossin@proton.me&gt;
Acked-by: Danilo Krummrich &lt;dakr@kernel.org&gt;
Link: https://lore.kernel.org/r/20250324210359.1199574-5-ojeda@kernel.org
Signed-off-by: Miguel Ojeda &lt;ojeda@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>
</feed>
