`alloc`, `#[expect]` and "Custom FFI"
Subsystems (20)
Patch "rust: alloc: introduce `ArrayLayout`" has been added to the 6.12-stable tree
In reply to Miguel OjedaThis is a note to let you know that I've just added the patch titled
rust: alloc: introduce ArrayLayout
to the 6.12-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
rust-alloc-introduce-arraylayout.patch
and it can be found in the queue-6.12 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
From [email protected] Fri Mar 7 23:52:14 2025
From: Miguel Ojeda <[email protected]>
Date: Fri, 7 Mar 2025 23:49:41 +0100
Subject: rust: alloc: introduce ArrayLayout
To: Greg Kroah-Hartman <[email protected]>, Sasha Levin <[email protected]>, [email protected]
Cc: Danilo Krummrich <[email protected]>, Alice Ryhl <[email protected]>, Alyssa Ross <[email protected]>, NoisyCoil <[email protected]>, [email protected], Miguel Ojeda <[email protected]>
Message-ID: <[email protected]>
From: Benno Lossin <[email protected]>
commit 9e7bbfa182767f638ba61dba3518ff78da9f31ff upstream.
When allocating memory for arrays using allocators, the Layout::array function is typically used. It returns a result, since the given size might be too big. However, Vec and its iterators store their allocated capacity and thus they already did check that the size is not too big.
The ArrayLayout type provides this exact behavior, as it can be infallibly converted into a Layout. Instead of a usize capacity, Vec and other similar array-storing types can use ArrayLayout instead.
--- rust/kernel/alloc.rs | 1 rust/kernel/alloc/layout.rs | 91 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 rust/kernel/alloc/layout.rs
rust/kernel/alloc.rs +1 -0
@@ -5,6 +5,7 @@#[cfg(not(any(test, testlib)))] pub mod allocator;pub mod kbox; +pub mod layout;pub mod vec_ext;#[cfg(any(test, testlib))]
rust/kernel/alloc/layout.rs new file +91 -0
91 lines not on this page · raw message
Patches currently in stable-queue which might be from [email protected] are
queue-6.12/drm-panic-avoid-reimplementing-iterator-find.patch queue-6.12/documentation-rust-add-coding-guidelines-on-lints.patch queue-6.12/rust-provide-proper-code-documentation-titles.patch queue-6.12/rust-alloc-make-allocator-module-public.patch queue-6.12/rust-alloc-remove-vecext-extension.patch queue-6.12/rust-alloc-implement-reallocfunc.patch queue-6.12/rust-alloc-separate-aligned_size-from-krealloc_aligned.patch queue-6.12/rust-enable-clippy-unnecessary_safety_comment-lint.patch queue-6.12/rust-alloc-update-module-comment-of-alloc.rs.patch queue-6.12/rust-kbuild-expand-rusttest-target-for-macros.patch queue-6.12/rust-error-use-core-alloc-layouterror.patch queue-6.12/rust-str-test-replace-alloc-format.patch queue-6.12/loongarch-use-asm_reachable.patch queue-6.12/rust-alloc-implement-allocator-for-kmalloc.patch queue-6.12/rust-alloc-implement-collect-for-intoiter.patch queue-6.12/rust-alloc-introduce-arraylayout.patch queue-6.12/rust-alloc-implement-vmalloc-allocator.patch queue-6.12/documentation-rust-discuss-in-the-guidelines.patch queue-6.12/rust-error-check-for-config-test-in-error-name.patch queue-6.12/rust-enable-clippy-ignored_unit_patterns-lint.patch queue-6.12/rust-enable-clippy-unnecessary_safety_doc-lint.patch queue-6.12/rust-alloc-add-box-to-prelude.patch queue-6.12/kbuild-rust-remove-the-alloc-crate-and-globalalloc.patch queue-6.12/rust-alloc-add-allocator-trait.patch queue-6.12/rust-treewide-switch-to-our-kernel-box-type.patch queue-6.12/rust-introduce-.clippy.toml.patch queue-6.12/rust-alloc-rename-kernelallocator-to-kmalloc.patch queue-6.12/rust-alloc-implement-cmalloc-in-module-allocator_test.patch queue-6.12/drm-panic-allow-verbose-version-check.patch queue-6.12/rust-map-__kernel_size_t-and-friends-also-to-usize-isize.patch queue-6.12/rust-alloc-add-module-allocator_test.patch queue-6.12/rust-replace-clippy-dbg_macro-with-disallowed_macros.patch queue-6.12/rust-alloc-add-__gfp_nowarn-to-flags.patch queue-6.12/rust-enable-clippy-s-check-private-items.patch queue-6.12/rust-error-make-conversion-functions-public.patch queue-6.12/rust-sort-global-rust-flags.patch queue-6.12/rust-alloc-implement-contains-for-flags.patch queue-6.12/rust-init-remove-unneeded.patch queue-6.12/rust-use-custom-ffi-integer-types.patch queue-6.12/rust-sync-remove-unneeded.patch queue-6.12/rust-treewide-switch-to-the-kernel-vec-type.patch queue-6.12/rust-alloc-implement-kvmalloc-allocator.patch queue-6.12/drm-panic-correctly-indent-continuation-of-line-in-list-item.patch queue-6.12/rust-alloc-implement-kernel-vec-type.patch queue-6.12/rust-workqueue-remove-unneeded.patch queue-6.12/rust-error-optimize-error-type-to-use-nonzero.patch queue-6.12/drm-panic-remove-unnecessary-borrow-in-alignment_pattern.patch queue-6.12/rust-alloc-remove-extension-of-std-s-box.patch queue-6.12/rust-block-fix-formatting-in-gendisk-doc.patch queue-6.12/rust-enable-rustdoc-unescaped_backticks-lint.patch queue-6.12/rust-fix-size_t-in-bindgen-prototypes-of-c-builtins.patch queue-6.12/rust-enable-clippy-undocumented_unsafe_blocks-lint.patch queue-6.12/rust-alloc-add-vec-to-prelude.patch queue-6.12/rust-alloc-implement-intoiterator-for-vec.patch queue-6.12/rust-alloc-implement-kernel-box.patch queue-6.12/drm-panic-remove-redundant-field-when-assigning-value.patch queue-6.12/rust-types-avoid-repetition-in-as-from-bytes-impls.patch queue-6.12/rust-start-using-the-attribute.patch queue-6.12/drm-panic-allow-verbose-boolean-for-clarity.patch queue-6.12/maintainers-add-entry-for-the-rust-alloc-module.patch queue-6.12/rust-alloc-fix-arraylayout-allocations.patch queue-6.12/drm-panic-prefer-eliding-lifetimes.patch
Patch "rust: enable `clippy::unnecessary_safety_doc` lint" has been added to the 6.12-stable tree
In reply to Miguel OjedaThis is a note to let you know that I've just added the patch titled
rust: enable clippy::unnecessary_safety_doc lint
to the 6.12-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
rust-enable-clippy-unnecessary_safety_doc-lint.patch
and it can be found in the queue-6.12 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
From [email protected] Fri Mar 7 23:50:58 2025
From: Miguel Ojeda <[email protected]>
Date: Fri, 7 Mar 2025 23:49:13 +0100
Subject: rust: enable clippy::unnecessary_safety_doc lint
To: Greg Kroah-Hartman <[email protected]>, Sasha Levin <[email protected]>, [email protected]
Cc: Danilo Krummrich <[email protected]>, Alice Ryhl <[email protected]>, Alyssa Ross <[email protected]>, NoisyCoil <[email protected]>, [email protected], Miguel Ojeda <[email protected]>
Message-ID: <[email protected]>
From: Miguel Ojeda <[email protected]>
commit 23f42dc054b3c550373eae0c9ae97f1ce1501e0a upstream.
In Rust 1.67.0, Clippy added the unnecessary_safety_doc lint [1], which is similar to unnecessary_safety_comment, but for # Safety sections, i.e. safety preconditions in the documentation.
This is something that should not happen with our coding guidelines in mind. Thus enable the lint to have it machine-checked.
--- Makefile | 1 + 1 file changed, 1 insertion(+)
Makefile +1 -0
@@ -460,6 +460,7 @@ export rust_common_flags := --edition=20 -Wclippy::no_mangle_with_rust_abi \ -Wclippy::undocumented_unsafe_blocks \ -Wclippy::unnecessary_safety_comment \ + -Wclippy::unnecessary_safety_doc \ -Wrustdoc::missing_crate_level_docs KBUILD_HOSTCFLAGS := $(KBUILD_USERHOSTCFLAGS) $(HOST_LFS_CFLAGS) \
Patches currently in stable-queue which might be from [email protected] are
queue-6.12/drm-panic-avoid-reimplementing-iterator-find.patch queue-6.12/documentation-rust-add-coding-guidelines-on-lints.patch queue-6.12/rust-provide-proper-code-documentation-titles.patch queue-6.12/rust-alloc-make-allocator-module-public.patch queue-6.12/rust-alloc-remove-vecext-extension.patch queue-6.12/rust-alloc-implement-reallocfunc.patch queue-6.12/rust-alloc-separate-aligned_size-from-krealloc_aligned.patch queue-6.12/rust-enable-clippy-unnecessary_safety_comment-lint.patch queue-6.12/rust-alloc-update-module-comment-of-alloc.rs.patch queue-6.12/rust-kbuild-expand-rusttest-target-for-macros.patch queue-6.12/rust-error-use-core-alloc-layouterror.patch queue-6.12/rust-str-test-replace-alloc-format.patch queue-6.12/loongarch-use-asm_reachable.patch queue-6.12/rust-alloc-implement-allocator-for-kmalloc.patch queue-6.12/rust-alloc-implement-collect-for-intoiter.patch queue-6.12/rust-alloc-introduce-arraylayout.patch queue-6.12/rust-alloc-implement-vmalloc-allocator.patch queue-6.12/documentation-rust-discuss-in-the-guidelines.patch queue-6.12/rust-error-check-for-config-test-in-error-name.patch queue-6.12/rust-enable-clippy-ignored_unit_patterns-lint.patch queue-6.12/rust-enable-clippy-unnecessary_safety_doc-lint.patch queue-6.12/rust-alloc-add-box-to-prelude.patch queue-6.12/kbuild-rust-remove-the-alloc-crate-and-globalalloc.patch queue-6.12/rust-alloc-add-allocator-trait.patch queue-6.12/rust-treewide-switch-to-our-kernel-box-type.patch queue-6.12/rust-introduce-.clippy.toml.patch queue-6.12/rust-alloc-rename-kernelallocator-to-kmalloc.patch queue-6.12/rust-alloc-implement-cmalloc-in-module-allocator_test.patch queue-6.12/drm-panic-allow-verbose-version-check.patch queue-6.12/rust-map-__kernel_size_t-and-friends-also-to-usize-isize.patch queue-6.12/rust-alloc-add-module-allocator_test.patch queue-6.12/rust-replace-clippy-dbg_macro-with-disallowed_macros.patch queue-6.12/rust-alloc-add-__gfp_nowarn-to-flags.patch queue-6.12/rust-enable-clippy-s-check-private-items.patch queue-6.12/rust-error-make-conversion-functions-public.patch queue-6.12/rust-sort-global-rust-flags.patch queue-6.12/rust-alloc-implement-contains-for-flags.patch queue-6.12/rust-init-remove-unneeded.patch queue-6.12/rust-use-custom-ffi-integer-types.patch queue-6.12/rust-sync-remove-unneeded.patch queue-6.12/rust-treewide-switch-to-the-kernel-vec-type.patch queue-6.12/rust-alloc-implement-kvmalloc-allocator.patch queue-6.12/drm-panic-correctly-indent-continuation-of-line-in-list-item.patch queue-6.12/rust-alloc-implement-kernel-vec-type.patch queue-6.12/rust-workqueue-remove-unneeded.patch queue-6.12/rust-error-optimize-error-type-to-use-nonzero.patch queue-6.12/drm-panic-remove-unnecessary-borrow-in-alignment_pattern.patch queue-6.12/rust-alloc-remove-extension-of-std-s-box.patch queue-6.12/rust-block-fix-formatting-in-gendisk-doc.patch queue-6.12/rust-enable-rustdoc-unescaped_backticks-lint.patch queue-6.12/rust-fix-size_t-in-bindgen-prototypes-of-c-builtins.patch queue-6.12/rust-enable-clippy-undocumented_unsafe_blocks-lint.patch queue-6.12/rust-alloc-add-vec-to-prelude.patch queue-6.12/rust-alloc-implement-intoiterator-for-vec.patch queue-6.12/rust-alloc-implement-kernel-box.patch queue-6.12/drm-panic-remove-redundant-field-when-assigning-value.patch queue-6.12/rust-types-avoid-repetition-in-as-from-bytes-impls.patch queue-6.12/rust-start-using-the-attribute.patch queue-6.12/drm-panic-allow-verbose-boolean-for-clarity.patch queue-6.12/maintainers-add-entry-for-the-rust-alloc-module.patch queue-6.12/rust-alloc-fix-arraylayout-allocations.patch queue-6.12/drm-panic-prefer-eliding-lifetimes.patch
Patch "rust: enable `rustdoc::unescaped_backticks` lint" has been added to the 6.12-stable tree
In reply to Miguel OjedaThis is a note to let you know that I've just added the patch titled
rust: enable rustdoc::unescaped_backticks lint
to the 6.12-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
rust-enable-rustdoc-unescaped_backticks-lint.patch
and it can be found in the queue-6.12 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
From [email protected] Fri Mar 7 23:51:00 2025
From: Miguel Ojeda <[email protected]>
Date: Fri, 7 Mar 2025 23:49:15 +0100
Subject: rust: enable rustdoc::unescaped_backticks lint
To: Greg Kroah-Hartman <[email protected]>, Sasha Levin <[email protected]>, [email protected]
Cc: Danilo Krummrich <[email protected]>, Alice Ryhl <[email protected]>, Alyssa Ross <[email protected]>, NoisyCoil <[email protected]>, [email protected], Miguel Ojeda <[email protected]>
Message-ID: <[email protected]>
From: Miguel Ojeda <[email protected]>
commit bef83245f5ed434932aaf07f890142b576dc5d85 upstream.
In Rust 1.71.0, rustdoc added the unescaped_backticks lint, which detects what are typically typos in Markdown formatting regarding inline code [1], e.g. from the Rust standard library:
/// ... to `deref`/`deref_mut`` must ...
/// ... use [`from_mut`]`. Specifically, ...It does not seem to have almost any false positives, from the experience of enabling it in the Rust standard library [2], which will be checked starting with Rust 1.82.0. The maintainers also confirmed it is ready to be used.
Thus enable it.
--- Makefile | 3 ++- rust/Makefile | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-)
Makefile +2 -1
@@ -462,7 +462,8 @@ export rust_common_flags := --edition=20 -Wclippy::undocumented_unsafe_blocks \ -Wclippy::unnecessary_safety_comment \ -Wclippy::unnecessary_safety_doc \ - -Wrustdoc::missing_crate_level_docs + -Wrustdoc::missing_crate_level_docs \ + -Wrustdoc::unescaped_backticks KBUILD_HOSTCFLAGS := $(KBUILD_USERHOSTCFLAGS) $(HOST_LFS_CFLAGS) \ $(HOSTCFLAGS) -I $(srctree)/scripts/include
rust/Makefile +4 -1
@@ -61,7 +61,7 @@ alloc-cfgs = \ quiet_cmd_rustdoc = RUSTDOC $(if $(rustdoc_host),H, ) $< cmd_rustdoc = \ OBJTREE=$(abspath $(objtree)) \ - $(RUSTDOC) $(if $(rustdoc_host),$(rust_common_flags),$(rust_flags)) \ + $(RUSTDOC) $(filter-out $(skip_flags),$(if $(rustdoc_host),$(rust_common_flags),$(rust_flags))) \ $(rustc_target_flags) -L$(objtree)/$(obj) \ -Zunstable-options --generate-link-to-definition \ --output $(rustdoc_output) \
@@ -98,6 +98,9 @@ rustdoc-macros: private rustc_target_fla rustdoc-macros: $(src)/macros/lib.rs FORCE +$(call if_changed,rustdoc) +# Starting with Rust 1.82.0, skipping `-Wrustdoc::unescaped_backticks` should +# not be needed -- see https://github.com/rust-lang/rust/pull/128307. +rustdoc-core: private skip_flags = -Wrustdoc::unescaped_backticks rustdoc-core: private rustc_target_flags = $(core-cfgs) rustdoc-core: $(RUST_LIB_SRC)/core/src/lib.rs FORCE +$(call if_changed,rustdoc)
Patches currently in stable-queue which might be from [email protected] are
queue-6.12/drm-panic-avoid-reimplementing-iterator-find.patch queue-6.12/documentation-rust-add-coding-guidelines-on-lints.patch queue-6.12/rust-provide-proper-code-documentation-titles.patch queue-6.12/rust-alloc-make-allocator-module-public.patch queue-6.12/rust-alloc-remove-vecext-extension.patch queue-6.12/rust-alloc-implement-reallocfunc.patch queue-6.12/rust-alloc-separate-aligned_size-from-krealloc_aligned.patch queue-6.12/rust-enable-clippy-unnecessary_safety_comment-lint.patch queue-6.12/rust-alloc-update-module-comment-of-alloc.rs.patch queue-6.12/rust-kbuild-expand-rusttest-target-for-macros.patch queue-6.12/rust-error-use-core-alloc-layouterror.patch queue-6.12/rust-str-test-replace-alloc-format.patch queue-6.12/loongarch-use-asm_reachable.patch queue-6.12/rust-alloc-implement-allocator-for-kmalloc.patch queue-6.12/rust-alloc-implement-collect-for-intoiter.patch queue-6.12/rust-alloc-introduce-arraylayout.patch queue-6.12/rust-alloc-implement-vmalloc-allocator.patch queue-6.12/documentation-rust-discuss-in-the-guidelines.patch queue-6.12/rust-error-check-for-config-test-in-error-name.patch queue-6.12/rust-enable-clippy-ignored_unit_patterns-lint.patch queue-6.12/rust-enable-clippy-unnecessary_safety_doc-lint.patch queue-6.12/rust-alloc-add-box-to-prelude.patch queue-6.12/kbuild-rust-remove-the-alloc-crate-and-globalalloc.patch queue-6.12/rust-alloc-add-allocator-trait.patch queue-6.12/rust-treewide-switch-to-our-kernel-box-type.patch queue-6.12/rust-introduce-.clippy.toml.patch queue-6.12/rust-alloc-rename-kernelallocator-to-kmalloc.patch queue-6.12/rust-alloc-implement-cmalloc-in-module-allocator_test.patch queue-6.12/drm-panic-allow-verbose-version-check.patch queue-6.12/rust-map-__kernel_size_t-and-friends-also-to-usize-isize.patch queue-6.12/rust-alloc-add-module-allocator_test.patch queue-6.12/rust-replace-clippy-dbg_macro-with-disallowed_macros.patch queue-6.12/rust-alloc-add-__gfp_nowarn-to-flags.patch queue-6.12/rust-enable-clippy-s-check-private-items.patch queue-6.12/rust-error-make-conversion-functions-public.patch queue-6.12/rust-sort-global-rust-flags.patch queue-6.12/rust-alloc-implement-contains-for-flags.patch queue-6.12/rust-init-remove-unneeded.patch queue-6.12/rust-use-custom-ffi-integer-types.patch queue-6.12/rust-sync-remove-unneeded.patch queue-6.12/rust-treewide-switch-to-the-kernel-vec-type.patch queue-6.12/rust-alloc-implement-kvmalloc-allocator.patch queue-6.12/drm-panic-correctly-indent-continuation-of-line-in-list-item.patch queue-6.12/rust-alloc-implement-kernel-vec-type.patch queue-6.12/rust-workqueue-remove-unneeded.patch queue-6.12/rust-error-optimize-error-type-to-use-nonzero.patch queue-6.12/drm-panic-remove-unnecessary-borrow-in-alignment_pattern.patch queue-6.12/rust-alloc-remove-extension-of-std-s-box.patch queue-6.12/rust-block-fix-formatting-in-gendisk-doc.patch queue-6.12/rust-enable-rustdoc-unescaped_backticks-lint.patch queue-6.12/rust-fix-size_t-in-bindgen-prototypes-of-c-builtins.patch queue-6.12/rust-enable-clippy-undocumented_unsafe_blocks-lint.patch queue-6.12/rust-alloc-add-vec-to-prelude.patch queue-6.12/rust-alloc-implement-intoiterator-for-vec.patch queue-6.12/rust-alloc-implement-kernel-box.patch queue-6.12/drm-panic-remove-redundant-field-when-assigning-value.patch queue-6.12/rust-types-avoid-repetition-in-as-from-bytes-impls.patch queue-6.12/rust-start-using-the-attribute.patch queue-6.12/drm-panic-allow-verbose-boolean-for-clarity.patch queue-6.12/maintainers-add-entry-for-the-rust-alloc-module.patch queue-6.12/rust-alloc-fix-arraylayout-allocations.patch queue-6.12/drm-panic-prefer-eliding-lifetimes.patch
Patch "rust: map `__kernel_size_t` and friends also to usize/isize" has been added to the 6.12-stable tree
In reply to Miguel OjedaThis is a note to let you know that I've just added the patch titled
rust: map __kernel_size_t and friends also to usize/isize
to the 6.12-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
rust-map-__kernel_size_t-and-friends-also-to-usize-isize.patch
and it can be found in the queue-6.12 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
From [email protected] Fri Mar 7 23:53:16 2025
From: Miguel Ojeda <[email protected]>
Date: Fri, 7 Mar 2025 23:50:05 +0100
Subject: rust: map __kernel_size_t and friends also to usize/isize
To: Greg Kroah-Hartman <[email protected]>, Sasha Levin <[email protected]>, [email protected]
Cc: Danilo Krummrich <[email protected]>, Alice Ryhl <[email protected]>, Alyssa Ross <[email protected]>, NoisyCoil <[email protected]>, [email protected], Miguel Ojeda <[email protected]>
Message-ID: <[email protected]>
From: Gary Guo <[email protected]>
commit 2fd6f55c048d0c863ffbc8590b1bd2edb5ff13e5 upstream.
Currently bindgen has special logic to recognise size_t and ssize_t and map them to Rust usize and isize. Similarly, ptrdiff_t is mapped to isize.
However this falls short for __kernel_size_t, __kernel_ssize_t and __kernel_ptrdiff_t. To ensure that they are mapped to usize/isize rather than 32/64 integers depending on platform, blocklist them in bindgen parameters and manually provide their definition.
--- rust/bindgen_parameters | 5 +++++ rust/bindings/lib.rs | 5 +++++ rust/uapi/lib.rs | 5 +++++ 3 files changed, 15 insertions(+)
rust/bindgen_parameters +5 -0
@@ -1,5 +1,10 @@ # SPDX-License-Identifier: GPL-2.0 +# We want to map these types to `isize`/`usize` manually, instead of +# define them as `int`/`long` depending on platform bitwidth. +--blocklist-type __kernel_s?size_t +--blocklist-type __kernel_ptrdiff_t + --opaque-type xregs_state --opaque-type desc_struct --opaque-type arch_lbr_state
rust/bindings/lib.rs +5 -0
@@ -27,6 +27,11 @@#[allow(dead_code)] #[allow(clippy::undocumented_unsafe_blocks)] mod bindings_raw { +// Manual definition for blocklisted types. +type __kernel_size_t =usize ; +type __kernel_ssize_t =isize ; +type __kernel_ptrdiff_t =isize ; +// Use glob import here to expose all helpers. // Symbols defined within the module will take precedence to the glob import. pub use super ::bindings_helper::*;
rust/uapi/lib.rs +5 -0
@@ -25,4 +25,9 @@ unsafe_op_in_unsafe_fn )] +// Manual definition of blocklisted types. +type __kernel_size_t =usize ; +type __kernel_ssize_t =isize ; +type __kernel_ptrdiff_t =isize ; +include! (concat! (env! ("OBJTREE" ),"/rust/uapi/uapi_generated.rs" ));
Patches currently in stable-queue which might be from [email protected] are
queue-6.12/drm-panic-avoid-reimplementing-iterator-find.patch queue-6.12/documentation-rust-add-coding-guidelines-on-lints.patch queue-6.12/rust-provide-proper-code-documentation-titles.patch queue-6.12/rust-alloc-make-allocator-module-public.patch queue-6.12/rust-alloc-remove-vecext-extension.patch queue-6.12/rust-alloc-implement-reallocfunc.patch queue-6.12/rust-alloc-separate-aligned_size-from-krealloc_aligned.patch queue-6.12/rust-enable-clippy-unnecessary_safety_comment-lint.patch queue-6.12/rust-alloc-update-module-comment-of-alloc.rs.patch queue-6.12/rust-kbuild-expand-rusttest-target-for-macros.patch queue-6.12/rust-error-use-core-alloc-layouterror.patch queue-6.12/rust-str-test-replace-alloc-format.patch queue-6.12/loongarch-use-asm_reachable.patch queue-6.12/rust-alloc-implement-allocator-for-kmalloc.patch queue-6.12/rust-alloc-implement-collect-for-intoiter.patch queue-6.12/rust-alloc-introduce-arraylayout.patch queue-6.12/rust-alloc-implement-vmalloc-allocator.patch queue-6.12/documentation-rust-discuss-in-the-guidelines.patch queue-6.12/rust-error-check-for-config-test-in-error-name.patch queue-6.12/rust-enable-clippy-ignored_unit_patterns-lint.patch queue-6.12/rust-enable-clippy-unnecessary_safety_doc-lint.patch queue-6.12/rust-alloc-add-box-to-prelude.patch queue-6.12/kbuild-rust-remove-the-alloc-crate-and-globalalloc.patch queue-6.12/rust-alloc-add-allocator-trait.patch queue-6.12/rust-treewide-switch-to-our-kernel-box-type.patch queue-6.12/rust-introduce-.clippy.toml.patch queue-6.12/rust-alloc-rename-kernelallocator-to-kmalloc.patch queue-6.12/rust-alloc-implement-cmalloc-in-module-allocator_test.patch queue-6.12/drm-panic-allow-verbose-version-check.patch queue-6.12/rust-map-__kernel_size_t-and-friends-also-to-usize-isize.patch queue-6.12/rust-alloc-add-module-allocator_test.patch queue-6.12/rust-replace-clippy-dbg_macro-with-disallowed_macros.patch queue-6.12/rust-alloc-add-__gfp_nowarn-to-flags.patch queue-6.12/rust-enable-clippy-s-check-private-items.patch queue-6.12/rust-error-make-conversion-functions-public.patch queue-6.12/rust-sort-global-rust-flags.patch queue-6.12/rust-alloc-implement-contains-for-flags.patch queue-6.12/rust-init-remove-unneeded.patch queue-6.12/rust-use-custom-ffi-integer-types.patch queue-6.12/rust-sync-remove-unneeded.patch queue-6.12/rust-treewide-switch-to-the-kernel-vec-type.patch queue-6.12/rust-alloc-implement-kvmalloc-allocator.patch queue-6.12/drm-panic-correctly-indent-continuation-of-line-in-list-item.patch queue-6.12/rust-alloc-implement-kernel-vec-type.patch queue-6.12/rust-workqueue-remove-unneeded.patch queue-6.12/rust-error-optimize-error-type-to-use-nonzero.patch queue-6.12/drm-panic-remove-unnecessary-borrow-in-alignment_pattern.patch queue-6.12/rust-alloc-remove-extension-of-std-s-box.patch queue-6.12/rust-block-fix-formatting-in-gendisk-doc.patch queue-6.12/rust-enable-rustdoc-unescaped_backticks-lint.patch queue-6.12/rust-fix-size_t-in-bindgen-prototypes-of-c-builtins.patch queue-6.12/rust-enable-clippy-undocumented_unsafe_blocks-lint.patch queue-6.12/rust-alloc-add-vec-to-prelude.patch queue-6.12/rust-alloc-implement-intoiterator-for-vec.patch queue-6.12/rust-alloc-implement-kernel-box.patch queue-6.12/drm-panic-remove-redundant-field-when-assigning-value.patch queue-6.12/rust-types-avoid-repetition-in-as-from-bytes-impls.patch queue-6.12/rust-start-using-the-attribute.patch queue-6.12/drm-panic-allow-verbose-boolean-for-clarity.patch queue-6.12/maintainers-add-entry-for-the-rust-alloc-module.patch queue-6.12/rust-alloc-fix-arraylayout-allocations.patch queue-6.12/drm-panic-prefer-eliding-lifetimes.patch
Patch "rust: provide proper code documentation titles" has been added to the 6.12-stable tree
In reply to Miguel OjedaThis is a note to let you know that I've just added the patch titled
rust: provide proper code documentation titles
to the 6.12-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
rust-provide-proper-code-documentation-titles.patch
and it can be found in the queue-6.12 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
From [email protected] Fri Mar 7 23:51:16 2025
From: Miguel Ojeda <[email protected]>
Date: Fri, 7 Mar 2025 23:49:20 +0100
Subject: rust: provide proper code documentation titles
To: Greg Kroah-Hartman <[email protected]>, Sasha Levin <[email protected]>, [email protected]
Cc: Danilo Krummrich <[email protected]>, Alice Ryhl <[email protected]>, Alyssa Ross <[email protected]>, NoisyCoil <[email protected]>, [email protected], Miguel Ojeda <[email protected]>
Message-ID: <[email protected]>
From: Miguel Ojeda <[email protected]>
commit 2f390cc589433dfcfedc307a141e103929a6fd4d upstream.
Rust 1.82.0's Clippy is introducing [1][2] a new warn-by-default lint, too_long_first_doc_paragraph [3], which is intended to catch titles of code documentation items that are too long (likely because no title was provided and the item documentation starts with a paragraph).
This lint does not currently trigger anywhere, but it does detect a couple cases if checking for private items gets enabled (which we will do in the next commit):
error: first doc comment paragraph is too long
--> rust/kernel/init/__internal.rs:18:1
|
18 | / /// This is the module-internal type implementing PinInit and Init. It is unsafe to create this 19 | | /// type, since the closure needs to fulfill the same safety requirement as the
20 | | /// __pinned_init/__init functions.
| |_
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#too_long_first_doc_paragraph
= note: -D clippy::too-long-first-doc-paragraph implied by -D warnings
= help: to override -D warnings add #[allow(clippy::too_long_first_doc_paragraph)]
error: first doc comment paragraph is too long
--> rust/kernel/sync/arc/std_vendor.rs:3:1
|
3 | / //! The contents of this file come from the Rust standard library, hosted in
4 | | //! the <https://github.com/rust-lang/rust> repository, licensed under
5 | | //! "Apache-2.0 OR MIT" and adapted for kernel use. For copyright details,
6 | | //! see <https://github.com/rust-lang/rust/blob/master/COPYRIGHT>.
| |_
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#too_long_first_doc_paragraph
Thus clean those two instances.
In addition, since we have a second std_vendor.rs file with a similar header, do the same there too (even if that one does not trigger the lint, because it is doc(hidden)).
--- rust/kernel/init/__internal.rs | 7 ++++--- rust/kernel/std_vendor.rs | 2 ++ rust/kernel/sync/arc/std_vendor.rs | 2 ++ 3 files changed, 8 insertions(+), 3 deletions(-)
rust/kernel/init/__internal.rs +4 -3
@@ -15,9 +15,10 @@ use super::*;/// [this table]: https://doc.rust-lang.org/nomicon/phantom-data.html#table-of-phantomdata-patterns pub (super )type Invariant <T > =PhantomData <fn (*mut T ) -> *mut T >; -/// This is the module-internal type implementing `PinInit` and `Init`. It is unsafe to create this -/// type, since the closure needs to fulfill the same safety requirement as the -/// `__pinned_init`/`__init` functions. +/// Module-internal type implementing `PinInit` and `Init`. +/// +/// It is unsafe to create this type, since the closure needs to fulfill the same safety +/// requirement as the `__pinned_init`/`__init` functions. pub (crate )struct InitClosure <F ,T : ?Sized ,E >(pub (crate )F ,pub (crate )Invariant <(E ,T )>);// SAFETY: While constructing the `InitClosure`, the user promised that it upholds the
rust/kernel/std_vendor.rs +2 -0
@@ -1,5 +1,7 @@// SPDX-License-Identifier: Apache-2.0 OR MIT +//! Rust standard library vendored code. +//! //! The contents of this file come from the Rust standard library, hosted in //! the <https://github.com/rust-lang/rust> repository, licensed under //! "Apache-2.0 OR MIT" and adapted for kernel use. For copyright details,
rust/kernel/sync/arc/std_vendor.rs +2 -0
@@ -1,5 +1,7 @@// SPDX-License-Identifier: Apache-2.0 OR MIT +//! Rust standard library vendored code. +//! //! The contents of this file come from the Rust standard library, hosted in //! the <https://github.com/rust-lang/rust> repository, licensed under //! "Apache-2.0 OR MIT" and adapted for kernel use. For copyright details,
Patches currently in stable-queue which might be from [email protected] are
queue-6.12/drm-panic-avoid-reimplementing-iterator-find.patch queue-6.12/documentation-rust-add-coding-guidelines-on-lints.patch queue-6.12/rust-provide-proper-code-documentation-titles.patch queue-6.12/rust-alloc-make-allocator-module-public.patch queue-6.12/rust-alloc-remove-vecext-extension.patch queue-6.12/rust-alloc-implement-reallocfunc.patch queue-6.12/rust-alloc-separate-aligned_size-from-krealloc_aligned.patch queue-6.12/rust-enable-clippy-unnecessary_safety_comment-lint.patch queue-6.12/rust-alloc-update-module-comment-of-alloc.rs.patch queue-6.12/rust-kbuild-expand-rusttest-target-for-macros.patch queue-6.12/rust-error-use-core-alloc-layouterror.patch queue-6.12/rust-str-test-replace-alloc-format.patch queue-6.12/loongarch-use-asm_reachable.patch queue-6.12/rust-alloc-implement-allocator-for-kmalloc.patch queue-6.12/rust-alloc-implement-collect-for-intoiter.patch queue-6.12/rust-alloc-introduce-arraylayout.patch queue-6.12/rust-alloc-implement-vmalloc-allocator.patch queue-6.12/documentation-rust-discuss-in-the-guidelines.patch queue-6.12/rust-error-check-for-config-test-in-error-name.patch queue-6.12/rust-enable-clippy-ignored_unit_patterns-lint.patch queue-6.12/rust-enable-clippy-unnecessary_safety_doc-lint.patch queue-6.12/rust-alloc-add-box-to-prelude.patch queue-6.12/kbuild-rust-remove-the-alloc-crate-and-globalalloc.patch queue-6.12/rust-alloc-add-allocator-trait.patch queue-6.12/rust-treewide-switch-to-our-kernel-box-type.patch queue-6.12/rust-introduce-.clippy.toml.patch queue-6.12/rust-alloc-rename-kernelallocator-to-kmalloc.patch queue-6.12/rust-alloc-implement-cmalloc-in-module-allocator_test.patch queue-6.12/drm-panic-allow-verbose-version-check.patch queue-6.12/rust-map-__kernel_size_t-and-friends-also-to-usize-isize.patch queue-6.12/rust-alloc-add-module-allocator_test.patch queue-6.12/rust-replace-clippy-dbg_macro-with-disallowed_macros.patch queue-6.12/rust-alloc-add-__gfp_nowarn-to-flags.patch queue-6.12/rust-enable-clippy-s-check-private-items.patch queue-6.12/rust-error-make-conversion-functions-public.patch queue-6.12/rust-sort-global-rust-flags.patch queue-6.12/rust-alloc-implement-contains-for-flags.patch queue-6.12/rust-init-remove-unneeded.patch queue-6.12/rust-use-custom-ffi-integer-types.patch queue-6.12/rust-sync-remove-unneeded.patch queue-6.12/rust-treewide-switch-to-the-kernel-vec-type.patch queue-6.12/rust-alloc-implement-kvmalloc-allocator.patch queue-6.12/drm-panic-correctly-indent-continuation-of-line-in-list-item.patch queue-6.12/rust-alloc-implement-kernel-vec-type.patch queue-6.12/rust-workqueue-remove-unneeded.patch queue-6.12/rust-error-optimize-error-type-to-use-nonzero.patch queue-6.12/drm-panic-remove-unnecessary-borrow-in-alignment_pattern.patch queue-6.12/rust-alloc-remove-extension-of-std-s-box.patch queue-6.12/rust-block-fix-formatting-in-gendisk-doc.patch queue-6.12/rust-enable-rustdoc-unescaped_backticks-lint.patch queue-6.12/rust-fix-size_t-in-bindgen-prototypes-of-c-builtins.patch queue-6.12/rust-enable-clippy-undocumented_unsafe_blocks-lint.patch queue-6.12/rust-alloc-add-vec-to-prelude.patch queue-6.12/rust-alloc-implement-intoiterator-for-vec.patch queue-6.12/rust-alloc-implement-kernel-box.patch queue-6.12/drm-panic-remove-redundant-field-when-assigning-value.patch queue-6.12/rust-types-avoid-repetition-in-as-from-bytes-impls.patch queue-6.12/rust-start-using-the-attribute.patch queue-6.12/drm-panic-allow-verbose-boolean-for-clarity.patch queue-6.12/maintainers-add-entry-for-the-rust-alloc-module.patch queue-6.12/rust-alloc-fix-arraylayout-allocations.patch queue-6.12/drm-panic-prefer-eliding-lifetimes.patch
Patch "rust: error: check for config `test` in `Error::name`" has been added to the 6.12-stable tree
In reply to Miguel OjedaThis is a note to let you know that I've just added the patch titled
rust: error: check for config test in Error::name
to the 6.12-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
rust-error-check-for-config-test-in-error-name.patch
and it can be found in the queue-6.12 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
From [email protected] Fri Mar 7 23:52:54 2025
From: Miguel Ojeda <[email protected]>
Date: Fri, 7 Mar 2025 23:49:49 +0100
Subject: rust: error: check for config test in Error::name
To: Greg Kroah-Hartman <[email protected]>, Sasha Levin <[email protected]>, [email protected]
Cc: Danilo Krummrich <[email protected]>, Alice Ryhl <[email protected]>, Alyssa Ross <[email protected]>, NoisyCoil <[email protected]>, [email protected], Miguel Ojeda <[email protected]>
Message-ID: <[email protected]>
From: Danilo Krummrich <[email protected]>
commit 4a28ab469ff01855eb819dfd94754d1792f03f2a upstream.
Additional to testlib also check for test in Error::name. This is required by a subsequent patch that (indirectly) uses Error in test cases.
--- rust/kernel/error.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
rust/kernel/error.rs +2 -2
@@ -161,7 +161,7 @@ impl Error { }/// Returns a string representing the error, if one exists. -#[cfg(not(testlib))] +#[cfg(not(any(test, testlib)))] pub fn name (&self) ->Option <&'staticCStr > {// SAFETY: Just an FFI call, there are no extra safety requirements. let ptr =unsafe { bindings::errname (-self.0 .get ()) };
@@ -178,7 +178,7 @@ impl Error {/// When `testlib` is configured, this always returns `None` to avoid the dependency on a /// kernel function so that tests that use this (e.g., by calling [`Result::unwrap`]) can still /// run in userspace. -#[cfg(testlib)] +#[cfg(any(test, testlib))] pub fn name (&self) ->Option <&'staticCStr > {None }
Patches currently in stable-queue which might be from [email protected] are
queue-6.12/drm-panic-avoid-reimplementing-iterator-find.patch queue-6.12/documentation-rust-add-coding-guidelines-on-lints.patch queue-6.12/rust-provide-proper-code-documentation-titles.patch queue-6.12/rust-alloc-make-allocator-module-public.patch queue-6.12/rust-alloc-remove-vecext-extension.patch queue-6.12/rust-alloc-implement-reallocfunc.patch queue-6.12/rust-alloc-separate-aligned_size-from-krealloc_aligned.patch queue-6.12/rust-enable-clippy-unnecessary_safety_comment-lint.patch queue-6.12/rust-alloc-update-module-comment-of-alloc.rs.patch queue-6.12/rust-kbuild-expand-rusttest-target-for-macros.patch queue-6.12/rust-error-use-core-alloc-layouterror.patch queue-6.12/rust-str-test-replace-alloc-format.patch queue-6.12/loongarch-use-asm_reachable.patch queue-6.12/rust-alloc-implement-allocator-for-kmalloc.patch queue-6.12/rust-alloc-implement-collect-for-intoiter.patch queue-6.12/rust-alloc-introduce-arraylayout.patch queue-6.12/rust-alloc-implement-vmalloc-allocator.patch queue-6.12/documentation-rust-discuss-in-the-guidelines.patch queue-6.12/rust-error-check-for-config-test-in-error-name.patch queue-6.12/rust-enable-clippy-ignored_unit_patterns-lint.patch queue-6.12/rust-enable-clippy-unnecessary_safety_doc-lint.patch queue-6.12/rust-alloc-add-box-to-prelude.patch queue-6.12/kbuild-rust-remove-the-alloc-crate-and-globalalloc.patch queue-6.12/rust-alloc-add-allocator-trait.patch queue-6.12/rust-treewide-switch-to-our-kernel-box-type.patch queue-6.12/rust-introduce-.clippy.toml.patch queue-6.12/rust-alloc-rename-kernelallocator-to-kmalloc.patch queue-6.12/rust-alloc-implement-cmalloc-in-module-allocator_test.patch queue-6.12/drm-panic-allow-verbose-version-check.patch queue-6.12/rust-map-__kernel_size_t-and-friends-also-to-usize-isize.patch queue-6.12/rust-alloc-add-module-allocator_test.patch queue-6.12/rust-replace-clippy-dbg_macro-with-disallowed_macros.patch queue-6.12/rust-alloc-add-__gfp_nowarn-to-flags.patch queue-6.12/rust-enable-clippy-s-check-private-items.patch queue-6.12/rust-error-make-conversion-functions-public.patch queue-6.12/rust-sort-global-rust-flags.patch queue-6.12/rust-alloc-implement-contains-for-flags.patch queue-6.12/rust-init-remove-unneeded.patch queue-6.12/rust-use-custom-ffi-integer-types.patch queue-6.12/rust-sync-remove-unneeded.patch queue-6.12/rust-treewide-switch-to-the-kernel-vec-type.patch queue-6.12/rust-alloc-implement-kvmalloc-allocator.patch queue-6.12/drm-panic-correctly-indent-continuation-of-line-in-list-item.patch queue-6.12/rust-alloc-implement-kernel-vec-type.patch queue-6.12/rust-workqueue-remove-unneeded.patch queue-6.12/rust-error-optimize-error-type-to-use-nonzero.patch queue-6.12/drm-panic-remove-unnecessary-borrow-in-alignment_pattern.patch queue-6.12/rust-alloc-remove-extension-of-std-s-box.patch queue-6.12/rust-block-fix-formatting-in-gendisk-doc.patch queue-6.12/rust-enable-rustdoc-unescaped_backticks-lint.patch queue-6.12/rust-fix-size_t-in-bindgen-prototypes-of-c-builtins.patch queue-6.12/rust-enable-clippy-undocumented_unsafe_blocks-lint.patch queue-6.12/rust-alloc-add-vec-to-prelude.patch queue-6.12/rust-alloc-implement-intoiterator-for-vec.patch queue-6.12/rust-alloc-implement-kernel-box.patch queue-6.12/drm-panic-remove-redundant-field-when-assigning-value.patch queue-6.12/rust-types-avoid-repetition-in-as-from-bytes-impls.patch queue-6.12/rust-start-using-the-attribute.patch queue-6.12/drm-panic-allow-verbose-boolean-for-clarity.patch queue-6.12/maintainers-add-entry-for-the-rust-alloc-module.patch queue-6.12/rust-alloc-fix-arraylayout-allocations.patch queue-6.12/drm-panic-prefer-eliding-lifetimes.patch
Patch "rust: error: make conversion functions public" has been added to the 6.12-stable tree
In reply to Miguel OjedaThis is a note to let you know that I've just added the patch titled
rust: error: make conversion functions public
to the 6.12-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
rust-error-make-conversion-functions-public.patch
and it can be found in the queue-6.12 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
From [email protected] Fri Mar 7 23:51:29 2025
From: Miguel Ojeda <[email protected]>
Date: Fri, 7 Mar 2025 23:49:25 +0100
Subject: rust: error: make conversion functions public
To: Greg Kroah-Hartman <[email protected]>, Sasha Levin <[email protected]>, [email protected]
Cc: Danilo Krummrich <[email protected]>, Alice Ryhl <[email protected]>, Alyssa Ross <[email protected]>, NoisyCoil <[email protected]>, [email protected], Miguel Ojeda <[email protected]>
Message-ID: <[email protected]>
From: Filipe Xavier <[email protected]>
commit 5ed147473458f8c20f908a03227d8f5bb3cb8f7d upstream.
Change visibility to public of functions in error.rs:from_err_ptr, from_errno, from_result and to_ptr. Additionally, remove dead_code annotations.
--- rust/kernel/error.rs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)
rust/kernel/error.rs +4 -9
@@ -95,7 +95,7 @@ impl Error {/// /// It is a bug to pass an out-of-range `errno`. `EINVAL` would /// be returned in such a case. -pub (crate )fn from_errno (errno: core::ffi::c_int ) ->Error { +pub fn from_errno (errno: core::ffi::c_int ) ->Error {if errno < -(bindings::MAX_ERRNO as i32 ) || errno >=0 {// TODO: Make it a `WARN_ONCE` once available. crate ::pr_warn!(
@@ -133,8 +133,7 @@ impl Error { }/// Returns the error encoded as a pointer. -#[expect(dead_code)] -pub (crate )fn to_ptr <T >(self) -> *mut T { +pub fn to_ptr <T >(self) -> *mut T {#[cfg_attr(target_pointer_width = "32" , allow(clippy::useless_conversion))] // SAFETY: `self.0` is a valid error due to its invariant. unsafe {
@@ -270,9 +269,7 @@ pub fn to_result(err: core::ffi::c_int)/// from_err_ptr(unsafe { bindings::devm_platform_ioremap_resource(pdev.to_ptr(), index) }) /// } /// ``` -// TODO: Remove `dead_code` marker once an in-kernel client is available. -#[allow(dead_code)] -pub (crate )fn from_err_ptr <T >(ptr: *mut T ) ->Result <*mut T > { +pub fn from_err_ptr <T >(ptr: *mut T ) ->Result <*mut T > {// CAST: Casting a pointer to `*const core::ffi::c_void` is always valid. let const_ptr: *const core::ffi::c_void = ptr.cast ();// SAFETY: The FFI function does not deref the pointer.
@@ -318,9 +315,7 @@ pub(crate) fn from_err_ptr<T>(ptr: *mut/// }) /// } /// ``` -// TODO: Remove `dead_code` marker once an in-kernel client is available. -#[allow(dead_code)] -pub (crate )fn from_result <T ,F >(f:F ) ->T +pub fn from_result <T ,F >(f:F ) ->T where T :From <i16 >,F :FnOnce () ->Result <T >,
Patches currently in stable-queue which might be from [email protected] are
queue-6.12/drm-panic-avoid-reimplementing-iterator-find.patch queue-6.12/documentation-rust-add-coding-guidelines-on-lints.patch queue-6.12/rust-provide-proper-code-documentation-titles.patch queue-6.12/rust-alloc-make-allocator-module-public.patch queue-6.12/rust-alloc-remove-vecext-extension.patch queue-6.12/rust-alloc-implement-reallocfunc.patch queue-6.12/rust-alloc-separate-aligned_size-from-krealloc_aligned.patch queue-6.12/rust-enable-clippy-unnecessary_safety_comment-lint.patch queue-6.12/rust-alloc-update-module-comment-of-alloc.rs.patch queue-6.12/rust-kbuild-expand-rusttest-target-for-macros.patch queue-6.12/rust-error-use-core-alloc-layouterror.patch queue-6.12/rust-str-test-replace-alloc-format.patch queue-6.12/loongarch-use-asm_reachable.patch queue-6.12/rust-alloc-implement-allocator-for-kmalloc.patch queue-6.12/rust-alloc-implement-collect-for-intoiter.patch queue-6.12/rust-alloc-introduce-arraylayout.patch queue-6.12/rust-alloc-implement-vmalloc-allocator.patch queue-6.12/documentation-rust-discuss-in-the-guidelines.patch queue-6.12/rust-error-check-for-config-test-in-error-name.patch queue-6.12/rust-enable-clippy-ignored_unit_patterns-lint.patch queue-6.12/rust-enable-clippy-unnecessary_safety_doc-lint.patch queue-6.12/rust-alloc-add-box-to-prelude.patch queue-6.12/kbuild-rust-remove-the-alloc-crate-and-globalalloc.patch queue-6.12/rust-alloc-add-allocator-trait.patch queue-6.12/rust-treewide-switch-to-our-kernel-box-type.patch queue-6.12/rust-introduce-.clippy.toml.patch queue-6.12/rust-alloc-rename-kernelallocator-to-kmalloc.patch queue-6.12/rust-alloc-implement-cmalloc-in-module-allocator_test.patch queue-6.12/drm-panic-allow-verbose-version-check.patch queue-6.12/rust-map-__kernel_size_t-and-friends-also-to-usize-isize.patch queue-6.12/rust-alloc-add-module-allocator_test.patch queue-6.12/rust-replace-clippy-dbg_macro-with-disallowed_macros.patch queue-6.12/rust-alloc-add-__gfp_nowarn-to-flags.patch queue-6.12/rust-enable-clippy-s-check-private-items.patch queue-6.12/rust-error-make-conversion-functions-public.patch queue-6.12/rust-sort-global-rust-flags.patch queue-6.12/rust-alloc-implement-contains-for-flags.patch queue-6.12/rust-init-remove-unneeded.patch queue-6.12/rust-use-custom-ffi-integer-types.patch queue-6.12/rust-sync-remove-unneeded.patch queue-6.12/rust-treewide-switch-to-the-kernel-vec-type.patch queue-6.12/rust-alloc-implement-kvmalloc-allocator.patch queue-6.12/drm-panic-correctly-indent-continuation-of-line-in-list-item.patch queue-6.12/rust-alloc-implement-kernel-vec-type.patch queue-6.12/rust-workqueue-remove-unneeded.patch queue-6.12/rust-error-optimize-error-type-to-use-nonzero.patch queue-6.12/drm-panic-remove-unnecessary-borrow-in-alignment_pattern.patch queue-6.12/rust-alloc-remove-extension-of-std-s-box.patch queue-6.12/rust-block-fix-formatting-in-gendisk-doc.patch queue-6.12/rust-enable-rustdoc-unescaped_backticks-lint.patch queue-6.12/rust-fix-size_t-in-bindgen-prototypes-of-c-builtins.patch queue-6.12/rust-enable-clippy-undocumented_unsafe_blocks-lint.patch queue-6.12/rust-alloc-add-vec-to-prelude.patch queue-6.12/rust-alloc-implement-intoiterator-for-vec.patch queue-6.12/rust-alloc-implement-kernel-box.patch queue-6.12/drm-panic-remove-redundant-field-when-assigning-value.patch queue-6.12/rust-types-avoid-repetition-in-as-from-bytes-impls.patch queue-6.12/rust-start-using-the-attribute.patch queue-6.12/drm-panic-allow-verbose-boolean-for-clarity.patch queue-6.12/maintainers-add-entry-for-the-rust-alloc-module.patch queue-6.12/rust-alloc-fix-arraylayout-allocations.patch queue-6.12/drm-panic-prefer-eliding-lifetimes.patch
Patch "rust: error: optimize error type to use nonzero" has been added to the 6.12-stable tree
In reply to Miguel OjedaThis is a note to let you know that I've just added the patch titled
rust: error: optimize error type to use nonzero
to the 6.12-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
rust-error-optimize-error-type-to-use-nonzero.patch
and it can be found in the queue-6.12 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
From [email protected] Fri Mar 7 23:51:30 2025
From: Miguel Ojeda <[email protected]>
Date: Fri, 7 Mar 2025 23:49:26 +0100
Subject: rust: error: optimize error type to use nonzero
To: Greg Kroah-Hartman <[email protected]>, Sasha Levin <[email protected]>, [email protected]
Cc: Danilo Krummrich <[email protected]>, Alice Ryhl <[email protected]>, Alyssa Ross <[email protected]>, NoisyCoil <[email protected]>, [email protected], Miguel Ojeda <[email protected]>
Message-ID: <[email protected]>
From: Filipe Xavier <[email protected]>
commit e9759c5b9ea555d09f426c70c880e9522e9b0576 upstream.
Optimize Result<(), Error> size by changing Error type to NonZero* for niche optimization.
This reduces the space used by the Result type, as the NonZero* type enables the compiler to apply more efficient memory layout. For example, the Result<(), Error> changes size from 8 to 4 bytes.
[ Removed unneeded block around match, added backticks in panic
message and added intra-doc link. - Miguel ]
--- rust/kernel/error.rs | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-)
rust/kernel/error.rs +28 -9
@@ -9,6 +9,7 @@ use crate::{alloc::AllocError, str::CStruse alloc::alloc::LayoutError ;use core::fmt; +use core::num::NonZeroI32 ;use core::num::TryFromIntError ;use core::str::Utf8Error ;
@@ -20,7 +21,11 @@ pub mod code { $( #[doc = $doc] )* - pub const $err: super::Error = super::Error(-(crate::bindings::$err as i32)); + pub const $err: super::Error = + match super::Error::try_from_errno(-(crate::bindings::$err as i32)) { + Some(err) => err, + None => panic!("Invalid errno in `declare_err!`"), + }; }; }
@@ -88,7 +93,7 @@ pub mod code {/// /// The value is a valid `errno` (i.e. `>= -MAX_ERRNO && < 0`). #[derive( Clone , Copy , PartialEq , Eq )] -pub struct Error (core::ffi::c_int ); +pub struct Error (NonZeroI32 );impl Error {/// Creates an [`Error`] from a kernel error code.
@@ -107,7 +112,20 @@ impl Error {// INVARIANT: The check above ensures the type invariant // will hold. -Error (errno) +// SAFETY: `errno` is checked above to be in a valid range. +unsafe {Error ::from_errno_unchecked (errno) } + } + +/// Creates an [`Error`] from a kernel error code. +/// +/// Returns [`None`] if `errno` is out-of-range. +const fn try_from_errno (errno: core::ffi::c_int ) ->Option <Error > { +if errno < -(bindings::MAX_ERRNO as i32 ) || errno >=0 { +return None ; + } + +// SAFETY: `errno` is checked above to be in a valid range. +Some (unsafe {Error ::from_errno_unchecked (errno) }) }/// Creates an [`Error`] from a kernel error code.
@@ -115,21 +133,22 @@ impl Error {/// # Safety /// /// `errno` must be within error code range (i.e. `>= -MAX_ERRNO && < 0`). -unsafe fn from_errno_unchecked (errno: core::ffi::c_int ) ->Error { +const unsafe fn from_errno_unchecked (errno: core::ffi::c_int ) ->Error {// INVARIANT: The contract ensures the type invariant // will hold. -Error (errno) +// SAFETY: The caller guarantees `errno` is non-zero. +Error (unsafe {NonZeroI32 ::new_unchecked (errno) }) }/// Returns the kernel error code. pub fn to_errno (self) -> core::ffi::c_int { - self.0 + self.0 .get () }#[cfg( CONFIG_BLOCK )] pub (crate )fn to_blk_status (self) -> bindings::blk_status_t {// SAFETY: `self.0` is a valid error due to its invariant. -unsafe { bindings::errno_to_blk_status (self.0 ) } +unsafe { bindings::errno_to_blk_status (self.0 .get ()) } }/// Returns the error encoded as a pointer.
@@ -137,7 +156,7 @@ impl Error {#[cfg_attr(target_pointer_width = "32" , allow(clippy::useless_conversion))] // SAFETY: `self.0` is a valid error due to its invariant. unsafe { - bindings::ERR_PTR (self.0 .into ())as *mut _ + bindings::ERR_PTR (self.0 .get ().into ())as *mut _ } }
@@ -145,7 +164,7 @@ impl Error {#[cfg(not(testlib))] pub fn name (&self) ->Option <&'staticCStr > {// SAFETY: Just an FFI call, there are no extra safety requirements. -let ptr =unsafe { bindings::errname (-self.0 ) }; +let ptr =unsafe { bindings::errname (-self.0 .get ()) };if ptr.is_null () {None }else {
Patches currently in stable-queue which might be from [email protected] are
queue-6.12/drm-panic-avoid-reimplementing-iterator-find.patch queue-6.12/documentation-rust-add-coding-guidelines-on-lints.patch queue-6.12/rust-provide-proper-code-documentation-titles.patch queue-6.12/rust-alloc-make-allocator-module-public.patch queue-6.12/rust-alloc-remove-vecext-extension.patch queue-6.12/rust-alloc-implement-reallocfunc.patch queue-6.12/rust-alloc-separate-aligned_size-from-krealloc_aligned.patch queue-6.12/rust-enable-clippy-unnecessary_safety_comment-lint.patch queue-6.12/rust-alloc-update-module-comment-of-alloc.rs.patch queue-6.12/rust-kbuild-expand-rusttest-target-for-macros.patch queue-6.12/rust-error-use-core-alloc-layouterror.patch queue-6.12/rust-str-test-replace-alloc-format.patch queue-6.12/loongarch-use-asm_reachable.patch queue-6.12/rust-alloc-implement-allocator-for-kmalloc.patch queue-6.12/rust-alloc-implement-collect-for-intoiter.patch queue-6.12/rust-alloc-introduce-arraylayout.patch queue-6.12/rust-alloc-implement-vmalloc-allocator.patch queue-6.12/documentation-rust-discuss-in-the-guidelines.patch queue-6.12/rust-error-check-for-config-test-in-error-name.patch queue-6.12/rust-enable-clippy-ignored_unit_patterns-lint.patch queue-6.12/rust-enable-clippy-unnecessary_safety_doc-lint.patch queue-6.12/rust-alloc-add-box-to-prelude.patch queue-6.12/kbuild-rust-remove-the-alloc-crate-and-globalalloc.patch queue-6.12/rust-alloc-add-allocator-trait.patch queue-6.12/rust-treewide-switch-to-our-kernel-box-type.patch queue-6.12/rust-introduce-.clippy.toml.patch queue-6.12/rust-alloc-rename-kernelallocator-to-kmalloc.patch queue-6.12/rust-alloc-implement-cmalloc-in-module-allocator_test.patch queue-6.12/drm-panic-allow-verbose-version-check.patch queue-6.12/rust-map-__kernel_size_t-and-friends-also-to-usize-isize.patch queue-6.12/rust-alloc-add-module-allocator_test.patch queue-6.12/rust-replace-clippy-dbg_macro-with-disallowed_macros.patch queue-6.12/rust-alloc-add-__gfp_nowarn-to-flags.patch queue-6.12/rust-enable-clippy-s-check-private-items.patch queue-6.12/rust-error-make-conversion-functions-public.patch queue-6.12/rust-sort-global-rust-flags.patch queue-6.12/rust-alloc-implement-contains-for-flags.patch queue-6.12/rust-init-remove-unneeded.patch queue-6.12/rust-use-custom-ffi-integer-types.patch queue-6.12/rust-sync-remove-unneeded.patch queue-6.12/rust-treewide-switch-to-the-kernel-vec-type.patch queue-6.12/rust-alloc-implement-kvmalloc-allocator.patch queue-6.12/drm-panic-correctly-indent-continuation-of-line-in-list-item.patch queue-6.12/rust-alloc-implement-kernel-vec-type.patch queue-6.12/rust-workqueue-remove-unneeded.patch queue-6.12/rust-error-optimize-error-type-to-use-nonzero.patch queue-6.12/drm-panic-remove-unnecessary-borrow-in-alignment_pattern.patch queue-6.12/rust-alloc-remove-extension-of-std-s-box.patch queue-6.12/rust-block-fix-formatting-in-gendisk-doc.patch queue-6.12/rust-enable-rustdoc-unescaped_backticks-lint.patch queue-6.12/rust-fix-size_t-in-bindgen-prototypes-of-c-builtins.patch queue-6.12/rust-enable-clippy-undocumented_unsafe_blocks-lint.patch queue-6.12/rust-alloc-add-vec-to-prelude.patch queue-6.12/rust-alloc-implement-intoiterator-for-vec.patch queue-6.12/rust-alloc-implement-kernel-box.patch queue-6.12/drm-panic-remove-redundant-field-when-assigning-value.patch queue-6.12/rust-types-avoid-repetition-in-as-from-bytes-impls.patch queue-6.12/rust-start-using-the-attribute.patch queue-6.12/drm-panic-allow-verbose-boolean-for-clarity.patch queue-6.12/maintainers-add-entry-for-the-rust-alloc-module.patch queue-6.12/rust-alloc-fix-arraylayout-allocations.patch queue-6.12/drm-panic-prefer-eliding-lifetimes.patch
Patch "rust: error: use `core::alloc::LayoutError`" has been added to the 6.12-stable tree
In reply to Miguel OjedaThis is a note to let you know that I've just added the patch titled
rust: error: use core::alloc::LayoutError
to the 6.12-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
rust-error-use-core-alloc-layouterror.patch
and it can be found in the queue-6.12 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
From [email protected] Fri Mar 7 23:52:38 2025
From: Miguel Ojeda <[email protected]>
Date: Fri, 7 Mar 2025 23:49:48 +0100
Subject: rust: error: use core::alloc::LayoutError
To: Greg Kroah-Hartman <[email protected]>, Sasha Levin <[email protected]>, [email protected]
Cc: Danilo Krummrich <[email protected]>, Alice Ryhl <[email protected]>, Alyssa Ross <[email protected]>, NoisyCoil <[email protected]>, [email protected], Miguel Ojeda <[email protected]>
Message-ID: <[email protected]>
From: Danilo Krummrich <[email protected]>
commit 29a48d25ff53c183482dc88a99133a0fb5aa541a upstream.
Use core::alloc::LayoutError instead of alloc::alloc::LayoutError in preparation to get rid of Rust's alloc crate.
--- rust/kernel/error.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
rust/kernel/error.rs +1 -1
@@ -6,7 +6,7 @@use crate ::{alloc::AllocError , str::CStr }; -use alloc::alloc::LayoutError ; +use core::alloc::LayoutError ;use core::fmt;use core::num::NonZeroI32 ;
Patches currently in stable-queue which might be from [email protected] are
queue-6.12/drm-panic-avoid-reimplementing-iterator-find.patch queue-6.12/documentation-rust-add-coding-guidelines-on-lints.patch queue-6.12/rust-provide-proper-code-documentation-titles.patch queue-6.12/rust-alloc-make-allocator-module-public.patch queue-6.12/rust-alloc-remove-vecext-extension.patch queue-6.12/rust-alloc-implement-reallocfunc.patch queue-6.12/rust-alloc-separate-aligned_size-from-krealloc_aligned.patch queue-6.12/rust-enable-clippy-unnecessary_safety_comment-lint.patch queue-6.12/rust-alloc-update-module-comment-of-alloc.rs.patch queue-6.12/rust-kbuild-expand-rusttest-target-for-macros.patch queue-6.12/rust-error-use-core-alloc-layouterror.patch queue-6.12/rust-str-test-replace-alloc-format.patch queue-6.12/loongarch-use-asm_reachable.patch queue-6.12/rust-alloc-implement-allocator-for-kmalloc.patch queue-6.12/rust-alloc-implement-collect-for-intoiter.patch queue-6.12/rust-alloc-introduce-arraylayout.patch queue-6.12/rust-alloc-implement-vmalloc-allocator.patch queue-6.12/documentation-rust-discuss-in-the-guidelines.patch queue-6.12/rust-error-check-for-config-test-in-error-name.patch queue-6.12/rust-enable-clippy-ignored_unit_patterns-lint.patch queue-6.12/rust-enable-clippy-unnecessary_safety_doc-lint.patch queue-6.12/rust-alloc-add-box-to-prelude.patch queue-6.12/kbuild-rust-remove-the-alloc-crate-and-globalalloc.patch queue-6.12/rust-alloc-add-allocator-trait.patch queue-6.12/rust-treewide-switch-to-our-kernel-box-type.patch queue-6.12/rust-introduce-.clippy.toml.patch queue-6.12/rust-alloc-rename-kernelallocator-to-kmalloc.patch queue-6.12/rust-alloc-implement-cmalloc-in-module-allocator_test.patch queue-6.12/drm-panic-allow-verbose-version-check.patch queue-6.12/rust-map-__kernel_size_t-and-friends-also-to-usize-isize.patch queue-6.12/rust-alloc-add-module-allocator_test.patch queue-6.12/rust-replace-clippy-dbg_macro-with-disallowed_macros.patch queue-6.12/rust-alloc-add-__gfp_nowarn-to-flags.patch queue-6.12/rust-enable-clippy-s-check-private-items.patch queue-6.12/rust-error-make-conversion-functions-public.patch queue-6.12/rust-sort-global-rust-flags.patch queue-6.12/rust-alloc-implement-contains-for-flags.patch queue-6.12/rust-init-remove-unneeded.patch queue-6.12/rust-use-custom-ffi-integer-types.patch queue-6.12/rust-sync-remove-unneeded.patch queue-6.12/rust-treewide-switch-to-the-kernel-vec-type.patch queue-6.12/rust-alloc-implement-kvmalloc-allocator.patch queue-6.12/drm-panic-correctly-indent-continuation-of-line-in-list-item.patch queue-6.12/rust-alloc-implement-kernel-vec-type.patch queue-6.12/rust-workqueue-remove-unneeded.patch queue-6.12/rust-error-optimize-error-type-to-use-nonzero.patch queue-6.12/drm-panic-remove-unnecessary-borrow-in-alignment_pattern.patch queue-6.12/rust-alloc-remove-extension-of-std-s-box.patch queue-6.12/rust-block-fix-formatting-in-gendisk-doc.patch queue-6.12/rust-enable-rustdoc-unescaped_backticks-lint.patch queue-6.12/rust-fix-size_t-in-bindgen-prototypes-of-c-builtins.patch queue-6.12/rust-enable-clippy-undocumented_unsafe_blocks-lint.patch queue-6.12/rust-alloc-add-vec-to-prelude.patch queue-6.12/rust-alloc-implement-intoiterator-for-vec.patch queue-6.12/rust-alloc-implement-kernel-box.patch queue-6.12/drm-panic-remove-redundant-field-when-assigning-value.patch queue-6.12/rust-types-avoid-repetition-in-as-from-bytes-impls.patch queue-6.12/rust-start-using-the-attribute.patch queue-6.12/drm-panic-allow-verbose-boolean-for-clarity.patch queue-6.12/maintainers-add-entry-for-the-rust-alloc-module.patch queue-6.12/rust-alloc-fix-arraylayout-allocations.patch queue-6.12/drm-panic-prefer-eliding-lifetimes.patch
Patch "rust: fix size_t in bindgen prototypes of C builtins" has been added to the 6.12-stable tree
In reply to Miguel OjedaThis is a note to let you know that I've just added the patch titled
rust: fix size_t in bindgen prototypes of C builtins
to the 6.12-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
rust-fix-size_t-in-bindgen-prototypes-of-c-builtins.patch
and it can be found in the queue-6.12 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
From [email protected] Fri Mar 7 23:53:18 2025
From: Miguel Ojeda <[email protected]>
Date: Fri, 7 Mar 2025 23:50:04 +0100
Subject: rust: fix size_t in bindgen prototypes of C builtins
To: Greg Kroah-Hartman <[email protected]>, Sasha Levin <[email protected]>, [email protected]
Cc: Danilo Krummrich <[email protected]>, Alice Ryhl <[email protected]>, Alyssa Ross <[email protected]>, NoisyCoil <[email protected]>, [email protected], Miguel Ojeda <[email protected]>
Message-ID: <[email protected]>
From: Gary Guo <[email protected]>
commit 75c1fd41a671a0843b89d1526411a837a7163fa2 upstream.
Without -fno-builtin, for functions like memcpy/memmove (and many others), bindgen seems to be using the clang-provided prototype. This prototype is ABI-wise compatible, but the issue is that it does not have the same information as the source code w.r.t. typedefs.
For example, bindgen generates the following:
extern "C" {
pub fn strlen(s: *const core::ffi::c_char) -> core::ffi::c_ulong;
}note that the return type is c_ulong (i.e. unsigned long), despite the size_t-is-usize behavior (this is default, and we have not opted out from it using --no-size_t-is-usize).
Similarly, memchr's size argument should be of type __kernel_size_t, but bindgen generates c_ulong directly.
We want to ensure any size_t is translated to Rust usize so that we can avoid having them be different type on 32-bit and 64-bit architectures, and hence would require a lot of excessive type casts when calling FFI functions.
I found that this bindgen behavior (which probably is caused by libclang) can be disabled by -fno-builtin. Using the flag for compiled code can result in less optimisation because compiler cannot assume about their properties anymore, but this should not affect bindgen.
[ Trevor asked: "I wonder how reliable this behavior is. Maybe bindgen
could do a better job controlling this, is there an open issue?".
Gary replied: ..."apparently this is indeed the suggested approach in
https://github.com/rust-lang/rust-bindgen/issues/1770". - Miguel ]
--- rust/Makefile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
rust/Makefile +5 -1
@@ -264,7 +264,11 @@ else bindgen_c_flags_lto = $(bindgen_c_flags) endif -bindgen_c_flags_final = $(bindgen_c_flags_lto) -D__BINDGEN__ +# `-fno-builtin` is passed to avoid `bindgen` from using `clang` builtin +# prototypes for functions like `memcpy` -- if this flag is not passed, +# `bindgen`-generated prototypes use `c_ulong` or `c_uint` depending on +# architecture instead of generating `usize`. +bindgen_c_flags_final = $(bindgen_c_flags_lto) -fno-builtin -D__BINDGEN__ # Each `bindgen` release may upgrade the list of Rust target versions. By # default, the highest stable release in their list is used. Thus we need to set
Patches currently in stable-queue which might be from [email protected] are
queue-6.12/drm-panic-avoid-reimplementing-iterator-find.patch queue-6.12/documentation-rust-add-coding-guidelines-on-lints.patch queue-6.12/rust-provide-proper-code-documentation-titles.patch queue-6.12/rust-alloc-make-allocator-module-public.patch queue-6.12/rust-alloc-remove-vecext-extension.patch queue-6.12/rust-alloc-implement-reallocfunc.patch queue-6.12/rust-alloc-separate-aligned_size-from-krealloc_aligned.patch queue-6.12/rust-enable-clippy-unnecessary_safety_comment-lint.patch queue-6.12/rust-alloc-update-module-comment-of-alloc.rs.patch queue-6.12/rust-kbuild-expand-rusttest-target-for-macros.patch queue-6.12/rust-error-use-core-alloc-layouterror.patch queue-6.12/rust-str-test-replace-alloc-format.patch queue-6.12/loongarch-use-asm_reachable.patch queue-6.12/rust-alloc-implement-allocator-for-kmalloc.patch queue-6.12/rust-alloc-implement-collect-for-intoiter.patch queue-6.12/rust-alloc-introduce-arraylayout.patch queue-6.12/rust-alloc-implement-vmalloc-allocator.patch queue-6.12/documentation-rust-discuss-in-the-guidelines.patch queue-6.12/rust-error-check-for-config-test-in-error-name.patch queue-6.12/rust-enable-clippy-ignored_unit_patterns-lint.patch queue-6.12/rust-enable-clippy-unnecessary_safety_doc-lint.patch queue-6.12/rust-alloc-add-box-to-prelude.patch queue-6.12/kbuild-rust-remove-the-alloc-crate-and-globalalloc.patch queue-6.12/rust-alloc-add-allocator-trait.patch queue-6.12/rust-treewide-switch-to-our-kernel-box-type.patch queue-6.12/rust-introduce-.clippy.toml.patch queue-6.12/rust-alloc-rename-kernelallocator-to-kmalloc.patch queue-6.12/rust-alloc-implement-cmalloc-in-module-allocator_test.patch queue-6.12/drm-panic-allow-verbose-version-check.patch queue-6.12/rust-map-__kernel_size_t-and-friends-also-to-usize-isize.patch queue-6.12/rust-alloc-add-module-allocator_test.patch queue-6.12/rust-replace-clippy-dbg_macro-with-disallowed_macros.patch queue-6.12/rust-alloc-add-__gfp_nowarn-to-flags.patch queue-6.12/rust-enable-clippy-s-check-private-items.patch queue-6.12/rust-error-make-conversion-functions-public.patch queue-6.12/rust-sort-global-rust-flags.patch queue-6.12/rust-alloc-implement-contains-for-flags.patch queue-6.12/rust-init-remove-unneeded.patch queue-6.12/rust-use-custom-ffi-integer-types.patch queue-6.12/rust-sync-remove-unneeded.patch queue-6.12/rust-treewide-switch-to-the-kernel-vec-type.patch queue-6.12/rust-alloc-implement-kvmalloc-allocator.patch queue-6.12/drm-panic-correctly-indent-continuation-of-line-in-list-item.patch queue-6.12/rust-alloc-implement-kernel-vec-type.patch queue-6.12/rust-workqueue-remove-unneeded.patch queue-6.12/rust-error-optimize-error-type-to-use-nonzero.patch queue-6.12/drm-panic-remove-unnecessary-borrow-in-alignment_pattern.patch queue-6.12/rust-alloc-remove-extension-of-std-s-box.patch queue-6.12/rust-block-fix-formatting-in-gendisk-doc.patch queue-6.12/rust-enable-rustdoc-unescaped_backticks-lint.patch queue-6.12/rust-fix-size_t-in-bindgen-prototypes-of-c-builtins.patch queue-6.12/rust-enable-clippy-undocumented_unsafe_blocks-lint.patch queue-6.12/rust-alloc-add-vec-to-prelude.patch queue-6.12/rust-alloc-implement-intoiterator-for-vec.patch queue-6.12/rust-alloc-implement-kernel-box.patch queue-6.12/drm-panic-remove-redundant-field-when-assigning-value.patch queue-6.12/rust-types-avoid-repetition-in-as-from-bytes-impls.patch queue-6.12/rust-start-using-the-attribute.patch queue-6.12/drm-panic-allow-verbose-boolean-for-clarity.patch queue-6.12/maintainers-add-entry-for-the-rust-alloc-module.patch queue-6.12/rust-alloc-fix-arraylayout-allocations.patch queue-6.12/drm-panic-prefer-eliding-lifetimes.patch
Patch "rust: init: remove unneeded `#[allow(clippy::disallowed_names)]`" has been added to the 6.12-stable tree
In reply to Miguel OjedaThis is a note to let you know that I've just added the patch titled
rust: init: remove unneeded #[allow(clippy::disallowed_names)]
to the 6.12-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
rust-init-remove-unneeded.patch
and it can be found in the queue-6.12 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
From [email protected] Fri Mar 7 23:51:07 2025
From: Miguel Ojeda <[email protected]>
Date: Fri, 7 Mar 2025 23:49:16 +0100
Subject: rust: init: remove unneeded #[allow(clippy::disallowed_names)]
To: Greg Kroah-Hartman <[email protected]>, Sasha Levin <[email protected]>, [email protected]
Cc: Danilo Krummrich <[email protected]>, Alice Ryhl <[email protected]>, Alyssa Ross <[email protected]>, NoisyCoil <[email protected]>, [email protected], Miguel Ojeda <[email protected]>
Message-ID: <[email protected]>
From: Miguel Ojeda <[email protected]>
commit d5cc7ab0a0a99496de1bd933dac242699a417809 upstream.
These few cases, unlike others in the same file, did not need the allow.
Thus clean them up.
--- rust/kernel/init.rs | 4 ---- 1 file changed, 4 deletions(-)
rust/kernel/init.rs +0 -4
@@ -87,7 +87,6 @@//! To declare an init macro/function you just return an [`impl PinInit<T, E>`]: //! //! ```rust -//! # #![allow(clippy::disallowed_names)] //! # use kernel::{sync::Mutex, new_mutex, init::PinInit, try_pin_init}; //! #[pin_data] //! struct DriverData {
@@ -368,7 +367,6 @@ macro_rules! stack_try_pin_init {/// The syntax is almost identical to that of a normal `struct` initializer: /// /// ```rust -/// # #![allow(clippy::disallowed_names)] /// # use kernel::{init, pin_init, macros::pin_data, init::*}; /// # use core::pin::Pin; /// #[pin_data]
@@ -413,7 +411,6 @@ macro_rules! stack_try_pin_init {/// To create an initializer function, simply declare it like this: /// /// ```rust -/// # #![allow(clippy::disallowed_names)] /// # use kernel::{init, pin_init, init::*}; /// # use core::pin::Pin; /// # #[pin_data]
@@ -468,7 +465,6 @@ macro_rules! stack_try_pin_init {/// They can also easily embed it into their own `struct`s: /// /// ```rust -/// # #![allow(clippy::disallowed_names)] /// # use kernel::{init, pin_init, macros::pin_data, init::*}; /// # use core::pin::Pin; /// # #[pin_data]
Patches currently in stable-queue which might be from [email protected] are
queue-6.12/drm-panic-avoid-reimplementing-iterator-find.patch queue-6.12/documentation-rust-add-coding-guidelines-on-lints.patch queue-6.12/rust-provide-proper-code-documentation-titles.patch queue-6.12/rust-alloc-make-allocator-module-public.patch queue-6.12/rust-alloc-remove-vecext-extension.patch queue-6.12/rust-alloc-implement-reallocfunc.patch queue-6.12/rust-alloc-separate-aligned_size-from-krealloc_aligned.patch queue-6.12/rust-enable-clippy-unnecessary_safety_comment-lint.patch queue-6.12/rust-alloc-update-module-comment-of-alloc.rs.patch queue-6.12/rust-kbuild-expand-rusttest-target-for-macros.patch queue-6.12/rust-error-use-core-alloc-layouterror.patch queue-6.12/rust-str-test-replace-alloc-format.patch queue-6.12/loongarch-use-asm_reachable.patch queue-6.12/rust-alloc-implement-allocator-for-kmalloc.patch queue-6.12/rust-alloc-implement-collect-for-intoiter.patch queue-6.12/rust-alloc-introduce-arraylayout.patch queue-6.12/rust-alloc-implement-vmalloc-allocator.patch queue-6.12/documentation-rust-discuss-in-the-guidelines.patch queue-6.12/rust-error-check-for-config-test-in-error-name.patch queue-6.12/rust-enable-clippy-ignored_unit_patterns-lint.patch queue-6.12/rust-enable-clippy-unnecessary_safety_doc-lint.patch queue-6.12/rust-alloc-add-box-to-prelude.patch queue-6.12/kbuild-rust-remove-the-alloc-crate-and-globalalloc.patch queue-6.12/rust-alloc-add-allocator-trait.patch queue-6.12/rust-treewide-switch-to-our-kernel-box-type.patch queue-6.12/rust-introduce-.clippy.toml.patch queue-6.12/rust-alloc-rename-kernelallocator-to-kmalloc.patch queue-6.12/rust-alloc-implement-cmalloc-in-module-allocator_test.patch queue-6.12/drm-panic-allow-verbose-version-check.patch queue-6.12/rust-map-__kernel_size_t-and-friends-also-to-usize-isize.patch queue-6.12/rust-alloc-add-module-allocator_test.patch queue-6.12/rust-replace-clippy-dbg_macro-with-disallowed_macros.patch queue-6.12/rust-alloc-add-__gfp_nowarn-to-flags.patch queue-6.12/rust-enable-clippy-s-check-private-items.patch queue-6.12/rust-error-make-conversion-functions-public.patch queue-6.12/rust-sort-global-rust-flags.patch queue-6.12/rust-alloc-implement-contains-for-flags.patch queue-6.12/rust-init-remove-unneeded.patch queue-6.12/rust-use-custom-ffi-integer-types.patch queue-6.12/rust-sync-remove-unneeded.patch queue-6.12/rust-treewide-switch-to-the-kernel-vec-type.patch queue-6.12/rust-alloc-implement-kvmalloc-allocator.patch queue-6.12/drm-panic-correctly-indent-continuation-of-line-in-list-item.patch queue-6.12/rust-alloc-implement-kernel-vec-type.patch queue-6.12/rust-workqueue-remove-unneeded.patch queue-6.12/rust-error-optimize-error-type-to-use-nonzero.patch queue-6.12/drm-panic-remove-unnecessary-borrow-in-alignment_pattern.patch queue-6.12/rust-alloc-remove-extension-of-std-s-box.patch queue-6.12/rust-block-fix-formatting-in-gendisk-doc.patch queue-6.12/rust-enable-rustdoc-unescaped_backticks-lint.patch queue-6.12/rust-fix-size_t-in-bindgen-prototypes-of-c-builtins.patch queue-6.12/rust-enable-clippy-undocumented_unsafe_blocks-lint.patch queue-6.12/rust-alloc-add-vec-to-prelude.patch queue-6.12/rust-alloc-implement-intoiterator-for-vec.patch queue-6.12/rust-alloc-implement-kernel-box.patch queue-6.12/drm-panic-remove-redundant-field-when-assigning-value.patch queue-6.12/rust-types-avoid-repetition-in-as-from-bytes-impls.patch queue-6.12/rust-start-using-the-attribute.patch queue-6.12/drm-panic-allow-verbose-boolean-for-clarity.patch queue-6.12/maintainers-add-entry-for-the-rust-alloc-module.patch queue-6.12/rust-alloc-fix-arraylayout-allocations.patch queue-6.12/drm-panic-prefer-eliding-lifetimes.patch
Patch "rust: introduce `.clippy.toml`" has been added to the 6.12-stable tree
In reply to Miguel OjedaThis is a note to let you know that I've just added the patch titled
rust: introduce .clippy.toml
to the 6.12-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
rust-introduce-.clippy.toml.patch
and it can be found in the queue-6.12 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
From [email protected] Fri Mar 7 23:51:09 2025
From: Miguel Ojeda <[email protected]>
Date: Fri, 7 Mar 2025 23:49:18 +0100
Subject: rust: introduce .clippy.toml
To: Greg Kroah-Hartman <[email protected]>, Sasha Levin <[email protected]>, [email protected]
Cc: Danilo Krummrich <[email protected]>, Alice Ryhl <[email protected]>, Alyssa Ross <[email protected]>, NoisyCoil <[email protected]>, [email protected], Miguel Ojeda <[email protected]>
Message-ID: <[email protected]>
From: Miguel Ojeda <[email protected]>
commit 7d56786edcbdf58b6367fd7f01d5861214ad1c95 upstream.
Some Clippy lints can be configured/tweaked. We will use these knobs to our advantage in later commits.
This is done via a configuration file, .clippy.toml [1]. The file is currently unstable. This may be a problem in the future, but we can adapt as needed. In addition, we proposed adding Clippy to the Rust CI's RFL job [2], so we should be able to catch issues pre-merge.
Thus introduce the file.
--- .clippy.toml | 1 + .gitignore | 1 + MAINTAINERS | 1 + Makefile | 3 +++ 4 files changed, 6 insertions(+) create mode 100644 .clippy.toml
.clippy.toml new file +1 -0
@@ -0,0 +1 @@ +# SPDX-License-Identifier: GPL-2.0
.gitignore +1 -0
@@ -103,6 +103,7 @@ modules.order # We don't want to ignore the following even if they are dot-files # !.clang-format +!.clippy.toml !.cocciconfig !.editorconfig !.get_maintainer.ignore
MAINTAINERS +1 -0
@@ -20175,6 +20175,7 @@ B: https://github.com/Rust-for-Linux/lin C: zulip://rust-for-linux.zulipchat.com P: https://rust-for-linux.com/contributing T: git https://github.com/Rust-for-Linux/linux.git rust-next +F: .clippy.toml F: Documentation/rust/ F: rust/ F: samples/rust/
Makefile +3 -0
@@ -588,6 +588,9 @@ endif # Allows the usage of unstable features in stable compilers. export RUSTC_BOOTSTRAP := 1 +# Allows finding `.clippy.toml` in out-of-srctree builds. +export CLIPPY_CONF_DIR := $(srctree) + export ARCH SRCARCH CONFIG_SHELL BASH HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE LD CC HOSTPKG_CONFIG export RUSTC RUSTDOC RUSTFMT RUSTC_OR_CLIPPY_QUIET RUSTC_OR_CLIPPY BINDGEN export HOSTRUSTC KBUILD_HOSTRUSTFLAGS
Patches currently in stable-queue which might be from [email protected] are
queue-6.12/drm-panic-avoid-reimplementing-iterator-find.patch queue-6.12/documentation-rust-add-coding-guidelines-on-lints.patch queue-6.12/rust-provide-proper-code-documentation-titles.patch queue-6.12/rust-alloc-make-allocator-module-public.patch queue-6.12/rust-alloc-remove-vecext-extension.patch queue-6.12/rust-alloc-implement-reallocfunc.patch queue-6.12/rust-alloc-separate-aligned_size-from-krealloc_aligned.patch queue-6.12/rust-enable-clippy-unnecessary_safety_comment-lint.patch queue-6.12/rust-alloc-update-module-comment-of-alloc.rs.patch queue-6.12/rust-kbuild-expand-rusttest-target-for-macros.patch queue-6.12/rust-error-use-core-alloc-layouterror.patch queue-6.12/rust-str-test-replace-alloc-format.patch queue-6.12/loongarch-use-asm_reachable.patch queue-6.12/rust-alloc-implement-allocator-for-kmalloc.patch queue-6.12/rust-alloc-implement-collect-for-intoiter.patch queue-6.12/rust-alloc-introduce-arraylayout.patch queue-6.12/rust-alloc-implement-vmalloc-allocator.patch queue-6.12/documentation-rust-discuss-in-the-guidelines.patch queue-6.12/rust-error-check-for-config-test-in-error-name.patch queue-6.12/rust-enable-clippy-ignored_unit_patterns-lint.patch queue-6.12/rust-enable-clippy-unnecessary_safety_doc-lint.patch queue-6.12/rust-alloc-add-box-to-prelude.patch queue-6.12/kbuild-rust-remove-the-alloc-crate-and-globalalloc.patch queue-6.12/rust-alloc-add-allocator-trait.patch queue-6.12/rust-treewide-switch-to-our-kernel-box-type.patch queue-6.12/rust-introduce-.clippy.toml.patch queue-6.12/rust-alloc-rename-kernelallocator-to-kmalloc.patch queue-6.12/rust-alloc-implement-cmalloc-in-module-allocator_test.patch queue-6.12/drm-panic-allow-verbose-version-check.patch queue-6.12/rust-map-__kernel_size_t-and-friends-also-to-usize-isize.patch queue-6.12/rust-alloc-add-module-allocator_test.patch queue-6.12/rust-replace-clippy-dbg_macro-with-disallowed_macros.patch queue-6.12/rust-alloc-add-__gfp_nowarn-to-flags.patch queue-6.12/rust-enable-clippy-s-check-private-items.patch queue-6.12/rust-error-make-conversion-functions-public.patch queue-6.12/rust-sort-global-rust-flags.patch queue-6.12/rust-alloc-implement-contains-for-flags.patch queue-6.12/rust-init-remove-unneeded.patch queue-6.12/rust-use-custom-ffi-integer-types.patch queue-6.12/rust-sync-remove-unneeded.patch queue-6.12/rust-treewide-switch-to-the-kernel-vec-type.patch queue-6.12/rust-alloc-implement-kvmalloc-allocator.patch queue-6.12/drm-panic-correctly-indent-continuation-of-line-in-list-item.patch queue-6.12/rust-alloc-implement-kernel-vec-type.patch queue-6.12/rust-workqueue-remove-unneeded.patch queue-6.12/rust-error-optimize-error-type-to-use-nonzero.patch queue-6.12/drm-panic-remove-unnecessary-borrow-in-alignment_pattern.patch queue-6.12/rust-alloc-remove-extension-of-std-s-box.patch queue-6.12/rust-block-fix-formatting-in-gendisk-doc.patch queue-6.12/rust-enable-rustdoc-unescaped_backticks-lint.patch queue-6.12/rust-fix-size_t-in-bindgen-prototypes-of-c-builtins.patch queue-6.12/rust-enable-clippy-undocumented_unsafe_blocks-lint.patch queue-6.12/rust-alloc-add-vec-to-prelude.patch queue-6.12/rust-alloc-implement-intoiterator-for-vec.patch queue-6.12/rust-alloc-implement-kernel-box.patch queue-6.12/drm-panic-remove-redundant-field-when-assigning-value.patch queue-6.12/rust-types-avoid-repetition-in-as-from-bytes-impls.patch queue-6.12/rust-start-using-the-attribute.patch queue-6.12/drm-panic-allow-verbose-boolean-for-clarity.patch queue-6.12/maintainers-add-entry-for-the-rust-alloc-module.patch queue-6.12/rust-alloc-fix-arraylayout-allocations.patch queue-6.12/drm-panic-prefer-eliding-lifetimes.patch
Patch "rust: kbuild: expand rusttest target for macros" has been added to the 6.12-stable tree
In reply to Miguel OjedaThis is a note to let you know that I've just added the patch titled
rust: kbuild: expand rusttest target for macros
to the 6.12-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
rust-kbuild-expand-rusttest-target-for-macros.patch
and it can be found in the queue-6.12 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
From [email protected] Fri Mar 7 23:53:11 2025
From: Miguel Ojeda <[email protected]>
Date: Fri, 7 Mar 2025 23:50:03 +0100
Subject: rust: kbuild: expand rusttest target for macros
To: Greg Kroah-Hartman <[email protected]>, Sasha Levin <[email protected]>, [email protected]
Cc: Danilo Krummrich <[email protected]>, Alice Ryhl <[email protected]>, Alyssa Ross <[email protected]>, NoisyCoil <[email protected]>, [email protected], Miguel Ojeda <[email protected]>
Message-ID: <[email protected]>
From: "Ethan D. Twardy" <[email protected]>
commit b2c261fa8629dff2bd1143fa790797a773ace102 upstream.
Previously, the rusttest target for the macros crate did not specify the dependencies necessary to run the rustdoc tests. These tests rely on the kernel crate, so add the dependencies.
[ Rebased (alloc is gone nowadays, sysroot handling is simpler) and
simplified (reused rustdoc_test rule instead of adding a new one, no need for rustdoc-compiler_builtins, removed unneeded macros explicit path). Made vtable example fail (avoiding to increase the complexity in the rusttest target). Removed unstable -Zproc-macro-backtrace option. Reworded accordingly. - Miguel ]
--- rust/Makefile | 17 +++++++++++++---- rust/macros/lib.rs | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-)
rust/Makefile +13 -4
@@ -129,6 +129,14 @@ rusttestlib-macros: private rustc_test_l rusttestlib-macros: $(src)/macros/lib.rs FORCE +$(call if_changed,rustc_test_library) +rusttestlib-kernel: private rustc_target_flags = \ + --extern build_error --extern macros \ + --extern bindings --extern uapi +rusttestlib-kernel: $(src)/kernel/lib.rs \ + rusttestlib-bindings rusttestlib-uapi rusttestlib-build_error \ + $(obj)/libmacros.so $(obj)/bindings.o FORCE + +$(call if_changed,rustc_test_library) + rusttestlib-bindings: $(src)/bindings/lib.rs FORCE +$(call if_changed,rustc_test_library)
@@ -181,19 +189,20 @@ quiet_cmd_rustc_test = RUSTC T $< rusttest: rusttest-macros rusttest-kernel -rusttest-macros: private rustc_target_flags = --extern proc_macro +rusttest-macros: private rustc_target_flags = --extern proc_macro \ + --extern macros --extern kernel rusttest-macros: private rustdoc_test_target_flags = --crate-type proc-macro -rusttest-macros: $(src)/macros/lib.rs FORCE +rusttest-macros: $(src)/macros/lib.rs \ + rusttestlib-macros rusttestlib-kernel FORCE +$(call if_changed,rustc_test) +$(call if_changed,rustdoc_test) rusttest-kernel: private rustc_target_flags = \ --extern build_error --extern macros --extern bindings --extern uapi -rusttest-kernel: $(src)/kernel/lib.rs \ +rusttest-kernel: $(src)/kernel/lib.rs rusttestlib-kernel \ rusttestlib-build_error rusttestlib-macros rusttestlib-bindings \ rusttestlib-uapi FORCE +$(call if_changed,rustc_test) - +$(call if_changed,rustc_test_library) ifdef CONFIG_CC_IS_CLANG bindgen_c_flags = $(c_flags)
rust/macros/lib.rs +1 -1
@@ -132,7 +132,7 @@ pub fn module(ts: TokenStream) -> TokenS/// calls to this function at compile time: /// /// ```compile_fail -/// # use kernel::error::VTABLE_DEFAULT_ERROR; +/// # // Intentionally missing `use`s to simplify `rusttest`. /// kernel::build_error(VTABLE_DEFAULT_ERROR) /// ``` ///
Patches currently in stable-queue which might be from [email protected] are
queue-6.12/drm-panic-avoid-reimplementing-iterator-find.patch queue-6.12/documentation-rust-add-coding-guidelines-on-lints.patch queue-6.12/rust-provide-proper-code-documentation-titles.patch queue-6.12/rust-alloc-make-allocator-module-public.patch queue-6.12/rust-alloc-remove-vecext-extension.patch queue-6.12/rust-alloc-implement-reallocfunc.patch queue-6.12/rust-alloc-separate-aligned_size-from-krealloc_aligned.patch queue-6.12/rust-enable-clippy-unnecessary_safety_comment-lint.patch queue-6.12/rust-alloc-update-module-comment-of-alloc.rs.patch queue-6.12/rust-kbuild-expand-rusttest-target-for-macros.patch queue-6.12/rust-error-use-core-alloc-layouterror.patch queue-6.12/rust-str-test-replace-alloc-format.patch queue-6.12/loongarch-use-asm_reachable.patch queue-6.12/rust-alloc-implement-allocator-for-kmalloc.patch queue-6.12/rust-alloc-implement-collect-for-intoiter.patch queue-6.12/rust-alloc-introduce-arraylayout.patch queue-6.12/rust-alloc-implement-vmalloc-allocator.patch queue-6.12/documentation-rust-discuss-in-the-guidelines.patch queue-6.12/rust-error-check-for-config-test-in-error-name.patch queue-6.12/rust-enable-clippy-ignored_unit_patterns-lint.patch queue-6.12/rust-enable-clippy-unnecessary_safety_doc-lint.patch queue-6.12/rust-alloc-add-box-to-prelude.patch queue-6.12/kbuild-rust-remove-the-alloc-crate-and-globalalloc.patch queue-6.12/rust-alloc-add-allocator-trait.patch queue-6.12/rust-treewide-switch-to-our-kernel-box-type.patch queue-6.12/rust-introduce-.clippy.toml.patch queue-6.12/rust-alloc-rename-kernelallocator-to-kmalloc.patch queue-6.12/rust-alloc-implement-cmalloc-in-module-allocator_test.patch queue-6.12/drm-panic-allow-verbose-version-check.patch queue-6.12/rust-map-__kernel_size_t-and-friends-also-to-usize-isize.patch queue-6.12/rust-alloc-add-module-allocator_test.patch queue-6.12/rust-replace-clippy-dbg_macro-with-disallowed_macros.patch queue-6.12/rust-alloc-add-__gfp_nowarn-to-flags.patch queue-6.12/rust-enable-clippy-s-check-private-items.patch queue-6.12/rust-error-make-conversion-functions-public.patch queue-6.12/rust-sort-global-rust-flags.patch queue-6.12/rust-alloc-implement-contains-for-flags.patch queue-6.12/rust-init-remove-unneeded.patch queue-6.12/rust-use-custom-ffi-integer-types.patch queue-6.12/rust-sync-remove-unneeded.patch queue-6.12/rust-treewide-switch-to-the-kernel-vec-type.patch queue-6.12/rust-alloc-implement-kvmalloc-allocator.patch queue-6.12/drm-panic-correctly-indent-continuation-of-line-in-list-item.patch queue-6.12/rust-alloc-implement-kernel-vec-type.patch queue-6.12/rust-workqueue-remove-unneeded.patch queue-6.12/rust-error-optimize-error-type-to-use-nonzero.patch queue-6.12/drm-panic-remove-unnecessary-borrow-in-alignment_pattern.patch queue-6.12/rust-alloc-remove-extension-of-std-s-box.patch queue-6.12/rust-block-fix-formatting-in-gendisk-doc.patch queue-6.12/rust-enable-rustdoc-unescaped_backticks-lint.patch queue-6.12/rust-fix-size_t-in-bindgen-prototypes-of-c-builtins.patch queue-6.12/rust-enable-clippy-undocumented_unsafe_blocks-lint.patch queue-6.12/rust-alloc-add-vec-to-prelude.patch queue-6.12/rust-alloc-implement-intoiterator-for-vec.patch queue-6.12/rust-alloc-implement-kernel-box.patch queue-6.12/drm-panic-remove-redundant-field-when-assigning-value.patch queue-6.12/rust-types-avoid-repetition-in-as-from-bytes-impls.patch queue-6.12/rust-start-using-the-attribute.patch queue-6.12/drm-panic-allow-verbose-boolean-for-clarity.patch queue-6.12/maintainers-add-entry-for-the-rust-alloc-module.patch queue-6.12/rust-alloc-fix-arraylayout-allocations.patch queue-6.12/drm-panic-prefer-eliding-lifetimes.patch
Patch "rust: sort global Rust flags" has been added to the 6.12-stable tree
In reply to Miguel OjedaThis is a note to let you know that I've just added the patch titled
rust: sort global Rust flags
to the 6.12-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
rust-sort-global-rust-flags.patch
and it can be found in the queue-6.12 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
From [email protected] Fri Mar 7 23:50:49 2025
From: Miguel Ojeda <[email protected]>
Date: Fri, 7 Mar 2025 23:49:09 +0100
Subject: rust: sort global Rust flags
To: Greg Kroah-Hartman <[email protected]>, Sasha Levin <[email protected]>, [email protected]
Cc: Danilo Krummrich <[email protected]>, Alice Ryhl <[email protected]>, Alyssa Ross <[email protected]>, NoisyCoil <[email protected]>, [email protected], Miguel Ojeda <[email protected]>
Message-ID: <[email protected]>
From: Miguel Ojeda <[email protected]>
commit a135aa3d30d28f26eb28a0ff5d48b387b0e0755f upstream.
Sort the global Rust flags so that it is easier to follow along when we have more, like this patch series does.
--- Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
Makefile +4 -4
@@ -446,19 +446,19 @@ KBUILD_USERLDFLAGS := $(USERLDFLAGS) export rust_common_flags := --edition=2021 \ -Zbinary_dep_depinfo=y \ -Astable_features \ - -Dunsafe_op_in_unsafe_fn \ -Dnon_ascii_idents \ + -Dunsafe_op_in_unsafe_fn \ + -Wmissing_docs \ -Wrust_2018_idioms \ -Wunreachable_pub \ - -Wmissing_docs \ - -Wrustdoc::missing_crate_level_docs \ -Wclippy::all \ + -Wclippy::dbg_macro \ -Wclippy::mut_mut \ -Wclippy::needless_bitwise_bool \ -Wclippy::needless_continue \ -Aclippy::needless_lifetimes \ -Wclippy::no_mangle_with_rust_abi \ - -Wclippy::dbg_macro + -Wrustdoc::missing_crate_level_docs KBUILD_HOSTCFLAGS := $(KBUILD_USERHOSTCFLAGS) $(HOST_LFS_CFLAGS) \ $(HOSTCFLAGS) -I $(srctree)/scripts/include
Patches currently in stable-queue which might be from [email protected] are
queue-6.12/drm-panic-avoid-reimplementing-iterator-find.patch queue-6.12/documentation-rust-add-coding-guidelines-on-lints.patch queue-6.12/rust-provide-proper-code-documentation-titles.patch queue-6.12/rust-alloc-make-allocator-module-public.patch queue-6.12/rust-alloc-remove-vecext-extension.patch queue-6.12/rust-alloc-implement-reallocfunc.patch queue-6.12/rust-alloc-separate-aligned_size-from-krealloc_aligned.patch queue-6.12/rust-enable-clippy-unnecessary_safety_comment-lint.patch queue-6.12/rust-alloc-update-module-comment-of-alloc.rs.patch queue-6.12/rust-kbuild-expand-rusttest-target-for-macros.patch queue-6.12/rust-error-use-core-alloc-layouterror.patch queue-6.12/rust-str-test-replace-alloc-format.patch queue-6.12/loongarch-use-asm_reachable.patch queue-6.12/rust-alloc-implement-allocator-for-kmalloc.patch queue-6.12/rust-alloc-implement-collect-for-intoiter.patch queue-6.12/rust-alloc-introduce-arraylayout.patch queue-6.12/rust-alloc-implement-vmalloc-allocator.patch queue-6.12/documentation-rust-discuss-in-the-guidelines.patch queue-6.12/rust-error-check-for-config-test-in-error-name.patch queue-6.12/rust-enable-clippy-ignored_unit_patterns-lint.patch queue-6.12/rust-enable-clippy-unnecessary_safety_doc-lint.patch queue-6.12/rust-alloc-add-box-to-prelude.patch queue-6.12/kbuild-rust-remove-the-alloc-crate-and-globalalloc.patch queue-6.12/rust-alloc-add-allocator-trait.patch queue-6.12/rust-treewide-switch-to-our-kernel-box-type.patch queue-6.12/rust-introduce-.clippy.toml.patch queue-6.12/rust-alloc-rename-kernelallocator-to-kmalloc.patch queue-6.12/rust-alloc-implement-cmalloc-in-module-allocator_test.patch queue-6.12/drm-panic-allow-verbose-version-check.patch queue-6.12/rust-map-__kernel_size_t-and-friends-also-to-usize-isize.patch queue-6.12/rust-alloc-add-module-allocator_test.patch queue-6.12/rust-replace-clippy-dbg_macro-with-disallowed_macros.patch queue-6.12/rust-alloc-add-__gfp_nowarn-to-flags.patch queue-6.12/rust-enable-clippy-s-check-private-items.patch queue-6.12/rust-error-make-conversion-functions-public.patch queue-6.12/rust-sort-global-rust-flags.patch queue-6.12/rust-alloc-implement-contains-for-flags.patch queue-6.12/rust-init-remove-unneeded.patch queue-6.12/rust-use-custom-ffi-integer-types.patch queue-6.12/rust-sync-remove-unneeded.patch queue-6.12/rust-treewide-switch-to-the-kernel-vec-type.patch queue-6.12/rust-alloc-implement-kvmalloc-allocator.patch queue-6.12/drm-panic-correctly-indent-continuation-of-line-in-list-item.patch queue-6.12/rust-alloc-implement-kernel-vec-type.patch queue-6.12/rust-workqueue-remove-unneeded.patch queue-6.12/rust-error-optimize-error-type-to-use-nonzero.patch queue-6.12/drm-panic-remove-unnecessary-borrow-in-alignment_pattern.patch queue-6.12/rust-alloc-remove-extension-of-std-s-box.patch queue-6.12/rust-block-fix-formatting-in-gendisk-doc.patch queue-6.12/rust-enable-rustdoc-unescaped_backticks-lint.patch queue-6.12/rust-fix-size_t-in-bindgen-prototypes-of-c-builtins.patch queue-6.12/rust-enable-clippy-undocumented_unsafe_blocks-lint.patch queue-6.12/rust-alloc-add-vec-to-prelude.patch queue-6.12/rust-alloc-implement-intoiterator-for-vec.patch queue-6.12/rust-alloc-implement-kernel-box.patch queue-6.12/drm-panic-remove-redundant-field-when-assigning-value.patch queue-6.12/rust-types-avoid-repetition-in-as-from-bytes-impls.patch queue-6.12/rust-start-using-the-attribute.patch queue-6.12/drm-panic-allow-verbose-boolean-for-clarity.patch queue-6.12/maintainers-add-entry-for-the-rust-alloc-module.patch queue-6.12/rust-alloc-fix-arraylayout-allocations.patch queue-6.12/drm-panic-prefer-eliding-lifetimes.patch
Patch "rust: start using the `#[expect(...)]` attribute" has been added to the 6.12-stable tree
In reply to Miguel OjedaThis is a note to let you know that I've just added the patch titled
rust: start using the #[expect(...)] attribute
to the 6.12-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
rust-start-using-the-attribute.patch
and it can be found in the queue-6.12 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
From [email protected] Fri Mar 7 23:51:25 2025
From: Miguel Ojeda <[email protected]>
Date: Fri, 7 Mar 2025 23:49:23 +0100
Subject: rust: start using the #[expect(...)] attribute
To: Greg Kroah-Hartman <[email protected]>, Sasha Levin <[email protected]>, [email protected]
Cc: Danilo Krummrich <[email protected]>, Alice Ryhl <[email protected]>, Alyssa Ross <[email protected]>, NoisyCoil <[email protected]>, [email protected], Miguel Ojeda <[email protected]>
Message-ID: <[email protected]>
From: Miguel Ojeda <[email protected]>
commit 1f9ed172545687e5c04c77490a45896be6d2e459 upstream.
In Rust, it is possible to allow particular warnings (diagnostics, lints) locally, making the compiler ignore instances of a given warning within a given function, module, block, etc.
It is similar to #pragma GCC diagnostic push + ignored + pop in C:
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function" static void f(void) {}
#pragma GCC diagnostic pop
But way less verbose:
#[allow(dead_code)]
fn f() {}By that virtue, it makes it possible to comfortably enable more diagnostics by default (i.e. outside W= levels) that may have some false positives but that are otherwise quite useful to keep enabled to catch potential mistakes.
The #[expect(...)] attribute [1] takes this further, and makes the compiler warn if the diagnostic was _not_ produced. For instance, the following will ensure that, when f() is called somewhere, we will have to remove the attribute:
#[expect(dead_code)]
fn f() {}If we do not, we get a warning from the compiler:
warning: this lint expectation is unfulfilled
--> x.rs:3:10
|
3 | #[expect(dead_code)]
| ^^^^^^^^^
|
= note: `#[warn(unfulfilled_lint_expectations)]` on by defaultThis means that expects do not get forgotten when they are not needed.
See the next commit for more details, nuances on its usage and documentation on the feature.
The attribute requires the lint_reasons [2] unstable feature, but it is becoming stable in 1.81.0 (to be released on 2024-09-05) and it has already been useful to clean things up in this patch series, finding cases where the allows should not have been there.
Thus, enable lint_reasons and convert some of our allows to expects where possible.
This feature was also an example of the ongoing collaboration between Rust and the kernel -- we tested it in the kernel early on and found an issue that was quickly resolved [3].
--- rust/kernel/error.rs | 2 +- rust/kernel/init.rs | 22 +++++++++++----------- rust/kernel/init/__internal.rs | 4 ++-- rust/kernel/init/macros.rs | 10 +++++----- rust/kernel/ioctl.rs | 2 +- rust/kernel/lib.rs | 1 + rust/kernel/list/arc_field.rs | 2 +- rust/kernel/print.rs | 4 ++-- rust/kernel/std_vendor.rs | 10 +++++----- samples/rust/rust_print.rs | 2 +- scripts/Makefile.build | 2 +- 11 files changed, 31 insertions(+), 30 deletions(-)
rust/kernel/error.rs +1 -1
@@ -133,7 +133,7 @@ impl Error { }/// Returns the error encoded as a pointer. -#[allow(dead_code)] +#[expect(dead_code)] pub (crate )fn to_ptr <T >(self) -> *mut T {#[cfg_attr(target_pointer_width = "32" , allow(clippy::useless_conversion))] // SAFETY: `self.0` is a valid error due to its invariant.
rust/kernel/init.rs +11 -11
@@ -35,7 +35,7 @@//! that you need to write `<-` instead of `:` for fields that you want to initialize in-place. //! //! ```rust -//! # #![allow(clippy::disallowed_names)] +//! # #![expect(clippy::disallowed_names)] //! use kernel::sync::{new_mutex, Mutex}; //! # use core::pin::Pin; //! #[pin_data]
@@ -55,7 +55,7 @@//! (or just the stack) to actually initialize a `Foo`: //! //! ```rust -//! # #![allow(clippy::disallowed_names)] +//! # #![expect(clippy::disallowed_names)] //! # use kernel::sync::{new_mutex, Mutex}; //! # use core::pin::Pin; //! # #[pin_data]
@@ -120,12 +120,12 @@//! `slot` gets called. //! //! ```rust -//! # #![allow(unreachable_pub, clippy::disallowed_names)] +//! # #![expect(unreachable_pub, clippy::disallowed_names)] //! use kernel::{init, types::Opaque}; //! use core::{ptr::addr_of_mut, marker::PhantomPinned, pin::Pin}; //! # mod bindings { -//! # #![allow(non_camel_case_types)] -//! # #![allow(clippy::missing_safety_doc)] +//! # #![expect(non_camel_case_types)] +//! # #![expect(clippy::missing_safety_doc)] //! # pub struct foo; //! # pub unsafe fn init_foo(_ptr: *mut foo) {} //! # pub unsafe fn destroy_foo(_ptr: *mut foo) {}
@@ -238,7 +238,7 @@ pub mod macros;/// # Examples /// /// ```rust -/// # #![allow(clippy::disallowed_names)] +/// # #![expect(clippy::disallowed_names)] /// # use kernel::{init, macros::pin_data, pin_init, stack_pin_init, init::*, sync::Mutex, new_mutex}; /// # use core::pin::Pin; /// #[pin_data]
@@ -290,7 +290,7 @@ macro_rules! stack_pin_init {/// # Examples /// /// ```rust,ignore -/// # #![allow(clippy::disallowed_names)] +/// # #![expect(clippy::disallowed_names)] /// # use kernel::{init, pin_init, stack_try_pin_init, init::*, sync::Mutex, new_mutex}; /// # use macros::pin_data; /// # use core::{alloc::AllocError, pin::Pin};
@@ -316,7 +316,7 @@ macro_rules! stack_pin_init {/// ``` /// /// ```rust,ignore -/// # #![allow(clippy::disallowed_names)] +/// # #![expect(clippy::disallowed_names)] /// # use kernel::{init, pin_init, stack_try_pin_init, init::*, sync::Mutex, new_mutex}; /// # use macros::pin_data; /// # use core::{alloc::AllocError, pin::Pin};
@@ -438,7 +438,7 @@ macro_rules! stack_try_pin_init {/// Users of `Foo` can now create it like this: /// /// ```rust -/// # #![allow(clippy::disallowed_names)] +/// # #![expect(clippy::disallowed_names)] /// # use kernel::{init, pin_init, macros::pin_data, init::*}; /// # use core::pin::Pin; /// # #[pin_data]
@@ -852,7 +852,7 @@ pub unsafe trait PinInit<T: ?Sized, E =/// # Examples /// /// ```rust -/// # #![allow(clippy::disallowed_names)] +/// # #![expect(clippy::disallowed_names)] /// use kernel::{types::Opaque, init::pin_init_from_closure}; /// #[repr(C)] /// struct RawFoo([u8; 16]);
@@ -964,7 +964,7 @@ pub unsafe trait Init<T: ?Sized, E = Inf/// # Examples /// /// ```rust -/// # #![allow(clippy::disallowed_names)] +/// # #![expect(clippy::disallowed_names)] /// use kernel::{types::Opaque, init::{self, init_from_closure}}; /// struct Foo { /// buf: [u8; 1_000_000],
rust/kernel/init/__internal.rs +2 -2
@@ -54,7 +54,7 @@ wherepub unsafe trait HasPinData {type PinData :PinData ; -#[allow(clippy::missing_safety_doc)] +#[expect(clippy::missing_safety_doc)] unsafe fn __pin_data () ->Self ::PinData ; }
@@ -84,7 +84,7 @@ pub unsafe trait PinData: Copy {pub unsafe trait HasInitData {type InitData :InitData ; -#[allow(clippy::missing_safety_doc)] +#[expect(clippy::missing_safety_doc)] unsafe fn __init_data () ->Self ::InitData ; }
rust/kernel/init/macros.rs +5 -5
@@ -182,13 +182,13 @@//! // Normally `Drop` bounds do not have the correct semantics, but for this purpose they do //! // (normally people want to know if a type has any kind of drop glue at all, here we want //! // to know if it has any kind of custom drop glue, which is exactly what this bound does). -//! #[allow(drop_bounds)] +//! #[expect(drop_bounds)] //! impl<T: ::core::ops::Drop> MustNotImplDrop for T {} //! impl<T> MustNotImplDrop for Bar<T> {} //! // Here comes a convenience check, if one implemented `PinnedDrop`, but forgot to add it to //! // `#[pin_data]`, then this will error with the same mechanic as above, this is not needed //! // for safety, but a good sanity check, since no normal code calls `PinnedDrop::drop`. -//! #[allow(non_camel_case_types)] +//! #[expect(non_camel_case_types)] //! trait UselessPinnedDropImpl_you_need_to_specify_PinnedDrop {} //! impl< //! T: ::kernel::init::PinnedDrop,
@@ -925,14 +925,14 @@ macro_rules! __pin_data {// `Drop`. Additionally we will implement this trait for the struct leading to a conflict, // if it also implements `Drop` trait MustNotImplDrop {} -#[allow(drop_bounds)] +#[expect(drop_bounds)] impl <T : ::core::ops::Drop >MustNotImplDrop for T {} impl<$($impl_generics)*> MustNotImplDrop for $name<$($ty_generics)*> where $($whr)* {}// We also take care to prevent users from writing a useless `PinnedDrop` implementation. // They might implement `PinnedDrop` correctly for the struct, but forget to give // `PinnedDrop` as the parameter to `#[pin_data]`. -#[allow(non_camel_case_types)] +#[expect(non_camel_case_types)] trait UselessPinnedDropImpl_you_need_to_specify_PinnedDrop {}impl <T : $crate::init::PinnedDrop >UselessPinnedDropImpl_you_need_to_specify_PinnedDrop for T {}
@@ -989,7 +989,7 @@ macro_rules! __pin_data {// // The functions are `unsafe` to prevent accidentally calling them. #[allow(dead_code)] -#[allow(clippy::missing_safety_doc)] +#[expect(clippy::missing_safety_doc)] impl<$($impl_generics)*> $pin_data<$($ty_generics)*> where $($whr)* {
rust/kernel/ioctl.rs +1 -1
@@ -4,7 +4,7 @@//! //! C header: [`include/asm-generic/ioctl.h`](srctree/include/asm-generic/ioctl.h) -#![allow(non_snake_case)] +#![expect(non_snake_case)] use crate ::build_assert;
rust/kernel/lib.rs +1 -0
@@ -15,6 +15,7 @@#![feature(arbitrary_self_types)] #![feature(coerce_unsized)] #![feature(dispatch_from_dyn)] +#![feature(lint_reasons)] #![feature(new_uninit)] #![feature(unsize)]
rust/kernel/list/arc_field.rs +1 -1
@@ -56,7 +56,7 @@ impl<T, const ID: u64> ListArcField<T, I/// /// The caller must have mutable access to the `ListArc<ID>` containing the struct with this /// field for the duration of the returned reference. -#[allow(clippy::mut_from_ref)] +#[expect(clippy::mut_from_ref)] pub unsafe fn assert_mut (&self) -> &mut T {// SAFETY: The caller has exclusive access to the `ListArc`, so they also have exclusive // access to this field.
rust/kernel/print.rs +2 -2
@@ -14,7 +14,7 @@ use core::{use crate ::str::RawFormatter ;// Called from `vsprintf` with format specifier `%pA`. -#[allow(clippy::missing_safety_doc)] +#[expect(clippy::missing_safety_doc)] #[no_mangle] unsafe extern "C" fn rust_fmt_argument ( buf: *mut c_char,
@@ -140,7 +140,7 @@ pub fn call_printk_cont(args: fmt::Argum#[doc(hidden)] #[cfg(not(testlib))] #[macro_export] -#[allow(clippy::crate_in_macro_def)] +#[expect(clippy::crate_in_macro_def)] macro_rules! print_macro ( // The non-continuation cases (most of them, e.g. `INFO`). ($format_string:path, false, $($arg:tt)+) => (
rust/kernel/std_vendor.rs +5 -5
@@ -16,7 +16,7 @@/// /// ```rust /// let a = 2; -/// # #[allow(clippy::disallowed_macros)] +/// # #[expect(clippy::disallowed_macros)] /// let b = dbg!(a * 2) + 1; /// // ^-- prints: [src/main.rs:2] a * 2 = 4 /// assert_eq!(b, 5);
@@ -54,7 +54,7 @@/// With a method call: /// /// ```rust -/// # #[allow(clippy::disallowed_macros)] +/// # #[expect(clippy::disallowed_macros)] /// fn foo(n: usize) { /// if dbg!(n.checked_sub(4)).is_some() { /// // ...
@@ -73,7 +73,7 @@/// Naive factorial implementation: /// /// ```rust -/// # #[allow(clippy::disallowed_macros)] +/// # #[expect(clippy::disallowed_macros)] /// # { /// fn factorial(n: u32) -> u32 { /// if dbg!(n <= 1) {
@@ -120,7 +120,7 @@/// a tuple (and return it, too): /// /// ``` -/// # #![allow(clippy::disallowed_macros)] +/// # #![expect(clippy::disallowed_macros)] /// assert_eq!(dbg!(1usize, 2u32), (1, 2)); /// ``` ///
@@ -129,7 +129,7 @@/// invocations. You can use a 1-tuple directly if you need one: /// /// ``` -/// # #[allow(clippy::disallowed_macros)] +/// # #[expect(clippy::disallowed_macros)] /// # { /// assert_eq!(1, dbg!(1u32,)); // trailing comma ignored /// assert_eq!((1,), dbg!((1u32,))); // 1-tuple
samples/rust/rust_print.rs +1 -1
@@ -15,7 +15,7 @@ module! {struct RustPrint ; -#[allow(clippy::disallowed_macros)] +#[expect(clippy::disallowed_macros)] fn arc_print () ->Result {use kernel::sync::*;
scripts/Makefile.build +1 -1
@@ -248,7 +248,7 @@ $(obj)/%.lst: $(obj)/%.c FORCE # Compile Rust sources (.rs) # --------------------------------------------------------------------------- -rust_allowed_features := arbitrary_self_types,new_uninit +rust_allowed_features := arbitrary_self_types,lint_reasons,new_uninit # `--out-dir` is required to avoid temporaries being created by `rustc` in the # current working directory, which may be not accessible in the out-of-tree
Patches currently in stable-queue which might be from [email protected] are
queue-6.12/drm-panic-avoid-reimplementing-iterator-find.patch queue-6.12/documentation-rust-add-coding-guidelines-on-lints.patch queue-6.12/rust-provide-proper-code-documentation-titles.patch queue-6.12/rust-alloc-make-allocator-module-public.patch queue-6.12/rust-alloc-remove-vecext-extension.patch queue-6.12/rust-alloc-implement-reallocfunc.patch queue-6.12/rust-alloc-separate-aligned_size-from-krealloc_aligned.patch queue-6.12/rust-enable-clippy-unnecessary_safety_comment-lint.patch queue-6.12/rust-alloc-update-module-comment-of-alloc.rs.patch queue-6.12/rust-kbuild-expand-rusttest-target-for-macros.patch queue-6.12/rust-error-use-core-alloc-layouterror.patch queue-6.12/rust-str-test-replace-alloc-format.patch queue-6.12/loongarch-use-asm_reachable.patch queue-6.12/rust-alloc-implement-allocator-for-kmalloc.patch queue-6.12/rust-alloc-implement-collect-for-intoiter.patch queue-6.12/rust-alloc-introduce-arraylayout.patch queue-6.12/rust-alloc-implement-vmalloc-allocator.patch queue-6.12/documentation-rust-discuss-in-the-guidelines.patch queue-6.12/rust-error-check-for-config-test-in-error-name.patch queue-6.12/rust-enable-clippy-ignored_unit_patterns-lint.patch queue-6.12/rust-enable-clippy-unnecessary_safety_doc-lint.patch queue-6.12/rust-alloc-add-box-to-prelude.patch queue-6.12/kbuild-rust-remove-the-alloc-crate-and-globalalloc.patch queue-6.12/rust-alloc-add-allocator-trait.patch queue-6.12/rust-treewide-switch-to-our-kernel-box-type.patch queue-6.12/rust-introduce-.clippy.toml.patch queue-6.12/rust-alloc-rename-kernelallocator-to-kmalloc.patch queue-6.12/rust-alloc-implement-cmalloc-in-module-allocator_test.patch queue-6.12/drm-panic-allow-verbose-version-check.patch queue-6.12/rust-map-__kernel_size_t-and-friends-also-to-usize-isize.patch queue-6.12/rust-alloc-add-module-allocator_test.patch queue-6.12/rust-replace-clippy-dbg_macro-with-disallowed_macros.patch queue-6.12/rust-alloc-add-__gfp_nowarn-to-flags.patch queue-6.12/rust-enable-clippy-s-check-private-items.patch queue-6.12/rust-error-make-conversion-functions-public.patch queue-6.12/rust-sort-global-rust-flags.patch queue-6.12/rust-alloc-implement-contains-for-flags.patch queue-6.12/rust-init-remove-unneeded.patch queue-6.12/rust-use-custom-ffi-integer-types.patch queue-6.12/rust-sync-remove-unneeded.patch queue-6.12/rust-treewide-switch-to-the-kernel-vec-type.patch queue-6.12/rust-alloc-implement-kvmalloc-allocator.patch queue-6.12/drm-panic-correctly-indent-continuation-of-line-in-list-item.patch queue-6.12/rust-alloc-implement-kernel-vec-type.patch queue-6.12/rust-workqueue-remove-unneeded.patch queue-6.12/rust-error-optimize-error-type-to-use-nonzero.patch queue-6.12/drm-panic-remove-unnecessary-borrow-in-alignment_pattern.patch queue-6.12/rust-alloc-remove-extension-of-std-s-box.patch queue-6.12/rust-block-fix-formatting-in-gendisk-doc.patch queue-6.12/rust-enable-rustdoc-unescaped_backticks-lint.patch queue-6.12/rust-fix-size_t-in-bindgen-prototypes-of-c-builtins.patch queue-6.12/rust-enable-clippy-undocumented_unsafe_blocks-lint.patch queue-6.12/rust-alloc-add-vec-to-prelude.patch queue-6.12/rust-alloc-implement-intoiterator-for-vec.patch queue-6.12/rust-alloc-implement-kernel-box.patch queue-6.12/drm-panic-remove-redundant-field-when-assigning-value.patch queue-6.12/rust-types-avoid-repetition-in-as-from-bytes-impls.patch queue-6.12/rust-start-using-the-attribute.patch queue-6.12/drm-panic-allow-verbose-boolean-for-clarity.patch queue-6.12/maintainers-add-entry-for-the-rust-alloc-module.patch queue-6.12/rust-alloc-fix-arraylayout-allocations.patch queue-6.12/drm-panic-prefer-eliding-lifetimes.patch
Patch "rust: str: test: replace `alloc::format`" has been added to the 6.12-stable tree
In reply to Miguel OjedaThis is a note to let you know that I've just added the patch titled
rust: str: test: replace alloc::format
to the 6.12-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
rust-str-test-replace-alloc-format.patch
and it can be found in the queue-6.12 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
From [email protected] Fri Mar 7 23:52:58 2025
From: Miguel Ojeda <[email protected]>
Date: Fri, 7 Mar 2025 23:49:52 +0100
Subject: rust: str: test: replace alloc::format
To: Greg Kroah-Hartman <[email protected]>, Sasha Levin <[email protected]>, [email protected]
Cc: Danilo Krummrich <[email protected]>, Alice Ryhl <[email protected]>, Alyssa Ross <[email protected]>, NoisyCoil <[email protected]>, [email protected], Miguel Ojeda <[email protected]>
Message-ID: <[email protected]>
From: Danilo Krummrich <[email protected]>
commit eb6f92cd3f755c179204ea1f933b07cf992892fd upstream.
The current implementation of tests in str.rs use format! to format strings for comparison, which, internally, creates a new String.
In order to prepare for getting rid of Rust's alloc crate, we have to cut this dependency. Instead, implement format! for CString.
Note that for userspace tests, Kmalloc, which is backing CString's memory, is just a type alias to Cmalloc.
--- rust/kernel/str.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)
rust/kernel/str.rs +22 -1
@@ -524,7 +524,28 @@ macro_rules! c_str {#[cfg(test)] mod tests {use super ::*; -use alloc::format; + +struct String (CString ); + +impl String { +fn from_fmt (args: fmt::Arguments <'_>) ->Self { +String (CString ::try_from_fmt (args).unwrap ()) + } + } + +impl Deref for String { +type Target =str ; + +fn deref (&self) -> &str { + self.0 .to_str ().unwrap () + } + } + +macro_rules! format { + ($($f:tt)*) => ({ + &*String ::from_fmt (kernel::fmt!($($f)*)) + }) + }const ALL_ASCII_CHARS : &'staticstr ="\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\x08\\x09\\x0a\\x0b\\x0c\\x0d\\x0e\\x0f\
Patches currently in stable-queue which might be from [email protected] are
queue-6.12/drm-panic-avoid-reimplementing-iterator-find.patch queue-6.12/documentation-rust-add-coding-guidelines-on-lints.patch queue-6.12/rust-provide-proper-code-documentation-titles.patch queue-6.12/rust-alloc-make-allocator-module-public.patch queue-6.12/rust-alloc-remove-vecext-extension.patch queue-6.12/rust-alloc-implement-reallocfunc.patch queue-6.12/rust-alloc-separate-aligned_size-from-krealloc_aligned.patch queue-6.12/rust-enable-clippy-unnecessary_safety_comment-lint.patch queue-6.12/rust-alloc-update-module-comment-of-alloc.rs.patch queue-6.12/rust-kbuild-expand-rusttest-target-for-macros.patch queue-6.12/rust-error-use-core-alloc-layouterror.patch queue-6.12/rust-str-test-replace-alloc-format.patch queue-6.12/loongarch-use-asm_reachable.patch queue-6.12/rust-alloc-implement-allocator-for-kmalloc.patch queue-6.12/rust-alloc-implement-collect-for-intoiter.patch queue-6.12/rust-alloc-introduce-arraylayout.patch queue-6.12/rust-alloc-implement-vmalloc-allocator.patch queue-6.12/documentation-rust-discuss-in-the-guidelines.patch queue-6.12/rust-error-check-for-config-test-in-error-name.patch queue-6.12/rust-enable-clippy-ignored_unit_patterns-lint.patch queue-6.12/rust-enable-clippy-unnecessary_safety_doc-lint.patch queue-6.12/rust-alloc-add-box-to-prelude.patch queue-6.12/kbuild-rust-remove-the-alloc-crate-and-globalalloc.patch queue-6.12/rust-alloc-add-allocator-trait.patch queue-6.12/rust-treewide-switch-to-our-kernel-box-type.patch queue-6.12/rust-introduce-.clippy.toml.patch queue-6.12/rust-alloc-rename-kernelallocator-to-kmalloc.patch queue-6.12/rust-alloc-implement-cmalloc-in-module-allocator_test.patch queue-6.12/drm-panic-allow-verbose-version-check.patch queue-6.12/rust-map-__kernel_size_t-and-friends-also-to-usize-isize.patch queue-6.12/rust-alloc-add-module-allocator_test.patch queue-6.12/rust-replace-clippy-dbg_macro-with-disallowed_macros.patch queue-6.12/rust-alloc-add-__gfp_nowarn-to-flags.patch queue-6.12/rust-enable-clippy-s-check-private-items.patch queue-6.12/rust-error-make-conversion-functions-public.patch queue-6.12/rust-sort-global-rust-flags.patch queue-6.12/rust-alloc-implement-contains-for-flags.patch queue-6.12/rust-init-remove-unneeded.patch queue-6.12/rust-use-custom-ffi-integer-types.patch queue-6.12/rust-sync-remove-unneeded.patch queue-6.12/rust-treewide-switch-to-the-kernel-vec-type.patch queue-6.12/rust-alloc-implement-kvmalloc-allocator.patch queue-6.12/drm-panic-correctly-indent-continuation-of-line-in-list-item.patch queue-6.12/rust-alloc-implement-kernel-vec-type.patch queue-6.12/rust-workqueue-remove-unneeded.patch queue-6.12/rust-error-optimize-error-type-to-use-nonzero.patch queue-6.12/drm-panic-remove-unnecessary-borrow-in-alignment_pattern.patch queue-6.12/rust-alloc-remove-extension-of-std-s-box.patch queue-6.12/rust-block-fix-formatting-in-gendisk-doc.patch queue-6.12/rust-enable-rustdoc-unescaped_backticks-lint.patch queue-6.12/rust-fix-size_t-in-bindgen-prototypes-of-c-builtins.patch queue-6.12/rust-enable-clippy-undocumented_unsafe_blocks-lint.patch queue-6.12/rust-alloc-add-vec-to-prelude.patch queue-6.12/rust-alloc-implement-intoiterator-for-vec.patch queue-6.12/rust-alloc-implement-kernel-box.patch queue-6.12/drm-panic-remove-redundant-field-when-assigning-value.patch queue-6.12/rust-types-avoid-repetition-in-as-from-bytes-impls.patch queue-6.12/rust-start-using-the-attribute.patch queue-6.12/drm-panic-allow-verbose-boolean-for-clarity.patch queue-6.12/maintainers-add-entry-for-the-rust-alloc-module.patch queue-6.12/rust-alloc-fix-arraylayout-allocations.patch queue-6.12/drm-panic-prefer-eliding-lifetimes.patch
Patch "rust: sync: remove unneeded `#[allow(clippy::non_send_fields_in_send_ty)]`" has been added to the 6.12-stable tree
In reply to Miguel OjedaThis is a note to let you know that I've just added the patch titled
rust: sync: remove unneeded #[allow(clippy::non_send_fields_in_send_ty)]
to the 6.12-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
rust-sync-remove-unneeded.patch
and it can be found in the queue-6.12 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
From [email protected] Fri Mar 7 23:51:07 2025
From: Miguel Ojeda <[email protected]>
Date: Fri, 7 Mar 2025 23:49:17 +0100
Subject: rust: sync: remove unneeded #[allow(clippy::non_send_fields_in_send_ty)]
To: Greg Kroah-Hartman <[email protected]>, Sasha Levin <[email protected]>, [email protected]
Cc: Danilo Krummrich <[email protected]>, Alice Ryhl <[email protected]>, Alyssa Ross <[email protected]>, NoisyCoil <[email protected]>, [email protected], Miguel Ojeda <[email protected]>
Message-ID: <[email protected]>
From: Miguel Ojeda <[email protected]>
commit 5e7c9b84ad08cc7a41b2ddbbbaccb60057da3860 upstream.
Rust 1.58.0 (before Rust was merged into the kernel) made Clippy's non_send_fields_in_send_ty lint part of the suspicious lint group for a brief window of time [1] until the minor version 1.58.1 got released a week after, where the lint was moved back to nursery.
By that time, we had already upgraded to that Rust version, and thus we had allowed the lint here for CondVar.
Nowadays, Clippy's non_send_fields_in_send_ty would still trigger here if it were enabled.
Moreover, if enabled, Lock<T, B> and Task would also require an allow. Therefore, it does not seem like someone is actually enabling it (in, e.g., a custom flags build).
Finally, the lint does not appear to have had major improvements since then [2].
Thus remove the allow since it is unneeded.
--- rust/kernel/sync/condvar.rs | 1 - 1 file changed, 1 deletion(-)
rust/kernel/sync/condvar.rs +0 -1
@@ -92,7 +92,6 @@ pub struct CondVar { _pin: PhantomPinned, } -#[allow(clippy::non_send_fields_in_send_ty)] // SAFETY: `CondVar` only uses a `struct wait_queue_head`, which is safe to use on any thread. unsafe impl Send for CondVar {}
Patches currently in stable-queue which might be from [email protected] are
queue-6.12/drm-panic-avoid-reimplementing-iterator-find.patch queue-6.12/documentation-rust-add-coding-guidelines-on-lints.patch queue-6.12/rust-provide-proper-code-documentation-titles.patch queue-6.12/rust-alloc-make-allocator-module-public.patch queue-6.12/rust-alloc-remove-vecext-extension.patch queue-6.12/rust-alloc-implement-reallocfunc.patch queue-6.12/rust-alloc-separate-aligned_size-from-krealloc_aligned.patch queue-6.12/rust-enable-clippy-unnecessary_safety_comment-lint.patch queue-6.12/rust-alloc-update-module-comment-of-alloc.rs.patch queue-6.12/rust-kbuild-expand-rusttest-target-for-macros.patch queue-6.12/rust-error-use-core-alloc-layouterror.patch queue-6.12/rust-str-test-replace-alloc-format.patch queue-6.12/loongarch-use-asm_reachable.patch queue-6.12/rust-alloc-implement-allocator-for-kmalloc.patch queue-6.12/rust-alloc-implement-collect-for-intoiter.patch queue-6.12/rust-alloc-introduce-arraylayout.patch queue-6.12/rust-alloc-implement-vmalloc-allocator.patch queue-6.12/documentation-rust-discuss-in-the-guidelines.patch queue-6.12/rust-error-check-for-config-test-in-error-name.patch queue-6.12/rust-enable-clippy-ignored_unit_patterns-lint.patch queue-6.12/rust-enable-clippy-unnecessary_safety_doc-lint.patch queue-6.12/rust-alloc-add-box-to-prelude.patch queue-6.12/kbuild-rust-remove-the-alloc-crate-and-globalalloc.patch queue-6.12/rust-alloc-add-allocator-trait.patch queue-6.12/rust-treewide-switch-to-our-kernel-box-type.patch queue-6.12/rust-introduce-.clippy.toml.patch queue-6.12/rust-alloc-rename-kernelallocator-to-kmalloc.patch queue-6.12/rust-alloc-implement-cmalloc-in-module-allocator_test.patch queue-6.12/drm-panic-allow-verbose-version-check.patch queue-6.12/rust-map-__kernel_size_t-and-friends-also-to-usize-isize.patch queue-6.12/rust-alloc-add-module-allocator_test.patch queue-6.12/rust-replace-clippy-dbg_macro-with-disallowed_macros.patch queue-6.12/rust-alloc-add-__gfp_nowarn-to-flags.patch queue-6.12/rust-enable-clippy-s-check-private-items.patch queue-6.12/rust-error-make-conversion-functions-public.patch queue-6.12/rust-sort-global-rust-flags.patch queue-6.12/rust-alloc-implement-contains-for-flags.patch queue-6.12/rust-init-remove-unneeded.patch queue-6.12/rust-use-custom-ffi-integer-types.patch queue-6.12/rust-sync-remove-unneeded.patch queue-6.12/rust-treewide-switch-to-the-kernel-vec-type.patch queue-6.12/rust-alloc-implement-kvmalloc-allocator.patch queue-6.12/drm-panic-correctly-indent-continuation-of-line-in-list-item.patch queue-6.12/rust-alloc-implement-kernel-vec-type.patch queue-6.12/rust-workqueue-remove-unneeded.patch queue-6.12/rust-error-optimize-error-type-to-use-nonzero.patch queue-6.12/drm-panic-remove-unnecessary-borrow-in-alignment_pattern.patch queue-6.12/rust-alloc-remove-extension-of-std-s-box.patch queue-6.12/rust-block-fix-formatting-in-gendisk-doc.patch queue-6.12/rust-enable-rustdoc-unescaped_backticks-lint.patch queue-6.12/rust-fix-size_t-in-bindgen-prototypes-of-c-builtins.patch queue-6.12/rust-enable-clippy-undocumented_unsafe_blocks-lint.patch queue-6.12/rust-alloc-add-vec-to-prelude.patch queue-6.12/rust-alloc-implement-intoiterator-for-vec.patch queue-6.12/rust-alloc-implement-kernel-box.patch queue-6.12/drm-panic-remove-redundant-field-when-assigning-value.patch queue-6.12/rust-types-avoid-repetition-in-as-from-bytes-impls.patch queue-6.12/rust-start-using-the-attribute.patch queue-6.12/drm-panic-allow-verbose-boolean-for-clarity.patch queue-6.12/maintainers-add-entry-for-the-rust-alloc-module.patch queue-6.12/rust-alloc-fix-arraylayout-allocations.patch queue-6.12/drm-panic-prefer-eliding-lifetimes.patch
Patch "rust: treewide: switch to our kernel `Box` type" has been added to the 6.12-stable tree
In reply to Miguel OjedaThis is a note to let you know that I've just added the patch titled
rust: treewide: switch to our kernel Box type
to the 6.12-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
rust-treewide-switch-to-our-kernel-box-type.patch
and it can be found in the queue-6.12 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
From [email protected] Fri Mar 7 23:52:11 2025
From: Miguel Ojeda <[email protected]>
Date: Fri, 7 Mar 2025 23:49:38 +0100
Subject: rust: treewide: switch to our kernel Box type
To: Greg Kroah-Hartman <[email protected]>, Sasha Levin <[email protected]>, [email protected]
Cc: Danilo Krummrich <[email protected]>, Alice Ryhl <[email protected]>, Alyssa Ross <[email protected]>, NoisyCoil <[email protected]>, [email protected], Miguel Ojeda <[email protected]>
Message-ID: <[email protected]>
From: Danilo Krummrich <[email protected]>
commit 8373147ce4961665c5700016b1c76299e962d077 upstream.
Now that we got the kernel Box type in place, convert all existing Box users to make use of it.
--- drivers/block/rnull.rs | 4 +- rust/kernel/init.rs | 51 +++++++++++++++++++------------------- rust/kernel/init/__internal.rs | 2 - rust/kernel/rbtree.rs | 49 ++++++++++++++++++++---------------- rust/kernel/sync/arc.rs | 17 +++++------- rust/kernel/sync/condvar.rs | 4 +- rust/kernel/sync/lock/mutex.rs | 2 - rust/kernel/sync/lock/spinlock.rs | 2 - rust/kernel/workqueue.rs | 20 +++++++------- rust/macros/lib.rs | 6 ++-- 10 files changed, 81 insertions(+), 76 deletions(-)
drivers/block/rnull.rs +2 -2
@@ -32,7 +32,7 @@ module! { }struct NullBlkModule { - _disk:Pin <Box <Mutex <GenDisk <NullBlkDevice >>>>, + _disk:Pin <KBox <Mutex <GenDisk <NullBlkDevice >>>>, }impl kernel::Module for NullBlkModule {
@@ -47,7 +47,7 @@ impl kernel::Module for NullBlkModule { .rotational(false) .build (format_args! ("rnullb{}" ,0 ), tagset)?; -let disk =Box ::pin_init (new_mutex! (disk,"nullb:disk" ), flags::GFP_KERNEL )?; +let disk =KBox ::pin_init (new_mutex! (disk,"nullb:disk" ), flags::GFP_KERNEL )?;Ok (Self { _disk: disk }) }
rust/kernel/init.rs +26 -25
178 lines not on this page · raw message
rust/kernel/init/__internal.rs +1 -1
@@ -105,7 +105,7 @@ pub unsafe trait InitData: Copy { } } -pub struct AllData <T : ?Sized >(PhantomData <fn (Box <T >) ->Box <T >>); +pub struct AllData <T : ?Sized >(PhantomData <fn (KBox <T >) ->KBox <T >>);impl <T : ?Sized >Clone for AllData <T > {fn clone (&self) ->Self {
rust/kernel/rbtree.rs +27 -22
139 lines not on this page · raw message
rust/kernel/sync/arc.rs +8 -9
@@ -17,13 +17,12 @@//! [`Arc`]: https://doc.rust-lang.org/std/sync/struct.Arc.html use crate ::{ - alloc::{box_ext::BoxExt ,AllocError ,Flags }, + alloc::{AllocError ,Flags ,KBox }, bindings, init::{self,InPlaceInit ,Init ,PinInit }, try_init, types::{ForeignOwnable ,Opaque }, }; -use alloc::boxed::Box ;use core::{ alloc::Layout , fmt,
@@ -201,11 +200,11 @@ impl<T> Arc<T> { data: contents, }; -let inner = <Box <_ >as BoxExt <_ >>::new (value, flags)?; +let inner =KBox ::new (value, flags)?;// SAFETY: We just created `inner` with a reference count of 1, which is owned by the new // `Arc` object. -Ok (unsafe {Self ::from_inner (Box ::leak (inner).into ()) }) +Ok (unsafe {Self ::from_inner (KBox ::leak (inner).into ()) }) } }
@@ -398,8 +397,8 @@ impl<T: ?Sized> Drop for Arc<T> {if is_zero {// The count reached zero, we must free the memory. // -// SAFETY: The pointer was initialised from the result of `Box::leak`. -unsafe {drop (Box ::from_raw (self.ptr.as_ptr ())) }; +// SAFETY: The pointer was initialised from the result of `KBox::leak`. +unsafe {drop (KBox ::from_raw (self.ptr.as_ptr ())) }; } } }
@@ -641,7 +640,7 @@ impl<T> UniqueArc<T> {/// Tries to allocate a new [`UniqueArc`] instance whose contents are not initialised yet. pub fn new_uninit (flags:Flags ) ->Result <UniqueArc <MaybeUninit <T >>,AllocError > {// INVARIANT: The refcount is initialised to a non-zero value. - let inner = Box::try_init::<AllocError>( + let inner = KBox::try_init::<AllocError>( try_init!(ArcInner { // SAFETY: There are no safety requirements for this FFI call. refcount: Opaque::new(unsafe { bindings::REFCOUNT_INIT(1) }),
@@ -651,8 +650,8 @@ impl<T> UniqueArc<T> { )?;Ok (UniqueArc {// INVARIANT: The newly-created object has a refcount of 1. -// SAFETY: The pointer from the `Box` is valid. - inner:unsafe {Arc ::from_inner (Box ::leak (inner).into ()) }, +// SAFETY: The pointer from the `KBox` is valid. + inner:unsafe {Arc ::from_inner (KBox ::leak (inner).into ()) }, }) } }
rust/kernel/sync/condvar.rs +2 -2
@@ -70,8 +70,8 @@ pub use new_condvar;/// } /// /// /// Allocates a new boxed `Example`. -/// fn new_example() -> Result<Pin<Box<Example>>> { -/// Box::pin_init(pin_init!(Example { +/// fn new_example() -> Result<Pin<KBox<Example>>> { +/// KBox::pin_init(pin_init!(Example { /// value <- new_mutex!(0), /// value_changed <- new_condvar!(), /// }), GFP_KERNEL)
rust/kernel/sync/lock/mutex.rs +1 -1
@@ -58,7 +58,7 @@ pub use new_mutex;/// } /// /// // Allocate a boxed `Example`. -/// let e = Box::pin_init(Example::new(), GFP_KERNEL)?; +/// let e = KBox::pin_init(Example::new(), GFP_KERNEL)?; /// assert_eq!(e.c, 10); /// assert_eq!(e.d.lock().a, 20); /// assert_eq!(e.d.lock().b, 30);
rust/kernel/sync/lock/spinlock.rs +1 -1
@@ -56,7 +56,7 @@ pub use new_spinlock;/// } /// /// // Allocate a boxed `Example`. -/// let e = Box::pin_init(Example::new(), GFP_KERNEL)?; +/// let e = KBox::pin_init(Example::new(), GFP_KERNEL)?; /// assert_eq!(e.c, 10); /// assert_eq!(e.d.lock().a, 20); /// assert_eq!(e.d.lock().b, 30);
rust/kernel/workqueue.rs +10 -10
@@ -216,7 +216,7 @@ impl Queue { func: Some(func), }); - self.enqueue (Box ::pin_init (init, flags).map_err (|_|AllocError )?); + self.enqueue (KBox ::pin_init (init, flags).map_err (|_|AllocError )?);Ok (()) } }
@@ -239,9 +239,9 @@ impl<T> ClosureWork<T> { }impl <T :FnOnce ()>WorkItem for ClosureWork <T > { -type Pointer =Pin <Box <Self >>; +type Pointer =Pin <KBox <Self >>; -fn run (mut this:Pin <Box <Self >>) { +fn run (mut this:Pin <KBox <Self >>) {if let Some (func) = this.as_mut ().project ().take () { (func)() }
@@ -297,7 +297,7 @@ pub unsafe trait RawWorkItem<const ID: u/// Defines the method that should be called directly when a work item is executed. /// -/// This trait is implemented by `Pin<Box<T>>` and [`Arc<T>`], and is mainly intended to be +/// This trait is implemented by `Pin<KBox<T>>` and [`Arc<T>`], and is mainly intended to be /// implemented for smart pointer types. For your own structs, you would implement [`WorkItem`] /// instead. The [`run`] method on this trait will usually just perform the appropriate /// `container_of` translation and then call into the [`run`][WorkItem::run] method from the
@@ -329,7 +329,7 @@ pub unsafe trait WorkItemPointer<const I/// This trait is used when the `work_struct` field is defined using the [`Work`] helper. pub trait WorkItem <const ID :u64 =0 > {/// The pointer type that this struct is wrapped in. This will typically be `Arc<Self>` or -/// `Pin<Box<Self>>`. +/// `Pin<KBox<Self>>`. type Pointer :WorkItemPointer <ID >;/// The method that should be called when this work item is executed.
@@ -567,7 +567,7 @@ where }// SAFETY: TODO. -unsafe impl <T ,const ID :u64 >WorkItemPointer <ID >for Pin <Box <T >> +unsafe impl <T ,const ID :u64 >WorkItemPointer <ID >for Pin <KBox <T >>where T :WorkItem <ID ,Pointer =Self >,T :HasWork <T ,ID >,
@@ -578,7 +578,7 @@ where// SAFETY: This computes the pointer that `__enqueue` got from `Arc::into_raw`. let ptr =unsafe {T ::work_container_of (ptr) };// SAFETY: This pointer comes from `Arc::into_raw` and we've been given back ownership. -let boxed =unsafe {Box ::from_raw (ptr) }; +let boxed =unsafe {KBox ::from_raw (ptr) };// SAFETY: The box was already pinned when it was enqueued. let pinned =unsafe {Pin ::new_unchecked (boxed) };
@@ -587,7 +587,7 @@ where }// SAFETY: TODO. -unsafe impl <T ,const ID :u64 >RawWorkItem <ID >for Pin <Box <T >> +unsafe impl <T ,const ID :u64 >RawWorkItem <ID >for Pin <KBox <T >>where T :WorkItem <ID ,Pointer =Self >,T :HasWork <T ,ID >,
@@ -601,9 +601,9 @@ where// SAFETY: We're not going to move `self` or any of its fields, so its okay to temporarily // remove the `Pin` wrapper. let boxed =unsafe {Pin ::into_inner_unchecked (self) }; -let ptr =Box ::into_raw (boxed); +let ptr =KBox ::into_raw (boxed); -// SAFETY: Pointers into a `Box` point at a valid value. +// SAFETY: Pointers into a `KBox` point at a valid value. let work_ptr =unsafe {T ::raw_get_work (ptr) };// SAFETY: `raw_get_work` returns a pointer to a valid value. let work_ptr =unsafe {Work ::raw_get (work_ptr) };
rust/macros/lib.rs +3 -3
@@ -243,7 +243,7 @@ pub fn concat_idents(ts: TokenStream) ->/// struct DriverData { /// #[pin] /// queue: Mutex<Vec<Command>>, -/// buf: Box<[u8; 1024 * 1024]>, +/// buf: KBox<[u8; 1024 * 1024]>, /// } /// ``` ///
@@ -252,7 +252,7 @@ pub fn concat_idents(ts: TokenStream) ->/// struct DriverData { /// #[pin] /// queue: Mutex<Vec<Command>>, -/// buf: Box<[u8; 1024 * 1024]>, +/// buf: KBox<[u8; 1024 * 1024]>, /// raw_info: *mut Info, /// } ///
@@ -282,7 +282,7 @@ pub fn pin_data(inner: TokenStream, item/// struct DriverData { /// #[pin] /// queue: Mutex<Vec<Command>>, -/// buf: Box<[u8; 1024 * 1024]>, +/// buf: KBox<[u8; 1024 * 1024]>, /// raw_info: *mut Info, /// } ///
Patches currently in stable-queue which might be from [email protected] are
queue-6.12/drm-panic-avoid-reimplementing-iterator-find.patch queue-6.12/documentation-rust-add-coding-guidelines-on-lints.patch queue-6.12/rust-provide-proper-code-documentation-titles.patch queue-6.12/rust-alloc-make-allocator-module-public.patch queue-6.12/rust-alloc-remove-vecext-extension.patch queue-6.12/rust-alloc-implement-reallocfunc.patch queue-6.12/rust-alloc-separate-aligned_size-from-krealloc_aligned.patch queue-6.12/rust-enable-clippy-unnecessary_safety_comment-lint.patch queue-6.12/rust-alloc-update-module-comment-of-alloc.rs.patch queue-6.12/rust-kbuild-expand-rusttest-target-for-macros.patch queue-6.12/rust-error-use-core-alloc-layouterror.patch queue-6.12/rust-str-test-replace-alloc-format.patch queue-6.12/loongarch-use-asm_reachable.patch queue-6.12/rust-alloc-implement-allocator-for-kmalloc.patch queue-6.12/rust-alloc-implement-collect-for-intoiter.patch queue-6.12/rust-alloc-introduce-arraylayout.patch queue-6.12/rust-alloc-implement-vmalloc-allocator.patch queue-6.12/documentation-rust-discuss-in-the-guidelines.patch queue-6.12/rust-error-check-for-config-test-in-error-name.patch queue-6.12/rust-enable-clippy-ignored_unit_patterns-lint.patch queue-6.12/rust-enable-clippy-unnecessary_safety_doc-lint.patch queue-6.12/rust-alloc-add-box-to-prelude.patch queue-6.12/kbuild-rust-remove-the-alloc-crate-and-globalalloc.patch queue-6.12/rust-alloc-add-allocator-trait.patch queue-6.12/rust-treewide-switch-to-our-kernel-box-type.patch queue-6.12/rust-introduce-.clippy.toml.patch queue-6.12/rust-alloc-rename-kernelallocator-to-kmalloc.patch queue-6.12/rust-alloc-implement-cmalloc-in-module-allocator_test.patch queue-6.12/drm-panic-allow-verbose-version-check.patch queue-6.12/rust-map-__kernel_size_t-and-friends-also-to-usize-isize.patch queue-6.12/rust-alloc-add-module-allocator_test.patch queue-6.12/rust-replace-clippy-dbg_macro-with-disallowed_macros.patch queue-6.12/rust-alloc-add-__gfp_nowarn-to-flags.patch queue-6.12/rust-enable-clippy-s-check-private-items.patch queue-6.12/rust-error-make-conversion-functions-public.patch queue-6.12/rust-sort-global-rust-flags.patch queue-6.12/rust-alloc-implement-contains-for-flags.patch queue-6.12/rust-init-remove-unneeded.patch queue-6.12/rust-use-custom-ffi-integer-types.patch queue-6.12/rust-sync-remove-unneeded.patch queue-6.12/rust-treewide-switch-to-the-kernel-vec-type.patch queue-6.12/rust-alloc-implement-kvmalloc-allocator.patch queue-6.12/drm-panic-correctly-indent-continuation-of-line-in-list-item.patch queue-6.12/rust-alloc-implement-kernel-vec-type.patch queue-6.12/rust-workqueue-remove-unneeded.patch queue-6.12/rust-error-optimize-error-type-to-use-nonzero.patch queue-6.12/drm-panic-remove-unnecessary-borrow-in-alignment_pattern.patch queue-6.12/rust-alloc-remove-extension-of-std-s-box.patch queue-6.12/rust-block-fix-formatting-in-gendisk-doc.patch queue-6.12/rust-enable-rustdoc-unescaped_backticks-lint.patch queue-6.12/rust-fix-size_t-in-bindgen-prototypes-of-c-builtins.patch queue-6.12/rust-enable-clippy-undocumented_unsafe_blocks-lint.patch queue-6.12/rust-alloc-add-vec-to-prelude.patch queue-6.12/rust-alloc-implement-intoiterator-for-vec.patch queue-6.12/rust-alloc-implement-kernel-box.patch queue-6.12/drm-panic-remove-redundant-field-when-assigning-value.patch queue-6.12/rust-types-avoid-repetition-in-as-from-bytes-impls.patch queue-6.12/rust-start-using-the-attribute.patch queue-6.12/drm-panic-allow-verbose-boolean-for-clarity.patch queue-6.12/maintainers-add-entry-for-the-rust-alloc-module.patch queue-6.12/rust-alloc-fix-arraylayout-allocations.patch queue-6.12/drm-panic-prefer-eliding-lifetimes.patch
Patch "rust: treewide: switch to the kernel `Vec` type" has been added to the 6.12-stable tree
In reply to Miguel OjedaThis is a note to let you know that I've just added the patch titled
rust: treewide: switch to the kernel Vec type
to the 6.12-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
rust-treewide-switch-to-the-kernel-vec-type.patch
and it can be found in the queue-6.12 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
From [email protected] Fri Mar 7 23:52:26 2025
From: Miguel Ojeda <[email protected]>
Date: Fri, 7 Mar 2025 23:49:45 +0100
Subject: rust: treewide: switch to the kernel Vec type
To: Greg Kroah-Hartman <[email protected]>, Sasha Levin <[email protected]>, [email protected]
Cc: Danilo Krummrich <[email protected]>, Alice Ryhl <[email protected]>, Alyssa Ross <[email protected]>, NoisyCoil <[email protected]>, [email protected], Miguel Ojeda <[email protected]>
Message-ID: <[email protected]>
From: Danilo Krummrich <[email protected]>
commit 58eff8e872bd04ccb3adcf99aec7334ffad06cfd upstream.
Now that we got the kernel Vec in place, convert all existing Vec users to make use of it.
--- mm/kasan/kasan_test_rust.rs | 2 +- rust/kernel/str.rs | 12 +++++------- rust/kernel/sync/locked_by.rs | 2 +- rust/kernel/types.rs | 2 +- rust/kernel/uaccess.rs | 17 +++++++---------- rust/macros/lib.rs | 6 +++--- samples/rust/rust_minimal.rs | 4 ++-- 7 files changed, 20 insertions(+), 25 deletions(-)
mm/kasan/kasan_test_rust.rs +1 -1
@@ -11,7 +11,7 @@ use kernel::prelude::*;/// drop the vector, and touch it. #[no_mangle] pub extern "C" fn kasan_test_rust_uaf () ->u8 { -let mut v:Vec <u8 > =Vec ::new (); +let mut v:KVec <u8 > =KVec ::new ();for _in 0 ..4096 { v.push (0x42 ,GFP_KERNEL ).unwrap (); }
rust/kernel/str.rs +5 -7
@@ -2,8 +2,7 @@//! String representations. -use crate ::alloc::{flags::*, vec_ext::VecExt ,AllocError }; -use alloc::vec::Vec ; +use crate ::alloc::{flags::*,AllocError ,KVec };use core::fmt::{self,Write };use core::ops::{self,Deref ,DerefMut ,Index };
@@ -791,7 +790,7 @@ impl fmt::Write for Formatter {/// assert_eq!(s.is_ok(), false); /// ``` pub struct CString { - buf:Vec <u8 >, + buf:KVec <u8 >, }impl CString {
@@ -804,7 +803,7 @@ impl CString {let size = f.bytes_written ();// Allocate a vector with the required number of bytes, and write to it. -let mut buf = <Vec <_ >as VecExt <_ >>::with_capacity (size,GFP_KERNEL )?; +let mut buf =KVec ::with_capacity (size,GFP_KERNEL )?;// SAFETY: The buffer stored in `buf` is at least of size `size` and is valid for writes. let mut f =unsafe {Formatter ::from_buffer (buf.as_mut_ptr (), size) }; f.write_fmt (args)?;
@@ -851,10 +850,9 @@ impl<'a> TryFrom<&'a CStr> for CString {type Error =AllocError ;fn try_from (cstr: &'aCStr ) ->Result <CString ,AllocError > { -let mut buf =Vec ::new (); +let mut buf =KVec ::new (); - <Vec <_ >as VecExt <_ >>::extend_from_slice (&mut buf, cstr.as_bytes_with_nul (),GFP_KERNEL ) - .map_err (|_|AllocError )?; + buf.extend_from_slice (cstr.as_bytes_with_nul (),GFP_KERNEL )?;// INVARIANT: The `CStr` and `CString` types have the same invariants for // the string data, and we copied it over without changes.
rust/kernel/sync/locked_by.rs +1 -1
@@ -43,7 +43,7 @@ use core::{cell::UnsafeCell, mem::size_o/// struct InnerDirectory { /// /// The sum of the bytes used by all files. /// bytes_used: u64, -/// _files: Vec<File>, +/// _files: KVec<File>, /// } /// /// struct Directory {
rust/kernel/types.rs +1 -1
@@ -135,7 +135,7 @@ impl ForeignOwnable for () {/// # use kernel::types::ScopeGuard; /// fn example3(arg: bool) -> Result { /// let mut vec = -/// ScopeGuard::new_with_data(Vec::new(), |v| pr_info!("vec had {} elements\n", v.len())); +/// ScopeGuard::new_with_data(KVec::new(), |v| pr_info!("vec had {} elements\n", v.len())); /// /// vec.push(10u8, GFP_KERNEL)?; /// if arg {
rust/kernel/uaccess.rs +7 -10
@@ -11,7 +11,6 @@ use crate::{ prelude::*, types::{AsBytes, FromBytes}, }; -use alloc::vec::Vec ;use core::ffi::{c_ulong, c_void};use core::mem::{size_of,MaybeUninit };
@@ -46,7 +45,6 @@ pub type UserPtr = usize;/// every byte in the region. /// /// ```no_run -/// use alloc::vec::Vec; /// use core::ffi::c_void; /// use kernel::error::Result; /// use kernel::uaccess::{UserPtr, UserSlice};
@@ -54,7 +52,7 @@ pub type UserPtr = usize;/// fn bytes_add_one(uptr: UserPtr, len: usize) -> Result<()> { /// let (read, mut write) = UserSlice::new(uptr, len).reader_writer(); /// -/// let mut buf = Vec::new(); +/// let mut buf = KVec::new(); /// read.read_all(&mut buf, GFP_KERNEL)?; /// /// for b in &mut buf {
@@ -69,7 +67,6 @@ pub type UserPtr = usize;/// Example illustrating a TOCTOU (time-of-check to time-of-use) bug. /// /// ```no_run -/// use alloc::vec::Vec; /// use core::ffi::c_void; /// use kernel::error::{code::EINVAL, Result}; /// use kernel::uaccess::{UserPtr, UserSlice};
@@ -78,21 +75,21 @@ pub type UserPtr = usize;/// fn is_valid(uptr: UserPtr, len: usize) -> Result<bool> { /// let read = UserSlice::new(uptr, len).reader(); /// -/// let mut buf = Vec::new(); +/// let mut buf = KVec::new(); /// read.read_all(&mut buf, GFP_KERNEL)?; /// /// todo!() /// } /// /// /// Returns the bytes behind this user pointer if they are valid. -/// fn get_bytes_if_valid(uptr: UserPtr, len: usize) -> Result<Vec<u8>> { +/// fn get_bytes_if_valid(uptr: UserPtr, len: usize) -> Result<KVec<u8>> { /// if !is_valid(uptr, len)? { /// return Err(EINVAL); /// } /// /// let read = UserSlice::new(uptr, len).reader(); /// -/// let mut buf = Vec::new(); +/// let mut buf = KVec::new(); /// read.read_all(&mut buf, GFP_KERNEL)?; /// /// // THIS IS A BUG! The bytes could have changed since we checked them.
@@ -130,7 +127,7 @@ impl UserSlice {/// Reads the entirety of the user slice, appending it to the end of the provided buffer. /// /// Fails with [`EFAULT`] if the read happens on a bad address. -pub fn read_all (self, buf: &mut Vec <u8 >, flags:Flags ) ->Result { +pub fn read_all (self, buf: &mut KVec <u8 >, flags:Flags ) ->Result { self.reader ().read_all (buf, flags) }
@@ -291,9 +288,9 @@ impl UserSliceReader {/// Reads the entirety of the user slice, appending it to the end of the provided buffer. /// /// Fails with [`EFAULT`] if the read happens on a bad address. -pub fn read_all (mut self, buf: &mut Vec <u8 >, flags:Flags ) ->Result { +pub fn read_all (mut self, buf: &mut KVec <u8 >, flags:Flags ) ->Result {let len = self.length; -VecExt ::<u8 >::reserve (buf, len, flags)?; + buf.reserve (len, flags)?;// The call to `try_reserve` was successful, so the spare capacity is at least `len` bytes // long.
rust/macros/lib.rs +3 -3
@@ -242,7 +242,7 @@ pub fn concat_idents(ts: TokenStream) ->/// #[pin_data] /// struct DriverData { /// #[pin] -/// queue: Mutex<Vec<Command>>, +/// queue: Mutex<KVec<Command>>, /// buf: KBox<[u8; 1024 * 1024]>, /// } /// ```
@@ -251,7 +251,7 @@ pub fn concat_idents(ts: TokenStream) ->/// #[pin_data(PinnedDrop)] /// struct DriverData { /// #[pin] -/// queue: Mutex<Vec<Command>>, +/// queue: Mutex<KVec<Command>>, /// buf: KBox<[u8; 1024 * 1024]>, /// raw_info: *mut Info, /// }
@@ -281,7 +281,7 @@ pub fn pin_data(inner: TokenStream, item/// #[pin_data(PinnedDrop)] /// struct DriverData { /// #[pin] -/// queue: Mutex<Vec<Command>>, +/// queue: Mutex<KVec<Command>>, /// buf: KBox<[u8; 1024 * 1024]>, /// raw_info: *mut Info, /// }
samples/rust/rust_minimal.rs +2 -2
@@ -13,7 +13,7 @@ module! { }struct RustMinimal { - numbers:Vec <i32 >, + numbers:KVec <i32 >, }impl kernel::Module for RustMinimal {
@@ -21,7 +21,7 @@ impl kernel::Module for RustMinimal {pr_info! ("Rust minimal sample (init)\n" );pr_info! ("Am I built-in? {}\n" , !cfg! (MODULE )); -let mut numbers =Vec ::new (); +let mut numbers =KVec ::new (); numbers.push (72 ,GFP_KERNEL )?; numbers.push (108 ,GFP_KERNEL )?; numbers.push (200 ,GFP_KERNEL )?;
Patches currently in stable-queue which might be from [email protected] are
queue-6.12/drm-panic-avoid-reimplementing-iterator-find.patch queue-6.12/documentation-rust-add-coding-guidelines-on-lints.patch queue-6.12/rust-provide-proper-code-documentation-titles.patch queue-6.12/rust-alloc-make-allocator-module-public.patch queue-6.12/rust-alloc-remove-vecext-extension.patch queue-6.12/rust-alloc-implement-reallocfunc.patch queue-6.12/rust-alloc-separate-aligned_size-from-krealloc_aligned.patch queue-6.12/rust-enable-clippy-unnecessary_safety_comment-lint.patch queue-6.12/rust-alloc-update-module-comment-of-alloc.rs.patch queue-6.12/rust-kbuild-expand-rusttest-target-for-macros.patch queue-6.12/rust-error-use-core-alloc-layouterror.patch queue-6.12/rust-str-test-replace-alloc-format.patch queue-6.12/loongarch-use-asm_reachable.patch queue-6.12/rust-alloc-implement-allocator-for-kmalloc.patch queue-6.12/rust-alloc-implement-collect-for-intoiter.patch queue-6.12/rust-alloc-introduce-arraylayout.patch queue-6.12/rust-alloc-implement-vmalloc-allocator.patch queue-6.12/documentation-rust-discuss-in-the-guidelines.patch queue-6.12/rust-error-check-for-config-test-in-error-name.patch queue-6.12/rust-enable-clippy-ignored_unit_patterns-lint.patch queue-6.12/rust-enable-clippy-unnecessary_safety_doc-lint.patch queue-6.12/rust-alloc-add-box-to-prelude.patch queue-6.12/kbuild-rust-remove-the-alloc-crate-and-globalalloc.patch queue-6.12/rust-alloc-add-allocator-trait.patch queue-6.12/rust-treewide-switch-to-our-kernel-box-type.patch queue-6.12/rust-introduce-.clippy.toml.patch queue-6.12/rust-alloc-rename-kernelallocator-to-kmalloc.patch queue-6.12/rust-alloc-implement-cmalloc-in-module-allocator_test.patch queue-6.12/drm-panic-allow-verbose-version-check.patch queue-6.12/rust-map-__kernel_size_t-and-friends-also-to-usize-isize.patch queue-6.12/rust-alloc-add-module-allocator_test.patch queue-6.12/rust-replace-clippy-dbg_macro-with-disallowed_macros.patch queue-6.12/rust-alloc-add-__gfp_nowarn-to-flags.patch queue-6.12/rust-enable-clippy-s-check-private-items.patch queue-6.12/rust-error-make-conversion-functions-public.patch queue-6.12/rust-sort-global-rust-flags.patch queue-6.12/rust-alloc-implement-contains-for-flags.patch queue-6.12/rust-init-remove-unneeded.patch queue-6.12/rust-use-custom-ffi-integer-types.patch queue-6.12/rust-sync-remove-unneeded.patch queue-6.12/rust-treewide-switch-to-the-kernel-vec-type.patch queue-6.12/rust-alloc-implement-kvmalloc-allocator.patch queue-6.12/drm-panic-correctly-indent-continuation-of-line-in-list-item.patch queue-6.12/rust-alloc-implement-kernel-vec-type.patch queue-6.12/rust-workqueue-remove-unneeded.patch queue-6.12/rust-error-optimize-error-type-to-use-nonzero.patch queue-6.12/drm-panic-remove-unnecessary-borrow-in-alignment_pattern.patch queue-6.12/rust-alloc-remove-extension-of-std-s-box.patch queue-6.12/rust-block-fix-formatting-in-gendisk-doc.patch queue-6.12/rust-enable-rustdoc-unescaped_backticks-lint.patch queue-6.12/rust-fix-size_t-in-bindgen-prototypes-of-c-builtins.patch queue-6.12/rust-enable-clippy-undocumented_unsafe_blocks-lint.patch queue-6.12/rust-alloc-add-vec-to-prelude.patch queue-6.12/rust-alloc-implement-intoiterator-for-vec.patch queue-6.12/rust-alloc-implement-kernel-box.patch queue-6.12/drm-panic-remove-redundant-field-when-assigning-value.patch queue-6.12/rust-types-avoid-repetition-in-as-from-bytes-impls.patch queue-6.12/rust-start-using-the-attribute.patch queue-6.12/drm-panic-allow-verbose-boolean-for-clarity.patch queue-6.12/maintainers-add-entry-for-the-rust-alloc-module.patch queue-6.12/rust-alloc-fix-arraylayout-allocations.patch queue-6.12/drm-panic-prefer-eliding-lifetimes.patch
Patch "rust: types: avoid repetition in `{As,From}Bytes` impls" has been added to the 6.12-stable tree
In reply to Miguel OjedaThis is a note to let you know that I've just added the patch titled
rust: types: avoid repetition in {As,From}Bytes impls
to the 6.12-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
rust-types-avoid-repetition-in-as-from-bytes-impls.patch
and it can be found in the queue-6.12 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
From [email protected] Fri Mar 7 23:50:48 2025
From: Miguel Ojeda <[email protected]>
Date: Fri, 7 Mar 2025 23:49:10 +0100
Subject: rust: types: avoid repetition in {As,From}Bytes impls
To: Greg Kroah-Hartman <[email protected]>, Sasha Levin <[email protected]>, [email protected]
Cc: Danilo Krummrich <[email protected]>, Alice Ryhl <[email protected]>, Alyssa Ross <[email protected]>, NoisyCoil <[email protected]>, [email protected], Miguel Ojeda <[email protected]>
Message-ID: <[email protected]>
From: Miguel Ojeda <[email protected]>
commit 567cdff53e71de56ae67eaf4309db38778b7bcd3 upstream.
In order to provide // SAFETY comments for every unsafe impl, we would need to repeat them, which is not very useful and would be harder to read.
We could perhaps allow the lint (ideally within a small module), but we can take the chance to avoid the repetition of the impls themselves too by using a small local macro, like in other places where we have had to do this sort of thing.
Thus add the straightforward impl_{from,as}bytes! macros and use them to implement FromBytes.
This, in turn, will allow us in the next patch to place a // SAFETY comment that defers to the actual invocation of the macro.
--- rust/kernel/types.rs | 68 ++++++++++++++++++++++++++------------------------- 1 file changed, 35 insertions(+), 33 deletions(-)
rust/kernel/types.rs +35 -33
@@ -481,21 +481,22 @@ pub enum Either<L, R> {/// All bit-patterns must be valid for this type. This type must not have interior mutability. pub unsafe trait FromBytes {} -// SAFETY: All bit patterns are acceptable values of the types below. -unsafe impl FromBytes for u8 {} -unsafe impl FromBytes for u16 {} -unsafe impl FromBytes for u32 {} -unsafe impl FromBytes for u64 {} -unsafe impl FromBytes for usize {} -unsafe impl FromBytes for i8 {} -unsafe impl FromBytes for i16 {} -unsafe impl FromBytes for i32 {} -unsafe impl FromBytes for i64 {} -unsafe impl FromBytes for isize {} -// SAFETY: If all bit patterns are acceptable for individual values in an array, then all bit -// patterns are also acceptable for arrays of that type. -unsafe impl <T :FromBytes >FromBytes for [T ] {} -unsafe impl <T :FromBytes ,const N :usize >FromBytes for [T ;N ] {} +macro_rules! impl_frombytes { + ($($({$($generics:tt)*})? $t:ty, )*) => { + $(unsafe impl $($($generics)*)?FromBytes for $t {})* + }; +} + +impl_frombytes! { +// SAFETY: All bit patterns are acceptable values of the types below. +u8 ,u16 ,u32 ,u64 ,usize , +i8 ,i16 ,i32 ,i64 ,isize , + +// SAFETY: If all bit patterns are acceptable for individual values in an array, then all bit +// patterns are also acceptable for arrays of that type. + {<T :FromBytes >} [T ], + {<T :FromBytes ,const N :usize >} [T ;N ], +}/// Types that can be viewed as an immutable slice of initialized bytes. ///
@@ -514,21 +515,22 @@ unsafe impl<T: FromBytes, const N: usize/// mutability. pub unsafe trait AsBytes {} -// SAFETY: Instances of the following types have no uninitialized portions. -unsafe impl AsBytes for u8 {} -unsafe impl AsBytes for u16 {} -unsafe impl AsBytes for u32 {} -unsafe impl AsBytes for u64 {} -unsafe impl AsBytes for usize {} -unsafe impl AsBytes for i8 {} -unsafe impl AsBytes for i16 {} -unsafe impl AsBytes for i32 {} -unsafe impl AsBytes for i64 {} -unsafe impl AsBytes for isize {} -unsafe impl AsBytes for bool {} -unsafe impl AsBytes for char {} -unsafe impl AsBytes for str {} -// SAFETY: If individual values in an array have no uninitialized portions, then the array itself -// does not have any uninitialized portions either. -unsafe impl <T :AsBytes >AsBytes for [T ] {} -unsafe impl <T :AsBytes ,const N :usize >AsBytes for [T ;N ] {} +macro_rules! impl_asbytes { + ($($({$($generics:tt)*})? $t:ty, )*) => { + $(unsafe impl $($($generics)*)?AsBytes for $t {})* + }; +} + +impl_asbytes! { +// SAFETY: Instances of the following types have no uninitialized portions. +u8 ,u16 ,u32 ,u64 ,usize , +i8 ,i16 ,i32 ,i64 ,isize , +bool , +char , +str , + +// SAFETY: If individual values in an array have no uninitialized portions, then the array +// itself does not have any uninitialized portions either. + {<T :AsBytes >} [T ], + {<T :AsBytes ,const N :usize >} [T ;N ], +}
Patches currently in stable-queue which might be from [email protected] are
queue-6.12/drm-panic-avoid-reimplementing-iterator-find.patch queue-6.12/documentation-rust-add-coding-guidelines-on-lints.patch queue-6.12/rust-provide-proper-code-documentation-titles.patch queue-6.12/rust-alloc-make-allocator-module-public.patch queue-6.12/rust-alloc-remove-vecext-extension.patch queue-6.12/rust-alloc-implement-reallocfunc.patch queue-6.12/rust-alloc-separate-aligned_size-from-krealloc_aligned.patch queue-6.12/rust-enable-clippy-unnecessary_safety_comment-lint.patch queue-6.12/rust-alloc-update-module-comment-of-alloc.rs.patch queue-6.12/rust-kbuild-expand-rusttest-target-for-macros.patch queue-6.12/rust-error-use-core-alloc-layouterror.patch queue-6.12/rust-str-test-replace-alloc-format.patch queue-6.12/loongarch-use-asm_reachable.patch queue-6.12/rust-alloc-implement-allocator-for-kmalloc.patch queue-6.12/rust-alloc-implement-collect-for-intoiter.patch queue-6.12/rust-alloc-introduce-arraylayout.patch queue-6.12/rust-alloc-implement-vmalloc-allocator.patch queue-6.12/documentation-rust-discuss-in-the-guidelines.patch queue-6.12/rust-error-check-for-config-test-in-error-name.patch queue-6.12/rust-enable-clippy-ignored_unit_patterns-lint.patch queue-6.12/rust-enable-clippy-unnecessary_safety_doc-lint.patch queue-6.12/rust-alloc-add-box-to-prelude.patch queue-6.12/kbuild-rust-remove-the-alloc-crate-and-globalalloc.patch queue-6.12/rust-alloc-add-allocator-trait.patch queue-6.12/rust-treewide-switch-to-our-kernel-box-type.patch queue-6.12/rust-introduce-.clippy.toml.patch queue-6.12/rust-alloc-rename-kernelallocator-to-kmalloc.patch queue-6.12/rust-alloc-implement-cmalloc-in-module-allocator_test.patch queue-6.12/drm-panic-allow-verbose-version-check.patch queue-6.12/rust-map-__kernel_size_t-and-friends-also-to-usize-isize.patch queue-6.12/rust-alloc-add-module-allocator_test.patch queue-6.12/rust-replace-clippy-dbg_macro-with-disallowed_macros.patch queue-6.12/rust-alloc-add-__gfp_nowarn-to-flags.patch queue-6.12/rust-enable-clippy-s-check-private-items.patch queue-6.12/rust-error-make-conversion-functions-public.patch queue-6.12/rust-sort-global-rust-flags.patch queue-6.12/rust-alloc-implement-contains-for-flags.patch queue-6.12/rust-init-remove-unneeded.patch queue-6.12/rust-use-custom-ffi-integer-types.patch queue-6.12/rust-sync-remove-unneeded.patch queue-6.12/rust-treewide-switch-to-the-kernel-vec-type.patch queue-6.12/rust-alloc-implement-kvmalloc-allocator.patch queue-6.12/drm-panic-correctly-indent-continuation-of-line-in-list-item.patch queue-6.12/rust-alloc-implement-kernel-vec-type.patch queue-6.12/rust-workqueue-remove-unneeded.patch queue-6.12/rust-error-optimize-error-type-to-use-nonzero.patch queue-6.12/drm-panic-remove-unnecessary-borrow-in-alignment_pattern.patch queue-6.12/rust-alloc-remove-extension-of-std-s-box.patch queue-6.12/rust-block-fix-formatting-in-gendisk-doc.patch queue-6.12/rust-enable-rustdoc-unescaped_backticks-lint.patch queue-6.12/rust-fix-size_t-in-bindgen-prototypes-of-c-builtins.patch queue-6.12/rust-enable-clippy-undocumented_unsafe_blocks-lint.patch queue-6.12/rust-alloc-add-vec-to-prelude.patch queue-6.12/rust-alloc-implement-intoiterator-for-vec.patch queue-6.12/rust-alloc-implement-kernel-box.patch queue-6.12/drm-panic-remove-redundant-field-when-assigning-value.patch queue-6.12/rust-types-avoid-repetition-in-as-from-bytes-impls.patch queue-6.12/rust-start-using-the-attribute.patch queue-6.12/drm-panic-allow-verbose-boolean-for-clarity.patch queue-6.12/maintainers-add-entry-for-the-rust-alloc-module.patch queue-6.12/rust-alloc-fix-arraylayout-allocations.patch queue-6.12/drm-panic-prefer-eliding-lifetimes.patch
Patch "rust: use custom FFI integer types" has been added to the 6.12-stable tree
In reply to Miguel OjedaThis is a note to let you know that I've just added the patch titled
rust: use custom FFI integer types
to the 6.12-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
rust-use-custom-ffi-integer-types.patch
and it can be found in the queue-6.12 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
From [email protected] Fri Mar 7 23:53:20 2025
From: Miguel Ojeda <[email protected]>
Date: Fri, 7 Mar 2025 23:50:06 +0100
Subject: rust: use custom FFI integer types
To: Greg Kroah-Hartman <[email protected]>, Sasha Levin <[email protected]>, [email protected]
Cc: Danilo Krummrich <[email protected]>, Alice Ryhl <[email protected]>, Alyssa Ross <[email protected]>, NoisyCoil <[email protected]>, [email protected], Miguel Ojeda <[email protected]>
Message-ID: <[email protected]>
From: Gary Guo <[email protected]>
commit d072acda4862f095ec9056979b654cc06a22cc68 upstream.
Currently FFI integer types are defined in libcore. This commit creates the ffi crate and asks bindgen to use that crate for FFI integer types instead of core::ffi.
This commit is preparatory and no type changes are made in this commit yet.
[ Added rustdoc, rusttest and KUnit tests support. Rebased on top of
rust-next (e.g. migrated more core::ffi cases). Reworded crate docs slightly and formatted. - Miguel ]
--- rust/Makefile | 39 ++++++++++++++++++++++++------------ rust/ffi.rs | 13 ++++++++++++ rust/kernel/alloc/allocator.rs | 2 - rust/kernel/alloc/allocator_test.rs | 4 +-- rust/kernel/alloc/kbox.rs | 12 +++++------ 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 | 20 +++++++++--------- rust/kernel/init.rs | 2 - rust/kernel/lib.rs | 2 + rust/kernel/net/phy.rs | 16 +++++++------- rust/kernel/str.rs | 4 +-- rust/kernel/sync/arc.rs | 6 ++--- rust/kernel/sync/condvar.rs | 2 - rust/kernel/sync/lock.rs | 2 - rust/kernel/sync/lock/mutex.rs | 2 - rust/kernel/sync/lock/spinlock.rs | 2 - rust/kernel/task.rs | 8 +------ rust/kernel/time.rs | 4 +-- rust/kernel/types.rs | 14 ++++++------ rust/kernel/uaccess.rs | 6 ++--- rust/macros/module.rs | 8 +++---- 23 files changed, 107 insertions(+), 83 deletions(-) create mode 100644 rust/ffi.rs
rust/Makefile +26 -13
@@ -3,7 +3,7 @@ # Where to place rustdoc generated documentation rustdoc_output := $(objtree)/Documentation/output/rust/rustdoc -obj-$(CONFIG_RUST) += core.o compiler_builtins.o +obj-$(CONFIG_RUST) += core.o compiler_builtins.o ffi.o always-$(CONFIG_RUST) += exports_core_generated.h # Missing prototypes are expected in the helpers since these are exported
@@ -103,10 +103,13 @@ rustdoc-core: $(RUST_LIB_SRC)/core/src/l rustdoc-compiler_builtins: $(src)/compiler_builtins.rs rustdoc-core FORCE +$(call if_changed,rustdoc) -rustdoc-kernel: private rustc_target_flags = \ +rustdoc-ffi: $(src)/ffi.rs rustdoc-core FORCE + +$(call if_changed,rustdoc) + +rustdoc-kernel: private rustc_target_flags = --extern ffi \ --extern build_error --extern macros=$(objtree)/$(obj)/libmacros.so \ --extern bindings --extern uapi -rustdoc-kernel: $(src)/kernel/lib.rs rustdoc-core rustdoc-macros \ +rustdoc-kernel: $(src)/kernel/lib.rs rustdoc-core rustdoc-ffi rustdoc-macros \ rustdoc-compiler_builtins $(obj)/libmacros.so \ $(obj)/bindings.o FORCE +$(call if_changed,rustdoc)
@@ -124,12 +127,15 @@ quiet_cmd_rustc_test_library = RUSTC TL rusttestlib-build_error: $(src)/build_error.rs FORCE +$(call if_changed,rustc_test_library) +rusttestlib-ffi: $(src)/ffi.rs FORCE + +$(call if_changed,rustc_test_library) + rusttestlib-macros: private rustc_target_flags = --extern proc_macro rusttestlib-macros: private rustc_test_library_proc = yes rusttestlib-macros: $(src)/macros/lib.rs FORCE +$(call if_changed,rustc_test_library) -rusttestlib-kernel: private rustc_target_flags = \ +rusttestlib-kernel: private rustc_target_flags = --extern ffi \ --extern build_error --extern macros \ --extern bindings --extern uapi rusttestlib-kernel: $(src)/kernel/lib.rs \
@@ -137,10 +143,12 @@ rusttestlib-kernel: $(src)/kernel/lib.rs $(obj)/libmacros.so $(obj)/bindings.o FORCE +$(call if_changed,rustc_test_library) -rusttestlib-bindings: $(src)/bindings/lib.rs FORCE +rusttestlib-bindings: private rustc_target_flags = --extern ffi +rusttestlib-bindings: $(src)/bindings/lib.rs rusttestlib-ffi FORCE +$(call if_changed,rustc_test_library) -rusttestlib-uapi: $(src)/uapi/lib.rs FORCE +rusttestlib-uapi: private rustc_target_flags = --extern ffi +rusttestlib-uapi: $(src)/uapi/lib.rs rusttestlib-ffi FORCE +$(call if_changed,rustc_test_library) quiet_cmd_rustdoc_test = RUSTDOC T $<
@@ -159,7 +167,7 @@ quiet_cmd_rustdoc_test_kernel = RUSTDOC mkdir -p $(objtree)/$(obj)/test/doctests/kernel; \ OBJTREE=$(abspath $(objtree)) \ $(RUSTDOC) --test $(rust_flags) \ - -L$(objtree)/$(obj) --extern kernel \ + -L$(objtree)/$(obj) --extern ffi --extern kernel \ --extern build_error --extern macros \ --extern bindings --extern uapi \ --no-run --crate-name kernel -Zunstable-options \
@@ -197,9 +205,9 @@ rusttest-macros: $(src)/macros/lib.rs \ +$(call if_changed,rustc_test) +$(call if_changed,rustdoc_test) -rusttest-kernel: private rustc_target_flags = \ +rusttest-kernel: private rustc_target_flags = --extern ffi \ --extern build_error --extern macros --extern bindings --extern uapi -rusttest-kernel: $(src)/kernel/lib.rs rusttestlib-kernel \ +rusttest-kernel: $(src)/kernel/lib.rs rusttestlib-ffi rusttestlib-kernel \ rusttestlib-build_error rusttestlib-macros rusttestlib-bindings \ rusttestlib-uapi FORCE +$(call if_changed,rustc_test)
@@ -286,7 +294,7 @@ bindgen_c_flags_final = $(bindgen_c_flag quiet_cmd_bindgen = BINDGEN $@ cmd_bindgen = \ $(BINDGEN) $< $(bindgen_target_flags) --rust-target 1.68 \ - --use-core --with-derive-default --ctypes-prefix core::ffi --no-layout-tests \ + --use-core --with-derive-default --ctypes-prefix ffi --no-layout-tests \ --no-debug '.*' --enable-function-attribute-detection \ -o $@ -- $(bindgen_c_flags_final) -DMODULE \ $(bindgen_target_cflags) $(bindgen_target_extra)
@@ -414,18 +422,23 @@ $(obj)/compiler_builtins.o: $(src)/compi $(obj)/build_error.o: $(src)/build_error.rs $(obj)/compiler_builtins.o FORCE +$(call if_changed_rule,rustc_library) +$(obj)/ffi.o: $(src)/ffi.rs $(obj)/compiler_builtins.o FORCE + +$(call if_changed_rule,rustc_library) + +$(obj)/bindings.o: private rustc_target_flags = --extern ffi $(obj)/bindings.o: $(src)/bindings/lib.rs \ - $(obj)/compiler_builtins.o \ + $(obj)/ffi.o \ $(obj)/bindings/bindings_generated.rs \ $(obj)/bindings/bindings_helpers_generated.rs FORCE +$(call if_changed_rule,rustc_library) +$(obj)/uapi.o: private rustc_target_flags = --extern ffi $(obj)/uapi.o: $(src)/uapi/lib.rs \ - $(obj)/compiler_builtins.o \ + $(obj)/ffi.o \ $(obj)/uapi/uapi_generated.rs FORCE +$(call if_changed_rule,rustc_library) -$(obj)/kernel.o: private rustc_target_flags = \ +$(obj)/kernel.o: private rustc_target_flags = --extern ffi \ --extern build_error --extern macros --extern bindings --extern uapi $(obj)/kernel.o: $(src)/kernel/lib.rs $(obj)/build_error.o \ $(obj)/libmacros.so $(obj)/bindings.o $(obj)/uapi.o FORCE
rust/ffi.rs new file +13 -0
@@ -0,0 +1,13 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! Foreign function interface (FFI) types. +//! +//! This crate provides mapping from C primitive types to Rust ones. +//! +//! The Rust [`core`] crate provides [`core::ffi`], which maps integer types to the platform default +//! C ABI. The kernel does not use [`core::ffi`], so it can customise the mapping that deviates from +//! the platform default. + +#![no_std] + +pub use core::ffi::*;
rust/kernel/alloc/allocator.rs +1 -1
@@ -58,7 +58,7 @@ fn aligned_size(new_layout: Layout) -> u/// /// One of the following: `krealloc`, `vrealloc`, `kvrealloc`. struct ReallocFunc ( -unsafe extern "C" fn (*const core::ffi::c_void ,usize ,u32 ) -> *mut core::ffi::c_void , +unsafe extern "C" fn (*const crate ::ffi::c_void ,usize ,u32 ) -> *mut crate ::ffi::c_void , );impl ReallocFunc {
rust/kernel/alloc/allocator_test.rs +2 -2
@@ -24,10 +24,10 @@ pub type KVmalloc = Kmalloc;extern "C" {#[link_name = "aligned_alloc" ] -fn libc_aligned_alloc (align:usize , size:usize ) -> *mut core::ffi::c_void ; +fn libc_aligned_alloc (align:usize , size:usize ) -> *mut crate ::ffi::c_void ;#[link_name = "free" ] -fn libc_free (ptr: *mut core::ffi::c_void ); +fn libc_free (ptr: *mut crate ::ffi::c_void ); }// SAFETY:
rust/kernel/alloc/kbox.rs +6 -6
@@ -355,17 +355,17 @@ where {type Borrowed <'a> = &'aT ; -fn into_foreign (self) -> *const core::ffi::c_void { +fn into_foreign (self) -> *const crate ::ffi::c_void {Box ::into_raw (self)as _ } -unsafe fn from_foreign (ptr: *const core::ffi::c_void ) ->Self { +unsafe fn from_foreign (ptr: *const crate ::ffi::c_void ) ->Self {// SAFETY: The safety requirements of this function ensure that `ptr` comes from a previous // call to `Self::into_foreign`. unsafe {Box ::from_raw (ptras _ ) } } -unsafe fn borrow <'a>(ptr: *const core::ffi::c_void ) -> &'aT { +unsafe fn borrow <'a>(ptr: *const crate ::ffi::c_void ) -> &'aT {// SAFETY: The safety requirements of this method ensure that the object remains alive and // immutable for the duration of 'a. unsafe { &*ptr.cast () }
@@ -378,18 +378,18 @@ where {type Borrowed <'a> =Pin <&'aT >; -fn into_foreign (self) -> *const core::ffi::c_void { +fn into_foreign (self) -> *const crate ::ffi::c_void {// SAFETY: We are still treating the box as pinned. Box ::into_raw (unsafe {Pin ::into_inner_unchecked (self) })as _ } -unsafe fn from_foreign (ptr: *const core::ffi::c_void ) ->Self { +unsafe fn from_foreign (ptr: *const crate ::ffi::c_void ) ->Self {// SAFETY: The safety requirements of this function ensure that `ptr` comes from a previous // call to `Self::into_foreign`. unsafe {Pin ::new_unchecked (Box ::from_raw (ptras _ )) } } -unsafe fn borrow <'a>(ptr: *const core::ffi::c_void ) ->Pin <&'aT > { +unsafe fn borrow <'a>(ptr: *const crate ::ffi::c_void ) ->Pin <&'aT > {// SAFETY: The safety requirements for this function ensure that the object is still alive, // so it is safe to dereference the raw pointer. // The safety requirements of `from_foreign` also ensure that the object remains alive for
rust/kernel/block/mq/operations.rs +9 -9
@@ -131,7 +131,7 @@ impl<T: Operations> OperationsVTable<T>unsafe extern "C" fn poll_callback ( _hctx: *mut bindings::blk_mq_hw_ctx , _iob: *mut bindings::io_comp_batch , - ) -> core::ffi::c_int { + ) ->crate ::ffi::c_int {T ::poll ().into () }
@@ -145,9 +145,9 @@ impl<T: Operations> OperationsVTable<T>/// for the same context. unsafe extern "C" fn init_hctx_callback ( _hctx: *mut bindings::blk_mq_hw_ctx , - _tagset_data: *mut core::ffi::c_void , - _hctx_idx: core::ffi::c_uint , - ) -> core::ffi::c_int { + _tagset_data: *mut crate ::ffi::c_void , + _hctx_idx:crate ::ffi::c_uint , + ) ->crate ::ffi::c_int {from_result (||Ok (0 )) }
@@ -159,7 +159,7 @@ impl<T: Operations> OperationsVTable<T>/// This function may only be called by blk-mq C infrastructure. unsafe extern "C" fn exit_hctx_callback ( _hctx: *mut bindings::blk_mq_hw_ctx , - _hctx_idx: core::ffi::c_uint , + _hctx_idx:crate ::ffi::c_uint , ) { }
@@ -176,9 +176,9 @@ impl<T: Operations> OperationsVTable<T>unsafe extern "C" fn init_request_callback ( _set: *mut bindings::blk_mq_tag_set , rq: *mut bindings::request , - _hctx_idx: core::ffi::c_uint , - _numa_node: core::ffi::c_uint , - ) -> core::ffi::c_int { + _hctx_idx:crate ::ffi::c_uint , + _numa_node:crate ::ffi::c_uint , + ) ->crate ::ffi::c_int {from_result (|| {// SAFETY: By the safety requirements of this function, `rq` points // to a valid allocation.
@@ -203,7 +203,7 @@ impl<T: Operations> OperationsVTable<T>unsafe extern "C" fn exit_request_callback ( _set: *mut bindings::blk_mq_tag_set , rq: *mut bindings::request , - _hctx_idx: core::ffi::c_uint , + _hctx_idx:crate ::ffi::c_uint , ) {// SAFETY: The tagset invariants guarantee that all requests are allocated with extra memory // for the request data.
rust/kernel/block/mq/raw_writer.rs +1 -1
@@ -25,7 +25,7 @@ impl<'a> RawWriter<'a> { }pub (crate )fn from_array <const N :usize >( - a: &'amut [core::ffi::c_char ;N ], + a: &'amut [crate ::ffi::c_char ;N ], ) ->Result <RawWriter <'a>> { Self::new(// SAFETY: the buffer of `a` is valid for read and write as `u8` for
rust/kernel/block/mq/tag_set.rs +1 -1
@@ -53,7 +53,7 @@ impl<T: Operations> TagSet<T> { queue_depth: num_tags, cmd_size, flags: bindings::BLK_MQ_F_SHOULD_MERGE, - driver_data: core::ptr::null_mut::<core::ffi::c_void>(), + driver_data: core::ptr::null_mut::<crate::ffi::c_void>(), nr_maps: num_maps, ..tag_set }
rust/kernel/error.rs +10 -10
@@ -100,7 +100,7 @@ impl Error {/// /// It is a bug to pass an out-of-range `errno`. `EINVAL` would /// be returned in such a case. -pub fn from_errno (errno: core::ffi::c_int ) ->Error { +pub fn from_errno (errno:crate ::ffi::c_int ) ->Error {if errno < -(bindings::MAX_ERRNO as i32 ) || errno >=0 {// TODO: Make it a `WARN_ONCE` once available. crate ::pr_warn!(
@@ -119,7 +119,7 @@ impl Error {/// Creates an [`Error`] from a kernel error code. /// /// Returns [`None`] if `errno` is out-of-range. -const fn try_from_errno (errno: core::ffi::c_int ) ->Option <Error > { +const fn try_from_errno (errno:crate ::ffi::c_int ) ->Option <Error > {if errno < -(bindings::MAX_ERRNO as i32 ) || errno >=0 {return None ; }
@@ -133,7 +133,7 @@ impl Error {/// # Safety /// /// `errno` must be within error code range (i.e. `>= -MAX_ERRNO && < 0`). -const unsafe fn from_errno_unchecked (errno: core::ffi::c_int ) ->Error { +const unsafe fn from_errno_unchecked (errno:crate ::ffi::c_int ) ->Error {// INVARIANT: The contract ensures the type invariant // will hold. // SAFETY: The caller guarantees `errno` is non-zero.
@@ -141,7 +141,7 @@ impl Error { }/// Returns the kernel error code. -pub fn to_errno (self) -> core::ffi::c_int { +pub fn to_errno (self) ->crate ::ffi::c_int { self.0 .get () }
@@ -259,7 +259,7 @@ pub type Result<T = (), E = Error> = cor/// Converts an integer as returned by a C kernel function to an error if it's negative, and /// `Ok(())` otherwise. -pub fn to_result (err: core::ffi::c_int ) ->Result { +pub fn to_result (err:crate ::ffi::c_int ) ->Result {if err <0 {Err (Error ::from_errno (err)) }else {
@@ -282,15 +282,15 @@ pub fn to_result(err: core::ffi::c_int)/// fn devm_platform_ioremap_resource( /// pdev: &mut PlatformDevice, /// index: u32, -/// ) -> Result<*mut core::ffi::c_void> { +/// ) -> Result<*mut kernel::ffi::c_void> { /// // SAFETY: `pdev` points to a valid platform device. There are no safety requirements /// // on `index`. /// from_err_ptr(unsafe { bindings::devm_platform_ioremap_resource(pdev.to_ptr(), index) }) /// } /// ``` pub fn from_err_ptr <T >(ptr: *mut T ) ->Result <*mut T > { -// CAST: Casting a pointer to `*const core::ffi::c_void` is always valid. -let const_ptr: *const core::ffi::c_void = ptr.cast (); +// CAST: Casting a pointer to `*const crate::ffi::c_void` is always valid. +let const_ptr: *const crate ::ffi::c_void = ptr.cast ();// SAFETY: The FFI function does not deref the pointer. if unsafe { bindings::IS_ERR (const_ptr) } {// SAFETY: The FFI function does not deref the pointer.
@@ -306,7 +306,7 @@ pub fn from_err_ptr<T>(ptr: *mut T) -> R// // SAFETY: `IS_ERR()` ensures `err` is a // negative value greater-or-equal to `-bindings::MAX_ERRNO`. -return Err (unsafe {Error ::from_errno_unchecked (erras core::ffi::c_int ) }); +return Err (unsafe {Error ::from_errno_unchecked (erras crate ::ffi::c_int ) }); }Ok (ptr) }
@@ -326,7 +326,7 @@ pub fn from_err_ptr<T>(ptr: *mut T) -> R/// # use kernel::bindings; /// unsafe extern "C" fn probe_callback( /// pdev: *mut bindings::platform_device, -/// ) -> core::ffi::c_int { +/// ) -> kernel::ffi::c_int { /// from_result(|| { /// let ptr = devm_alloc(pdev)?; /// bindings::platform_set_drvdata(pdev, ptr);
rust/kernel/init.rs +1 -1
@@ -133,7 +133,7 @@//! # } //! # // `Error::from_errno` is `pub(crate)` in the `kernel` crate, thus provide a workaround. //! # trait FromErrno { -//! # fn from_errno(errno: core::ffi::c_int) -> Error { +//! # fn from_errno(errno: kernel::ffi::c_int) -> Error { //! # // Dummy error that can be constructed outside the `kernel` crate. //! # Error::from(core::fmt::Error) //! # }
rust/kernel/lib.rs +2 -0
@@ -27,6 +27,8 @@ compile_error!("Missing kernel configura// Allow proc-macros to refer to `::kernel` inside the `kernel` crate (this crate). extern crate selfas kernel; +pub use ffi; +pub mod alloc;#[cfg( CONFIG_BLOCK )] pub mod block;
rust/kernel/net/phy.rs +8 -8
@@ -314,7 +314,7 @@ impl<T: Driver> Adapter<T> {/// `phydev` must be passed by the corresponding callback in `phy_driver`. unsafe extern "C" fn soft_reset_callback ( phydev: *mut bindings::phy_device , - ) -> core::ffi::c_int { + ) ->crate ::ffi::c_int {from_result (|| {// SAFETY: This callback is called only in contexts // where we hold `phy_device->lock`, so the accessors on
@@ -328,7 +328,7 @@ impl<T: Driver> Adapter<T> {/// # Safety /// /// `phydev` must be passed by the corresponding callback in `phy_driver`. -unsafe extern "C" fn probe_callback (phydev: *mut bindings::phy_device ) -> core::ffi::c_int { +unsafe extern "C" fn probe_callback (phydev: *mut bindings::phy_device ) ->crate ::ffi::c_int {from_result (|| {// SAFETY: This callback is called only in contexts // where we can exclusively access `phy_device` because
@@ -345,7 +345,7 @@ impl<T: Driver> Adapter<T> {/// `phydev` must be passed by the corresponding callback in `phy_driver`. unsafe extern "C" fn get_features_callback ( phydev: *mut bindings::phy_device , - ) -> core::ffi::c_int { + ) ->crate ::ffi::c_int {from_result (|| {// SAFETY: This callback is called only in contexts // where we hold `phy_device->lock`, so the accessors on
@@ -359,7 +359,7 @@ impl<T: Driver> Adapter<T> {/// # Safety /// /// `phydev` must be passed by the corresponding callback in `phy_driver`. -unsafe extern "C" fn suspend_callback (phydev: *mut bindings::phy_device ) -> core::ffi::c_int { +unsafe extern "C" fn suspend_callback (phydev: *mut bindings::phy_device ) ->crate ::ffi::c_int {from_result (|| {// SAFETY: The C core code ensures that the accessors on // `Device` are okay to call even though `phy_device->lock`
@@ -373,7 +373,7 @@ impl<T: Driver> Adapter<T> {/// # Safety /// /// `phydev` must be passed by the corresponding callback in `phy_driver`. -unsafe extern "C" fn resume_callback (phydev: *mut bindings::phy_device ) -> core::ffi::c_int { +unsafe extern "C" fn resume_callback (phydev: *mut bindings::phy_device ) ->crate ::ffi::c_int {from_result (|| {// SAFETY: The C core code ensures that the accessors on // `Device` are okay to call even though `phy_device->lock`
@@ -389,7 +389,7 @@ impl<T: Driver> Adapter<T> {/// `phydev` must be passed by the corresponding callback in `phy_driver`. unsafe extern "C" fn config_aneg_callback ( phydev: *mut bindings::phy_device , - ) -> core::ffi::c_int { + ) ->crate ::ffi::c_int {from_result (|| {// SAFETY: This callback is called only in contexts // where we hold `phy_device->lock`, so the accessors on
@@ -405,7 +405,7 @@ impl<T: Driver> Adapter<T> {/// `phydev` must be passed by the corresponding callback in `phy_driver`. unsafe extern "C" fn read_status_callback ( phydev: *mut bindings::phy_device , - ) -> core::ffi::c_int { + ) ->crate ::ffi::c_int {from_result (|| {// SAFETY: This callback is called only in contexts // where we hold `phy_device->lock`, so the accessors on
@@ -421,7 +421,7 @@ impl<T: Driver> Adapter<T> {/// `phydev` must be passed by the corresponding callback in `phy_driver`. unsafe extern "C" fn match_phy_device_callback ( phydev: *mut bindings::phy_device , - ) -> core::ffi::c_int { + ) ->crate ::ffi::c_int {// SAFETY: This callback is called only in contexts // where we hold `phy_device->lock`, so the accessors on // `Device` are okay to call.
rust/kernel/str.rs +2 -2
@@ -184,7 +184,7 @@ impl CStr {/// last at least `'a`. When `CStr` is alive, the memory pointed by `ptr` /// must not be mutated. #[inline] -pub unsafe fn from_char_ptr <'a>(ptr: *const core::ffi::c_char ) -> &'aSelf { +pub unsafe fn from_char_ptr <'a>(ptr: *const crate ::ffi::c_char ) -> &'aSelf {// SAFETY: The safety precondition guarantees `ptr` is a valid pointer // to a `NUL`-terminated C string. let len =unsafe { bindings::strlen (ptr) } +1 ;
@@ -247,7 +247,7 @@ impl CStr {/// Returns a C pointer to the string. #[inline] -pub const fn as_char_ptr (&self) -> *const core::ffi::c_char { +pub const fn as_char_ptr (&self) -> *const crate ::ffi::c_char { self.0 .as_ptr ()as _ }
rust/kernel/sync/arc.rs +3 -3
@@ -332,11 +332,11 @@ impl<T: ?Sized> Arc<T> {impl <T : 'static>ForeignOwnable for Arc <T > {type Borrowed <'a> =ArcBorrow <'a,T >; -fn into_foreign (self) -> *const core::ffi::c_void { +fn into_foreign (self) -> *const crate ::ffi::c_void {ManuallyDrop ::new (self).ptr.as_ptr ()as _ } -unsafe fn borrow <'a>(ptr: *const core::ffi::c_void ) ->ArcBorrow <'a,T > { +unsafe fn borrow <'a>(ptr: *const crate ::ffi::c_void ) ->ArcBorrow <'a,T > {// By the safety requirement of this function, we know that `ptr` came from // a previous call to `Arc::into_foreign`. let inner =NonNull ::new (ptras *mut ArcInner <T >).unwrap ();
@@ -346,7 +346,7 @@ impl<T: 'static> ForeignOwnable for Arc<unsafe {ArcBorrow ::new (inner) } } -unsafe fn from_foreign (ptr: *const core::ffi::c_void ) ->Self { +unsafe fn from_foreign (ptr: *const crate ::ffi::c_void ) ->Self {// SAFETY: By the safety requirement of this function, we know that `ptr` came from // a previous call to `Arc::into_foreign`, which guarantees that `ptr` is valid and // holds a reference count increment that is transferrable to us.
rust/kernel/sync/condvar.rs +1 -1
@@ -7,6 +7,7 @@use super ::{lock::Backend , lock::Guard ,LockClassKey };use crate ::{ + ffi::{c_int, c_long}, init::PinInit , pin_init, str::CStr ,
@@ -14,7 +15,6 @@ use crate::{ time::Jiffies, types::Opaque, }; -use core::ffi::{c_int, c_long};use core::marker::PhantomPinned ;use core::ptr;use macros::pin_data;
rust/kernel/sync/lock.rs +1 -1
@@ -46,7 +46,7 @@ pub unsafe trait Backend {/// remain valid for read indefinitely. unsafe fn init ( ptr: *mut Self ::State , - name: *const core::ffi::c_char , + name: *const crate ::ffi::c_char , key: *mut bindings::lock_class_key , );
rust/kernel/sync/lock/mutex.rs +1 -1
@@ -96,7 +96,7 @@ unsafe impl super::Backend for MutexBackunsafe fn init ( ptr: *mut Self ::State , - name: *const core::ffi::c_char , + name: *const crate ::ffi::c_char , key: *mut bindings::lock_class_key , ) {// SAFETY: The safety requirements ensure that `ptr` is valid for writes, and `name` and
rust/kernel/sync/lock/spinlock.rs +1 -1
@@ -95,7 +95,7 @@ unsafe impl super::Backend for SpinLockBunsafe fn init ( ptr: *mut Self ::State , - name: *const core::ffi::c_char , + name: *const crate ::ffi::c_char , key: *mut bindings::lock_class_key , ) {// SAFETY: The safety requirements ensure that `ptr` is valid for writes, and `name` and
rust/kernel/task.rs +2 -6
@@ -4,13 +4,9 @@//! //! C header: [`include/linux/sched.h`](srctree/include/linux/sched.h). +use crate ::ffi::{c_int, c_long, c_uint};use crate ::types::Opaque ; -use core::{ - ffi::{c_int, c_long, c_uint}, - marker::PhantomData , - ops::Deref , - ptr, -}; +use core::{marker::PhantomData , ops::Deref , ptr};/// A sentinel value used for infinite timeouts. pub const MAX_SCHEDULE_TIMEOUT :c_long = c_long::MAX ;
rust/kernel/time.rs +2 -2
@@ -12,10 +12,10 @@pub const NSEC_PER_MSEC :i64 = bindings::NSEC_PER_MSEC as i64 ;/// The time unit of Linux kernel. One jiffy equals (1/HZ) second. -pub type Jiffies = core::ffi::c_ulong ; +pub type Jiffies =crate ::ffi::c_ulong ;/// The millisecond time unit. -pub type Msecs = core::ffi::c_uint ; +pub type Msecs =crate ::ffi::c_uint ;/// Converts milliseconds to jiffies. #[inline]
rust/kernel/types.rs +7 -7
@@ -29,7 +29,7 @@ pub trait ForeignOwnable: Sized {/// For example, it might be invalid, dangling or pointing to uninitialized memory. Using it in /// any way except for [`ForeignOwnable::from_foreign`], [`ForeignOwnable::borrow`], /// [`ForeignOwnable::try_from_foreign`] can result in undefined behavior. -fn into_foreign (self) -> *const core::ffi::c_void ; +fn into_foreign (self) -> *const crate ::ffi::c_void ;/// Borrows a foreign-owned object. ///
@@ -37,7 +37,7 @@ pub trait ForeignOwnable: Sized {/// /// `ptr` must have been returned by a previous call to [`ForeignOwnable::into_foreign`] for /// which a previous matching [`ForeignOwnable::from_foreign`] hasn't been called yet. -unsafe fn borrow <'a>(ptr: *const core::ffi::c_void ) ->Self ::Borrowed <'a>; +unsafe fn borrow <'a>(ptr: *const crate ::ffi::c_void ) ->Self ::Borrowed <'a>;/// Converts a foreign-owned object back to a Rust-owned one. ///
@@ -47,7 +47,7 @@ pub trait ForeignOwnable: Sized {/// which a previous matching [`ForeignOwnable::from_foreign`] hasn't been called yet. /// Additionally, all instances (if any) of values returned by [`ForeignOwnable::borrow`] for /// this object must have been dropped. -unsafe fn from_foreign (ptr: *const core::ffi::c_void ) ->Self ; +unsafe fn from_foreign (ptr: *const crate ::ffi::c_void ) ->Self ;/// Tries to convert a foreign-owned object back to a Rust-owned one. ///
@@ -58,7 +58,7 @@ pub trait ForeignOwnable: Sized {/// /// `ptr` must either be null or satisfy the safety requirements for /// [`ForeignOwnable::from_foreign`]. -unsafe fn try_from_foreign (ptr: *const core::ffi::c_void ) ->Option <Self > { +unsafe fn try_from_foreign (ptr: *const crate ::ffi::c_void ) ->Option <Self > {if ptr.is_null () {None }else {
@@ -72,13 +72,13 @@ pub trait ForeignOwnable: Sized {impl ForeignOwnable for () {type Borrowed <'a> = (); -fn into_foreign (self) -> *const core::ffi::c_void { +fn into_foreign (self) -> *const crate ::ffi::c_void { core::ptr::NonNull ::dangling ().as_ptr () } -unsafe fn borrow <'a>(_: *const core::ffi::c_void ) ->Self ::Borrowed <'a> {} +unsafe fn borrow <'a>(_: *const crate ::ffi::c_void ) ->Self ::Borrowed <'a> {} -unsafe fn from_foreign (_: *const core::ffi::c_void ) ->Self {} +unsafe fn from_foreign (_: *const crate ::ffi::c_void ) ->Self {} }/// Runs a cleanup function/closure when dropped.
rust/kernel/uaccess.rs +3 -3
@@ -8,10 +8,10 @@ use crate::{ alloc::Flags, bindings, error::Result, + ffi::{c_ulong, c_void}, prelude::*, types::{AsBytes, FromBytes}, }; -use core::ffi::{c_ulong, c_void};use core::mem::{size_of,MaybeUninit };/// The type used for userspace addresses.
@@ -45,7 +45,7 @@ pub type UserPtr = usize;/// every byte in the region. /// /// ```no_run -/// use core::ffi::c_void; +/// use kernel::ffi::c_void; /// use kernel::error::Result; /// use kernel::uaccess::{UserPtr, UserSlice}; ///
@@ -67,7 +67,7 @@ pub type UserPtr = usize;/// Example illustrating a TOCTOU (time-of-check to time-of-use) bug. /// /// ```no_run -/// use core::ffi::c_void; +/// use kernel::ffi::c_void; /// use kernel::error::{code::EINVAL, Result}; /// use kernel::uaccess::{UserPtr, UserSlice}; ///
rust/macros/module.rs +4 -4
@@ -253,7 +253,7 @@ pub(crate) fn module(ts: TokenStream) ->#[doc(hidden)] #[no_mangle] #[link_section = \".init.text\"] - pub unsafe extern \"C\" fn init_module() -> core::ffi::c_int {{ + pub unsafe extern \"C\" fn init_module() -> kernel::ffi::c_int {{ // SAFETY: This function is inaccessible to the outside due to the double // module wrapping it. It is called exactly once by the C side via its // unique name.
@@ -292,7 +292,7 @@ pub(crate) fn module(ts: TokenStream) ->#[doc(hidden)] #[link_section = \"{initcall_section}\"] #[used] - pub static __{name}_initcall: extern \"C\" fn() -> core::ffi::c_int = __{name}_init; + pub static __{name}_initcall: extern \"C\" fn() -> kernel::ffi::c_int = __{name}_init; #[cfg(not(MODULE))] #[cfg(CONFIG_HAVE_ARCH_PREL32_RELOCATIONS)]
@@ -307,7 +307,7 @@ pub(crate) fn module(ts: TokenStream) ->#[cfg(not( MODULE ))] #[doc(hidden)] #[no_mangle] - pub extern \"C\" fn __{name}_init() -> core::ffi::c_int {{ + pub extern \"C\" fn __{name}_init() -> kernel::ffi::c_int {{ // SAFETY: This function is inaccessible to the outside due to the double // module wrapping it. It is called exactly once by the C side via its // placement above in the initcall section.
@@ -330,7 +330,7 @@ pub(crate) fn module(ts: TokenStream) ->/// # Safety /// /// This function must only be called once. -unsafe fn __init () -> core::ffi::c_int {{ +unsafe fn __init () -> kernel::ffi::c_int {{ match <{type_} as kernel::Module>::init(&super::super::THIS_MODULE) {{Ok (m) => {{// SAFETY: No data race, since `__MOD` can only be accessed by this
Patches currently in stable-queue which might be from [email protected] are
queue-6.12/drm-panic-avoid-reimplementing-iterator-find.patch queue-6.12/documentation-rust-add-coding-guidelines-on-lints.patch queue-6.12/rust-provide-proper-code-documentation-titles.patch queue-6.12/rust-alloc-make-allocator-module-public.patch queue-6.12/rust-alloc-remove-vecext-extension.patch queue-6.12/rust-alloc-implement-reallocfunc.patch queue-6.12/rust-alloc-separate-aligned_size-from-krealloc_aligned.patch queue-6.12/rust-enable-clippy-unnecessary_safety_comment-lint.patch queue-6.12/rust-alloc-update-module-comment-of-alloc.rs.patch queue-6.12/rust-kbuild-expand-rusttest-target-for-macros.patch queue-6.12/rust-error-use-core-alloc-layouterror.patch queue-6.12/rust-str-test-replace-alloc-format.patch queue-6.12/loongarch-use-asm_reachable.patch queue-6.12/rust-alloc-implement-allocator-for-kmalloc.patch queue-6.12/rust-alloc-implement-collect-for-intoiter.patch queue-6.12/rust-alloc-introduce-arraylayout.patch queue-6.12/rust-alloc-implement-vmalloc-allocator.patch queue-6.12/documentation-rust-discuss-in-the-guidelines.patch queue-6.12/rust-error-check-for-config-test-in-error-name.patch queue-6.12/rust-enable-clippy-ignored_unit_patterns-lint.patch queue-6.12/rust-enable-clippy-unnecessary_safety_doc-lint.patch queue-6.12/rust-alloc-add-box-to-prelude.patch queue-6.12/kbuild-rust-remove-the-alloc-crate-and-globalalloc.patch queue-6.12/rust-alloc-add-allocator-trait.patch queue-6.12/rust-treewide-switch-to-our-kernel-box-type.patch queue-6.12/rust-introduce-.clippy.toml.patch queue-6.12/rust-alloc-rename-kernelallocator-to-kmalloc.patch queue-6.12/rust-alloc-implement-cmalloc-in-module-allocator_test.patch queue-6.12/drm-panic-allow-verbose-version-check.patch queue-6.12/rust-map-__kernel_size_t-and-friends-also-to-usize-isize.patch queue-6.12/rust-alloc-add-module-allocator_test.patch queue-6.12/rust-replace-clippy-dbg_macro-with-disallowed_macros.patch queue-6.12/rust-alloc-add-__gfp_nowarn-to-flags.patch queue-6.12/rust-enable-clippy-s-check-private-items.patch queue-6.12/rust-error-make-conversion-functions-public.patch queue-6.12/rust-sort-global-rust-flags.patch queue-6.12/rust-alloc-implement-contains-for-flags.patch queue-6.12/rust-init-remove-unneeded.patch queue-6.12/rust-use-custom-ffi-integer-types.patch queue-6.12/rust-sync-remove-unneeded.patch queue-6.12/rust-treewide-switch-to-the-kernel-vec-type.patch queue-6.12/rust-alloc-implement-kvmalloc-allocator.patch queue-6.12/drm-panic-correctly-indent-continuation-of-line-in-list-item.patch queue-6.12/rust-alloc-implement-kernel-vec-type.patch queue-6.12/rust-workqueue-remove-unneeded.patch queue-6.12/rust-error-optimize-error-type-to-use-nonzero.patch queue-6.12/drm-panic-remove-unnecessary-borrow-in-alignment_pattern.patch queue-6.12/rust-alloc-remove-extension-of-std-s-box.patch queue-6.12/rust-block-fix-formatting-in-gendisk-doc.patch queue-6.12/rust-enable-rustdoc-unescaped_backticks-lint.patch queue-6.12/rust-fix-size_t-in-bindgen-prototypes-of-c-builtins.patch queue-6.12/rust-enable-clippy-undocumented_unsafe_blocks-lint.patch queue-6.12/rust-alloc-add-vec-to-prelude.patch queue-6.12/rust-alloc-implement-intoiterator-for-vec.patch queue-6.12/rust-alloc-implement-kernel-box.patch queue-6.12/drm-panic-remove-redundant-field-when-assigning-value.patch queue-6.12/rust-types-avoid-repetition-in-as-from-bytes-impls.patch queue-6.12/rust-start-using-the-attribute.patch queue-6.12/drm-panic-allow-verbose-boolean-for-clarity.patch queue-6.12/maintainers-add-entry-for-the-rust-alloc-module.patch queue-6.12/rust-alloc-fix-arraylayout-allocations.patch queue-6.12/drm-panic-prefer-eliding-lifetimes.patch
Patch "rust: workqueue: remove unneeded ``#[allow(clippy::new_ret_no_self)]`" has been added to the 6.12-stable tree
In reply to Miguel OjedaThis is a note to let you know that I've just added the patch titled
rust: workqueue: remove unneeded ``#[allow(clippy::new_ret_no_self)]`
to the 6.12-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
rust-workqueue-remove-unneeded.patch
and it can be found in the queue-6.12 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
From [email protected] Fri Mar 7 23:50:44 2025
From: Miguel Ojeda <[email protected]>
Date: Fri, 7 Mar 2025 23:49:08 +0100
Subject: rust: workqueue: remove unneeded ``#[allow(clippy::new_ret_no_self)]`
To: Greg Kroah-Hartman <[email protected]>, Sasha Levin <[email protected]>, [email protected]
Cc: Danilo Krummrich <[email protected]>, Alice Ryhl <[email protected]>, Alyssa Ross <[email protected]>, NoisyCoil <[email protected]>, [email protected], Miguel Ojeda <[email protected]>
Message-ID: <[email protected]>
From: Miguel Ojeda <[email protected]>
commit 024f9676a6d236132119832a90fb9a1a9115b41a upstream.
Perform the same clean commit b2516f7af9d2 ("rust: kernel: remove #[allow(clippy::new_ret_no_self)]") did for a case that appeared in workqueue in parallel in commit 7324b88975c5 ("rust: workqueue: add helper for defining work_struct fields"):
Clippy triggered a false positive on its new_ret_no_self lint when using the pin_init! macro. Since Rust 1.67.0, that does not happen anymore, since Clippy learnt to not warn about -> impl Trait<Self> [1][2].
The kernel nowadays uses Rust 1.72.1, thus remove the #[allow].
--- rust/kernel/workqueue.rs | 1 - 1 file changed, 1 deletion(-)
rust/kernel/workqueue.rs +0 -1
@@ -366,7 +366,6 @@ unsafe impl<T: ?Sized, const ID: u64> Syimpl <T : ?Sized ,const ID :u64 >Work <T ,ID > {/// Creates a new instance of [`Work`]. #[inline] -#[allow(clippy::new_ret_no_self)] pub fn new (name: &'staticCStr , key: &'staticLockClassKey ) ->impl PinInit <Self >where T :WorkItem <ID >,
Patches currently in stable-queue which might be from [email protected] are
queue-6.12/drm-panic-avoid-reimplementing-iterator-find.patch queue-6.12/documentation-rust-add-coding-guidelines-on-lints.patch queue-6.12/rust-provide-proper-code-documentation-titles.patch queue-6.12/rust-alloc-make-allocator-module-public.patch queue-6.12/rust-alloc-remove-vecext-extension.patch queue-6.12/rust-alloc-implement-reallocfunc.patch queue-6.12/rust-alloc-separate-aligned_size-from-krealloc_aligned.patch queue-6.12/rust-enable-clippy-unnecessary_safety_comment-lint.patch queue-6.12/rust-alloc-update-module-comment-of-alloc.rs.patch queue-6.12/rust-kbuild-expand-rusttest-target-for-macros.patch queue-6.12/rust-error-use-core-alloc-layouterror.patch queue-6.12/rust-str-test-replace-alloc-format.patch queue-6.12/loongarch-use-asm_reachable.patch queue-6.12/rust-alloc-implement-allocator-for-kmalloc.patch queue-6.12/rust-alloc-implement-collect-for-intoiter.patch queue-6.12/rust-alloc-introduce-arraylayout.patch queue-6.12/rust-alloc-implement-vmalloc-allocator.patch queue-6.12/documentation-rust-discuss-in-the-guidelines.patch queue-6.12/rust-error-check-for-config-test-in-error-name.patch queue-6.12/rust-enable-clippy-ignored_unit_patterns-lint.patch queue-6.12/rust-enable-clippy-unnecessary_safety_doc-lint.patch queue-6.12/rust-alloc-add-box-to-prelude.patch queue-6.12/kbuild-rust-remove-the-alloc-crate-and-globalalloc.patch queue-6.12/rust-alloc-add-allocator-trait.patch queue-6.12/rust-treewide-switch-to-our-kernel-box-type.patch queue-6.12/rust-introduce-.clippy.toml.patch queue-6.12/rust-alloc-rename-kernelallocator-to-kmalloc.patch queue-6.12/rust-alloc-implement-cmalloc-in-module-allocator_test.patch queue-6.12/drm-panic-allow-verbose-version-check.patch queue-6.12/rust-map-__kernel_size_t-and-friends-also-to-usize-isize.patch queue-6.12/rust-alloc-add-module-allocator_test.patch queue-6.12/rust-replace-clippy-dbg_macro-with-disallowed_macros.patch queue-6.12/rust-alloc-add-__gfp_nowarn-to-flags.patch queue-6.12/rust-enable-clippy-s-check-private-items.patch queue-6.12/rust-error-make-conversion-functions-public.patch queue-6.12/rust-sort-global-rust-flags.patch queue-6.12/rust-alloc-implement-contains-for-flags.patch queue-6.12/rust-init-remove-unneeded.patch queue-6.12/rust-use-custom-ffi-integer-types.patch queue-6.12/rust-sync-remove-unneeded.patch queue-6.12/rust-treewide-switch-to-the-kernel-vec-type.patch queue-6.12/rust-alloc-implement-kvmalloc-allocator.patch queue-6.12/drm-panic-correctly-indent-continuation-of-line-in-list-item.patch queue-6.12/rust-alloc-implement-kernel-vec-type.patch queue-6.12/rust-workqueue-remove-unneeded.patch queue-6.12/rust-error-optimize-error-type-to-use-nonzero.patch queue-6.12/drm-panic-remove-unnecessary-borrow-in-alignment_pattern.patch queue-6.12/rust-alloc-remove-extension-of-std-s-box.patch queue-6.12/rust-block-fix-formatting-in-gendisk-doc.patch queue-6.12/rust-enable-rustdoc-unescaped_backticks-lint.patch queue-6.12/rust-fix-size_t-in-bindgen-prototypes-of-c-builtins.patch queue-6.12/rust-enable-clippy-undocumented_unsafe_blocks-lint.patch queue-6.12/rust-alloc-add-vec-to-prelude.patch queue-6.12/rust-alloc-implement-intoiterator-for-vec.patch queue-6.12/rust-alloc-implement-kernel-box.patch queue-6.12/drm-panic-remove-redundant-field-when-assigning-value.patch queue-6.12/rust-types-avoid-repetition-in-as-from-bytes-impls.patch queue-6.12/rust-start-using-the-attribute.patch queue-6.12/drm-panic-allow-verbose-boolean-for-clarity.patch queue-6.12/maintainers-add-entry-for-the-rust-alloc-module.patch queue-6.12/rust-alloc-fix-arraylayout-allocations.patch queue-6.12/drm-panic-prefer-eliding-lifetimes.patch
Patch "rust: replace `clippy::dbg_macro` with `disallowed_macros`" has been added to the 6.12-stable tree
In reply to Miguel OjedaThis is a note to let you know that I've just added the patch titled
rust: replace clippy::dbg_macro with disallowed_macros
to the 6.12-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
rust-replace-clippy-dbg_macro-with-disallowed_macros.patch
and it can be found in the queue-6.12 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
From [email protected] Fri Mar 7 23:51:13 2025
From: Miguel Ojeda <[email protected]>
Date: Fri, 7 Mar 2025 23:49:19 +0100
Subject: rust: replace clippy::dbg_macro with disallowed_macros
To: Greg Kroah-Hartman <[email protected]>, Sasha Levin <[email protected]>, [email protected]
Cc: Danilo Krummrich <[email protected]>, Alice Ryhl <[email protected]>, Alyssa Ross <[email protected]>, NoisyCoil <[email protected]>, [email protected], Miguel Ojeda <[email protected]>
Message-ID: <[email protected]>
From: Miguel Ojeda <[email protected]>
commit 8577c9dca799bd74377f7c30015d8cdc53a53ca2 upstream.
Back when we used Rust 1.60.0 (before Rust was merged in the kernel), we added -Wclippy::dbg_macro to the compilation flags. This worked great with our custom dbg! macro (vendored from std, but slightly modified to use the kernel printing facilities).
However, in the very next version, 1.61.0, it stopped working [1] since the lint started to use a Rust diagnostic item rather than a path to find the dbg! macro [1]. This behavior remains until the current nightly (1.83.0).
Therefore, currently, the dbg_macro is not doing anything, which explains why we can invoke dbg! in samples/rust/rust_print.rs, as well as why changing the #[allow()]s to #[expect()]s in std_vendor.rs` doctests does not work since they are not fulfilled.
One possible workaround is using rustc_attrs like the standard library does. However, this is intended to be internal, and we just started supporting several Rust compiler versions, so it is best to avoid it.
Therefore, instead, use disallowed_macros. It is a stable lint and is more flexible (in that we can provide different macros), although its diagnostic message(s) are not as nice as the specialized one (yet), and does not allow to set different lint levels per macro/path [2].
In turn, this requires allowing the (intentional) dbg! use in the sample, as one would have expected.
Finally, in a single case, the allow is fixed to be an inner attribute, since otherwise it was not being applied.
--- .clippy.toml | 6 ++++++ Makefile | 1 - rust/kernel/std_vendor.rs | 10 +++++----- samples/rust/rust_print.rs | 1 + 4 files changed, 12 insertions(+), 6 deletions(-)
.clippy.toml +6 -0
@@ -1 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 + +disallowed-macros = [ + # The `clippy::dbg_macro` lint only works with `std::dbg!`, thus we simulate + # it here, see: https://github.com/rust-lang/rust-clippy/issues/11303. + { path = "kernel::dbg", reason = "the `dbg!` macro is intended as a debugging tool" }, +]
Makefile +0 -1
@@ -452,7 +452,6 @@ export rust_common_flags := --edition=20 -Wrust_2018_idioms \ -Wunreachable_pub \ -Wclippy::all \ - -Wclippy::dbg_macro \ -Wclippy::ignored_unit_patterns \ -Wclippy::mut_mut \ -Wclippy::needless_bitwise_bool \
rust/kernel/std_vendor.rs +5 -5
@@ -14,7 +14,7 @@/// /// ```rust /// let a = 2; -/// # #[allow(clippy::dbg_macro)] +/// # #[allow(clippy::disallowed_macros)] /// let b = dbg!(a * 2) + 1; /// // ^-- prints: [src/main.rs:2] a * 2 = 4 /// assert_eq!(b, 5);
@@ -52,7 +52,7 @@/// With a method call: /// /// ```rust -/// # #[allow(clippy::dbg_macro)] +/// # #[allow(clippy::disallowed_macros)] /// fn foo(n: usize) { /// if dbg!(n.checked_sub(4)).is_some() { /// // ...
@@ -71,7 +71,7 @@/// Naive factorial implementation: /// /// ```rust -/// # #[allow(clippy::dbg_macro)] +/// # #[allow(clippy::disallowed_macros)] /// # { /// fn factorial(n: u32) -> u32 { /// if dbg!(n <= 1) {
@@ -118,7 +118,7 @@/// a tuple (and return it, too): /// /// ``` -/// # #[allow(clippy::dbg_macro)] +/// # #![allow(clippy::disallowed_macros)] /// assert_eq!(dbg!(1usize, 2u32), (1, 2)); /// ``` ///
@@ -127,7 +127,7 @@/// invocations. You can use a 1-tuple directly if you need one: /// /// ``` -/// # #[allow(clippy::dbg_macro)] +/// # #[allow(clippy::disallowed_macros)] /// # { /// assert_eq!(1, dbg!(1u32,)); // trailing comma ignored /// assert_eq!((1,), dbg!((1u32,))); // 1-tuple
samples/rust/rust_print.rs +1 -0
@@ -15,6 +15,7 @@ module! {struct RustPrint ; +#[allow(clippy::disallowed_macros)] fn arc_print () ->Result {use kernel::sync::*;
Patches currently in stable-queue which might be from [email protected] are
queue-6.12/drm-panic-avoid-reimplementing-iterator-find.patch queue-6.12/documentation-rust-add-coding-guidelines-on-lints.patch queue-6.12/rust-provide-proper-code-documentation-titles.patch queue-6.12/rust-alloc-make-allocator-module-public.patch queue-6.12/rust-alloc-remove-vecext-extension.patch queue-6.12/rust-alloc-implement-reallocfunc.patch queue-6.12/rust-alloc-separate-aligned_size-from-krealloc_aligned.patch queue-6.12/rust-enable-clippy-unnecessary_safety_comment-lint.patch queue-6.12/rust-alloc-update-module-comment-of-alloc.rs.patch queue-6.12/rust-kbuild-expand-rusttest-target-for-macros.patch queue-6.12/rust-error-use-core-alloc-layouterror.patch queue-6.12/rust-str-test-replace-alloc-format.patch queue-6.12/loongarch-use-asm_reachable.patch queue-6.12/rust-alloc-implement-allocator-for-kmalloc.patch queue-6.12/rust-alloc-implement-collect-for-intoiter.patch queue-6.12/rust-alloc-introduce-arraylayout.patch queue-6.12/rust-alloc-implement-vmalloc-allocator.patch queue-6.12/documentation-rust-discuss-in-the-guidelines.patch queue-6.12/rust-error-check-for-config-test-in-error-name.patch queue-6.12/rust-enable-clippy-ignored_unit_patterns-lint.patch queue-6.12/rust-enable-clippy-unnecessary_safety_doc-lint.patch queue-6.12/rust-alloc-add-box-to-prelude.patch queue-6.12/kbuild-rust-remove-the-alloc-crate-and-globalalloc.patch queue-6.12/rust-alloc-add-allocator-trait.patch queue-6.12/rust-treewide-switch-to-our-kernel-box-type.patch queue-6.12/rust-introduce-.clippy.toml.patch queue-6.12/rust-alloc-rename-kernelallocator-to-kmalloc.patch queue-6.12/rust-alloc-implement-cmalloc-in-module-allocator_test.patch queue-6.12/drm-panic-allow-verbose-version-check.patch queue-6.12/rust-map-__kernel_size_t-and-friends-also-to-usize-isize.patch queue-6.12/rust-alloc-add-module-allocator_test.patch queue-6.12/rust-replace-clippy-dbg_macro-with-disallowed_macros.patch queue-6.12/rust-alloc-add-__gfp_nowarn-to-flags.patch queue-6.12/rust-enable-clippy-s-check-private-items.patch queue-6.12/rust-error-make-conversion-functions-public.patch queue-6.12/rust-sort-global-rust-flags.patch queue-6.12/rust-alloc-implement-contains-for-flags.patch queue-6.12/rust-init-remove-unneeded.patch queue-6.12/rust-use-custom-ffi-integer-types.patch queue-6.12/rust-sync-remove-unneeded.patch queue-6.12/rust-treewide-switch-to-the-kernel-vec-type.patch queue-6.12/rust-alloc-implement-kvmalloc-allocator.patch queue-6.12/drm-panic-correctly-indent-continuation-of-line-in-list-item.patch queue-6.12/rust-alloc-implement-kernel-vec-type.patch queue-6.12/rust-workqueue-remove-unneeded.patch queue-6.12/rust-error-optimize-error-type-to-use-nonzero.patch queue-6.12/drm-panic-remove-unnecessary-borrow-in-alignment_pattern.patch queue-6.12/rust-alloc-remove-extension-of-std-s-box.patch queue-6.12/rust-block-fix-formatting-in-gendisk-doc.patch queue-6.12/rust-enable-rustdoc-unescaped_backticks-lint.patch queue-6.12/rust-fix-size_t-in-bindgen-prototypes-of-c-builtins.patch queue-6.12/rust-enable-clippy-undocumented_unsafe_blocks-lint.patch queue-6.12/rust-alloc-add-vec-to-prelude.patch queue-6.12/rust-alloc-implement-intoiterator-for-vec.patch queue-6.12/rust-alloc-implement-kernel-box.patch queue-6.12/drm-panic-remove-redundant-field-when-assigning-value.patch queue-6.12/rust-types-avoid-repetition-in-as-from-bytes-impls.patch queue-6.12/rust-start-using-the-attribute.patch queue-6.12/drm-panic-allow-verbose-boolean-for-clarity.patch queue-6.12/maintainers-add-entry-for-the-rust-alloc-module.patch queue-6.12/rust-alloc-fix-arraylayout-allocations.patch queue-6.12/drm-panic-prefer-eliding-lifetimes.patch
Greg Kroah-Hartman
maintainerQuoted 35 lines · Miguel Ojeda
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
allocseries 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 libraryalloc(and the unstablecfgoption we used) anymore in any stable kernel that supports several Rust versions, so e.g. upstream Rust could consider removing thatcfgif 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=yissue. It will also make future patches easier to backport, since we will have the sameffi::types.I tested that the entire series builds between every commit for
x86_64LLVM=1with 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.
Quoted 2 lines
Things could still break, so extra tests on the next -rc from users in Cc here would be welcome -- thanks!
All queued up now, thanks!
greg k-h
Hi, I think this is missing one final change, specifically 27c7518e, or rather, the only line of it that applies:
pub unsafe extern "C" fn drm_panic_qr_generate(
- url: *const i8,
+ url: *const kernel::ffi::c_char,
Without it, the build fails on Rust 1.85 / aarch64.
Quoted 192 lines · Miguel Ojeda
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
allocseries 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 libraryalloc(and the unstablecfgoption we used) anymore in any stable kernel that supports several Rust versions, so e.g. upstream Rust could consider removing thatcfgif 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=yissue. It will also make future patches easier to backport, since we will have the sameffi::types.I tested that the entire series builds between every commit for
x86_64LLVM=1with 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,
MiguelAsahi Lina (1):
rust: alloc: FixArrayLayoutallocationsBenno Lossin (1):
rust: alloc: introduceArrayLayoutDanilo Krummrich (28):
rust: alloc: addAllocatortrait
rust: alloc: separatealigned_sizefromkrealloc_aligned
rust: alloc: renameKernelAllocatortoKmalloc
rust: alloc: implementReallocFunc
rust: alloc: makeallocatormodule public
rust: alloc: implementAllocatorforKmalloc
rust: alloc: add moduleallocator_test
rust: alloc: implementVmallocallocator
rust: alloc: implementKVmallocallocator
rust: alloc: add__GFP_NOWARNtoFlags
rust: alloc: implement kernelBox
rust: treewide: switch to our kernelBoxtype
rust: alloc: remove extension of std'sBox
rust: alloc: addBoxto prelude
rust: alloc: implement kernelVectype
rust: alloc: implementIntoIteratorforVec
rust: alloc: implementcollectforIntoIter
rust: treewide: switch to the kernelVectype
rust: alloc: removeVecExtextension
rust: alloc: addVecto prelude
rust: error: usecore::alloc::LayoutError
rust: error: check for configtestinError::name
rust: alloc: implementcontainsforFlags
rust: alloc: implementCmallocin moduleallocator_test
rust: str: test: replacealloc::format
rust: alloc: update module comment ofalloc.rs
kbuild: rust: remove thealloccrate andGlobalAlloc
MAINTAINERS: add entry for the RustallocmoduleEthan D. Twardy (1):
rust: kbuild: expand rusttest target for macrosFilipe Xavier (2):
rust: error: make conversion functions public
rust: error: optimize error type to use nonzeroGary Guo (3):
rust: fixsize_tin bindgen prototypes of C builtins
rust: map__kernel_size_tand friends also to usize/isize
rust: use custom FFI integer typesMiguel Ojeda (17):
rust: workqueue: remove unneeded ``#[allow(clippy::new_ret_no_self)]`
rust: sort global Rust flags
rust: types: avoid repetition in{As,From}Bytesimpls
rust: enableclippy::undocumented_unsafe_blockslint
rust: enableclippy::unnecessary_safety_commentlint
rust: enableclippy::unnecessary_safety_doclint
rust: enableclippy::ignored_unit_patternslint
rust: enablerustdoc::unescaped_backtickslint
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: replaceclippy::dbg_macrowithdisallowed_macros
rust: provide proper code documentation titles
rust: enable Clippy'scheck-private-items
Documentation: rust: add coding guidelines on lints
rust: start using the#[expect(...)]attribute
Documentation: rust: discuss#[expect(...)]in the guidelinesThomas Böhler (7):
drm/panic: avoid reimplementingIterator::finddrm/panic: remove unnecessary borrow inalignment_patterndrm/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
Quoted 9 lines · Ilya K
Hi, I think this is missing one final change, specifically
27c7518e, or rather, the only line of it that applies:pub unsafe extern "C" fn drm_panic_qr_generate(
(quoted diff) +1
-1- url: *const i8, + url: *const kernel::ffi::c_char,Without it, the build fails on Rust 1.85 / aarch64.
Bah, sorry, my bad, that is embarrassing... It is not just that one -- the actual remap is not there. Let me re-send...
Greg: no changes except for the 2 extra on top you will see.
It still holds that the x86_64 build still builds commit-by-commit, and I double-checked that hash builds for x86_64, arm64 and riscv64 with the min and max compilers.
Let me also run a test for loongarch64 with the unrelated fix applied.
Cheers,
Miguel
Greg Kroah-Hartman
maintainerQuoted 14 lines · Miguel Ojeda
Quoted 9 lines · Ilya K
Hi, I think this is missing one final change, specifically
27c7518e, or rather, the only line of it that applies:pub unsafe extern "C" fn drm_panic_qr_generate(
(quoted diff) +1
-1- url: *const i8, + url: *const kernel::ffi::c_char,Without it, the build fails on Rust 1.85 / aarch64.
Bah, sorry, my bad, that is embarrassing... It is not just that one -- the actual remap is not there. Let me re-send...
Quoted 7 lines
Greg: no changes except for the 2 extra on top you will see.
It still holds that the
x86_64build still builds commit-by-commit, and I double-checked that hash builds forx86_64, arm64 and riscv64 with the min and max compilers.Let me also run a test for loongarch64 with the unrelated fix applied.
Please just send additional ones, not the whole series, otherwise I'm going to get confused :)
thanks,
greg k-h
Miguel Ojeda
maintainercover The two missing ones
Two missing ones on top of the other 60 -- sorry again! I tested the end result of applying the 62 on top of v6.12.18 with all combinations of:
- The minimum and maximum Rust compiler versions (i.e. 1.78.0 and 1.85.0).
- x86_64, arm64, riscv64 and loongarch64 (this last one with the other unrelated-to-Rust fix on top).
- A defconfig with Rust users enabled (rust_minimal, rust_print, rnull, drm_panic_qr, qt2025, ax88796b_rust) plus a similar with a couple debug options on top (Rust debug assertions and KUnit Rust doctests).
All pass my usual tests, are WERROR=y and Clippy-clean etc.
Plus x86_64 out-of-tree build, a x86_64 subdir build and a x86_64 Rust disabled build. On x86_64, it should still build commit-by-commit.
Cheers,
Miguel
Gary Guo (1):
rust: map long to isize and char to u8
Miguel Ojeda (1):
rust: finish using custom FFI integer types
drivers/gpu/drm/drm_panic_qr.rs | 2 +- rust/ffi.rs | 37 ++++++++++++++++++++++++++++++++- rust/kernel/error.rs | 5 +---- rust/kernel/firmware.rs | 2 +- rust/kernel/uaccess.rs | 27 +++++++----------------- 5 files changed, 46 insertions(+), 27 deletions(-)
--
2.48.1
Miguel Ojeda
maintainerPATCH 1/2 rust: finish using custom FFI integer types
commit 27c7518e7f1ccaaa43eb5f25dc362779d2dc2ccb upstream.
In the last kernel cycle we migrated most of the core::ffi cases in commit d072acda4862 ("rust: use custom FFI integer types"):
Currently FFI integer types are defined in libcore. This commit creates the ffi crate and asks bindgen to use that crate for FFI integer types instead of core::ffi.
This commit is preparatory and no type changes are made in this commit yet.
Finish now the few remaining/new cases so that we perform the actual remapping in the next commit as planned.
--- drivers/gpu/drm/drm_panic_qr.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/drm_panic_qr.rs +1 -1
@@ -931,7 +931,7 @@ fn draw_all(&mut self, data: impl Iterator<Item = u8>) {/// They must remain valid for the duration of the function call. #[no_mangle] pub unsafe extern "C" fn drm_panic_qr_generate ( - url: *const i8 , + url: *const kernel::ffi::c_char , data: *mut u8 , data_len:usize , data_size: usize,
Signature · 1 line
2.48.1
Miguel Ojeda
maintainerPATCH 2/2 rust: map `long` to `isize` and `char` to `u8`
In reply to Miguel OjedaFrom: Gary Guo <[email protected]>
commit 1bae8729e50a900f41e9a1c17ae81113e4cf62b8 upstream.
The following FFI types are replaced compared to core::ffi:
1. char type is now always mapped to u8, since kernel uses -funsigned-char on the C code. core::ffi maps it to platform default ABI, which can be either signed or unsigned.
2. long is now always mapped to isize. It's very common in the kernel to use long to represent a pointer-sized integer, and in fact intptr_t is a typedef of long in the kernel. Enforce this mapping rather than mapping to i32/i64 depending on platform can save us a lot of unnecessary casts.
[ Moved uaccess changes from the next commit, since they were
irrefutable patterns that Rust >= 1.82.0 warns about. Reworded slightly and reformatted a few documentation comments. Rebased on top of rust-next. Added the removal of two casts to avoid Clippy warnings. - Miguel ]
--- rust/ffi.rs | 37 ++++++++++++++++++++++++++++++++++++- rust/kernel/error.rs | 5 +---- rust/kernel/firmware.rs | 2 +- rust/kernel/uaccess.rs | 27 +++++++-------------------- 4 files changed, 45 insertions(+), 26 deletions(-)
rust/ffi.rs +36 -1
@@ -10,4 +10,39 @@#![no_std] -pub use core::ffi::*; +macro_rules! alias { + ($($name:ident = $ty:ty;)*) => {$( +#[allow(non_camel_case_types, missing_docs)] +pub type $name = $ty; + +// Check size compatibility with `core`. +const _: () =assert! ( + core::mem::size_of ::<$name>() == core::mem::size_of ::<core::ffi::$name>() + ); + )*} +} + +alias! { +// `core::ffi::c_char` is either `i8` or `u8` depending on architecture. In the kernel, we use +// `-funsigned-char` so it's always mapped to `u8`. + c_char =u8 ; + + c_schar =i8 ; + c_uchar =u8 ; + + c_short =i16 ; + c_ushort =u16 ; + + c_int =i32 ; + c_uint =u32 ; + +// In the kernel, `intptr_t` is defined to be `long` in all platforms, so we can map the type to +// `isize`. + c_long =isize ; + c_ulong =usize ; + + c_longlong =i64 ; + c_ulonglong =u64 ; +} + +pub use core::ffi::c_void;
rust/kernel/error.rs +1 -4
@@ -153,11 +153,8 @@ pub(crate) fn to_blk_status(self) -> bindings::blk_status_t {/// Returns the error encoded as a pointer. pub fn to_ptr <T >(self) -> *mut T { -#[cfg_attr(target_pointer_width = "32" , allow(clippy::useless_conversion))] // SAFETY: `self.0` is a valid error due to its invariant. -unsafe { - bindings::ERR_PTR (self.0 .get ().into ())as *mut _ - } +unsafe { bindings::ERR_PTR (self.0 .get ()as _ )as *mut _ } }/// Returns a string representing the error, if one exists.
rust/kernel/firmware.rs +1 -1
@@ -12,7 +12,7 @@/// One of the following: `bindings::request_firmware`, `bindings::firmware_request_nowarn`, /// `bindings::firmware_request_platform`, `bindings::request_firmware_direct`. struct FwFunc ( -unsafe extern "C" fn (*mut *const bindings::firmware , *const i8 , *mut bindings::device ) ->i32 , +unsafe extern "C" fn (*mut *const bindings::firmware , *const u8 , *mut bindings::device ) ->i32 , );impl FwFunc {
rust/kernel/uaccess.rs +7 -20
@@ -8,7 +8,7 @@ alloc::Flags, bindings, error::Result, - ffi::{c_ulong, c_void}, + ffi::c_void, prelude::*, types::{AsBytes, FromBytes}, };
@@ -224,13 +224,9 @@ pub fn read_raw(&mut self, out: &mut [MaybeUninit<u8>]) -> Result {if len > self.length {return Err (EFAULT ); } -let Ok (len_ulong) = c_ulong::try_from (len)else { -return Err (EFAULT ); - }; -// SAFETY: `out_ptr` points into a mutable slice of length `len_ulong`, so we may write +// SAFETY: `out_ptr` points into a mutable slice of length `len`, so we may write // that many bytes to it. -let res = -unsafe { bindings::copy_from_user (out_ptr, self.ptras *const c_void , len_ulong) }; +let res =unsafe { bindings::copy_from_user (out_ptr, self.ptras *const c_void , len) };if res !=0 {return Err (EFAULT ); }
@@ -259,9 +255,6 @@ pub fn read<T: FromBytes>(&mut self) -> Result<T> {if len > self.length {return Err (EFAULT ); } -let Ok (len_ulong) = c_ulong::try_from (len)else { -return Err (EFAULT ); - };let mut out:MaybeUninit <T > =MaybeUninit ::uninit ();// SAFETY: The local variable `out` is valid for writing `size_of::<T>()` bytes. //
@@ -272,7 +265,7 @@ pub fn read<T: FromBytes>(&mut self) -> Result<T> { bindings::_copy_from_user ( out.as_mut_ptr ().cast ::<c_void >(), self.ptras *const c_void , - len_ulong, + len, ) };if res !=0 {
@@ -335,12 +328,9 @@ pub fn write_slice(&mut self, data: &[u8]) -> Result {if len > self.length {return Err (EFAULT ); } -let Ok (len_ulong) = c_ulong::try_from (len)else { -return Err (EFAULT ); - }; -// SAFETY: `data_ptr` points into an immutable slice of length `len_ulong`, so we may read +// SAFETY: `data_ptr` points into an immutable slice of length `len`, so we may read // that many bytes from it. -let res =unsafe { bindings::copy_to_user (self.ptras *mut c_void , data_ptr, len_ulong) }; +let res =unsafe { bindings::copy_to_user (self.ptras *mut c_void , data_ptr, len) };if res !=0 {return Err (EFAULT ); }
@@ -359,9 +349,6 @@ pub fn write<T: AsBytes>(&mut self, value: &T) -> Result {if len > self.length {return Err (EFAULT ); } -let Ok (len_ulong) = c_ulong::try_from (len)else { -return Err (EFAULT ); - };// SAFETY: The reference points to a value of type `T`, so it is valid for reading // `size_of::<T>()` bytes. //
@@ -372,7 +359,7 @@ pub fn write<T: AsBytes>(&mut self, value: &T) -> Result { bindings::_copy_to_user ( self.ptras *mut c_void , (valueas *const T ).cast ::<c_void >(), - len_ulong, + len, ) };if res !=0 {
Signature · 1 line
2.48.1
Patch "rust: finish using custom FFI integer types" has been added to the 6.12-stable tree
In reply to Miguel OjedaThis is a note to let you know that I've just added the patch titled
rust: finish using custom FFI integer types
to the 6.12-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
rust-finish-using-custom-ffi-integer-types.patch
and it can be found in the queue-6.12 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
From [email protected] Sun Mar 9 21:42:38 2025
From: Miguel Ojeda <[email protected]>
Date: Sun, 9 Mar 2025 21:42:16 +0100
Subject: rust: finish using custom FFI integer types
To: Greg Kroah-Hartman <[email protected]>, Sasha Levin <[email protected]>, [email protected]
Cc: Danilo Krummrich <[email protected]>, Alice Ryhl <[email protected]>, Alyssa Ross <[email protected]>, NoisyCoil <[email protected]>, [email protected], Miguel Ojeda <[email protected]>
Message-ID: <[email protected]>
From: Miguel Ojeda <[email protected]>
commit 27c7518e7f1ccaaa43eb5f25dc362779d2dc2ccb upstream.
In the last kernel cycle we migrated most of the core::ffi cases in commit d072acda4862 ("rust: use custom FFI integer types"):
Currently FFI integer types are defined in libcore. This commit creates the ffi crate and asks bindgen to use that crate for FFI integer types instead of core::ffi.
This commit is preparatory and no type changes are made in this commit yet.
Finish now the few remaining/new cases so that we perform the actual remapping in the next commit as planned.
--- drivers/gpu/drm/drm_panic_qr.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/drm_panic_qr.rs +1 -1
@@ -931,7 +931,7 @@ impl QrImage<'_> {/// They must remain valid for the duration of the function call. #[no_mangle] pub unsafe extern "C" fn drm_panic_qr_generate ( - url: *const i8 , + url: *const kernel::ffi::c_char , data: *mut u8 , data_len:usize , data_size: usize,
Patches currently in stable-queue which might be from [email protected] are
queue-6.12/rust-fix-size_t-in-bindgen-prototypes-of-c-builtins.patch queue-6.12/rust-alloc-add-box-to-prelude.patch queue-6.12/drm-panic-correctly-indent-continuation-of-line-in-list-item.patch queue-6.12/rust-replace-clippy-dbg_macro-with-disallowed_macros.patch queue-6.12/rust-error-use-core-alloc-layouterror.patch queue-6.12/rust-alloc-add-allocator-trait.patch queue-6.12/rust-alloc-fix-arraylayout-allocations.patch queue-6.12/rust-alloc-update-module-comment-of-alloc.rs.patch queue-6.12/rust-map-__kernel_size_t-and-friends-also-to-usize-isize.patch queue-6.12/rust-sync-remove-unneeded.patch queue-6.12/drm-panic-remove-unnecessary-borrow-in-alignment_pattern.patch queue-6.12/rust-error-make-conversion-functions-public.patch queue-6.12/rust-alloc-implement-intoiterator-for-vec.patch queue-6.12/rust-alloc-introduce-arraylayout.patch queue-6.12/rust-alloc-implement-kernel-box.patch queue-6.12/rust-alloc-remove-vecext-extension.patch queue-6.12/rust-alloc-make-allocator-module-public.patch queue-6.12/rust-alloc-add-vec-to-prelude.patch queue-6.12/rust-alloc-implement-vmalloc-allocator.patch queue-6.12/rust-alloc-implement-collect-for-intoiter.patch queue-6.12/rust-enable-rustdoc-unescaped_backticks-lint.patch queue-6.12/rust-error-optimize-error-type-to-use-nonzero.patch queue-6.12/rust-treewide-switch-to-the-kernel-vec-type.patch queue-6.12/rust-alloc-implement-contains-for-flags.patch queue-6.12/rust-start-using-the-attribute.patch queue-6.12/rust-alloc-implement-cmalloc-in-module-allocator_test.patch queue-6.12/rust-introduce-.clippy.toml.patch queue-6.12/rust-alloc-implement-kernel-vec-type.patch queue-6.12/documentation-rust-discuss-in-the-guidelines.patch queue-6.12/rust-alloc-add-module-allocator_test.patch queue-6.12/rust-alloc-implement-allocator-for-kmalloc.patch queue-6.12/rust-treewide-switch-to-our-kernel-box-type.patch queue-6.12/rust-alloc-separate-aligned_size-from-krealloc_aligned.patch queue-6.12/rust-enable-clippy-unnecessary_safety_comment-lint.patch queue-6.12/rust-alloc-remove-extension-of-std-s-box.patch queue-6.12/rust-provide-proper-code-documentation-titles.patch queue-6.12/rust-str-test-replace-alloc-format.patch queue-6.12/rust-enable-clippy-s-check-private-items.patch queue-6.12/drm-panic-avoid-reimplementing-iterator-find.patch queue-6.12/drm-panic-allow-verbose-version-check.patch queue-6.12/rust-enable-clippy-undocumented_unsafe_blocks-lint.patch queue-6.12/rust-enable-clippy-unnecessary_safety_doc-lint.patch queue-6.12/rust-sort-global-rust-flags.patch queue-6.12/maintainers-add-entry-for-the-rust-alloc-module.patch queue-6.12/drm-panic-prefer-eliding-lifetimes.patch queue-6.12/documentation-rust-add-coding-guidelines-on-lints.patch queue-6.12/kbuild-rust-remove-the-alloc-crate-and-globalalloc.patch queue-6.12/rust-kbuild-expand-rusttest-target-for-macros.patch queue-6.12/drm-panic-allow-verbose-boolean-for-clarity.patch queue-6.12/rust-block-fix-formatting-in-gendisk-doc.patch queue-6.12/rust-alloc-add-__gfp_nowarn-to-flags.patch queue-6.12/drm-panic-remove-redundant-field-when-assigning-value.patch queue-6.12/rust-workqueue-remove-unneeded.patch queue-6.12/rust-use-custom-ffi-integer-types.patch queue-6.12/rust-alloc-implement-kvmalloc-allocator.patch queue-6.12/rust-alloc-implement-reallocfunc.patch queue-6.12/loongarch-use-asm_reachable.patch queue-6.12/rust-init-remove-unneeded.patch queue-6.12/rust-enable-clippy-ignored_unit_patterns-lint.patch queue-6.12/rust-map-long-to-isize-and-char-to-u8.patch queue-6.12/rust-alloc-rename-kernelallocator-to-kmalloc.patch queue-6.12/rust-finish-using-custom-ffi-integer-types.patch queue-6.12/rust-error-check-for-config-test-in-error-name.patch queue-6.12/rust-types-avoid-repetition-in-as-from-bytes-impls.patch
Patch "rust: map `long` to `isize` and `char` to `u8`" has been added to the 6.12-stable tree
In reply to Miguel OjedaThis is a note to let you know that I've just added the patch titled
rust: map long to isize and char to u8
to the 6.12-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
rust-map-long-to-isize-and-char-to-u8.patch
and it can be found in the queue-6.12 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
From [email protected] Sun Mar 9 21:42:43 2025
From: Miguel Ojeda <[email protected]>
Date: Sun, 9 Mar 2025 21:42:17 +0100
Subject: rust: map long to isize and char to u8
To: Greg Kroah-Hartman <[email protected]>, Sasha Levin <[email protected]>, [email protected]
Cc: Danilo Krummrich <[email protected]>, Alice Ryhl <[email protected]>, Alyssa Ross <[email protected]>, NoisyCoil <[email protected]>, [email protected], Miguel Ojeda <[email protected]>
Message-ID: <[email protected]>
From: Gary Guo <[email protected]>
commit 1bae8729e50a900f41e9a1c17ae81113e4cf62b8 upstream.
The following FFI types are replaced compared to core::ffi:
1. char type is now always mapped to u8, since kernel uses -funsigned-char on the C code. core::ffi maps it to platform default ABI, which can be either signed or unsigned.
2. long is now always mapped to isize. It's very common in the kernel to use long to represent a pointer-sized integer, and in fact intptr_t is a typedef of long in the kernel. Enforce this mapping rather than mapping to i32/i64 depending on platform can save us a lot of unnecessary casts.
[ Moved uaccess changes from the next commit, since they were
irrefutable patterns that Rust >= 1.82.0 warns about. Reworded slightly and reformatted a few documentation comments. Rebased on top of rust-next. Added the removal of two casts to avoid Clippy warnings. - Miguel ]
--- rust/ffi.rs | 37 ++++++++++++++++++++++++++++++++++++- rust/kernel/error.rs | 5 +---- rust/kernel/firmware.rs | 2 +- rust/kernel/uaccess.rs | 27 +++++++-------------------- 4 files changed, 45 insertions(+), 26 deletions(-)
rust/ffi.rs +36 -1
@@ -10,4 +10,39 @@#![no_std] -pub use core::ffi::*; +macro_rules! alias { + ($($name:ident = $ty:ty;)*) => {$( +#[allow(non_camel_case_types, missing_docs)] +pub type $name = $ty; + +// Check size compatibility with `core`. +const _: () =assert! ( + core::mem::size_of ::<$name>() == core::mem::size_of ::<core::ffi::$name>() + ); + )*} +} + +alias! { +// `core::ffi::c_char` is either `i8` or `u8` depending on architecture. In the kernel, we use +// `-funsigned-char` so it's always mapped to `u8`. + c_char =u8 ; + + c_schar =i8 ; + c_uchar =u8 ; + + c_short =i16 ; + c_ushort =u16 ; + + c_int =i32 ; + c_uint =u32 ; + +// In the kernel, `intptr_t` is defined to be `long` in all platforms, so we can map the type to +// `isize`. + c_long =isize ; + c_ulong =usize ; + + c_longlong =i64 ; + c_ulonglong =u64 ; +} + +pub use core::ffi::c_void;
rust/kernel/error.rs +1 -4
@@ -153,11 +153,8 @@ impl Error {/// Returns the error encoded as a pointer. pub fn to_ptr <T >(self) -> *mut T { -#[cfg_attr(target_pointer_width = "32" , allow(clippy::useless_conversion))] // SAFETY: `self.0` is a valid error due to its invariant. -unsafe { - bindings::ERR_PTR (self.0 .get ().into ())as *mut _ - } +unsafe { bindings::ERR_PTR (self.0 .get ()as _ )as *mut _ } }/// Returns a string representing the error, if one exists.
rust/kernel/firmware.rs +1 -1
@@ -12,7 +12,7 @@ use core::ptr::NonNull;/// One of the following: `bindings::request_firmware`, `bindings::firmware_request_nowarn`, /// `bindings::firmware_request_platform`, `bindings::request_firmware_direct`. struct FwFunc ( -unsafe extern "C" fn (*mut *const bindings::firmware , *const i8 , *mut bindings::device ) ->i32 , +unsafe extern "C" fn (*mut *const bindings::firmware , *const u8 , *mut bindings::device ) ->i32 , );impl FwFunc {
rust/kernel/uaccess.rs +7 -20
@@ -8,7 +8,7 @@ use crate::{ alloc::Flags, bindings, error::Result, - ffi::{c_ulong, c_void}, + ffi::c_void, prelude::*, types::{AsBytes, FromBytes}, };
@@ -224,13 +224,9 @@ impl UserSliceReader {if len > self.length {return Err (EFAULT ); } -let Ok (len_ulong) = c_ulong::try_from (len)else { -return Err (EFAULT ); - }; -// SAFETY: `out_ptr` points into a mutable slice of length `len_ulong`, so we may write +// SAFETY: `out_ptr` points into a mutable slice of length `len`, so we may write // that many bytes to it. -let res = -unsafe { bindings::copy_from_user (out_ptr, self.ptras *const c_void , len_ulong) }; +let res =unsafe { bindings::copy_from_user (out_ptr, self.ptras *const c_void , len) };if res !=0 {return Err (EFAULT ); }
@@ -259,9 +255,6 @@ impl UserSliceReader {if len > self.length {return Err (EFAULT ); } -let Ok (len_ulong) = c_ulong::try_from (len)else { -return Err (EFAULT ); - };let mut out:MaybeUninit <T > =MaybeUninit ::uninit ();// SAFETY: The local variable `out` is valid for writing `size_of::<T>()` bytes. //
@@ -272,7 +265,7 @@ impl UserSliceReader { bindings::_copy_from_user ( out.as_mut_ptr ().cast ::<c_void >(), self.ptras *const c_void , - len_ulong, + len, ) };if res !=0 {
@@ -335,12 +328,9 @@ impl UserSliceWriter {if len > self.length {return Err (EFAULT ); } -let Ok (len_ulong) = c_ulong::try_from (len)else { -return Err (EFAULT ); - }; -// SAFETY: `data_ptr` points into an immutable slice of length `len_ulong`, so we may read +// SAFETY: `data_ptr` points into an immutable slice of length `len`, so we may read // that many bytes from it. -let res =unsafe { bindings::copy_to_user (self.ptras *mut c_void , data_ptr, len_ulong) }; +let res =unsafe { bindings::copy_to_user (self.ptras *mut c_void , data_ptr, len) };if res !=0 {return Err (EFAULT ); }
@@ -359,9 +349,6 @@ impl UserSliceWriter {if len > self.length {return Err (EFAULT ); } -let Ok (len_ulong) = c_ulong::try_from (len)else { -return Err (EFAULT ); - };// SAFETY: The reference points to a value of type `T`, so it is valid for reading // `size_of::<T>()` bytes. //
@@ -372,7 +359,7 @@ impl UserSliceWriter { bindings::_copy_to_user ( self.ptras *mut c_void , (valueas *const T ).cast ::<c_void >(), - len_ulong, + len, ) };if res !=0 {
Patches currently in stable-queue which might be from [email protected] are
queue-6.12/rust-fix-size_t-in-bindgen-prototypes-of-c-builtins.patch queue-6.12/rust-alloc-add-box-to-prelude.patch queue-6.12/drm-panic-correctly-indent-continuation-of-line-in-list-item.patch queue-6.12/rust-replace-clippy-dbg_macro-with-disallowed_macros.patch queue-6.12/rust-error-use-core-alloc-layouterror.patch queue-6.12/rust-alloc-add-allocator-trait.patch queue-6.12/rust-alloc-fix-arraylayout-allocations.patch queue-6.12/rust-alloc-update-module-comment-of-alloc.rs.patch queue-6.12/rust-map-__kernel_size_t-and-friends-also-to-usize-isize.patch queue-6.12/rust-sync-remove-unneeded.patch queue-6.12/drm-panic-remove-unnecessary-borrow-in-alignment_pattern.patch queue-6.12/rust-error-make-conversion-functions-public.patch queue-6.12/rust-alloc-implement-intoiterator-for-vec.patch queue-6.12/rust-alloc-introduce-arraylayout.patch queue-6.12/rust-alloc-implement-kernel-box.patch queue-6.12/rust-alloc-remove-vecext-extension.patch queue-6.12/rust-alloc-make-allocator-module-public.patch queue-6.12/rust-alloc-add-vec-to-prelude.patch queue-6.12/rust-alloc-implement-vmalloc-allocator.patch queue-6.12/rust-alloc-implement-collect-for-intoiter.patch queue-6.12/rust-enable-rustdoc-unescaped_backticks-lint.patch queue-6.12/rust-error-optimize-error-type-to-use-nonzero.patch queue-6.12/rust-treewide-switch-to-the-kernel-vec-type.patch queue-6.12/rust-alloc-implement-contains-for-flags.patch queue-6.12/rust-start-using-the-attribute.patch queue-6.12/rust-alloc-implement-cmalloc-in-module-allocator_test.patch queue-6.12/rust-introduce-.clippy.toml.patch queue-6.12/rust-alloc-implement-kernel-vec-type.patch queue-6.12/documentation-rust-discuss-in-the-guidelines.patch queue-6.12/rust-alloc-add-module-allocator_test.patch queue-6.12/rust-alloc-implement-allocator-for-kmalloc.patch queue-6.12/rust-treewide-switch-to-our-kernel-box-type.patch queue-6.12/rust-alloc-separate-aligned_size-from-krealloc_aligned.patch queue-6.12/rust-enable-clippy-unnecessary_safety_comment-lint.patch queue-6.12/rust-alloc-remove-extension-of-std-s-box.patch queue-6.12/rust-provide-proper-code-documentation-titles.patch queue-6.12/rust-str-test-replace-alloc-format.patch queue-6.12/rust-enable-clippy-s-check-private-items.patch queue-6.12/drm-panic-avoid-reimplementing-iterator-find.patch queue-6.12/drm-panic-allow-verbose-version-check.patch queue-6.12/rust-enable-clippy-undocumented_unsafe_blocks-lint.patch queue-6.12/rust-enable-clippy-unnecessary_safety_doc-lint.patch queue-6.12/rust-sort-global-rust-flags.patch queue-6.12/maintainers-add-entry-for-the-rust-alloc-module.patch queue-6.12/drm-panic-prefer-eliding-lifetimes.patch queue-6.12/documentation-rust-add-coding-guidelines-on-lints.patch queue-6.12/kbuild-rust-remove-the-alloc-crate-and-globalalloc.patch queue-6.12/rust-kbuild-expand-rusttest-target-for-macros.patch queue-6.12/drm-panic-allow-verbose-boolean-for-clarity.patch queue-6.12/rust-block-fix-formatting-in-gendisk-doc.patch queue-6.12/rust-alloc-add-__gfp_nowarn-to-flags.patch queue-6.12/drm-panic-remove-redundant-field-when-assigning-value.patch queue-6.12/rust-workqueue-remove-unneeded.patch queue-6.12/rust-use-custom-ffi-integer-types.patch queue-6.12/rust-alloc-implement-kvmalloc-allocator.patch queue-6.12/rust-alloc-implement-reallocfunc.patch queue-6.12/loongarch-use-asm_reachable.patch queue-6.12/rust-init-remove-unneeded.patch queue-6.12/rust-enable-clippy-ignored_unit_patterns-lint.patch queue-6.12/rust-map-long-to-isize-and-char-to-u8.patch queue-6.12/rust-alloc-rename-kernelallocator-to-kmalloc.patch queue-6.12/rust-finish-using-custom-ffi-integer-types.patch queue-6.12/rust-error-check-for-config-test-in-error-name.patch queue-6.12/rust-types-avoid-repetition-in-as-from-bytes-impls.patch
Greg Kroah-Hartman
maintainerRe: [PATCH 6.12.y 0/2] The two missing ones
In reply to Miguel OjedaQuoted 33 lines · Miguel Ojeda
Two missing ones on top of the other 60 -- sorry again! I tested the end result of applying the 62 on top of v6.12.18 with all combinations of:
- The minimum and maximum Rust compiler versions (i.e. 1.78.0 and 1.85.0).
-
x86_64, arm64, riscv64 and loongarch64 (this last one with the other unrelated-to-Rust fix on top).- A defconfig with Rust users enabled (
rust_minimal,rust_print, rnull,drm_panic_qr, qt2025,ax88796b_rust) plus a similar with a couple debug options on top (Rust debug assertions and KUnit Rust doctests).All pass my usual tests, are
WERROR=yand Clippy-clean etc.Plus
x86_64out-of-tree build, ax86_64subdir build and ax86_64Rust disabled build. Onx86_64, it should still build commit-by-commit.Cheers,
MiguelGary Guo (1):
rust: maplongtoisizeandchartou8Miguel Ojeda (1):
rust: finish using custom FFI integer typesdrivers/gpu/drm/drm_panic_qr.rs | 2 +- rust/ffi.rs | 37 ++++++++++++++++++++++++++++++++- rust/kernel/error.rs | 5 +---- rust/kernel/firmware.rs | 2 +- rust/kernel/uaccess.rs | 27 +++++++----------------- 5 files changed, 46 insertions(+), 27 deletions(-)
Quoted 3 lines
--
2.48.1
Now queued up, thanks.
greg k-h
Sasha Levin
maintainerRe: [PATCH 6.12.y 2/2] rust: map `long` to `isize` and `char` to `u8`
In reply to Miguel Ojeda[ Sasha's backport helper bot ]
Hi,
Summary of potential issues:
ℹ️ This is part 2/2 of a series
❌ Build failures detected
The upstream commit SHA1 provided is correct: 1bae8729e50a900f41e9a1c17ae81113e4cf62b8
WARNING: Author mismatch between patch and upstream commit:
Backport author: Miguel Ojeda<[email protected]> Commit author: Gary Guo<[email protected]>
Status in newer kernel trees:
6.13.y | Present (different SHA1: 7efbbb5407e7)
Note: The patch differs from the upstream commit:
---
Failed to apply patch cleanly.
---
NOTE: These results are for this patch alone. Full series testing will be performed when all parts are received.
Results of testing on various branches:
| Branch | Patch Apply | Build Test | |---------------------------|-------------|------------| | stable/linux-6.12.y | Failed | N/A |
Build Errors:
Patch failed to apply on stable/linux-6.12.y. Reject:
diff a/rust/kernel/error.rs b/rust/kernel/error.rs (rejected hunks)
@@ -153,11 +153,8 @@ pub(crate) fn to_blk_status(self) -> bindings::blk_status_t {
/// Returns the error encoded as a pointer.
pub fn to_ptr<T>(self) -> *mut T {
- #[cfg_attr(target_pointer_width = "32", allow(clippy::useless_conversion))]
// SAFETY: `self.0` is a valid error due to its invariant.- unsafe {
- bindings::ERR_PTR(self.0.get().into()) as *mut _
- }
+ unsafe { bindings::ERR_PTR(self.0.get() as _) as *mut _ }
}
/// Returns a string representing the error, if one exists.diff a/rust/kernel/uaccess.rs b/rust/kernel/uaccess.rs (rejected hunks)
@@ -8,7 +8,7 @@
alloc::Flags,
bindings,
error::Result,
- ffi::{c_ulong, c_void},
+ ffi::c_void,
prelude::*,
types::{AsBytes, FromBytes},};
Sasha Levin
maintainerRe: [PATCH 6.12.y 1/2] rust: finish using custom FFI integer types
In reply to Miguel Ojeda[ Sasha's backport helper bot ]
Hi,
✅ All tests passed successfully. No issues detected. No action required from the submitter.
The upstream commit SHA1 provided is correct: 27c7518e7f1ccaaa43eb5f25dc362779d2dc2ccb
Status in newer kernel trees:
6.13.y | Present (different SHA1: 0545eb878267)
Note: The patch differs from the upstream commit:
---
1: 27c7518e7f1cc < -: ------------- rust: finish using custom FFI integer types -: ------------- > 1: e14eb7876bb06 rust: finish using custom FFI integer types
---
Results of testing on various branches:
| Branch | Patch Apply | Build Test | |---------------------------|-------------|------------| | stable/linux-6.12.y | Success | Success |
Re: [PATCH 6.12.y 2/2] rust: map `long` to `isize` and `char` to `u8`
In reply to Sasha LevinQuoted 10 lines · Sasha Levin
[ Sasha's backport helper bot ]
Summary of potential issues:
ℹ️ This is part 2/2 of a series
❌ Build failures detectedFailed to apply patch cleanly.
Patch failed to apply on stable/linux-6.12.y. Reject:
Hmm... these patches are already applied in -rc.
I guess the bot picked up these 2 "independent" patches that were not really independent but rather were meant to be applied on top of the other 60 I sent.
All 62 were applied by Greg, the 2-series at commit 9cbe3832da9c ("rust: map long to isize and char to u8") and the 60-series at commit bfc1c86b1e13 ("rust: alloc: Fix ArrayLayout allocations").
I hope that helps!
Cheers,
Miguel