From nobody Sun Oct 5 19:50:13 2025 Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2A9122E0B4E; Wed, 30 Jul 2025 17:15:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.251.105.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753895717; cv=none; b=qP3oXw0uDvB4/nF08DuFIm4cDCZeXW74CAmNJ+pZbTmn3FVs7Qzp+/l3YR9vpI3GMh+10Retjhis8gong/ho++DPxLdzscr7kd02IdFB2wg4RE5c1VsqoOMwT3NXWPH5e6hs/MooVna1VpjiV5lJ6zaBrrewE5RWZo5MIBZAXiQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753895717; c=relaxed/simple; bh=mTPBfKO4z4+W6J3cY3fLbZo21S5Y1PGCVi84PExWXcQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=U+GrNkcy3iYUsWRfsVQO3H5T4vaUPG0O5Tw4pZNxr9aYQqM5sUlDd+xAPozs3O4IZCWxKzGZP2FTOnm1CbYf5xuCl39qSJbEhewWAy4gUIR8uYTZFeQpxGAtK3LzIBdvXwGb8IjKYuUF8RY32R1n4mfJUrDWd9IOTK+VchAIKvU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=QRzF/Fbh; arc=none smtp.client-ip=148.251.105.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="QRzF/Fbh" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1753895713; bh=mTPBfKO4z4+W6J3cY3fLbZo21S5Y1PGCVi84PExWXcQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=QRzF/Fbh1UipAN19OrVb8tUoVGLk3DnLQXoCLm+6Mm4UTN4V0wAp0WDiI53s6Kgno B90DIqI/jC6i4/5tneT8kjdMonyrwv+Qxe88wfQIUJFLMppAScyOpYQf6Ueg3iK0Oq zcszsK65NkvXI78c0z+5aHYl+eozAp052mDsxLmW5Q4ndwFlxo06tce7pR481bR1jo uAYzfreFEsppBXMNAKU3FzOClgSfz7lz+0KfIXCd8DkV6s/xYIZJg2dtZChrfOS3AL gl2Z1REbU5oPYOKJ7q0RCpAC8JoomdPFVZlF2pu9pd4NCujjRziSHs0PBRbCA2Hejs Ez+3di4shtr0A== Received: from [192.168.0.7] (unknown [IPv6:2804:14d:72b4:82f6:67c:16ff:fe57:b5a3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: dwlsalmeida) by bali.collaboradmins.com (Postfix) with ESMTPSA id CFC6717E15D4; Wed, 30 Jul 2025 19:15:10 +0200 (CEST) From: Daniel Almeida Date: Wed, 30 Jul 2025 14:14:46 -0300 Subject: [PATCH 3/3] rust: lock: add a Pin<&mut T> accessor Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250730-lock-t-when-t-is-pinned-v1-3-1b97d5f28aa2@collabora.com> References: <20250730-lock-t-when-t-is-pinned-v1-0-1b97d5f28aa2@collabora.com> In-Reply-To: <20250730-lock-t-when-t-is-pinned-v1-0-1b97d5f28aa2@collabora.com> To: Peter Zijlstra , Ingo Molnar , Will Deacon , Boqun Feng , Waiman Long , Miguel Ojeda , Alex Gaynor , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich Cc: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, Daniel Almeida X-Mailer: b4 0.14.2 In order for callers to be able to access the inner T safely if T: !Unpin, there needs to be a way to get a Pin<&mut T>. Add this accessor and a corresponding example to tell users how it works. This is not useful on its own for now, because we do not support pin projections yet. This means that the following is not going to compile: let mut data: MutexGuard<'_, Data> =3D mutex.lock(); let mut data: Pin<&mut Data> =3D data.as_mut(); let foo =3D &mut data.foo; A future patch can enable the behavior above by implementing support for pin projections. Link: https://github.com/Rust-for-Linux/linux/issues/1181 Suggested-by: Benno Lossin Suggested-by: Boqun Feng Signed-off-by: Daniel Almeida --- rust/kernel/sync/lock.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/rust/kernel/sync/lock.rs b/rust/kernel/sync/lock.rs index 087bc0391f92a73b9af18ca31461b513bb5a9bcd..27857659a7f1ba4a8b844bb18d0= 09d037e0c5b03 100644 --- a/rust/kernel/sync/lock.rs +++ b/rust/kernel/sync/lock.rs @@ -243,6 +243,25 @@ pub(crate) fn do_unlocked(&mut self, cb: impl FnOnc= e() -> U) -> U { =20 cb() } + + /// Returns a pinned mutable reference to the protected data. + /// + /// # Examples + /// + /// ``` + /// # use kernel::sync::{Mutex, MutexGuard}; + /// # use core::pin::Pin; + /// struct Data; + /// + /// fn example(mutex: &Mutex) { + /// let mut data: MutexGuard<'_, Data> =3D mutex.lock(); + /// let mut data: Pin<&mut Data> =3D data.as_mut(); + /// } + /// ``` + pub fn as_mut(&mut self) -> Pin<&mut T> { + // SAFETY: `self.lock.data` is structurally pinned. + unsafe { Pin::new_unchecked(&mut *self.lock.data.get()) } + } } =20 impl core::ops::Deref for Guard<'_, T, B> { --=20 2.50.1