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 590C5C54E64 for ; Sat, 23 Mar 2024 00:15:55 +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=Lp0xuREJ9Yd1ygdrigHRE4uVnx02gSanKOA4L9Zj0vc=; b=FWrvjq+ebRK1fF Tb7If1Gl6Wp6aCg/GEgr+6nnDHDy3qmLe7Z7TKJFFf2qD+3Z2P/WdTrCsS1PHPbPksJuvTy/Het1R kPjStUhjQBZQs7Au8ZHqpHNQCgtvsexMbFpyQsbDwzez+++FvodzN+qHhkQ42nVy1vkbyWfViwCFx 5HE4DOtECYHN3CHEgXcKkNj3jnvipK1de/+/Tv1Z1cRJQhQ/ZtybjjP5PLifmpRa7FQVt5wSORWpF dEdH7gkvsCKoXJXB18QmYP+sE/L0rEZNv9pi9c7f+tB5AGG4mgPMs7JyRKEPxlLknDL8sHPRGbKOz Ru0+sGk4JN1kaUuUbq/g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rnp2y-000000090RP-1897; Sat, 23 Mar 2024 00:15:40 +0000 Received: from mail-qv1-xf30.google.com ([2607:f8b0:4864:20::f30]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rnp2u-000000090Q5-41tt for linux-arm-kernel@lists.infradead.org; Sat, 23 Mar 2024 00:15:38 +0000 Received: by mail-qv1-xf30.google.com with SMTP id 6a1803df08f44-690c1747c3cso21267316d6.0 for ; Fri, 22 Mar 2024 17:15:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711152935; x=1711757735; darn=lists.infradead.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:feedback-id:from:to:cc:subject:date :message-id:reply-to; bh=whmVMHuEBXgRIj9diBxuHvfTM2nWAuNzeXBmM3HZHOY=; b=GrqebWrSKIG0LUodu/2sBA8tVns3wuKmuqsyHtbEMloXZtHqnIpCVaUbPqW50CGrPv iy2aa+phK1Y6JrlEi45QpFypGqFSga1KH3+pRuq20YyalsgCCXSV9Ria0f5rVW7TeH6R bPR9BXOaMWRzZy65zurZ8qjrN5YbYlBHaLD5RnGMAXMsIGSrxgaV9Ut0QoNSMPOxTDZl 7cY9KXpqJYQ2XV+J20Y+wL5BLenWMgYeY/Mh5lLpCItPRytz5tLewloFCAVOUs8DhArg JMPT9rAANYwiLM7h09l17uiwA3aRCbdOWuDHcuhEidXXsN3x2Y+U6HaKsnWVWrkMzwI7 fCdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711152935; x=1711757735; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:feedback-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=whmVMHuEBXgRIj9diBxuHvfTM2nWAuNzeXBmM3HZHOY=; b=rGExFKKgbRp/mNhzSc4q85yx7mpSH7C/+bvJ81svoAOIDv/w9GxgMDHRD2sdlWcFaI 5lXr91+4RDJ8aLuFN+ChfDDOlAMQ7ui02QbvLt/LMml6q2c0FyW+VV6a2/AQZUrgNLqt B9Z8KGGFmMRNDenCuYK7Ula9Bx68vY0xsQR+7xyDwXM73QruAMN629clFFBmfiETEaJb 0Huq/DrWibPjlnp+zlkN2RqQKugHm6N2ysELSy57X/P5wqbDtMnDD4Cnh/d3xBFfNRXj a7e1w1AY3sC9smQ+2YjzfkYv7Ult93cL+AXt2MFCCzKghODyNuceOZcGtEzlBNjQFOxn dUPw== X-Forwarded-Encrypted: i=1; AJvYcCUvOPjrPtV1XrUwOxo2wrWm6Y6/gYyHZuu43qK1yoNe2q+oFHAJfbA3wlG83ySKVBC1bOGPSCQO1ugfy8ljkDt773L9NjBJxk2oo1yQDhZjo1Jptzw= X-Gm-Message-State: AOJu0Yx1MZnfvGaN9+ww7JBFmgr5dMOu6gJqCBtP/8gV/Xz/ZoM0NI+9 OXc0JfYpfjSmzpzyTUg6eiBsmVU8mrFL+OmIgKq9TIMkGM+zfoan X-Google-Smtp-Source: AGHT+IHOo27LLL5BHPFVw2rGuSB7QeBeHaMSJwGhonKrbQGbCwa6LdZz9tGDqQaK9+FrfZtfSfp36A== X-Received: by 2002:a05:6214:2124:b0:691:3d91:80bb with SMTP id r4-20020a056214212400b006913d9180bbmr1044086qvc.11.1711152935122; Fri, 22 Mar 2024 17:15:35 -0700 (PDT) Received: from auth2-smtp.messagingengine.com (auth2-smtp.messagingengine.com. [66.111.4.228]) by smtp.gmail.com with ESMTPSA id i11-20020ad45c6b000000b0069068161388sm1558668qvh.131.2024.03.22.17.15.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 17:15:34 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailauth.nyi.internal (Postfix) with ESMTP id 8AF5227C005B; Fri, 22 Mar 2024 20:15:32 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Fri, 22 Mar 2024 20:15:32 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledruddtfedgvdduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvdenucfhrhhomhepuehoqhhu nhcuhfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrihhlrdgtohhmqeenucggtffrrg htthgvrhhnpefftdeihfeigedtvdeuueffieetvedtgeejuefhhffgudfgfeeggfeftdei geehvdenucffohhmrghinhepghhithhhuhgsrdgtohhmnecuvehluhhsthgvrhfuihiivg eptdenucfrrghrrghmpehmrghilhhfrhhomhepsghoqhhunhdomhgvshhmthhprghuthhh phgvrhhsohhnrghlihhthidqieelvdeghedtieegqddujeejkeehheehvddqsghoqhhunh drfhgvnhhgpeepghhmrghilhdrtghomhesfhhigihmvgdrnhgrmhgv X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 22 Mar 2024 20:15:31 -0400 (EDT) Date: Fri, 22 Mar 2024 17:15:08 -0700 From: Boqun Feng To: Kent Overstreet 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 , =?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 , 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: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240322_171537_137832_D9435F11 X-CRM114-Status: GOOD ( 32.76 ) 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 07:57:41PM -0400, Kent Overstreet wrote: > 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 wonder about that. The disadvantage of only supporting LKMM atomics is > that we'll be incompatible with third party code, and we don't want to > be rolling all of our own data structures forever. > A possible solution to that is a set of C++ memory model atomics implemented by LKMM atomics. That should be possible. > Do we see a path towards eventually supporting the standard Rust model? > Things that Rust/C++ memory model don't suppor but we use are at least: mixed size atomics (cmpxchg a u64, but read a u8 from another thread), dependencies (we used a lot in fast path), so it's not trivial. There are also issues like where one Rust thread does a store(.., RELEASE), and a C thread does a rcu_deference(), in practice, it probably works but no one works out (and no one would work out) a model to describe such an interaction. Regards, Boqun > Perhaps LKMM atomics could be reworked to be a layer on top of C/C++ > atomics. When I last looked, they didn't look completely incompatible; > rather, there is a common subset that both support with the same > semantics, and either has some things that it supports and the other > doesn't (i.e., LKMLL atomics have smp_mb__after_atomic(); this is just a > straightforward optimization to avoid an unnecessary barrier on > architectures where the atomic already provided it). _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel