Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp591349rdh; Thu, 26 Oct 2023 10:08:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFU7+Bh0yL1lfzAyYRICd/wZAc+BbXIJMo1oQ2BMLie0SVoiZ6NVYFX22n/x8vUIazsCx2e X-Received: by 2002:aca:2112:0:b0:3a7:8f94:743a with SMTP id 18-20020aca2112000000b003a78f94743amr17823405oiz.10.1698340124834; Thu, 26 Oct 2023 10:08:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698340124; cv=none; d=google.com; s=arc-20160816; b=MybuV2GLZwxAta/D0pBZokk+S9e7LbONchEIfXFvA7YGBohRn21iSJvPR1fRl1Diqd zWN6EWl8lAd8sxar5p1fanz+nnQpM6Ab+PMlE7SYGixDgn+Ap3Ucxw/KT3G1EMSW3uq5 FfdRI6EBVlGhuhScvWqoe0MGj9iTm6EwS9pUm0E56T/AuHCVBpxx0TPlaj4+XKy7Jkp6 mh6B8csz6evmFGB14+0hRh9OnoU3e/xo+8TuSoAJ5FTL/qUM4haUMF1Q7gi93L/CNurm zJKxD+/I7NLAgQrU9tX7zWKZKNQkyBiOLOft2nicHmDItGdf8lhEdjsilz3QCOQ1vByU OudQ== 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:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=QTJ4325QJCtiLxaH/c+SgrBWe4BSNG/+aEdJCtaC9wg=; fh=0+8qv0arAjXcXxmfXG2s5qMl1x6K6TkCFBc1IVIL42w=; b=RFFUX94pyOcn9tlgwRXacVnw8WdFFl3fnHpk7f63ct/COJ4WBVXn/crPhMSWZt6AAt 2R0M8FzC4IX5lpCaDSF4VNc5xa4k+5g27KYuRyNMB2LnezBXBxkCzECi2CBQ35LkmtbF EWOFqhbWJmt5XupoiR7i0xzdzZZvfEiH1njJiUlV5yxTZRDYHKQBy3rbHNwYbdHqkbNO uUAZVpZaTXQ68SoUi+lKno/yjwldt57M1+ywuXAujL3I523c44IAQjSNwMOUPyTNopRP Spo+DSOvT4tuAZfq9bP12GdqaB2MjFTuXH2LgL1Zb/zPjSVb3bIockhwVFoaxU+5Ae1g 9Rrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kvKAZN2M; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id e196-20020a2537cd000000b00da03911e27esi8230178yba.618.2023.10.26.10.08.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 10:08:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kvKAZN2M; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id B59B08227783; Thu, 26 Oct 2023 10:08:41 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231774AbjJZRIc (ORCPT + 99 others); Thu, 26 Oct 2023 13:08:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229815AbjJZRIb (ORCPT ); Thu, 26 Oct 2023 13:08:31 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A0B191; Thu, 26 Oct 2023 10:08:29 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C5A6EC433C7; Thu, 26 Oct 2023 17:08:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1698340108; bh=q5nu5IfnRwPtcWkLDIu4aKyLwlMTLZH09mIm5x2Tuis=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=kvKAZN2MMSkl1+CvCbw+bKVWIonlMLlGvoyOkrluhiKxg6aAKGv7elmEkFI6RMlk1 L2WGU4VBOmRIzvFLMQIivxqRBZldlSs8hE8LrXKkZvVdM2jdW0IhKifYjRnNGI7dp0 7GQYBSYrAQlElOlklY4PCPR1C1dNMK0Uw2AOLO2LFZDz38HOx9uPZRUVr74ZD42lkF uppRnkPjzY+r3oIpxavk/wSZbZ/WlJA9yD6XOQadktbY7anFw+dikPBP35tY9L6fPm qG6bVF1QQPHi3CLYEyTauxQqHXJDcKe4/mmhnOyBtQH8L5gr09L5S4iXS8vUROldXF udSXExCrBk2jA== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id E3628CE0D12; Thu, 26 Oct 2023 10:08:27 -0700 (PDT) Date: Thu, 26 Oct 2023 10:08:27 -0700 From: "Paul E. McKenney" To: Peter Zijlstra Cc: Gary Guo , 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 , 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: <272fb0fa-bff7-4ccf-bea1-fba388c5d512@paulmck-laptop> Reply-To: paulmck@kernel.org References: <20231025195339.1431894-1-boqun.feng@gmail.com> <20231026081345.GJ31411@noisy.programming.kicks-ass.net> <20231026113610.1425be1b@eugeo> <20231026111625.GK33965@noisy.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231026111625.GK33965@noisy.programming.kicks-ass.net> X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 howler.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 (howler.vger.email [0.0.0.0]); Thu, 26 Oct 2023 10:08:41 -0700 (PDT) On Thu, Oct 26, 2023 at 01:16:25PM +0200, Peter Zijlstra wrote: > 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. Plus cmpxchg8b can be quite a bit heavier weight than READ_ONCE(), in some cases to the point that you would instead use some other concurrency design. > It might be interesting to make the Rust side more strict in this regard > and see where/when we run into trouble. And maybe have some other name for READ_ONCE() that is permitted to tear. > > * 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. On C-language atomics, people who have talked about implementing atomics for objects too large for tear-free loads and stores have tended to want ot invent locks. :-( Thanx, Paul