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 14375C27C6E for ; Fri, 14 Jun 2024 14:18:52 +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=+sjDmlk8xndLaxRABwpUKDEvjWtvENBQR7ofiVHlQf8=; b=PHSrwcYB63w6XD2apytvKM6Agl 5Z5TW3zAE9Symy/jUscbgospYV7mkoMIsuzbtyCKnJHnB7F8ksaNKHIjJ7ADg5QmB8GmsfMMU7QA5 IZZg3TYyKhojG3VXjsAyzpffZmwekrgQH4M6aYLPo3jaJDbcZumqkIzKml7DyhLvp3NzzuMsYlSpo /teuVmByQ9jUEb4+nzT484EfymUQnav3oUoqL8CX2ZHGOrUiISHtkGTRUoym07yExYu8VUXNcqgZ9 nK7sMLL2Hkycg1VjIGGe5PxyHTUvaoSypN82eE2yLIitpn3qdUSjTtuMdBsnTf5MxSLQvN0EbWYD1 cJi6BAlw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sI7lI-00000002zQf-0DKR; Fri, 14 Jun 2024 14:18:40 +0000 Received: from mail-oo1-xc35.google.com ([2607:f8b0:4864:20::c35]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sI7lF-00000002zPn-2NZf for linux-arm-kernel@lists.infradead.org; Fri, 14 Jun 2024 14:18:38 +0000 Received: by mail-oo1-xc35.google.com with SMTP id 006d021491bc7-5bad217c51aso1185467eaf.1 for ; Fri, 14 Jun 2024 07:18:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718374714; x=1718979514; 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=+sjDmlk8xndLaxRABwpUKDEvjWtvENBQR7ofiVHlQf8=; b=PLmpkhdtDRNNnnhIvSMQwxdXR3QprnC2+1YhtLlBBSWYVG6Xlnp2MQpXqRHiSdEkAd 1Z+fx92Sv95oWDIzwUIF3/BzhAtfQlEMFCMs5Lo0SlV3YCzkoQCcJ7tY7iY0FnhlszwT VgUmoKXTXJHrRVnEU12BuNBO4GAw9J1NRhwMU3sJtRKo7yR9fSrclnd5IN5SEQ4yVM5b rB7+CS+KYY2d4WmXWszZlvzWLgmlXeIA7fZKfcQrFI2rFpW1UYAzlz/4MeddlpTrHEHf KzgxrU3jtEu7tIsYZbiURveiGWJ+5V2W4uAL7Fc1Uz3BRbASW/YO01bGRAbeUm40+rED kmFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718374714; x=1718979514; 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=+sjDmlk8xndLaxRABwpUKDEvjWtvENBQR7ofiVHlQf8=; b=j01iQcZm8u4lNbHpUfnVHjrqmm2A1xe4om9rCi3naZVradpSv0Blieu3NulMfNlfxy ZZoSmIJdUHDHID2ZFZhVDtjb9cjL3+oUlv04z0AdnBTYflHND5EOy2/OyOIT1hgIUXJn Rz0WjNzL6ZpI7MurpbHC5Ae1s2j9b32f+wdumY7dLGXXyaEkIjOoxZBf/ieiZQdmBEMW R+mqU+EFYR1yO7pjm8wDOyoVIdYUnir/VoRq/OpuKnEHPFkQzzqlYyks+6f9pCKDyoaJ EdF4QIG/iD7o0zkFD81BPji/YH00kF/EhU3mk6PSyowwM9rwFwED+oVt1hdAgHihcsh3 wxqw== X-Forwarded-Encrypted: i=1; AJvYcCXaADjsAGDaQENI+MZm9Jd1/WbHTOJXsX24qNLZb+9HYeh2PwAPxQyJCQGkeN7MuxbWmRUBddUc4N5O8zpS03UhhBiye1ERtJHGXFXnQf52UVfkSlw= X-Gm-Message-State: AOJu0YzcZRwZT/A0JZJSWnweqwOEg+tXEpiEEgk16DN4WUVDyk6wkKf0 PPchLyQ2dqz8yfQ24ws0o215Zk2BtMk33SENG2UQ/naSM4QkujYP X-Google-Smtp-Source: AGHT+IHksCM6QMMN5oCKowkEIaoVhI9skWX8S0kfwKK9ws9t3YFTdPmgNyYWeEUIfdx/qQgRrfSgkw== X-Received: by 2002:a4a:344e:0:b0:5bd:b100:8ab1 with SMTP id 006d021491bc7-5bdb1008d1bmr1669345eaf.7.1718374714251; Fri, 14 Jun 2024 07:18:34 -0700 (PDT) Received: from fauth2-smtp.messagingengine.com (fauth2-smtp.messagingengine.com. [103.168.172.201]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6b2a5c1ff4fsm18535236d6.47.2024.06.14.07.18.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jun 2024 07:18:33 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfauth.nyi.internal (Postfix) with ESMTP id B89AD1200068; Fri, 14 Jun 2024 10:18:32 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Fri, 14 Jun 2024 10:18:32 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrfeduledgjeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvdenucfhrhhomhepuehoqhhu nhcuhfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrihhlrdgtohhmqeenucggtffrrg htthgvrhhnpeehudfgudffffetuedtvdehueevledvhfelleeivedtgeeuhfegueeviedu ffeivdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe gsohhquhhnodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqdeiledvgeehtdei gedqudejjeekheehhedvqdgsohhquhhnrdhfvghngheppehgmhgrihhlrdgtohhmsehfih igmhgvrdhnrghmvg X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 14 Jun 2024 10:18:31 -0400 (EDT) Date: Fri, 14 Jun 2024 07:18:30 -0700 From: Boqun Feng To: Peter Zijlstra Cc: Gary Guo , 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 , 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: <20240612223025.1158537-1-boqun.feng@gmail.com> <20240612223025.1158537-3-boqun.feng@gmail.com> <20240613144432.77711a3a@eugeo> <20240614095124.GN8774@noisy.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240614095124.GN8774@noisy.programming.kicks-ass.net> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240614_071837_628502_B50B164F X-CRM114-Status: GOOD ( 29.48 ) 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 Fri, Jun 14, 2024 at 11:51:24AM +0200, Peter Zijlstra wrote: > On Thu, Jun 13, 2024 at 09:30:26AM -0700, Boqun Feng wrote: > > > We can always add a layer on top of what we have here to provide the > > generic `Atomic`. However, I personally don't think generic > > `Atomic` is a good idea, for a few reasons: > > > > * I'm not sure it will bring benefits to users, the current atomic > > users in kernel are pretty specific on the size of atomic they > > use, so they want to directly use AtomicI32 or AtomicI64 in > > their type definitions rather than use a `Atomic` where their > > users can provide type later. > > > > * I can also see the future where we have different APIs on > > different types of atomics, for example, we could have a: > > > > impl AtomicI64 { > > pub fn split(&self) -> (&AtomicI32, &AtomicI32) > > } > > > > which doesn't exist for AtomicI32. Note this is not a UB because > > we write our atomic implementation in asm, so it's perfectly > > fine for mix-sized atomics. > > > > So let's start with some basic and simple until we really have a need > > for generic `Atomic`. Thoughts? > > Not on the generic thing, but on the lack of long. atomic_long_t is > often used when we have pointers with extra bits on. Then you want a > number type in order to be able to manipulate the low bits. I mentioned my plan on AtomicPtr, but I think I should have clarified this more. My plan is: pub struct AtomicIsize { #[cfg(CONFIG_64BIT)] inner: AtomicI64 #[cfg(not(CONFIG_64BIT))] inner: AtomicI32 } i.e. building AtomicIsize (Rust's atomic_long_t) based on AtomicI64 and AtomicI32. And we can a AtomicPtr type on it: pub struct AtomicPtr { inner: AtomicIsize, _type: PhantomData<*mut T> } Of course, I need to do some code generating work for AtomicIsize and AtomicPtr, I plan to do that in Rust not in scripts, this will keep the rust/kernel/sync/atomic/impl.rs relatively small (i.e. the Rust/C interface is smaller). I can include this part in the next version, if you want to see it. Regards, Boqun