From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AD0BEC0032E for ; Thu, 26 Oct 2023 03:31:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232876AbjJZDbs (ORCPT ); Wed, 25 Oct 2023 23:31:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231286AbjJZDbq (ORCPT ); Wed, 25 Oct 2023 23:31:46 -0400 Received: from mail-yb1-xb32.google.com (mail-yb1-xb32.google.com [IPv6:2607:f8b0:4864:20::b32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D28D194; Wed, 25 Oct 2023 20:31:43 -0700 (PDT) Received: by mail-yb1-xb32.google.com with SMTP id 3f1490d57ef6-d9ad67058fcso325025276.1; Wed, 25 Oct 2023 20:31:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698291102; x=1698895902; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:feedback-id:from:to:cc:subject:date :message-id:reply-to; bh=6GDP4Ji1MuCk3r0rvr3Ck3tuIDn99qjLg2EPnlAxDfI=; b=aj/0YbEw0yP9qQ7QfTRz5qIG2TDcC5ABohmOSzlKIUC3RANRtYa4mblxwK8kXjMsXu tuNJThNtYoYzCeIDSRrC40XsXWkivt7d/9iTV/d9G9K2DcehZN8z/zPEv9E9/rGTC1nH 4IXl+/3ORvulLO+GhGRkVv/zWR5Q3HjzrmnfFS7t3iAeJ3lqoPv22tlbI9s7nWS0gQRb 8Z7yca9eKfFGbO/u8AZEy339yE8EDhjDiZUwLU804MWtNhFYBJfwy/eycemhkON6rb2m dZEwwym33n12u5Jx56GGc8+GnJSeOWdKBZBUdoPZwhIGWP0Aboptr5QL/tEO4mcRVlnh gpow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698291102; x=1698895902; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:feedback-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6GDP4Ji1MuCk3r0rvr3Ck3tuIDn99qjLg2EPnlAxDfI=; b=K08QtJp+rxMU4OLsTqhted7TveJTT8touTl28by7pehvWjsr8QM0Pq5Jn8P9hb+Gk1 PRtSrnZolpiN/3jOb1CsfSlZs26b8xH5rqx8P/VDnWVXMyj6Syn8t/rwONkAp7XQukKZ 5DJXuZ1gCrBBghFMvJHSq1MUlDzpy9P8E+Z3xS5zbowoYt6en1qIIyBXdHl7JE5SqytB K4R1bn3bwgMUUl2BP1oFjuFU5csMbXBK2PpUHQnsLcvNUS3RZZ4v7NnnvPSoIE9oVXPE I2OTC+S1ul+1k/tEDXQ6V8AJh3d3PaOffyXZNiqWR/UVYpj5M9GosjZViWtwqqfXmJwr db/g== X-Gm-Message-State: AOJu0Yy6cduxSzexMIM/br9kYyRDAjGEgQ0UQp1NlGuTGc/XUKnmiG4K du0TXNw9cVZXHzZWZX6v3fU= X-Google-Smtp-Source: AGHT+IE6nWVjaeF4q/0JgTm0tiEMymvKwaOV3OJaUyaEBTfVrh0s6CM2luZevzfv2bUOnfOHijnNPw== X-Received: by 2002:a25:918e:0:b0:d36:99eb:fc01 with SMTP id w14-20020a25918e000000b00d3699ebfc01mr15701879ybl.15.1698291102146; Wed, 25 Oct 2023 20:31:42 -0700 (PDT) Received: from auth1-smtp.messagingengine.com (auth1-smtp.messagingengine.com. [66.111.4.227]) by smtp.gmail.com with ESMTPSA id w31-20020a25ac1f000000b00d9ab86bdaffsm4984302ybi.12.2023.10.25.20.31.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 20:31:41 -0700 (PDT) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailauth.nyi.internal (Postfix) with ESMTP id 3B45227C0054; Wed, 25 Oct 2023 23:31:40 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 25 Oct 2023 23:31:40 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrledugdejtdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvvefukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpeeuohhquhhn ucfhvghnghcuoegsohhquhhnrdhfvghnghesghhmrghilhdrtghomheqnecuggftrfgrth htvghrnhephedugfduffffteeutddvheeuveelvdfhleelieevtdeguefhgeeuveeiudff iedvnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepsg hoqhhunhdomhgvshhmthhprghuthhhphgvrhhsohhnrghlihhthidqieelvdeghedtieeg qddujeejkeehheehvddqsghoqhhunhdrfhgvnhhgpeepghhmrghilhdrtghomhesfhhigi hmvgdrnhgrmhgv X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 25 Oct 2023 23:31:38 -0400 (EDT) Date: Wed, 25 Oct 2023 20:31:37 -0700 From: Boqun Feng To: Benno Lossin Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, llvm@lists.linux.dev, Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Gary Guo , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron , Andreas Hindborg , Alice Ryhl , Alan Stern , Andrea Parri , Will Deacon , Peter Zijlstra , Nicholas Piggin , David Howells , Jade Alglave , Luc Maranget , "Paul E. McKenney" , Akira Yokosawa , Daniel Lustig , Joel Fernandes , Nathan Chancellor , Nick Desaulniers , Tom Rix , Alexander Viro , Christian Brauner , kent.overstreet@gmail.com, Greg Kroah-Hartman , elver@google.com, Matthew Wilcox , Dave Chinner , linux-fsdevel@vger.kernel.org Subject: Re: [RFC] rust: types: Add read_once and write_once Message-ID: References: <20231025195339.1431894-1-boqun.feng@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-arch@vger.kernel.org On Wed, Oct 25, 2023 at 04:02:45PM -0700, Boqun Feng wrote: [...] > > > +/// The counter part of C `READ_ONCE()`. > > > +/// > > > +/// The semantics is exactly the same as `READ_ONCE()`, especially when used for intentional data > > > +/// races. > > > > It would be great if these semantics are either linked or spelled out > > here. Ideally both. > > > > Actually I haven't found any document about `READ_ONCE()` races with > writes is not UB: we do have document saying `READ_ONCE()` will disable > KCSAN checks, but no document says (explicitly) that it's not a UB. > Apparently I wasn't carefully reading the doc, in tools/memory-model/Documentation/explanation.txt, there is: In technical terms, the compiler is allowed to assume that when the program executes, there will not be any data races. A "data race" occurs when there are two memory accesses such that: 1. they access the same location, 2. at least one of them is a store, 3. at least one of them is plain, 4. they occur on different CPUs (or in different threads on the same CPU), and 5. they execute concurrently. the #3 limits that in LKMM, data races cannot happen if both accesses are marked (i.e. not plain). Thank Paul for bringing this to me, and I will update this accordingly in the next version. Regards, Boqun > > > +/// > > > +/// # Safety > > > +/// > > > +/// * `src` must be valid for reads. > > > +/// * `src` must be properly aligned. > > > +/// * `src` must point to a properly initialized value of value `T`. > > > +#[inline(always)] > > > +pub unsafe fn read_once(src: *const T) -> T { > > > > Why only `T: Copy`? > > [...]