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 8EF58C54E58 for ; Mon, 25 Mar 2024 10:45:24 +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: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:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=EHgoF2APjJNW216WXaU1Qnx85oowo1c36o4rOSYcreo=; b=vsgGQay9ITXNrK 26cz6/9E6jaaUCq1gWklA/CWq9gJmfiv+US4rwDXHqvOENR8FCbr4jnuaIQAPVDTW0EyR7VaMyONm jxmd1vzlj+vcK0W90FGmPgpOwLTl1CyJ2TLAu7hp293Rluq7jEZoz6Vz0z6rYwa2nv9NkYihNYQmH Qiscx5cQ7tY1auQwu0gH/31AyAE8u8/puxN28ZHqy0UzKBAOF3UR9viEsjSlv1LXa7GEpjxpAyOhJ W72w5AdaahZUh3PapfZF9ZgwC1aVI9C4uht7Q4ns+pfhj7Xty0WLYREHmAlKAZOlYIwN4KDQC5j4S G4/GWgLMesm4WC8khiPg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rohpG-0000000Gpw2-0Q7o; Mon, 25 Mar 2024 10:45:10 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rohp9-0000000GpsO-2XbQ for linux-arm-kernel@lists.infradead.org; Mon, 25 Mar 2024 10:45:06 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C15E01FB; Mon, 25 Mar 2024 03:45:31 -0700 (PDT) Received: from FVFF77S0Q05N (unknown [10.57.16.150]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id AFF8B3F67D; Mon, 25 Mar 2024 03:44:51 -0700 (PDT) Date: Mon, 25 Mar 2024 10:44:45 +0000 From: Mark Rutland To: Boqun Feng Cc: 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 , =?us-ascii?Q?Bj=22orn?= 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, Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Catalin Marinas , torvalds@linux-foundation.org, 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: <20240322233838.868874-1-boqun.feng@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240325_034503_816307_7F3EFA56 X-CRM114-Status: GOOD ( 28.01 ) 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: , 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 Fri, Mar 22, 2024 at 04:38:35PM -0700, Boqun Feng wrote: > Hi, > > Since I see more and more Rust code is comming in, I feel like this > should be sent sooner rather than later, so here is a WIP to open the > discussion and get feedback. > > One of the most important questions we need to answer is: which > memory (ordering) model we should use when developing Rust in Linux > kernel, given Rust has its own memory ordering model[1]. I had some > discussion with Rust language community to understand their position > on this: > > https://github.com/rust-lang/unsafe-code-guidelines/issues/348#issuecomment-1218407557 > https://github.com/rust-lang/unsafe-code-guidelines/issues/476#issue-2001382992 > > My takeaway from these discussions, along with other offline discussion > is that supporting two memory models is challenging for both correctness > reasoning (some one needs to provide a model) and implementation (one > model needs to be aware of the other model). So that's not wise to do > (at least at the beginning). So the most reasonable option to me is: > > we only use LKMM for Rust code in kernel (i.e. avoid using > Rust's own atomic). > > Because kernel developers are more familiar with LKMM and when Rust code > interacts with C code, it has to use the model that C code uses. I think that makes sense; if nothing else it's consistent with how we handle the C atomics today. > And this patchset is the result of that option. I introduced an atomic > library to wrap and implement LKMM atomics (of course, given it's a WIP, > so it's unfinished). Things to notice: > > * I know I could use Rust macro to generate the whole set of atomics, > but I choose not to in the beginning, as I want to make it easier to > review. > > * Very likely, we will only have AtomicI32, AtomicI64 and AtomicUsize > (i.e no atomic for bool, u8, u16, etc), with limited support for > atomic load and store on 8/16 bits. > > * I choose to re-implement atomics in Rust `asm` because we are still > figuring out how we can make it easy and maintainable for Rust to call > a C function _inlinely_ (Gary makes some progress [2]). Otherwise, > atomic primitives would be function calls, and that can be performance > bottleneck in a few cases. I don't think we want to maintain two copies of each architecture's atomics. This gets painful very quickly (e.g. as arm64's atomics get patched between LL/SC and LSE forms). Can we start off with out-of-line atomics, and see where the bottlenecks are? It's relatively easy to do that today, at least for the atomic*_*() APIs: https://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git/commit/?h=atomics/outlined&id=e0a77bfa63e7416d610769aa4ab62bc06993ce56 ... which IIUC covers the "AtomicI32, AtomicI64 and AtomicUsize" cases you mention above. Mark. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel