Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2885149lqp; Mon, 25 Mar 2024 11:59:57 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVMZv8Zf6oHG8zjDzOSpcWjtGufSPOb+qUQHgGVDMadrWT5tsGYhz1fBWCMjwtPogrmcZ183J9bqSUzNdGLHkLOtasJi1aaYAxByHDz0w== X-Google-Smtp-Source: AGHT+IHiNli/FtOIjNNI+vSVtM1YqUk+q5zKbJq/gZirmuw5di5omLy2eoTP+9n4HmS14kaUY85Q X-Received: by 2002:a05:620a:2492:b0:789:ee50:5458 with SMTP id i18-20020a05620a249200b00789ee505458mr10336859qkn.2.1711393197719; Mon, 25 Mar 2024 11:59:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711393197; cv=pass; d=google.com; s=arc-20160816; b=tsG/lREo7XYNLazaw878q53asSf+bBEVNVrthipG5DuOMWTHcz9Sc215I0AMkEUfzB pktHiX2ZHefp0NUhP7O/Y2ELC5t7odkcUGQmxtRB1m9BP2hfNmGvuRXfh/EY9wdDzjEx KRn4J19zgrzLL2n35Wi5s1OcacuDV2bE75mVEboceA11/uXsyv88LkTzWJ3RIzyOmG1f YTzPK0vkxzFSqrKY3vACDtUbayJtPNkisiSTIrwKDBa4H1Q3/R3CG2ZqmXPJfEpNfn6f Rz+rIgvlUwnefCkeIkN2eqwKHYMlkQUqZlJpQ2AoKvjSKHchh+nV+dImlNTrp3tVCHnk pmfw== 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=VkxyhaTa5U3F8wqjsa7LRBFbMSJiyk7bCAom1K7zW40=; fh=LuTc+rSQG9YcR2DOqbGLjGLHMJjyIJ+YzY6iRtsJinE=; b=qcg1n8/nOwS9g8JXu/uJTIxyfTcZKKrM2GzGR/CAZwY7yybk08AZilxIJ4+mi54iy3 F+XVNHylONdtAJHaU54/JNGP2ZhRbZJjDF37LTM1KpWW7ilCLkJuspTrZnyuu8nrZ1/m ugMQh1nibUpuf6rhIsy3vW9VBD71FUSsYjQp7tr6EZl3zjGaLbCzld9e1VdUt5NaZvF4 3e8MAjWoy4YWnB4ThZKklJ4/rel6547L6KmnRLxWUMHAWnn+gYUOEjRliauBlmYcTT6e sepH+5t6xWAdNKZB0CYF9ozvDKA1/5b+qmvIFymtmo6xkGItLGQFzYIBc0doWdUkeTOc 0+Qw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Dq7T0k6+; 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-117756-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-117756-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. [147.75.199.223]) by mx.google.com with ESMTPS id a38-20020a05620a43a600b0078a59b97d5esi2085254qkp.222.2024.03.25.11.59.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 11:59:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-117756-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Dq7T0k6+; 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-117756-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-117756-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 73E831C3FA5E for ; Mon, 25 Mar 2024 18:59:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B9A3D8836; Mon, 25 Mar 2024 18:59:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="Dq7T0k6+" Received: from out-185.mta0.migadu.com (out-185.mta0.migadu.com [91.218.175.185]) (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 E493B4A29; Mon, 25 Mar 2024 18:59:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.185 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711393185; cv=none; b=VgEu0VvAOh0UQkr1GZJpdkNjIFJElDEDQXMsT8iKiKHAC5eBTDQHPxZ+9HIUCJekqqegyWrcjv1qJgo8Dv+Z9aOGcCDvz/fkGSKvsVOpwx/43OE/v1+RbmdKoBxEhx25LJOZr4DNCYyBr4u3AxhqmBWWLF3YNYdgnT6Iv5pbmEg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711393185; c=relaxed/simple; bh=5gZosMRdgXPNa3JQMcKlsbHmM1gyLPrPMFgAM70+YQw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=k2mCpyj9btd32YHNiwpnvOwBQwIjh/+4JqUkRe5YMD+5058GfTKERcGFOqua7U6+3J/nKs/Qt4z9CBhRGr2dXeOEuyu910MmvWa/jYX8fRwjObBHx4MSfy0T/dQYkESVWH+JfEbY69ycn6ilABSrOJENWNW34O5CdSYB8zsItxo= 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=Dq7T0k6+; arc=none smtp.client-ip=91.218.175.185 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 14:59:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1711393181; 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=VkxyhaTa5U3F8wqjsa7LRBFbMSJiyk7bCAom1K7zW40=; b=Dq7T0k6+H7nOTJbABp2Z2wN8NULCHNW0C7jHxsGk8umchshL+Bt0+paSu3yXZ0U/Y4O7Qw 2Wpvlj/e3fmhSm/vChaqixf/iHXD+YHD9CLhy0X4PoAiONraZ+KcYsPwPUDyOPWoE0DhGp ati/oPgLBYa7j6sRtKFgS2L5MNPZSGU= 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 10:44:43AM -0700, Linus Torvalds wrote: > On Mon, 25 Mar 2024 at 06:57, Philipp Stanner wrote: > > > > On Fri, 2024-03-22 at 17:36 -0700, Linus Torvalds wrote: > > > > > > It's kind of like our "volatile" usage. If you read the C (and C++) > > > standards, you'll find that you should use "volatile" on data types. > > > That's almost *never* what the kernel does. The kernel uses > > > "volatile" > > > in _code_ (ie READ_ONCE() etc), and uses it by casting etc. > > > > > > Compiler people don't tend to really like those kinds of things. > > > > Just for my understanding: Why don't they like it? > > So I actually think most compiler people are perfectly fine with the > kernel model of mostly doing 'volatile' not on the data structures > themselves, but as accesses through casts. > > It's very traditional C, and there's actually nothing particularly odd > about it. Not even from a compiler standpoint. > > In fact, I personally will argue that it is fundamentally wrong to > think that the underlying data has to be volatile. A variable may be > entirely stable in some cases (ie locks held), but not in others. > > So it's not the *variable* (aka "object") that is 'volatile', it's the > *context* that makes a particular access volatile. > > That explains why the kernel has basically zero actual volatile > objects, and 99% of all volatile accesses are done through accessor > functions that use a cast to mark a particular access volatile. > > But I've had negative comments from compiler people who read the > standards as language lawyers (which honestly, I despise - it's always > possible to try to argue what the meaning of some wording is), and > particularly C++ people used to be very very antsy about "volatile". > > They had some truly _serious_ problems with volatile. > > The C++ people spent absolutely insane amounts of time arguing about > "volatile objects" vs "accesses", and how an access through a cast > didn't make the underlying object volatile etc. 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. (Someone might want to think about depracating volatile on objects and adding compiler flag to disable it; I suspect it'd be a useful cleanup for the compiler guys if they could get rid of it.) 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) Except C atomics only support pointer and integer types, READ_ONCE() supports anything up to machine word size - that's something the C people need to fix.