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: <DF4IZZCCY3OL.3L759760HY8LD@kernel.org>
Date: Mon, 22 Dec 2025 07:19:26 +0100
From: "Benno Lossin" <lossin@...nel.org>
To: "Lyude Paul" <lyude@...hat.com>, <rust-for-linux@...r.kernel.org>,
 <linux-kernel@...r.kernel.org>, "Thomas Gleixner" <tglx@...utronix.de>
Cc: "Boqun Feng" <boqun.feng@...il.com>, "Daniel Almeida"
 <daniel.almeida@...labora.com>, "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>,
 "Andrew Morton" <akpm@...ux-foundation.org>, "Peter Zijlstra"
 <peterz@...radead.org>, "Ingo Molnar" <mingo@...hat.com>, "Will Deacon"
 <will@...nel.org>, "Waiman Long" <longman@...hat.com>
Subject: Re: [PATCH v16 11/17] rust: sync: lock: Add
 `Backend::BackendInContext`

On Mon Dec 15, 2025 at 6:57 PM CET, Lyude Paul wrote:
> diff --git a/rust/kernel/sync/lock.rs b/rust/kernel/sync/lock.rs
> index bf2d94c1999bd..938ffe1bac06c 100644
> --- a/rust/kernel/sync/lock.rs
> +++ b/rust/kernel/sync/lock.rs
> @@ -30,10 +30,15 @@
>  ///   is owned, that is, between calls to [`lock`] and [`unlock`].
>  /// - Implementers must also ensure that [`relock`] uses the same locking method as the original
>  ///   lock operation.
> +/// - Implementers must ensure if [`BackendInContext`] is a [`Backend`], it's safe to acquire the
> +///   lock under the [`Context`], the [`State`] of two backends must be the same.
>  ///
>  /// [`lock`]: Backend::lock
>  /// [`unlock`]: Backend::unlock
>  /// [`relock`]: Backend::relock
> +/// [`BackendInContext`]: Backend::BackendInContext
> +/// [`Context`]: Backend::Context
> +/// [`State`]: Backend::State
>  pub unsafe trait Backend {
>      /// The state required by the lock.
>      type State;
> @@ -47,6 +52,9 @@ pub unsafe trait Backend {
>      /// The context which can be provided to acquire the lock with a different backend.
>      type Context<'a>;
>  
> +    /// The alternative backend we can use if a [`Context`](Backend::Context) is provided.
> +    type BackendInContext: Sized;
> +

I'm wondering if it'd be better to have a subtrait of `Backend` that
stores all this information instead:

    pub unsafe trait BackendWithContext: Backend {
        type Context<'a>;

        type ContextualBackend: Backend<State = Self::State>;
    }

That way, we don't need to specify `()` for the `Context`/`BackendInContext`
in e.g. `Mutex`. And the safety requirements also get much simpler: the
state requirement is directly encoded in the trait bound and the other
part loses the `if` condition.

Then only implement the `lock_with` method on `Lock<T, B>` where `B` is
a `BackendWithContext`.

Cheers,
Benno

>      /// Initialises the lock.
>      ///
>      /// # Safety

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ