Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp4564396rwd; Tue, 23 May 2023 09:15:42 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5Pi/ctZ1wxutEDW+SM7voYuoK7S3Q6Wy4iqz/sIHnNcT1D7piuBgbO44U+R2Mg70pH072I X-Received: by 2002:a17:903:234a:b0:1ab:289f:65cf with SMTP id c10-20020a170903234a00b001ab289f65cfmr19789702plh.54.1684858541459; Tue, 23 May 2023 09:15:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1684858541; cv=pass; d=google.com; s=arc-20160816; b=pv8uPE607F5OsHQiDHB7qpmFN8jbkVGrhAbJdq9s30xjVh2n001T8bTWA0OyI+oO8B LfmOFn2vDMLmFh2VTFvHpxJbBWLNCO95mrVHTKJaw6sr03jI4EdVVHN0wufAyke51qT8 xgh83p5EfsWdeQsjltkRO5NHpDLeYuFmyjqxPJ2LAK4DQb2ArLPnCdD0i6JQJob14bux gKVEX4qUVaPuFNjfE1EqufoQqktDUwO3NwXaf5BoEOfO+QtMJRoEeQRIDp+JyjXBgrJ8 eWnMHXJSoCF0/Oejcz7bKwVkVWlNcduVLEQ/Eo+bXDjhAqAZuR7VHjwIVUWj1uKhzEDJ JkeA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=i4ZPMDyMfr9bPaNdWp8oa1JJqhgW8wETrNhY9Wz1Qtk=; b=JCjz68cK1GSoka5cN4afzG7eVBJIWT6W30s5Gd2Kvq+rhdPToJnzyI3WRDui43JiJF Jl8O9SAeRnE4mBAHmMetb4WRbpgaLQYysE1kLYkv0vi2iT082OSxcO5Lk++4OhV4ruFp PU6v8WYoPEWNzL03xmsSf6byVW+LTuVx9r0QfoNDY0nXUyO4AP2DAIKne0mMzvmJYC32 Jajhiy1I2pB+NQwrskS7rK32uYZmEkbcUhgGTfMbrhIWI1/iPksqDUFwck2JFAwx4KQb MTN/5JdfaS2ytvmSffhpcA7mKp5CsxqO+LNN6o3hNVR8Vqzskv8xooZUW2RZru2apOs3 loeA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@garyguo.net header.s=selector1 header.b=QN3TsHeI; arc=pass (i=1 spf=pass spfdomain=garyguo.net dkim=pass dkdomain=garyguo.net dmarc=pass fromdomain=garyguo.net); 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p4-20020a170902e74400b001a55571febesi5037075plf.277.2023.05.23.09.15.28; Tue, 23 May 2023 09:15:41 -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=@garyguo.net header.s=selector1 header.b=QN3TsHeI; arc=pass (i=1 spf=pass spfdomain=garyguo.net dkim=pass dkdomain=garyguo.net dmarc=pass fromdomain=garyguo.net); 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237105AbjEWPuf (ORCPT + 99 others); Tue, 23 May 2023 11:50:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231433AbjEWPue (ORCPT ); Tue, 23 May 2023 11:50:34 -0400 Received: from GBR01-CWL-obe.outbound.protection.outlook.com (mail-cwlgbr01on2111.outbound.protection.outlook.com [40.107.11.111]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F61ADD; Tue, 23 May 2023 08:50:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iCGttJo7mPJLptqFL9PRdymLmXf958o+ACyl99Xw5XNkQknOhev12bVCR40qXbuWojKe88okKssxAszhSko2VH/Rwt/QKepIv6etsEd3eiDCC5hLafnpbjeM8JYA/QRTgKZ3sL6DvOVFAu4hNngo9HxMf1Mrw3j/N47/h3GKWiClSqIPQpSvzvyVMG+6WCph9l85XQJ0lMMyD8jT8LNjoV3Ks9NC66dcELLTsw7K7hOt2dXnI7v8qbj82hswIZETr6MvBSgpYMxSx2oJ7pC/edZcYZugDCpXMaM7XRYfP6OQe+HmdaLu1yIId7o5H79vWdK4+7QUO6/sQdVD0bBsrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=i4ZPMDyMfr9bPaNdWp8oa1JJqhgW8wETrNhY9Wz1Qtk=; b=FhUwfd5zzbEP6OFKJXwnIDHij11EdZFEloAfLJp9b19e7PyK3oKbObIqQhdvvSx52YNLltmA6PXkIL3g9KnaaDTA5CxmXQrAGyAtuXnHJXwD9xQwaRG2Bs9csdlLCLNz20KfwrH4nbGBFeKU4S0AzlGjpymMFMYH22nGl98+ukolQM25lUoW6cThbJz5Khue9d744JvaU6ldaCjXS10dhqVPvXndDgiHHW4xF29rQfGzz5yak6zAavLCm6cSXBcaRaRuEnVaZ+5dgc4tTV3AAB64P6z21sVbkA3F0UzdTsQhs6JAj2NzEmrSvoearJfNB9SRJbba9NXU7z1+NmVV2A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=garyguo.net; dmarc=pass action=none header.from=garyguo.net; dkim=pass header.d=garyguo.net; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=garyguo.net; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=i4ZPMDyMfr9bPaNdWp8oa1JJqhgW8wETrNhY9Wz1Qtk=; b=QN3TsHeIBhQviv0pcN6XGqtg5GTgEkW1KOPKHeaXlrbgK6+AQ2cu7Oa1CODPkfSV3/OTcTgNqA4zXVzRiDwFE73oyRLxAgPTOTobrgWaUMtqB8yIVIyyQFJWLgCcxPXyMxDbc2XgXfM9Fpd/vWT9K2XYk2Qqt/r3dtZqyJbFJkw= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=garyguo.net; Received: from LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:253::10) by LO0P265MB6054.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:289::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.14; Tue, 23 May 2023 15:50:29 +0000 Received: from LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM ([fe80::1d51:d482:270c:7daf]) by LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM ([fe80::1d51:d482:270c:7daf%4]) with mapi id 15.20.6433.013; Tue, 23 May 2023 15:50:29 +0000 Date: Tue, 23 May 2023 16:50:27 +0100 From: Gary Guo To: Alice Ryhl Cc: Miguel Ojeda , Wedson Almeida Filho , Alex Gaynor , Boqun Feng , "=?UTF-8?B?QmrDtnJu?= Roy Baron" , Benno Lossin , 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 Subject: Re: [PATCH v2 2/4] rust: sync: reword the `Arc` safety comment for `Sync` Message-ID: <20230523165027.71600b4b.gary@garyguo.net> In-Reply-To: <20230523144418.1250547-3-aliceryhl@google.com> References: <20230523144418.1250547-1-aliceryhl@google.com> <20230523144418.1250547-3-aliceryhl@google.com> X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.33; x86_64-pc-linux-gnu) Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-ClientProxiedBy: LO4P123CA0469.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:1a8::6) To LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:253::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LO2P265MB5183:EE_|LO0P265MB6054:EE_ X-MS-Office365-Filtering-Correlation-Id: 509dfd14-a1a9-4e1a-4e1c-08db5ba56f2a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0c7EHY5b2qYPlgEhPjs7i5MiQXgg1DnVrq3zfU056jxTcuxxpxirU+c2Fz0LhtmUAJis+Qmd9Yg+7h88Q2QTptUnVqAPcUAL4lfrK9ZICsqgJDJ96iTbQ6DuKEpAXv5XZAyERyhx01x5smeKylc2bzqidGaLFBN04ykJnZgwCN2cAOUE57khsmBwmw6pHgd3ET/ubXcy1PPKyygiM0xUmBiNhLQgX5yZ73uaAcQkxX8S6HGEpGtjECpqcqqqFhUFswWcYiAAlZWEeO/HB+O5c/iAs3DaLbCAhqBBF93MPLTC82wlOJN5/PQO+cApvzGwwJx/iO8g2v/rsNZ38lZd7ZffAMQRgHEozS+BKwfH1gXmZyKxOrrESPJS0il0ht4a07yPOkK1GhHv/+YhQrTO8bDfxbvnh7UC/eD8yMPbJckbyNBlxwPbnnCT4B102eue+EJ1rdqytpPvOO7Em+hO4ndOX6J1RWiaEONRp2PPNKSNVdbaw2tXi1sHXYoiC7BU31Ol95Yjt4jEl9x9A4zhIX6OA6FTjkybMchJof9YLM6tOCH/mXgjlZRl+7N5M1yTf69Tidi2X+K1gcYPs2fLcnBrVIdeVXCIsDEE9G5t7BA= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230028)(376002)(366004)(136003)(396003)(39830400003)(346002)(451199021)(38100700002)(86362001)(36756003)(6506007)(1076003)(6512007)(8936002)(8676002)(7416002)(2616005)(2906002)(54906003)(478600001)(186003)(4326008)(316002)(6916009)(26005)(41300700001)(5660300002)(66476007)(6486002)(66556008)(66946007)(83380400001)(81973001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?kwnMv/xXoIVNknDzsU9VP4CxwBEroRtudtsM1dvXJJhUWqYv7C45BWDIFdvV?= =?us-ascii?Q?mvqjJ9mPf7lwZyVmuR7BAXhXrU3yzJ7QpADLM5jlT88/DKlrmeTA48TmxTYz?= =?us-ascii?Q?0/ApmEwZD4iIbE9Az21CFt3NgeHIKnDETNNKCaZmiZXZqtzpIaDJdbZSffSE?= =?us-ascii?Q?Hs84oy08GCrsxaoIyhrlBywohFxGYqL1fJjI6Z0Hav3zd4qRYnczBFltjzM4?= =?us-ascii?Q?xMr7L8lyB3B+GTC5MaM8bpAvBmJnJqgNKjUlviUdZ69juVlgmH/hUtW0+ElN?= =?us-ascii?Q?OyVgGq5A7LwkHzmvw37sbZl/tqyT5y7k70TdNXlv1XrTEfcWBLt/xS1o68F7?= =?us-ascii?Q?HBlIZ+1StAbJoJP7uJjv6QYPnue4uXH+VALcBpV+kMNwux/Jt1vKbEpa0de3?= =?us-ascii?Q?lV7TesDhl/EOBeFRQSpX+JCtacpD+QCTM3PPeQDpLa5rKkiM1fop2wDMa/uV?= =?us-ascii?Q?OkqZoBnBr56fUa4GydyUIgY8WkIkg6FTmUoIsg+fs7xTey97qIbKxMgO+wK2?= =?us-ascii?Q?FeUOKYsY05GrfWoPbrPHIo6PzsEU2KdGJ8pUdforRm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H5k8kjrB+VE53vPFnn9UX5Y19BchTnqXUco40?= =?us-ascii?Q?jwa6chGCYOaN1tuz+wxr4okkRzAnChZbBYFVJjEG4xHYq/+S62O9akcQwq0k?= =?us-ascii?Q?GIArN4JQYfSZvfeAQB/WEoGegEUP4ctcOp8ii0mm?= X-OriginatorOrg: garyguo.net X-MS-Exchange-CrossTenant-Network-Message-Id: 509dfd14-a1a9-4e1a-4e1c-08db5ba56f2a X-MS-Exchange-CrossTenant-AuthSource: LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 May 2023 15:50:29.7069 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bbc898ad-b10f-4e10-8552-d9377b823d45 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: iVnHu0MdMcU0Wf4rkkMCVDHLpkOMMrISZWOKZTUI41iO8TmmlwifvcF8Fd8xQqM2W5103ESjIZ/Ks6xYVY+rSQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: LO0P265MB6054 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED 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 On Tue, 23 May 2023 14:44:16 +0000 Alice Ryhl wrote: > 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. "for example" here implies that there are other case to get a mutable reference? I don't think that's true for our `Arc` since we don't provide a `get_mut` method. > unsafe impl Sync for Arc {} > > impl Arc {