From patchwork Wed May 31 14:59:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alice Ryhl X-Patchwork-Id: 101515 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2961472vqr; Wed, 31 May 2023 08:23:17 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4qTXAP5d7jHE0nSqjkwasv4znC2H84aJg39UZcaJos+AgAYBUFYkWmUg7d0nuUbBB/IbgV X-Received: by 2002:a05:6358:5923:b0:123:3408:6da6 with SMTP id g35-20020a056358592300b0012334086da6mr2277428rwf.2.1685546597006; Wed, 31 May 2023 08:23:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685546596; cv=none; d=google.com; s=arc-20160816; b=KeS9vv6j2AWLH9I5x1xq4+rWeWQny1ScRLzhdYgC3qgaBI8zxbdbplaoViBvUAsT+p 5UJOdD8H1w++nvLDaihiKmt/W8KEvLSOU62tQTQ1giZv/L4soFWO4eIQVh682vXYY9VA szWKVuEzAZ++teENSk0/J6M/FOHWpRC3W05O2h++MOtCdysUPlekWEtKm/uDyxHKgCjQ TzoxA+5/WvDobY8e9J6QAPsjkUpLwe/otFWv5pz7f3VDjL1YpIPXnXo/iffFo84bnHY2 Fz7Wiy/jO4kdM01cYa3dkZnvHeTP4Tmpv7kQ0ZydAdTZw77aEXf69FzeNaw6jfAZTI/S BRHg== 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=1Q+2I5zSt9CeXJ84cI2DkRkCdZ4Svm4rmosqyRFgB4Q=; b=0UvYHSNJk5VFUWdz6pR9eptzSt4NMaL44hYZ9+wy/DMTUG+FPm+WmQXevM9id8QnWR W5X7iVFzihzZ65KEuSk8NxbqoWJr9WUVHJeDii8VyGnfc0mVKbTXS3UxIxXNbDzJuK4n skd6XImG97tnnfE6V6ISqBDql1tTBWMS6RnHzLCQYbx5iYUbfS655NQ/Qy7mSv4ZPzmb BjyrRhWGFdzGic3/uTiRfGcUpiB6uxuWqBQyM5EjuZB85vkyF8dgjE8t5fODzzUXW4DR bJx6W7kqDG1DJ8Nly3H+T3i+XF17QbkhZjxIpHJH/GUm2DsepUCq27xnW93+RGvLp5NH gjGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=bnNa4BzN; 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 dw21-20020a17090b095500b00255ab0ed47asi1127453pjb.49.2023.05.31.08.23.01; Wed, 31 May 2023 08:23:16 -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=bnNa4BzN; 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 S233614AbjEaPBh (ORCPT + 99 others); Wed, 31 May 2023 11:01:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233543AbjEaPBg (ORCPT ); Wed, 31 May 2023 11:01:36 -0400 Received: from mail-ej1-x649.google.com (mail-ej1-x649.google.com [IPv6:2a00:1450:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F236EC0 for ; Wed, 31 May 2023 08:01:34 -0700 (PDT) Received: by mail-ej1-x649.google.com with SMTP id a640c23a62f3a-96fb396ee3dso480062566b.1 for ; Wed, 31 May 2023 08:01:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685545293; x=1688137293; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=1Q+2I5zSt9CeXJ84cI2DkRkCdZ4Svm4rmosqyRFgB4Q=; b=bnNa4BzNnMkAV8sNhlJArseXSoa/Cp3RaANBWBzd9VxjyIDTlr4hV7uLR/Fqr9sPFg V3T4M1u/Cqm0TGKtaApBthh754cK9SVYKk7sf7q3cjbDyz6YZOGdIstimjRAUVz5u2hR 8m671arTsCNlICRB/UITLp9bQ0bfiVv7ZPXC8NfTxKukxFdruO1EVpr8lAweg52Zhtt/ L3D8bfG+9M6OBkd6fuW1h7I971Cedkt4wE2UQtCSpAXNcu0eSmZhV39uhvD0x4mx1YER ls/kFUZu9/H1vEW7IHInniok08Iozig+z3zNg4JUoo/DWBFqr6kTLIvM4uP263wWuHu9 tIyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685545293; x=1688137293; 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=1Q+2I5zSt9CeXJ84cI2DkRkCdZ4Svm4rmosqyRFgB4Q=; b=OxGD6oaR3LfwYl4fudrd7WPoDkbbQs0N/W0ljMnjw6YvdJveJRQwW2fZYtx2AF1AOc ErxWh9tFKdTGfEG3pz5yhZ9wj9wfCZhxdUFklQo6z5S9clQtGghPL8L7B8PDGQZpF/Hw elk88LFTeM9lO6qTWPWd/IxpfT6bwpl8pPcRGZ0BscXzg0wF9mo4U/Ec/m13ci/eYben V2xlc3XqSw7xGZDLVVpZ2ezxUSCQfBbFpvlb9DwJw++uCgL/SyuY5IFtRveGF9/cujVf KBFkEhbnv2fr5YV6qb4il4oKvk+aV3UGk4Viz5Sp+JmZSoWq47tfkuYw0LfauSOveMpr k4tA== X-Gm-Message-State: AC+VfDz+rJqyQuEGKI4j/6UELh9AumNwcO6JdpuWmkyUaN/7QNlDvxlw w+dmRYiKK0KmvyF/QmSWNFX8Ya7aOLLQBMo= X-Received: from aliceryhl.c.googlers.com ([fda3:e722:ac3:cc00:31:98fb:c0a8:6c8]) (user=aliceryhl job=sendgmr) by 2002:a17:906:846d:b0:96f:5348:6ce0 with SMTP id hx13-20020a170906846d00b0096f53486ce0mr2119526ejc.5.1685545293508; Wed, 31 May 2023 08:01:33 -0700 (PDT) Date: Wed, 31 May 2023 14:59:37 +0000 In-Reply-To: <20230531145939.3714886-1-aliceryhl@google.com> Mime-Version: 1.0 References: <20230531145939.3714886-1-aliceryhl@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Message-ID: <20230531145939.3714886-3-aliceryhl@google.com> Subject: [PATCH v3 2/4] rust: sync: reword the `Arc` safety comment for `Sync` From: Alice Ryhl To: rust-for-linux@vger.kernel.org Cc: Miguel Ojeda , Wedson Almeida Filho , Alex Gaynor , Boqun Feng , Gary Guo , " =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= " , Benno Lossin , Alice Ryhl , Ingo Molnar , Peter Zijlstra , Will Deacon , Mark Rutland , linux-kernel@vger.kernel.org, patches@lists.linux.dev, Andreas Hindborg , Martin Rodriguez Reboredo 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?1767423708413589043?= X-GMAIL-MSGID: =?utf-8?q?1767423708413589043?= The safety comment on `impl Sync for Arc` references the Send safety comment. This commit avoids that in case the two comments drift apart in the future. Suggested-by: Andreas Hindborg Signed-off-by: Alice Ryhl Reviewed-by: Andreas Hindborg Reviewed-by: Boqun Feng Reviewed-by: Martin Rodriguez Reboredo Reviewed-by: Benno Lossin --- rust/kernel/sync/arc.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs index 3ad831603cf4..3da84187ecf4 100644 --- a/rust/kernel/sync/arc.rs +++ b/rust/kernel/sync/arc.rs @@ -150,9 +150,11 @@ impl, U: ?Sized> core::ops::DispatchFromDyn> for Ar // mutable reference when the reference count reaches zero and `T` is dropped. unsafe impl Send for Arc {} -// SAFETY: It is safe to send `&Arc` to another thread when the underlying `T` is `Sync` for the -// same reason as above. `T` needs to be `Send` as well because a thread can clone an `&Arc` -// into an `Arc`, which may lead to `T` being accessed by the same reasoning as above. +// SAFETY: It is safe to send `&Arc` to another thread when the underlying `T` is `Sync` +// because it effectively means sharing `&T` (which is safe because `T` is `Sync`); additionally, +// it needs `T` to be `Send` because any thread that has a `&Arc` may clone it and get an +// `Arc` on that thread, so the thread may ultimately access `T` using a mutable reference when +// the reference count reaches zero and `T` is dropped. unsafe impl Sync for Arc {} impl Arc {