From: Alice Ryhl Date: Wed, 31 May 2023 14:59:39 +0000 (+0000) Subject: rust: task: add `Send` marker to `Task` X-Git-Tag: v6.5-rc1~249^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d09a61024f6b78c6a08892fc916cdafd87b50365;p=thirdparty%2Fkernel%2Flinux.git rust: task: add `Send` marker to `Task` When a type also implements `Sync`, the meaning of `Send` is just "this type may be accessed mutably from threads other than the one it is created on". That's ok for this type. Signed-off-by: Alice Ryhl Reviewed-by: Andreas Hindborg Reviewed-by: Gary Guo Reviewed-by: Martin Rodriguez Reboredo Reviewed-by: Benno Lossin Link: https://lore.kernel.org/r/20230531145939.3714886-5-aliceryhl@google.com Signed-off-by: Miguel Ojeda --- diff --git a/rust/kernel/task.rs b/rust/kernel/task.rs index 526d29a0ae278..7eda15e5f1b37 100644 --- a/rust/kernel/task.rs +++ b/rust/kernel/task.rs @@ -64,8 +64,14 @@ macro_rules! current { #[repr(transparent)] pub struct Task(pub(crate) Opaque); -// SAFETY: It's OK to access `Task` through references from other threads because we're either -// accessing properties that don't change (e.g., `pid`, `group_leader`) or that are properly +// SAFETY: By design, the only way to access a `Task` is via the `current` function or via an +// `ARef` obtained through the `AlwaysRefCounted` impl. This means that the only situation in +// which a `Task` can be accessed mutably is when the refcount drops to zero and the destructor +// runs. It is safe for that to happen on any thread, so it is ok for this type to be `Send`. +unsafe impl Send for Task {} + +// SAFETY: It's OK to access `Task` through shared references from other threads because we're +// either accessing properties that don't change (e.g., `pid`, `group_leader`) or that are properly // synchronised by C code (e.g., `signal_pending`). unsafe impl Sync for Task {}