Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2950760lqp; Mon, 25 Mar 2024 14:15:05 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVbqRw5QdILjRbn/CAI2wYPmxjFcL9Z7qK5jGbcuaJtIRu3X4dpwPKYxC8dmrEp56zqBg4yT4RcwMILIWfxnBVYSXDy3VZNIxYOA1tzjQ== X-Google-Smtp-Source: AGHT+IF2nxwdo2qZmqbwjnuFYdbTsmmTthHD1ClP3o82p1Dm5DI0MLllOMiY61qG7JZs7xQZ7zlJ X-Received: by 2002:a05:620a:5796:b0:78a:5166:417c with SMTP id wk22-20020a05620a579600b0078a5166417cmr5575097qkn.46.1711401305024; Mon, 25 Mar 2024 14:15:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711401305; cv=pass; d=google.com; s=arc-20160816; b=JCsTb7NMYXGDIR4folubM2dPKmz5A/vl2VcqkQlbWst3bdqPTLXcnV/L0kMTXHN9gE 1yCrTLPEKgRWSaopRc0dBdvRYKhf5xt+szib05RAcFAlOhigObgiJdsL+JJCKObzhoQB Yb1blwbvOYJfYq1os6pwm0ubsdZsbkqCfAOyjtnwDUmMolC4iwDEC9tBMPNO0z2UerX5 +0brKeG4cL+Ujzdda6CwaBDnDolhs/5PMRFvgYfR6OsCZS55a8q7CdrtpHJeeSXfxZeI BiXqY4mURWyY2pNEC64CiQ100Z2tRGZDgEvAzYN/9QtQ8MJY9+D08ds5Pq9c59m6XtMc o5QA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:dkim-signature:date; bh=llHHasdPTnE564yAWRIEDlb7QeNB14A4Flfy8lgEg5U=; fh=LuTc+rSQG9YcR2DOqbGLjGLHMJjyIJ+YzY6iRtsJinE=; b=jZwlhLrIBRawECwnbBuQro2Sf+hjr1uAFbk5RnracgVf1/v7Y2GwFQvVOSeYAPMZuc sDgxwY5hzeGiphxgWUkZ94qRnDaW+1bvI34DlOjaNZI72N47DuZYHc5/38ca7Wa8dotm gBWO0iKpb/LlKVfI1MNbJ/ZRYprXxd0FxhXN+QYFSF0VmxWEipCgGFwMLMBXu/WWK5vr TMinCix8+avLSUOK4RgK/xxIwwP9M78S9PUV5JUjpW9eGEgTIKDvjBfDQMiNn85U6RYB ODJVCA8QHjpZJrz0MQ+ET1wL28bBv2DH7DW//uyBQIMwAsQ7qprCLbvMErfiKkaKLBER Ratg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=uiEgXaX1; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-118019-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-118019-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id f10-20020a05620a20ca00b0078a34bee9ffsi6175825qka.397.2024.03.25.14.15.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 14:15:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-118019-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=uiEgXaX1; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-118019-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-118019-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id ABBC61C63688 for ; Mon, 25 Mar 2024 21:15:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0C9A06D1C1; Mon, 25 Mar 2024 21:14:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="uiEgXaX1" Received: from out-184.mta1.migadu.com (out-184.mta1.migadu.com [95.215.58.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2AFFE5A7A8 for ; Mon, 25 Mar 2024 21:14:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.184 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711401292; cv=none; b=teYLScT0b4Gnlwht4QgPb3F7fprYpd25hR2Tv74rZsimUzbC62ph5XU1b5Jo78Gq9kLiDipFhESQuikBfZPJ1VGP3faCZxWYD1U2y6PkGVZH0OzZLPH4IHKIq4m8wzCNUh9Q6t+WVg/r13/ZhhCHGPdV/MoVXw1sH8RTEpmZuGA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711401292; c=relaxed/simple; bh=W1hWRjm3jNJ351RXmnzHe0zzrwx7OW190ghWMHNY1Mw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=UYJL6Hca8a7AG5fntF7lKP47EwF7DrvnXIKjgJaroX3VenabH0hw8uivnD4PuKoPkZZIOXkoqQrovRW/nHzIzwYdTQk4t9Wfkfj9JnKyB/PTJGjHgj4J3UbDwFWah5CVrROUMBAriZMeTjkVYqyVrbO+NfdqYO59a4s/FFuGvDg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=uiEgXaX1; arc=none smtp.client-ip=95.215.58.184 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Date: Mon, 25 Mar 2024 17:14:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1711401287; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=llHHasdPTnE564yAWRIEDlb7QeNB14A4Flfy8lgEg5U=; b=uiEgXaX1EP5tHiPl9/JxgOTwnEkgEqLTkBqdn1FGdGdStYBsEYrfnHyG72l2Ygm0omugkq hspjjqtAH5hNoEQrqWg0Akg1oKhMqTHMnJCEQrJ5aIv4gYjmjaqTT2aN19dl9XREDZdahI RBHeMDIwoVU+fqu2uBvmz9Gzn2npmts= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Kent Overstreet To: Linus Torvalds Cc: Philipp Stanner , 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 , Gary Guo , =?utf-8?B?QmrDtnJu?= 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 , kent.overstreet@gmail.com, Greg Kroah-Hartman , elver@google.com, Mark Rutland , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Catalin Marinas , linux-arm-kernel@lists.infradead.org, linux-fsdevel@vger.kernel.org Subject: Re: [WIP 0/3] Memory model and atomic API in Rust Message-ID: References: <20240322233838.868874-1-boqun.feng@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Migadu-Flow: FLOW_OUT On Mon, Mar 25, 2024 at 12:44:34PM -0700, Linus Torvalds wrote: > On Mon, 25 Mar 2024 at 11:59, Kent Overstreet wrote: > > > > To be fair, "volatile" dates from an era when we didn't have the haziest > > understanding of what a working memory model for C would look like or > > why we'd even want one. > > I don't disagree, but I find it very depressing that now that we *do* > know about memory models etc, the C++ memory model basically doubled > down on the same "object" model. > > > The way the kernel uses volatile in e.g. READ_ONCE() is fully in line > > with modern thinking, just done with the tools available at the time. A > > more modern version would be just > > > > __atomic_load_n(ptr, __ATOMIC_RELAXED) > > Yes. Again, that's the *right* model in many ways, where you mark the > *access*, not the variable. You make it completely and utterly clear > that this is a very explicit access to memory. > > But that's not what C++ actually did. They went down the same old > "volatile object" road, and instead of marking the access, they mark > the object, and the way you do the above is > > std::atomic_int value; > > and then you just access 'value' and magic happens. > > EXACTLY the same way that > > volatile int value; > > works, in other words. With exactly the same downsides. Yeah that's crap. Unfortunate too, because this does need to be a type system thing and we have all the tools to do it correctly now. What we need is for loads and stores to be explict, and that absolutely can and should be a type system thing. In Rust terminology, what we want is Volatile where T is any type that fits in a machine word, and the only operations it supports are get(), set(), xchg() and cmpxchG(). You DO NOT want it to be possible to transparantly use Volatile in place of a regular T - in exactly the same way as an atomic_t can't be used in place of a regular integer.