Skip to content

`alloc`, `#[expect]` and "Custom FFI"

Miguel Ojeda linux-patches stable 1 version Applied

Status from this message: This is a note to let you know that I've just added the patch titled

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest60 patches 64 repliesApplied

Patches in v1 Applied

#Subject and filesSizeRepliesApplied
1/60rust: workqueue: remove unneeded ``#[allow(clippy::new_ret_no_self)]`rust/kernel/workqueue.rs+0 -11 reply
2/60rust: sort global Rust flagsMakefile+4 -41 reply
3/60rust: types: avoid repetition in `{As,From}Bytes` implsrust/kernel/types.rs+35 -331 reply
4/60rust: enable `clippy::undocumented_unsafe_blocks` lintMakefile mm/kasan/kasan_test_rust.rs rust/bindings/lib.rs +13 more+47 -101 reply
5/60rust: enable `clippy::unnecessary_safety_comment` lintMakefile rust/kernel/sync/arc.rs rust/kernel/workqueue.rs+4 -31 reply
6/60rust: enable `clippy::unnecessary_safety_doc` lintMakefile+1 -01 reply
7/60rust: enable `clippy::ignored_unit_patterns` lintMakefile rust/kernel/types.rs+2 -11 reply
8/60rust: enable `rustdoc::unescaped_backticks` lintMakefile rust/Makefile+6 -21 reply
9/60rust: init: remove unneeded `#[allow(clippy::disallowed_names)]`rust/kernel/init.rs+0 -41 reply
10/60rust: sync: remove unneeded `#[allow(clippy::non_send_fields_in_send_ty)]`rust/kernel/sync/condvar.rs+0 -11 reply
11/60rust: introduce `.clippy.toml`.clippy.toml .gitignore MAINTAINERS +1 more+6 -01 reply
12/60rust: replace `clippy::dbg_macro` with `disallowed_macros`.clippy.toml Makefile rust/kernel/std_vendor.rs +1 more+12 -61 reply
13/60rust: provide proper code documentation titlesrust/kernel/init/__internal.rs rust/kernel/std_vendor.rs rust/kernel/sync/arc/std_vendor.rs+8 -31 reply
14/60rust: enable Clippy's `check-private-items`.clippy.toml rust/kernel/init.rs rust/kernel/init/__internal.rs +2 more+7 -01 reply
15/60Documentation: rust: add coding guidelines on lintsDocumentation/rust/coding-guidelines.rst+38 -01 reply
16/60rust: start using the `#[expect(...)]` attributerust/kernel/error.rs rust/kernel/init.rs rust/kernel/init/__internal.rs +8 more+31 -301 reply
17/60Documentation: rust: discuss `#[expect(...)]` in the guidelinesDocumentation/rust/coding-guidelines.rst+110 -01 reply
18/60rust: error: make conversion functions publicrust/kernel/error.rs+4 -91 reply
19/60rust: error: optimize error type to use nonzerorust/kernel/error.rs+28 -91 reply
20/60rust: alloc: add `Allocator` traitrust/kernel/alloc.rs+101 -01 reply
21/60rust: alloc: separate `aligned_size` from `krealloc_aligned`rust/kernel/alloc/allocator.rs+12 -71 reply
22/60rust: alloc: rename `KernelAllocator` to `Kmalloc`rust/kernel/alloc/allocator.rs+3 -31 reply
23/60rust: alloc: implement `ReallocFunc`rust/kernel/alloc.rs rust/kernel/alloc/allocator.rs+79 -01 reply
24/60rust: alloc: make `allocator` module publicrust/kernel/alloc.rs+1 -11 reply
25/60rust: alloc: implement `Allocator` for `Kmalloc`rust/kernel/alloc/allocator.rs+28 -31 reply
26/60rust: alloc: add module `allocator_test`rust/kernel/alloc.rs rust/kernel/alloc/allocator_test.rs+27 -21 reply
27/60rust: alloc: implement `Vmalloc` allocatorrust/helpers/helpers.c rust/helpers/vmalloc.c rust/kernel/alloc/allocator.rs +1 more+48 -01 reply
28/60rust: alloc: implement `KVmalloc` allocatorrust/helpers/slab.c rust/kernel/alloc/allocator.rs rust/kernel/alloc/allocator_test.rs+43 -01 reply
29/60rust: alloc: add __GFP_NOWARN to `Flags`rust/bindings/bindings_helper.h rust/kernel/alloc.rs+6 -01 reply
30/60rust: alloc: implement kernel `Box`rust/kernel/alloc.rs rust/kernel/alloc/kbox.rs rust/kernel/prelude.rs+463 -11 reply
31/60rust: treewide: switch to our kernel `Box` typedrivers/block/rnull.rs rust/kernel/init.rs rust/kernel/init/__internal.rs +7 more+81 -761 reply
32/60rust: alloc: remove extension of std's `Box`rust/kernel/alloc.rs rust/kernel/alloc/box_ext.rs rust/kernel/init.rs +3 more+3 -1881 reply
33/60rust: alloc: add `Box` to preluderust/kernel/prelude.rs+1 -11 reply
34/60rust: alloc: introduce `ArrayLayout`rust/kernel/alloc.rs rust/kernel/alloc/layout.rs+92 -01 reply
35/60rust: alloc: implement kernel `Vec` typerust/kernel/alloc.rs rust/kernel/alloc/kvec.rs rust/kernel/lib.rs +1 more+656 -11 reply
36/60rust: alloc: implement `IntoIterator` for `Vec`rust/kernel/alloc.rs rust/kernel/alloc/kvec.rs+171 -01 reply
37/60rust: alloc: implement `collect` for `IntoIter`rust/kernel/alloc/kvec.rs+95 -01 reply
38/60rust: treewide: switch to the kernel `Vec` typemm/kasan/kasan_test_rust.rs rust/kernel/str.rs rust/kernel/sync/locked_by.rs +4 more+20 -251 reply
39/60rust: alloc: remove `VecExt` extensionrust/kernel/alloc.rs rust/kernel/alloc/vec_ext.rs rust/kernel/prelude.rs+1 -1901 reply
40/60rust: alloc: add `Vec` to preluderust/kernel/prelude.rs+1 -11 reply
41/60rust: error: use `core::alloc::LayoutError`rust/kernel/error.rs+1 -11 reply
42/60rust: error: check for config `test` in `Error::name`rust/kernel/error.rs+2 -21 reply
43/60rust: alloc: implement `contains` for `Flags`rust/kernel/alloc.rs+6 -11 reply
44/60rust: alloc: implement `Cmalloc` in module allocator_testrust/kernel/alloc.rs rust/kernel/alloc/allocator_test.rs+81 -91 reply
45/60rust: str: test: replace `alloc::format`rust/kernel/str.rs+22 -11 reply
46/60rust: alloc: update module comment of alloc.rsrust/kernel/alloc.rs+1 -11 reply
47/60kbuild: rust: remove the `alloc` crate and `GlobalAlloc`rust/Makefile rust/exports.c rust/kernel/alloc/allocator.rs +2 more+16 -1081 reply
48/60MAINTAINERS: add entry for the Rust `alloc` moduleMAINTAINERS+7 -01 reply
49/60drm/panic: avoid reimplementing Iterator::finddrivers/gpu/drm/drm_panic_qr.rs+3 -61 reply
50/60drm/panic: remove unnecessary borrow in alignment_patterndrivers/gpu/drm/drm_panic_qr.rs+1 -11 reply
51/60drm/panic: prefer eliding lifetimesdrivers/gpu/drm/drm_panic_qr.rs+1 -11 reply
52/60drm/panic: remove redundant field when assigning valuedrivers/gpu/drm/drm_panic_qr.rs+1 -11 reply
53/60drm/panic: correctly indent continuation of line in list itemdrivers/gpu/drm/drm_panic_qr.rs+1 -11 reply
54/60drm/panic: allow verbose boolean for claritydrivers/gpu/drm/drm_panic_qr.rs+4 -11 reply
55/60drm/panic: allow verbose version checkdrivers/gpu/drm/drm_panic_qr.rs+1 -01 reply
56/60rust: kbuild: expand rusttest target for macrosrust/Makefile rust/macros/lib.rs+14 -51 reply
57/60rust: fix size_t in bindgen prototypes of C builtinsrust/Makefile+5 -11 reply
58/60rust: map `__kernel_size_t` and friends also to usize/isizerust/bindgen_parameters rust/bindings/lib.rs rust/uapi/lib.rs+15 -01 reply
59/60rust: use custom FFI integer typesrust/Makefile rust/ffi.rs rust/kernel/alloc/allocator.rs +20 more+107 -831 reply
60/60rust: alloc: Fix `ArrayLayout` allocationsrust/kernel/alloc/layout.rs+1 -11 reply

Reviews trailers per patch

55 of 60 patches have a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchAlice RyhlTrevor GrossGary GuoVincenzo PalazzoBenno LossinFiona BehrensJocelyn FalempeDanilo KrummrichNeal Gompa
SeriesR-b R-b A-b A-b
1/60R-b R-b R-b R-b T-b R-b T-b R-b
2/60R-b R-b R-b R-b T-b R-b T-b R-b
3/60R-b R-b R-b R-b T-b R-b T-b R-b
4/60R-b R-b R-b R-b T-b R-b T-b R-b
5/60R-b R-b R-b R-b T-b R-b T-b R-b R-b R-b
6/60R-b R-b R-b R-b T-b R-b T-b R-b
7/60R-b R-b R-b R-b T-b R-b T-b R-b
8/60R-b R-b R-b R-b T-b R-b T-b R-b
9/60R-b R-b R-b R-b T-b R-b T-b R-b
10/60R-b R-b R-b R-b T-b R-b T-b R-b
11/60R-b R-b R-b R-b T-b R-b T-b R-b
12/60T-b R-b T-b R-b
13/60R-b R-b R-b R-b T-b R-b T-b R-b
14/60R-b R-b R-b R-b T-b R-b T-b R-b
15/60R-b R-b R-b R-b T-b R-b T-b R-b
16/60R-b R-b R-b R-b T-b R-b T-b R-b
17/60T-b R-b T-b R-b
18/60R-b R-b R-b R-b R-b R-b
19/60R-b R-b R-b R-b R-b R-b
20/60R-b R-b R-b R-b R-b R-b
21/60R-b R-b R-b R-b R-b R-b
22/60R-b R-b R-b R-b R-b R-b
23/60R-b R-b R-b R-b
24/60R-b R-b R-b R-b
25/60R-b R-b R-b R-b
26/60R-b R-b R-b R-b R-b R-b
27/60R-b R-b R-b R-b R-b R-b
28/60R-b R-b R-b R-b R-b R-b
29/60R-b R-b R-b R-b R-b R-b
30/60R-b R-b R-b R-b
31/60R-b R-b R-b R-b R-b R-b
32/60R-b R-b R-b R-b R-b R-b
33/60R-b R-b R-b R-b R-b R-b
34/60R-b R-b
35/60R-b R-b R-b R-b
36/60R-b R-b R-b R-b R-b R-b
37/60R-b R-b R-b R-b
38/60R-b R-b R-b R-b R-b R-b
39/60R-b R-b R-b R-b R-b R-b
40/60R-b R-b R-b R-b R-b R-b
41/60R-b R-b R-b R-b R-b R-b
42/60R-b R-b R-b R-b R-b R-b
43/60R-b R-b R-b R-b R-b R-b
44/60R-b R-b R-b R-b
45/60R-b R-b R-b R-b R-b R-b
46/60R-b R-b R-b R-b R-b R-b
47/60
48/60
49/60R-b R-b
50/60R-b R-b
51/60R-b R-b
52/60R-b R-b
53/60R-b R-b
54/60R-b R-b
55/60R-b R-b
56/60
57/60
58/60R-b R-b R-b R-b
59/60
60/60A-b A-b R-b R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 9 reviewers.

Read the v1 thread

Cover letter [PATCH 6.12.y 00/60] `alloc`, `#[expect]` and "Custom FFI"

Hi Greg, Sasha,

Please consider this series for 6.12.y. It should apply cleanly on top of v6.12.18.

These are the patches to backport the alloc series for Rust, which will be useful for Rust Android Binder and others. It also means that, with this applied, we will not rely on the standard library alloc (and the unstable cfg option we used) anymore in any stable kernel that supports several Rust versions, so e.g. upstream Rust could consider removing that cfg if they needed.

The entire series of cherry-picks apply almost cleanly (only 2 trivial conflicts) -- to achieve that, I included the #[expect] support, which will make future backports that use that feature easier anyway. That series also enabled some Clippy warnings. We could reduce the series, but the end result is warning-free and Clippy is opt-in anyway. Out-of-tree code could, of course, see some warnings if they use it.

I also included a bunch of Clippy warnings cleanups for the DRM QR Code to have this series clean up to Rust 1.85.0 (the latest stable), but I could send them separately if needed.

Finally, I included the "Custom FFI" series backport, which in turn solves the arm64 + Rust 1.85.0 + CONFIG_RUST_FW_LOADER_ABSTRACTIONS=y issue. It will also make future patches easier to backport, since we will have the same ffi:: types.

I tested that the entire series builds between every commit for x86_64 LLVM=1 with the latest stable and minimum supported Rust compiler versions. I also ran my usual stable kernel tests on the end result; that is, boot-tested in QEMU for several architectures etc. In v6.12.18 for loongarch there is an unrelated error that was not there in v6.12.17 when I did a previous test run -- reported separately.

Things could still break, so extra tests on the next -rc from users in Cc here would be welcome -- thanks!

Cheers,
Miguel

Asahi Lina (1):
rust: alloc: Fix ArrayLayout allocations

Benno Lossin (1):
rust: alloc: introduce ArrayLayout

Danilo Krummrich (28):
rust: alloc: add Allocator trait
rust: alloc: separate aligned_size from krealloc_aligned
rust: alloc: rename KernelAllocator to Kmalloc
rust: alloc: implement ReallocFunc
rust: alloc: make allocator module public
rust: alloc: implement Allocator for Kmalloc
rust: alloc: add module allocator_test
rust: alloc: implement Vmalloc allocator
rust: alloc: implement KVmalloc allocator
rust: alloc: add __GFP_NOWARN to Flags
rust: alloc: implement kernel Box
rust: treewide: switch to our kernel Box type
rust: alloc: remove extension of std's Box
rust: alloc: add Box to prelude
rust: alloc: implement kernel Vec type
rust: alloc: implement IntoIterator for Vec
rust: alloc: implement collect for IntoIter
rust: treewide: switch to the kernel Vec type
rust: alloc: remove VecExt extension
rust: alloc: add Vec to prelude
rust: error: use core::alloc::LayoutError
rust: error: check for config test in Error::name
rust: alloc: implement contains for Flags
rust: alloc: implement Cmalloc in module allocator_test
rust: str: test: replace alloc::format
rust: alloc: update module comment of alloc.rs
kbuild: rust: remove the alloc crate and GlobalAlloc
MAINTAINERS: add entry for the Rust alloc module

Ethan D. Twardy (1):
rust: kbuild: expand rusttest target for macros

Filipe Xavier (2):
rust: error: make conversion functions public
rust: error: optimize error type to use nonzero

Gary Guo (3):
rust: fix size_t in bindgen prototypes of C builtins
rust: map __kernel_size_t and friends also to usize/isize
rust: use custom FFI integer types

Miguel Ojeda (17):
rust: workqueue: remove unneeded ``#[allow(clippy::new_ret_no_self)]`
rust: sort global Rust flags
rust: types: avoid repetition in {As,From}Bytes impls
rust: enable clippy::undocumented_unsafe_blocks lint
rust: enable clippy::unnecessary_safety_comment lint
rust: enable clippy::unnecessary_safety_doc lint
rust: enable clippy::ignored_unit_patterns lint
rust: enable rustdoc::unescaped_backticks lint
rust: init: remove unneeded #[allow(clippy::disallowed_names)]
rust: sync: remove unneeded

    `#[allow(clippy::non_send_fields_in_send_ty)]`

rust: introduce .clippy.toml
rust: replace clippy::dbg_macro with disallowed_macros
rust: provide proper code documentation titles
rust: enable Clippy's check-private-items
Documentation: rust: add coding guidelines on lints
rust: start using the #[expect(...)] attribute
Documentation: rust: discuss #[expect(...)] in the guidelines

Thomas Böhler (7):
drm/panic: avoid reimplementing Iterator::find drm/panic: remove unnecessary borrow in alignment_pattern drm/panic: prefer eliding lifetimes
drm/panic: remove redundant field when assigning value drm/panic: correctly indent continuation of line in list item drm/panic: allow verbose boolean for clarity drm/panic: allow verbose version check

 .clippy.toml                             |   9 +
 .gitignore                               |   1 +
 Documentation/rust/coding-guidelines.rst | 148 ++++
 MAINTAINERS                              |   8 +
 Makefile                                 |  15 +-
 drivers/block/rnull.rs                   |   4 +-
 drivers/gpu/drm/drm_panic_qr.rs          |  23 +-
 mm/kasan/kasan_test_rust.rs              |   3 +-
 rust/Makefile                            |  92 +--
 rust/bindgen_parameters                  |   5 +
 rust/bindings/bindings_helper.h          |   1 +
 rust/bindings/lib.rs                     |   6 +
 rust/exports.c                           |   1 -
 rust/ffi.rs                              |  13 +
 rust/helpers/helpers.c                   |   1 +
 rust/helpers/slab.c                      |   6 +
 rust/helpers/vmalloc.c                   |   9 +
 rust/kernel/alloc.rs                     | 150 +++-
 rust/kernel/alloc/allocator.rs           | 208 ++++--
 rust/kernel/alloc/allocator_test.rs      |  95 +++
 rust/kernel/alloc/box_ext.rs             |  89 ---
 rust/kernel/alloc/kbox.rs                | 456 +++++++++++
 rust/kernel/alloc/kvec.rs                | 913 +++++++++++++++++++++++
 rust/kernel/alloc/layout.rs              |  91 +++
 rust/kernel/alloc/vec_ext.rs             | 185 -----
 rust/kernel/block/mq/operations.rs       |  18 +-
 rust/kernel/block/mq/raw_writer.rs       |   2 +-
 rust/kernel/block/mq/tag_set.rs          |   2 +-
 rust/kernel/error.rs                     |  79 +-
 rust/kernel/init.rs                      | 127 ++--
 rust/kernel/init/__internal.rs           |  13 +-
 rust/kernel/init/macros.rs               |  18 +-
 rust/kernel/ioctl.rs                     |   2 +-
 rust/kernel/lib.rs                       |   5 +-
 rust/kernel/list.rs                      |   1 +
 rust/kernel/list/arc_field.rs            |   2 +-
 rust/kernel/net/phy.rs                   |  16 +-
 rust/kernel/prelude.rs                   |   5 +-
 rust/kernel/print.rs                     |   5 +-
 rust/kernel/rbtree.rs                    |  49 +-
 rust/kernel/std_vendor.rs                |  12 +-
 rust/kernel/str.rs                       |  46 +-
 rust/kernel/sync/arc.rs                  |  25 +-
 rust/kernel/sync/arc/std_vendor.rs       |   2 +
 rust/kernel/sync/condvar.rs              |   7 +-
 rust/kernel/sync/lock.rs                 |   8 +-
 rust/kernel/sync/lock/mutex.rs           |   4 +-
 rust/kernel/sync/lock/spinlock.rs        |   4 +-
 rust/kernel/sync/locked_by.rs            |   2 +-
 rust/kernel/task.rs                      |   8 +-
 rust/kernel/time.rs                      |   4 +-
 rust/kernel/types.rs                     | 140 ++--
 rust/kernel/uaccess.rs                   |  23 +-
 rust/kernel/workqueue.rs                 |  29 +-
 rust/macros/lib.rs                       |  14 +-
 rust/macros/module.rs                    |   8 +-
 rust/uapi/lib.rs                         |   6 +
 samples/rust/rust_minimal.rs             |   4 +-
 samples/rust/rust_print.rs               |   1 +
 scripts/Makefile.build                   |   4 +-
 scripts/generate_rust_analyzer.py        |  11 +-
 61 files changed, 2482 insertions(+), 756 deletions(-)
 create mode 100644 .clippy.toml
 create mode 100644 rust/ffi.rs
 create mode 100644 rust/helpers/vmalloc.c
 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
 create mode 100644 rust/kernel/alloc/layout.rs
 delete mode 100644 rust/kernel/alloc/vec_ext.rs

--
2.48.1