[PATCH] rust: sync: completion: document Send and Sync safety

Younes Akhouayri via B4 Relay posted 1 patch 1 month, 2 weeks ago
rust/kernel/sync/completion.rs | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
[PATCH] rust: sync: completion: document Send and Sync safety
Posted by Younes Akhouayri via B4 Relay 1 month, 2 weeks ago
From: Younes Akhouayri <git@younes.io>

The existing safety comments only restate the guarantees provided by
Send and Sync. Document that completions have no task affinity, that
moving an owning pointer preserves pinning, and that the C API serializes
access to the completion state with wait.lock.

Signed-off-by: Younes Akhouayri <git@younes.io>
---
 rust/kernel/sync/completion.rs | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/rust/kernel/sync/completion.rs b/rust/kernel/sync/completion.rs
index 35ff049ff078..b5842f04887b 100644
--- a/rust/kernel/sync/completion.rs
+++ b/rust/kernel/sync/completion.rs
@@ -69,10 +69,12 @@ pub struct Completion {
     inner: Opaque<bindings::completion>,
 }
 
-// SAFETY: `Completion` is safe to be send to any task.
+// SAFETY: `Completion` has no task affinity, and moving an owning pointer to another task preserves
+// the pinning of the underlying `struct completion`.
 unsafe impl Send for Completion {}
 
-// SAFETY: `Completion` is safe to be accessed concurrently.
+// SAFETY: The C completion API protects accesses to `done` and the wait queue with `wait.lock`, so
+// the operations exposed through shared references may be called concurrently.
 unsafe impl Sync for Completion {}
 
 impl Completion {

---
base-commit: 8fe5e5f62bdb9660999449a4b5eaebcc37d7f842
change-id: 20260811-docs-completion-send-sync-safety-296f16d6135c

Best regards,
--  
Younes Akhouayri <git@younes.io>
Re: [PATCH] rust: sync: completion: document Send and Sync safety
Posted by Gary Guo 1 month, 2 weeks ago
On Tue Aug 11, 2026 at 7:35 PM BST, Younes Akhouayri via B4 Relay wrote:
> From: Younes Akhouayri <git@younes.io>
>
> The existing safety comments only restate the guarantees provided by
> Send and Sync. Document that completions have no task affinity, that
> moving an owning pointer preserves pinning, and that the C API serializes
> access to the completion state with wait.lock.
>
> Signed-off-by: Younes Akhouayri <git@younes.io>
> ---
>  rust/kernel/sync/completion.rs | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/rust/kernel/sync/completion.rs b/rust/kernel/sync/completion.rs
> index 35ff049ff078..b5842f04887b 100644
> --- a/rust/kernel/sync/completion.rs
> +++ b/rust/kernel/sync/completion.rs
> @@ -69,10 +69,12 @@ pub struct Completion {
>      inner: Opaque<bindings::completion>,
>  }
>  
> -// SAFETY: `Completion` is safe to be send to any task.
> +// SAFETY: `Completion` has no task affinity,

This is just a different way of stating "safe to send to any task"

> and moving an owning pointer to another task preserves
> +// the pinning of the underlying `struct completion`.

I don't parse the sentence at all.

>  unsafe impl Send for Completion {}
>  
> -// SAFETY: `Completion` is safe to be accessed concurrently.
> +// SAFETY: The C completion API protects accesses to `done` and the wait queue with `wait.lock`, so
> +// the operations exposed through shared references may be called concurrently.
>  unsafe impl Sync for Completion {}

These are internal details of `bindings::completion` and completely opaque to
Rust abstractions. They are not referenced in Rust code at all.

I am not seeing any value of adding this.

Best,
Gary

>  
>  impl Completion {
>
> ---
> base-commit: 8fe5e5f62bdb9660999449a4b5eaebcc37d7f842
> change-id: 20260811-docs-completion-send-sync-safety-296f16d6135c
>
> Best regards,
> --  
> Younes Akhouayri <git@younes.io>