7 Commits
Author SHA1 Message Date
Danilo Krummrich 445ac1c805 rust: types: implement ForeignOwnable for ARef<T>
Implement ForeignOwnable for ARef<T>, making it possible for C code to
own an ARef<T>.

Since ARef represents shared ownership, BorrowedMut is &T rather than
&mut T, matching the semantics of the underlying reference-counted type.

Signed-off-by: Danilo Krummrich <[email protected]>
Reviewed-by: Alice Ryhl <[email protected]>
Tested-by: Daniel Almeida <[email protected]>
Signed-off-by: Philipp Stanner <[email protected]>
Acked-by: Danilo Krummrich <[email protected]>
Link: https://patch.msgid.link/[email protected]
[ Relaxed `'static` bound and added `#[inline]` as discussed. Added
  the submitter's Signed-off-by tag. - Miguel ]
Signed-off-by: Miguel Ojeda <[email protected]>
2026-08-10 07:58:27 +02:00
Andreas Hindborg 8e86830d62 rust: aref: use the "kernel vertical" imports style
Convert the imports to use the "kernel vertical" imports style [1].

No functional changes intended.

Link: https://docs.kernel.org/rust/coding-guidelines.html#imports [1]
Signed-off-by: Andreas Hindborg <[email protected]>
Link: https://patch.msgid.link/[email protected]
[ Picked from larger series and reworded. - Miguel ]
Signed-off-by: Miguel Ojeda <[email protected]>
2026-06-10 09:07:13 +02:00
Alice Ryhl 18e9fafb26 rust: sync: implement == operator for ARef
Rust Binder wants to perform a comparison between ARef<Task> and &Task,
so define the == operator for ARef<_> when compared with another ARef<_>
or just a reference. The operator is implemented in terms of the same
operator applied to the inner type.

Note that PartialEq<U> cannot be implemented because it would overlap
with the impl for ARef<U>.

Reviewed-by: Gary Guo <[email protected]>
Signed-off-by: Alice Ryhl <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
2026-04-01 12:18:21 +02:00
Alice Ryhl 09248ed8cd rust: sync: Implement Unpin for ARef
The default implementation of Unpin for ARef<T> is conditional on T
being Unpin due to its PhantomData<T> field. However, this is overly
strict as pointers to T are legal to move even if T itself cannot move.

Since commit 66f1ea83d9 ("rust: lock: Add a Pin<&mut T> accessor")
this causes build failures when combined with a Mutex that contains an
field ARef<T>, because almost any type that ARef is used with is !Unpin.

Reviewed-by: Daniel Almeida <[email protected]>
Signed-off-by: Alice Ryhl <[email protected]>
Reviewed-by: Alexandre Courbot <[email protected]>
Reviewed-by: Benno Lossin <[email protected]>
Signed-off-by: Boqun Feng <[email protected]>
Link: https://patch.msgid.link/[email protected]
2026-01-09 19:01:40 +08:00
Benno Lossin a15d12c24f rust: sync: extend module documentation of aref
Commit 07dad44aa9 ("rust: kernel: move ARef and AlwaysRefCounted to
sync::aref") moved `ARef` and `AlwaysRefCounted` into their own module.
In that process only a short, single line description of the module was
added. Extend the description by explaining what is meant by "internal
reference counting", the two items in the trait & the difference to
`Arc`.

Signed-off-by: Benno Lossin <[email protected]>
Reviewed-by: Alexandre Courbot <[email protected]>
Signed-off-by: Miguel Ojeda <[email protected]>
2025-09-15 00:02:22 +02:00
Shankari Anand 8a7c11af8e rust: sync: Update ARef and AlwaysRefCounted imports from sync::aref
Update the in-file reference of sync/aref.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]>
Reviewed-by: Benno Lossin <[email protected]>
Signed-off-by: Miguel Ojeda <[email protected]>
2025-09-08 00:11:19 +02:00
Shankari Anand 07dad44aa9 rust: kernel: move ARef and AlwaysRefCounted to sync::aref
Move the definitions of `ARef` and `AlwaysRefCounted` from `types.rs`
to a new file `sync/aref.rs`.  Define the corresponding `aref` module
under `rust/kernel/sync.rs`.  These types are better grouped in `sync`.

To avoid breaking existing imports, they are re-exported from `types.rs`.
Drop unused imports `mem::ManuallyDrop`, `ptr::NonNull` from `types.rs`,
they are now only used in `sync/aref.rs`, where they are already imported.

Suggested-by: Benno Lossin <[email protected]>
Link: https://github.com/Rust-for-Linux/linux/issues/1173
Signed-off-by: Shankari Anand <[email protected]>
Reviewed-by: Benno Lossin <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
[ Added missing `///`. Changed module title. Reworded slightly. - Miguel ]
Signed-off-by: Miguel Ojeda <[email protected]>
2025-07-22 13:52:14 +02:00