Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp3046558lqp; Mon, 25 Mar 2024 18:36:08 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUNeutnFFp1XpPilkFWiTUT/4FmEJe284HE0s/avS8OqBIyRh+omyai/w7uD5hb77MJulv7nz3JoWTlXmpBYfxN8LTVBxPeyaPsZlJTsg== X-Google-Smtp-Source: AGHT+IGOsI0bv6bZBv863i37vDPN5Koo+9K8Sz9f2+dShQYHMs17S6ZPVvEmAxQECCT2zeGG8lY4 X-Received: by 2002:a50:aac9:0:b0:568:d315:b85e with SMTP id r9-20020a50aac9000000b00568d315b85emr6065460edc.36.1711416968701; Mon, 25 Mar 2024 18:36:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711416968; cv=pass; d=google.com; s=arc-20160816; b=XalydWvLzjxawUYlUOaU/zOyOTJTUhydjpXipMSG/vcSagemeNytdkcdIL0wgMouJu uWz4uJt6SmRDHDcEZhxZMgZG+kCZnhrJG3/xGpq1PGZ2TXjq2e5aPy1Uzx3QhQsV3bNF yseVKb6nebGXMbN8HTqUHMDSP7ggVyFlqF9WVJ9do+BF0VKG6Z33lURuokmn4bEWZJzQ dwFq6exWTGZjYk0QlyA+u1nZb6Yp7ndlnFOODYJ0OFX0LwHvaay3D5kuDJSFSkm4Xj1m A2dNk00IZ/Q6Bwr/PZU8foFjVgaEaAGjRaPJNOiKHcDInoHnWKzNaTF/3Ii4HeBeB5B9 DyDA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-disposition:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:references :message-id:subject:cc:to:from:date:dkim-signature; bh=7MTd97O9BSApms3QxNYhwJPeXymy6xECMh8DYUL0Obg=; fh=OuVO6FFozCnktouFjUfs6hDgX3pKA3G1bFgd6XJlDsE=; b=tJDpTlcJdPqN6f5GL4V+SAs/U2saVusWUXj4X8bgyQxO8kr4VQ0qYXEq3P5FVG6AVT fd+FllwRBqHWnxzF0YUKNgekfasUhNwkCp7+HxEzMcFEqNVtOpxAQMFVPtEMKm0RfXsU xPsX6LrLAFZ2b6xDfQJzA8KkOB4c16PAFDsXzrZTcaeRXQqltSX9RN5uJTV2Iu7WVZQq obfMuftch2mtYdHoDOn/4ff86Ck6BCZjlCQ1AIqvJkXQB3DAAL5HQzZh/wS4hb+FFQmJ 4T/jy+nl6f4Ow/H2QHFZwqYVtk6J269xohssayV8PQieGWTvhE7qmtXcPbgy1Em+rlWv kQfQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=fail header.i=@treblig.org header.s=bytemarkmx header.b=UQ3hSSuq; arc=pass (i=1 spf=pass spfdomain=treblig.org dkim=pass dkdomain=treblig.org dmarc=pass fromdomain=treblig.org); spf=pass (google.com: domain of linux-kernel+bounces-118256-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-118256-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=treblig.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id fi12-20020a056402550c00b0056c07b5c8ccsi2020793edb.318.2024.03.25.18.36.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 18:36:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-118256-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=fail header.i=@treblig.org header.s=bytemarkmx header.b=UQ3hSSuq; arc=pass (i=1 spf=pass spfdomain=treblig.org dkim=pass dkdomain=treblig.org dmarc=pass fromdomain=treblig.org); spf=pass (google.com: domain of linux-kernel+bounces-118256-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-118256-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=treblig.org 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 6E4441F3AC53 for ; Tue, 26 Mar 2024 01:36:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 527E945036; Tue, 26 Mar 2024 01:35:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=treblig.org header.i=@treblig.org header.b="UQ3hSSuq" Received: from mx.treblig.org (mx.treblig.org [46.235.229.95]) (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 5FC0C1BF47; Tue, 26 Mar 2024 01:35:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.235.229.95 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711416955; cv=none; b=n3avQIgovji2+pqS+W7io2xUJmZACh0aswpA1jAruncqcjoyakwdV+08YeyL6wPvh8nphidHm0U2Ju8ypcykjpWC0hnX2jNcGkYRmEkffKoOuFjxKZ8WBE1fhwyyOtojgvsjpAO1mcq5VtdCa9ZSvBCiqOZ3DFb+GTGWSkdbrWM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711416955; c=relaxed/simple; bh=Cto5rrUQ3AB9cCrvDWtrx00MykIQlk8+5ByUeyjpQz4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=s86e+9wXu5KPnXzgsir2KGjkci7T4bhYN7xKdxI9lkyQ0auDAflDnvxh1H6fUX7comckwBAWMNWOvpaJuhw7tp69iFTKz247sKyzCghJ0obZZZYkxcj1eQdIKClNqk7XjD38wn/lY7eXbSaliBNuiCznsBSybmuzWARq8ULbNxY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=treblig.org; spf=pass smtp.mailfrom=treblig.org; dkim=pass (2048-bit key) header.d=treblig.org header.i=@treblig.org header.b=UQ3hSSuq; arc=none smtp.client-ip=46.235.229.95 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=treblig.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=treblig.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=treblig.org ; s=bytemarkmx; 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:Resent-Date:Resent-From:Resent-Sender:Resent-To: Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe :List-Post:List-Owner:List-Archive; bh=7MTd97O9BSApms3QxNYhwJPeXymy6xECMh8DYUL0Obg=; b=UQ3hSSuqboARrf6bU2CsIRc5oL FduPfMjLWW8VgJRnHBb/aTsKkN0ZxDd1/zcpZZvPrAxWEdiE81zkuQjxZFpHqyYlF6yTOGcOFllKj qrnQDtL4jmRGexVtVElsSnx4JjCi7Eezd+bstJYaXaSJ2BGXWn3BdihxAKiLf8mWM4vDX5+AGWPxl AWqnVEL6168JZrNbvDFkgyty8CDn/aUk1w8aJ/+vBH/mUAe9wvh4Nk3rV2qzjBAjunODJ4nuF7Wso zFo7KdMixQHRL8UvoW/PnQyPNKdGjqU1oFaHYS33bvOtMva1AyjvN+0sBTZC585ydAuuWE+EN4Gkn zziXhjAg==; Received: from dg by mx.treblig.org with local (Exim 4.96) (envelope-from ) id 1rovj9-00EokP-00; Tue, 26 Mar 2024 01:35:47 +0000 Date: Tue, 26 Mar 2024 01:35:46 +0000 From: "Dr. David Alan Gilbert" To: Kent Overstreet 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 , =?iso-8859-1?Q?Bj=F6rn?= 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: 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=iso-8859-1 Content-Disposition: inline In-Reply-To: X-Chocolate: 70 percent or better cocoa solids preferably X-Operating-System: Linux/6.1.0-17-amd64 (x86_64) X-Uptime: 01:29:31 up 83 days, 4:19, 1 user, load average: 0.03, 0.02, 0.00 User-Agent: Mutt/2.2.12 (2023-09-09) * Kent Overstreet (kent.overstreet@linux.dev) wrote: > 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). That's quite architecturally specific isn't it? Or is this the distinction between accesses that are implicitly atomic (i.e. naturally aligned word) and things that are locked/exclusive? (either with a 'lock' on x86 or load-exclusive/store exclusive on some others)? Which are we talking about here? > 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. OK, so that's essentially the opposite worry of what I was saying; I was worrying about people forgetting to use an atomic access to a shared variable; I think you're worrying about people forgetting to mark a variable shared and since the accesses are the same nothing shouts? Dave -- -----Open up your eyes, open up your mind, open up your code ------- / Dr. David Alan Gilbert | Running GNU/Linux | Happy \ \ dave @ treblig.org | | In Hex / \ _________________________|_____ http://www.treblig.org |_______/