From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qt1-f179.google.com (mail-qt1-f179.google.com [209.85.160.179]) (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 71D9F1991D2; Fri, 4 Jul 2025 22:30:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751668236; cv=none; b=gGPJYCuK4DnzwjAW0gLHG+uGufaCaN16bJDrzCFRbWyNBEmQTCXs/31yl0HOjZSe33lzrTRgjW2SHPIYHsqcKRNPU86fg9xCJg8nL5UldXpNt8mc1gNPddKdBryNfnRvoEcwLjPqIjtckQ4DL2PezK3ff4YasBNgSONWrErGBQ4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751668236; c=relaxed/simple; bh=V3QcC619cgfXh78rzL/aBg2aB9/ohO0hsNXEcmi7jVE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=LfP8DA/nir6YTjzR82qZRfBwvqQXWyhrxF/GxguRpF3hnKI5GBH/bXK6EtQ6ZamVuz7GYAUa5EXoMbZZeVTc3gTtuGnkiX0ooWWe/9jIHvuB/fpjlRCyRQKgDYxBLIA2mT84L7BEqUaDQ62AEyUi6xl2N9/4Rqx2NVf0epdWSEE= 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=RSHJzpLY; arc=none smtp.client-ip=209.85.160.179 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RSHJzpLY" Received: by mail-qt1-f179.google.com with SMTP id d75a77b69052e-4a4bb155edeso16429801cf.2; Fri, 04 Jul 2025 15:30:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1751668233; x=1752273033; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :feedback-id:from:to:cc:subject:date:message-id:reply-to; bh=nefZOk+kep9tY/NwNpHy33HLJmnyE2SxXn/pEIOWo0I=; b=RSHJzpLYBdyNtGWVf+oMFctr1XWDrpnZAUFZfNcJXg/h80zBMX9sb3ZZxxP8SVlLPf rK4+7dzKWzYPvPMh3i2xxNdgE4NHThFVBysTINL3oWa95c/4OR7emQvS7pg33KcWwArw gMoLYXczmZmudwGzkm/IypBayzjV7bgkhT5X22eB3OyEYcSij2S5/pkR1vu4SeaDB2AQ Y4+YeGYItylNLxnNaMKrCVMoQwZTPo9999JgvUlZ1pQ2YpM9G37Y2JDicOdvfFebo7Ww IorENAz6bHG2NoZDKKbv7pNLowTijoWaiLdNT268+CW5SsnUVRx/WuLDDGrag2FScIQi QNKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751668233; x=1752273033; h=in-reply-to:content-transfer-encoding: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=nefZOk+kep9tY/NwNpHy33HLJmnyE2SxXn/pEIOWo0I=; b=jjqv/vJL3UEdgT8grNTMW6ZwKFZV30YxNb/q18o/AWYzMemSKSedSdFTr5NvQ2aR2u Otkv4vErgf1UcvAL3me+0DRWvVMtI1JUJYAxE5X4eQY7kZz7PF5jMLUus/uUaL0OaBqX 811APloeB7gphae9aemA2ZdVBuvrg5DhttGul0TpnpG/CGS+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4ct/hxx/mmwZ2bUHzXAYzptMqwal+VpPBqDDwH0PZjIqpb+XOdkgZ9e4wftMhzLVM0iXQ== X-Received: by 2002:a05:622a:1310:b0:4a7:8916:90a1 with SMTP id d75a77b69052e-4a9a6899b53mr8186101cf.22.1751668233254; Fri, 04 Jul 2025 15:30:33 -0700 (PDT) Received: from fauth-a1-smtp.messagingengine.com (fauth-a1-smtp.messagingengine.com. [103.168.172.200]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4a994a8cdc4sm21340451cf.60.2025.07.04.15.30.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Jul 2025 15:30:32 -0700 (PDT) Received: from phl-compute-06.internal (phl-compute-06.phl.internal [10.202.2.46]) by mailfauth.phl.internal (Postfix) with ESMTP id 31D3AF40066; Fri, 4 Jul 2025 18:30:32 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Fri, 04 Jul 2025 18:30:32 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgddvgeefiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpeffhffvvefukfhfgggtugfgjgesthekredttddtudenucfhrhhomhepuehoqhhunhcu hfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrihhlrdgtohhmqeenucggtffrrghtth gvrhhnpedtgeehleevffdujeffgedvlefghffhleekieeifeegveetjedvgeevueffieeh hfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegsoh hquhhnodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqdeiledvgeehtdeigedq udejjeekheehhedvqdgsohhquhhnrdhfvghngheppehgmhgrihhlrdgtohhmsehfihigmh gvrdhnrghmvgdpnhgspghrtghpthhtohepvdeipdhmohguvgepshhmthhpohhuthdprhgt phhtthhopehlohhsshhinheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepghgrrhihse hgrghrhihguhhordhnvghtpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgv rhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheprhhushhtqdhfohhrqdhlihhnuhigse hvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhkmhhmsehlihhsthhsrdhl ihhnuhigrdguvghvpdhrtghpthhtoheplhhinhhugidqrghrtghhsehvghgvrhdrkhgvrh hnvghlrdhorhhgpdhrtghpthhtohepohhjvggurgeskhgvrhhnvghlrdhorhhgpdhrtghp thhtoheprghlvgigrdhgrgihnhhorhesghhmrghilhdrtghomhdprhgtphhtthhopegsjh horhhnfegpghhhsehprhhothhonhhmrghilhdrtghomh X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 4 Jul 2025 18:30:31 -0400 (EDT) Date: Fri, 4 Jul 2025 15:30:30 -0700 From: Boqun Feng To: Benno Lossin Cc: Gary Guo , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, lkmm@lists.linux.dev, linux-arch@vger.kernel.org, Miguel Ojeda , Alex Gaynor , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Will Deacon , Peter Zijlstra , Mark Rutland , Wedson Almeida Filho , Viresh Kumar , Lyude Paul , Ingo Molnar , Mitchell Levy , "Paul E. McKenney" , Greg Kroah-Hartman , Linus Torvalds , Thomas Gleixner Subject: Re: [PATCH v5 04/10] rust: sync: atomic: Add generic atomics Message-ID: References: <20250618164934.19817-5-boqun.feng@gmail.com> <20250621123212.66fb016b.gary@garyguo.net> <20250623193019.6c425467.gary@garyguo.net> Precedence: bulk X-Mailing-List: linux-arch@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Sat, Jul 05, 2025 at 12:05:48AM +0200, Benno Lossin wrote: [..] > >> > >> I don't think there is a big difference between `Opaque` and > >> `Opaque` if we have the transmute equivalence between the two. > >> From a safety perspective, you don't gain or lose anything by using the > >> first over the second one. They both require the invariant that they are > >> valid (as `Opaque` removes that... we should really be using > >> `UnsafeCell` here instead... why aren't we doing that?). > >> > > > > I need the `UnsafePinned`-like behavior of `Atomic<*mut T>` to support > > Rcu, and I will replace it with `UnsafePinned`, once that's is > > available. > > Can you expand on this? What do you mean by "`UnsafePinned`-like > behavior"? And what does `Rcu` have to do with atomics? > `Rcu` is an RCU protected (atomic) pointer, the its definition is pub struct Rcu(Atomic<*mut T>); I need Pin<&mut Rcu> and &Rcu able to co-exist: an updater will have the access to Pin<&mut Rcu>, and all the readers will have the access to &Rcu, for that I need `Atomic<*mut T>` to be `UnsafePinned`, because `Pin<&mut Rcu>` cannot imply noalias. > > Maybe that also means `UnsafePinned` make more sense? Because if `T` > > is a pointer, it's easy to prove the provenance is there. (Note a > > `&Atomic<*mut T>` may come from a `*mut *mut T`, may be a field in C > > struct) > > Also don't understand this. > One of the usage of the atomic is being able to communicate with C side, for example, if we have a struct foo: struct foo { struct bar *b; } and writer can do this at C side: struct foo *f = ...; struct bar *b = kcalloc(*b, ...); // init b; smp_store_release(&f->b, b); and a reader at Rust side can do: #[repr(transparent)] struct Bar(binding::bar); struct Foo(Opaque); fn get_bar(foo: &Foo) { let foo_ptr = foo.0.get(); let b: *mut *mut Bar = unsafe { &raw mut (*foo_ptr).b }.cast(); // SAFETY: C side accessing this pointer with atomics. let b = unsafe { Atomic::<*mut Bar>::from_ptr(b) }; // Acquire pairs with the Release from C side; let bar_ptr = b.load(Acquire); // accessing bar. } This is the case we must support if we want to write any non-trivial synchronization code communicate with C side. And in this case, it's generally easier to reason why we can convert a *mut *mut Bar to &UnsafePinned<*mut Bar>. Regards, Boqun > --- > Cheers, > Benno