* [PATCH v2] rust: sync: implement Unpin for ARef
@ 2025-12-18 8:25 Alice Ryhl
2025-12-18 10:24 ` Benno Lossin
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Alice Ryhl @ 2025-12-18 8:25 UTC (permalink / raw)
To: Miguel Ojeda, Boqun Feng
Cc: Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Trevor Gross, Danilo Krummrich, rust-for-linux, linux-kernel,
Daniel Almeida, Alice Ryhl
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.
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com>
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
---
Changes in v2:
- Add T: AlwaysRefCounted bound.
- Link to v1: https://lore.kernel.org/r/20251217-unpin-for-aref-v1-1-84711b747d02@google.com
---
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..a297477f23a3960928302709f6aeb322fd4d1bd0 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: AlwaysRefCounted> Unpin for ARef<T> {}
+
impl<T: AlwaysRefCounted> ARef<T> {
/// Creates a new instance of [`ARef`].
///
---
base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8
change-id: 20251217-unpin-for-aref-3dc0fe3fd5b0
Best regards,
--
Alice Ryhl <aliceryhl@google.com>
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH v2] rust: sync: implement Unpin for ARef
2025-12-18 8:25 [PATCH v2] rust: sync: implement Unpin for ARef Alice Ryhl
@ 2025-12-18 10:24 ` Benno Lossin
2025-12-18 10:26 ` Miguel Ojeda
2025-12-18 11:07 ` Alexandre Courbot
2 siblings, 0 replies; 5+ messages in thread
From: Benno Lossin @ 2025-12-18 10:24 UTC (permalink / raw)
To: Alice Ryhl, Miguel Ojeda, Boqun Feng
Cc: Gary Guo, Björn Roy Baron, Andreas Hindborg, Trevor Gross,
Danilo Krummrich, rust-for-linux, linux-kernel, Daniel Almeida
On Thu Dec 18, 2025 at 9:25 AM CET, Alice Ryhl 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.
>
> Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com>
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Benno Lossin <lossin@kernel.org>
Cheers,
Benno
> ---
> Changes in v2:
> - Add T: AlwaysRefCounted bound.
> - Link to v1: https://lore.kernel.org/r/20251217-unpin-for-aref-v1-1-84711b747d02@google.com
> ---
> rust/kernel/sync/aref.rs | 3 +++
> 1 file changed, 3 insertions(+)
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH v2] rust: sync: implement Unpin for ARef
2025-12-18 8:25 [PATCH v2] rust: sync: implement Unpin for ARef Alice Ryhl
2025-12-18 10:24 ` Benno Lossin
@ 2025-12-18 10:26 ` Miguel Ojeda
2025-12-18 13:23 ` Boqun Feng
2025-12-18 11:07 ` Alexandre Courbot
2 siblings, 1 reply; 5+ messages in thread
From: Miguel Ojeda @ 2025-12-18 10:26 UTC (permalink / raw)
To: Alice Ryhl
Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Trevor Gross, Danilo Krummrich,
rust-for-linux, linux-kernel, Daniel Almeida
On Thu, Dec 18, 2025 at 9:25 AM Alice Ryhl <aliceryhl@google.com> wrote:
>
> +// Even if T is pinned, pointers to T can still move.
Boqun, if you pick this up, then please tweak this to:
// Even if `T` is pinned, pointers to `T` can still move.
Otherwise, if you want me to pick it up, please let me know -- thanks!
Cheers,
Miguel
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH v2] rust: sync: implement Unpin for ARef
2025-12-18 10:26 ` Miguel Ojeda
@ 2025-12-18 13:23 ` Boqun Feng
0 siblings, 0 replies; 5+ messages in thread
From: Boqun Feng @ 2025-12-18 13:23 UTC (permalink / raw)
To: Miguel Ojeda
Cc: Alice Ryhl, Miguel Ojeda, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Trevor Gross, Danilo Krummrich,
rust-for-linux, linux-kernel, Daniel Almeida
On Thu, Dec 18, 2025 at 11:26:19AM +0100, Miguel Ojeda wrote:
> On Thu, Dec 18, 2025 at 9:25 AM Alice Ryhl <aliceryhl@google.com> wrote:
> >
> > +// Even if T is pinned, pointers to T can still move.
>
> Boqun, if you pick this up, then please tweak this to:
>
> // Even if `T` is pinned, pointers to `T` can still move.
>
Done:
https://git.kernel.org/pub/scm/linux/kernel/git/boqun/linux.git/ rust-sync
Thanks!
Regards,
Boqun
> Otherwise, if you want me to pick it up, please let me know -- thanks!
>
> Cheers,
> Miguel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] rust: sync: implement Unpin for ARef
2025-12-18 8:25 [PATCH v2] rust: sync: implement Unpin for ARef Alice Ryhl
2025-12-18 10:24 ` Benno Lossin
2025-12-18 10:26 ` Miguel Ojeda
@ 2025-12-18 11:07 ` Alexandre Courbot
2 siblings, 0 replies; 5+ messages in thread
From: Alexandre Courbot @ 2025-12-18 11:07 UTC (permalink / raw)
To: Alice Ryhl, Miguel Ojeda, Boqun Feng
Cc: Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Trevor Gross, Danilo Krummrich, rust-for-linux, linux-kernel,
Daniel Almeida
On Thu Dec 18, 2025 at 5:25 PM JST, Alice Ryhl 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.
>
> Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com>
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-12-18 14:59 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-18 8:25 [PATCH v2] rust: sync: implement Unpin for ARef Alice Ryhl
2025-12-18 10:24 ` Benno Lossin
2025-12-18 10:26 ` Miguel Ojeda
2025-12-18 13:23 ` Boqun Feng
2025-12-18 11:07 ` Alexandre Courbot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox