Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp1473632lqp; Fri, 22 Mar 2024 16:58:06 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVt2NWCV3CJ5CpBDf0LoBC0Q6zPJPR9G62cVARqS7JSOS2JwLGZzP6MXyAZJZrNizfylU9cC58lHv3bMF6Ki1Pa4WJasr86bSWIGFONfQ== X-Google-Smtp-Source: AGHT+IGzkPu8Jc5Rbo/qdba6qgJySzUo2vP+7kv+icgYoMk7Cqe/PaNyUtj11BaLXTZ9o7yyIkD6 X-Received: by 2002:a19:5f5a:0:b0:513:c2e6:fbb2 with SMTP id a26-20020a195f5a000000b00513c2e6fbb2mr516989lfj.62.1711151886580; Fri, 22 Mar 2024 16:58:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711151886; cv=pass; d=google.com; s=arc-20160816; b=j8Fd3/PAF13KIELWE346h+KWdVTcUriRvGknYTEjD2auMQpgkxDff+M6UHrh043CUI /73PVWH4CGTKVRdZpY0CkcWOslk6w2kvtY6QZzXM3Dwrq/wXkNiy0+ml2/Z0t8jk2ciS 12j2eTROJiLubnPXlDhGtD+AZXtYsvyWi+inhWytQXRE3jrJ4KTuDFmVCJaLKvIULaPI S66f4q0w4nyuD8yN2sut6FIL0dCT1se9tGaZ7wrvAzI/TSXSBHGmIGfcNDB4J6+ni/B4 zqkWgWG3EEqbpb/YAkx8ubpHc8pQdFLwwuMCkeZFQBKful0tQqF/QjIhTwstDqtIh4nL fBLw== 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:dkim-signature:date; bh=hzaOVOcWvV/nA21QW9YCB5ZLkXvzMsM78SbUFC/cEIU=; fh=SgekPetps+JCBgfNx6uf7s2OjSbXWTTmsPA2TjM/D0k=; b=gF06H4MYG1zYd/uiefgQdHUyo2vQvHxMqyi8IddsbgGxf3oqYJ39r4mNdmmxl2Pgly npOSOjxjcTTd9cQifnicXC+CpjcCAFNnZNICMWChoUz21rWcA1c4pYzboOrc0xfza9iD npWhVnUqywcM+3+BHggyOYbagL9tE0trQjsbMcw+8RWsFCCtlZrwnCtvXBaXJuRv1Izr /UYR7YZnEmfKoze+6XIZWX4MFckM4Y9nBOZm+YBAWGHRbJHaONmxgffGrwE7QRzOpqMR nfgMzGe7XhcycZKYXHi2K4E8evDXaYfr7rxHETxdoQTCephECS+CK1mnC68UBMip0db+ pmcg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=u71BeYo8; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-112119-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112119-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id sh18-20020a1709076e9200b00a474234e5c3si147335ejc.810.2024.03.22.16.58.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 16:58:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-112119-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=u71BeYo8; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-112119-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112119-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 447121F22AD4 for ; Fri, 22 Mar 2024 23:58:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3111682D72; Fri, 22 Mar 2024 23:57:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="u71BeYo8" Received: from out-184.mta1.migadu.com (out-184.mta1.migadu.com [95.215.58.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 608158289E for ; Fri, 22 Mar 2024 23:57:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.184 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711151874; cv=none; b=OPq3fTs6TJaDKqvPvwZmOpCBt1LDcc99YwDSyQXpnMDEDB+nM7a1c7Yf44M8QiDaNNfTLWVy+F9MrytIr9dBml7hnVO9DtZFDJ/u/U0WPWUtb6NmjXiVocPPpJFK8qXnyt23T08gaWzqXmz5aUSAtXTHeoLXkXuVU5PGvTp95+0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711151874; c=relaxed/simple; bh=gHKzUe8JzF89dHoFO0MdDMvtGmOiIhrk5YeCQO2D14Q=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Q6jSYePefEyNOQhml6zgWT3kbbqftDPYJJ3emniIDy/T+tpUxg0SfQmkkEt94g8cJJ8j0ZEbvUgmQmNM8Rs0NFeFDsoTUZbO2n0cncqsCTj5H1nSyE7r9rS0uiCedEtxA7YccpDLBxTolFNNSQW20AH0e4rxrfHVgYVyuKimBdo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=u71BeYo8; arc=none smtp.client-ip=95.215.58.184 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Date: Fri, 22 Mar 2024 19:57:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1711151869; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=hzaOVOcWvV/nA21QW9YCB5ZLkXvzMsM78SbUFC/cEIU=; b=u71BeYo8ZPPBx6zr7bjzI7c8dcXHxeJlKAd5L/MOx7wYcQg4q0IZx9gmNGikve9VrVZYQy ZefMTKuAcyE0DNidFJO0phvDd/T3yRH/CZvA7jq3XM6XsFq1j7rnE9x1MC1/FN7Qktod1f QyjixmECOSwLtVmjm8Br0fFffn0ZVxk= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Kent Overstreet 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 , =?utf-8?B?QmrDtnJu?= 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: <20240322233838.868874-1-boqun.feng@gmail.com> X-Migadu-Flow: FLOW_OUT 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. Do we see a path towards eventually supporting the standard Rust model? 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).