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: <20251125215919.6af03a2e@nimda.home>
Date: Tue, 25 Nov 2025 21:59:19 +0300
From: Onur Özkan <work@...rozkan.dev>
To: Daniel Almeida <daniel.almeida@...labora.com>
Cc: rust-for-linux@...r.kernel.org, lossin@...nel.org, lyude@...hat.com,
 ojeda@...nel.org, alex.gaynor@...il.com, boqun.feng@...il.com,
 gary@...yguo.net, a.hindborg@...nel.org, aliceryhl@...gle.com,
 tmgross@...ch.edu, dakr@...nel.org, peterz@...radead.org, mingo@...hat.com,
 will@...nel.org, longman@...hat.com, felipe_life@...e.com,
 daniel@...lak.dev, bjorn3_gh@...tonmail.com, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v7 4/6] rust: ww_mutex: add Mutex, AcquireCtx and
 MutexGuard

On Tue, 25 Nov 2025 15:32:08 -0300
Daniel Almeida <daniel.almeida@...labora.com> wrote:


[...]
> > +    /// Similar to `lock`, but can be interrupted by signals.
> > +    ///
> > +    /// # Safety
> > +    ///
> > +    /// The given `mutex` must be created with the [`Class`] that
> > was used
> > +    /// to initialize this [`AcquireCtx`].
> > +    pub unsafe fn lock_interruptible<'a, T>(
> > +        &'a self,
> > +        mutex: &'a Mutex<'a, T>,
> > +    ) -> Result<MutexGuard<'a, T>> {
> > +        // SAFETY: By the safety contract, `mutex` belongs to the
> > same `Class`
> > +        // as `self` does.
> > +        unsafe { lock_common(mutex, Some(self),
> > LockKind::Interruptible) }
> > +    }
> > +
> > +    /// Locks the given mutex on this [`AcquireCtx`] using the
> > slow path.
> > +    ///
> > +    /// This function should be used when `lock` fails (typically
> > due to a potential deadlock).
> > +    ///
> > +    /// # Safety
> > +    ///
> > +    /// The given `mutex` must be created with the [`Class`] that
> > was used
> > +    /// to initialize this [`AcquireCtx`].
> 
> I’m assuming we either can’t or otherwise don’t want to store this in
> the Mutex itself?
> 
> IOW: the class is ’static IIUC, so it’s always safe to store a
> reference anyways, at the cost of providing the storage.
> 

We used to do this but I had to revert them when I implemented
`from_raw` functions. I wrote about it on [1], let me know what you
think about the solution idea I wrote there.

[1]: https://lore.kernel.org/all/20251124184928.30b8bbaf@nimda/

> > +    pub unsafe fn lock_slow<'a, T>(&'a self, mutex: &'a Mutex<'a,
> > T>) -> Result<MutexGuard<'a, T>> {
> > +        // SAFETY: By the safety contract, `mutex` belongs to the
> > same `Class`
> > +        // as `self` does.
> > +        unsafe { lock_common(mutex, Some(self), LockKind::Slow) }
> > +    }
> > +
> > +    /// Similar to `lock_slow`, but can be interrupted by signals.
> > +    ///
> > +    /// # Safety
> > +    ///
> > +    /// The given `mutex` must be created with the [`Class`] that
> > was used
> > +    /// to initialize this [`AcquireCtx`].
> > +    pub unsafe fn lock_slow_interruptible<'a, T>(
> > +        &'a self,
> > +        mutex: &'a Mutex<'a, T>,
> > +    ) -> Result<MutexGuard<'a, T>> {
> > +        // SAFETY: By the safety contract, `mutex` belongs to the
> > same `Class`
> > +        // as `self` does.
> > +        unsafe { lock_common(mutex, Some(self),
> > LockKind::SlowInterruptible) }
> > +    }
> > +
> > +    /// Tries to lock the mutex on this [`AcquireCtx`] without
> > blocking.
> > +    ///
> > +    /// Unlike `lock`, no deadlock handling is performed.
> 
> You can use [`lock`] here for better docs.
> 

I will update it as [`Self::lock`] ([`lock`] will not work). There are
some other lines where I need to do the same thing.

> > +    ///
> > +    /// # Safety
> > +    ///
> > +    /// The given `mutex` must be created with the [`Class`] that
[...]

BR,
Onur

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ