Skip to content

Commit 26ff969

Browse files
committed
Merge tag 'rust-7.1' of git://git.kernel.org/pub/scm/linux/kernel/git/ojeda/linux
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 ...
2 parents 2848320 + 8a23051 commit 26ff969

78 files changed

Lines changed: 1391 additions & 821 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.clippy.toml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SPDX-License-Identifier: GPL-2.0
22

3-
msrv = "1.78.0"
3+
msrv = "1.85.0"
44

55
check-private-items = true
66

@@ -9,3 +9,13 @@ disallowed-macros = [
99
# it here, see: https://github.com/rust-lang/rust-clippy/issues/11303.
1010
{ path = "kernel::dbg", reason = "the `dbg!` macro is intended as a debugging tool", allow-invalid = true },
1111
]
12+
13+
[[disallowed-methods]]
14+
path = "core::ffi::CStr::as_ptr"
15+
replacement = "kernel::prelude::CStrExt::as_char_ptr"
16+
reason = "kernel's `char` is always unsigned, use `as_char_ptr` instead"
17+
18+
[[disallowed-methods]]
19+
path = "core::ffi::CStr::from_ptr"
20+
replacement = "kernel::prelude::CStrExt::from_char_ptr"
21+
reason = "kernel's `char` is always unsigned, use `from_char_ptr` instead"

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
.*
1414
*.a
1515
*.asn1.[ch]
16+
*.bc
1617
*.bin
1718
*.bz2
1819
*.c.[012]*.*
@@ -184,3 +185,6 @@ sphinx_*/
184185

185186
# Rust analyzer configuration
186187
/rust-project.json
188+
189+
# bc language scripts (not LLVM bitcode)
190+
!kernel/time/timeconst.bc

Documentation/process/changes.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ you probably needn't concern yourself with pcmciautils.
3131
====================== =============== ========================================
3232
GNU C 8.1 gcc --version
3333
Clang/LLVM (optional) 15.0.0 clang --version
34-
Rust (optional) 1.78.0 rustc --version
35-
bindgen (optional) 0.65.1 bindgen --version
34+
Rust (optional) 1.85.0 rustc --version
35+
bindgen (optional) 0.71.1 bindgen --version
3636
GNU make 4.0 make --version
3737
bash 4.2 bash --version
3838
binutils 2.30 ld -v

Documentation/rust/general-information.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,5 +157,5 @@ numerical comparisons, one may define a new Kconfig symbol:
157157

158158
.. code-block:: kconfig
159159
160-
config RUSTC_VERSION_MIN_107900
161-
def_bool y if RUSTC_VERSION >= 107900
160+
config RUSTC_HAS_SPAN_FILE
161+
def_bool RUSTC_VERSION >= 108800

Documentation/rust/quick-start.rst

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ of the box, e.g.::
5757
Gentoo Linux
5858
************
5959

60-
Gentoo Linux (and especially the testing branch) provides recent Rust releases
61-
and thus it should generally work out of the box, e.g.::
60+
Gentoo Linux provides recent Rust releases and thus it should generally work out
61+
of the box, e.g.::
6262

6363
USE='rust-src rustfmt clippy' emerge dev-lang/rust dev-util/bindgen
6464

@@ -68,8 +68,8 @@ and thus it should generally work out of the box, e.g.::
6868
Nix
6969
***
7070

71-
Nix (unstable channel) provides recent Rust releases and thus it should
72-
generally work out of the box, e.g.::
71+
Nix provides recent Rust releases and thus it should generally work out of the
72+
box, e.g.::
7373

7474
{ pkgs ? import <nixpkgs> {} }:
7575
pkgs.mkShell {
@@ -84,16 +84,13 @@ openSUSE
8484
openSUSE Slowroll and openSUSE Tumbleweed provide recent Rust releases and thus
8585
they should generally work out of the box, e.g.::
8686

87-
zypper install rust rust1.79-src rust-bindgen clang
87+
zypper install rust rust-src rust-bindgen clang
8888

8989

9090
Ubuntu
9191
******
9292

93-
25.04
94-
~~~~~
95-
96-
The latest Ubuntu releases provide recent Rust releases and thus they should
93+
Ubuntu 25.10 and 26.04 LTS provide recent Rust releases and thus they should
9794
generally work out of the box, e.g.::
9895

9996
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
112109
releases, they require some additional configuration to be set, using
113110
the versioned packages, e.g.::
114111

115-
apt install rustc-1.80 rust-1.80-src bindgen-0.65 rustfmt-1.80 \
116-
rust-1.80-clippy
117-
ln -s /usr/lib/rust-1.80/bin/rustfmt /usr/bin/rustfmt-1.80
118-
ln -s /usr/lib/rust-1.80/bin/clippy-driver /usr/bin/clippy-driver-1.80
112+
apt install rustc-1.85 rust-1.85-src bindgen-0.71 rustfmt-1.85 \
113+
rust-1.85-clippy
114+
ln -s /usr/lib/rust-1.85/bin/rustfmt /usr/bin/rustfmt-1.85
115+
ln -s /usr/lib/rust-1.85/bin/clippy-driver /usr/bin/clippy-driver-1.85
119116

120117
None of these packages set their tools as defaults; therefore they should be
121118
specified explicitly, e.g.::
122119

123-
make LLVM=1 RUSTC=rustc-1.80 RUSTDOC=rustdoc-1.80 RUSTFMT=rustfmt-1.80 \
124-
CLIPPY_DRIVER=clippy-driver-1.80 BINDGEN=bindgen-0.65
120+
make LLVM=1 RUSTC=rustc-1.85 RUSTDOC=rustdoc-1.85 RUSTFMT=rustfmt-1.85 \
121+
CLIPPY_DRIVER=clippy-driver-1.85 BINDGEN=bindgen-0.71
125122

126-
Alternatively, modify the ``PATH`` variable to place the Rust 1.80 binaries
123+
Alternatively, modify the ``PATH`` variable to place the Rust 1.85 binaries
127124
first and set ``bindgen`` as the default, e.g.::
128125

129-
PATH=/usr/lib/rust-1.80/bin:$PATH
126+
PATH=/usr/lib/rust-1.85/bin:$PATH
130127
update-alternatives --install /usr/bin/bindgen bindgen \
131-
/usr/bin/bindgen-0.65 100
132-
update-alternatives --set bindgen /usr/bin/bindgen-0.65
128+
/usr/bin/bindgen-0.71 100
129+
update-alternatives --set bindgen /usr/bin/bindgen-0.71
133130

134-
``RUST_LIB_SRC`` needs to be set when using the versioned packages, e.g.::
131+
``RUST_LIB_SRC`` may need to be set when using the versioned packages, e.g.::
135132

136-
RUST_LIB_SRC=/usr/src/rustc-$(rustc-1.80 --version | cut -d' ' -f2)/library
133+
RUST_LIB_SRC=/usr/src/rustc-$(rustc-1.85 --version | cut -d' ' -f2)/library
137134

138135
For convenience, ``RUST_LIB_SRC`` can be exported to the global environment.
139136

140-
In addition, ``bindgen-0.65`` is available in newer releases (24.04 LTS and
141-
24.10), but it may not be available in older ones (20.04 LTS and 22.04 LTS),
137+
In addition, ``bindgen-0.71`` is available in newer releases (24.04 LTS),
138+
but it may not be available in older ones (20.04 LTS and 22.04 LTS),
142139
thus ``bindgen`` may need to be built manually (please see below).
143140

144141

@@ -355,12 +352,3 @@ Hacking
355352
To dive deeper, take a look at the source code of the samples
356353
at ``samples/rust/``, the Rust support code under ``rust/`` and
357354
the ``Rust hacking`` menu under ``Kernel hacking``.
358-
359-
If GDB/Binutils is used and Rust symbols are not getting demangled, the reason
360-
is the toolchain does not support Rust's new v0 mangling scheme yet.
361-
There are a few ways out:
362-
363-
- Install a newer release (GDB >= 10.2, Binutils >= 2.36).
364-
365-
- Some versions of GDB (e.g. vanilla GDB 10.1) are able to use
366-
the pre-demangled names embedded in the debug info (``CONFIG_DEBUG_INFO``).

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23166,6 +23166,7 @@ C: zulip://rust-for-linux.zulipchat.com
2316623166
P: https://rust-for-linux.com/contributing
2316723167
T: git https://github.com/Rust-for-Linux/linux.git rust-next
2316823168
F: .clippy.toml
23169+
F: .rustfmt.toml
2316923170
F: Documentation/rust/
2317023171
F: include/trace/events/rust_sample.h
2317123172
F: rust/

Makefile

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ export rust_common_flags := --edition=2021 \
487487
-Wclippy::as_underscore \
488488
-Wclippy::cast_lossless \
489489
-Wclippy::ignored_unit_patterns \
490+
-Aclippy::incompatible_msrv \
490491
-Wclippy::mut_mut \
491492
-Wclippy::needless_bitwise_bool \
492493
-Aclippy::needless_lifetimes \
@@ -495,6 +496,7 @@ export rust_common_flags := --edition=2021 \
495496
-Wclippy::ptr_cast_constness \
496497
-Wclippy::ref_as_ptr \
497498
-Wclippy::undocumented_unsafe_blocks \
499+
-Aclippy::uninlined_format_args \
498500
-Wclippy::unnecessary_safety_comment \
499501
-Wclippy::unnecessary_safety_doc \
500502
-Wrustdoc::missing_crate_level_docs \
@@ -505,7 +507,7 @@ KBUILD_HOSTCFLAGS := $(KBUILD_USERHOSTCFLAGS) $(HOST_LFS_CFLAGS) \
505507
KBUILD_HOSTCXXFLAGS := -Wall -O2 $(HOST_LFS_CFLAGS) $(HOSTCXXFLAGS) \
506508
-I $(srctree)/scripts/include
507509
KBUILD_HOSTRUSTFLAGS := $(rust_common_flags) -O -Cstrip=debuginfo \
508-
-Zallow-features= $(HOSTRUSTFLAGS)
510+
-Zallow-features=
509511
KBUILD_HOSTLDFLAGS := $(HOST_LFS_LDFLAGS) $(HOSTLDFLAGS)
510512
KBUILD_HOSTLDLIBS := $(HOST_LFS_LIBS) $(HOSTLDLIBS)
511513
KBUILD_PROCMACROLDFLAGS := $(or $(PROCMACROLDFLAGS),$(KBUILD_HOSTLDFLAGS))
@@ -516,6 +518,7 @@ ifneq ($(LLVM),)
516518
CC = $(LLVM_PREFIX)clang$(LLVM_SUFFIX)
517519
LD = $(LLVM_PREFIX)ld.lld$(LLVM_SUFFIX)
518520
AR = $(LLVM_PREFIX)llvm-ar$(LLVM_SUFFIX)
521+
LLVM_LINK = $(LLVM_PREFIX)llvm-link$(LLVM_SUFFIX)
519522
NM = $(LLVM_PREFIX)llvm-nm$(LLVM_SUFFIX)
520523
OBJCOPY = $(LLVM_PREFIX)llvm-objcopy$(LLVM_SUFFIX)
521524
OBJDUMP = $(LLVM_PREFIX)llvm-objdump$(LLVM_SUFFIX)
@@ -629,7 +632,7 @@ export RUSTC_BOOTSTRAP := 1
629632
export CLIPPY_CONF_DIR := $(srctree)
630633

631634
export ARCH SRCARCH CONFIG_SHELL BASH HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE LD CC HOSTPKG_CONFIG
632-
export RUSTC RUSTDOC RUSTFMT RUSTC_OR_CLIPPY_QUIET RUSTC_OR_CLIPPY BINDGEN
635+
export RUSTC RUSTDOC RUSTFMT RUSTC_OR_CLIPPY_QUIET RUSTC_OR_CLIPPY BINDGEN LLVM_LINK
633636
export HOSTRUSTC KBUILD_HOSTRUSTFLAGS
634637
export CPP AR NM STRIP OBJCOPY OBJDUMP READELF PAHOLE RESOLVE_BTFIDS LEX YACC AWK INSTALLKERNEL
635638
export PERL PYTHON3 CHECK CHECKFLAGS MAKE UTS_MACHINE HOSTCXX
@@ -834,6 +837,20 @@ endif # CONFIG_TRACEPOINTS
834837

835838
export WARN_ON_UNUSED_TRACEPOINTS
836839

840+
# Per-version Rust flags. These are like `rust_common_flags`, but may
841+
# depend on the Rust compiler version (e.g. using `rustc-min-version`).
842+
#
843+
# `-Aclippy::precedence`: the lint was extended in Rust 1.85.0 to
844+
# include bitmasking and shift operations. However, because it generated
845+
# many hits, in Rust 1.86.0 it was split into a new `precedence_bits`
846+
# lint which is not enabled by default.
847+
rust_common_flags_per_version := \
848+
$(if $(call rustc-min-version,108600),,-Aclippy::precedence)
849+
850+
rust_common_flags += $(rust_common_flags_per_version)
851+
KBUILD_HOSTRUSTFLAGS += $(rust_common_flags_per_version) $(HOSTRUSTFLAGS)
852+
KBUILD_RUSTFLAGS += $(rust_common_flags_per_version)
853+
837854
include $(srctree)/arch/$(SRCARCH)/Makefile
838855

839856
ifdef need-config

arch/Kconfig

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -968,10 +968,9 @@ config HAVE_CFI_ICALL_NORMALIZE_INTEGERS
968968
config HAVE_CFI_ICALL_NORMALIZE_INTEGERS_RUSTC
969969
def_bool y
970970
depends on HAVE_CFI_ICALL_NORMALIZE_INTEGERS
971-
depends on RUSTC_VERSION >= 107900
972971
depends on ARM64 || X86_64
973972
# With GCOV/KASAN we need this fix: https://github.com/rust-lang/rust/pull/129373
974-
depends on (RUSTC_LLVM_VERSION >= 190103 && RUSTC_VERSION >= 108200) || \
973+
depends on RUSTC_LLVM_VERSION >= 190103 || \
975974
(!GCOV_KERNEL && !KASAN_GENERIC && !KASAN_SW_TAGS)
976975

977976
config CFI_PERMISSIVE

arch/arm64/Kconfig

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -292,14 +292,6 @@ config ARM64
292292
config RUSTC_SUPPORTS_ARM64
293293
def_bool y
294294
depends on CPU_LITTLE_ENDIAN
295-
# Shadow call stack is only supported on certain rustc versions.
296-
#
297-
# When using the UNWIND_PATCH_PAC_INTO_SCS option, rustc version 1.80+ is
298-
# required due to use of the -Zfixed-x18 flag.
299-
#
300-
# Otherwise, rustc version 1.82+ is required due to use of the
301-
# -Zsanitizer=shadow-call-stack flag.
302-
depends on !SHADOW_CALL_STACK || RUSTC_VERSION >= 108200 || RUSTC_VERSION >= 108000 && UNWIND_PATCH_PAC_INTO_SCS
303295

304296
config CLANG_SUPPORTS_DYNAMIC_FTRACE_WITH_ARGS
305297
def_bool CC_IS_CLANG

arch/riscv/Kconfig

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,6 @@ config RISCV
232232
config RUSTC_SUPPORTS_RISCV
233233
def_bool y
234234
depends on 64BIT
235-
# Shadow call stack requires rustc version 1.82+ due to use of the
236-
# -Zsanitizer=shadow-call-stack flag.
237-
depends on !SHADOW_CALL_STACK || RUSTC_VERSION >= 108200
238235

239236
config CLANG_SUPPORTS_DYNAMIC_FTRACE
240237
def_bool CC_IS_CLANG

0 commit comments

Comments
 (0)