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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <aMcsI14mzwubhT6e@tardis.local>
Date: Sun, 14 Sep 2025 13:57:07 -0700
From: Boqun Feng <boqun.feng@...il.com>
To: Daniel Almeida <daniel.almeida@...labora.com>
Cc: Benno Lossin <lossin@...nel.org>, Peter Zijlstra <peterz@...radead.org>,
	Ingo Molnar <mingo@...hat.com>, Will Deacon <will@...nel.org>,
	Waiman Long <longman@...hat.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>, linux-kernel@...r.kernel.org,
	rust-for-linux@...r.kernel.org
Subject: Re: [PATCH v2 3/3] rust: lock: add a Pin<&mut T> accessor

On Tue, Sep 09, 2025 at 04:50:19PM -0300, Daniel Almeida wrote:
> Hi Boqun, sorry for the delay,
> 
> >>>> +
> >>>> +    /// Returns a pinned mutable reference to the protected data.
> >>>> +    ///
> >>>> +    /// The guard implements [`DerefMut`] when `T: Unpin`, so for [`Unpin`]
> >>>> +    /// types [`DerefMut`] should be used instead of this function.
> >>>> +    ///
> >>>> +    /// [`DerefMut`]: core::ops::DerefMut
> >>>> +    /// [`Unpin`]: core::marker::Unpin
> >>>> +    ///
> >>>> +    /// # Examples
> >>>> +    ///
> >>>> +    /// ```
> >>>> +    /// # use kernel::sync::{Mutex, MutexGuard};
> >>>> +    /// # use core::pin::Pin;
> >>>> +    /// struct Data;
> >>>> +    ///
> >>>> +    /// fn example(mutex: &Mutex<Data>) {
> >>>> +    ///   let mut data: MutexGuard<'_, Data> = mutex.lock();
> >>>> +    ///   let mut data: Pin<&mut Data> = data.as_mut();
> >>>> +    ///  }
> >>> 
> >>> The formatting looks off in this one, there should be 4 spaces of
> >>> indentation here; there are also 2 spaces in front of the `}`.
> >>> 
> >>> Also `Data` implements `Unpin`, so you're not following your own
> >>> recommendation from above :)
> >> 
> >> I´ll fix this :)
> >> 
> > 
> > If the fix is small, feel free to send a diff and I can fold it when
> > queueing (i.e. no need to resend the whole series). I'm trying to send
> > it to tip before -rc6 so there will be some more tests. Thanks!
> > 
> > Regards,
> > Boqun
> > 
> 
> 
> This should address what Benno pointed out:
> 
> 
> diff --git a/rust/kernel/sync/lock.rs b/rust/kernel/sync/lock.rs
> index 7191804a244d..cb00fdb94ffd 100644
> --- a/rust/kernel/sync/lock.rs
> +++ b/rust/kernel/sync/lock.rs
> @@ -258,13 +258,13 @@ pub(crate) fn do_unlocked<U>(&mut self, cb: impl FnOnce() -> U) -> U {
>      ///
>      /// ```
>      /// # use kernel::sync::{Mutex, MutexGuard};
> -    /// # use core::pin::Pin;
> -    /// struct Data;
> +    /// # use core::{pin::Pin, marker::PhantomPinned};
> +    /// struct Data(PhantomPinned);
>      ///
>      /// fn example(mutex: &Mutex<Data>) {
> -    ///   let mut data: MutexGuard<'_, Data> = mutex.lock();
> -    ///   let mut data: Pin<&mut Data> = data.as_mut();
> -    ///  }
> +    ///     let mut data: MutexGuard<'_, Data> = mutex.lock();
> +    ///     let mut data: Pin<&mut Data> = data.as_mut();
> +    /// }
>      /// ```
>      pub fn as_mut(&mut self) -> Pin<&mut T> {
>          // SAFETY: `self.lock.data` is structurally pinned.

Applied and queued:

	git://git.kernel.org/pub/scm/linux/kernel/git/boqun/linux.git locking

I also remove the part in the commit log where it mentioned about pin
projection, since the pull request for that is already created and
merged. Thanks!

I will give it some tests and see if I could send a pull request to tip
early next week, so it can be in v6.18.

Regards,
Boqun

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ