From patchwork Tue May 23 14:44:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alice Ryhl X-Patchwork-Id: 98035 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:3046:b0:115:7a1d:dabb with SMTP id p6csp2201921rwl; Tue, 23 May 2023 08:15:44 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7TsUOrackrfhVuL/a/3RePJqYJIgeyAo+ZAK1eI1hnwhuXVtScHBs5hiQoryw0Yv+oew1n X-Received: by 2002:a05:6a20:6a26:b0:10c:e60d:537a with SMTP id p38-20020a056a206a2600b0010ce60d537amr81720pzk.21.1684854944139; Tue, 23 May 2023 08:15:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684854944; cv=none; d=google.com; s=arc-20160816; b=rxHngc8ohwtFI0OtBQcgSmVLHx5tpRXrGrRq+dDCVYaI17SYV8H7b+Ddt3C4gHviGC XNDIoKj9UXc0ncBZGu8D+hZLapAeX+/1S1AxQf+709csJdMun+/hSRl7wuAY45soaEj3 XU3t7gcEkN5c3bCAoz9s2+XcxuLEJhNgGxU5JqjVYAGFbzgZ2pO7f8fWqxAIvB7W7SLy 7qkUdL6JYetEmvMJ+iw9sXbNmj/gESWROQhVppApOrXm2owOaOdfl/eRn+C+zZoUQOUD 3TpSchg7mFo+ggqGxy55jhqy9kJS5bfIMAtq+LsnYyjA/6JLyfDraJN5nKFfdQP/JCRS ZvbA== 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=lZ4w9FZLzrevw3euUgZ/CnJwq2fkRa+GrhkB6vuUVZU=; b=w13SHOP+GJQocKNw7TkFYRz1Ud3S+S5gPl3VlwGS0lYPJVrsLZz7z+V6l9mHd7wvLz zm1ZDS0ePzSs9SZtsmMsenlytR6j+Sfr1ioExVx21Q/NjPzun8S0damXD+mS6EiwM//R zBE43HYzPemUd+/Ftc3a4Fe7rtCXnipIq6xoGMrtarnaAeM6wBOcDb3S1u2SiDdpssUc Qh/NxD/5gL79Loh+jrI35Cv9SHcWtPK4K+t9lBLaNHK7Di3sCRGmoO1BcQIfL+Zm7WPw qe2iHNWE6U6Ae2WpcGCWiXIAPJg9wJHrJJF3OttExdFNzlKPK3tGml1pjPRydXaxhPpe kYQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=DM09wBFc; 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 c8-20020a17090a8d0800b0024e1ae3fb36si8490464pjo.128.2023.05.23.08.15.31; Tue, 23 May 2023 08:15:44 -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=DM09wBFc; 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 S237298AbjEWOpe (ORCPT + 99 others); Tue, 23 May 2023 10:45:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234406AbjEWOpc (ORCPT ); Tue, 23 May 2023 10:45:32 -0400 Received: from mail-ej1-x64a.google.com (mail-ej1-x64a.google.com [IPv6:2a00:1450:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB405121 for ; Tue, 23 May 2023 07:45:25 -0700 (PDT) Received: by mail-ej1-x64a.google.com with SMTP id a640c23a62f3a-96fffd1ba46so215044266b.0 for ; Tue, 23 May 2023 07:45:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684853124; x=1687445124; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=lZ4w9FZLzrevw3euUgZ/CnJwq2fkRa+GrhkB6vuUVZU=; b=DM09wBFceGQyjzVeQn88f9gT37GoP8CdPRKIqccyn5klXMCzMXmxgXiA33U1xBdApV phKL7Y6oJqHMuNyPNkbrA8fkuJoSJtclCT6DlV4sbNFhEYoRh71OR3w1YoSmECRVdrmX bJ+EqUNSt4SfVYAfMThw8o4+OOuqNeNXdCilulQS1pEFabKB0fed/m9nsAE3FHgf28Tt 5s9oD0Ammk7IScrdsNQ9otYN9ftb17Wl/mIR2fwtLw0Ei+SJ5U4VKFjJriNnbE5Ef95u se6yubaEdwOhFET+po90z+DhM/u2x4CqHeuJOKgTgzofYW75jZE4kv8+8G3kvzEMoYIB CFhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684853124; x=1687445124; 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=lZ4w9FZLzrevw3euUgZ/CnJwq2fkRa+GrhkB6vuUVZU=; b=JLFP4QVUQvBhK69+RWeQ0It59AGAl12vZzz6+rdGXY1c0n27G0PbO8uSDX1lPfYPlf CqxxZiwP2YtXvJfK4nHB6i0by5EcxuH1vq+DvJpjwCgZ6KQ69yRarX7bDMYV7LUhaeVr ZOg5nDPP38N4xZydtTf2kvMENfn0Jd0RT09kgk1uAmbrM8ves4XwAd/qDMkVQRfqRj95 9/q6NDBHt/gVSg2WH8BglwODSw0ipkmz0r4gO2QEd70vcBpg4yvyxADAzmu7WoOCiw20 +H/sEKtve65a9kARm4JsRF+NNBfHnTNCKamI+OzwmIyJq39csP0WP2b4MglZyrI5JfgH LzIQ== X-Gm-Message-State: AC+VfDzVOjAxAKRsWhqH5v323Au2ozr1LPjHObLQFLVl7bzdN0EoOigZ GKSqPwX1qtXJ3IWbkYOKAZevlPsq0Pzati0= X-Received: from aliceryhl.c.googlers.com ([fda3:e722:ac3:cc00:31:98fb:c0a8:6c8]) (user=aliceryhl job=sendgmr) by 2002:a17:906:ad82:b0:96f:5864:eb73 with SMTP id la2-20020a170906ad8200b0096f5864eb73mr4342619ejb.9.1684853124405; Tue, 23 May 2023 07:45:24 -0700 (PDT) Date: Tue, 23 May 2023 14:44:16 +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-3-aliceryhl@google.com> Subject: [PATCH v2 2/4] rust: sync: reword the `Arc` safety comment for `Sync` 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?1766698457687734931?= X-GMAIL-MSGID: =?utf-8?q?1766698457687734931?= 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 87a4c9ed712b..4d10f9868d9e 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, for example, 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, for +// example, when the reference count reaches zero and `T` is dropped. unsafe impl Sync for Arc {} impl Arc {