From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qv1-f46.google.com (mail-qv1-f46.google.com [209.85.219.46]) (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 7E9DB26D4EE for ; Fri, 19 Sep 2025 09:13:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758273193; cv=none; b=AmxDkG6ijF+GGoJ1byspIMWgWhmIeTjPwUCpdg1sWBgcmhaO7WXPat3O9oW3JrlOEI6sN1C04fYDKK1EnlsJ+zUj8QxgsgH5cFHIllHK9bd6IWqD2V81PYQJhkR/wYDFSWQJThLl8HjfCYLgrpmfo1rim3va+QH7IYK4qTmXk6k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758273193; c=relaxed/simple; bh=6iII7fOYlyuZ8eQyG3nIT1ClvaKOibtuYRtJwPDwqjw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FfpAdz7nMwBhZQDicEBeEWKxiUIIBG5FCu54HoV0X9STGq+/dJh2uXQywO+JRx2+Cjo9Jf9uIhu7Gl7P7cZiNcqF6BoGuLtFta4y/VRX6r9Nl8dbLINQhuhx1QBPup/krmA4+qnt0TLoSKLpSPYB/DNv+OkWT/D7U6cpvA+miEQ= 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=foOFT6sQ; arc=none smtp.client-ip=209.85.219.46 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="foOFT6sQ" Received: by mail-qv1-f46.google.com with SMTP id 6a1803df08f44-77dd76f6964so29155376d6.1 for ; Fri, 19 Sep 2025 02:13:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1758273190; x=1758877990; 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=Tz+hRdDjBJIiUvT5QMJv4FOcC6A5SLAQN/E0smv/a6w=; b=foOFT6sQj+DqYplwDHoXOA6+ovMEpwod5lZoF3zjF+rG7AcnsMuD7kqnfPsr8Uxqfa xXMHRKxFdHQoUWC/jeXWMNEz5ZLnRpVwM7vAeRaYi/RA1INo1mEaEiRDZVg0Wh1oNhLa SsUbkeZivDQQi04wq2I1o3yhHzl4ig2dY+uC95g05B+wrA6QaJIqBj7uE5jppZH48w9H xgH8enZXAFCZzFUdoW21GoXtrMhkLwYyz8yVbtO5RfjjoetF1QRGXnbPre2K4BDt3mxb GAh1Rcayg1Sw76zj9ywf8yDyCemAaY+haDnNC3MnKqPtJzPFVmGRw7MS+LyZeKFllKHz cEug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758273190; x=1758877990; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Tz+hRdDjBJIiUvT5QMJv4FOcC6A5SLAQN/E0smv/a6w=; b=ox1fBOK3N05gTwynZXeHyYyR1tcX6FWrbNlWdTJuAlilLTIuzER+9/GP7MzT24KCm/ VtGbcEaUVZjd/7tDXnF2gJJuoTNl93RjNUrOLwAN9kJXyC8WOH3qybR9JeNSjmGHTNWC J66sorgQCmKhWkB7KeM/htDTRX2DuyPblW4+jymfq+0Jk/QrvP0ma/n8XPFq5QBTv4aE JhCfU5BvAZZZFKEWQoDSEEttrAWet9Bp8O8dGy4OpBuu6++uCFKYvypC23fJIMpKL8H0 5ZUejdM1Wr++1PD17BShAnRykxl/cnc3ETU24x8C+r+sVQMCwZGnYnnvckaqU7985sfK Veog== X-Gm-Message-State: AOJu0Yw5qdLYE4W+k/b52HWoeHu0WMjC0fKs5Dj5aIrXMK3FKEFsJk0Y fuLbDnWBMX64u5OxD3gnDOsZv5DvRFaZhIdllU2CqnVYG9c9CznQHEW/ X-Gm-Gg: ASbGncv3WzL5AszgqdWKdP7gwEFiTGouVrb++kmk7kw4blR3BOIOCy5OxVyRU8SUlWw rSJb+zo3LHMIJLErxns66EoIX6moju0MhzdHiAEsf1miJVbEXk/mCDvrVfLIPFPtWh9tinI/eSJ 3SXIF+/dsNSloypTYrIeCZwf3Dk5eo+KgQKVisNplhNI2LUwClxG8tSiO3t/hGUwBksg31aiFzJ 5kTcNYCMrW0xfTrGyuE/F1RCVMevwwaei2A1uqIhfFugHE6M+jhBpsQjQRxXNfgxMH3h4Bmx+VC ba7rRn7kkFHb5PI4hr5KehnYVECoSbcTTyzKpZRXhjXWOTNiELunYRqnPhwLmJL/mMc7ErAIFn4 NqytJqqMR+X/tBynj48byxtTIky1V0uxDx9YIZpsdrGXpxRndbGkR48zt1DLMnU6gO2vxkTiRbl bUP4ZY4jZI6U8R X-Google-Smtp-Source: AGHT+IGHdHKieKTrB7753iPEOZIDAZM2fgg6Vs6HuQORCmBrQ4D7MJr31cHmfl/qBr2eF2H/N1qLqg== X-Received: by 2002:a05:6214:20ce:b0:783:f54f:418a with SMTP id 6a1803df08f44-798bc7bf0damr31065416d6.15.1758273190002; Fri, 19 Sep 2025 02:13:10 -0700 (PDT) Received: from fauth-a2-smtp.messagingengine.com (fauth-a2-smtp.messagingengine.com. [103.168.172.201]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-793533ac961sm25881696d6.50.2025.09.19.02.13.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Sep 2025 02:13:09 -0700 (PDT) Received: from phl-compute-02.internal (phl-compute-02.internal [10.202.2.42]) by mailfauth.phl.internal (Postfix) with ESMTP id 23359F40067; Fri, 19 Sep 2025 05:13:09 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-02.internal (MEProxy); Fri, 19 Sep 2025 05:13:09 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggdegkeekvdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeeuohhquhhnucfh vghnghcuoegsohhquhhnrdhfvghnghesghhmrghilhdrtghomheqnecuggftrfgrthhtvg hrnhepkeetteejgeduieekudejfedvvddtiefgieffffeljeefieehiefffedvfeffgfet necuffhomhgrihhnpehgihhthhhusgdrtghomhdpkhgvrhhnvghlrdhorhhgnecuvehluh hsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepsghoqhhunhdomhgv shhmthhprghuthhhphgvrhhsohhnrghlihhthidqieelvdeghedtieegqddujeejkeehhe ehvddqsghoqhhunhdrfhgvnhhgpeepghhmrghilhdrtghomhesfhhigihmvgdrnhgrmhgv pdhnsggprhgtphhtthhopedvtddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepph gvthgvrhiisehnfhhrrgguvggrugdrohhrghdprhgtphhtthhopehmihhnghhosehkvghr nhgvlhdrohhrghdprhgtphhtthhopehtghhlgieslhhinhhuthhrohhnihigrdguvgdprh gtphhtthhopehruhhsthdqfhhorhdqlhhinhhugiesvhhgvghrrdhkvghrnhgvlhdrohhr ghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdroh hrghdprhgtphhtthhopehlkhhmmheslhhishhtshdrlhhinhhugidruggvvhdprhgtphht thhopeifihhllheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepphgvthgvrhiisehinh hfrhgruggvrggurdhorhhgpdhrtghpthhtoheplhhonhhgmhgrnhesrhgvughhrghtrdgt ohhm X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 19 Sep 2025 05:13:08 -0400 (EDT) From: Boqun Feng To: "Peter Zijlstra" , "Ingo Molnar" , "Thomas Gleixner" Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, lkmm@lists.linux.dev, "Will Deacon" , "Peter Zijlstra" , Waiman Long , "Miguel Ojeda" , alex.gaynor@gmail.com, "Gary Guo" , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , "Benno Lossin" , "Alice Ryhl" , "Trevor Gross" , "Danilo Krummrich" , "Andreas Hindborg" , Daniel Almeida , Boqun Feng Subject: [PATCH 3/4] rust: lock: Pin the inner data Date: Fri, 19 Sep 2025 11:12:40 +0200 Message-ID: <20250919091241.32138-4-boqun.feng@gmail.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250919091241.32138-1-boqun.feng@gmail.com> References: <20250919091241.32138-1-boqun.feng@gmail.com> Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Daniel Almeida In preparation to support Lock where T is pinned, the first thing that needs to be done is to structurally pin the 'data' member. This switches the 't' parameter in Lock::new() to take in an impl PinInit instead of a plain T. This in turn uses the blanket implementation "impl PinInit for T". Subsequent patches will touch on Guard. Link: https://github.com/Rust-for-Linux/linux/issues/1181 Suggested-by: Benno Lossin Suggested-by: Boqun Feng Reviewed-by: Benno Lossin Reviewed-by: Alice Ryhl Signed-off-by: Daniel Almeida Signed-off-by: Boqun Feng --- Notes: SubmissionLink: https://lore.kernel.org/all/20250828-lock-t-when-t-is-pinned-v2-2-b067c4b93fd6@collabora.com/ rust/kernel/sync/lock.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/rust/kernel/sync/lock.rs b/rust/kernel/sync/lock.rs index b482f34bf0ce..9242790d15db 100644 --- a/rust/kernel/sync/lock.rs +++ b/rust/kernel/sync/lock.rs @@ -11,7 +11,7 @@ types::{NotThreadSafe, Opaque, ScopeGuard}, }; use core::{cell::UnsafeCell, marker::PhantomPinned, pin::Pin}; -use pin_init::{pin_data, pin_init, PinInit}; +use pin_init::{pin_data, pin_init, PinInit, Wrapper}; pub mod mutex; pub mod spinlock; @@ -115,6 +115,7 @@ pub struct Lock { _pin: PhantomPinned, /// The data protected by the lock. + #[pin] pub(crate) data: UnsafeCell, } @@ -127,9 +128,13 @@ unsafe impl Sync for Lock {} impl Lock { /// Constructs a new lock initialiser. - pub fn new(t: T, name: &'static CStr, key: Pin<&'static LockClassKey>) -> impl PinInit { + pub fn new( + t: impl PinInit, + name: &'static CStr, + key: Pin<&'static LockClassKey>, + ) -> impl PinInit { pin_init!(Self { - data: UnsafeCell::new(t), + data <- UnsafeCell::pin_init(t), _pin: PhantomPinned, // SAFETY: `slot` is valid while the closure is called and both `name` and `key` have // static lifetimes so they live indefinitely. -- 2.51.0