Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp3049505lqp; Mon, 25 Mar 2024 18:45:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV6POV7SyrKNkWMybrrEyHpIm1AO8UOwHSOr816ynPEDx8OETgVbrV64x/aMV183xw8tXCKxF7gp8Hm4yrcm9I+OjTpObGwwirHycCODw== X-Google-Smtp-Source: AGHT+IEBuA5MfvP9C5RI2w/aa1vh1vAgBiv3Mj10w2agGeKqddq4wUOKKW3YuJRNd8jZAulgsowG X-Received: by 2002:a05:6358:2922:b0:17b:71cc:8f5a with SMTP id y34-20020a056358292200b0017b71cc8f5amr9798370rwb.27.1711417522057; Mon, 25 Mar 2024 18:45:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711417522; cv=pass; d=google.com; s=arc-20160816; b=WiHsyBgs7mOkXehyeJsq0X8/9SpIEUp8o+ZVFeeZx8WI9+28TD0nH21ZVccOZZ8BcT IIjnJFRe/OBHnZ9bm+przDWgh7ZE6mV4IjgkjnGD5bU8e7cB+1mJSouv57CtFgaEUxlQ sN/EGPt9NgRt1Ik8NefVuxx/ZS3p2GtU9dxe7eA0TUHCRMDQ+uLQaP6Rfa4DtSqsSBtt xNyKSAoTTZCCb9sHViS04SyXQfjf2o1a7kTS13QqcJtzCCe/1qqjjoD3BNfzwEAYV1CS xgd7y6tQwlfx+UmP367y/cBaneJjsRhxxRoYZUvdPpiuFxT27ywIudyhqtcopWgP2VRE HoFQ== 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=K7/P1e12pVDFD60cFU8dr+GfEYW0gad9J1o/dhSRroU=; fh=MxrPzrf2Tab41glFGFL5GWHQ6T02Lt7HSPTzMyRVZmA=; b=K8RnDd+gSdvw6fpTNe/4pt5ibgqN6ZbOTRQQpDa7163bnaLJZeZPKyc6VdhLL8uaz7 AUYRJHncMJ5DQzwo1RmAn4zGByksYvdakysiOnuWm6jE9SgGIUT6efRmAco7SpF3MRnt G0+VFf+jztm8EKs8Q8Ru61VHsB+hEIfbVbCLfkRKT/iklSlUzjB9cZZ67m4AX7YqGhAa u2GA3SK6rMu9zXRCftaRCROZnzLWKqt61YHosSFFCaFbiUduHB3W+6h9X8lIUyBb2lPX uXt90KNijDlrj1JvizugRoPIlnRITNShmJ6KzLYZoNsrpoiqORxfFLDC4Ju5Z8RvifXh 3IMA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=NLb9kon9; 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-118216-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-118216-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id m197-20020a633fce000000b005dc7e8a6d6fsi8556410pga.520.2024.03.25.18.45.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 18:45:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-118216-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=NLb9kon9; 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-118216-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-118216-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 84DC5B28CF3 for ; Tue, 26 Mar 2024 00:37:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C292A1B800; Tue, 26 Mar 2024 00:37:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="NLb9kon9" Received: from out-187.mta0.migadu.com (out-187.mta0.migadu.com [91.218.175.187]) (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 AD52C1804E for ; Tue, 26 Mar 2024 00:37:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.187 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711413431; cv=none; b=eabmhozWqKvAt8Om0Ase8mcihh6j5IbcB8mW8nOw+kMQE7lf/GNjbZuM7UojQTUjJbjw0xQuoGiOdEPmwvAhsrKMrWhPgZRJlQN5GOETrvDBmEWkCdZgPynFgLxEPS+kOv9UGH2eOA5qm/6VjzcFO/MRfPquKTNRqg9yDEQ9nio= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711413431; c=relaxed/simple; bh=ESqWTQ+HRZyQ87yUo/GTNFE0cDkeMSEhIHwbnTdrt8o=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=KDNvQBcwTSHkxBKTtANYpLnmxVmkVB4LV7Oprjd+VNOrf2+W+rUNKj4PAuuBoE3zEVn8EDXvf6Yl/vsufxVYqmhTUYLoomATKUwV0LROubtzNwdsKRN+EnXeSXc8JNAkad+0k/85PTir6jVk1qD4AaFDn9eJZl3fk5XzIUdnMv0= 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=NLb9kon9; arc=none smtp.client-ip=91.218.175.187 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 20:36:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1711413427; 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=K7/P1e12pVDFD60cFU8dr+GfEYW0gad9J1o/dhSRroU=; b=NLb9kon9YXeMPqajYlhJHM/8psRsNlhfBLdL0kTxa+vUMeGImlECNyeyGq09Ue5Wcutxh6 kuHWyImi7GVqgD5GJuuGKm6U0F/3s9oQzoXGdf5FuRJtzoDtacMjGzA5sI9ReSSU6cClND 6KC01NNpfxLWl6Prlf+9TF2C4TQVtpA= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Kent Overstreet To: "Dr. David Alan Gilbert" Cc: Linus Torvalds , 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 Tue, Mar 26, 2024 at 12:05:48AM +0000, Dr. David Alan Gilbert wrote: > * Linus Torvalds (torvalds@linux-foundation.org) wrote: > > > > > IOW, the whole access size problem that Boqun described is > > *inherently* tied to the fact that the C++ and Rust memory model is > > badly designed from the wrong principles. > > > > Instead of designing it as a "this is an atomic object that you can do > > these operations on", it should have been "this is an atomic access, > > and you can use this simple object model to have the compiler generate > > the accesses for you". > > Isn't one of the aims of the Rust/C++ idea that you can't forget to access > a shared piece of data atomically? > > If you want to have 'atomic accesses' explicitly, how do you tell the compiler > what you can use them on, and when it should stop you mixing them with > normal accesses on the same object? "can't forget to access data atomically" - that's only half of it. And atomic accesses loads/stores are not a thing under the hood, they're just loads and stores (possibly, but not necessarily, with memory barriers). The other half is at the _source_ level you don't want to treat accesses to volatiles/atomics like accesses to normal variables, you really want those to be explicit, and not look like normal variable accesses. std:atomic_int is way better than volatile in the sense that it's not a barely specified mess, but adding operator overloading was just gratuitious and unnecessary. This is a theme with C++ - they add a _ton_ of magic to make things concise and pretty, but you have to understand in intimate detail what all that magic is doing or you're totally fucked. std::atomic_int makes it such that just changing a single line of code in a single location in your program will change the semantics of your _entire_ program and the only obserable result will be that it's faster but a ticking time bomb because you just introduced a ton of races. With Rust - I honestly haven't looked at whether they added operator overlaoding for their atomics, but it's _much_ less of a concern because changing the type to the non-atomic version means your program won't compile if it's now racy.