From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qv1-f53.google.com (mail-qv1-f53.google.com [209.85.219.53]) (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 DF367234984; Mon, 14 Jul 2025 14:59:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752505175; cv=none; b=GCAXsQWKCr9/OrdyXg7lElzzezy4Me772Y89nx5+1lqd/+Ja3DgU4t3hAjR9zdLpHdkF8LG+rgGSCZf4n6VAv2HI6oflI1GplgTK5171F4xvkNMxCvx4+eNHlc6MISihLCL2mwpIBrRvHBwK838Dc1cr3eXpQHoCeVr756IbW5U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752505175; c=relaxed/simple; bh=gnPNfGNhvz8u1TxFQVMlnCmvFMjVfxzTigxWK8CCFAo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=IHzz8n7gIMGgGrxOfFc9TJNGYg+KbYMMt4wMkTy3JG+OtHMd/A6a5BtYpK0qZ+Egackxn38+p3oM3kW1uFD8PT0SCgy6linKiBI0sqIjHtIl0tEZvLjUaCksJDkK5XczMho8wPImn1zEsQEiZrA1SPq98wRUtkQM/X1zCvIKPxs= 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=SDpgHVEB; arc=none smtp.client-ip=209.85.219.53 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="SDpgHVEB" Received: by mail-qv1-f53.google.com with SMTP id 6a1803df08f44-6fabe9446a0so36416036d6.2; Mon, 14 Jul 2025 07:59:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752505173; x=1753109973; 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=Emm0Lj04Ala0s2Dvnm1J6cHglimWIHUYLnLqb+co8Ck=; b=SDpgHVEBGR4y3fB7kWQ9gsQWNksFHV5a5JACXtyQ2zth3h+bVhsMk6rb5sOZnC/2q2 F11xcxc3hgebeEaG9gQCZs4Bsfut6mM0JEe44r/DWJ6WWjBG8FHBEYHc/UE9kn4ut+CC 9sPkzdMw02LKxW/mpIlC1qwWzNd5Ib9wdu4yLJ6I7Llspq/6i6e1v3Umy7Ey0srr8079 aP3hA/v/5RBL96oqFsVGgRdXHtk4wdyctkA8UFJbONZNtGuR9/wh6f5cpRZZ3TPnpjZv ePCIomgAbmfxo1cxFo1VPOHS8vJ6EfPjcqmjkYwGQubNP1QinKwXMqnw+x3AyjSd6cbA sZ+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752505173; x=1753109973; 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=Emm0Lj04Ala0s2Dvnm1J6cHglimWIHUYLnLqb+co8Ck=; b=WBKhAqOuwl/Jl1Nhju6tBGdCqMtgcGN8IlNkQ4/gJl21pTYsVbFr90gFzkLlSDf2l+ sDaEHVEk7GyCMr7e7+Jq5jYM1WjDPBMO1hqDUyvX5HYUaDC7I9fhW4fHkLm5QSYa7XJm f1tV7ucQ7nXoEsdeCKlNR7iLExCsP/HmCAHJWzM1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WrB76w== X-Received: by 2002:a05:6214:f6f:b0:6fd:24e8:7b04 with SMTP id 6a1803df08f44-704a399524amr204039356d6.33.1752505172434; Mon, 14 Jul 2025 07:59:32 -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 6a1803df08f44-70497d39c9dsm47646236d6.66.2025.07.14.07.59.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 07:59:31 -0700 (PDT) Received: from phl-compute-07.internal (phl-compute-07.phl.internal [10.202.2.47]) by mailfauth.phl.internal (Postfix) with ESMTP id 37821F40066; Mon, 14 Jul 2025 10:59:31 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-07.internal (MEProxy); Mon, 14 Jul 2025 10:59:31 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdehvddvhecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpeffhffvvefukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpeeuohhquhhnucfh vghnghcuoegsohhquhhnrdhfvghnghesghhmrghilhdrtghomheqnecuggftrfgrthhtvg hrnhephfetvdfgtdeukedvkeeiteeiteejieehvdetheduudejvdektdekfeegvddvhedt necuffhomhgrihhnpehkvghrnhgvlhdrohhrghenucevlhhushhtvghrufhiiigvpedtne curfgrrhgrmhepmhgrihhlfhhrohhmpegsohhquhhnodhmvghsmhhtphgruhhthhhpvghr shhonhgrlhhithihqdeiledvgeehtdeigedqudejjeekheehhedvqdgsohhquhhnrdhfvg hngheppehgmhgrihhlrdgtohhmsehfihigmhgvrdhnrghmvgdpnhgspghrtghpthhtohep vdejpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehlohhsshhinheskhgvrhhnvg hlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhn vghlrdhorhhgpdhrtghpthhtoheprhhushhtqdhfohhrqdhlihhnuhigsehvghgvrhdrkh gvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhkmhhmsehlihhsthhsrdhlihhnuhigrdgu vghvpdhrtghpthhtoheplhhinhhugidqrghrtghhsehvghgvrhdrkhgvrhhnvghlrdhorh hgpdhrtghpthhtohepohhjvggurgeskhgvrhhnvghlrdhorhhgpdhrtghpthhtoheprghl vgigrdhgrgihnhhorhesghhmrghilhdrtghomhdprhgtphhtthhopehgrghrhiesghgrrh ihghhuohdrnhgvthdprhgtphhtthhopegsjhhorhhnfegpghhhsehprhhothhonhhmrghi lhdrtghomh X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 14 Jul 2025 10:59:30 -0400 (EDT) Date: Mon, 14 Jul 2025 07:59:29 -0700 From: Boqun Feng To: Benno Lossin Cc: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, lkmm@lists.linux.dev, linux-arch@vger.kernel.org, Miguel Ojeda , Alex Gaynor , Gary Guo , =?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 , Alan Stern Subject: Re: [PATCH v7 3/9] rust: sync: atomic: Add ordering annotation types Message-ID: References: <20250714053656.66712-1-boqun.feng@gmail.com> <20250714053656.66712-4-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: On Mon, Jul 14, 2025 at 12:10:46PM +0200, Benno Lossin wrote: > On Mon Jul 14, 2025 at 7:36 AM CEST, Boqun Feng wrote: > > Preparation for atomic primitives. Instead of a suffix like _acquire, a > > method parameter along with the corresponding generic parameter will be > > used to specify the ordering of an atomic operations. For example, > > atomic load() can be defined as: > > > > impl Atomic { > > pub fn load(&self, _o: O) -> T { ... } > > } > > > > and acquire users would do: > > > > let r = x.load(Acquire); > > > > relaxed users: > > > > let r = x.load(Relaxed); > > > > doing the following: > > > > let r = x.load(Release); > > > > will cause a compiler error. > > > > Compared to suffixes, it's easier to tell what ordering variants an > > operation has, and it also make it easier to unify the implementation of > > all ordering variants in one method via generic. The `TYPE` associate > > const is for generic function to pick up the particular implementation > > specified by an ordering annotation. > > > > Reviewed-by: Alice Ryhl > > Signed-off-by: Boqun Feng > > --- > > Benno, please take a good and if you want to provide your Reviewed-by > > for this one. I didn't apply your Reviewed-by because I used > > `ordering::Any` instead of `AnyOrdering`, I think you're Ok with it [1], > > but I could be wrong. Thanks! > > > > [1]: https://lore.kernel.org/rust-for-linux/DB8M91D7KIT4.14W69YK7108ND@kernel.org/ > > > +/// The trait bound for annotating operations that support any ordering. > > +pub trait Any: internal::Sealed { > > How about we just name this `Ordering`? Because that's what it is :) > Seems OK to me, I then also followed Gary's suggestion: https://lore.kernel.org/rust-for-linux/20250621121842.0c3ca452.gary@garyguo.net/ and dropped `RelaxedOnly` trait. > That sadly means you can't do > > fn foo() {} > -------- ^^^^^^^^ not a trait > | > found this type parameter > > But you can still do > > fn foo(_: O) {} > > If we don't have the ordering module public and instead re-export from Keeping ordering mod public helps rustdoc readers to find the module and read the module documentation (where is the best place to explain each ordering), and also I made `Relaxed`, `Acquire`, `Release` and `Full` refer to the module documentation in their doc, making `ordering` mod private would cause rustdoc issues. Regards, Boqun > atomic, you could also write: > > fn foo(_: Ordering) {} > > If you want it to be extra clear. What do you think? > > --- > Cheers, > Benno > > > + /// Describes the exact memory ordering. > > + const TYPE: OrderingType; > > +}