rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rust: clk: implement Send and Sync
@ 2025-09-04  9:03 Alice Ryhl
  2025-09-04  9:08 ` Viresh Kumar
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Alice Ryhl @ 2025-09-04  9:03 UTC (permalink / raw)
  To: Michael Turquette, Stephen Boyd
  Cc: Viresh Kumar, Miguel Ojeda, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	Trevor Gross, Danilo Krummrich, Daniel Almeida, linux-clk,
	rust-for-linux, linux-kernel, 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. See e.g. [1] for the kind of workaround that drivers currently
need due to lacking this annotation.

Link: https://lore.kernel.org/rust-for-linux/20250812-tyr-v2-1-9e0f3dc9da95@collabora.com/ [1]
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
---
I'm not sure if there was already sent a patch for this. I recall
being told that one had been sent, but I could not find it. Maybe I
mixed it up with the regulator change, so now I'm sending a change for
clk.
---
 rust/kernel/clk.rs | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/rust/kernel/clk.rs b/rust/kernel/clk.rs
index 1e6c8c42fb3a321951e275101848b35e1ae5c2a8..0a290202da69669d670ddad2b6762a1d5f1d912e 100644
--- a/rust/kernel/clk.rs
+++ b/rust/kernel/clk.rs
@@ -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.
         ///

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

Best regards,
-- 
Alice Ryhl <aliceryhl@google.com>


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] rust: clk: implement Send and Sync
  2025-09-04  9:03 [PATCH] rust: clk: implement Send and Sync Alice Ryhl
@ 2025-09-04  9:08 ` Viresh Kumar
  2025-09-04 12:31 ` Daniel Almeida
  2025-09-04 13:13 ` Danilo Krummrich
  2 siblings, 0 replies; 6+ messages in thread
From: Viresh Kumar @ 2025-09-04  9:08 UTC (permalink / raw)
  To: Alice Ryhl
  Cc: Michael Turquette, Stephen Boyd, Miguel Ojeda, Boqun Feng,
	Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	Trevor Gross, Danilo Krummrich, Daniel Almeida, linux-clk,
	rust-for-linux, linux-kernel

On 04-09-25, 09:03, Alice Ryhl wrote:
> 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. See e.g. [1] for the kind of workaround that drivers currently
> need due to lacking this annotation.
> 
> Link: https://lore.kernel.org/rust-for-linux/20250812-tyr-v2-1-9e0f3dc9da95@collabora.com/ [1]
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>
> ---
> I'm not sure if there was already sent a patch for this. I recall
> being told that one had been sent, but I could not find it. Maybe I
> mixed it up with the regulator change, so now I'm sending a change for
> clk.
> ---
>  rust/kernel/clk.rs | 7 +++++++
>  1 file changed, 7 insertions(+)

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>

-- 
viresh

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] rust: clk: implement Send and Sync
  2025-09-04  9:03 [PATCH] rust: clk: implement Send and Sync Alice Ryhl
  2025-09-04  9:08 ` Viresh Kumar
@ 2025-09-04 12:31 ` Daniel Almeida
  2025-09-04 13:07   ` Alice Ryhl
  2025-09-04 13:13 ` Danilo Krummrich
  2 siblings, 1 reply; 6+ messages in thread
From: Daniel Almeida @ 2025-09-04 12:31 UTC (permalink / raw)
  To: Alice Ryhl
  Cc: Michael Turquette, Stephen Boyd, Viresh Kumar, Miguel Ojeda,
	Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Trevor Gross, Danilo Krummrich, linux-clk,
	rust-for-linux, linux-kernel

Hi Alice, good catch, this is indeed missing.

> On 4 Sep 2025, at 06:03, Alice Ryhl <aliceryhl@google.com> wrote:
> 
> 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. See e.g. [1] for the kind of workaround that drivers currently
> need due to lacking this annotation.
> 
> Link: https://lore.kernel.org/rust-for-linux/20250812-tyr-v2-1-9e0f3dc9da95@collabora.com/ [1]
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>
> ---
> I'm not sure if there was already sent a patch for this. I recall
> being told that one had been sent, but I could not find it. Maybe I
> mixed it up with the regulator change, so now I'm sending a change for
> clk.
> ---
> rust/kernel/clk.rs | 7 +++++++
> 1 file changed, 7 insertions(+)
> 
> diff --git a/rust/kernel/clk.rs b/rust/kernel/clk.rs
> index 1e6c8c42fb3a321951e275101848b35e1ae5c2a8..0a290202da69669d670ddad2b6762a1d5f1d912e 100644
> --- a/rust/kernel/clk.rs
> +++ b/rust/kernel/clk.rs
> @@ -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.
>         ///
> 
> ---
> base-commit: 1b237f190eb3d36f52dffe07a40b5eb210280e00
> change-id: 20250904-clk-send-sync-3cfa7f4e1ce2
> 
> Best regards,
> -- 
> Alice Ryhl <aliceryhl@google.com>
> 

Can you base your change on top of [0]? Otherwise it will become stale rather
quickly, as this introduces new types, i.e.: Clk<Unprepared>, Clk<Prepared>
etc.

I will push out a new version today.

[0]: https://lore.kernel.org/rust-for-linux/20250729-clk-type-state-v1-1-896b53816f7b@collabora.com/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] rust: clk: implement Send and Sync
  2025-09-04 12:31 ` Daniel Almeida
@ 2025-09-04 13:07   ` Alice Ryhl
  2025-09-04 13:22     ` Daniel Almeida
  0 siblings, 1 reply; 6+ messages in thread
From: Alice Ryhl @ 2025-09-04 13:07 UTC (permalink / raw)
  To: Daniel Almeida
  Cc: Michael Turquette, Stephen Boyd, Viresh Kumar, Miguel Ojeda,
	Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Trevor Gross, Danilo Krummrich, linux-clk,
	rust-for-linux, linux-kernel

On Thu, Sep 4, 2025 at 2:31 PM Daniel Almeida
<daniel.almeida@collabora.com> wrote:
> Can you base your change on top of [0]? Otherwise it will become stale rather
> quickly, as this introduces new types, i.e.: Clk<Unprepared>, Clk<Prepared>
> etc.
>
> I will push out a new version today.
>
> [0]: https://lore.kernel.org/rust-for-linux/20250729-clk-type-state-v1-1-896b53816f7b@collabora.com/

I would suggest the reverse. If your series is based on top of mine,
then this patch can land today regardless of how long it takes to
finish the clk refactor.

Alice

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] rust: clk: implement Send and Sync
  2025-09-04  9:03 [PATCH] rust: clk: implement Send and Sync Alice Ryhl
  2025-09-04  9:08 ` Viresh Kumar
  2025-09-04 12:31 ` Daniel Almeida
@ 2025-09-04 13:13 ` Danilo Krummrich
  2 siblings, 0 replies; 6+ messages in thread
From: Danilo Krummrich @ 2025-09-04 13:13 UTC (permalink / raw)
  To: Alice Ryhl
  Cc: Michael Turquette, Stephen Boyd, Viresh Kumar, Miguel Ojeda,
	Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Trevor Gross, Daniel Almeida, linux-clk,
	rust-for-linux, linux-kernel

On 9/4/25 11:03 AM, Alice Ryhl wrote:
> 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. See e.g. [1] for the kind of workaround that drivers currently
> need due to lacking this annotation.
> 
> Link: https://lore.kernel.org/rust-for-linux/20250812-tyr-v2-1-9e0f3dc9da95@collabora.com/ [1]
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>

Reviewed-by: Danilo Krummrich <dakr@kernel.org>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] rust: clk: implement Send and Sync
  2025-09-04 13:07   ` Alice Ryhl
@ 2025-09-04 13:22     ` Daniel Almeida
  0 siblings, 0 replies; 6+ messages in thread
From: Daniel Almeida @ 2025-09-04 13:22 UTC (permalink / raw)
  To: Alice Ryhl
  Cc: Michael Turquette, Stephen Boyd, Viresh Kumar, Miguel Ojeda,
	Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Trevor Gross, Danilo Krummrich, linux-clk,
	rust-for-linux, linux-kernel



> On 4 Sep 2025, at 10:07, Alice Ryhl <aliceryhl@google.com> wrote:
> 
> On Thu, Sep 4, 2025 at 2:31 PM Daniel Almeida
> <daniel.almeida@collabora.com> wrote:
>> Can you base your change on top of [0]? Otherwise it will become stale rather
>> quickly, as this introduces new types, i.e.: Clk<Unprepared>, Clk<Prepared>
>> etc.
>> 
>> I will push out a new version today.
>> 
>> [0]: https://lore.kernel.org/rust-for-linux/20250729-clk-type-state-v1-1-896b53816f7b@collabora.com/
> 
> I would suggest the reverse. If your series is based on top of mine,
> then this patch can land today regardless of how long it takes to
> finish the clk refactor.
> 
> Alice
> 

True,

Ok then:

Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com>

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-09-04 13:23 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-04  9:03 [PATCH] rust: clk: implement Send and Sync Alice Ryhl
2025-09-04  9:08 ` Viresh Kumar
2025-09-04 12:31 ` Daniel Almeida
2025-09-04 13:07   ` Alice Ryhl
2025-09-04 13:22     ` Daniel Almeida
2025-09-04 13:13 ` Danilo Krummrich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).