Skip to contentSkip to conversation

rust: sync: completion: document Send and Sync safety

PATCH In review Younes Akhouayri 2 participants 2 messages Aug 11

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rust: sync: completion: document Send and Sync safety

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.

---
 rust/kernel/sync/completion.rs | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
rust/kernel/sync/completion.rs +4 -2
index 35ff049ff078..b5842f04887b 100644
@@ -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,

Signature · 1 line
Younes Akhouayri <[email protected]>
maintainer
#1 lore raw
Quoted 17 lines · On Tue Aug 11, 2026 at 7:35 PM BST, Younes Akhouayri via B4 Relay wrote:

From: Younes Akhouayri <[email protected]>

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.

---
 rust/kernel/sync/completion.rs | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
rust/kernel/sync/completion.rs +0 -0
index 35ff049ff078..b5842f04887b 100644

rust/kernel/sync/completion.rs pub struct Completion { · line 72

Quoted 5 lines
rust/kernel/sync/completion.rs +1 -1
@@ -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"

Quoted 2 lines

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

I don't parse the sentence at all.

rust/kernel/sync/completion.rs pub struct Completion { · line 78

Quoted 6 lines

unsafe impl Send for Completion {}

rust/kernel/sync/completion.rs +2 -1
-// 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

Quoted 10 lines

impl Completion {

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

Best regards,

Signature · 1 line
Younes Akhouayri <[email protected]>