From nobody Fri Oct 3 16:40:13 2025 Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) (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 953B9223DDD; Thu, 28 Aug 2025 20:53:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.112 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756414394; cv=pass; b=isjCeQwo030cGwCuOWyn6nItzF4m24Omz/MotAAQcVvBYfNVAAdQzUIqzp7UQbY+Pe3lkHFbC8aQT9Qfz9ucxALbcDY0dEnfPkNIi4cbRsUxTIef1XYTfYR7+G82ptoYJHR8U06fCD86l1+nf3ESWyzbeA3gjtPHc0J4dAqD074= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756414394; c=relaxed/simple; bh=ml6FKS6NYtN5XzgKBC9OB62SYvKtyoW/Npz59dU9wDM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pO9JT0eERMxbz5Ib2K3fb7HEjw6dog4JsOgzTuOSKCgbJMNtFC/nuAQBcKpeyEYkDy0E2N6qx/pUvq11GYfh0qqIBrn6swbngYdrhi79ebDltAmTCdZ68s2FUTqly18iJ1z+rRR6ndx9FVQNf3YcgSi/5D71XG77KaiAT1W3Yi0= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (1024-bit key) header.d=collabora.com header.i=daniel.almeida@collabora.com header.b=bryn2ljn; arc=pass smtp.client-ip=136.143.188.112 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 (1024-bit key) header.d=collabora.com header.i=daniel.almeida@collabora.com header.b="bryn2ljn" ARC-Seal: i=1; a=rsa-sha256; t=1756414372; cv=none; d=zohomail.com; s=zohoarc; b=JVp7avEZMEFFW8zvRIO/Jnp/uSAuYGbL3GZ0m0v9CtknFqh3Ffz5pwEuD8zuKEcR5vvlN5wjPV8HwZlNBzNPEJVwa+Y7SnGKK4bWpeMxDUKpjgtfD27+N1BnmZQ+k49DcFkts3eQ56CzY/djl7Z3c9RWbfuzwfFq5IUHDbKLAiM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1756414372; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=avOuCwsXzd/3kp2rlCFI8ziT5ewR4e3wib7MI1JPpJA=; b=GCFHAnAgzx22FudQ/rW5FSmnY9O8kuq8KWU+Vwktz1OF9I9iGX+3yBCa0ys/9okP598EkJ71xIEir/2HM6M4LSPHVhhBaxQTkXq61jjbTrP44l46dVthZzoFsHF4sOnwV6yXCWDPkOex5E1QjBpIEYje7S86E2YGbD+DpFWecNE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=daniel.almeida@collabora.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1756414372; s=zohomail; d=collabora.com; i=daniel.almeida@collabora.com; h=From:From:Date:Date:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Message-Id:References:In-Reply-To:To:To:Cc:Cc:Reply-To; bh=avOuCwsXzd/3kp2rlCFI8ziT5ewR4e3wib7MI1JPpJA=; b=bryn2ljncdcU0SQW1DQQlhdRsAOKvM8PspT6ykvbfPR9rfzSiYBt81RGlEPxvWQA T297lfstWd1LvXhGVELicQJX21xCKDyslSvdsd1xzLdLB2WnettlxU9aeLHPeRTM2AC R1YgDZSfq9tjqaf60KilJHYmnoFYvyEnXNH8cgkQ= Received: by mx.zohomail.com with SMTPS id 1756414369613309.01930956826266; Thu, 28 Aug 2025 13:52:49 -0700 (PDT) From: Daniel Almeida Date: Thu, 28 Aug 2025 17:52:17 -0300 Subject: [PATCH v2 1/3] rust: lock: guard: add T: Unpin bound to DerefMut 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: <20250828-lock-t-when-t-is-pinned-v2-1-b067c4b93fd6@collabora.com> References: <20250828-lock-t-when-t-is-pinned-v2-0-b067c4b93fd6@collabora.com> In-Reply-To: <20250828-lock-t-when-t-is-pinned-v2-0-b067c4b93fd6@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 X-ZohoMailClient: External A core property of pinned types is not handing a mutable reference to the inner data in safe code, as this trivially allows that data to be moved. Enforce this condition by adding a bound on lock::Guard's DerefMut implementation, so that it's only implemented for pinning-agnostic types. 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 --- rust/kernel/sync/lock.rs | 5 ++++- rust/kernel/sync/lock/global.rs | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/rust/kernel/sync/lock.rs b/rust/kernel/sync/lock.rs index 27202beef90c88dda13c58bbea9e8d4ce8d314de..b482f34bf0ce817e70f7a0da934= 43f77dd19ea79 100644 --- a/rust/kernel/sync/lock.rs +++ b/rust/kernel/sync/lock.rs @@ -251,7 +251,10 @@ fn deref(&self) -> &Self::Target { } } =20 -impl core::ops::DerefMut for Guard<'_, T, B> { +impl core::ops::DerefMut for Guard<'_, T, B> +where + T: Unpin, +{ fn deref_mut(&mut self) -> &mut Self::Target { // SAFETY: The caller owns the lock, so it is safe to deref the pr= otected data. unsafe { &mut *self.lock.data.get() } diff --git a/rust/kernel/sync/lock/global.rs b/rust/kernel/sync/lock/global= .rs index d65f94b5caf2668586088417323496629492932f..38b44803279986275616eef499f= d40b8d4e97fdf 100644 --- a/rust/kernel/sync/lock/global.rs +++ b/rust/kernel/sync/lock/global.rs @@ -106,7 +106,10 @@ fn deref(&self) -> &Self::Target { } } =20 -impl core::ops::DerefMut for GlobalGuard { +impl core::ops::DerefMut for GlobalGuard +where + B::Item: Unpin, +{ fn deref_mut(&mut self) -> &mut Self::Target { &mut self.inner } --=20 2.50.1