Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp4465057rwd; Tue, 23 May 2023 08:04:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6DRsu92lnliDhqZMp9xfWDIkaycRnKczms2XtvHahKDhBxFOqbi4Ry3kebGf/SbqdpnWwf X-Received: by 2002:a05:6a00:130b:b0:64d:3e7f:7121 with SMTP id j11-20020a056a00130b00b0064d3e7f7121mr16614324pfu.22.1684854297959; Tue, 23 May 2023 08:04:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684854297; cv=none; d=google.com; s=arc-20160816; b=V71fySRRvpn6RozNEBYQ1lpPdNehmEdE6vgltxq16fFjUYkC/sQpNJCWCnXFVXniVs yeA8g7cbugyAvKu59gFgc6orV9IXOJ4d3zvwIOOKNUnNmykuZb7deAuCyYH3LrVHZnEp cV3PnbgsGW8PQPmM3+iV+7mfsSTatb3cHS7PtikLy/s61/jRKbvBD1w1K9K6dXJJt1NG SJAoxrSkvaXDMfzIJf7tSTzBsJf5+e+pKMwAnA6xjI0T9LIXp13KPSefstu08TjWNV1f rvqVPE28T3kMvIw3VjBfSN3jEGwVqJwMbnU9Q8+Fal+IYFd5LBrPdjBpMJO/ZaoA7lEs fvqA== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 72-20020a63004b000000b00528a9f56705si4929616pga.602.2023.05.23.08.04.35; Tue, 23 May 2023 08:04:57 -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 S236481AbjEWOpe (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=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 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 --- 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 { -- 2.40.1.698.g37aff9b760-goog