Re: [PATCH] rust: sync: implement Unpin for ARef
From: Alice Ryhl
Date: Thu Dec 18 2025 - 03:35:15 EST
On Wed, Dec 17, 2025 at 6:37 PM Alice Ryhl <aliceryhl@xxxxxxxxxx> wrote:
>
> 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 66f1ea83d9f8 ("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.
>
> Signed-off-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>
> ---
> rust/kernel/sync/aref.rs | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/rust/kernel/sync/aref.rs b/rust/kernel/sync/aref.rs
> index 0d24a0432015d09509a255df0a4f114171ae9fb0..c4be6f5d4884ddd6cbfbd7c27d396310a7cde30e 100644
> --- a/rust/kernel/sync/aref.rs
> +++ b/rust/kernel/sync/aref.rs
> @@ -83,6 +83,9 @@ unsafe impl<T: AlwaysRefCounted + Sync + Send> Send for ARef<T> {}
> // example, when the reference count reaches zero and `T` is dropped.
> unsafe impl<T: AlwaysRefCounted + Sync + Send> Sync for ARef<T> {}
>
> +// Even if T is pinned, pointers to T can still move.
> +impl<T> Unpin for ARef<T> {}
This needs an AlwaysRefCounted bound. I sent a v2:
https://lore.kernel.org/all/20251218-unpin-for-aref-v2-1-30d77129cbc6@xxxxxxxxxx/
Alice