Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp4451757rwd; Tue, 23 May 2023 07:56:44 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ430O74iu9FH3pyZuxtOdnxFUve6wHjYMwkoajo6yNtwzPYINsMO+LYAQ67ShIDGtA/6+di X-Received: by 2002:a05:6a20:918a:b0:101:282c:2b with SMTP id v10-20020a056a20918a00b00101282c002bmr16067482pzd.32.1684853803949; Tue, 23 May 2023 07:56:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684853803; cv=none; d=google.com; s=arc-20160816; b=wLnBrM8WnFz4Nxeg7954yzyRH1KoUR9uf1muiyVCOqTSq4mIE5H/yDGsgWmmh3Rspu gyV8EufnB5S6cJvf6nUSshpdkT4DMNyRErnP2tc5F7UOlyVBmi2RFfb1ByrzRMwJSZt1 73vxjOFsQrm/O7psyv67hbShCg1KHa/Yqqwigs54HM/4XRIxkhovT/qMV3KKhsRmZnB6 btAf5QbuXLZiwolb6dnwjPbAiCwrFq5bqfo3f6LjRQtfV4CyQb0kLloarFG8OfIcO5t8 6xpgzN6FVcG5cUyEQb8UhgTOGTgUfhNslYJx2zgJedIXdsZ48PhNSRmApVnp25+aOsp+ erCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=r16leosVab/uLX7D74lYCjCyQd2teI7cw9N2TnAgQsA=; b=fcT4Cf0W3UL08ytaQBmufd984zUrVWptja0sMH+GLR8JT6Iv1aIZCvw/cZ3hvsJMFJ rLs2uSVHYAqnBmdbuCOOKxlhbjwjdIdXv3ySl+MxDaRkNq8WkMjk8RGwDCCCxM8Cjxy7 nBaxR1TGx4rwPuc5hzqkwDBwKqRsEM3NtsBEeJOpv7t4WrSid7M4sk55Jb3OQtgugFrU qdnH/eiK+OiCQ/vy8ogcHMvA7g/JLBF35v5c67faiWEN6IZ4JOMEIm7O5/qaI6sV4Rai JkO5kwVbuhKhivZx1D8DFmyBCGfkiSpGG99dtcjWX/HeZYhkAJxnKbfK8Y4/Hk/94K9c 2cgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b="Hd/uUrDI"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f72-20020a62384b000000b0064391b0ea2csi6519012pfa.403.2023.05.23.07.56.31; Tue, 23 May 2023 07:56:43 -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=@google.com header.s=20221208 header.b="Hd/uUrDI"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234406AbjEWOqF (ORCPT + 99 others); Tue, 23 May 2023 10:46:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232856AbjEWOqE (ORCPT ); Tue, 23 May 2023 10:46:04 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF659119 for ; Tue, 23 May 2023 07:46:02 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-ba8bab3b392so9966548276.1 for ; Tue, 23 May 2023 07:46:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684853162; x=1687445162; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=r16leosVab/uLX7D74lYCjCyQd2teI7cw9N2TnAgQsA=; b=Hd/uUrDISL30aYgFZm7tT9bNmVfu5Hj5bE8z8pqztEcp7fh7IokeZvyVl4+oOgQpv2 1msJ8stWSASsldMCECBLTZSZbmB67D/T7j1oTM2DeUMplouDBShHymsHyviGEf60tBiM d5vZPUEHKU0E12wSNBYOP4P1NYGjDUM5j4FC2jB/qherVgJcq2o2o9Lx9KuA3cUjjFbh fGZSVMVBEzRtgYXzq81Yb06w9UEFGdV9cfI9x14itoTZcmT+hYvViRiWZtK/VEhv4HGE vpDT/Rx7Cux0WO7uyvBET3G0qLUukSAXX6k4OFRmxbn4iL0lJKuXNJeqS7trW8tXqQhC akzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684853162; x=1687445162; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=r16leosVab/uLX7D74lYCjCyQd2teI7cw9N2TnAgQsA=; b=VnRpNx//PCRUC6kaSXEDNJ8FdJ4eH801yTEA5aq0Ko3Ebl714GMxqyxLaWj7U4PtFp VGqMt9n5Hu9M+vzrVUGlRdoIvfZ7cfM6RnGol8p8fBc5d507Dj9N0sCpVYfM4qNXipA6 SqEIR5TIpCLR8979SWUaeKtG2iyOLzWmgWIItX9xnitrvWCB55qdqN1Utumom4yqQsxR XynjuwjhlDuUZRSpSGGVZ9clB9O2TtMqx+aOd71901m9XIpbG/twLTS5ReYTDQdb4Rth ZbUnBHoJmTin2AXPcdI+zjsTGffcHJhjOlJSTIvlhlMVq4XKHoH0FQQeG7eTGnb2qYOU k7XA== X-Gm-Message-State: AC+VfDz50AZaG3GN0VbaW9/M6hqDrCeOOxrbC9havZwxldmQ0oyUp+oA ml+IyI1WuPUCq/uTq2SvMgVDZZCPaIqRbj4= X-Received: from aliceryhl.c.googlers.com ([fda3:e722:ac3:cc00:31:98fb:c0a8:6c8]) (user=aliceryhl job=sendgmr) by 2002:a25:9989:0:b0:ba2:2d0e:a752 with SMTP id p9-20020a259989000000b00ba22d0ea752mr8278874ybo.6.1684853162123; Tue, 23 May 2023 07:46:02 -0700 (PDT) Date: Tue, 23 May 2023 14:44:18 +0000 In-Reply-To: <20230523144418.1250547-1-aliceryhl@google.com> Mime-Version: 1.0 References: <20230523144418.1250547-1-aliceryhl@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Message-ID: <20230523144418.1250547-5-aliceryhl@google.com> Subject: [PATCH v2 4/4] rust: task: add `Send` marker to `Task` From: Alice Ryhl To: Miguel Ojeda , Wedson Almeida Filho , Alex Gaynor Cc: Boqun Feng , Gary Guo , "=?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?=" , Benno Lossin , Alice Ryhl , 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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED, USER_IN_DEF_DKIM_WL autolearn=ham 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 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 --- 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); -// 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 {} -- 2.40.1.698.g37aff9b760-goog