Rust for Linux List
 help / color / mirror / Atom feed
From: Gary Guo <gary@garyguo.net>
To: Alice Ryhl <aliceryhl@google.com>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
	"Wedson Almeida Filho" <wedsonaf@gmail.com>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <benno.lossin@proton.me>,
	"Ingo Molnar" <mingo@redhat.com>,
	"Peter Zijlstra" <peterz@infradead.org>,
	"Will Deacon" <will@kernel.org>,
	"Mark Rutland" <mark.rutland@arm.com>,
	rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
	patches@lists.linux.dev,
	"Andreas Hindborg" <a.hindborg@samsung.com>
Subject: Re: [PATCH v2 4/4] rust: task: add `Send` marker to `Task`
Date: Tue, 23 May 2023 16:56:29 +0100	[thread overview]
Message-ID: <20230523165629.0b092b08.gary@garyguo.net> (raw)
In-Reply-To: <20230523144418.1250547-5-aliceryhl@google.com>

On Tue, 23 May 2023 14:44:18 +0000
Alice Ryhl <aliceryhl@google.com> wrote:

> 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 <aliceryhl@google.com>
> Reviewed-by: Andreas Hindborg <a.hindborg@samsung.com>

Reviewed-by: Gary Guo <gary@garyguo.net>

> ---
>  rust/kernel/task.rs | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/rust/kernel/task.rs b/rust/kernel/task.rs
> index 526d29a0ae27..7eda15e5f1b3 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<bindings::task_struct>);
>  
> -// 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<Task>` 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 {}
>  


  reply	other threads:[~2023-05-23 15:56 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-23 14:44 [PATCH v2 0/4] Update thread safety markers Alice Ryhl
2023-05-23 14:44 ` [PATCH v2 1/4] rust: sync: reword the `Arc` safety comment for `Send` Alice Ryhl
2023-05-23 15:49   ` Gary Guo
2023-05-23 16:27   ` Martin Rodriguez Reboredo
2023-05-25 13:35   ` Benno Lossin
2023-05-23 14:44 ` [PATCH v2 2/4] rust: sync: reword the `Arc` safety comment for `Sync` Alice Ryhl
2023-05-23 15:50   ` Gary Guo
2023-05-23 17:08     ` Alice Ryhl
2023-05-23 16:29   ` Martin Rodriguez Reboredo
2023-05-25 13:43   ` Benno Lossin
2023-05-23 14:44 ` [PATCH v2 3/4] rust: specify when `ARef` is thread safe Alice Ryhl
2023-05-23 16:31   ` Martin Rodriguez Reboredo
2023-05-25 13:45     ` Benno Lossin
2023-05-23 14:44 ` [PATCH v2 4/4] rust: task: add `Send` marker to `Task` Alice Ryhl
2023-05-23 15:56   ` Gary Guo [this message]
2023-05-23 16:41   ` Martin Rodriguez Reboredo
2023-05-25 13:46   ` Benno Lossin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230523165629.0b092b08.gary@garyguo.net \
    --to=gary@garyguo.net \
    --cc=a.hindborg@samsung.com \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=benno.lossin@proton.me \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=ojeda@kernel.org \
    --cc=patches@lists.linux.dev \
    --cc=peterz@infradead.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=wedsonaf@gmail.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox