From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EB8A5C67861 for ; Mon, 8 Apr 2024 16:55:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Reply-To:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=llbXOVAiLNiZ8XnPw3czuRBgZNihfqIouty7qNdgcqY=; b=zF36o5exvbLBbz NbEHCNyDeKFk67s3aPKKIbxIFEo/mPo1gIrv1cShPFrcwfFFlRT7byCbYAgYOJy061MpN8CbHeCB6 m7+6J2jquSKbH5K10SZ1xUSPs4gThP0B0dGGwuYmIveS/P62/2e9l7grZbPdVFGAasHGzQOY/AufT ikA/rr5u/al2XzA5MfCqDdX8FYlrZhhSwPO5z6wIG8bkAY8QYVGyTX2DRuyDsUuvQEDzbAAWG03w3 vgShA8YGy6Z7pDXFNWI/aOSYPo/rBihyURTJmUV66xvySSP/fx0AhWSBaSg5fr1oFhhpGIW9WbI2M C3feCdGjc+I50E5mOeKA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rtsHJ-0000000GGCp-34Eg; Mon, 08 Apr 2024 16:55:29 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rtsHH-0000000GGBg-0SW2 for linux-arm-kernel@lists.infradead.org; Mon, 08 Apr 2024 16:55:28 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id BB432612FB; Mon, 8 Apr 2024 16:55:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5068EC433F1; Mon, 8 Apr 2024 16:55:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712595324; bh=YFesB505hWnJdX9pdGDcBCrm9rzqVPPUgN5AuPqk1jo=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=CBqmxFJNWXXmB6Mytn75OQxNrcngJMryHSEI+Hp/ETWN1cAsGUcQGncp66pzuie3g glriyS4CYQaYGBNVTbzUEP4ZAR3mDwqKs7WKq9UFu3L8lA632C5CN9LhoPlvCgNjir qnHTDCaE7XOnpNDku2GaUCUZukZTycMhid4NyM3moCZIx0R6y2X0HtKXMtbHZ1WuXz 4dqXce9nprWNNPskUmQgAlDfHVHVxTaJGkqZLgpI+V+x0YSjWHAdfcQs7bvOfAf9M5 h6PcDlYaKvgcNNRgT6xaTSiUS7o39LVA3AvYyBEgsyF1EaAnLyFWVTK2ppk2ktwpxv YYKk/40Nxicww== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id E96B8CE126C; Mon, 8 Apr 2024 09:55:23 -0700 (PDT) Date: Mon, 8 Apr 2024 09:55:23 -0700 From: "Paul E. McKenney" To: Matthew Wilcox Cc: Linus Torvalds , Philipp Stanner , Kent Overstreet , 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 , 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> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240408_095527_281817_A1054895 X-CRM114-Status: GOOD ( 33.94 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: paulmck@kernel.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, Apr 08, 2024 at 05:02:37PM +0100, Matthew Wilcox wrote: > On Mon, Mar 25, 2024 at 10:44:43AM -0700, Linus Torvalds wrote: > > 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. > > What annoys me is that 'volatile' accesses have (at least) two distinct > meanings: > - Make this access untorn > - Prevent various optimisations (code motion, > common-subexpression-elimination, ...) > > As an example, folio_migrate_flags() (in mm/migrate.c): > > if (folio_test_error(folio)) > folio_set_error(newfolio); > if (folio_test_referenced(folio)) > folio_set_referenced(newfolio); > if (folio_test_uptodate(folio)) > folio_mark_uptodate(newfolio); > > ... which becomes... > > 1f: f6 c4 04 test $0x4,%ah > 22: 74 05 je 29 > 24: f0 80 4f 01 04 lock orb $0x4,0x1(%rdi) > 29: 48 8b 03 mov (%rbx),%rax > 2c: a8 04 test $0x4,%al > 2e: 74 05 je 35 > 30: f0 80 4d 00 04 lock orb $0x4,0x0(%rbp) > 35: 48 8b 03 mov (%rbx),%rax > 38: a8 08 test $0x8,%al > 3a: 74 05 je 41 > 3c: f0 80 4d 00 08 lock orb $0x8,0x0(%rbp) > > In my ideal world, the compiler would turn this into: > > newfolio->flags |= folio->flags & MIGRATE_MASK; > > but because folio_test_foo() and folio_set_foo() contain all manner of > volatile casts, the compiler is forced to do individual tests and sets. > > Part of that is us being dumb; folio_set_foo() should be __folio_set_foo() > because this folio is newly allocated and nobody else can be messing > with its flags word yet. I failed to spot that at the time I was doing > the conversion from SetPageFoo to folio_set_foo. > > But if the compiler people could give us something a little more > granular than "scary volatile access disable everything", that would > be nice. Also hard, because now you have to figure out what this new > thing interacts with and when is it safe to do what. OK, I will bite... Why not accumulate the changes in a mask, and then apply the mask the one time? (In situations where __folio_set_foo() need not apply.) If it turns out that we really do need a not-quite-volatile, what exactly does it do? You clearly want it to be able to be optimized so as to merge similar accesses. Is there a limit to the number of accesses that can be merged or to the region of code over which such merging is permitted? Either way, how is the compiler informed of these limits? (I admit that I am not crazy about this sort of proposal, but that might have something to do with the difficulty of repeatedly convincing people that volatile is necessary and must be retained...) Thanx, Paul _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel