Skip to content
Rust changes for v6.4

More additions to the Rust core. Importantly, this adds the pin-init
API, which will be used by other abstractions, such as the
synchronization ones added here too:

  - pin-init API: a solution for the safe pinned initialization problem.
    This allows to reduce the need for 'unsafe' code in the kernel when
    dealing with data structures that require a stable address. Commit
    90e53c5e70a6 ("rust: add pin-init API core") contains a nice
    introduction -- here is an example of how it looks like:

        #[pin_data]
        struct Example {
            #[pin]
            value: Mutex<u32>,

            #[pin]
            value_changed: CondVar,
        }

        impl Example {
            fn new() -> impl PinInit<Self> {
                pin_init!(Self {
                    value <- new_mutex!(0),
                    value_changed <- new_condvar!(),
                })
            }
        }

        // In a `Box`.
        let b = Box::pin_init(Example::new())?;

        // In the stack.
        stack_pin_init!(let s = Example::new());

  - 'sync' module: new types 'LockClassKey' ('struct lock_class_key'),
    'Lock', 'Guard', 'Mutex' ('struct mutex'), 'SpinLock'
    ('spinlock_t'), 'LockedBy' and 'CondVar' (uses 'wait_queue_head_t'),
    plus macros such as 'static_lock_class!' and 'new_spinlock!'.

    In particular, 'Lock' and 'Guard' are generic implementations that
    contain code that is common to all locks. Then, different backends
    (the new 'Backend' trait) are implemented and used to define types
    like 'Mutex':

        type Mutex<T> = Lock<T, MutexBackend>;

    In addition, new methods 'assume_init()', 'init_with()' and
    'pin_init_with()' for 'UniqueArc<MaybeUninit<T>>' and 'downcast()'
    for 'Arc<dyn Any + Send + Sync>'; as well as 'Debug' and 'Display'
    implementations for 'Arc' and 'UniqueArc'. Reduced stack usage of
    'UniqueArc::try_new_uninit()', too.

  - 'types' module: new trait 'AlwaysRefCounted' and new type 'ARef'
    (an owned reference to an always-reference-counted object, meant to
    be used in wrappers for C types that have their own ref counting
    functions).

    Moreover, new associated functions 'raw_get()' and 'ffi_init()'
    for 'Opaque'.

  - New 'task' module with a new type 'Task' ('struct task_struct'), and
    a new macro 'current!' to safely get a reference to the current one.

  - New 'ioctl' module with new '_IOC*' const functions (equivalent to
    the C macros).

  - New 'uapi' crate, intended to be accessible by drivers directly.

  - 'macros' crate: new 'quote!' macro (similar to the one provided in
    userspace by the 'quote' crate); and the 'module!' macro now allows
    specifying multiple module aliases.

  - 'error' module: new associated functions for the 'Error' type,
    such as 'from_errno()' and new functions such as 'to_result()'.

  - 'alloc' crate: more fallible 'Vec' methods: 'try_resize` and
    'try_extend_from_slice' and the infrastructure (imported from
    the Rust standard library) they need.