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 X-Spam-Level: X-Spam-Status: No, score=-11.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 98442C43461 for ; Fri, 16 Apr 2021 18:47:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7C0B0613BB for ; Fri, 16 Apr 2021 18:47:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245017AbhDPSrj (ORCPT ); Fri, 16 Apr 2021 14:47:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:52644 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237334AbhDPSri (ORCPT ); Fri, 16 Apr 2021 14:47:38 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A45B9611AF; Fri, 16 Apr 2021 18:47:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1618598833; bh=N2KsTvifrgq/rqC0brjMwrMhFZQCdz7M8vStss5BFQ4=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=nF79sJC+RtSJr3mZhq6eKVwcK2vI4svdbyPBTB1AzQLNEiMlRni8RI27NgWXdzf6y I0JHjhzeALc13hBv4Vo9eQyGBjhBMV6nWpw4oV1MYx/oZceej+bRdHgm2sn6JkZDdI LHo9/LvhS1n/mvqsMi7zLf9MSLPYUUjFP6UwKmzdrm6V6SCAJV9ERCDLfha0Pr/3MM kvDDhaFYGE2Y018D0hYf7FV84CwMIXgJaDcXMIqopcThsCUAU4HWyxfbRKEna3enTR tYGj0dPcXtFDdD1u1VY7/vWwQWo1yPq4j/edRIoPhXgFV/qX8Xs0gjGVmcMA1iusgB C3vWXnP4RqpQw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 70DB95C0253; Fri, 16 Apr 2021 11:47:13 -0700 (PDT) Date: Fri, 16 Apr 2021 11:47:13 -0700 From: "Paul E. McKenney" To: Nick Desaulniers Cc: Boqun Feng , Peter Zijlstra , ojeda@kernel.org, Linus Torvalds , Greg Kroah-Hartman , rust-for-linux@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Alan Stern , Andrea Parri , Will Deacon , Nicholas Piggin , David Howells , Jade Alglave , Luc Maranget , Akira Yokosawa , Daniel Lustig , Joel Fernandes , Josh Triplett , Wedson Almeida Filho Subject: Re: [PATCH 00/13] [RFC] Rust support Message-ID: <20210416184713.GI4212@paulmck-ThinkPad-P17-Gen-1> Reply-To: paulmck@kernel.org References: <20210414184604.23473-1-ojeda@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: rust-for-linux@vger.kernel.org On Thu, Apr 15, 2021 at 11:04:37PM -0700, Nick Desaulniers wrote: > On Thu, Apr 15, 2021 at 9:27 PM Boqun Feng wrote: > > > > [Copy LKMM people, Josh, Nick and Wedson] > > > > On Thu, Apr 15, 2021 at 08:58:16PM +0200, Peter Zijlstra wrote: > > > On Wed, Apr 14, 2021 at 08:45:51PM +0200, ojeda@kernel.org wrote: > > > > > > > Rust is a systems programming language that brings several key > > > > advantages over C in the context of the Linux kernel: > > > > > > > > - No undefined behavior in the safe subset (when unsafe code is > > > > sound), including memory safety and the absence of data races. > > > > > > And yet I see not a single mention of the Rust Memory Model and how it > > > aligns (or not) with the LKMM. The C11 memory model for example is a > > > really poor fit for LKMM. > > > > > > > I think Rust currently uses C11 memory model as per: > > > > https://doc.rust-lang.org/nomicon/atomics.html > > > > , also I guess another reason that they pick C11 memory model is because > > LLVM has the support by default. > > > > But I think the Rust Community still wants to have a good memory model, > > and they are open to any kind of suggestion and input. I think we (LKMM > > people) should really get involved, because the recent discussion on > > RISC-V's atomics shows that if we didn't people might get a "broken" > > design because they thought C11 memory model is good enough: > > > > https://lore.kernel.org/lkml/YGyZPCxJYGOvqYZQ@boqun-archlinux/ > > > > And the benefits are mutual: a) Linux Kernel Memory Model (LKMM) is > > defined by combining the requirements of developers and the behavior of > > hardwares, it's pratical and can be a very good input for memory model > > designing in Rust; b) Once Rust has a better memory model, the compiler > > technologies whatever Rust compilers use to suppor the memory model can > > be adopted to C compilers and we can get that part for free. > > Yes, I agree; I think that's a very good approach. Avoiding the ISO > WG14 is interesting; at least the merits could be debated in the > public and not behind closed doors. WG14 (C) and WG21 (C++) are at least somewhat open. Here are some of the proposals a few of us have in flight: P2055R0 A Relaxed Guide to memory_order_relaxed http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p2055r0.pdf P0124R7 Linux-Kernel Memory Model (vs. that of C/C++) http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p0124r7.html P1726R4 Pointer lifetime-end zap http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1726r4.pdf https://docs.google.com/document/d/1MfagxTa6H0rTxtq9Oxyh4X53NzKqOt7y3hZBVzO_LMk/edit?usp=sharing P1121R2 Hazard Pointers: Proposed Interface and Wording for Concurrency TS 2 http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p1121r2.pdf P1382R1 volatile_load and volatile_store http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1382r1.pdf P1122R2 Proposed Wording for Concurrent Data Structures: Read-Copy-Update (RCU) http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1122r2.pdf https://docs.google.com/document/d/1MfagxTa6H0rTxtq9Oxyh4X53NzKqOt7y3hZBVzO_LMk/edit?usp=sharing P0190R4 Proposal for New memory order consume Definition http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0190r4.pdf P0750R1 Consume http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0750r1.html P1726R4 is of particular concern, along with consume. > > At least I personally is very intereted to help Rust on a complete and > > pratical memory model ;-) > > > > Josh, I think it's good if we can connect to the people working on Rust > > memoryg model, I think the right person is Ralf Jung and the right place > > is https://github.com/rust-lang/unsafe-code-guidelines, but you > > cerntainly know better than me ;-) Or maybe we can use Rust-for-Linux or > > linux-toolchains list to discuss. > > > > [...] > > > > - Boqun Feng is working hard on the different options for > > > > threading abstractions and has reviewed most of the `sync` PRs. > > > > > > Boqun, I know you're familiar with LKMM, can you please talk about how > > > Rust does things and how it interacts? > > > > As Wedson said in the other email, currently there is no code requiring > > synchronization between C side and Rust side, so we are currently fine. > > But in the longer term, we need to teach Rust memory model about the > > "design patterns" used in Linux kernel for parallel programming. > > > > What I have been doing so far is reviewing patches which have memory > > orderings in Rust-for-Linux project, try to make sure we don't include > > memory ordering bugs for the beginning. I believe that compatibility with both C/C++ and the Linux kernel are important. Thanx, Paul