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 98050C27C6E for ; Mon, 17 Jun 2024 05:36:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=lJeIgTT6Qh/sxRKpkuk9BR9tYX+tCBNvv142Tf4kLOk=; b=Y9xQ0BqAMmluQZFO3WU30AaPwr eEAK27Vkdclfj2UQarV+g7wcZSaSPPtsQ0mn2gsswru3IWVmNRRVl/aeQklrvhnsZ4pBfSVEtVD9e Uayj2kchlcqcjSy9clOgLOsFE/aS09A1BbbJ4Z5fZvSbgjxPlTVTvpRJBBvkqvYeDez21nc0YjMic 6QSLjYzXpTTauc25GTxGV1dAXRIme3yAikoMeYQDsfLgFFVeGNjRJnb2RA2KlpextT1UR4PtuiHjr Sb03o4Gdq5FBZjE3S7eBxhVNK12zJ0ucqICgAfLcf9q2wbn7YgByab2X55v2nHoNFQNcGUDzX0a/u GDWdekSQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sJ52a-00000009Ehy-1pFn; Mon, 17 Jun 2024 05:36:28 +0000 Received: from mail-qk1-x72b.google.com ([2607:f8b0:4864:20::72b]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sJ52V-00000009Ego-3rCg for linux-arm-kernel@lists.infradead.org; Mon, 17 Jun 2024 05:36:26 +0000 Received: by mail-qk1-x72b.google.com with SMTP id af79cd13be357-797a7f9b52eso317638185a.2 for ; Sun, 16 Jun 2024 22:36:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718602580; x=1719207380; 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=lJeIgTT6Qh/sxRKpkuk9BR9tYX+tCBNvv142Tf4kLOk=; b=Miwgjqo89SlSDIyLzy6JJC7uQ9ZlF+KLdwCN8BbSHFf2eDggtK/+QIqzCznhsZ1WiL MpmOns/FuJ/4EJkspil0sXtZfYk3MM02taeD0Wz2nGJc+VFwXFaQmtyjXThtdHmEgqat MgoEpD8VuyZV6I5I/qCH4flVTbPfCvaJkBDiIfK/cChMYNUwY5hThO+cMo/lwjmv0IfO 9ewXZ8QsbSGpUDLFSmpuKgHJh/0GQMSF98Z2H30Ky2af7B8TNTHJimVbyMnkXqp2j77o GPA1i7v/eFMz7/4zBQPH7+CjHupCwfb91GA/vA5oPMxITPk1foZ0tuZYn6wXCBJhGElQ F9rQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718602580; x=1719207380; 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=lJeIgTT6Qh/sxRKpkuk9BR9tYX+tCBNvv142Tf4kLOk=; b=F5S2PVG7BLJbNUgro/DplcYaasN6J5x0WaceeVZCM3x3W/+PyREF4fhcCoR3JYQ8UH igzZthpyryduUhmTcjqyQsYnBPfgZOPVVhHq0Mkr5SgaaLnw1ESY8TXQ32xyVbEoBl0Z 4u0S7J5b7ffrIuvl+ZhSt5b3Ov3pYAiWCpn/+syrFYKaa7RvFm1ehODPrshQildzuDVz dgnVaerzhl+wubiwiWSw5RkUTYDKcdYQrIFhGppalEEz2VbSiiCrnMYgwYPvgG0nasH5 FPtVjgbsi2EiAI6EMI225Yb49ENgZsK8eRVfYvErhBgghgZQy6ltWr+YJI0G24JYZe/V Kjlw== X-Forwarded-Encrypted: i=1; AJvYcCWVhPY9pt8gMwSBp9O+eIvqbphlY2a5mYLdZbK1QDKJ2VGCPex9RvkQ9KSzu0NlBBoewf1Nxfmlk8iRCFUTcEqo2qn0sZ+Ug1+ODhzN3+O6tYC5uio= X-Gm-Message-State: AOJu0Yyoxlz7wZqDZVGDdEV+rwQly600RQ1orzFaATFDTnjRQCXdu+UE ukFNaBl9H+tbmDAU8pN0A+fv5xv3Q+xcs8eL+H1F3kl2RnkCQCCp X-Google-Smtp-Source: AGHT+IHQxDKmzbQN3wDBWu2GUvw9lePhre6ZMLcLvCTUY/3kdj6Q6oqMmjAj+h53BtENoBkKnF5x2Q== X-Received: by 2002:a05:620a:1921:b0:797:b67e:e843 with SMTP id af79cd13be357-798d258cf02mr869592085a.48.1718602580414; Sun, 16 Jun 2024 22:36:20 -0700 (PDT) Received: from fauth2-smtp.messagingengine.com (fauth2-smtp.messagingengine.com. [103.168.172.201]) by smtp.gmail.com with ESMTPSA id af79cd13be357-798abe4f35dsm398786285a.122.2024.06.16.22.36.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Jun 2024 22:36:19 -0700 (PDT) Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfauth.nyi.internal (Postfix) with ESMTP id CAEB21200066; Mon, 17 Jun 2024 01:36:18 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Mon, 17 Jun 2024 01:36:18 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrfedvgedgkeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvdenucfhrhhomhepuehoqhhu nhcuhfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrihhlrdgtohhmqeenucggtffrrg htthgvrhhnpedtteeuudejhfekffeiudeuvddvheduteejudeiieffhedvhffhffevtefg tdevtdenucffohhmrghinheptghrrghtvghsrdhiohdpghhithhhuhgsrdgtohhmnecuve hluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepsghoqhhunhdo mhgvshhmthhprghuthhhphgvrhhsohhnrghlihhthidqieelvdeghedtieegqddujeejke ehheehvddqsghoqhhunhdrfhgvnhhgpeepghhmrghilhdrtghomhesfhhigihmvgdrnhgr mhgv X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 17 Jun 2024 01:36:17 -0400 (EDT) Date: Sun, 16 Jun 2024 22:36:13 -0700 From: Boqun Feng To: Gary Guo Cc: John Hubbard , Miguel Ojeda , 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 , =?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, Trevor Gross , dakr@redhat.com Subject: Re: [RFC 2/2] rust: sync: Add atomic support Message-ID: References: <79239550-dd6e-4738-acea-e7df50176487@nvidia.com> <20240616155145.54371240.gary@garyguo.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240616_223624_085497_17701E2E X-CRM114-Status: GOOD ( 29.24 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Sun, Jun 16, 2024 at 08:06:05AM -0700, Boqun Feng wrote: [...] > > > > Note that crossbeam's AtomicCell is also generic, and crossbeam is used > > by tons of crates. As Miguel mentioned, I think it's very likely that in > > the future we want be able to do atomics on new types (e.g. for > > seqlocks perhaps). We probably don't need the non-lock-free fallback of > > Good, another design bit, thank you! > > What's our overall idea on sub-word types, like Atomic and > Atomic, do we plan to say no to them, or they could have a limited > APIs? IIUC, some operations on them are relatively sub-optimal on some > architectures, supporting the same set of API as i32 and i64 is probably > a bad idea. > > Another thing in my mind is making `Atomic` > > pub struct Atomic { ... } > > so that `Atomic` will always be `Sync`, because quite frankly, an > atomic type that cannot `Sync` is pointless. > Also, how do we avoid this issue [1] in kernel? `atomic_load()` in C is implemented as READ_ONCE() and it's, at most time, a volatile read, so the eventual code is: let a: (u8, u16) = (1, 2); let b = unsafe { core::ptr::read_volatile::(&a as *const _ as *const i32) }; I know we probably ignore data race here and treat `read_volatile` as a dependency read per LKMM [2]. But this is an using of uninitialized data, so it's a bit different. We can do what https://crates.io/crates/atomic does: pub struct Atomic { ... } , where `NoUinit` means no internal padding bytes, but it loses the ability to put a #[repr(u32)] pub enum Foo { .. } into `Atomic`, right? Which is probably a case you want to support? Regards, Boqun [1]: https://github.com/crossbeam-rs/crossbeam/issues/748#issuecomment-1133926617 [2]: tools/memory-model/Documentation/access-marking.txt > Regards, > Boqun > > > crossbeam's AtomicCell, but the lock-free subset with newtype support > > is desirable. > > > > People in general don't use the `atomic` crate because it provides no > > additional feature compared to the standard library. But it doesn't > > really mean that the standard library's atomic design is good. > > > > People decided to use AtomicT and NonZeroT instead of Atomic or > > NonZero long time ago, but many now thinks the decision was bad. > > Introduction of NonZero is a good example of it. NonZeroT are now > > all type aliases of NonZero. > > > > I also don't see any downside in using generics. We can provide type > > aliases so people can use `AtomicI32` and `AtomicI64` when they want > > their code to be compatible with userspace Rust can still do so. > > > > `Atomic` is also just aesthetically better than `AtomicI32` IMO. > > When all other types look like `NonZero`, `Wrapping`, I don't > > think we should have `AtomicI32` just because "it's done this way in > > Rust std". Our alloc already deviates a lot from Rust std. > > > > Best, > > Gary