From nobody Sun Feb 8 15:57:49 2026 Received: from mail-qv1-f68.google.com (mail-qv1-f68.google.com [209.85.219.68]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D8FA033ADBA for ; Sun, 11 Jan 2026 11:58:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.68 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768132712; cv=none; b=Dd0xeUpp2DVz5cIrItASo+/XV08vZxqfaskokxy6XaIDiac+Rc42XmHGjKX/vDKANLYES8QvM0UDKtYp+bk4nVKfwP+e4fjVFgDLk9OgqjQzGrJDMh7DgLYIt9z2FfOQTQ9U6sJYTRiKLXPOMbpxAjGM7Ud+WM48bEdV8QZQ4ys= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768132712; c=relaxed/simple; bh=qoDNG6DumbB68T3T/3idHm5J3FT4KY0Gxz5BLyi2v+I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eZiCWZxByoOzoHYMxH55swg2I5e0Tjyia/IDBKumVL5E23f6hyxZ3U0RZlp/+uF5KKkYDg3tDOKz/0s6gdPZjmXo6kqsX/JOuoDY7YZYKQvooLOW1E2AtM/V5FxFluffL4yrhQ3zsTsxhHjhTEUWuWJTrKM1JQMjX2WG6dsCIac= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=fVU1WMBU; arc=none smtp.client-ip=209.85.219.68 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fVU1WMBU" Received: by mail-qv1-f68.google.com with SMTP id 6a1803df08f44-88a2fe9e200so52855466d6.0 for ; Sun, 11 Jan 2026 03:58:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768132707; x=1768737507; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:from:to:cc:subject :date:message-id:reply-to; bh=zzUujVMOfW0CmXB1JVajE/vv1q+DHQuZ+S5KxfCqrRc=; b=fVU1WMBUX8s0CSo1dloAcpgPU1rVi7C3jLwmEmOzmqOdfqJvUj/3cM3nXZa3LKVEO+ 0j5+s6NLpOqKa6Gr7+oHpzVxtj+bTw6ALQ0EH9vFsXVVmvtF5XE+Q+Hm8BzBgRi9EiSi q4/4QNieylF4ve6rmePxcibM4saWZ1qy9/XYjp3QCsDMDfGlbyBsYcPLTEeteqAMQjND qTlvu4azRxQke6enL7DkC8tM1PcQ3iF/8X1jKbP9se6PfjPfKKat+KhXkQyr8MNq8JRK oMXpiriC7mpyJsp0M6RnAxQlq8Wd5tjaiDmrW6cIeqIEUfiY2fGJJtXYhA7nOB5VUWTg wiOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768132707; x=1768737507; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=zzUujVMOfW0CmXB1JVajE/vv1q+DHQuZ+S5KxfCqrRc=; b=wafZXlq9GGTQiG5v1WN51OxaM9vjW45qix4IJPH1kSyWZdC/jbWeSqY8TrFdzF+wyM OrnRAyspcxswpaMdBea10qP5vsSLZI938ExERBmEHTkFKyfmVhWxS9O3bIG6pruK6GFF vTKo5bLScLP24sqkyxP1EWXX9+mcOu16nWUshFmekovcJ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87c:268d:bbda with SMTP id 6a1803df08f44-890842dc7a0mr200399756d6.60.1768132706668; Sun, 11 Jan 2026 03:58:26 -0800 (PST) Received: from fauth-a2-smtp.messagingengine.com (fauth-a2-smtp.messagingengine.com. [103.168.172.201]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8907723469fsm128951486d6.37.2026.01.11.03.58.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Jan 2026 03:58:26 -0800 (PST) Received: from phl-compute-09.internal (phl-compute-09.internal [10.202.2.49]) by mailfauth.phl.internal (Postfix) with ESMTP id 90FE3F40068; Sun, 11 Jan 2026 06:58:25 -0500 (EST) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-09.internal (MEProxy); Sun, 11 Jan 2026 06:58:25 -0500 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgdduudegheduucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepuehoqhhunhcu hfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrihhlrdgtohhmqeenucggtffrrghtth gvrhhnpedvveekvddtffelffelfedvudefffeuheejgeeivedufffgledvgeduveffueeh leenucffohhmrghinhepmhhsghhiugdrlhhinhhknecuvehluhhsthgvrhfuihiivgeptd enucfrrghrrghmpehmrghilhhfrhhomhepsghoqhhunhdomhgvshhmthhprghuthhhphgv rhhsohhnrghlihhthidqieelvdeghedtieegqddujeejkeehheehvddqsghoqhhunhdrfh gvnhhgpeepghhmrghilhdrtghomhesfhhigihmvgdrnhgrmhgvpdhnsggprhgtphhtthho peduhedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepphgvthgvrhiisehinhhfrh gruggvrggurdhorhhgpdhrtghpthhtohepmhhinhhgoheskhgvrhhnvghlrdhorhhgpdhr tghpthhtoheprhhushhtqdhfohhrqdhlihhnuhigsehvghgvrhdrkhgvrhhnvghlrdhorh hgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdho rhhgpdhrtghpthhtohepfihilhhlsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehmrg hrkhdrrhhuthhlrghnugesrghrmhdrtghomhdprhgtphhtthhopehtghhlgieslhhinhhu thhrohhnihigrdguvgdprhgtphhtthhopehojhgvuggrsehkvghrnhgvlhdrohhrghdprh gtphhtthhopehgrghrhiesghgrrhihghhuohdrnhgvth X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 11 Jan 2026 06:58:25 -0500 (EST) From: Boqun Feng To: "Peter Zijlstra" , "Ingo Molnar" Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, "Will Deacon" , "Mark Rutland" , "Thomas Gleixner" , "Miguel Ojeda" , "Gary Guo" , "Alice Ryhl" , "Andreas Hindborg" , "Benno Lossin" , "Danilo Krummrich" , Daniel Almeida , Boqun Feng Subject: [PATCH 01/36] rust: sync: Refactor static_lock_class!() macro Date: Sun, 11 Jan 2026 19:57:33 +0800 Message-ID: <20260111115808.5702-2-boqun.feng@gmail.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260111115808.5702-1-boqun.feng@gmail.com> References: <20260111115808.5702-1-boqun.feng@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Alice Ryhl 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 not only requires that the value is leaked, 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 that safety requirement isn't needed. However, it simplifies matters to require that static_obj() will succeed and it's not a burdensome requirement on the caller. Suggested-by: Benno Lossin Reviewed-by: Daniel Almeida Reviewed-by: Benno Lossin Signed-off-by: Alice Ryhl Signed-off-by: Boqun Feng Link: https://patch.msgid.link/20250811-lock-class-key-cleanup-v3-1-b12967e= e1ca2@google.com --- rust/kernel/sync.rs | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/rust/kernel/sync.rs b/rust/kernel/sync.rs index 5df87e2bd212..1dfbee8e9d00 100644 --- a/rust/kernel/sync.rs +++ b/rust/kernel/sync.rs @@ -45,6 +45,21 @@ pub struct LockClassKey { unsafe impl Sync for LockClassKey {} =20 impl LockClassKey { + /// Initializes a statically allocated lock class key. + /// + /// This is usually used indirectly through the [`static_lock_class!`]= macro. + /// + /// # Safety + /// + /// * Before using the returned value, it must be pinned in a static m= emory location. + /// * The destructor must never run on the returned `LockClassKey`. + #[doc(hidden)] + pub const unsafe fn new_static() -> Self { + LockClassKey { + inner: Opaque::uninit(), + } + } + /// Initializes a dynamically allocated lock class key. In the common = case of using a /// statically allocated lock class key, the static_lock_class! macro = should be used instead. /// @@ -101,12 +116,9 @@ fn drop(self: Pin<&mut Self>) { macro_rules! static_lock_class { () =3D> {{ static CLASS: $crate::sync::LockClassKey =3D - // Lockdep expects uninitialized memory when it's handed a sta= tically allocated `struct - // lock_class_key`. - // - // SAFETY: `LockClassKey` transparently wraps `Opaque` which p= ermits uninitialized - // memory. - unsafe { ::core::mem::MaybeUninit::uninit().assume_init() }; + // SAFETY: The returned `LockClassKey` is stored in static mem= ory and we pin it. Drop + // never runs on a static global. + unsafe { $crate::sync::LockClassKey::new_static() }; $crate::prelude::Pin::static_ref(&CLASS) }}; } --=20 2.51.0