From: "Benno Lossin" <lossin@kernel.org>
To: "Alice Ryhl" <aliceryhl@google.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Miguel Ojeda" <ojeda@kernel.org>
Cc: "Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/2] rust: sync: refactor static_lock_class!() macro
Date: Mon, 28 Jul 2025 12:18:29 +0200 [thread overview]
Message-ID: <DBNM0XTCESZY.18G1A6U91QNE6@kernel.org> (raw)
In-Reply-To: <20250728-lock-class-key-cleanup-v2-1-ad02b80c69e1@google.com>
On Mon Jul 28, 2025 at 11:42 AM CEST, Alice Ryhl wrote:
> By introducing a new_static() constructor, the macro does not need to go
> through MaybeUninit::uninit().assume_init(), which is a pattern that is
> best avoided when possible.
>
> The safety comment requires not only requires that the value is leaked,
"requires" appears twice.
> but also that it is stored in the right portion of memory. This is so
> that the lockdep static_obj() check will succeed when using this
> constructor. One could argue that lockdep detects this scenario, so the
> safety comment isn't needed. However, it simplifies matters to require
> that static_obj() will succeed and it's not a burdensome requirement on
> the caller.
I'd argue that's implementation detail and the safety requirement of
using a lockclass key is that it either is uninit in static memory or it
was registered. (otherwise we wouldn't be "allowed" to add this as a
safety requirement)
(just adding this for info, feel free to keep the paragraph above as-is)
> Suggested-by: Benno Lossin <lossin@kernel.org>
> Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com>
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Benno Lossin <lossin@kernel.org>
> @@ -95,13 +110,11 @@ fn drop(self: Pin<&mut Self>) {
> #[macro_export]
> macro_rules! static_lock_class {
> () => {{
> - static CLASS: $crate::sync::LockClassKey =
> - // Lockdep expects uninitialized memory when it's handed a statically allocated `struct
> - // lock_class_key`.
> - //
> - // SAFETY: `LockClassKey` transparently wraps `Opaque` which permits uninitialized
> - // memory.
> - unsafe { ::core::mem::MaybeUninit::uninit().assume_init() };
> + // SAFETY: The returned `LockClassKey` is stored in static memory. Drop never runs on a
You're not mentioning the "pinned in a static memory location" part
(only the static memory, so missing the pinning). A read-only static
is implicitly pinned, so we should mention that.
---
Cheers,
Benno
> + // static global.
> + static CLASS: $crate::sync::LockClassKey = unsafe {
> + $crate::sync::LockClassKey::new_static()
> + };
> $crate::prelude::Pin::static_ref(&CLASS)
> }};
> }
next prev parent reply other threads:[~2025-07-28 10:18 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-28 9:42 [PATCH v2 0/2] Clean up Rust LockClassKey Alice Ryhl
2025-07-28 9:42 ` [PATCH v2 1/2] rust: sync: refactor static_lock_class!() macro Alice Ryhl
2025-07-28 10:18 ` Benno Lossin [this message]
2025-07-28 9:42 ` [PATCH v2 2/2] rust: sync: clean up LockClassKey and its docs Alice Ryhl
2025-08-12 8:05 ` Benno Lossin
2025-08-12 15:46 ` Boqun Feng
2026-01-20 21:05 ` Tamir Duberstein
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=DBNM0XTCESZY.18G1A6U91QNE6@kernel.org \
--to=lossin@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=gary@garyguo.net \
--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
all inboxes | Powered by JetHome®