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: <DF4J4VKRL07V.9LLZA5UR1BD5@kernel.org>
Date: Mon, 22 Dec 2025 07:25:49 +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 16/17] rust: sync: lock/global: Add BackendInContext
 support to GlobalLock

On Mon Dec 15, 2025 at 6:58 PM CET, Lyude Paul wrote:
> Now that we have the ability to provide an explicit lifetime for a
> GlobalGuard and an explicit Backend for a GlobalGuard, we can finally
> implement lock_with() and try_lock_with().
>
> Signed-off-by: Lyude Paul <lyude@...hat.com>
> ---
>  rust/kernel/sync/lock/global.rs | 28 ++++++++++++++++++++++++++++
>  1 file changed, 28 insertions(+)
>
> diff --git a/rust/kernel/sync/lock/global.rs b/rust/kernel/sync/lock/global.rs
> index 64fc7e7a4b282..7aee9b25baefc 100644
> --- a/rust/kernel/sync/lock/global.rs
> +++ b/rust/kernel/sync/lock/global.rs
> @@ -89,6 +89,34 @@ pub fn try_lock(&'static self) -> Option<GlobalGuard<'static, G, G::Backend>> {
>              inner: self.inner.try_lock()?,
>          })
>      }
> +
> +    /// Lock this global lock with the provided `context`.
> +    pub fn lock_with<'a, B>(
> +        &'static self,
> +        context: <G::Backend as Backend>::Context<'a>,
> +    ) -> GlobalGuard<'a, G, B>
> +    where
> +        G::Backend: Backend<BackendInContext = B>,
> +        B: Backend,

Since `BackendInContext` is an associated type, you don't need this type
parameter and can write instead:

    pub fn lock_with<'a>(
        &'static self,
        context: <G::Backend as Backend>::Context<'a>,
    ) -> GlobalGuard<'a, G, <G::Backend as Backend>::BackendInContext>
    where
        <G::Backend as Backend>::BackendInContext: Backend,

Cheers,
Benno

> +    {
> +        GlobalGuard {
> +            inner: self.inner.lock_with(context),
> +        }
> +    }
> +
> +    /// Try to lock this global lock with the provided `context`.
> +    pub fn try_lock_with<'a, B>(
> +        &'static self,
> +        context: <G::Backend as Backend>::Context<'a>,
> +    ) -> Option<GlobalGuard<'a, G, B>>
> +    where
> +        G::Backend: Backend<BackendInContext = B>,
> +        B: Backend,
> +    {
> +        Some(GlobalGuard {
> +            inner: self.inner.try_lock_with(context)?,
> +        })
> +    }
>  }
>  
>  /// A guard for a [`GlobalLock`].


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ