Skip to content

Generic `Allocator` support for Rust

Danilo Krummrich lkml oe-kbuild-all rust-for-linux 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest20 patches 19 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/20rust: alloc: add `Allocator` traitrust/kernel/alloc.rs+73 -08 replies
2/20rust: alloc: separate `aligned_size` from `krealloc_aligned`rust/kernel/alloc/allocator.rs+18 -80 replies
3/20rust: alloc: rename `KernelAllocator` to `Kmalloc`rust/kernel/alloc/allocator.rs+3 -30 replies
4/20rust: alloc: implement `Allocator` for `Kmalloc`rust/kernel/alloc.rs rust/kernel/alloc/allocator.rs+63 -132 replies
5/20rust: alloc: add module `allocator_test`rust/kernel/alloc.rs rust/kernel/alloc/allocator_test.rs+28 -20 replies
6/20rust: alloc: remove `krealloc_aligned`rust/kernel/alloc/allocator.rs rust/kernel/alloc/box_ext.rs rust/kernel/alloc/vec_ext.rs+17 -400 replies
7/20rust: alloc: implement `Vmalloc` allocatorrust/bindings/bindings_helper.h rust/kernel/alloc/allocator.rs rust/kernel/alloc/allocator_test.rs+57 -04 replies
8/20rust: alloc: implement `KVmalloc` allocatorrust/kernel/alloc/allocator.rs rust/kernel/alloc/allocator_test.rs+36 -00 replies
9/20rust: types: implement `Unique<T>`rust/kernel/types.rs+176 -03 replies
10/20rust: alloc: implement `KBox`rust/kernel/alloc.rs rust/kernel/alloc/kbox.rs rust/kernel/init.rs +2 more+377 -20 replies
11/20rust: treewide: switch to `KBox`rust/kernel/init.rs rust/kernel/init/__internal.rs rust/kernel/sync/arc.rs +4 more+59 -550 replies
12/20rust: alloc: remove `BoxExt` extensionrust/kernel/alloc.rs rust/kernel/alloc/box_ext.rs rust/kernel/init.rs +3 more+3 -1110 replies
13/20rust: alloc: implement `KVec`rust/kernel/alloc.rs rust/kernel/alloc/kbox.rs rust/kernel/alloc/kvec.rs +1 more+623 -20 replies
14/20rust: alloc: implement `IntoIterator` for `KVec`rust/kernel/alloc.rs rust/kernel/alloc/kvec.rs+177 -10 replies
15/20rust: alloc: implement `collect` for `IntoIter`rust/kernel/alloc/kvec.rs+82 -12 replies
16/20rust: treewide: switch to `KVec`rust/kernel/str.rs rust/kernel/sync/locked_by.rs rust/kernel/types.rs +1 more+9 -110 replies
17/20rust: alloc: remove `VecExt` extensionrust/kernel/alloc.rs rust/kernel/alloc/vec_ext.rs rust/kernel/prelude.rs+1 -1900 replies
18/20rust: error: use `core::alloc::LayoutError`rust/kernel/error.rs+1 -10 replies
19/20rust: str: test: replace `alloc::format`rust/kernel/str.rs+46 -200 replies
20/20kbuild: rust: remove the `alloc` craterust/Makefile rust/exports.c scripts/Makefile.build+11 -410 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 00/20] Generic `Allocator` support for Rust

Hi,

This patch series adds generic kernel allocator support for Rust, which so far is limited to kmalloc allocations.

In order to abstain from (re-)adding unstable Rust features to the kernel, this patch series does not extend the Allocator trait from Rust's alloc crate, nor does it extend the BoxExt and VecExt extensions.

Instead, this series introduces a kernel specific Allocator trait, which is implemented by the Kmalloc, Vmalloc and KVmalloc allocators, also implemented in the context of this series.

As a consequence we need our own Box and Vec types, which are implemented by this series as KBox and KVec.

With that, we can start using KBox and KVec throughout the tree and remove the now obolete extensions BoxExt and VecExt.

For a final cleanup, this series removes the last minor dependencies to Rust's alloc crate and removes it from the entire kernel build.

The series ensures not to break the rusttest make target by implementing the allocator_test module providing a stub implementation for all kernel Allocators.

This patch series passes all KUnit tests, including the ones added by this series. Additionally, the tests were run with kmemleak and KASAN enabled, without any issues.

This series is also available in [1].

[1] https://gitlab.freedesktop.org/drm/nova/-/tree/topic/allocator

Danilo Krummrich (20):
rust: alloc: add Allocator trait
rust: alloc: separate aligned_size from krealloc_aligned
rust: alloc: rename KernelAllocator to Kmalloc
rust: alloc: implement Allocator for Kmalloc
rust: alloc: add module allocator_test
rust: alloc: remove krealloc_aligned
rust: alloc: implement Vmalloc allocator
rust: alloc: implement KVmalloc allocator
rust: types: implement Unique<T>
rust: alloc: implement KBox
rust: treewide: switch to KBox
rust: alloc: remove BoxExt extension
rust: alloc: implement KVec
rust: alloc: implement IntoIterator for KVec
rust: alloc: implement collect for IntoIter
rust: treewide: switch to KVec
rust: alloc: remove VecExt extension
rust: error: use core::alloc::LayoutError
rust: str: test: replace alloc::format
kbuild: rust: remove the alloc crate

 rust/Makefile                       |  44 +-
 rust/bindings/bindings_helper.h     |   1 +
 rust/exports.c                      |   1 -
 rust/kernel/alloc.rs                |  92 ++-
 rust/kernel/alloc/allocator.rs      | 177 +++++-
 rust/kernel/alloc/allocator_test.rs |  23 +
 rust/kernel/alloc/box_ext.rs        |  56 --
 rust/kernel/alloc/kbox.rs           | 333 +++++++++++
 rust/kernel/alloc/kvec.rs           | 861 ++++++++++++++++++++++++++++
 rust/kernel/alloc/vec_ext.rs        | 182 ------
 rust/kernel/error.rs                |   2 +-
 rust/kernel/init.rs                 |  72 +--
 rust/kernel/init/__internal.rs      |   2 +-
 rust/kernel/lib.rs                  |   1 -
 rust/kernel/prelude.rs              |   5 +-
 rust/kernel/str.rs                  |  78 ++-
 rust/kernel/sync/arc.rs             |  17 +-
 rust/kernel/sync/condvar.rs         |   5 +-
 rust/kernel/sync/lock/mutex.rs      |   3 +-
 rust/kernel/sync/lock/spinlock.rs   |   3 +-
 rust/kernel/sync/locked_by.rs       |   2 +-
 rust/kernel/types.rs                | 186 +++++-
 rust/kernel/workqueue.rs            |  22 +-
 samples/rust/rust_minimal.rs        |   4 +-
 scripts/Makefile.build              |   7 +-
 25 files changed, 1769 insertions(+), 410 deletions(-)
 create mode 100644 rust/kernel/alloc/allocator_test.rs
 delete mode 100644 rust/kernel/alloc/box_ext.rs
 create mode 100644 rust/kernel/alloc/kbox.rs
 create mode 100644 rust/kernel/alloc/kvec.rs
 delete mode 100644 rust/kernel/alloc/vec_ext.rs

base-commit: 1613e604df0cd359cf2a7fbd9be7a0bcfacfabd0

Signature · 1 line
2.45.2