Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp1764571lqp; Sat, 23 Mar 2024 07:55:36 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXoKW2ZhcGReWco8uqVlfJH8F4k68Kdu0P5pQ+xidoXCz0n+oY6DHRQcZEEYJxhwR/EkDzr4WAAHPHMtYgK7KBP8kaSA9UL/TNinkgEbQ== X-Google-Smtp-Source: AGHT+IF0YDKOLPeMMP0VC0uoG4TWYm4kp+8KR9Pm2YqqnIiLuth6NsZk6PB/rRV8jtp0Frhli9qA X-Received: by 2002:a17:906:802:b0:a47:1c19:9a48 with SMTP id e2-20020a170906080200b00a471c199a48mr1757333ejd.28.1711205735910; Sat, 23 Mar 2024 07:55:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711205735; cv=pass; d=google.com; s=arc-20160816; b=igXxO2ui72dnLmszfGTFYGco/zeUEfBa1lgj9G/kg+pdTonLQqdsyL7uaNd9G76U0g p8Fff8ZA7Vz3lt2xXPKXmb4S3DLEYGkl98eAGVUNX0MDypsuh/UX5ZJgljY0hwW8r1i4 xllqnYynN0wH0RCp0tVi2c/fmX0u1pjVi9yxupWpUF1cX72ZWZOP+j+JlZy5poyqbjmV UhoFYbialtEo42+KYpsMQVOg3ZA0W7LATS1u1vN6nKUaubTUjXggGOWHU3nvKqmh4Scr /y3nx4fGNT8SqCYSsXMS59nc/URK2/6KPFjWFh7khEfJsEs+O9gOsFzY4Fk8E1mhAhT+ 3+1A== 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=VRfoDMeQr45A3YPnCIYGOXROndTyGMuSPLDLPYakgoQ=; fh=rI4e3kkLbpv9fvZpwVreXsyaqx8Bp8SJ/O97kv0u1sU=; b=tuGuHp94iUAvbsLkKZ9XKFskp2KOxJzEI/TvkfFQXUgE6+h5NbGb2ixRTCsLW1BBsk wdmLG6I5EMB5viDxYWbQG11XH4oYseQSRNZYNXOFf7uodxvyfOZI9XJ1iO0ACqLYgeIr 99CliTGk3qpRmqTPX8qhkgnO1RLXs17Aa40Bvd5KW1p/zkxDUp2gL+vd6kjhpUKggau+ cudhQ3GonvUE3389BBAWrewwuEnCYhSdxs7BcgQWP9DiTOKSQk9CG+gZu1fXd4xGXrm3 SADSIy2HlpONtXnplQduSBmYgfAVXOLox+4RmzDAjsVRqtC9k3+2LclFBlTn9JunYtRr y+yg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=m6qd8GfX; 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-112385-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112385-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id by4-20020a170906a2c400b00a468c0de70esi862774ejb.901.2024.03.23.07.55.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Mar 2024 07:55:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-112385-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=m6qd8GfX; 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-112385-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112385-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 76F491F21797 for ; Sat, 23 Mar 2024 14:55:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4774643AD7; Sat, 23 Mar 2024 14:55:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="m6qd8GfX" Received: from mail-qt1-f174.google.com (mail-qt1-f174.google.com [209.85.160.174]) (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 D215317583; Sat, 23 Mar 2024 14:55:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711205720; cv=none; b=nGXJd1a7e2tsv8n4s2rp0Qq3BRiZGr0aMf1zjcqS0qk8MBHey0Kie/uqKV8PFPu0tLiiFebaqM2nDDN4vewRAgBE8ZY4K+T9nlIjC6F5OXT027kG5FHZ9OW73JTC2+O6K9PTid3/o8ORcquessKLkQfVqe+7m6Dr27zLKYz2f/w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711205720; c=relaxed/simple; bh=fQ82XO62lP17bp9mjIw1zlMFrpZjOT2ZJn2+KAtC9V0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=cvgjGeuJfc3GrKnomKTHgYZjyyKZpja9fmES86sqeIgXVeF+NMoF/veqbM7IYO0C9wt/fUMu8LRlGacQEZWy7de1/BkG30Oe3oS/awoc/jDbePM0sStHUeHQ8gGdDCKDvswmV9Xl8NmPlje2Vo7Vq6meLwt/ySZDb17xVOOHMQA= 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=m6qd8GfX; arc=none smtp.client-ip=209.85.160.174 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-qt1-f174.google.com with SMTP id d75a77b69052e-430ca04b09bso22546661cf.1; Sat, 23 Mar 2024 07:55:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711205718; x=1711810518; 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=VRfoDMeQr45A3YPnCIYGOXROndTyGMuSPLDLPYakgoQ=; b=m6qd8GfXvMm8O9fG8NUM1Ckb/gYAT2F1i2ssQDKvelKZwJ5HOeTy/2OWvdNrepZz9A VVyYO/WT9Jqii82RdnA7xdGj0jb3iYuuhXWnYcOUfzj1TLWZPrnOMOyo0Uw1NVRJHKzo FxDGchPggi4Zi6EdL22TB31j30YdbHJ1q+scKGbWwotNA0+uAH5Qdf0ANs2n/wjKzc6x OXtD0qadKTX9yXQti4ZtY3rhGbG3zSyJ6f/aQDFQ0yne6vOh0ZbUa5EryxXtMhYd2zAn v0yfiLHoZgRb1RFOorxeg1fqBt+1+fZKxaaeEPHg3R3pOmU264/Bi9TBHlTlHpf6atsd CZKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711205718; x=1711810518; 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=VRfoDMeQr45A3YPnCIYGOXROndTyGMuSPLDLPYakgoQ=; b=XyAMBKUSTx+8ds32C9ZjgGG9oxLKj8DGWlhfYTVl+l7Sjrw2ShzJ8KpPVO/LxnJaGJ 7dwqT54Ij+dIiaOxRseto32ox7ziLWlnQb+VeeqCop3abqd1W6qNXEXR+qs6vo4dCB3i Wb6HQPJ3dF5228TdF1bfB5h7/yHDvQW8IV7XK7DVlw1GsJXrP07Fmh2zdsIvPxGuUoe7 t+JSf7NviHIn62q2EqZvDpUTHGOiUndeG5um8EU/x6bLb3nhtF4Q3iOz+lTrGntyoNoC AjbwC8RsyqhJ3sRBE1uq4NAXD5B241bqYNBfyc7n0EGI8vrkKsy6J8SM7YSORPK2MJrb wpUA== X-Forwarded-Encrypted: i=1; AJvYcCXNg7pL37uxWm4hgjyL6eSBgKfrP55iDfe3dLjL3OdEeFVD2fx9zTNMcMfoI0CQRLmpVN3BJQZnC2pXCKmLNCQ9rFQtDvHK26BbiLFteAJb7lyRTxEQfeIVq+xkKbH0pnjn6pK15A2EqJtpyKjSynH7H1WLutk0z0U4sHZXpPMBmfeGJHW3MmySQdAHHNawQSr6L0w371/rP4+d9MxI+7JC8pC7oOTARg== X-Gm-Message-State: AOJu0YxYNJbV9S3+d3yBBxcsrCVf+BM1YqFk66H6DAMmwROy7x2auokX 4JPh06xZZLXuOGEe7+cn3hKE+V7nvdSbQKr9UHYU8D1Njj85lVQ3 X-Received: by 2002:a05:622a:1994:b0:431:3e65:3bd7 with SMTP id u20-20020a05622a199400b004313e653bd7mr2246075qtc.47.1711205717718; Sat, 23 Mar 2024 07:55:17 -0700 (PDT) Received: from fauth2-smtp.messagingengine.com (fauth2-smtp.messagingengine.com. [103.168.172.201]) by smtp.gmail.com with ESMTPSA id r12-20020ac85e8c000000b00431236d1f56sm843488qtx.30.2024.03.23.07.55.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Mar 2024 07:55:17 -0700 (PDT) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfauth.nyi.internal (Postfix) with ESMTP id 551D41200032; Sat, 23 Mar 2024 10:55:16 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Sat, 23 Mar 2024 10:55:16 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledruddtgedgjedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvdenucfhrhhomhepuehoqhhu nhcuhfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrihhlrdgtohhmqeenucggtffrrg htthgvrhhnpeehudfgudffffetuedtvdehueevledvhfelleeivedtgeeuhfegueeviedu ffeivdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe gsohhquhhnodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqdeiledvgeehtdei gedqudejjeekheehhedvqdgsohhquhhnrdhfvghngheppehgmhgrihhlrdgtohhmsehfih igmhgvrdhnrghmvg X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 23 Mar 2024 10:55:13 -0400 (EDT) Date: Sat, 23 Mar 2024 07:55:12 -0700 From: Boqun Feng To: Andrew Lunn Cc: Kent Overstreet , 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> <03f629b6-1e4e-4689-9b69-db0b75577822@lunn.ch> 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 Sat, Mar 23, 2024 at 07:41:28AM -0700, Boqun Feng wrote: > On Sat, Mar 23, 2024 at 03:29:11PM +0100, Andrew Lunn wrote: > > > 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. > > > > Isn't that what Paul E. McKenney litmus tests are all about? > > > > Litmus tests (or herd, or any other memory model tools) works for either > LKMM or C++ memory model. But there is no model I'm aware of works for > the communication between two memory models. So for example: > > Rust thread: > > let mut foo: Box = ...; > foo.a = 1; > let global_ptr: &AtomicPtr = ...; > global_ptr.store(foo.leak() as _, RELEASE); > > > C thread: > > rcu_read_lock(); > > foo = rcu_dereference(global_ptr); > if (foo) { > r1 = foo->a; > } > > rcu_read_unlock(); > > no tool or model yet to guarantee "r1" is 1, but yeah, in practice for > the case we care, it's probably guaranteed. But no tool or model means > challenging for code reasoning. > There are also cases where two similar APIs from C++ memory model and LKMM have different semantics, for example, a SeqCst atomic in C++ memory model doesn't imply a full barrier, while a fully ordered LKMM atomic does: Rust: a.store(1, RELAXED); x.fetch_add(1, SeqCst); b.store(2, RELAXED); // ^ writes to a and b are not ordered. C: WRITE_ONCE(*a, 1); atomic_fetch_add(x, 1); WRITE_ONCE(*b, 2); // ^ writes to a and b are ordered. So if you used to have two parts synchronizing each other with LKMM atomics, converting one side to Rust *and* using Rust atomics requires much caution. Regards, Boqun > Regards, > Boqun > > > tools/memory-model/litmus-test > > > > Andrew