Re: [PATCH v4 2/2] rust: lockdep: Use Pin for all LockClassKey usages

From: Boqun Feng
Date: Mon Feb 10 2025 - 00:40:29 EST


On Sun, Feb 09, 2025 at 09:57:00AM +0000, Benno Lossin wrote:
> On 08.02.25 01:39, Mitchell Levy wrote:
> > Reintroduce dynamically-allocated LockClassKeys such that they are
> > automatically (de)registered. Require that all usages of LockClassKeys
> > ensure that they are Pin'd.
> >
> > Currently, only `'static` LockClassKeys are supported, so Pin is
> > redundant. However, it is intended that dynamically-allocated
> > LockClassKeys will eventually be supported, so using Pin from the outset
> > will make that change simpler.
> >
> > Closes: https://github.com/Rust-for-Linux/linux/issues/1102
> > Suggested-by: Benno Lossin <benno.lossin@xxxxxxxxx>
> > Suggested-by: Boqun Feng <boqun.feng@xxxxxxxxx>
> > Signed-off-by: Mitchell Levy <levymitchell0@xxxxxxxxx>
>
> One nit below, but it's fine.
>
> Reviewed-by: Benno Lossin <benno.lossin@xxxxxxxxx>
>

Thank you both!

> > ---
> > rust/helpers/helpers.c | 1 +
> > rust/helpers/sync.c | 13 ++++++++++
> > rust/kernel/sync.rs | 57 ++++++++++++++++++++++++++++++++++++++---
> > rust/kernel/sync/condvar.rs | 5 ++--
> > rust/kernel/sync/lock.rs | 9 +++----
> > rust/kernel/sync/lock/global.rs | 5 ++--
> > rust/kernel/sync/poll.rs | 2 +-
> > rust/kernel/workqueue.rs | 2 +-
> > 8 files changed, 78 insertions(+), 16 deletions(-)
>
> [...]
>
> > diff --git a/rust/kernel/sync/lock.rs b/rust/kernel/sync/lock.rs
> > index eb80048e0110..6dafe338bbc7 100644
> > --- a/rust/kernel/sync/lock.rs
> > +++ b/rust/kernel/sync/lock.rs
> > @@ -7,12 +7,9 @@
> >
> > use super::LockClassKey;
> > use crate::{
> > - init::PinInit,
> > - pin_init,
> > - str::CStr,
> > - types::{NotThreadSafe, Opaque, ScopeGuard},
> > + init::PinInit, pin_init, str::CStr, types::NotThreadSafe, types::Opaque, types::ScopeGuard,
>
> Why does this change exist? I prefer imports to be merged.
>

Agreed. Queued with this change reverted.

Regards,
Boqun

> ---
> Cheers,
> Benno
>
> > };
> > -use core::{cell::UnsafeCell, marker::PhantomPinned};
> > +use core::{cell::UnsafeCell, marker::PhantomPinned, pin::Pin};
> > use macros::pin_data;
> >
> > pub mod mutex;
> > @@ -129,7 +126,7 @@ unsafe impl<T: ?Sized + Send, B: Backend> Sync for Lock<T, B> {}
> >
> > impl<T, B: Backend> Lock<T, B> {
> > /// Constructs a new lock initialiser.
> > - pub fn new(t: T, name: &'static CStr, key: &'static LockClassKey) -> impl PinInit<Self> {
> > + pub fn new(t: T, name: &'static CStr, key: Pin<&'static LockClassKey>) -> impl PinInit<Self> {
> > pin_init!(Self {
> > data: UnsafeCell::new(t),
> > _pin: PhantomPinned,
>