From: Benno Lossin <benno.lossin@proton.me>
To: "Mitchell Levy" <levymitchell0@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.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>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Andreas Hindborg" <a.hindborg@kernel.org>
Cc: linux-block@vger.kernel.org, rust-for-linux@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 2/2] rust: lockdep: Use Pin for all LockClassKey usages
Date: Wed, 05 Feb 2025 20:30:50 +0000 [thread overview]
Message-ID: <19dfbe36-237c-4da8-acfb-1d14069a8d1c@proton.me> (raw)
In-Reply-To: <20250205-rust-lockdep-v3-2-5313e83a0bef@gmail.com>
On 05.02.25 20:59, Mitchell Levy wrote:
> diff --git a/rust/kernel/sync/lock.rs b/rust/kernel/sync/lock.rs
> index 41dcddac69e2..119e5f569bdb 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,
> };
> -use core::{cell::UnsafeCell, marker::PhantomPinned};
> +use core::{cell::UnsafeCell, marker::PhantomPinned, pin::Pin};
> use macros::pin_data;
>
> pub mod mutex;
> @@ -121,7 +118,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> {
Static references do not need `Pin`, since `Pin::static_ref` [1] exists,
so you can just as well not add the `Pin` here and the other places
where you have `Pin<&'static T>`.
The reasoning is that since the data lives for `'static` at that
location, it will never move (since it is borrowed for `'static` after
all).
[1]: https://doc.rust-lang.org/std/pin/struct.Pin.html#method.static_ref
---
Cheers,
Benno
> pin_init!(Self {
> data: UnsafeCell::new(t),
> _pin: PhantomPinned,
> diff --git a/rust/kernel/sync/lock/global.rs b/rust/kernel/sync/lock/global.rs
> index 480ee724e3cc..d65f94b5caf2 100644
> --- a/rust/kernel/sync/lock/global.rs
> +++ b/rust/kernel/sync/lock/global.rs
> @@ -13,6 +13,7 @@
> use core::{
> cell::UnsafeCell,
> marker::{PhantomData, PhantomPinned},
> + pin::Pin,
> };
>
> /// Trait implemented for marker types for global locks.
next prev parent reply other threads:[~2025-02-05 20:31 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-05 19:59 [PATCH v3 0/2] rust: lockdep: Fix soundness issue affecting LockClassKeys Mitchell Levy
2025-02-05 19:59 ` [PATCH v3 1/2] rust: lockdep: Remove support for dynamically allocated LockClassKeys Mitchell Levy
2025-02-06 23:27 ` Miguel Ojeda
2025-02-07 23:11 ` Mitchell Levy
2025-02-07 0:23 ` Benno Lossin
2025-02-05 19:59 ` [PATCH v3 2/2] rust: lockdep: Use Pin for all LockClassKey usages Mitchell Levy
2025-02-05 20:30 ` Benno Lossin [this message]
2025-02-06 21:27 ` Boqun Feng
2025-02-07 0:22 ` Benno Lossin
2025-02-07 23:09 ` Mitchell Levy
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=19dfbe36-237c-4da8-acfb-1d14069a8d1c@proton.me \
--to=benno.lossin@proton.me \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=gary@garyguo.net \
--cc=levymitchell0@gmail.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
/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;
as well as URLs for NNTP newsgroup(s).