Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp1480535lqp; Fri, 22 Mar 2024 17:15:52 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW57MgfXolbHE9JFC6fg8umVdrapv6aLHfhyxx6E9AJj/sbFHlQoxv75g3ddiWavaK404euW7fziAEp6o+3Ewq88eVz8afCq9/I8nCITg== X-Google-Smtp-Source: AGHT+IH1yCvmnVtA3HpboZ64NMM4mf5J4L36LgH5rnYsI9Tor0bGIW61WoG96Rzsqbw31F8x6zno X-Received: by 2002:a17:90a:f001:b0:29f:76d4:306a with SMTP id bt1-20020a17090af00100b0029f76d4306amr558275pjb.24.1711152952021; Fri, 22 Mar 2024 17:15:52 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711152952; cv=pass; d=google.com; s=arc-20160816; b=B5HyGLUHaiBieZRLV0z4Ylf5d3gCk8YSDg7uH8ClQ5mZCHJxN89LtXAwuA56xa/23M clM4MTkRF4ChlGa9PJC8a0EJc5KdL0GDlMPz94gxT6jisDN2r6Bqrz7/+XOxs65eAV2l zO9scx22+BSx9hk2ZwKpQdwhP80HpDDAHKR9S7D09F7eKIz1vBobNbpk8jZ0W19QZsW3 x6GA/LtSnkYrwI354h90fjqHIzzjfbnWVrqAL8grMAMLIxMVJGLkU3kzeALCXLRuXSF9 0ftp/nV6F+WJnKLaegWVz8WlJNQDc4tw1RKyaJRWjSRle93Xsf8JIVKF9rgvRbUIIUKt qYwQ== 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:date:feedback-id:dkim-signature; bh=whmVMHuEBXgRIj9diBxuHvfTM2nWAuNzeXBmM3HZHOY=; fh=6CA1wNAgJHLiBwC82mUGvPLFGylLvMoJVY4jPpPVmv4=; b=MUZ/sK3vZkObNKVbTQvRUnIlrrpR5TM8UOgx2MCnT5lscUSQNK6TUOA0XQkbUe4GVZ 0Kmx9387dPD1FlLSQrdQnp+ETwNJafaOe29jv6cdk6TzLt+MOSpp/9Ow/9n9nPUxS3Ux 7I+Jk6z+JJAtkD7zHHVFq4TXyZ3FCOVMWWWNWfjZnWjvTPvaVVNEPGr02QmI4RAlCRRR K0Ge1omqIDl+NMor0Y4jUThHs1O15SCyubtwvcuWMc+2d24Turtz/NN5Yw55OkGtqte9 n/vbOq5F1SIr/TmOiD+L/98xDMbuPsjmHIBfpnM5I9hfaE7LIaI1HZWNbh617YyCeO3Z h0Tg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=k1kWeaxq; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-112127-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112127-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id r22-20020a17090a941600b0029de97229e8si172483pjo.189.2024.03.22.17.15.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 17:15:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-112127-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=k1kWeaxq; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-112127-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112127-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id A1727283E42 for ; Sat, 23 Mar 2024 00:15:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CD6691841; Sat, 23 Mar 2024 00:15:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="k1kWeaxq" Received: from mail-qv1-f41.google.com (mail-qv1-f41.google.com [209.85.219.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 44CEC1FA1; Sat, 23 Mar 2024 00:15:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711152937; cv=none; b=q7qdFV2soRwRRfle4fuZlwJo0EaNrCewYId1qWniFEJ4Aa1zni6bFDlwliN5HXzS/D0Y24jF+D+SO6Rk408nPOyOeRRKeTgc2OIn+gpXh9Wei9TNDRtjpMHEFzBVMxn7IX9CAEqw8362VV/DCAA3+2g3uJA2WaU3H1kBUdI+Clo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711152937; c=relaxed/simple; bh=VTI9Sf3VccnbABPGXsY1j2qF+SStz+OEfznm86+qGLM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=sMfn5lJhzTWNh6b+EX2ikc7hGsLITAznC7gomrRrmYVi64luhMf+/Et9MrPeDevGPul0hFuJMia9+lKIDvEi+o/Yd6OhusmOgHG2/BDvTFD1ji435vOJLuWaZkhAdGTAbPxhfCkWY+Ow7GyzNW9/fKvaCV35oKvkJ2fAGSVKc/Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=k1kWeaxq; arc=none smtp.client-ip=209.85.219.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-qv1-f41.google.com with SMTP id 6a1803df08f44-690d7a8f904so34549316d6.1; Fri, 22 Mar 2024 17:15:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711152935; x=1711757735; darn=vger.kernel.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=k1kWeaxqCSkS5z1d046Rs4gFuYTzg/F7efu0e2m49a0LdRk9SSA3FiIdEGMixDWivT +G+f8OVtc+haWHPUIVXvWWOCs3uBNTUH9LTZ9q9GcxuOj9KWkk+YUQVzRVJ4Ke14XuSl WI2OfxbDuIVzSsop/nOvJYjpP/y9KoSrtvT3t9suc+txKEJacPuMzIuhXfUcJ1K0v4hI 1Civ2To5yc//w/fQBFnV5UC3qgiqJkE7J57gFWZJy6UN3DqYjG090biAXBdydHhFrWxs CzNhuXZuMUFsuDTLLbMXg+LfUacN2QeMZUATGy93u2RmhbZ706EhAHw76Q8Kyc6SRm+q JN3g== 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=S8gpeG8DGRZh75npbyXFtdKruG9MwpPSdnlmC1Wo0TA63PqZplFDUXBmIC6X6VOFPa lV8gK3roTTqUDV72TCNAlzMKy07Dol0Y+8SATG/o7eKycrNLqqhpprrKAgw6JS+5fNvQ 4x8Hu6FWg5mUuCF/EmpoCgK/Bo7D4rx23G2P+JDIDHCqoF/cWcNCr8xzgdLJ2blpHzMB wafdJKNjww89+z3W4J2otgx6sHuqSKtryaQ2tkRYAJBLFB4otlcLGCp3dRlwYIbkyCxF oujYurA2dGPVfisn8YwfkJ65qyZQ3PYpOzdtRpiJnCN9hI3IV8OWf4KCFMADMXMV4/oW qU4g== X-Forwarded-Encrypted: i=1; AJvYcCVmoHBpogub1u0zunyXe7bd5z2YlYTry2/X6okExnf6LzLPNl9AEn8roZsibrQzUPhAD2T0dlMZu7zs2LUzDDUzAZ0JH5RZxCRucupjCVb49acA7I5yadqz2OuofztbH7MBcUVDRJUXGSl4NIfdUk/zbj1N/eGTnvmdih24qwQoSflXqoRiKDE= X-Gm-Message-State: AOJu0Ywx6M2dtnXqaLMxOF0BSEylQdLRq7kIJfu6MXVqy61bof7fkD8F jezp8nuOgT4b6ATNcTR0R4bw3ugM5iPd3ISXGJTi8+dWTDIcvttm 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> 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: 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).