mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Boqun Feng <boqun.feng@gmail.com>
To: Daniel Almeida <daniel.almeida@collabora.com>
Cc: "Benno Lossin" <lossin@kernel.org>,
	"Peter Zijlstra" <peterz@infradead.org>,
	"Ingo Molnar" <mingo@redhat.com>, "Will Deacon" <will@kernel.org>,
	"Waiman Long" <longman@redhat.com>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Danilo Krummrich" <dakr@kernel.org>,
	linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org
Subject: Re: [PATCH v2 3/3] rust: lock: add a Pin<&mut T> accessor
Date: Sun, 14 Sep 2025 13:57:07 -0700	[thread overview]
Message-ID: <aMcsI14mzwubhT6e@tardis.local> (raw)
In-Reply-To: <A2534940-B847-40F6-8420-4ABEAE1D9A39@collabora.com>

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

      reply	other threads:[~2025-09-14 20:57 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-28 20:52 [PATCH v2 0/3] Groundwork for Lock<T> when T is pinned Daniel Almeida
2025-08-28 20:52 ` [PATCH v2 1/3] rust: lock: guard: add T: Unpin bound to DerefMut Daniel Almeida
2025-08-28 20:52 ` [PATCH v2 2/3] rust: lock: pin the inner data Daniel Almeida
2025-08-28 20:52 ` [PATCH v2 3/3] rust: lock: add a Pin<&mut T> accessor Daniel Almeida
2025-09-04 15:13   ` Benno Lossin
2025-09-04 15:15     ` Daniel Almeida
2025-09-08  2:13       ` Boqun Feng
2025-09-09 19:50         ` Daniel Almeida
2025-09-14 20:57           ` Boqun Feng [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aMcsI14mzwubhT6e@tardis.local \
    --to=boqun.feng@gmail.com \
    --cc=a.hindborg@kernel.org \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=gary@garyguo.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=lossin@kernel.org \
    --cc=mingo@redhat.com \
    --cc=ojeda@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tmgross@umich.edu \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®