Commit Graph
1445 Commits
Author SHA1 Message Date
Daniel Almeida f5e841e496 rust: workqueue: add support for ARef<T>
Add support for the ARef<T> smart pointer. This allows an instance of
ARef<T> to handle deferred work directly, which can be convenient or even
necessary at times, depending on the specifics of the driver or subsystem.

The implementation is similar to that of Arc<T>, and a subsequent patch
will implement support for drm::Device as the first user. This is notably
important for work items that need access to the drm device, as it was not
possible to enqueue work on a ARef<drm::Device<T>> previously without
failing the orphan rule.

Reviewed-by: Alice Ryhl <[email protected]>
Acked-by: Danilo Krummrich <[email protected]>
Signed-off-by: Daniel Almeida <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Alice Ryhl <[email protected]>
2026-03-26 13:08:48 +00:00
Lyude Paul 442ba16a5a rust: gem: Introduce DriverObject::Args
This is an associated type that may be used in order to specify a
data-type to pass to gem objects when constructing them, allowing for
drivers to more easily initialize their private-data for gem objects.

Signed-off-by: Lyude Paul <[email protected]>
Reviewed-by: Alice Ryhl <[email protected]>
Reviewed-by: Daniel Almeida <[email protected]>
Reviewed-by: Janne Grunau <[email protected]>
Tested-by: Deborah Brouwer <[email protected]>
Link: https://patch.msgid.link/[email protected]
[ Resolve merge conflicts in Tyr. - Danilo ]
Signed-off-by: Danilo Krummrich <[email protected]>
2026-03-26 02:08:04 +01:00
Lyude Paul e64b9cc293 rust: drm: Add gem::impl_aref_for_gem_obj!
In the future we're going to be introducing more GEM object types in rust
then just gem::Object<T>. Since all types of GEM objects have refcounting,
let's introduce a macro that we can use in the gem crate in order to copy
this boilerplate implementation for each type: impl_aref_for_gem_obj!().

Signed-off-by: Lyude Paul <[email protected]>
Reviewed-by: Daniel Almeida <[email protected]>
Reviewed-by: Janne Grunau <[email protected]>
Tested-by: Deborah Brouwer <[email protected]>
Link: https://patch.msgid.link/[email protected]
[ Resolve merge conflicts. - Danilo ]
Signed-off-by: Danilo Krummrich <[email protected]>
2026-03-26 02:05:29 +01:00
Timur Tabi 0168185139 rust: dma: implement BinaryWriter for Coherent<[u8]>
Implement the BinaryWriter trait for Coherent<[u8]>, enabling DMA
coherent allocations to be exposed as readable binary files.  The
implementation handles offset tracking and bounds checking, copying data
from the coherent allocation to userspace via write_dma().

Signed-off-by: Timur Tabi <[email protected]>
Reviewed-by: Alice Ryhl <[email protected]>
Reviewed-by: Alexandre Courbot <[email protected]>
Tested-by: John Hubbard <[email protected]>
Tested-by: Eliot Courtney <[email protected]>
Link: https://patch.msgid.link/[email protected]
[ Rebase onto Coherent<T> changes. - Danilo ]
Signed-off-by: Danilo Krummrich <[email protected]>
2026-03-25 01:24:11 +01:00
Timur Tabi 69bfce0f25 rust: uaccess: add write_dma() for copying from DMA buffers to userspace
Add UserSliceWriter::write_dma() to copy data from a Coherent<[u8]> to
userspace. This provides a safe interface for copying DMA buffer
contents to userspace without requiring callers to work with raw
pointers.

Because write_dma() and write_slice() have common code, factor that code
out into a helper function, write_raw().

The method handles bounds checking and offset calculation internally,
wrapping the unsafe copy_to_user() call.

Signed-off-by: Timur Tabi <[email protected]>
Reviewed-by: Alexandre Courbot <[email protected]>
Acked-by: Miguel Ojeda <[email protected]>
Tested-by: John Hubbard <[email protected]>
Tested-by: Eliot Courtney <[email protected]>
Reviewed-by: Alice Ryhl <[email protected]>
Link: https://patch.msgid.link/[email protected]
[ Rebase onto Coherent<T> changes; remove unnecessary turbofish from
  cast(). - Danilo ]
Signed-off-by: Danilo Krummrich <[email protected]>
2026-03-25 01:23:59 +01:00
Timur Tabi d35ae50c5f rust: device: add device name method
Add a name() method to the `Device` type, which returns a CStr that
contains the device name.

Signed-off-by: Timur Tabi <[email protected]>
Reviewed-by: Alice Ryhl <[email protected]>
Reviewed-by: Alexandre Courbot <[email protected]>
Reviewed-by: Gary Guo <[email protected]>
Tested-by: John Hubbard <[email protected]>
Tested-by: Eliot Courtney <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Danilo Krummrich <[email protected]>
2026-03-24 23:51:23 +01:00
Alice Ryhl 8121353a4b rust: regulator: do not assume that regulator_get() returns non-null
The Rust `Regulator` abstraction uses `NonNull` to wrap the underlying
`struct regulator` pointer. When `CONFIG_REGULATOR` is disabled, the C
stub for `regulator_get` returns `NULL`. `from_err_ptr` does not treat
`NULL` as an error, so it was passed to `NonNull::new_unchecked`,
causing undefined behavior.

Fix this by using a raw pointer `*mut bindings::regulator` instead of
`NonNull`. This allows `inner` to be `NULL` when `CONFIG_REGULATOR` is
disabled, and leverages the C stubs which are designed to handle `NULL`
or are no-ops.

Fixes: 9b614ceada ("rust: regulator: add a bare minimum regulator abstraction")
Reported-by: Miguel Ojeda <[email protected]>
Closes: https://lore.kernel.org/r/[email protected]
Signed-off-by: Alice Ryhl <[email protected]>
Reviewed-by: Daniel Almeida <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Mark Brown <[email protected]>
2026-03-24 13:08:21 +00:00
Danilo Krummrich 55fd681cdd rust: dma: remove dma::CoherentAllocation<T>
Now that everything has been converted to the new dma::Coherent<T> API,
remove dma::CoherentAllocation<T>.

Suggested-by: Gary Guo <[email protected]>
Reviewed-by: Gary Guo <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Danilo Krummrich <[email protected]>
2026-03-23 22:36:00 +01:00
Danilo Krummrich 40251bac0e rust: dma: add Coherent:init() and Coherent::init_with_attrs()
Analogous to Coherent::zeroed() and Coherent::zeroed_with_attrs(), add
Coherent:init() and Coherent::init_with_attrs() which both take an impl
Init<T, E> argument initializing the DMA coherent memory.

Compared to CoherentInit, Coherent::init() is a one-shot constructor
that runs an Init closure and immediately exposes the DMA handle,
whereas CoherentInit is a multi-stage initializer that provides safe
&mut T access by withholding the DMA address until converted to
Coherent.

Reviewed-by: Gary Guo <[email protected]>
Reviewed-by: Alexandre Courbot <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Danilo Krummrich <[email protected]>
2026-03-23 22:36:00 +01:00
Danilo Krummrich 80f4a7b513 rust: dma: introduce dma::CoherentBox for memory initialization
Currently, dma::Coherent cannot safely provide (mutable) access to its
underlying memory because the memory might be concurrently accessed by a
DMA device. This makes it difficult to safely initialize the memory
before handing it over to the hardware.

Introduce dma::CoherentBox, a type that encapsulates a dma::Coherent
before its DMA address is exposed to the device. dma::CoherentBox can
guarantee exclusive access to the inner dma::Coherent and implement
Deref and DerefMut.

Once the memory is properly initialized, dma::CoherentBox can be
converted into a regular dma::Coherent.

Reviewed-by: Alice Ryhl <[email protected]>
Reviewed-by: Gary Guo <[email protected]>
Reviewed-by: Alexandre Courbot <[email protected]>
Link: https://patch.msgid.link/[email protected]
[ Remove unnecessary trait bounds. - Danilo ]
Signed-off-by: Danilo Krummrich <[email protected]>
2026-03-23 22:35:38 +01:00
Gary Guo f84ecffa3f rust: dma: add zeroed constructor to Coherent
These constructors create a coherent container of a single object
instead of slice. They are named `zeroed` and `zeroed_with_attrs` to
emphasis that they are created initialized zeroed. It is intended that
there'll be new constructors that take `PinInit` instead of zeroing.

Signed-off-by: Gary Guo <[email protected]>
Reviewed-by: Alice Ryhl <[email protected]>
Reviewed-by: Alexandre Courbot <[email protected]>
Link: https://patch.msgid.link/[email protected]
[ Use kernel import style. - Danilo ]
Signed-off-by: Danilo Krummrich <[email protected]>
2026-03-23 22:33:23 +01:00
Gary Guo d9aee73c56 rust: dma: add generalized container for types other than slices
Currently, `CoherentAllocation` is concecptually a DMA coherent container
of a slice of `[T]` of runtime-checked length. Generalize it by creating
`dma::Coherent<T>` which can hold any value of `T`.
`Coherent::alloc_with_attrs` is implemented but not yet exposed, as I
believe we should not expose the way to obtain an uninitialized coherent
region.

`Coherent<[T]>` provides a `len` method instead of the previous `count()`
method to be consistent with methods on slices.

The existing type is re-defined as a type alias of `Coherent<[T]>` to ease
transition. Methods in use are not yet removed.

Signed-off-by: Gary Guo <[email protected]>
Reviewed-by: Alice Ryhl <[email protected]>
Reviewed-by: Alexandre Courbot <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Danilo Krummrich <[email protected]>
2026-03-23 22:15:03 +01:00
Danilo Krummrich 7ea1a61129 rust: dma: use "kernel vertical" style for imports
Convert all imports to use "kernel vertical" style.

With this, subsequent patches neither introduce unrelated changes nor
leave an inconsistent import pattern.

While at it, drop unnecessary imports covered by prelude::*.

Link: https://docs.kernel.org/rust/coding-guidelines.html#imports
Reviewed-by: Gary Guo <[email protected]>
Reviewed-by: Alexandre Courbot <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Danilo Krummrich <[email protected]>
2026-03-23 22:15:03 +01:00
Joel Fernandes b9616d9721 rust: gpu: Add GPU buddy allocator bindings
Add safe Rust abstractions over the Linux kernel's GPU buddy
allocator for physical memory management. The GPU buddy allocator
implements a binary buddy system useful for GPU physical memory
allocation. nova-core will use it for physical memory allocation.

Cc: Nikola Djukic <[email protected]>
Signed-off-by: Joel Fernandes <[email protected]>
Reviewed-by: Alexandre Courbot <[email protected]>
Link: https://patch.msgid.link/[email protected]
[ * Use doc-comments for GpuBuddyAllocMode methods and GpuBuddyGuard,
  * Fix comma splice in GpuBuddyParams::chunk_size doc-comment,
  * Remove redundant summary in GpuBuddy::new doc-comment,
  * Drop Rust helper for gpu_buddy_block_size().

    - Danilo ]
Signed-off-by: Danilo Krummrich <[email protected]>
2026-03-23 21:41:47 +01:00
Joel Fernandes f9f0b4a1f3 rust: interop: Add list module for C linked list interface
Add a new module `kernel::interop::list` for working with C's doubly
circular linked lists. Provide low-level iteration over list nodes.

Typed iteration over actual items is provided with a `clist_create`
macro to assist in creation of the `CList` type.

Cc: Nikola Djukic <[email protected]>
Reviewed-by: Daniel Almeida <[email protected]>
Reviewed-by: Alexandre Courbot <[email protected]>
Reviewed-by: Alice Ryhl <[email protected]>
Acked-by: Alexandre Courbot <[email protected]>
Acked-by: Gary Guo <[email protected]>
Acked-by: Miguel Ojeda <[email protected]>
Signed-off-by: Joel Fernandes <[email protected]>
Link: https://patch.msgid.link/[email protected]
[ * Remove stray empty comment and double blank line in doctest,
  * Improve wording and fix a few typos,
  * Use markdown emphasis instead of caps,
  * Move interop/mod.rs to interop.rs.

    - Danilo ]
Signed-off-by: Danilo Krummrich <[email protected]>
2026-03-23 20:29:28 +01:00
Andreas Hindborg ddb1444d33 hrtimer: add usage examples to documentation
Add documentation examples showing various ways to use hrtimers:

- Box-allocated timers with shared state in Arc.
- Arc-allocated timers.
- Stack-based timers for scoped usage.
- Mutable stack-based timers with shared state.

Tested-by: Daniel Almeida <[email protected]>
Reviewed-by: Daniel Almeida <[email protected]>
Reviewed-by: Alice Ryhl <[email protected]>
Link: https://msgid.link/[email protected]
Signed-off-by: Andreas Hindborg <[email protected]>
2026-03-23 08:31:00 +01:00
FUJITA Tomonori 67b598db7e rust: time: make ClockSource unsafe trait
Mark the ClockSource trait as unsafe and document its safety
requirements. Specifically, implementers must guarantee that their
`ktime_get()` implementation returns a value in the inclusive range
[0, KTIME_MAX].

Update all existing implementations to use `unsafe impl` with
corresponding safety comments.

Note that there could be potential users of a customized clock source [1]
so we don't seal the trait.

Link: https://lore.kernel.org/rust-for-linux/Z9xb1r1x5tOzAIZT@boqun-archlinux/ [1]
Suggested-by: Boqun Feng <[email protected]>
Signed-off-by: FUJITA Tomonori <[email protected]>
Reviewed-by: Alice Ryhl <[email protected]>
Link: https://msgid.link/[email protected]
[ Change range expressions in docs. - Andreas ]
Signed-off-by: Andreas Hindborg <[email protected]>
2026-03-23 08:29:48 +01:00
Lyude Paul c51866f65b rust/time: Add Delta::from_nanos()
Since rvkms is going to need to create its own Delta instances, and we
already have functions for creating Delta with every other unit of time.

Signed-off-by: Lyude Paul <[email protected]>
Reviewed-by: Alice Ryhl <[email protected]>
Link: https://msgid.link/[email protected]
Signed-off-by: Andreas Hindborg <[email protected]>
2026-03-23 08:29:48 +01:00
Nakamura Shuta bf074eb689 rust: str: improve safety comment for CString::try_from_fmt
Improve the safety comment for the `inc_len()` call in
`CString::try_from_fmt()` to clarify why `bytes_written()` is
guaranteed not to exceed the buffer capacity.

The current comment states that bytes written is bounded by size,
but does not explain that this invariant is maintained because:
1. The `Formatter` is created with `size` as its capacity limit
2. The `?` operators on `write_fmt` and `write_str` ensure early
   return if writing exceeds this limit

Suggested-by: Gary Guo <[email protected]>
Link: https://lore.kernel.org/rust-for-linux/20221114145329.0f47a3ab@GaryWorkstation/
Link: https://github.com/Rust-for-Linux/linux/issues/936
Signed-off-by: Nakamura Shuta <[email protected]>
Reviewed-by: Alice Ryhl <[email protected]>
Link: https://patch.msgid.link/[email protected]
[ Updated tags: it was a suggestion from Gary from the mailing list
  (the linked issue is mostly about adding a `debug_assert_eq!`).
    - Miguel ]
Signed-off-by: Miguel Ojeda <[email protected]>
2026-03-23 00:08:55 +01:00
Danilo Krummrich 9aa64d2503 rust: devres: embed struct devres_node directly
Currently, the Devres<T> container uses devm_add_action() to register a
devres callback.

devm_add_action() allocates a struct action_devres, which on top of
struct devres_node, just keeps a data pointer and release function
pointer.

This is an unnecessary indirection, given that analogous to struct
devres, the Devres<T> container can just embed a struct devres_node
directly without an additional allocation.

In contrast to struct devres, we don't need to force an alignment of
ARCH_DMA_MINALIGN (as struct devres does to account for the worst case)
since we have generics in Rust. I.e. the compiler already ensures
correct alignment of the embedded T in Devres<T>.

Thus, get rid of devm_add_action() and instead embed a struct
devres_node directly.

Reviewed-by: Alice Ryhl <[email protected]>
Acked-by: Greg Kroah-Hartman <[email protected]>
Link: https://patch.msgid.link/[email protected]
[ * Improve comment about core::any::type_name(),
  * add #[must_use] to devres_node_remove(),
  * use container_of!() in devres_node_free_node().

    - Danilo ]
Signed-off-by: Danilo Krummrich <[email protected]>
2026-03-18 00:47:14 +01:00
Danilo Krummrich d19ab42867 Merge tag 'rust_io-7.1-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core into drm-rust-next
Register abstraction and I/O infrastructure improvements

Introduce the register!() macro to define type-safe I/O register
accesses. Refactor the IoCapable trait into a functional trait, which
simplifies I/O backends and removes the need for overloaded Io methods.

This is a stable tag for other trees to merge.

Signed-off-by: Danilo Krummrich <[email protected]>
2026-03-17 20:13:16 +01:00
Danilo Krummrich de25dc008e Merge tag 'rust_io-7.1-rc1' into driver-core-next
Register abstraction and I/O infrastructure improvements

Introduce the register!() macro to define type-safe I/O register
accesses. Refactor the IoCapable trait into a functional trait, which
simplifies I/O backends and removes the need for overloaded Io methods.

This is a stable tag for other trees to merge.

Signed-off-by: Danilo Krummrich <[email protected]>
2026-03-17 20:12:36 +01:00
Alexandre Courbot 9a52a8f5ed rust: io: introduce write_reg and LocatedRegister
Some I/O types, like fixed address registers, carry their location
alongside their values. For these types, the regular `Io::write` method
can lead into repeating the location information twice: once to provide
the location itself, another time to build the value.

We are also considering supporting making all register values carry
their full location information for convenience and safety.

Add a new `Io::write_reg` method that takes a single argument
implementing `LocatedRegister`, a trait that decomposes implementors
into a `(location, value)` tuple. This allows write operations on fixed
offset registers to be done while specifying their name only once.

Suggested-by: Danilo Krummrich <[email protected]>
Link: https://lore.kernel.org/all/[email protected]/
Signed-off-by: Alexandre Courbot <[email protected]>
Link: https://patch.msgid.link/[email protected]
[ Replace FIFO with VERSION register in the examples. - Danilo ]
Signed-off-by: Danilo Krummrich <[email protected]>
2026-03-17 20:04:11 +01:00
Alexandre Courbot 20ba6a1dbc rust: io: add register! macro
Add a macro for defining hardware register types with I/O accessors.

Each register field is represented as a `Bounded` of the appropriate bit
width, ensuring field values are never silently truncated.

Fields can optionally be converted to/from custom types, either fallibly
or infallibly.

The address of registers can be direct, relative, or indexed, supporting
most of the patterns in which registers are arranged.

Suggested-by: Danilo Krummrich <[email protected]>
Link: https://lore.kernel.org/all/[email protected]/
Co-developed-by: Gary Guo <[email protected]>
Signed-off-by: Gary Guo <[email protected]>
Signed-off-by: Alexandre Courbot <[email protected]>
Link: https://patch.msgid.link/[email protected]
[ * Improve wording and formatting of doc-comments,
  * Import build_assert!(),
  * Add missing inline annotations,
  * Call static_assert!() with absolute path,
  * Use expect instead of allow.

    - Danilo ]
Signed-off-by: Danilo Krummrich <[email protected]>
2026-03-17 20:04:11 +01:00
Alexandre Courbot 147b41ba23 rust: io: use generic read/write accessors for primitive accesses
By providing the required `IoLoc` implementations on `usize`, we can
leverage the generic accessors and reduce the number of unsafe blocks in
the module.

This also allows us to directly call the generic `read/write/update`
methods with primitive types, so add examples illustrating this.

Signed-off-by: Alexandre Courbot <[email protected]>
Reviewed-by: Gary Guo <[email protected]>
Link: https://patch.msgid.link/[email protected]
[ Slightly improve wording in doc-comment. - Danilo ]
Signed-off-by: Danilo Krummrich <[email protected]>
2026-03-17 20:04:11 +01:00
Alexandre Courbot 498823541b rust: io: add IoLoc type and generic I/O accessors
I/O accesses are defined by the following properties:

- An I/O location, which consists of a start address, a width, and a
  type to interpret the read value as,
- A value, which is returned for reads or provided for writes.

Introduce the `IoLoc` trait, which allows implementing types to fully
specify an I/O location.

This allows I/O operations to be made generic through the new `read` and
`write` methods.

This design will allow us to factorize the I/O code working with
primitives, and to introduce ways to perform I/O with a higher degree of
control through register types.

Co-developed-by: Gary Guo <[email protected]>
Signed-off-by: Gary Guo <[email protected]>
Signed-off-by: Alexandre Courbot <[email protected]>
Link: https://patch.msgid.link/[email protected]
[ Fix incorrect reference to io_addr_assert() in try_update(). - Danilo ]
Signed-off-by: Danilo Krummrich <[email protected]>
2026-03-17 20:04:11 +01:00
Alexandre Courbot 7836ec76ec rust: num: make Bounded::get const
There is a need to access the inner value of a `Bounded` in const
context, notably for bitfields and registers. Remove the invariant check
of `Bounded::get`, which allows us to make it const.

Reviewed-by: Gary Guo <[email protected]>
Signed-off-by: Alexandre Courbot <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Danilo Krummrich <[email protected]>
2026-03-17 20:04:11 +01:00
Alexandre Courbot 164f8634bf rust: num: add into_bool method to Bounded
Single-bit numbers are typically treated as booleans. There is an
`Into<bool>` implementation for those, but invoking it from contexts
that lack type expectations is not always convenient.

Add an `into_bool` method as a simpler shortcut.

Reviewed-by: Alice Ryhl <[email protected]>
Reviewed-by: Gary Guo <[email protected]>
Reviewed-by: Daniel Almeida <[email protected]>
Reviewed-by: Yury Norov <[email protected]>
Tested-by: Dirk Behme <[email protected]>
Acked-by: Miguel Ojeda <[email protected]>
Signed-off-by: Alexandre Courbot <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Danilo Krummrich <[email protected]>
2026-03-17 20:04:11 +01:00
Alexandre Courbot c59a2d14cd rust: num: add shr and shl methods to Bounded
Shifting a `Bounded` left or right changes the number of bits required
to represent the value. Add methods that perform the shift and return a
`Bounded` with the appropriately adjusted bit width.

These methods are particularly useful for bitfield extraction.

Suggested-by: Alice Ryhl <[email protected]>
Reviewed-by: Alice Ryhl <[email protected]>
Reviewed-by: Gary Guo <[email protected]>
Reviewed-by: Daniel Almeida <[email protected]>
Tested-by: Dirk Behme <[email protected]>
Acked-by: Miguel Ojeda <[email protected]>
Acked-by: Yury Norov <[email protected]>
Signed-off-by: Alexandre Courbot <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Danilo Krummrich <[email protected]>
2026-03-17 20:04:11 +01:00
Alexandre Courbot 3cc319d5f4 rust: enable the generic_arg_infer feature
This feature is stable since 1.89, and used in subsequent patches.

Reviewed-by: Gary Guo <[email protected]>
Tested-by: Dirk Behme <[email protected]>
Acked-by: Miguel Ojeda <[email protected]>
Signed-off-by: Alexandre Courbot <[email protected]>
Link: https://patch.msgid.link/[email protected]
[ Resolve merge conflict. - Danilo ]
Signed-off-by: Danilo Krummrich <[email protected]>
2026-03-17 20:03:45 +01:00
Alexandre Courbot 6291ee23da rust: io: remove overloaded Io methods of Mmio
Since `Mmio` now has the relevant implementations of `IoCapable`, the
default methods of `Io` can be used in place of the overloaded ones.
Remove them as well as the macros generating them.

Reviewed-by: Daniel Almeida <[email protected]>
Acked-by: Alice Ryhl <[email protected]>
Signed-off-by: Alexandre Courbot <[email protected]>
Reviewed-by: Gary Guo <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Danilo Krummrich <[email protected]>
2026-03-17 20:02:10 +01:00
Alexandre Courbot 50aad5510f rust: pci: io: remove overloaded Io methods of ConfigSpace
Since `ConfigSpace` now has the relevant implementations of `IoCapable`,
the default methods of `Io` can be used in place of the overloaded ones.
Remove them as well as the macros generating them.

Reviewed-by: Daniel Almeida <[email protected]>
Acked-by: Alice Ryhl <[email protected]>
Signed-off-by: Alexandre Courbot <[email protected]>
Reviewed-by: Gary Guo <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Danilo Krummrich <[email protected]>
2026-03-17 20:02:09 +01:00
Alexandre Courbot e385eb0d1c rust: io: remove legacy relaxed accessors of Mmio
The relaxed access functionality is now provided by the `RelaxedMmio`
wrapper type, and we don't have any user of the legacy methods left.
Remove them.

Reviewed-by: Daniel Almeida <[email protected]>
Acked-by: Alice Ryhl <[email protected]>
Signed-off-by: Alexandre Courbot <[email protected]>
Reviewed-by: Gary Guo <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Danilo Krummrich <[email protected]>
2026-03-17 20:02:09 +01:00
Alexandre Courbot 1d1c5c73d7 rust: io: provide Mmio relaxed ops through a wrapper type
Relaxed I/O accessors for `Mmio` are currently implemented as an extra
set of methods that mirror the ones defined in `Io`, but with the
`_relaxed` suffix.

This makes these methods impossible to use with generic code, which is a
highly plausible proposition now that we have the `Io` trait.

Address this by adding a new `RelaxedMmio` wrapper type for `Mmio` that
provides its own `IoCapable` implementations relying on the relaxed C
accessors. This makes it possible to use relaxed operations on a `Mmio`
simply by wrapping it, and to use `RelaxedMmio` in code generic against
`Io`.

Acked-by: Alice Ryhl <[email protected]>
Signed-off-by: Alexandre Courbot <[email protected]>
Reviewed-by: Daniel Almeida <[email protected]>
Reviewed-by: Gary Guo <[email protected]>
Link: https://patch.msgid.link/[email protected]
[ Use kernel import style in examples. - Danilo ]
Signed-off-by: Danilo Krummrich <[email protected]>
2026-03-17 20:02:09 +01:00
Alexandre Courbot 19103d4f93 rust: io: mem: use non-relaxed I/O ops in examples
The `_relaxed` I/O variant methods are about to be replaced by a wrapper
type exposing this access pattern with the regular methods of the `Io`
trait. Thus replace the examples to use the regular I/O methods.

Since these are examples, we want them to use the most standard ops
anyway, and the relaxed variants were but an addition that was
MMIO-specific.

Reviewed-by: Daniel Almeida <[email protected]>
Acked-by: Alice Ryhl <[email protected]>
Signed-off-by: Alexandre Courbot <[email protected]>
Reviewed-by: Gary Guo <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Danilo Krummrich <[email protected]>
2026-03-17 20:02:09 +01:00
Alexandre Courbot e2d599021c rust: io: turn IoCapable into a functional trait
`IoCapable<T>` is currently used as a marker trait to signal that the
methods of the `Io` trait corresponding to `T` have been overridden by
the implementor (the default implementations triggering a build-time
error).

This goes against the DRY principle and separates the signaling of the
capability from its implementation, making it possible to forget a step
while implementing a new `Io`.

Another undesirable side-effect is that it makes the implementation of
I/O backends boilerplate-y and convoluted: currently this is done using
two levels of imbricated macros that generate unsafe code.

Fix these issues by turning `IoCapable` into a functional trait that
includes the raw implementation of the I/O access for `T` using
unsafe methods that work with an arbitrary address.

This allows us to turn the default methods of `Io` into regular methods
that check the passed offset, turn it into an address, and call into the
corresponding `IoCapable` functions, removing the need to overload them
at all.

`IoCapable` must still be implemented for all supported primitive types,
which is still done more concisely using a macro, but this macro becomes
much simpler and does not require calling into another one.

Reviewed-by: Daniel Almeida <[email protected]>
Acked-by: Alice Ryhl <[email protected]>
Signed-off-by: Alexandre Courbot <[email protected]>
Reviewed-by: Gary Guo <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Danilo Krummrich <[email protected]>
2026-03-17 20:02:09 +01:00
Greg Kroah-Hartman 3812943e01 Merge 7.0-rc4 into char-misc-next
We need the char/misc/iio fixes in this branch as well to build on top
of.

Signed-off-by: Greg Kroah-Hartman <[email protected]>
2026-03-16 11:41:58 +01:00
Danilo Krummrich 76bce7ac51 Merge tag 'v7.0-rc4' into drm-rust-next
We need the latest fixes from drm-rust-fixes in drm-rust-next as well to
build on top of.

Signed-off-by: Danilo Krummrich <[email protected]>
2026-03-15 22:58:48 +01:00
Shankari Anand 79e25710e7 rust: types: remove temporary re-exports of ARef and AlwaysRefCounted
Remove the temporary re-exports of `ARef` and `AlwaysRefCounted`
from `types.rs` now that all in-tree users have been updated to
import them directly from `sync::aref`.

These re-exports were originally added to avoid breaking the
kernel build during the transition period while call sites were
incrementally migrated. With all users updated, they are no
longer needed.

Suggested-by: Benno Lossin <[email protected]>
Link: https://github.com/Rust-for-Linux/linux/issues/1173
Signed-off-by: Shankari Anand <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Miguel Ojeda <[email protected]>
2026-03-15 20:30:29 +01:00
Shankari Anand ebbed9d02e rust: usb: Update AlwaysRefCounted imports to use sync::aref
Update call sites in `usb.rs` to import `AlwaysRefCounted`
from `sync::aref` instead of `types`.

This aligns with the ongoing effort to move `ARef` and
`AlwaysRefCounted` to sync.

Suggested-by: Benno Lossin <[email protected]>
Link: https://github.com/Rust-for-Linux/linux/issues/1173
Signed-off-by: Shankari Anand <[email protected]>
Link: https://patch.msgid.link/[email protected]
[ Rebase. - Miguel ]
Signed-off-by: Miguel Ojeda <[email protected]>
2026-03-15 20:30:29 +01:00
Shankari Anand dfce283387 rust: i2c: Update ARef and AlwaysRefCounted imports to use sync::aref
Update call sites in `i2c.rs` to import `ARef` and
`AlwaysRefCounted` from `sync::aref` instead of `types`.

This aligns with the ongoing effort to move `ARef` and
`AlwaysRefCounted` to sync.

Suggested-by: Benno Lossin <[email protected]>
Link: https://github.com/Rust-for-Linux/linux/issues/1173
Signed-off-by: Shankari Anand <[email protected]>
Acked-by: Igor Korotin <[email protected]>
Link: https://patch.msgid.link/[email protected]
[ Move `ARef` import into the `kernel` `use` tree above. - Miguel ]
Signed-off-by: Miguel Ojeda <[email protected]>
2026-03-15 20:30:29 +01:00
Tamir Duberstein 1353b8f32c rust: str: update c_str! documentation
Now that all literals are C-Strings, update the documentation to explain
that use of this macro should be limited to non-literal strings.

Link: https://github.com/Rust-for-Linux/linux/issues/1075
Acked-by: Greg Kroah-Hartman <[email protected]>
Reviewed-by: Alice Ryhl <[email protected]>
Signed-off-by: Tamir Duberstein <[email protected]>
Reviewed-by: Gary Guo <[email protected]>
Link: https://patch.msgid.link/[email protected]
[ Apply sentence case to comment. Reword title. - Miguel ]
Signed-off-by: Miguel Ojeda <[email protected]>
2026-03-15 20:28:45 +01:00
Linus Torvalds 267594792a Merge tag 'rust-fixes-7.0-2' of git://git.kernel.org/pub/scm/linux/kernel/git/ojeda/linux
Pull Rust fixes from Miguel Ojeda:
 "Toolchain and infrastructure:

   - Remap paths to avoid absolute ones starting with the upcoming Rust
     1.95.0 release. This improves build reproducibility, avoids leaking
     the exact path and avoids having the same path appear in two forms

     The approach here avoids remapping debug information as well, in
     order to avoid breaking tools that used the paths to access source
     files, which was the previous attempt that needed to be reverted

   - Allow 'unused_features' lint for the upcoming Rust 1.96.0 release.
     While well-intentioned, we do not benefit much from the new lint

   - Emit dependency information into '$(depfile)' directly to avoid a
     temporary '.d' file (it was an old approach)

  'kernel' crate:

   - 'str' module: fix warning under '!CONFIG_BLOCK' by making
     'NullTerminatedFormatter' public

   - 'cpufreq' module: suppress false positive Clippy warning

  'pin-init' crate:

   - Remove '#[disable_initialized_field_access]' attribute which was
     unsound. This means removing the support for structs with unaligned
     fields (through the 'repr(packed)' attribute), for now

     And document the load-bearing fact of field accessors (i.e. that
     they are required for soundness)

   - Replace shadowed return token by 'unsafe'-to-create token in order
     to remain sound in the face of the likely upcoming Type Alias Impl
     Trait (TAIT) and the next trait solver in upstream Rust"

* tag 'rust-fixes-7.0-2' of git://git.kernel.org/pub/scm/linux/kernel/git/ojeda/linux:
  rust: kbuild: allow `unused_features`
  rust: cpufreq: suppress clippy::double_parens in Policy doctest
  rust: pin-init: replace shadowed return token by `unsafe`-to-create token
  rust: pin-init: internal: init: document load-bearing fact of field accessors
  rust: pin-init: internal: init: remove `#[disable_initialized_field_access]`
  rust: build: remap path to avoid absolute path
  rust: kbuild: emit dep-info into $(depfile) directly
  rust: str: make NullTerminatedFormatter public
2026-03-14 12:35:16 -07:00
Dave Airlie b28913e897 Merge tag 'drm-rust-fixes-2026-03-12' of https://gitlab.freedesktop.org/drm/rust/kernel into drm-fixes
Core Changes:

- Fix safety issue in dma_read! and dma_write!.

Driver Changes (Nova Core):

- Fix UB in DmaGspMem pointer accessors.
- Fix stack overflow in GSP memory allocation.

Signed-off-by: Dave Airlie <[email protected]>

From: Alice Ryhl <[email protected]>
Link: https://patch.msgid.link/[email protected]
2026-03-13 10:40:17 +10:00
John Hubbard 487f9b3dc6 rust: cpufreq: suppress clippy::double_parens in Policy doctest
The kernel fmt! proc macro wraps each format argument as &(arg). Passing a
tuple such as (a, b) produces &((a, b)) after expansion. Clippy flags that
as double_parens, but it is a false positive fixed in Clippy 1.92 [1] [2].

Suppress the warning on the affected doctest function with a reason
attribute so it can be removed once the minimum toolchain moves past 1.92.

[ We may end up deciding to support per-version Clippy lints, in which
  case we will need [3].

  In the future, if [4] gets fixed, we may be able to use
  `Delimiter::None` as Gary suggested in [5].

  Link: https://lore.kernel.org/rust-for-linux/[email protected]/ [3]
  Link: https://github.com/rust-lang/rust/issues/67062 [4]
  Link: https://lore.kernel.org/rust-for-linux/[email protected]/ [5]

    - Miguel ]

Link: https://github.com/rust-lang/rust-clippy/issues/15852 [1]
Link: https://github.com/rust-lang/rust-clippy/pull/15939 [2]
Suggested-by: Gary Guo <[email protected]>
Signed-off-by: John Hubbard <[email protected]>
Acked-by: Viresh Kumar <[email protected]>
Link: https://patch.msgid.link/[email protected]
[ Reworded to replace GitHub-like short link with full URLs in Link tags.
  Reworded reason string to match the style of a couple others we have
  elsewhere. - Miguel ]
Signed-off-by: Miguel Ojeda <[email protected]>
2026-03-12 11:01:23 +01:00
Gary Guo b3d161f22b rust: disallow use of CStr::as_ptr and CStr::from_ptr
As kernel always use unsigned char and not the platform ABI's default, an
user should always use `as_char_ptr` provided via `CStrExt` instead.
Therefore configure `disallow-methods` feature of clippy to catch incorrect
usage.

Similarly, the dual `from_ptr` is also disallowed.

[ As an example, without the previous commit, we would get a warning like:

      warning: use of a disallowed method `core::ffi::CStr::as_ptr`
         --> rust/kernel/task.rs:422:54
          |
      422 |         unsafe { crate::bindings::__might_sleep(file.as_ptr().cast(), loc.line() as i32) }
          |                                                      ^^^^^^ help: kernel's `char` is always unsigned, use `as_char_ptr` instead: `kernel::prelude::CStrExt::as_char_ptr`
          |
          = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.94.0/index.html#disallowed_methods
          = note: `-W clippy::disallowed-methods` implied by `-W clippy::all`
          = help: to override `-W clippy::all` add `#[allow(clippy::disallowed_methods)]`

    - Miguel ]

Signed-off-by: Gary Guo <[email protected]>
Reviewed-by: Tamir Duberstein <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Miguel Ojeda <[email protected]>
2026-03-11 00:33:40 +01:00
Gary Guo 1a933719e7 rust: task: use as_char_ptr instead of as_ptr().cast()
`as_char_ptr` would provide the correct (unsigned char) type without
needing to convert to an intermediate type and cast the pointer.

The `as_ptr()` function is going to be disallowed by clippy warning, so fix
this usage.

This is used only if CONFIG_DEBUG_ATOMIC_SLEEP=y. Instead of conditionally
importing `CStrExt`, import it via prelude instead, and remove other
imports that are already available via the prelude.

Reported-by: kernel test robot <[email protected]>
Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
Signed-off-by: Gary Guo <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Miguel Ojeda <[email protected]>
2026-03-10 23:52:21 +01:00
Eliot Courtney 59f237a0d1 rust: add EMSGSIZE error code
Add the EMSGSIZE error code, which indicates that a message is too
long.

Tested-by: Zhi Wang <[email protected]>
Acked-by: Miguel Ojeda <[email protected]>
Reviewed-by: Gary Guo <[email protected]>
Signed-off-by: Eliot Courtney <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Alexandre Courbot <[email protected]>
2026-03-10 16:07:33 +09:00
Danilo Krummrich 9900002f7a Merge tag 'v7.0-rc3' into driver-core-next
We need the driver-core fixes in here as well to build on top of.

Signed-off-by: Danilo Krummrich <[email protected]>
2026-03-09 12:08:45 +01:00
Andreas Hindborg b91d5d4bcf rust: atomic: Update a safety comment in impl of fetch_add()
The safety comment used in the implementation of `fetch_add()` could be
read as just saying something it is true without justifying it. Update
the safety comment to include justification.

Suggested-by: Miguel Ojeda <[email protected]>
Signed-off-by: Andreas Hindborg <[email protected]>
Signed-off-by: Boqun Feng <[email protected]>
Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Reviewed-by: Alice Ryhl <[email protected]>
Link: https://patch.msgid.link/[email protected]
Link: https://patch.msgid.link/[email protected]
2026-03-08 11:06:51 +01:00