Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp352810rdh; Thu, 26 Oct 2023 04:17:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF18v2gLsuO5yio9RytE9Y+xXViOKPOgNU0wKaIBy1z7LH2YzkgnH/gq4FxRLgyFepv4bM9 X-Received: by 2002:a81:ab4c:0:b0:5a7:af86:8d3b with SMTP id d12-20020a81ab4c000000b005a7af868d3bmr19404244ywk.37.1698319039002; Thu, 26 Oct 2023 04:17:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698319038; cv=none; d=google.com; s=arc-20160816; b=leKMAC4VNvdj5TQs9DAhfnND09xnQ+xsE4BbCOYQtp7meCEedWP6yT3zAgxMcU2DTQ mzDVteYHRjXL7/SNXLLRcTkw3spDQ4I8vfJgDKrEomY1kLszkbtB/HsiEV/7mjxnKUDL r4IFKWiRagcUA8glkUcAaH+jpOOeYgEEM4Utk5K+2AotMhlWLSpFyQGgg1URlw9SNIQm dhJ/yCxLmKs2G8dhbdMuEVfqbB8qHt2b+F60cebYOKa1OfzW+2gpPAowOmW/IjOz81mf xn5gLygXq96VPF2K4JX/dNXqmecOuKP3bxU119sGQ40InFYYW9MOzegcJapj+rs8418c zYbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=5cohiNIB1FuP42t4pW7beekQI1iJD/MHJhnEGgn6Hk4=; fh=M9V81gxbP/hGpgUpB00muZ92K+QJrmekKTs821H+0gg=; b=iV4SVMpj5OVbbKl13n76TzPVu1WmoAg2pBT8llijobk6hQj3U+VnNfrWPitsWfTR8A CCeYx6UBD5WKlROP0ymb53EjUFk52EIicMkp/QWacRfuUDlo+etK3ofKVuRBu1m+hgmc qPlzzTOY+ecz+fEiUbT1eIrbGkFrWy1GBzEZuOVQsMYI4yuCEWhISqUpjfy9jFbkybWn 1VhwyWHkYg1VyC69blFJYLV4/6PDgK+aZiPA0LD0TO0AHpi7X/9BhWU4HjSD/HC7ymYa 257Olg8WtxrHy0suAKZUmhuQWHl1S1+0CP9qo1Qp6hvJNpb7cVt25zIFbv9BSuElUVF+ l04w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=OXHMup0e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id n187-20020a8172c4000000b005a7f2c46b5dsi12992353ywc.162.2023.10.26.04.17.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 04:17:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=OXHMup0e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 31A7D829F1C0; Thu, 26 Oct 2023 04:17:12 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344781AbjJZLRE (ORCPT + 99 others); Thu, 26 Oct 2023 07:17:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230105AbjJZLRD (ORCPT ); Thu, 26 Oct 2023 07:17:03 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28B21191; Thu, 26 Oct 2023 04:17:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=5cohiNIB1FuP42t4pW7beekQI1iJD/MHJhnEGgn6Hk4=; b=OXHMup0eJ11eXPtr0XyZILpT2W QK73ZPV5Gh1MXIYdKATLblLvVMNNzIyUhhkt1NDZNH3IHqUzOMkIUSbRjfYGqA/DGj5h3dLAUAjPV HdETUfXELNLZEJDpknsAteTNcktZ6BDQRU4sdyL/8NXnd6IOvGqGKAQX93tNpTvDHCwdFfDNpjPvD 0r1n1zWKUNDfGm/NQK+25GAeCBOoJxL1rZ9FJgupeVYdYPrgU1gN+pxAqW2M5HC1kEMa3Nn4B+JCd zbqH85Y+btf6RaY2W+D9rRtsxl85VwWps6ET3xzsfjV0J2kvTiixo7By3NJB3jpJFDumdEBdDM+u0 KqfSMHrw==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qvyLh-00HGQ2-2Q; Thu, 26 Oct 2023 11:16:26 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 6969D300473; Thu, 26 Oct 2023 13:16:25 +0200 (CEST) Date: Thu, 26 Oct 2023 13:16:25 +0200 From: Peter Zijlstra To: Gary Guo Cc: Boqun Feng , 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 , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron , Benno Lossin , Andreas Hindborg , Alice Ryhl , Alan Stern , Andrea Parri , Will Deacon , 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, Linus Torvalds Subject: Re: [RFC] rust: types: Add read_once and write_once Message-ID: <20231026111625.GK33965@noisy.programming.kicks-ass.net> References: <20231025195339.1431894-1-boqun.feng@gmail.com> <20231026081345.GJ31411@noisy.programming.kicks-ass.net> <20231026113610.1425be1b@eugeo> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231026113610.1425be1b@eugeo> X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.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 (fry.vger.email [0.0.0.0]); Thu, 26 Oct 2023 04:17:12 -0700 (PDT) On Thu, Oct 26, 2023 at 11:36:10AM +0100, Gary Guo wrote: > There's two reasons that we are using volatile read/write as opposed to > relaxed atomic: > * Rust lacks volatile atomics at the moment. Non-volatile atomics are > not sufficient because the compiler is allowed (although they > currently don't) optimise atomics. If you have two adjacent relaxed > loads, they could be merged into one. Ah yes, that would be problematic, eg, if lifted out of a loop things could go sideways fast. > * Atomics only works for integer types determined by the platform. On > some 32-bit platforms you wouldn't be able to use 64-bit atomics at > all, and on x86 you get less optimal sequence since volatile load is > permitted to tear while atomic load needs to use LOCK CMPXCHG8B. We only grudgingly allowed u64 READ_ONCE() on 32bit platforms because the fallout was too numerous to fix. Some of them are probably bugs. Also, I think cmpxchg8b without lock prefix would be sufficient, but I've got too much of a head-ache to be sure. Worse is that we still support targets without cmpxchg8b. It might be interesting to make the Rust side more strict in this regard and see where/when we run into trouble. > * Atomics doesn't work for complex structs. Although I am not quite sure > of the value of supporting it. So on the C side we mandate the size is no larger than machine word, with the exception of the u64 on 32bit thing. We don't mandate strict integer types because things like pte_t are wrapper types.