From nobody Thu Oct 2 09:19:14 2025 Received: from mail-qt1-f179.google.com (mail-qt1-f179.google.com [209.85.160.179]) (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 D2A012FDC4E for ; Fri, 19 Sep 2025 09:13:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758273190; cv=none; b=LTCGXcPoeGUvfxFirdcRVM20thS+2BeH1NKjjCQjQLkMFISgnBoMCGmZLG92SU9WY8n6nnge2h2hgMxO5jJ32Q27M5KCRhsnb1pRdk1TFT5awfAjFArrB9IyYbh7MYIMN4nJMMgSTaxMCCkH5Zt84YJ88jRQVF6Z2t4kkK7g7HA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758273190; c=relaxed/simple; bh=Lzovmfm5FiaEorEh9d/YkmbdKQ4FW9Q9fpLfGCU4K1Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TxX5MgdpZ0fy6mnGtLOk+MDjTx/TMXsZFr4z9thUAyG6T69d9OYOjJqVqBkdPJFymCc85tw0g2GXzyED6hJ3KPN3DgXC3eH7WupHwAJ7AvwNrD6Tdm7ADaul32VdG4n5OtuMu0rAvFNCHgTPFi3S6wdzIjF4XPzEwX6bNQMGQ/E= 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=HdbmJC25; arc=none smtp.client-ip=209.85.160.179 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="HdbmJC25" Received: by mail-qt1-f179.google.com with SMTP id d75a77b69052e-4b548745253so30569341cf.0 for ; Fri, 19 Sep 2025 02:13:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1758273187; x=1758877987; 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=kIwF6rXqWhVto9ZPqUAqlWxtbpHvuz3MRQbuOi5HJu4=; b=HdbmJC25TshYjud28rUPQqyU3sfKngH067nsd6b7RiZRMLUyz3SUNGdBNBmDJBjS8V Cg4AMRH2zIr4qwoXRLUYxMxEnteJjFkSRKzgz5Th60x6uXmijHvo3/AnVj3kmXAyHtpA rhcEQ+eferXCJfTFM5Jxy2apoyitg0bYSXSRWMbqtvhbpH6BGZOuhZuVR/ggMWUmuf9F tNgymEjhu1/SyYqBulq9R7l0ZVcZyWcPtnq9dGRy8mVzRtQK3UKzYcg0iVGnlT2WQTXr t01PwTWiXMoQ36zdsMpwYl/0DZ23OpvraxlnEJh4qZ2Tqx4I2ToBhYESLdXGr7bVjBMy 0qtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758273187; x=1758877987; 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=kIwF6rXqWhVto9ZPqUAqlWxtbpHvuz3MRQbuOi5HJu4=; b=u4eVuSMsaXoJFY0ReYR94vhzjU5qRx+4uvJoxkNi1B1eSJz7jL+crnZKzT2Sso4IY9 bNAqvzcLU+5zX+l1YxHyGNfMuDucGyijjsGT86bGUI4gRNmEBn6RlAe8reqro91hhnfT 5LHRBfWl6LBFTBV1KH89SWkYK+F4tpikVGrePjI5KUEaBwfF3IoyLfiICIs5U5fUeDFo 2lpS/C58zhEszOiz/nvlLTJT4FFBFFyD8PyD+SmdN4hyvUqDJoJlNMz0wngoAc2w/ma7 b6lRziiuQr4KzhJEjcYl8Xw4heXzBwljrkOXzBvViOsRekETDP/GEQ47NS4cJ9MPgQjA he9A== X-Forwarded-Encrypted: i=1; AJvYcCVPyysYBH3ygtcfid6WynPhJ2YA5biiWPQB4PWpjkpSL4zUbz+P602q13lvRwGBVWpuUyveL71//Hq0uF0=@vger.kernel.org X-Gm-Message-State: AOJu0YxEpKNtCXo8MXGEdkiewSIYzCKek2BbuGWgHMVpKkOicqJfo0XX 9HuKv3s0gpJiDe5jPTnPcwTgMtXVJy5eg9xKmJJGnTlGXhKgNbYhcfuK X-Gm-Gg: ASbGncumpDxDC1YLPiKL0T0klQ+ze63Afx5gebWi5QguS1HnEeHYp+L9z2MTfXlIC1i 3HBNFyssSBXGEDck2PDCopnBqr1I3U66Bt8SV0a/el92EkNdsJnKHa1tENg875G6oOH4WnreQAp 8X7skHHjtWkGqIozsK5d4fLP+PSu/yl+Kef8AwhKfOsytR75B5NiPT5aIZL51JcCZdVdz0nHik/ oA/+j8TGEXc+wtzf+Ad+rxJWob9FeMb8CRCFikcyfYTQtXyO/a9qRThB0r3PsXuJXl6BwzNeQY6 KIVnQH4KGaEXfV5otm3UytndkTJM9NBJ9rFogYWK0qWBdddztjnEJ6w/4oZOILD+r3td2fXqf9p 0WrlQWRkolLrrxnKkafYEC5L8gEiVRhkirmzcPH5rMBdnwsvu7feac90bhJpBVUYEV9qWcoGyYq 14osHM0Aews/Vr X-Google-Smtp-Source: AGHT+IGADpUlc4d6GuGOP+3nLljBkz9sqj/QHSoZhghqe3A6PffXI/lWFd81SOfDZ9Hd2vishRWIPA== X-Received: by 2002:ac8:5dd1:0:b0:4b4:96a8:f79c with SMTP id d75a77b69052e-4c073c99e35mr31025171cf.79.1758273186690; Fri, 19 Sep 2025 02:13:06 -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 d75a77b69052e-4bda2c6d0c5sm26674071cf.21.2025.09.19.02.13.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Sep 2025 02:13:06 -0700 (PDT) Received: from phl-compute-01.internal (phl-compute-01.internal [10.202.2.41]) by mailfauth.phl.internal (Postfix) with ESMTP id DBC8AF40066; Fri, 19 Sep 2025 05:13:05 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-01.internal (MEProxy); Fri, 19 Sep 2025 05:13:05 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggdegkeekvdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeeuohhquhhnucfh vghnghcuoegsohhquhhnrdhfvghnghesghhmrghilhdrtghomheqnecuggftrfgrthhtvg hrnheptedtteegjeefffeileevheeguddvleekfeeigfevgffhfeetieekgfffhfeiledv necuffhomhgrihhnpehgihhthhhusgdrtghomhdpkhgvrhhnvghlrdhorhhgpdhlohgtkh druggrthgrnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhho mhepsghoqhhunhdomhgvshhmthhprghuthhhphgvrhhsohhnrghlihhthidqieelvdeghe dtieegqddujeejkeehheehvddqsghoqhhunhdrfhgvnhhgpeepghhmrghilhdrtghomhes fhhigihmvgdrnhgrmhgvpdhnsggprhgtphhtthhopedvtddpmhhouggvpehsmhhtphhouh htpdhrtghpthhtohepphgvthgvrhiisehnfhhrrgguvggrugdrohhrghdprhgtphhtthho pehmihhnghhosehkvghrnhgvlhdrohhrghdprhgtphhtthhopehtghhlgieslhhinhhuth hrohhnihigrdguvgdprhgtphhtthhopehruhhsthdqfhhorhdqlhhinhhugiesvhhgvghr rdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvg hrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlkhhmmheslhhishhtshdrlhhinhhu gidruggvvhdprhgtphhtthhopeifihhllheskhgvrhhnvghlrdhorhhgpdhrtghpthhtoh epphgvthgvrhiisehinhhfrhgruggvrggurdhorhhgpdhrtghpthhtoheplhhonhhgmhgr nhesrhgvughhrghtrdgtohhm X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 19 Sep 2025 05:13:04 -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 2/4] rust: lock: guard: Add T: Unpin bound to DerefMut Date: Fri, 19 Sep 2025 11:12:39 +0200 Message-ID: <20250919091241.32138-3-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: 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: Daniel Almeida 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 Signed-off-by: Boqun Feng --- Notes: SubmissionLink: https://lore.kernel.org/all/20250828-lock-t-when-t-is-p= inned-v2-1-b067c4b93fd6@collabora.com/ 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 27202beef90c..b482f34bf0ce 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 d65f94b5caf2..38b448032799 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.51.0