Skip to content

Commit 784faa8

Browse files
committed
Merge tag 'rust-6.19' of git://git.kernel.org/pub/scm/linux/kernel/git/ojeda/linux
Pull Rust updates from Miguel Ojeda: "Toolchain and infrastructure: - Add support for 'syn'. Syn is a parsing library for parsing a stream of Rust tokens into a syntax tree of Rust source code. Currently this library is geared toward use in Rust procedural macros, but contains some APIs that may be useful more generally. 'syn' allows us to greatly simplify writing complex macros such as 'pin-init' (Benno has already prepared the 'syn'-based version). We will use it in the 'macros' crate too. 'syn' is the most downloaded Rust crate (according to crates.io), and it is also used by the Rust compiler itself. While the amount of code is substantial, there should not be many updates needed for these crates, and even if there are, they should not be too big, e.g. +7k -3k lines across the 3 crates in the last year. 'syn' requires two smaller dependencies: 'quote' and 'proc-macro2'. I only modified their code to remove a third dependency ('unicode-ident') and to add the SPDX identifiers. The code can be easily verified to exactly match upstream with the provided scripts. They are all licensed under "Apache-2.0 OR MIT", like the other vendored 'alloc' crate we had for a while. Please see the merge commit with the cover letter for more context. - Allow 'unreachable_pub' and 'clippy::disallowed_names' for doctests. Examples (i.e. doctests) may want to do things like show public items and use names such as 'foo'. Nevertheless, we still try to keep examples as close to real code as possible (this is part of why running Clippy on doctests is important for us, e.g. for safety comments, which userspace Rust does not support yet but we are stricter). 'kernel' crate: - Replace our custom 'CStr' type with 'core::ffi::CStr'. Using the standard library type reduces our custom code footprint, and we retain needed custom functionality through an extension trait and a new 'fmt!' macro which replaces the previous 'core' import. This started in 6.17 and continued in 6.18, and we finally land the replacement now. This required quite some stamina from Tamir, who split the changes in steps to prepare for the flag day change here. - Replace 'kernel::c_str!' with C string literals. C string literals were added in Rust 1.77, which produce '&CStr's (the 'core' one), so now we can write: c"hi" instead of: c_str!("hi") - Add 'num' module for numerical features. It includes the 'Integer' trait, implemented for all primitive integer types. It also includes the 'Bounded' integer wrapping type: an integer value that requires only the 'N' least significant bits of the wrapped type to be encoded: // An unsigned 8-bit integer, of which only the 4 LSBs are used. let v = Bounded::<u8, 4>::new::<15>(); assert_eq!(v.get(), 15); 'Bounded' is useful to e.g. enforce guarantees when working with bitfields that have an arbitrary number of bits. Values can also be constructed from simple non-constant expressions or, for more complex ones, validated at runtime. 'Bounded' also comes with comparison and arithmetic operations (with both their backing type and other 'Bounded's with a compatible backing type), casts to change the backing type, extending/shrinking and infallible/fallible conversions from/to primitives as applicable. - 'rbtree' module: add immutable cursor ('Cursor'). It enables to use just an immutable tree reference where appropriate. The existing fully-featured mutable cursor is renamed to 'CursorMut'. kallsyms: - Fix wrong "big" kernel symbol type read from procfs. 'pin-init' crate: - A couple minor fixes (Benno asked me to pick these patches up for him this cycle). Documentation: - Quick Start guide: add Debian 13 (Trixie). Debian Stable is now able to build Linux, since Debian 13 (released 2025-08-09) packages Rust 1.85.0, which is recent enough. We are planning to propose that the minimum supported Rust version in Linux follows Debian Stable releases, with Debian 13 being the first one we upgrade to, i.e. Rust 1.85. MAINTAINERS: - Add entry for the new 'num' module. - Remove Alex as Rust maintainer: he hasn't had the time to contribute for a few years now, so it is a no-op change in practice. And a few other cleanups and improvements" * tag 'rust-6.19' of git://git.kernel.org/pub/scm/linux/kernel/git/ojeda/linux: (53 commits) rust: macros: support `proc-macro2`, `quote` and `syn` rust: syn: enable support in kbuild rust: syn: add `README.md` rust: syn: remove `unicode-ident` dependency rust: syn: add SPDX License Identifiers rust: syn: import crate rust: quote: enable support in kbuild rust: quote: add `README.md` rust: quote: add SPDX License Identifiers rust: quote: import crate rust: proc-macro2: enable support in kbuild rust: proc-macro2: add `README.md` rust: proc-macro2: remove `unicode_ident` dependency rust: proc-macro2: add SPDX License Identifiers rust: proc-macro2: import crate rust: kbuild: support using libraries in `rustc_procmacro` rust: kbuild: support skipping flags in `rustc_test_library` rust: kbuild: add proc macro library support rust: kbuild: simplify `--cfg` handling rust: kbuild: introduce `core-flags` and `core-skip_flags` ...
2 parents 51ab33f + 54e3eae commit 784faa8

File tree

131 files changed

+59666
-477
lines changed

Some content is hidden

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

131 files changed

+59666
-477
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
*.o.*
4242
*.patch
4343
*.pyc
44+
*.rlib
4445
*.rmeta
4546
*.rpm
4647
*.rsi

Documentation/rust/quick-start.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ of the box, e.g.::
3939
Debian
4040
******
4141

42-
Debian Testing and Debian Unstable (Sid), outside of the freeze period, provide
43-
recent Rust releases and thus they should generally work out of the box, e.g.::
42+
Debian 13 (Trixie), as well as Testing and Debian Unstable (Sid) provide recent
43+
Rust releases and thus they should generally work out of the box, e.g.::
4444

4545
apt install rustc rust-src bindgen rustfmt rust-clippy
4646

MAINTAINERS

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22524,7 +22524,6 @@ F: tools/verification/
2252422524

2252522525
RUST
2252622526
M: Miguel Ojeda <[email protected]>
22527-
M: Alex Gaynor <[email protected]>
2252822527
R: Boqun Feng <[email protected]>
2252922528
R: Gary Guo <[email protected]>
2253022529
R: Björn Roy Baron <[email protected]>
@@ -22561,6 +22560,14 @@ T: git https://github.com/Rust-for-Linux/linux.git alloc-next
2256122560
F: rust/kernel/alloc.rs
2256222561
F: rust/kernel/alloc/
2256322562

22563+
RUST [NUM]
22564+
M: Alexandre Courbot <[email protected]>
22565+
R: Yury Norov <[email protected]>
22566+
22567+
S: Maintained
22568+
F: rust/kernel/num.rs
22569+
F: rust/kernel/num/
22570+
2256422571
RUST [PIN-INIT]
2256522572
M: Benno Lossin <[email protected]>
2256622573

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1830,10 +1830,17 @@ rusttest: prepare
18301830
$(Q)$(MAKE) $(build)=rust $@
18311831

18321832
# Formatting targets
1833+
#
1834+
# Generated files as well as vendored crates are skipped.
18331835
PHONY += rustfmt rustfmtcheck
18341836

18351837
rustfmt:
18361838
$(Q)find $(srctree) $(RCS_FIND_IGNORE) \
1839+
\( \
1840+
-path $(srctree)/rust/proc-macro2 \
1841+
-o -path $(srctree)/rust/quote \
1842+
-o -path $(srctree)/rust/syn \
1843+
\) -prune -o \
18371844
-type f -a -name '*.rs' -a ! -name '*generated*' -print \
18381845
| xargs $(RUSTFMT) $(rustfmt_flags)
18391846

drivers/android/binder/error.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
// Copyright (C) 2025 Google LLC.
44

5+
use kernel::fmt;
56
use kernel::prelude::*;
67

78
use crate::defs::*;
@@ -76,8 +77,8 @@ impl From<kernel::alloc::AllocError> for BinderError {
7677
}
7778
}
7879

79-
impl core::fmt::Debug for BinderError {
80-
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
80+
impl fmt::Debug for BinderError {
81+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8182
match self.reply {
8283
BR_FAILED_REPLY => match self.source.as_ref() {
8384
Some(source) => f

drivers/android/binder/freeze.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ impl Process {
331331
KVVec::with_capacity(8, GFP_KERNEL).unwrap_or_else(|_err| KVVec::new());
332332

333333
let mut inner = self.lock_with_nodes();
334-
let mut curr = inner.nodes.cursor_front();
334+
let mut curr = inner.nodes.cursor_front_mut();
335335
while let Some(cursor) = curr {
336336
let (key, node) = cursor.current();
337337
let key = *key;
@@ -345,7 +345,7 @@ impl Process {
345345
// Find the node we were looking at and try again. If the set of nodes was changed,
346346
// then just proceed to the next node. This is ok because we don't guarantee the
347347
// inclusion of nodes that are added or removed in parallel with this operation.
348-
curr = inner.nodes.cursor_lower_bound(&key);
348+
curr = inner.nodes.cursor_lower_bound_mut(&key);
349349
continue;
350350
}
351351

drivers/android/binder/process.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ impl Process {
623623
" ref {}: desc {} {}node {debug_id} s {strong} w {weak}",
624624
r.debug_id,
625625
r.handle,
626-
if dead { "dead " } else { "" },
626+
if dead { "dead " } else { "" }
627627
);
628628
}
629629
}
@@ -1320,7 +1320,7 @@ impl Process {
13201320
{
13211321
while let Some(node) = {
13221322
let mut lock = self.inner.lock();
1323-
lock.nodes.cursor_front().map(|c| c.remove_current().1)
1323+
lock.nodes.cursor_front_mut().map(|c| c.remove_current().1)
13241324
} {
13251325
node.to_key_value().1.release();
13261326
}

drivers/android/binder/range_alloc/tree.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ impl<T> TreeRangeAllocator<T> {
207207
}
208208

209209
pub(crate) fn reservation_abort(&mut self, offset: usize) -> Result<FreedRange> {
210-
let mut cursor = self.tree.cursor_lower_bound(&offset).ok_or_else(|| {
210+
let mut cursor = self.tree.cursor_lower_bound_mut(&offset).ok_or_else(|| {
211211
pr_warn!(
212212
"EINVAL from range_alloc.reservation_abort - offset: {}",
213213
offset

drivers/android/binder/stats.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl BinderStats {
6161

6262
mod strings {
6363
use core::str::from_utf8_unchecked;
64-
use kernel::str::CStr;
64+
use kernel::str::{CStr, CStrExt as _};
6565

6666
extern "C" {
6767
static binder_command_strings: [*const u8; super::BC_COUNT];
@@ -72,7 +72,7 @@ mod strings {
7272
// SAFETY: Accessing `binder_command_strings` is always safe.
7373
let c_str_ptr = unsafe { binder_command_strings[i] };
7474
// SAFETY: The `binder_command_strings` array only contains nul-terminated strings.
75-
let bytes = unsafe { CStr::from_char_ptr(c_str_ptr) }.as_bytes();
75+
let bytes = unsafe { CStr::from_char_ptr(c_str_ptr) }.to_bytes();
7676
// SAFETY: The `binder_command_strings` array only contains strings with ascii-chars.
7777
unsafe { from_utf8_unchecked(bytes) }
7878
}
@@ -81,7 +81,7 @@ mod strings {
8181
// SAFETY: Accessing `binder_return_strings` is always safe.
8282
let c_str_ptr = unsafe { binder_return_strings[i] };
8383
// SAFETY: The `binder_command_strings` array only contains nul-terminated strings.
84-
let bytes = unsafe { CStr::from_char_ptr(c_str_ptr) }.as_bytes();
84+
let bytes = unsafe { CStr::from_char_ptr(c_str_ptr) }.to_bytes();
8585
// SAFETY: The `binder_command_strings` array only contains strings with ascii-chars.
8686
unsafe { from_utf8_unchecked(bytes) }
8787
}

drivers/block/rnull/configfs.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
// SPDX-License-Identifier: GPL-2.0
22

33
use super::{NullBlkDevice, THIS_MODULE};
4-
use core::fmt::{Display, Write};
54
use kernel::{
65
block::mq::gen_disk::{GenDisk, GenDiskBuilder},
76
c_str,
87
configfs::{self, AttributeOperations},
9-
configfs_attrs, new_mutex,
8+
configfs_attrs,
9+
fmt::{self, Write as _},
10+
new_mutex,
1011
page::PAGE_SIZE,
1112
prelude::*,
1213
str::{kstrtobool_bytes, CString},
@@ -99,8 +100,8 @@ impl TryFrom<u8> for IRQMode {
99100
}
100101
}
101102

102-
impl Display for IRQMode {
103-
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
103+
impl fmt::Display for IRQMode {
104+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
104105
match self {
105106
Self::None => f.write_str("0")?,
106107
Self::Soft => f.write_str("1")?,

0 commit comments

Comments
 (0)