From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qv1-f50.google.com (mail-qv1-f50.google.com [209.85.219.50]) (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 7A15F24728E for ; Tue, 10 Jun 2025 17:58:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749578317; cv=none; b=ry6ZlAb1cFx825WTxmQ67UQsWGex9kACvz3iYuhOeMpdqwPo0Qa4hp4+gLTdEkjM2xpCmVCqT2osTgG5zwSJiLHwkXMOU5QAj6y1w3rxZKyzm9QzADDE2tztbjVlJScPWavp/hKzXfClB9cuOKj6g1+/FyJyNbDvmgqi7xYqmuU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749578317; c=relaxed/simple; bh=WFSJOtGCy5DLWDZOUk7n++u9oB7z1T3ZkJpFtiZCWDY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ZSxnT713gduBs/y7RerXG1TY/HoVnUaAfmvgh4228pPIg6+rYhemNhIx5mAYtfvzrSqIb0mKNQ3/aUhmqJPwgPOspTm2yzwT7LLE00moZxzcSgzQZMm/6Pd8yPpkKbzcnJDxrxd/kqyYvp9NECGt9jFmhryR4suAVMBNgPc76lg= 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=LPnjv5dY; arc=none smtp.client-ip=209.85.219.50 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="LPnjv5dY" Received: by mail-qv1-f50.google.com with SMTP id 6a1803df08f44-6facacf521eso61204506d6.3 for ; Tue, 10 Jun 2025 10:58:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749578314; x=1750183114; darn=lists.linux.dev; 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=RFKC/VZAsPOtc+J1pi0LsDxSLSLhC1cMgwlK+mG2rRo=; b=LPnjv5dYlkVEzKuryeGQF8jBQw/XvyUy9aX/R9EchaT2bwuoVZe7xWzQ/T0GEGNZrN lwsBnZe9nzJpcDD2ahAcj8qgZMhPNh4rDdqnnDzNxPvdNzhq+Gye74rTOQEJ4i7VtFjw WPqWJ64qeUXk19igFjaM+kwOSKnc5CGGzpewUfnz1wyujt1841e0sMwThVO5eC/hIEJi Lp4cKSvSSMPe4ZLEiTC74hMsXh2WHd8RjIcXawV04sNDyt+fBkV/z7YCOwFGa/NyoDwH INsRQKWo6IXO0oszl9XPe9HIpENFiQDnaBhC0qeAGX3U3ItNC2HqrtznVzqBKhLbmVAU qe+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749578314; x=1750183114; 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=RFKC/VZAsPOtc+J1pi0LsDxSLSLhC1cMgwlK+mG2rRo=; b=lzAMiK+ToRR+K5/ARsLJaRcsk0Ze5W1457ZVnbKTh10LxFmLWU/PtVF1ioBp23vdCf yPXTPsqEVe2508ADT5D6TVoaOqpCbKiaRjJdj+9lqrbkBzGZcpk+9gMHx2EcC9GK9nlN KnpXyqGM8G3QgVQF3uPH4N2hvVtn/cuqEcPKwFDrsDYXr1k53o//pKk3/JmcRRoEn9L5 Ejak6DTDXIoaZNXH8L53J0FWkQAK0XwPKY04ndDi38eZ0TYO7t51dUoZd5bpMcYG3Sty njEeESv7jR2mYSBBcmq2MrFVz9Nw6bk0CRfFLKvC0tYVUfiZa5oPouxCBS9tanyaC8e9 Ltww== X-Forwarded-Encrypted: i=1; AJvYcCWN/Rn3dJGFiowWX+iz9kR9BO5iB5ELiyMK6McphiWuvK2dRISbxYId9fkG1rD8HhH4LZvq@lists.linux.dev X-Gm-Message-State: AOJu0YzYEzaImEgF2vVk31elW9lSsYn4XNya/Cw1lBQTzQIRjABeCI6r qz8u3rLai07FmsQOp08ligDItyAm32L7QtBphaYLp1oyxG9XXpbREJ6n X-Gm-Gg: ASbGncuznTyAGDecOgIzrCZRqXBikiG8GCz++C3V1vfTie4eOGZM4qerJg0gAlBEcav sFnB4YHTH0chHKJfXbVyvkKz2gT1R3VMhgMA+cg0dZmCh0u8PavJj+/69OwfwN+ZLCVk0zjkX8n xUnT9Axcf1hgWFjgB31QVoTI2xiXx+d0Xh7VrB5ICdCpBdfbOy6myclxCmek2NHhTBLBc1H3diJ 1mUkA7dBtkpYWUQ2Ckr5gB6vtm4ozd3mqhJlakJxjkNC45K8qHqvj4RkG5AQB8cw41Htr1ReDu2 xbw/QfsUoV3TmucQk2/9q16h7TNDf8DkeXUG4PLReHJGwTLGpYZo/WGF5Fl/DTMAT20wHl6aYTE EEUdoOI1xVXlS3/3B03Vnx0e8X8RcjAq7Nc4js+MOB4jpqeBwSY/DYMAV49tbTvY= X-Google-Smtp-Source: AGHT+IE1ZgmFQqI16FjmhRw0PUqrqN2GZWUt9lHT730+lp5RjXgeKiNOIijStPhoRxTKPLxmV0rguA== X-Received: by 2002:a05:6214:da5:b0:6ed:df6:cdcd with SMTP id 6a1803df08f44-6fb2c36a381mr5736416d6.21.1749578314169; Tue, 10 Jun 2025 10:58:34 -0700 (PDT) Received: from fauth-a2-smtp.messagingengine.com (fauth-a2-smtp.messagingengine.com. [103.168.172.201]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7d250f64bacsm732339885a.17.2025.06.10.10.58.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 10:58:33 -0700 (PDT) Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfauth.phl.internal (Postfix) with ESMTP id B85001200043; Tue, 10 Jun 2025 13:58:32 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-11.internal (MEProxy); Tue, 10 Jun 2025 13:58:32 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtddugdduuddtjecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehttdertddttddv necuhfhrohhmpeeuohhquhhnucfhvghnghcuoegsohhquhhnrdhfvghnghesghhmrghilh drtghomheqnecuggftrfgrthhtvghrnhephedugfduffffteeutddvheeuveelvdfhleel ieevtdeguefhgeeuveeiudffiedvnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrg hmpehmrghilhhfrhhomhepsghoqhhunhdomhgvshhmthhprghuthhhphgvrhhsohhnrghl ihhthidqieelvdeghedtieegqddujeejkeehheehvddqsghoqhhunhdrfhgvnhhgpeepgh hmrghilhdrtghomhesfhhigihmvgdrnhgrmhgvpdhnsggprhgtphhtthhopedviedpmhho uggvpehsmhhtphhouhhtpdhrtghpthhtoheplhhoshhsihhnsehkvghrnhgvlhdrohhrgh dprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhr ghdprhgtphhtthhopehruhhsthdqfhhorhdqlhhinhhugiesvhhgvghrrdhkvghrnhgvlh drohhrghdprhgtphhtthhopehlkhhmmheslhhishhtshdrlhhinhhugidruggvvhdprhgt phhtthhopehlihhnuhigqdgrrhgthhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtph htthhopehojhgvuggrsehkvghrnhgvlhdrohhrghdprhgtphhtthhopegrlhgvgidrghgr hihnohhrsehgmhgrihhlrdgtohhmpdhrtghpthhtohepghgrrhihsehgrghrhihguhhord hnvghtpdhrtghpthhtohepsghjohhrnhefpghghhesphhrohhtohhnmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 10 Jun 2025 13:58:30 -0400 (EDT) Date: Tue, 10 Jun 2025 10:58:30 -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 Subject: Re: [PATCH v4 03/10] rust: sync: atomic: Add ordering annotation types Message-ID: References: <20250609224615.27061-1-boqun.feng@gmail.com> <20250609224615.27061-4-boqun.feng@gmail.com> Precedence: bulk X-Mailing-List: lkmm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Tue, Jun 10, 2025 at 10:30:55AM -0700, Boqun Feng wrote: [...] > > > +/// Describes the exact memory ordering of an `impl` [`All`]. > > > +pub enum OrderingDesc { > > > > Why not name this `Ordering`? > > > > I was trying to avoid having an `Ordering` enum in a `ordering` mod. > Also I want to save the name "Ordering" for the generic type parameter > of an atomic operation, e.g. > > pub fn xchg(..) > > this enum is more of an internal implementation detail, and users should > not use this enum directly, so I would like to avoid potential > confusion. > > I have played a few sealed trait tricks on my end, but seems I cannot > achieve: > > 1) `OrderingDesc` is only accessible in the atomic mod. > 2) `All` is only impl-able in the atomic mod, while it can be used as a > trait bound outside kernel crate. > > Maybe there is a trick I'm missing? > Something like this seems to work: pub(super) mod private { /// Describes the exact memory ordering of an `impl` [`All`]. pub enum Ordering { /// Relaxed ordering. Relaxed, /// Acquire ordering. Acquire, /// Release ordering. Release, /// Fully-ordered. Full, } pub trait HasOrderingDesc { /// Describes the exact memory ordering. const ORDERING: Ordering; } } /// The trait bound for annotating operations that should support all orderings. pub trait All: private::HasOrderingDesc { } impl private::HasOrderingDesc for Relaxed { const ORDERING: private::Ordering = private::Ordering::Relaxed; } the trick is to seal the enum and the trait together. Regards, Boqun > > > + /// Relaxed ordering. > > > + Relaxed, > > > + /// Acquire ordering. > > > + Acquire, > > > + /// Release ordering. > > > + Release, > > > + /// Fully-ordered. > > > + Full, > > > +} > > > + > > > +/// The trait bound for annotating operations that should support all orderings. > > > +pub trait All { > > > + /// Describes the exact memory ordering. > > > + const ORDER: OrderingDesc; > > > > And then here: `ORDERING`. > [..]