Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1039396rwd; Thu, 25 May 2023 07:20:08 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ79wEzIStQAsZZ31kOUpITnxizzM+c+LjPb40nu1isCFUAQHoRP/F3K05b/DUjzGUAXqyI3 X-Received: by 2002:a05:6a20:7f8c:b0:f3:33fb:a62b with SMTP id d12-20020a056a207f8c00b000f333fba62bmr24227183pzj.9.1685024408458; Thu, 25 May 2023 07:20:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685024408; cv=none; d=google.com; s=arc-20160816; b=IPMzX/sr7MFaUtgNVqofVKiMV4Dyam9AEudkWOBOjeCxhNTD4inGZsPjv4PXMMfzL4 mL8x0/yhTIUcFAVBvpPlAwaq2Ii5M5LqCrXyjU/xGqfK2jzEje7g19ePD6q8Q24+zEmp VK3G6ZbyEykWz2xKlHWvSXxV0XqPXBL8Cw+kgXVd2XQsEOJ7mOVKbj9xdS2BKCcN799g TkQduNg46A+h2wO+rSkh2IcwYBfwPpbq1SuUa8Z6gtoLbKTfZt2ceOkwUif41iJqRPmf VLFmsJQwvohMZSI+r8tE2tGxG3KjZm1yXpVhouhAGo5aWBUzySYDqzE/zKfEznkkIEk0 eZdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :feedback-id:references:in-reply-to:message-id:subject:cc:from:to :dkim-signature:date; bh=61hvWsMU7lXC84Xrt2kc9OPqYj0r7Uqdnc1xD7J8Q8g=; b=jv304U0bprdr05I+6jFCGQeoap7o0uZQjdQMCgoC9QLETaHLczUKKZV6ojybuMCPGn cZzj8zomu9OycmziLS6+xXZC7wJh5jVRtkJJlKJZnDynU0VyWpOJIYdIMbCrzW2Nj2F9 wjW9EbcwYlArvmw8X7nxZpFcKyt7W1M5KlCImxdKHTpCILEZ9Z97QHk2aM4N5jXTQfOl uIRsuG9+rDWCuotMLyo712M+ccTVRAAr/sBvL4QogwjX5H3zAxYTdG1uK8bBFS9e/tm2 SblOy3yExSG2WTNnbfXn7AIHLWlFoXYhIA3BdWqSv9WbRyeAVg/wvFpxEknUg+A6kQpj AivA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=d37z04qn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 201-20020a6306d2000000b0053b8f80c656si1310354pgg.781.2023.05.25.07.19.51; Thu, 25 May 2023 07:20:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=d37z04qn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241154AbjEYNq7 (ORCPT + 99 others); Thu, 25 May 2023 09:46:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240569AbjEYNq6 (ORCPT ); Thu, 25 May 2023 09:46:58 -0400 Received: from mail-4316.protonmail.ch (mail-4316.protonmail.ch [185.70.43.16]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8DB7186; Thu, 25 May 2023 06:46:53 -0700 (PDT) Date: Thu, 25 May 2023 13:46:40 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1685022411; x=1685281611; bh=61hvWsMU7lXC84Xrt2kc9OPqYj0r7Uqdnc1xD7J8Q8g=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=d37z04qn6hsgDWNDNykUzBqjii9W8Zw2MIvtrqUoQe1zFzE2d9tdu32FaY7OyKZVd oIdvaS9f3/dVi25EOXV06rokcjRN8qDcxGC3pMEzzLDwu8NKQt5bfV+ZfE0s+987Yi 9Kpvd5ZHV/cl5LQUWgp/QcEjuolXQ1j+hENOKLqcfnbprZTb5rjn+/7kRWVvSjI2ct l1d4o5o0UOn9BHkKbjcHrfZ61LIyIrl3UHKWqC3aQiSV1E6tR3beeZzXr1SSS9ipfC p/yuRWlg10eYq65UkUmOdbp67oQIHt6Ij12JzPgdDsNWdcCBQYpX/ioMC8ULYe5xRr Fioe5PANVaUug== To: Alice Ryhl From: Benno Lossin Cc: Miguel Ojeda , Wedson Almeida Filho , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , Ingo Molnar , Peter Zijlstra , Will Deacon , Mark Rutland , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, Andreas Hindborg Subject: Re: [PATCH v2 4/4] rust: task: add `Send` marker to `Task` Message-ID: In-Reply-To: <20230523144418.1250547-5-aliceryhl@google.com> References: <20230523144418.1250547-1-aliceryhl@google.com> <20230523144418.1250547-5-aliceryhl@google.com> Feedback-ID: 71780778:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 5/23/23 16:44, Alice Ryhl 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. >=20 > Signed-off-by: Alice Ryhl > Reviewed-by: Andreas Hindborg Reviewed-by: Benno Lossin > --- > rust/kernel/task.rs | 10 ++++++++-- > 1 file changed, 8 insertions(+), 2 deletions(-) >=20 > 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); >=20 > -// SAFETY: It's OK to access `Task` through references from other thread= s 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 `curren= t` 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 th= is 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_le= ader`) or that are properly > // synchronised by C code (e.g., `signal_pending`). > unsafe impl Sync for Task {} >=20 > -- > 2.40.1.698.g37aff9b760-goog >=20 --=20 Cheers, Benno