Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp352888rdh; Thu, 26 Oct 2023 04:17:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEpL59OhRZ+sBuS5AOOfygw5nK9RpgxsTDk/65hh3FImEk0bj22NpCO9Rnd6KzpqNFCj3IA X-Received: by 2002:a25:ab44:0:b0:d9a:c0af:9da with SMTP id u62-20020a25ab44000000b00d9ac0af09damr4292899ybi.28.1698319047867; Thu, 26 Oct 2023 04:17:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698319047; cv=none; d=google.com; s=arc-20160816; b=zicxG+ZHlNu6KA/Jr5KTB9PrVBSIG4Ps0fXi8y2s8kS6++FDvptWU3ySjoQzbqlQYK CWHyBbRNh3BGJs13f0CfnFUAKYDf0P3GR0nOUnwOviq7i/J1vfTkZtJIManPSM0tM+FN bNOah2oKMv5n7PeuK+CL+5yTzJit/Sgm+CSql5UiDgzwf4WgrL9OIWumBolphw2HAkbw NbSFeKO10WcCFDCx9AtgTnnApj6q0qk/lyQbNZBZeDqysMlYKh14UP6ArMjX17CkDJeX r8tEWVR5XNuuVEFkHtiueCS9IJbc5/nBVbwYZQfvxWUDiUjF40M3GyGDxFIL/lf2ma4V MPXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=ADQcQPFXDFUAE1kDLSEymM4GykgZRpKmE6Mqe8TDGH4=; fh=daY75LH/pwmJShphGh8F5iOq1WgkNTmg3orPxS/Vpms=; b=vWMnxFCv1DeGoftHQQDnzwY8y7XjyTHSw12Qhzj+aQkMa+ai1ffEr7RIt1tEa6pdCE bwqDj+Ih34J14t/ST8K5c4hgdZAfBNiP2kHQofJwYpHpKNtNUiGFi9c78Ov12DZpJ7km 7aPbl8mLnJR8G1sojaeYJwSfnGjhDlJDo5ipKOkG/iFlibazdJj7ttJOL25stREGiu25 UUpsvExe4GsJJK4s7J8MKrF4HcRXHzyw/dpnep0eM716UbfyHAeldw7Qhiz4H6c5uxXx KhIcSLZ9iSgFTWeElytPZURTHICJ5wsJqndpH3O60YrQ2FPBLeNnxn03l1CgRwqW4vl9 I2OQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=hLgA+35T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id b10-20020a25ae8a000000b00d9ced828b6csi13622290ybj.126.2023.10.26.04.17.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 04:17:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=hLgA+35T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id EED8A8163C3D; Thu, 26 Oct 2023 04:17:24 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344787AbjJZLRI (ORCPT + 99 others); Thu, 26 Oct 2023 07:17:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230105AbjJZLRG (ORCPT ); Thu, 26 Oct 2023 07:17:06 -0400 Received: from mail-vs1-xe35.google.com (mail-vs1-xe35.google.com [IPv6:2607:f8b0:4864:20::e35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8CCE51A1 for ; Thu, 26 Oct 2023 04:17:04 -0700 (PDT) Received: by mail-vs1-xe35.google.com with SMTP id ada2fe7eead31-457d9ffc9d2so498599137.1 for ; Thu, 26 Oct 2023 04:17:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698319023; x=1698923823; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=ADQcQPFXDFUAE1kDLSEymM4GykgZRpKmE6Mqe8TDGH4=; b=hLgA+35TwPIRTqpwo25BV1IqB+22lDsO+ZzJFFejglYNU/9CBRxzasxR079HuJaP2f Fi5D4lWHOm0QRKswoeNH/oI5IGtlaIB5zPrZ+BzqgDVRdZWp4QTDZ9C9NcFp0bd3YHhi Fpvi/P1favuSuzE3GgqZSo0CrStCLNAdKijyAcDlXWWXtb2cd0I46eEkZ1072haxM8BG IR00FZVGSJHkd7tBApkrlOHcrXgkT3bDe8mz64MTuvnd5lfBBTz51/6wwZ3mxIwJ3m1G H9yUD698Em0cNN/z11Dtdbo483KqIquOuP3cffQ8KHFB3AzfC0gyGQrTdtbP65Qsh1/G IZiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698319023; x=1698923823; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ADQcQPFXDFUAE1kDLSEymM4GykgZRpKmE6Mqe8TDGH4=; b=QGQZJD3JarrLnstqxsKgHIS6oaRTm/eXT0LkDh6L7WHE9yhpPGlRAZNfK4TL8RHkKI gjCiXTgIBNpaGCqMxDA3Vnw7Nh/dcLjwERFeZQ4shOVegJdibgpkqVWzbAXSEAcQmY1B H3lxGEpdtwZik8zUUN/Hti3eaSh1CsB9I1jgMFwGui5aZh5dG39iSz1ODnsbxzeBZ9CS YiyPO5EDnyMFHI0BWHhRg6bFGnnIjm9nvcn9K7ADFP6dp+1Hv+oUPKb1bLg4kNthMKLM vrr0k5EM5ZnyrVx3uIJUqEijsUPUdqZdDjDEj4QsKyHatv0iR1jfmIPNZzMjxF5mTG2z vD6g== X-Gm-Message-State: AOJu0YxYvRBOZTdIl1TBmW9DDOOlE5DF1sSXdMkwEt35ylzaau2Tw71E HyhKpMS7KggHTd6xy30XEIwMVe8FPW31aF1hMjj83w== X-Received: by 2002:a67:e086:0:b0:450:cebb:4f15 with SMTP id f6-20020a67e086000000b00450cebb4f15mr1164753vsl.1.1698319023532; Thu, 26 Oct 2023 04:17:03 -0700 (PDT) MIME-Version: 1.0 References: <20231025195339.1431894-1-boqun.feng@gmail.com> In-Reply-To: <20231025195339.1431894-1-boqun.feng@gmail.com> From: Marco Elver Date: Thu, 26 Oct 2023 13:16:25 +0200 Message-ID: Subject: Re: [RFC] rust: types: Add read_once and write_once To: Boqun Feng 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 , =?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , 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 , Matthew Wilcox , Dave Chinner , linux-fsdevel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Thu, 26 Oct 2023 04:17:25 -0700 (PDT) On Wed, 25 Oct 2023 at 21:54, Boqun Feng wrote: > > In theory, `read_volatile` and `write_volatile` in Rust can have UB in > case of the data races [1]. However, kernel uses volatiles to implement > READ_ONCE() and WRITE_ONCE(), and expects races on these marked accesses > don't cause UB. And they are proven to have a lot of usages in kernel. > > To close this gap, `read_once` and `write_once` are introduced, they > have the same semantics as `READ_ONCE` and `WRITE_ONCE` especially > regarding data races under the assumption that `read_volatile` and > `write_volatile` have the same behavior as a volatile pointer in C from > a compiler point of view. > > Longer term solution is to work with Rust language side for a better way > to implement `read_once` and `write_once`. But so far, it should be good > enough. One thing you may also want to address is the ability to switch between READ_ONCE implementations depending on config. For one, arm64 with LTO will promote READ_ONCE() to acquires.