Skip to content

Tags: Rust-for-Linux/linux

Tags

rust-6.17

Verified

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

Toolchain and infrastructure:

 - Enable a set of Clippy lints: 'ptr_as_ptr', 'ptr_cast_constness',
   'as_ptr_cast_mut', 'as_underscore', 'cast_lossless' and 'ref_as_ptr'.

   These are intended to avoid type casts with the 'as' operator, which
   are quite powerful, into restricted variants that are less powerful
   and thus should help to avoid mistakes.

 - Remove the 'author' key now that most instances were moved to the
   plural one in the previous cycle.

'kernel' crate:

 - New 'bug' module: add 'warn_on!' macro which reuses the existing
   'BUG'/'WARN' infrastructure, i.e. it respects the usual sysctls and
   kernel parameters:

       warn_on!(value == 42);

   To avoid duplicating the assembly code, the same strategy is followed
   as for the static branch code in order to share the assembly between
   both C and Rust. This required a few rearrangements on C arch headers
   -- the existing C macros should still generate the same outputs, thus
   no functional change expected there.

 - 'workqueue' module: add delayed work items, including a 'DelayedWork'
   struct, a 'impl_has_delayed_work!' macro and an 'enqueue_delayed'
   method, e.g.:

       /// Enqueue the struct for execution on the system workqueue,
       /// where its value will be printed 42 jiffies later.
       fn print_later(value: Arc<MyStruct>) {
           let _ = workqueue::system().enqueue_delayed(value, 42);
       }

 - New 'bits' module: add support for 'bit' and 'genmask' functions,
   with runtime- and compile-time variants, e.g.:

       static_assert!(0b00010000 == bit_u8(4));
       static_assert!(0b00011110 == genmask_u8(1..=4));

       assert!(checked_bit_u32(u32::BITS).is_none());

 - 'uaccess' module: add 'UserSliceReader::strcpy_into_buf', which reads
   NUL-terminated strings from userspace into a '&CStr'.

   Introduce 'UserPtr' newtype, similar in purpose to '__user' in C, to
   minimize mistakes handling userspace pointers, including mixing them
   up with integers and leaking them via the 'Debug' trait. Add it to
   the prelude, too.

 - Start preparations for the replacement of our custom 'CStr' type
   with the analogous type in the 'core' standard library. This will
   take place across several cycles to make it easier. For this one,
   it includes a new 'fmt' module, using upstream method names and some
   other cleanups.

   Replace 'fmt!' with a re-export, which helps Clippy lint properly,
   and clean up the found 'uninlined-format-args' instances.

 - 'dma' module:

   - Clarify wording and be consistent in 'coherent' nomenclature.

   - Convert the 'read!()' and 'write!()' macros to return a 'Result'.

   - Add 'as_slice()', 'write()' methods in 'CoherentAllocation'.

   - Expose 'count()' and 'size()' in 'CoherentAllocation' and add the
     corresponding type invariants.

   - Implement 'CoherentAllocation::dma_handle_with_offset()'.

 - 'time' module:

   - Make 'Instant' generic over clock source. This allows the compiler
     to assert that arithmetic expressions involving the 'Instant' use
     'Instants' based on the same clock source.

   - Make 'HrTimer' generic over the timer mode. 'HrTimer' timers take a
     'Duration' or an 'Instant' when setting the expiry time, depending
     on the timer mode. With this change, the compiler can check the
     type matches the timer mode.

   - Add an abstraction for 'fsleep'. 'fsleep' is a flexible sleep
     function that will select an appropriate sleep method depending on
     the requested sleep time.

   - Avoid 64-bit divisions on 32-bit hardware when calculating
     timestamps.

   - Seal the 'HrTimerMode' trait. This prevents users of the
     'HrTimerMode' from implementing the trait on their own types.

   - Pass the correct timer mode ID to 'hrtimer_start_range_ns()'.

 - 'list' module: remove 'OFFSET' constants, allowing to remove pointer
   arithmetic; now 'impl_list_item!' invokes 'impl_has_list_links!' or
   'impl_has_list_links_self_ptr!'. Other simplifications too.

 - 'types' module: remove 'ForeignOwnable::PointedTo' in favor of a
   constant, which avoids exposing the type of the opaque pointer, and
   require 'into_foreign' to return non-null.

   Remove the 'Either<L, R>' type as well. It is unused, and we want to
   encourage the use of custom enums for concrete use cases.

 - 'sync' module: implement 'Borrow' and 'BorrowMut' for 'Arc' types
   to allow them to be used in generic APIs.

 - 'alloc' module: implement 'Borrow' and 'BorrowMut' for 'Box<T, A>';
    and 'Borrow', 'BorrowMut' and 'Default' for 'Vec<T, A>'.

 - 'Opaque' type: add 'cast_from' method to perform a restricted cast
   that cannot change the inner type and use it in callers of
   'container_of!'. Rename 'raw_get' to 'cast_into' to match it.

 - 'rbtree' module: add 'is_empty' method.

 - 'sync' module: new 'aref' submodule to hold 'AlwaysRefCounted' and
   'ARef', which are moved from the too general 'types' module which we
   want to reduce or eventually remove. Also fix a safety comment in
   'static_lock_class'.

'pin-init' crate:

 - Add 'impl<T, E> [Pin]Init<T, E> for Result<T, E>', so results are now
   (pin-)initializers.

 - Add 'Zeroable::init_zeroed()' that delegates to 'init_zeroed()'.

 - New 'zeroed()', a safe version of 'mem::zeroed()' and also provide
   it via 'Zeroable::zeroed()'.

 - Implement 'Zeroable' for 'Option<&T>', 'Option<&mut T>' and for
   'Option<[unsafe] [extern "abi"] fn(...args...) -> ret>' for '"Rust"'
   and '"C"' ABIs and up to 20 arguments.

 - Changed blanket impls of 'Init' and 'PinInit' from 'impl<T, E>
   [Pin]Init<T, E> for T' to 'impl<T> [Pin]Init<T> for T'.

 - Renamed 'zeroed()' to 'init_zeroed()'.

 - Upstream dev news: improve CI more to deny warnings, use
   '--all-targets'. Check the synchronization status of the two '-next'
   branches in upstream and the kernel.

MAINTAINERS:

 - Add Vlastimil Babka, Liam R. Howlett, Uladzislau Rezki and Lorenzo
   Stoakes as reviewers (thanks everyone).

And a few other cleanups and improvements.

rust-fixes-6.16-2

Verified

This tag was signed with the committer’s verified signature.
ojeda Miguel Ojeda
Rust fixes for v6.16 (2nd)

Toolchain and infrastructure:

 - Fix build and modpost confusion for the upcoming Rust 1.89.0 release.

 - Clean objtool warning for the upcoming Rust 1.89.0 release by adding
   one more noreturn function.

'kernel' crate:

 - Fix build error when using generics in the 'try_{,pin_}init!' macros.

alloc-next-v6.17-2025-07-15

Alloc & DMA changes for v6.17

Box:
  - Implement Borrow / BorrowMut for Box<T, A>.

Vec:
  - Implement Default for Vec<T, A>.

  - Implement Borrow / BorrowMut for Vec<T, A>.

DMA:
  - Clarify wording and be consistent in 'coherent' nomenclature.

  - Convert the read!() / write!() macros to return a Result.

  - Add as_slice() / write() methods in CoherentAllocation.

  - Fix doc-comment of dma_handle().

  - Expose count() and size() in CoherentAllocation and add the
    corresponding type invariants.

  - Implement CoherentAllocation::dma_handle_with_offset().

  - Require mutable reference for as_slice_mut() and write().

- Add Vlastimil Babka, Liam R. Howlett, Uladzislau Rezki and Lorenzo Stoakes
  as reviewers (thanks everyone).

rust-timekeeping-for-v6.17

rust-timekeeping for v6.17

pin-init-v6.17

pin-init changes for v6.17

Added:

- 'impl<T, E> [Pin]Init<T, E> for Result<T, E>', so results are now
  (pin-)initializers.

- 'Zeroable::init_zeroed()' delegating to 'init_zeroed()'.

- New 'zeroed()', a safe version of 'mem::zeroed()' and also provide
  it via 'Zeroable::zeroed()'.

- Implement 'Zeroable' for 'Option<&T>' and 'Option<&mut T>'.

- Implement 'Zeroable' for 'Option<[unsafe] [extern "abi"]
  fn(...args...) -> ret>' for '"Rust"' and '"C"' ABIs and up to 20
  arguments.

Changed:

- Blanket impls of 'Init' and 'PinInit' from 'impl<T, E> [Pin]Init<T, E>
  for T' to 'impl<T> [Pin]Init<T> for T'.

- Renamed 'zeroed()' to 'init_zeroed()'.

Upstream dev news:

- More CI improvements to deny warnings, use '--all-targets'. Also check
  the synchronization status of the two '-next' branches in upstream and
  the kernel.

pin-init-v6.17-result-blanket

pin-init blanket implementation changes for v6.17

Remove the error from the blanket implementations for `[Pin]Init` and
add implementations for `Result`.

rust-fixes-6.16

Verified

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

'kernel' crate:

  - 'hrtimer': fix future compile error when the 'impl_has_hr_timer!'
    macro starts to get called.

v6.16-rc1

Linux 6.16-rc1

rust-6.16

Verified

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

Toolchain and infrastructure:

 - KUnit '#[test]'s:

   - Support KUnit-mapped 'assert!' macros.

     The support that landed last cycle was very basic, and the
     'assert!' macros panicked since they were the standard library
     ones. Now, they are mapped to the KUnit ones in a similar way to
     how is done for doctests, reusing the infrastructure there.

     With this, a failing test like:

         #[test]
         fn my_first_test() {
             assert_eq!(42, 43);
         }

     will report:

         # my_first_test: ASSERTION FAILED at rust/kernel/lib.rs:251
         Expected 42 == 43 to be true, but is false
         # my_first_test.speed: normal
         not ok 1 my_first_test

   - Support tests with checked 'Result' return types.

     The return value of test functions that return a 'Result' will be
     checked, thus one can now easily catch errors when e.g. using the
     '?' operator in tests.

     With this, a failing test like:

         #[test]
         fn my_test() -> Result {
             f()?;
             Ok(())
         }

     will report:

         # my_test: ASSERTION FAILED at rust/kernel/lib.rs:321
         Expected is_test_result_ok(my_test()) to be true, but is false
         # my_test.speed: normal
         not ok 1 my_test

   - Add 'kunit_tests' to the prelude.

 - Clarify the remaining language unstable features in use.

 - Compile 'core' with edition 2024 for Rust >= 1.87.

 - Workaround 'bindgen' issue with forward references to 'enum' types.

 - objtool: relax slice condition to cover more 'noreturn' functions.

 - Use absolute paths in macros referencing 'core' and 'kernel' crates.

 - Skip '-mno-fdpic' flag for bindgen in GCC 32-bit arm builds.

 - Clean some 'doc_markdown' lint hits -- we may enable it later on.

'kernel' crate:

 - 'alloc' module:

   - 'Box': support for type coercion, e.g. 'Box<T>' to 'Box<dyn U>' if
     'T' implements 'U'.

   - 'Vec': implement new methods (prerequisites for nova-core and
     binder): 'truncate', 'resize', 'clear', 'pop',
     'push_within_capacity' (with new error type 'PushError'),
     'drain_all', 'retain', 'remove' (with new error type
     'RemoveError'), insert_within_capacity' (with new error type
     'InsertError').

     In addition, simplify 'push' using 'spare_capacity_mut', split
     'set_len' into 'inc_len' and 'dec_len', add type invariant
     'len <= capacity' and simplify 'truncate' using 'dec_len'.

 - 'time' module:

   - Morph the Rust hrtimer subsystem into the Rust timekeeping
     subsystem, covering delay, sleep, timekeeping, timers. This new
     subsystem has all the relevant timekeeping C maintainers listed in
     the entry.

   - Replace 'Ktime' with 'Delta' and 'Instant' types to represent a
     duration of time and a point in time.

   - Temporarily add 'Ktime' to 'hrtimer' module to allow 'hrtimer' to
     delay converting to 'Instant' and 'Delta'.

 - 'xarray' module:

   - Add a Rust abstraction for the 'xarray' data structure. This
     abstraction allows Rust code to leverage the 'xarray' to store
     types that implement 'ForeignOwnable'. This support is a dependency
     for memory backing feature of the Rust null block driver, which is
     waiting to be merged.

   - Set up an entry in 'MAINTAINERS' for the XArray Rust support.
     Patches will go to the new Rust XArray tree and then via the Rust
     subsystem tree for now.

   - Allow 'ForeignOwnable' to carry information about the pointed-to
     type. This helps asserting alignment requirements for the pointer
     passed to the foreign language.

 - 'container_of!': retain pointer mut-ness and add a compile-time check
   of the type of the first parameter ('$field_ptr').

 - Support optional message in 'static_assert!'.

 - Add C FFI types (e.g. 'c_int') to the prelude.

 - 'str' module: simplify KUnit tests 'format!' macro, convert
   'rusttest' tests into KUnit, take advantage of the '-> Result'
   support in KUnit '#[test]'s.

 - 'list' module: add examples for 'List', fix path of 'assert_pinned!'
   (so far unused macro rule).

 - 'workqueue' module: remove 'HasWork::OFFSET'.

 - 'page' module: add 'inline' attribute.

'macros' crate:

 - 'module' macro: place 'cleanup_module()' in '.exit.text' section.

'pin-init' crate:

 - Add 'Wrapper<T>' trait for creating pin-initializers for wrapper
   structs with a structurally pinned value such as 'UnsafeCell<T>' or
   'MaybeUninit<T>'.

 - Add 'MaybeZeroable' derive macro to try to derive 'Zeroable', but
   not error if not all fields implement it. This is needed to derive
   'Zeroable' for all bindgen-generated structs.

 - Add 'unsafe fn cast_[pin_]init()' functions to unsafely change the
   initialized type of an initializer. These are utilized by the
   'Wrapper<T>' implementations.

 - Add support for visibility in 'Zeroable' derive macro.

 - Add support for 'union's in 'Zeroable' derive macro.

 - Upstream dev news: streamline CI, fix some bugs. Add new workflows
   to check if the user-space version and the one in the kernel tree
   have diverged. Use the issues tab [1] to track them, which should
   help folks report and diagnose issues w.r.t. 'pin-init' better.

     [1] https://github.com/rust-for-linux/pin-init/issues

Documentation:

 - Testing: add docs on the new KUnit '#[test]' tests.

 - Coding guidelines: explain that '///' vs. '//' applies to private
   items too. Add section on C FFI types.

 - Quick Start guide: update Ubuntu instructions and split them into
   "25.04" and "24.04 LTS and older".

And a few other cleanups and improvements.

alloc-next-v6.16-2025-05-13

Alloc changes for v6.16

Box:
  - support for type coercion, e.g. `Box<T>` to `Box<dyn U>` if T
    implements U

Vec:
  - implement new methods (prerequisites for nova-core and binder)
    - Vec::truncate()
    - Vec::resize()
    - Vec::clear()
    - Vec::pop()
    - Vec::push_within_capacity()
      - new error type: PushError
    - Vec::drain_all()
    - Vec::retain()
    - Vec::remove()
      - new error type: RemoveError
    - Vec::insert_within_capacity
      - new error type: InsertError
  - simplify Vec::push() using Vec::spare_capacity_mut()
  - split Vec::set_len() into Vec::inc_len() and Vec::dec_len()
    - add type invariant Vec::len() <= Vec::capacity
    - simplify Vec::truncate() using Vec::dec_len()