projects/linux·commit 26ff9699

Merge tag 'rust-7.1' of git://git.kernel.org/pub/scm/linux/kernel/git/ojeda/linux

26ff9699 · Linus Torvalds <[email protected]> · 2026-04-13 09:54:20 -07:00

Pull Rust updates from Miguel Ojeda:
 "Toolchain and infrastructure:

   - Bump the minimum Rust version to 1.85.0 (and 'bindgen' to 0.71.1).

     As proposed in LPC 2025 and the Maintainers Summit [1], we are
     going to follow Debian Stable's Rust versions as our minimum
     versions.

     Debian Trixie was released on 2025-08-09 with a Rust 1.85.0 and
     'bindgen' 0.71.1 toolchain, which is a fair amount of time for e.g.
     kernel developers to upgrade.

     Other major distributions support a Rust version that is high
     enough as well, including:

       + Arch Linux.
       + Fedora Linux.
       + Gentoo Linux.
       + Nix.
       + openSUSE Slowroll and openSUSE Tumbleweed.
       + Ubuntu 25.10 and 26.04 LTS. In addition, 24.04 LTS using
         their versioned packages.

     The merged patch series comes with the associated cleanups and
     simplifications treewide that can be performed thanks to both
     bumps, as well as documentation updates.

     In addition, start using 'bindgen''s '--with-attribute-custom-enum'
     feature to set the 'cfi_encoding' attribute for the 'lru_status'
     enum used in Binder.

     Link: https://lwn.net/Articles/1050174/ [1]

   - Add experimental Kconfig option ('CONFIG_RUST_INLINE_HELPERS') that
     inlines C helpers into Rust.

     Essentially, it performs a step similar to LTO, but just for the
     helpers, i.e. very local and fast.

     It relies on 'llvm-link' and its '--internalize' flag, and requires
     a compatible LLVM between Clang and 'rustc' (i.e. same major
     version, 'CONFIG_RUSTC_CLANG_LLVM_COMPATIBLE'). It is only enabled
     for two architectures for now.

     The result is a measurable speedup in different workloads that
     different users have tested. For instance, for the null block
     driver, it amounts to a 2%.

   - Support global per-version flags.

     While we already have per-version flags in many places, we didn't
     have a place to set global ones that depend on the compiler
     version, i.e. in 'rust_common_flags', which sometimes is needed to
     e.g. tweak the lints set per version.

     Use that to allow the 'clippy::precedence' lint for Rust < 1.86.0,
     since it had a change in behavior.

   - Support overriding the crate name and apply it to Rust Binder,
     which wanted the module to be called 'rust_binder'.

   - Add the remaining '__rust_helper' annotations (started in the
     previous cycle).

  'kernel' crate:

   - Introduce the 'const_assert!' macro: a more powerful version of
     'static_assert!' that can refer to generics inside functions or
     implementation bodies, e.g.:

         fn f<const N: usize>() {
             const_assert!(N > 1);
         }

         fn g<T>() {
             const_assert!(size_of::<T>() > 0, "T cannot be ZST");
         }

     In addition, reorganize our set of build-time assertion macros
     ('{build,const,static_assert}!') to live in the 'build_assert'
     module.

     Finally, improve the docs as well to clarify how these are
     different from one another and how to pick the right one to use,
     and their equivalence (if any) to the existing C ones for extra
     clarity.

   - 'sizes' module: add 'SizeConstants' trait.

     This gives us typed 'SZ_*' constants (avoiding casts) for use in
     device address spaces where the address width depends on the
     hardware (e.g. 32-bit MMIO windows, 64-bit GPU framebuffers, etc.),
     e.g.:

         let gpu_heap = 14 * u64::SZ_1M;
         let mmio_window = u32::SZ_16M;

   - 'clk' module: implement 'Send' and 'Sync' for 'Clk' and thus
     simplify the users in Tyr and PWM.

   - 'ptr' module: add 'const_align_up'.

   - 'str' module: improve the documentation of the 'c_str!' macro to
     explain that one should only use it for non-literal cases (for the
     other case we instead use C string literals, e.g. 'c"abc"').

   - Disallow the use of 'CStr::{as_ptr,from_ptr}' and clean one such
     use in the 'task' module.

   - 'sync' module: finish the move of 'ARef' and 'AlwaysRefCounted'
     outside of the 'types' module, i.e. update the last remaining
     instances and finally remove the re-exports.

   - 'error' module: clarify that 'from_err_ptr' can return 'Ok(NULL)',
     including runtime-tested examples.

     The intention is to hopefully prevent UB that assumes the result of
     the function is not 'NULL' if successful. This originated from a
     case of UB I noticed in 'regulator' that created a 'NonNull' on it.

  Timekeeping:

   - Expand the example section in the 'HrTimer' documentation.

   - Mark the 'ClockSource' trait as unsafe to ensure valid values for
     'ktime_get()'.

   - Add 'Delta::from_nanos()'.

  'pin-init' crate:

   - Replace the 'Zeroable' impls for 'Option<NonZero*>' with impls of
     'ZeroableOption' for 'NonZero*'.

   - Improve feature gate handling for unstable features.

   - Declutter the documentation of implementations of 'Zeroable' for
     tuples.

   - Replace uses of 'addr_of[_mut]!' with '&raw [mut]'.

  rust-analyzer:

   - Add type annotations to 'generate_rust_analyzer.py'.

   - Add support for scripts written in Rust ('generate_rust_target.rs',
     'rustdoc_test_builder.rs', 'rustdoc_test_gen.rs').

   - Refactor 'generate_rust_analyzer.py' to explicitly identify host
     and target crates, improve readability, and reduce duplication.

  And some other fixes, cleanups and improvements"

* tag 'rust-7.1' of git://git.kernel.org/pub/scm/linux/kernel/git/ojeda/linux: (79 commits)
  rust: sizes: add SizeConstants trait for device address space constants
  rust: kernel: update `file_with_nul` comment
  rust: kbuild: allow `clippy::precedence` for Rust < 1.86.0
  rust: kbuild: support global per-version flags
  rust: declare cfi_encoding for lru_status
  docs: rust: general-information: use real example
  docs: rust: general-information: simplify Kconfig example
  docs: rust: quick-start: remove GDB/Binutils mention
  docs: rust: quick-start: remove Nix "unstable channel" note
  docs: rust: quick-start: remove Gentoo "testing" note
  docs: rust: quick-start: add Ubuntu 26.04 LTS and remove subsection title
  docs: rust: quick-start: update minimum Ubuntu version
  docs: rust: quick-start: update Ubuntu versioned packages
  docs: rust: quick-start: openSUSE provides `rust-src` package nowadays
  rust: kbuild: remove "dummy parameter" workaround for `bindgen` < 0.71.1
  rust: kbuild: update `bindgen --rust-target` version and replace comment
  rust: rust_is_available: remove warning for `bindgen` < 0.69.5 && libclang >= 19.1
  rust: rust_is_available: remove warning for `bindgen` 0.66.[01]
  rust: bump `bindgen` minimum supported version to 0.71.1 (Debian Trixie)
  rust: block: update `const_refs_to_static` MSRV TODO comment
  ...
Commit
26ff969926a08eee069767ddbbbc301adbcd9676
Parents
28483203 · 8a23051e

Merge commit. Changes below are compared with the first parent: 28483203.

Changes

78 files changed · +1391 −821

FileStatusAddDelContent
.clippy.tomlmodified+11−1View file
.gitignoremodified+4−0View file
Documentation/process/changes.rstmodified+2−2View file
Documentation/rust/general-information.rstmodified+2−2View file
Documentation/rust/quick-start.rstmodified+20−32View file
MAINTAINERSmodified+1−0View file
Makefilemodified+19−2View file
arch/Kconfigmodified+1−2View file
arch/arm64/Kconfigmodified+0−8View file
arch/riscv/Kconfigmodified+0−3View file
drivers/android/binder/Makefilemodified+1−2View file
drivers/android/binder/page_range.rsmodified+3−3View file
drivers/android/binder/page_range_helper.cdeleted+0−24View before deletion
drivers/android/binder/page_range_helper.hdeleted+0−15View before deletion
drivers/android/binder/rust_binder_main.rsmodified+2−0View file
drivers/gpu/drm/tyr/driver.rsmodified+0−12View file
drivers/gpu/nova-core/gsp/cmdq.rsmodified+1−5View file
drivers/gpu/nova-core/gsp/fw/r570_144.rsmodified+0−3View file
drivers/pwm/pwm_th1520.rsmodified+0−15View file
init/Kconfigmodified+16−14View file
lib/Kconfig.debugmodified+17−0View file
rust/Makefilemodified+36−33View file
rust/bindgen_parametersmodified+4−4View file
rust/bindings/bindings_helper.hmodified+0−1View file
rust/bindings/lib.rsmodified+1−4View file
rust/exports.cmodified+4−1View file
rust/helpers/clk.cmodified+13−11View file
rust/helpers/helpers.cmodified+29−0View file
rust/helpers/jump_label.cmodified+1−1View file
rust/kernel/alloc/allocator/iter.rsmodified+1−7View file
rust/kernel/alloc/kbox.rsmodified+2−27View file
rust/kernel/alloc/kvec/errors.rsmodified+3−0View file
rust/kernel/block/mq/gen_disk.rsmodified+1−3View file
rust/kernel/build_assert.rsmodified+153−30View file
rust/kernel/clk.rsmodified+7−0View file
rust/kernel/error.rsmodified+37−0View file
rust/kernel/i2c.rsmodified+6−7View file
rust/kernel/lib.rsmodified+2−36View file
rust/kernel/list.rsmodified+19−3View file
rust/kernel/list/arc.rsmodified+2−21View file
rust/kernel/list/arc_field.rsmodified+1−0View file
rust/kernel/list/impl_list_item_mod.rsmodified+3−0View file
rust/kernel/num/bounded.rsmodified+9−15View file
rust/kernel/prelude.rsmodified+82−28View file
rust/kernel/ptr.rsmodified+35−7View file
rust/kernel/sizes.rsmodified+128−44View file
rust/kernel/slice.rsdeleted+0−49View before deletion
rust/kernel/static_assert.rsdeleted+0−39View before deletion
rust/kernel/str.rsmodified+23−4View file
rust/kernel/sync/arc.rsmodified+2−19View file
rust/kernel/task.rsmodified+3−4View file
rust/kernel/time.rsmodified+26−6View file
rust/kernel/time/hrtimer.rsmodified+336−0View file
rust/kernel/transmute.rsmodified+6−29View file
rust/kernel/types.rsmodified+0−2View file
rust/kernel/usb.rsmodified+2−4View file
rust/kernel/xarray.rsmodified+1−0View file
rust/macros/helpers.rsmodified+0−1View file
rust/macros/kunit.rsmodified+5−4View file
rust/macros/lib.rsmodified+3−0View file
rust/macros/module.rsmodified+2−7View file
rust/pin-init/README.mdmodified+1−2View file
rust/pin-init/examples/big_struct_in_place.rsmodified+3−0View file
rust/pin-init/examples/linked_list.rsmodified+2−1View file
rust/pin-init/examples/mutex.rsmodified+2−1View file
rust/pin-init/examples/pthread_mutex.rsmodified+2−1View file
rust/pin-init/examples/static_init.rsmodified+2−1View file
rust/pin-init/internal/src/init.rsmodified+10−4View file
rust/pin-init/internal/src/lib.rsmodified+1−1View file
rust/pin-init/src/lib.rsmodified+50−23View file
rust/uapi/lib.rsmodified+1−4View file
scripts/Makefile.buildmodified+7−8View file
scripts/generate_rust_analyzer.pymodified+216−82View file
scripts/min-tool-version.shmodified+2−2View file
scripts/rust_is_available.shmodified+1−35View file
scripts/rust_is_available_bindgen_0_66.hdeleted+0−2View before deletion
scripts/rust_is_available_bindgen_libclang_concat.hdeleted+0−3View before deletion
scripts/rust_is_available_test.pymodified+3−55View file

Only the first 600 diff lines are shown. Download the complete patch.

.clippy.toml

View file
diff --git a/.clippy.toml b/.clippy.toml
index 137f41d..b0a78cc 100644
--- a/.clippy.toml
+++ b/.clippy.toml
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: GPL-2.0
-msrv = "1.78.0"
+msrv = "1.85.0"
check-private-items = true
@@ -9,3 +9,13 @@ disallowed-macros = [
# 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", allow-invalid = true },
]
+
+[[disallowed-methods]]
+path = "core::ffi::CStr::as_ptr"
+replacement = "kernel::prelude::CStrExt::as_char_ptr"
+reason = "kernel's `char` is always unsigned, use `as_char_ptr` instead"
+
+[[disallowed-methods]]
+path = "core::ffi::CStr::from_ptr"
+replacement = "kernel::prelude::CStrExt::from_char_ptr"
+reason = "kernel's `char` is always unsigned, use `from_char_ptr` instead"

.gitignore

View file
diff --git a/.gitignore b/.gitignore
index 3a7241c..3044b95 100644
--- a/.gitignore
+++ b/.gitignore
@@ -13,6 +13,7 @@
.*
*.a
*.asn1.[ch]
+*.bc
*.bin
*.bz2
*.c.[012]*.*
@@ -184,3 +185,6 @@ sphinx_*/
# Rust analyzer configuration
/rust-project.json
+
+# bc language scripts (not LLVM bitcode)
+!kernel/time/timeconst.bc

Documentation/process/changes.rst

View file
diff --git a/Documentation/process/changes.rst b/Documentation/process/changes.rst
index 6b373e1..84156d0 100644
--- a/Documentation/process/changes.rst
+++ b/Documentation/process/changes.rst
@@ -31,8 +31,8 @@ you probably needn't concern yourself with pcmciautils.
====================== =============== ========================================
GNU C 8.1 gcc --version
Clang/LLVM (optional) 15.0.0 clang --version
-Rust (optional) 1.78.0 rustc --version
-bindgen (optional) 0.65.1 bindgen --version
+Rust (optional) 1.85.0 rustc --version
+bindgen (optional) 0.71.1 bindgen --version
GNU make 4.0 make --version
bash 4.2 bash --version
binutils 2.30 ld -v

Documentation/rust/general-information.rst

View file
diff --git a/Documentation/rust/general-information.rst b/Documentation/rust/general-information.rst
index 6146b49..09234be 100644
--- a/Documentation/rust/general-information.rst
+++ b/Documentation/rust/general-information.rst
@@ -157,5 +157,5 @@ numerical comparisons, one may define a new Kconfig symbol:
.. code-block:: kconfig
- config RUSTC_VERSION_MIN_107900
- def_bool y if RUSTC_VERSION >= 107900
+ config RUSTC_HAS_SPAN_FILE
+ def_bool RUSTC_VERSION >= 108800

Documentation/rust/quick-start.rst

View file
diff --git a/Documentation/rust/quick-start.rst b/Documentation/rust/quick-start.rst
index 152289f..a6ec3fa 100644
--- a/Documentation/rust/quick-start.rst
+++ b/Documentation/rust/quick-start.rst
@@ -57,8 +57,8 @@ of the box, e.g.::
Gentoo Linux
************
-Gentoo Linux (and especially the testing branch) provides recent Rust releases
-and thus it should generally work out of the box, e.g.::
+Gentoo Linux provides recent Rust releases and thus it should generally work out
+of the box, e.g.::
USE='rust-src rustfmt clippy' emerge dev-lang/rust dev-util/bindgen
@@ -68,8 +68,8 @@ and thus it should generally work out of the box, e.g.::
Nix
***
-Nix (unstable channel) provides recent Rust releases and thus it should
-generally work out of the box, e.g.::
+Nix provides recent Rust releases and thus it should generally work out of the
+box, e.g.::
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
@@ -84,16 +84,13 @@ openSUSE
openSUSE Slowroll and openSUSE Tumbleweed provide recent Rust releases and thus
they should generally work out of the box, e.g.::
- zypper install rust rust1.79-src rust-bindgen clang
+ zypper install rust rust-src rust-bindgen clang
Ubuntu
******
-25.04
-~~~~~
-
-The latest Ubuntu releases provide recent Rust releases and thus they should
+Ubuntu 25.10 and 26.04 LTS provide recent Rust releases and thus they should
generally work out of the box, e.g.::
apt install rustc rust-src bindgen rustfmt rust-clippy
@@ -112,33 +109,33 @@ Though Ubuntu 24.04 LTS and older versions still provide recent Rust
releases, they require some additional configuration to be set, using
the versioned packages, e.g.::
- apt install rustc-1.80 rust-1.80-src bindgen-0.65 rustfmt-1.80 \
- rust-1.80-clippy
- ln -s /usr/lib/rust-1.80/bin/rustfmt /usr/bin/rustfmt-1.80
- ln -s /usr/lib/rust-1.80/bin/clippy-driver /usr/bin/clippy-driver-1.80
+ apt install rustc-1.85 rust-1.85-src bindgen-0.71 rustfmt-1.85 \
+ rust-1.85-clippy
+ ln -s /usr/lib/rust-1.85/bin/rustfmt /usr/bin/rustfmt-1.85
+ ln -s /usr/lib/rust-1.85/bin/clippy-driver /usr/bin/clippy-driver-1.85
None of these packages set their tools as defaults; therefore they should be
specified explicitly, e.g.::
- make LLVM=1 RUSTC=rustc-1.80 RUSTDOC=rustdoc-1.80 RUSTFMT=rustfmt-1.80 \
- CLIPPY_DRIVER=clippy-driver-1.80 BINDGEN=bindgen-0.65
+ make LLVM=1 RUSTC=rustc-1.85 RUSTDOC=rustdoc-1.85 RUSTFMT=rustfmt-1.85 \
+ CLIPPY_DRIVER=clippy-driver-1.85 BINDGEN=bindgen-0.71
-Alternatively, modify the ``PATH`` variable to place the Rust 1.80 binaries
+Alternatively, modify the ``PATH`` variable to place the Rust 1.85 binaries
first and set ``bindgen`` as the default, e.g.::
- PATH=/usr/lib/rust-1.80/bin:$PATH
+ PATH=/usr/lib/rust-1.85/bin:$PATH
update-alternatives --install /usr/bin/bindgen bindgen \
- /usr/bin/bindgen-0.65 100
- update-alternatives --set bindgen /usr/bin/bindgen-0.65
+ /usr/bin/bindgen-0.71 100
+ update-alternatives --set bindgen /usr/bin/bindgen-0.71
-``RUST_LIB_SRC`` needs to be set when using the versioned packages, e.g.::
+``RUST_LIB_SRC`` may need to be set when using the versioned packages, e.g.::
- RUST_LIB_SRC=/usr/src/rustc-$(rustc-1.80 --version | cut -d' ' -f2)/library
+ RUST_LIB_SRC=/usr/src/rustc-$(rustc-1.85 --version | cut -d' ' -f2)/library
For convenience, ``RUST_LIB_SRC`` can be exported to the global environment.
-In addition, ``bindgen-0.65`` is available in newer releases (24.04 LTS and
-24.10), but it may not be available in older ones (20.04 LTS and 22.04 LTS),
+In addition, ``bindgen-0.71`` is available in newer releases (24.04 LTS),
+but it may not be available in older ones (20.04 LTS and 22.04 LTS),
thus ``bindgen`` may need to be built manually (please see below).
@@ -355,12 +352,3 @@ Hacking
To dive deeper, take a look at the source code of the samples
at ``samples/rust/``, the Rust support code under ``rust/`` and
the ``Rust hacking`` menu under ``Kernel hacking``.
-
-If GDB/Binutils is used and Rust symbols are not getting demangled, the reason
-is the toolchain does not support Rust's new v0 mangling scheme yet.
-There are a few ways out:
-
-- Install a newer release (GDB >= 10.2, Binutils >= 2.36).
-
-- Some versions of GDB (e.g. vanilla GDB 10.1) are able to use
- the pre-demangled names embedded in the debug info (``CONFIG_DEBUG_INFO``).

MAINTAINERS

View file
diff --git a/MAINTAINERS b/MAINTAINERS
index d1cc0e1..cff1061 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -23166,6 +23166,7 @@ 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: .rustfmt.toml
F: Documentation/rust/
F: include/trace/events/rust_sample.h
F: rust/

Makefile

View file
diff --git a/Makefile b/Makefile
index 36d0a32..2345552 100644
--- a/Makefile
+++ b/Makefile
@@ -487,6 +487,7 @@ export rust_common_flags := --edition=2021 \
-Wclippy::as_underscore \
-Wclippy::cast_lossless \
-Wclippy::ignored_unit_patterns \
+ -Aclippy::incompatible_msrv \
-Wclippy::mut_mut \
-Wclippy::needless_bitwise_bool \
-Aclippy::needless_lifetimes \
@@ -495,6 +496,7 @@ export rust_common_flags := --edition=2021 \
-Wclippy::ptr_cast_constness \
-Wclippy::ref_as_ptr \
-Wclippy::undocumented_unsafe_blocks \
+ -Aclippy::uninlined_format_args \
-Wclippy::unnecessary_safety_comment \
-Wclippy::unnecessary_safety_doc \
-Wrustdoc::missing_crate_level_docs \
@@ -505,7 +507,7 @@ KBUILD_HOSTCFLAGS := $(KBUILD_USERHOSTCFLAGS) $(HOST_LFS_CFLAGS) \
KBUILD_HOSTCXXFLAGS := -Wall -O2 $(HOST_LFS_CFLAGS) $(HOSTCXXFLAGS) \
-I $(srctree)/scripts/include
KBUILD_HOSTRUSTFLAGS := $(rust_common_flags) -O -Cstrip=debuginfo \
- -Zallow-features= $(HOSTRUSTFLAGS)
+ -Zallow-features=
KBUILD_HOSTLDFLAGS := $(HOST_LFS_LDFLAGS) $(HOSTLDFLAGS)
KBUILD_HOSTLDLIBS := $(HOST_LFS_LIBS) $(HOSTLDLIBS)
KBUILD_PROCMACROLDFLAGS := $(or $(PROCMACROLDFLAGS),$(KBUILD_HOSTLDFLAGS))
@@ -516,6 +518,7 @@ ifneq ($(LLVM),)
CC = $(LLVM_PREFIX)clang$(LLVM_SUFFIX)
LD = $(LLVM_PREFIX)ld.lld$(LLVM_SUFFIX)
AR = $(LLVM_PREFIX)llvm-ar$(LLVM_SUFFIX)
+LLVM_LINK = $(LLVM_PREFIX)llvm-link$(LLVM_SUFFIX)
NM = $(LLVM_PREFIX)llvm-nm$(LLVM_SUFFIX)
OBJCOPY = $(LLVM_PREFIX)llvm-objcopy$(LLVM_SUFFIX)
OBJDUMP = $(LLVM_PREFIX)llvm-objdump$(LLVM_SUFFIX)
@@ -629,7 +632,7 @@ export RUSTC_BOOTSTRAP := 1
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 RUSTC RUSTDOC RUSTFMT RUSTC_OR_CLIPPY_QUIET RUSTC_OR_CLIPPY BINDGEN LLVM_LINK
export HOSTRUSTC KBUILD_HOSTRUSTFLAGS
export CPP AR NM STRIP OBJCOPY OBJDUMP READELF PAHOLE RESOLVE_BTFIDS LEX YACC AWK INSTALLKERNEL
export PERL PYTHON3 CHECK CHECKFLAGS MAKE UTS_MACHINE HOSTCXX
@@ -834,6 +837,20 @@ endif # CONFIG_TRACEPOINTS
export WARN_ON_UNUSED_TRACEPOINTS
+# Per-version Rust flags. These are like `rust_common_flags`, but may
+# depend on the Rust compiler version (e.g. using `rustc-min-version`).
+#
+# `-Aclippy::precedence`: the lint was extended in Rust 1.85.0 to
+# include bitmasking and shift operations. However, because it generated
+# many hits, in Rust 1.86.0 it was split into a new `precedence_bits`
+# lint which is not enabled by default.
+rust_common_flags_per_version := \
+ $(if $(call rustc-min-version,108600),,-Aclippy::precedence)
+
+rust_common_flags += $(rust_common_flags_per_version)
+KBUILD_HOSTRUSTFLAGS += $(rust_common_flags_per_version) $(HOSTRUSTFLAGS)
+KBUILD_RUSTFLAGS += $(rust_common_flags_per_version)
+
include $(srctree)/arch/$(SRCARCH)/Makefile
ifdef need-config

arch/Kconfig

View file
diff --git a/arch/Kconfig b/arch/Kconfig
index 102ddbd..84089e8 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -968,10 +968,9 @@ config HAVE_CFI_ICALL_NORMALIZE_INTEGERS
config HAVE_CFI_ICALL_NORMALIZE_INTEGERS_RUSTC
def_bool y
depends on HAVE_CFI_ICALL_NORMALIZE_INTEGERS
- depends on RUSTC_VERSION >= 107900
depends on ARM64 || X86_64
# With GCOV/KASAN we need this fix: https://github.com/rust-lang/rust/pull/129373
- depends on (RUSTC_LLVM_VERSION >= 190103 && RUSTC_VERSION >= 108200) || \
+ depends on RUSTC_LLVM_VERSION >= 190103 || \
(!GCOV_KERNEL && !KASAN_GENERIC && !KASAN_SW_TAGS)
config CFI_PERMISSIVE

arch/arm64/Kconfig

View file
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 9ea19b7..4de630e 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -292,14 +292,6 @@ config ARM64
config RUSTC_SUPPORTS_ARM64
def_bool y
depends on CPU_LITTLE_ENDIAN
- # Shadow call stack is only supported on certain rustc versions.
- #
- # When using the UNWIND_PATCH_PAC_INTO_SCS option, rustc version 1.80+ is
- # required due to use of the -Zfixed-x18 flag.
- #
- # Otherwise, rustc version 1.82+ is required due to use of the
- # -Zsanitizer=shadow-call-stack flag.
- depends on !SHADOW_CALL_STACK || RUSTC_VERSION >= 108200 || RUSTC_VERSION >= 108000 && UNWIND_PATCH_PAC_INTO_SCS
config CLANG_SUPPORTS_DYNAMIC_FTRACE_WITH_ARGS
def_bool CC_IS_CLANG

arch/riscv/Kconfig

View file
diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index 90c531e..ddc5344 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -232,9 +232,6 @@ config RISCV
config RUSTC_SUPPORTS_RISCV
def_bool y
depends on 64BIT
- # Shadow call stack requires rustc version 1.82+ due to use of the
- # -Zsanitizer=shadow-call-stack flag.
- depends on !SHADOW_CALL_STACK || RUSTC_VERSION >= 108200
config CLANG_SUPPORTS_DYNAMIC_FTRACE
def_bool CC_IS_CLANG

drivers/android/binder/Makefile

View file
diff --git a/drivers/android/binder/Makefile b/drivers/android/binder/Makefile
index 09eabb5..7e0cd97 100644
--- a/drivers/android/binder/Makefile
+++ b/drivers/android/binder/Makefile
@@ -5,5 +5,4 @@ obj-$(CONFIG_ANDROID_BINDER_IPC_RUST) += rust_binder.o
rust_binder-y := \
rust_binder_main.o \
rust_binderfs.o \
- rust_binder_events.o \
- page_range_helper.o
+ rust_binder_events.o

drivers/android/binder/page_range.rs

View file
diff --git a/drivers/android/binder/page_range.rs b/drivers/android/binder/page_range.rs
index b57e0c7..60e20fc 100644
--- a/drivers/android/binder/page_range.rs
+++ b/drivers/android/binder/page_range.rs
@@ -683,15 +683,15 @@ unsafe extern "C" fn rust_shrink_scan(
unsafe {
bindings::list_lru_walk(
list_lru,
- Some(bindings::rust_shrink_free_page_wrap),
+ Some(rust_shrink_free_page),
ptr::null_mut(),
nr_to_scan,
)
}
}
-const LRU_SKIP: bindings::lru_status = bindings::lru_status_LRU_SKIP;
-const LRU_REMOVED_ENTRY: bindings::lru_status = bindings::lru_status_LRU_REMOVED_RETRY;
+const LRU_SKIP: bindings::lru_status = bindings::lru_status::LRU_SKIP;
+const LRU_REMOVED_ENTRY: bindings::lru_status = bindings::lru_status::LRU_REMOVED_RETRY;
/// # Safety
/// Called by the shrinker.

drivers/android/binder/page_range_helper.c

View before deletion
diff --git a/drivers/android/binder/page_range_helper.c b/drivers/android/binder/page_range_helper.c
deleted file mode 100644
index 4968877..0000000
--- a/drivers/android/binder/page_range_helper.c
+++ /dev/null
@@ -1,24 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-
-/* C helper for page_range.rs to work around a CFI violation.
- *
- * Bindgen currently pretends that `enum lru_status` is the same as an integer.
- * This assumption is fine ABI-wise, but once you add CFI to the mix, it
- * triggers a CFI violation because `enum lru_status` gets a different CFI tag.
- *
- * This file contains a workaround until bindgen can be fixed.
- *
- * Copyright (C) 2025 Google LLC.
- */
-#include "page_range_helper.h"
-
-unsigned int rust_shrink_free_page(struct list_head *item,
- struct list_lru_one *list,
- void *cb_arg);
-
-enum lru_status
-rust_shrink_free_page_wrap(struct list_head *item, struct list_lru_one *list,
- void *cb_arg)
-{
- return rust_shrink_free_page(item, list, cb_arg);
-}

drivers/android/binder/page_range_helper.h

View before deletion
diff --git a/drivers/android/binder/page_range_helper.h b/drivers/android/binder/page_range_helper.h
deleted file mode 100644
index 18dd2dd..0000000
--- a/drivers/android/binder/page_range_helper.h
+++ /dev/null
@@ -1,15 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/*
- * Copyright (C) 2025 Google, Inc.
- */
-
-#ifndef _LINUX_PAGE_RANGE_HELPER_H
-#define _LINUX_PAGE_RANGE_HELPER_H
-
-#include <linux/list_lru.h>
-
-enum lru_status
-rust_shrink_free_page_wrap(struct list_head *item, struct list_lru_one *list,
- void *cb_arg);
-
-#endif /* _LINUX_PAGE_RANGE_HELPER_H */

drivers/android/binder/rust_binder_main.rs

View file
diff --git a/drivers/android/binder/rust_binder_main.rs b/drivers/android/binder/rust_binder_main.rs
index 0140106..632b547 100644
--- a/drivers/android/binder/rust_binder_main.rs
+++ b/drivers/android/binder/rust_binder_main.rs
@@ -3,6 +3,8 @@
// Copyright (C) 2025 Google LLC.
//! Binder -- the Android IPC mechanism.
+
+#![crate_name = "rust_binder"]
#![recursion_limit = "256"]
#![allow(
clippy::as_underscore,

drivers/gpu/drm/tyr/driver.rs

View file
diff --git a/drivers/gpu/drm/tyr/driver.rs b/drivers/gpu/drm/tyr/driver.rs
index beeffe3..e833e9f 100644
--- a/drivers/gpu/drm/tyr/driver.rs
+++ b/drivers/gpu/drm/tyr/driver.rs
@@ -53,18 +53,6 @@ pub(crate) struct TyrData {
pub(crate) gpu_info: GpuInfo,
}
-// Both `Clk` and `Regulator` do not implement `Send` or `Sync`, but they
-// should. There are patches on the mailing list to address this, but they have
-// not landed yet.
-//
-// For now, add this workaround so that this patch compiles with the promise
-// that it will be removed in a future patch.
-//
-// SAFETY: This will be removed in a future patch.
-unsafe impl Send for TyrData {}
-// SAFETY: This will be removed in a future patch.
-unsafe impl Sync for TyrData {}
-
fn issue_soft_reset(dev: &Device<Bound>, iomem: &Devres<IoMem>) -> Result {
regs::GPU_CMD.write(dev, iomem, regs::GPU_CMD_SOFT_RESET)?;

drivers/gpu/nova-core/gsp/cmdq.rs

View file
diff --git a/drivers/gpu/nova-core/gsp/cmdq.rs b/drivers/gpu/nova-core/gsp/cmdq.rs
index 03a4f35..c1fbc54 100644
--- a/drivers/gpu/nova-core/gsp/cmdq.rs
+++ b/drivers/gpu/nova-core/gsp/cmdq.rs
@@ -293,7 +293,6 @@ impl DmaGspMem {
let (slice_1, slice_2) = {
let (slice_1, slice_2) = self.driver_write_area();
- #[allow(clippy::incompatible_msrv)]
(slice_1.as_flattened_mut(), slice_2.as_flattened_mut())
};
@@ -545,10 +544,7 @@ impl Cmdq {
Delta::from_millis(1),
timeout,
)
- .map(|(slice_1, slice_2)| {
- #[allow(clippy::incompatible_msrv)]
- (slice_1.as_flattened(), slice_2.as_flattened())
- })?;
+ .map(|(slice_1, slice_2)| (slice_1.as_flattened(), slice_2.as_flattened()))?;
// Extract the `GspMsgElement`.
let (header, slice_1) = GspMsgElement::from_bytes_prefix(slice_1).ok_or(EIO)?;

drivers/gpu/nova-core/gsp/fw/r570_144.rs

View file
diff --git a/drivers/gpu/nova-core/gsp/fw/r570_144.rs b/drivers/gpu/nova-core/gsp/fw/r570_144.rs
index e99d315..2e6f0d2 100644
--- a/drivers/gpu/nova-core/gsp/fw/r570_144.rs
+++ b/drivers/gpu/nova-core/gsp/fw/r570_144.rs
@@ -7,9 +7,6 @@
//! This module may not be directly used. Please abstract or re-export the needed symbols in the
//! parent module instead.
-#![cfg_attr(test, allow(deref_nullptr))]
-#![cfg_attr(test, allow(unaligned_references))]
-#![cfg_attr(test, allow(unsafe_op_in_unsafe_fn))]
#![allow(
dead_code,
clippy::all,

drivers/pwm/pwm_th1520.rs

View file
diff --git a/drivers/pwm/pwm_th1520.rs b/drivers/pwm/pwm_th1520.rs
index b0e24ee..6cd6fa3 100644
--- a/drivers/pwm/pwm_th1520.rs
+++ b/drivers/pwm/pwm_th1520.rs
@@ -99,21 +99,6 @@ struct Th1520PwmDriverData {
clk: Clk,
}
-// This `unsafe` implementation is a temporary necessity because the underlying `kernel::clk::Clk`
-// type does not yet expose `Send` and `Sync` implementations. This block should be removed
-// as soon as the clock abstraction provides these guarantees directly.
-// TODO: Remove those unsafe impl's when Clk will support them itself.
-
-// SAFETY: The `devres` framework requires the driver's private data to be `Send` and `Sync`.
-// We can guarantee this because the PWM core synchronizes all callbacks, preventing concurrent
-// access to the contained `iomem` and `clk` resources.
-unsafe impl Send for Th1520PwmDriverData {}
-
-// SAFETY: The same reasoning applies as for `Send`. The PWM core's synchronization
-// guarantees that it is safe for multiple threads to have shared access (`&self`)
-// to the driver data during callbacks.
-unsafe impl Sync for Th1520PwmDriverData {}
-
impl pwm::PwmOps for Th1520PwmDriverData {
type WfHw = Th1520WfHw;

init/Kconfig

View file
diff --git a/init/Kconfig b/init/Kconfig
index 7484cd7..e18fa24 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -82,6 +82,21 @@ config RUSTC_LLVM_VERSION
int
default $(rustc-llvm-version)
+config RUSTC_LLVM_MAJOR_VERSION
+ int
+ default $(shell,expr $(rustc-llvm-version) / 10000)
+
+config RUSTC_CLANG_LLVM_COMPATIBLE
+ bool
+ default y if CC_IS_CLANG && RUSTC_LLVM_MAJOR_VERSION = $(shell,expr $(cc-version) / 10000)
+ help
+ This indicates whether Rust and Clang use LLVM of the same major
+ version.
+
+ Operations involving handling LLVM IR or bitcode (e.g. cross-language
+ LTO) require the same LLVM major version to work properly. For best
+ compatibility it is recommended that the exact same LLVM is used.
+
config ARCH_HAS_CC_CAN_LINK
bool
@@ -163,12 +178,6 @@ config LD_CAN_USE_KEEP_IN_OVERLAY
# https://github.com/llvm/llvm-project/pull/130661
def_bool LD_IS_BFD || LLD_VERSION >= 210000
-config RUSTC_HAS_SLICE_AS_FLATTENED
- def_bool RUSTC_VERSION >= 108000
-
-config RUSTC_HAS_COERCE_POINTEE
- def_bool RUSTC_VERSION >= 108400
-
config RUSTC_HAS_SPAN_FILE
def_bool RUSTC_VERSION >= 108800
@@ -2178,9 +2187,7 @@ config RUST
depends on !DEBUG_INFO_BTF || (PAHOLE_HAS_LANG_EXCLUDE && !LTO)
depends on !CFI || HAVE_CFI_ICALL_NORMALIZE_INTEGERS_RUSTC
select CFI_ICALL_NORMALIZE_INTEGERS if CFI
- depends on !CALL_PADDING || RUSTC_VERSION >= 108100
depends on !KASAN_SW_TAGS
- depends on !(MITIGATION_RETHUNK && KASAN) || RUSTC_VERSION >= 108300
help
Enables Rust support in the kernel.
@@ -2204,12 +2211,7 @@ config RUSTC_VERSION_TEXT
config BINDGEN_VERSION_TEXT
string
depends on RUST
- # The dummy parameter `workaround-for-0.69.0` is required to support 0.69.0
- # (https://github.com/rust-lang/rust-bindgen/pull/2678) and 0.71.0
- # (https://github.com/rust-lang/rust-bindgen/pull/3040). It can be removed
- # when the minimum version is upgraded past the latter (0.69.1 and 0.71.1
- # both fixed the issue).
- default "$(shell,$(BINDGEN) --version workaround-for-0.69.0 2>/dev/null)"
+ default "$(shell,$(BINDGEN) --version 2>/dev/null)"
#
# Place an empty function call at each tracepoint site. Can be

lib/Kconfig.debug

View file
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 93f356d..30d0696 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -3577,6 +3577,23 @@ config RUST_KERNEL_DOCTESTS
If unsure, say N.
+config RUST_INLINE_HELPERS
+ bool "Inline C helpers into Rust code (EXPERIMENTAL)"
+ depends on RUST && RUSTC_CLANG_LLVM_COMPATIBLE
+ depends on EXPERT
+ depends on ARM64 || X86_64
+ depends on !UML
+ help
+ Inlines C helpers into Rust code using Link Time Optimization.
+
+ If this option is enabled, C helper functions declared in
+ rust/helpers/ are inlined into Rust code, which is helpful for
+ performance of Rust code. This requires a matching LLVM version for
+ Clang and rustc.
+
+ If you are sure that you're using Clang and rustc with matching LLVM
+ versions, say Y. Otherwise say N.
+
endmenu # "Rust"
endmenu # Kernel hacking

rust/Makefile

View file
diff --git a/rust/Makefile b/rust/Makefile
index 9801af2..b361bfe 100644
--- a/rust/Makefile
+++ b/rust/Makefile
@@ -6,15 +6,19 @@ rustdoc_output := $(objtree)/Documentation/output/rust/rustdoc
obj-$(CONFIG_RUST) += core.o compiler_builtins.o ffi.o
always-$(CONFIG_RUST) += exports_core_generated.h
+ifdef CONFIG_RUST_INLINE_HELPERS
+always-$(CONFIG_RUST) += helpers/helpers.bc helpers/helpers_module.bc
+else
+obj-$(CONFIG_RUST) += helpers/helpers.o
+always-$(CONFIG_RUST) += exports_helpers_generated.h
+endif
# Missing prototypes are expected in the helpers since these are exported
# for Rust only, thus there is no header nor prototypes.
-obj-$(CONFIG_RUST) += helpers/helpers.o
CFLAGS_REMOVE_helpers/helpers.o = -Wmissing-prototypes -Wmissing-declarations

This diff is incomplete. Download the complete patch.

rust/bindgen_parameters

View file

This diff is incomplete. Download the complete patch.

rust/bindings/bindings_helper.h

View file

This diff is incomplete. Download the complete patch.

rust/bindings/lib.rs

View file

This diff is incomplete. Download the complete patch.

rust/exports.c

View file

This diff is incomplete. Download the complete patch.

rust/helpers/clk.c

View file

This diff is incomplete. Download the complete patch.

rust/helpers/helpers.c

View file

This diff is incomplete. Download the complete patch.

rust/helpers/jump_label.c

View file

This diff is incomplete. Download the complete patch.

rust/kernel/alloc/allocator/iter.rs

View file

This diff is incomplete. Download the complete patch.

rust/kernel/alloc/kbox.rs

View file

This diff is incomplete. Download the complete patch.

rust/kernel/alloc/kvec/errors.rs

View file

This diff is incomplete. Download the complete patch.

rust/kernel/block/mq/gen_disk.rs

View file

This diff is incomplete. Download the complete patch.

rust/kernel/build_assert.rs

View file

This diff is incomplete. Download the complete patch.

rust/kernel/clk.rs

View file

This diff is incomplete. Download the complete patch.

rust/kernel/error.rs

View file

This diff is incomplete. Download the complete patch.

rust/kernel/i2c.rs

View file

This diff is incomplete. Download the complete patch.

rust/kernel/lib.rs

View file

This diff is incomplete. Download the complete patch.

rust/kernel/list.rs

View file

This diff is incomplete. Download the complete patch.

rust/kernel/list/arc.rs

View file

This diff is incomplete. Download the complete patch.

rust/kernel/list/arc_field.rs

View file

This diff is incomplete. Download the complete patch.

rust/kernel/list/impl_list_item_mod.rs

View file

This diff is incomplete. Download the complete patch.

rust/kernel/num/bounded.rs

View file

This diff is incomplete. Download the complete patch.

rust/kernel/prelude.rs

View file

This diff is incomplete. Download the complete patch.

rust/kernel/ptr.rs

View file

This diff is incomplete. Download the complete patch.

rust/kernel/sizes.rs

View file

This diff is incomplete. Download the complete patch.

rust/kernel/slice.rs

View before deletion

This diff is incomplete. Download the complete patch.

rust/kernel/static_assert.rs

View before deletion

This diff is incomplete. Download the complete patch.

rust/kernel/str.rs

View file

This diff is incomplete. Download the complete patch.

rust/kernel/sync/arc.rs

View file

This diff is incomplete. Download the complete patch.

rust/kernel/task.rs

View file

This diff is incomplete. Download the complete patch.

rust/kernel/time.rs

View file

This diff is incomplete. Download the complete patch.

rust/kernel/time/hrtimer.rs

View file

This diff is incomplete. Download the complete patch.

rust/kernel/transmute.rs

View file

This diff is incomplete. Download the complete patch.

rust/kernel/types.rs

View file

This diff is incomplete. Download the complete patch.

rust/kernel/usb.rs

View file

This diff is incomplete. Download the complete patch.

rust/kernel/xarray.rs

View file

This diff is incomplete. Download the complete patch.

rust/macros/helpers.rs

View file

This diff is incomplete. Download the complete patch.

rust/macros/kunit.rs

View file

This diff is incomplete. Download the complete patch.

rust/macros/lib.rs

View file

This diff is incomplete. Download the complete patch.

rust/macros/module.rs

View file

This diff is incomplete. Download the complete patch.

rust/pin-init/README.md

View file

This diff is incomplete. Download the complete patch.

rust/pin-init/examples/big_struct_in_place.rs

View file

This diff is incomplete. Download the complete patch.

rust/pin-init/examples/linked_list.rs

View file

This diff is incomplete. Download the complete patch.

rust/pin-init/examples/mutex.rs

View file

This diff is incomplete. Download the complete patch.

rust/pin-init/examples/pthread_mutex.rs

View file

This diff is incomplete. Download the complete patch.

rust/pin-init/examples/static_init.rs

View file

This diff is incomplete. Download the complete patch.

rust/pin-init/internal/src/init.rs

View file

This diff is incomplete. Download the complete patch.

rust/pin-init/internal/src/lib.rs

View file

This diff is incomplete. Download the complete patch.

rust/pin-init/src/lib.rs

View file

This diff is incomplete. Download the complete patch.

rust/uapi/lib.rs

View file

This diff is incomplete. Download the complete patch.

scripts/Makefile.build

View file

This diff is incomplete. Download the complete patch.

scripts/generate_rust_analyzer.py

View file

This diff is incomplete. Download the complete patch.

scripts/min-tool-version.sh

View file

This diff is incomplete. Download the complete patch.

scripts/rust_is_available.sh

View file

This diff is incomplete. Download the complete patch.

scripts/rust_is_available_bindgen_0_66.h

View before deletion

This diff is incomplete. Download the complete patch.

scripts/rust_is_available_bindgen_libclang_concat.h

View before deletion

This diff is incomplete. Download the complete patch.

scripts/rust_is_available_test.py

View file

This diff is incomplete. Download the complete patch.