Skip to content

Tags: Rust-for-Linux/linux

Tags

rust-6.10

Toggle rust-6.10's commit message

Verified

This tag was signed with the committer’s verified signature.
ojeda Miguel Ojeda
Rust changes for v6.10

The most notable change is the drop of the 'alloc' in-tree fork. This
is nicely reflected in the diffstat as a ~10k lines drop. In turn, this
makes the version upgrades way simpler and smaller in the future, e.g.
the latest one in commit 56f64b3 ("rust: upgrade to Rust 1.78.0").

More importantly, this increases the chances that a newer compiler
version just works, which in turn means supporting several compiler
versions is easier now. Thus we will look into finally setting a minimum
version in the near future.

Toolchain and infrastructure:

 - Upgrade to Rust 1.78.0.

   This time around, due to how the kernel and Rust schedules have
   aligned, there are two upgrades in fact. These allow us to remove one
   more unstable feature ('offset_of') from the list, among other
   improvements.

 - Drop 'alloc' in-tree fork of the standard library crate, which means
   all the unstable features used by 'alloc' (~30 language ones, ~60
   library ones) are not a concern anymore.

 - Support DWARFv5 via the '-Zdwarf-version' flag.

 - Support zlib and zstd debuginfo compression via the
   '-Zdebuginfo-compression' flag.

'kernel' crate:

 - Support allocation flags ('GFP_*'), particularly in 'Box' (via
   'BoxExt'), 'Vec' (via 'VecExt'), 'Arc' and 'UniqueArc', as well as in
   the 'init' module APIs.

 - Remove usage of the 'allocator_api' unstable feature.

 - Remove 'try_' prefix in allocation APIs' names.

 - Add 'VecExt' (an extension trait) to be able to drop the 'alloc'
   fork.

 - Add the '{make,to}_{upper,lower}case()' methods to 'CStr'/'CString'.

 - Add the 'as_ptr' method to 'ThisModule'.

 - Add the 'from_raw' method to 'ArcBorrow'.

 - Add the 'into_unique_or_drop' method to 'Arc'.

 - Display column number in the 'dbg!' macro output by applying the
   equivalent change done to the standard library one.

 - Migrate 'Work' to '#[pin_data]' thanks to the changes in the 'macros'
   crate, which allows to remove an unsafe call in its 'new' associated
   function.

 - Prevent namespacing issues when using the '[try_][pin_]init!' macros
   by changing the generated name of guard variables.

 - Make the 'get' method in 'Opaque' const.

 - Implement the 'Default' trait for 'LockClassKey'.

 - Remove unneeded 'kernel::prelude' imports from doctests.

 - Remove redundant imports.

'macros' crate:

 - Add 'decl_generics' to 'parse_generics()' to support default values,
   and use that to allow them in '#[pin_data]'.

Helpers:

 - Trivial English grammar fix.

Documentation:

 - Add section on Rust Kselftests to the "Testing" document.

 - Expand the "Abstractions vs. bindings" section of the "General
   Information" document.

rust-fixes-6.9

Toggle rust-fixes-6.9's commit message

Verified

This tag was signed with the committer’s verified signature.
ojeda Miguel Ojeda
Rust fixes for v6.9

 - Soundness: make internal functions generated by the 'module!' macro
   inaccessible, do not implement 'Zeroable' for 'Infallible' and
   require 'Send' for the 'Module' trait.

 - Build: avoid errors with "empty" files and workaround 'rustdoc' ICE.

 - Kconfig: depend on '!CFI_CLANG' and avoid selecting 'CONSTRUCTORS'.

 - Code docs: remove non-existing key from 'module!' macro example.

 - Docs: trivial rendering fix in arch table.

rust-6.9

Toggle rust-6.9's commit message

Verified

This tag was signed with the committer’s verified signature.
ojeda Miguel Ojeda
Rust changes for v6.9

Another routine one in terms of features. We got two version upgrades
this time, but in terms of lines, 'alloc' changes are not very large.

Toolchain and infrastructure:

 - Upgrade to Rust 1.76.0.

   This time around, due to how the kernel and Rust schedules have
   aligned, there are two upgrades in fact. These allow us to remove two
   more unstable features ('const_maybe_uninit_zeroed' and
   'ptr_metadata') from the list, among other improvements.

 - Mark 'rustc' (and others) invocations as recursive, which fixes a new
   warning and prepares us for the future in case we eventually take
   advantage of the Make jobserver.

'kernel' crate:

 - Add the 'container_of!' macro.

 - Stop using the unstable 'ptr_metadata' feature by employing the now
   stable 'byte_sub' method to implement 'Arc::from_raw()'.

 - Add the 'time' module with a 'msecs_to_jiffies()' conversion function
   to begin with, to be used by Rust Binder.

 - Add 'notify_sync()' and 'wait_interruptible_timeout()' methods to
   'CondVar', to be used by Rust Binder.

 - Update integer types for 'CondVar'.

 - Rename 'wait_list' field to 'wait_queue_head' in 'CondVar'.

 - Implement 'Display' and 'Debug' for 'BStr'.

 - Add the 'try_from_foreign()' method to the 'ForeignOwnable' trait.

 - Add reexports for macros so that they can be used from the right
   module (in addition to the root).

 - A series of code documentation improvements, including adding
   intra-doc links, consistency improvements, typo fixes...

'macros' crate:

 - Place generated 'init_module()' function in '.init.text'.

Documentation:

 - Add documentation on Rust doctests and how they work.

rust-6.8

Toggle rust-6.8's commit message

Verified

This tag was signed with the committer’s verified signature.
ojeda Miguel Ojeda
Rust changes for v6.8

Another routine one in terms of features. In terms of lines, this time
the 'alloc' version upgrade is less prominent, given that it was fairly
small (and we did not have two upgrades).

Toolchain and infrastructure:

 - Upgrade to Rust 1.74.1.

   The patch release includes a fix for an ICE that the Apple AGX GPU
   driver was hitting.

 - Support 'srctree'-relative links in Rust code documentation.

 - Automate part of the manual constants handling (i.e. the ones not
   recognised by 'bindgen').

 - Suppress searching builtin sysroot to avoid confusion with installed
   sysroots, needed for the to-be-merged arm64 support which uses
   a builtin target.

 - Ignore '__preserve_most' functions for 'bindgen'.

 - Reduce header inclusion bloat in exports.

'kernel' crate:

 - Implement 'Debug' for 'CString'.

 - Make 'CondVar::wait()' an uninterruptible wait.

'macros' crate:

 - Update 'paste!' to accept string literals.

 - Improve '#[vtable]' documentation.

Documentation:

 - Add testing section (KUnit and 'rusttest' target).

 - Remove 'CC=clang' mentions.

 - Clarify that 'rustup override' applies to build directory.

rust-6.7

Toggle rust-6.7's commit message

Verified

This tag was signed with the committer’s verified signature.
ojeda Miguel Ojeda
Rust changes for v6.7

A small one compared to the previous one in terms of features. In terms
of lines, as usual, the 'alloc' version upgrade accounts for most of them.

Toolchain and infrastructure:

 - Upgrade to Rust 1.73.0.

   This time around, due to how the kernel and Rust schedules have
   aligned, there are two upgrades in fact. They contain the fixes for
   a few issues we reported to the Rust project.

   In addition, a few cleanups indicated by the upgraded compiler
   or possible thanks to it. For instance, the compiler now detects
   redundant explicit links.

 - A couple changes to the Rust 'Makefile' so that it can be used with
   toybox tools, allowing Rust to be used in the Android kernel build.

x86:

 - Enable IBT if enabled in C.

Documentation:

 - Add "The Rust experiment" section to the Rust index page.

MAINTAINERS

 - Add Maintainer Entry Profile field ('P:').

 - Update our 'W:' field to point to the webpage we have been building
   this year.

rust-fixes-6.6

Toggle rust-fixes-6.6's commit message

Verified

This tag was signed with the committer’s verified signature.
ojeda Miguel Ojeda
Rust fixes for 6.6

 - GCC build: fix bindgen build error with '-fstrict-flex-arrays'.

 - Error module: fix the description for 'ECHILD' and fix Markdown
   style nit.

 - Code docs: fix logo replacement.

 - Docs: update docs output path.

 - Kbuild: remove old docs output path in 'cleandocs' target.

rust-6.6

Toggle rust-6.6's commit message

Verified

This tag was signed with the committer’s verified signature.
ojeda Miguel Ojeda
Rust changes for v6.6

In terms of lines, most changes this time are on the pinned-init API
and infrastructure. While we have a Rust version upgrade, and thus a
bunch of changes from the vendored 'alloc' crate as usual, this time
those do not account for many lines.

Toolchain and infrastructure:

 - Upgrade to Rust 1.71.1. This is the second such upgrade, which is a
   smaller jump compared to the last time.

   This version allows us to remove the '__rust_*' allocator functions
   -- the compiler now generates them as expected, thus now our
   'KernelAllocator' is used.

   It also introduces the 'offset_of!' macro in the standard library
   (as an unstable feature) which we will need soon. So far, we were
   using a declarative macro as a prerequisite in some not-yet-landed
   patch series, which did not support sub-fields (i.e. nested structs):

       #[repr(C)]
       struct S {
           a: u16,
           b: (u8, u8),
       }

       assert_eq!(offset_of!(S, b.1), 3);

 - Upgrade to bindgen 0.65.1. This is the first time we upgrade its
   version.

   Given it is a fairly big jump, it comes with a fair number of
   improvements/changes that affect us, such as a fix needed to support
   LLVM 16 as well as proper support for '__noreturn' C functions, which
   are now mapped to return the '!' type in Rust:

       void __noreturn f(void); // C
       pub fn f() -> !;         // Rust

 - 'scripts/rust_is_available.sh' improvements and fixes.

   This series takes care of all the issues known so far and adds a few
   new checks to cover for even more cases, plus adds some more help
   texts. All this together will hopefully make problematic setups
   easier to identify and to be solved by users building the kernel.

   In addition, it adds a test suite which covers all branches of the
   shell script, as well as tests for the issues found so far.

 - Support rust-analyzer for out-of-tree modules too.

 - Give 'cfg's to rust-analyzer for the 'core' and 'alloc' crates.

 - Drop 'scripts/is_rust_module.sh' since it is not needed anymore.

Macros crate:

 - New 'paste!' proc macro.

   This macro is a more flexible version of 'concat_idents!': it allows
   the resulting identifier to be used to declare new items and it
   allows to transform the identifiers before concatenating them, e.g.

       let x_1 = 42;
       paste!(let [<x _2>] = [<x _1>];);
       assert!(x_1 == x_2);

   The macro is then used for several of the pinned-init API changes in
   this pull.

Pinned-init API:

 - Make '#[pin_data]' compatible with conditional compilation of fields,
   allowing to write code like:

       #[pin_data]
       pub struct Foo {
           #[cfg(CONFIG_BAR)]
           a: Bar,
           #[cfg(not(CONFIG_BAR))]
           a: Baz,
       }

 - New '#[derive(Zeroable)]' proc macro for the 'Zeroable' trait, which
   allows 'unsafe' implementations for structs where every field
   implements the 'Zeroable' trait, e.g.:

       #[derive(Zeroable)]
       pub struct DriverData {
           id: i64,
           buf_ptr: *mut u8,
           len: usize,
       }

 - Add '..Zeroable::zeroed()' syntax to the 'pin_init!'  macro for
   zeroing all other fields, e.g.:

       pin_init!(Buf {
           buf: [1; 64],
           ..Zeroable::zeroed()
       });

 - New '{,pin_}init_array_from_fn()' functions to create array
   initializers given a generator function, e.g.:

       let b: Box<[usize; 1_000]> = Box::init::<Error>(
           init_array_from_fn(|i| i)
       ).unwrap();

       assert_eq!(b.len(), 1_000);
       assert_eq!(b[123], 123);

 - New '{,pin_}chain' methods for '{,Pin}Init<T, E>' that allow to
   execute a closure on the value directly after initialization, e.g.:

       let foo = init!(Foo {
           buf <- init::zeroed()
       }).chain(|foo| {
           foo.setup();
           Ok(())
       });

 - Support arbitrary paths in init macros, instead of just identifiers
   and generic types.

 - Implement the 'Zeroable' trait for the 'UnsafeCell<T>' and
   'Opaque<T>' types.

 - Make initializer values inaccessible after initialization.

 - Make guards in the init macros hygienic.

'allocator' module:

 - Use 'krealloc_aligned()' in 'KernelAllocator::alloc' preventing
   misaligned allocations when the Rust 1.71.1 upgrade is applied later
   in this pull.

   The equivalent fix for the previous compiler version (where
   'KernelAllocator' is not yet used) was merged into 6.5 already,
   which added the 'krealloc_aligned()' function used here.

 - Implement 'KernelAllocator::{realloc, alloc_zeroed}' for performance,
   using 'krealloc_aligned()' too, which forwards the call to the C API.

'types' module:

 - Make 'Opaque' be '!Unpin', removing the need to add a 'PhantomPinned'
   field to Rust structs that contain C structs which must not be moved.

 - Make 'Opaque' use 'UnsafeCell' as the outer type, rather than inner.

Documentation:

 - Suggest obtaining the source code of the Rust's 'core' library using
   the tarball instead of the repository.

MAINTAINERS:

 - Andreas and Alice, from Samsung and Google respectively, are joining
   as reviewers of the "RUST" entry.

As well as a few other minor changes and cleanups.

rust-fixes-6.5-rc7

Toggle rust-fixes-6.5-rc7's commit message

Verified

This tag was signed with the committer’s verified signature.
ojeda Miguel Ojeda
Rust fixes for 6.5-rc7

 - Macros: fix 'HAS_*' redefinition by the '#[vtable]' macro
   under conditional compilation.

rust-fixes-6.5-rc5

Toggle rust-fixes-6.5-rc5's commit message

Verified

This tag was signed with the committer’s verified signature.
ojeda Miguel Ojeda
Rust fixes for 6.5-rc5

 - Allocator: prevent mis-aligned allocation.

 - Types: delete 'ForeignOwnable::borrow_mut'. A sound replacement is
   planned for the merge window.

 - Build: fix bindgen error with UBSAN_BOUNDS_STRICT.

rust-6.5

Toggle rust-6.5's commit message

Verified

This tag was signed with the committer’s verified signature.
ojeda Miguel Ojeda
Rust changes for v6.5

A fairly small one in terms of feature additions. Most of the changes in
terms of lines come from the upgrade to the new version of the toolchain
(which in turn is big due to the vendored 'alloc' crate).

 - Upgrade to Rust 1.68.2:

   This is the first such upgrade, and we will try to update it often
   from now on, in order to remain close to the latest release, until
   a minimum version (which is "in the future") can be established.

   The upgrade brings the stabilization of 4 features we used (and 2
   more that we used in our old 'rust' branch).

   Commit 3ed03f4 ("rust: upgrade to Rust 1.68.2") contains the
   details and rationale.

 - pin-init API:

   Several internal improvements and fixes to the pin-init API, e.g.
   allowing to use 'Self' in a struct definition with '#[pin_data]'.

 - 'error'  module:

   New 'name()' method for the 'Error' type (with 'errname()'
   integration), used to implement the 'Debug' trait for 'Error'.

   Add error codes from 'include/linux/errno.h' to the list of Rust
   'Error' constants.

   Allow specifying error type on the 'Result' type (with the default
   still being our usual 'Error' type).

 - 'str' module:

   'TryFrom' implementation for 'CStr', and new 'to_cstring()' method
   based on it.

 - 'sync' module:

   Implement 'AsRef' trait for 'Arc', allowing to use 'Arc' in code that
   is generic over smart pointer types.

   Add 'ptr_eq' method to 'Arc' for easier, less error prone comparison
   between two 'Arc' pointers.

   Reword the 'Send' safety comment for 'Arc', and avoid referencing it
   from the 'Sync' one.

 - 'task' module:

   Implement 'Send' marker for 'Task'.

 - 'types' module:

   Implement 'Send' and 'Sync' markers for 'ARef<T>' when 'T' is
   'AlwaysRefCounted', 'Send' and 'Sync'.

 - Other changes:

   Documentation improvements and '.gitattributes' change to start
   using the Rust diff driver.