lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aEhyRhb71dIXzqSu@tardis.local>
Date: Tue, 10 Jun 2025 10:58:30 -0700
From: Boqun Feng <boqun.feng@...il.com>
To: Benno Lossin <lossin@...nel.org>
Cc: linux-kernel@...r.kernel.org, rust-for-linux@...r.kernel.org,
	lkmm@...ts.linux.dev, linux-arch@...r.kernel.org,
	Miguel Ojeda <ojeda@...nel.org>,
	Alex Gaynor <alex.gaynor@...il.com>, Gary Guo <gary@...yguo.net>,
	Björn Roy Baron <bjorn3_gh@...tonmail.com>,
	Andreas Hindborg <a.hindborg@...nel.org>,
	Alice Ryhl <aliceryhl@...gle.com>, Trevor Gross <tmgross@...ch.edu>,
	Danilo Krummrich <dakr@...nel.org>, Will Deacon <will@...nel.org>,
	Peter Zijlstra <peterz@...radead.org>,
	Mark Rutland <mark.rutland@....com>,
	Wedson Almeida Filho <wedsonaf@...il.com>,
	Viresh Kumar <viresh.kumar@...aro.org>,
	Lyude Paul <lyude@...hat.com>, Ingo Molnar <mingo@...nel.org>,
	Mitchell Levy <levymitchell0@...il.com>,
	"Paul E. McKenney" <paulmck@...nel.org>,
	Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
	Linus Torvalds <torvalds@...ux-foundation.org>,
	Thomas Gleixner <tglx@...utronix.de>
Subject: Re: [PATCH v4 03/10] rust: sync: atomic: Add ordering annotation
 types

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<Ordering: ALL>(..)
> 
> 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`.
> 
[..]

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ