From patchwork Tue May 23 14:44:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alice Ryhl X-Patchwork-Id: 98032 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:3046:b0:115:7a1d:dabb with SMTP id p6csp2201280rwl; Tue, 23 May 2023 08:14:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ57IZBALZoAsYKMZZxJNpg9Gn60q/trbMzXPAApeTJnYdEG2o3W6n7+/w0nFYlk0fP5QL63 X-Received: by 2002:a17:902:d3cb:b0:1a5:dfd:d167 with SMTP id w11-20020a170902d3cb00b001a50dfdd167mr13503206plb.8.1684854898954; Tue, 23 May 2023 08:14:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684854898; cv=none; d=google.com; s=arc-20160816; b=lsCog//IIUsDJ5Ik/nw5Nry9rLspGpaKpL45rEITUXZimFphJSM0Ey7cnKnFvIsHMf 43k6ILUPfSn/DtBO3gT9y5955fSB9+TC9v2G+iV12tsd/uOw/yDZBZuTDtrRrHMYoxOP SEE06cBlb0GHYT4xqyY+MvLQGihxhtk4ficagVwehhyGc4k7qCAMdbtrnkSH1kjM4aUE fr08Afy8rRTddIEQmHWWyJ/Tn7t12PxBK469pGeZMSQEZzY10Q8KVVI0ib1ThirAYGpk KXcWZwxUqc5+aRUo1Vo0BvAh3UQcrppbkNourH30pui/4FFLkJNdTY40tZvbhGFuKuDE S3qQ== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y18-20020a170902ed5200b001a9581fe4b6si5821116plb.653.2023.05.23.08.14.46; Tue, 23 May 2023 08:14:58 -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 S237361AbjEWOqF (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_Roy_Baron?= " , 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766698410562627317?= X-GMAIL-MSGID: =?utf-8?q?1766698410562627317?= 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 --- 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 {}