Skip to contentSkip to conversation

Implement Send and Sync for clk

PATCH Superseded Alice Ryhl 4 participants 11 messages Oct 20, 2025 – Nov 10, 2025

Subsystems (5)
DRM drivers Common clk Rust DRM Rust +1 more subsystems

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Alice Ryhl

author maintainer
#0 lore raw

v2 cover Implement Send and Sync for clk

I added a patch to remove the Send/Sync impl for the Tyr driver as well. I think it's fine for the Tyr patch to land through whichever tree takes the clk patch, as there should be no non-trivial merge conflicts. Or we can also take the clk patch through drm-rust where tyr patches normally go if preferred by clk maintainers.

Regarding Daniel's patch [1], I suggest that Daniel sends his type-state change rebased on top of this series (without including the patches in this series in his).

[1]: https://lore.kernel.org/rust-for-linux/[email protected]/

---
Changes in v2:
- Rebase on v6.18-rc1.
- Add patch to tyr driver.
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Alice Ryhl (2):
rust: clk: implement Send and Sync
tyr: remove impl Send/Sync for TyrData

 drivers/gpu/drm/tyr/driver.rs | 12 ------------
 rust/kernel/clk.rs            |  7 +++++++
 2 files changed, 7 insertions(+), 12 deletions(-)

---
base-commit: 3a8660878839faadb4f1a6dd72c3179c1df56787
change-id: 20250904-clk-send-sync-3cfa7f4e1ce2

Best regards,

Signature · 1 line
Alice Ryhl <[email protected]>
author maintainer
#1 lore raw

PATCH v2 1/2 rust: clk: implement Send and Sync

These traits are required for drivers to embed the Clk type in their own data structures because driver data structures are usually required to be Send. Since the Clk type is thread-safe, implement the relevant traits.

---
 rust/kernel/clk.rs | 7 +++++++
 1 file changed, 7 insertions(+)
rust/kernel/clk.rs +7 -0
index 1e6c8c42fb3a321951e275101848b35e1ae5c2a8..0a290202da69669d670ddad2b6762a1d5f1d912e 100644
@@ -129,6 +129,13 @@ mod common_clk {
     #[repr(transparent)]
     pub struct Clk(*mut bindings::clk);
 
+    // SAFETY: It is safe to call `clk_put` on another thread than where `clk_get` was called.
+    unsafe impl Send for Clk {}
+
+    // SAFETY: It is safe to call any combination of the `&self` methods in parallel, as the
+    // methods are synchronized internally.
+    unsafe impl Sync for Clk {}
+
     impl Clk {
         /// Gets [`Clk`] corresponding to a [`Device`] and a connection id.
         ///
Signature · 1 line
2.51.0.915.g61a8936c21-goog
Acked-by on v2 1/2
#2 lore raw

Re: [PATCH v2 1/2] rust: clk: implement Send and Sync

Quoted 18 lines · Alice Ryhl

These traits are required for drivers to embed the Clk type in their own data structures because driver data structures are usually required to be Send. Since the Clk type is thread-safe, implement the relevant traits.

---
 rust/kernel/clk.rs | 7 +++++++
 1 file changed, 7 insertions(+)
rust/kernel/clk.rs +0 -0
index 1e6c8c42fb3a321951e275101848b35e1ae5c2a8..0a290202da69669d670ddad2b6762a1d5f1d912e 100644
@@ -129,6 +129,13 @@ mod common_clk {
     #[repr(transparent)]
     pub struct Clk(*mut bindings::clk);
 

rust/kernel/clk.rs mod common_clk { · line 141

Quoted 10 lines
rust/kernel/clk.rs +7 -0
+    // SAFETY: It is safe to call `clk_put` on another thread than where `clk_get` was called.
+    unsafe impl Send for Clk {}
+
+    // SAFETY: It is safe to call any combination of the `&self` methods in parallel, as the
+    // methods are synchronized internally.
+    unsafe impl Sync for Clk {}
+
     impl Clk {
         /// Gets [`Clk`] corresponding to a [`Device`] and a connection id.
         ///
Signature · 1 line
viresh
author maintainer
#3 lore raw

Re: [PATCH v2 1/2] rust: clk: implement Send and Sync

Quoted 19 lines · Viresh Kumar
Quoted 18 lines · Alice Ryhl

These traits are required for drivers to embed the Clk type in their own data structures because driver data structures are usually required to be Send. Since the Clk type is thread-safe, implement the relevant traits.

---
 rust/kernel/clk.rs | 7 +++++++
 1 file changed, 7 insertions(+)
rust/kernel/clk.rs +0 -0
index 1e6c8c42fb3a321951e275101848b35e1ae5c2a8..0a290202da69669d670ddad2b6762a1d5f1d912e 100644
@@ -129,6 +129,13 @@ mod common_clk {
     #[repr(transparent)]
     pub struct Clk(*mut bindings::clk);
 
Quoted 12 lines

rust/kernel/clk.rs mod common_clk { · line 141

Quoted 10 lines
rust/kernel/clk.rs +7 -0
+    // SAFETY: It is safe to call `clk_put` on another thread than where `clk_get` was called.
+    unsafe impl Send for Clk {}
+
+    // SAFETY: It is safe to call any combination of the `&self` methods in parallel, as the
+    // methods are synchronized internally.
+    unsafe impl Sync for Clk {}
+
     impl Clk {
         /// Gets [`Clk`] corresponding to a [`Device`] and a connection id.
         ///

I'm guessing this means you want me to take it through drm-rust? See what I put in the cover letter about choice of tree.

Alice

#4 lore raw

Re: [PATCH v2 1/2] rust: clk: implement Send and Sync

Quoted 2 lines · Alice Ryhl

I'm guessing this means you want me to take it through drm-rust? See what I put in the cover letter about choice of tree.

I was expecting Stephen to pick it up directly.

Signature · 1 line
viresh
author maintainer
#5 lore raw

Re: [PATCH v2 1/2] rust: clk: implement Send and Sync

Quoted 5 lines · Viresh Kumar
Quoted 2 lines · Alice Ryhl

I'm guessing this means you want me to take it through drm-rust? See what I put in the cover letter about choice of tree.

I was expecting Stephen to pick it up directly.

Ah, that's fine, thanks.

Alice

maintainer Reviewed-by on v2 1/2
#6 lore raw

Re: [PATCH v2 1/2] rust: clk: implement Send and Sync

In reply to Alice Ryhl
Quoted 6 lines · Alice Ryhl

These traits are required for drivers to embed the Clk type in their own data structures because driver data structures are usually required to be Send. Since the Clk type is thread-safe, implement the relevant traits.

author maintainer
#7 lore raw

PATCH v2 2/2 tyr: remove impl Send/Sync for TyrData

In reply to Alice Ryhl

Now that clk implements Send and Sync, we no longer need to manually implement these traits for TyrData. Thus remove the implementations.

The comment also mentions the regulator. However, the regulator had the traits added in commit 9a200cbdb543 ("rust: regulator: implement Send and Sync for Regulator<T>"), which is already in mainline.

---
 drivers/gpu/drm/tyr/driver.rs | 12 ------------
 1 file changed, 12 deletions(-)
drivers/gpu/drm/tyr/driver.rs +0 -12
index d5625dd1e41c8406494b267d4ac560c442a8012c..574b85bbc497f8d1053d16a11f77ecbe2c87bfb2 100644
@@ -53,18 +53,6 @@ pub(crate) struct TyrData {
     pub(crate) gpu_info: GpuInfo,
 }
 
-// Both `Clk` and `Regulator` do not implement `Send` or `Sync`, but they
-// should. There are patches on the mailing list to address this, but they have
-// not landed yet.
-//
-// For now, add this workaround so that this patch compiles with the promise
-// that it will be removed in a future patch.
-//
-// SAFETY: This will be removed in a future patch.
-unsafe impl Send for TyrData {}
-// SAFETY: This will be removed in a future patch.
-unsafe impl Sync for TyrData {}
-
 fn issue_soft_reset(dev: &Device<Bound>, iomem: &Devres<IoMem>) -> Result {
     regs::GPU_CMD.write(dev, iomem, regs::GPU_CMD_SOFT_RESET)?;
 
Signature · 1 line
2.51.0.915.g61a8936c21-goog
maintainer Reviewed-by on v2 2/2
#8 lore raw

Re: [PATCH v2 2/2] tyr: remove impl Send/Sync for TyrData

Quoted 8 lines · Alice Ryhl

Now that clk implements Send and Sync, we no longer need to manually implement these traits for TyrData. Thus remove the implementations.

The comment also mentions the regulator. However, the regulator had the traits added in commit 9a200cbdb543 ("rust: regulator: implement Send and Sync for Regulator<T>"), which is already in mainline.

Reviewed-by on the v2 series
#9 lore raw
In reply to Alice Ryhl
Quoted 6 lines · Alice Ryhl

I added a patch to remove the Send/Sync impl for the Tyr driver as well. I think it's fine for the Tyr patch to land through whichever tree takes the clk patch, as there should be no non-trivial merge conflicts. Or we can also take the clk patch through drm-rust where tyr patches normally go if preferred by clk maintainers.

Quoted 7 lines

Regarding Daniel's patch [1], I suggest that Daniel sends his type-state change rebased on top of this series (without including the patches in this series in his).

[1]: https://lore.kernel.org/rust-for-linux/[email protected]/

For the whole series:

Regards,
Boqun

Quoted 22 lines

---
Changes in v2:
- Rebase on v6.18-rc1.
- Add patch to tyr driver.
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Alice Ryhl (2):
rust: clk: implement Send and Sync
tyr: remove impl Send/Sync for TyrData

 drivers/gpu/drm/tyr/driver.rs | 12 ------------
 rust/kernel/clk.rs            |  7 +++++++
 2 files changed, 7 insertions(+), 12 deletions(-)

---
base-commit: 3a8660878839faadb4f1a6dd72c3179c1df56787
change-id: 20250904-clk-send-sync-3cfa7f4e1ce2

Best regards,

Signature · 1 line
Alice Ryhl <[email protected]>
author maintainer
#10 lore raw
In reply to Alice Ryhl
Quoted 6 lines · Alice Ryhl

I added a patch to remove the Send/Sync impl for the Tyr driver as well. I think it's fine for the Tyr patch to land through whichever tree takes the clk patch, as there should be no non-trivial merge conflicts. Or we can also take the clk patch through drm-rust where tyr patches normally go if preferred by clk maintainers.

Quoted 7 lines

Regarding Daniel's patch [1], I suggest that Daniel sends his type-state change rebased on top of this series (without including the patches in this series in his).

[1]: https://lore.kernel.org/rust-for-linux/[email protected]/

Stephen, any chance you could pick up this series? Thanks!

Alice