From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-40133.protonmail.ch (mail-40133.protonmail.ch [185.70.40.133]) (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 BF74521ADB7 for ; Fri, 7 Mar 2025 13:49:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.70.40.133 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741355394; cv=none; b=aaBHzQfw/C2rFQVN9ed/RAjNmHzpnh/bAI8889SJ1wQLXxN+dTtEXtGFh7sggbijToHhRmLWkD7/kLZS3mdZIP8ANdTSud/AiKEEErcxmLRNT7Io1HbwVHXawunhDtNSIOc37/LRG0POJVxQ4YgF4DThDIaEX+GpUCyFX/GETeg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741355394; c=relaxed/simple; bh=yW9/4dLSersMO4DNHldQci8zupCYVd7u26yzS3h3m0o=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=CQ0UXrrqbvViHo7zU6D50Q3L8lXyioJDtLU9nApLQ/YC1Se4lugVQa8zmAxFM6Uek5AeAbXZF3BiinT38F+nsqQOYDU4n0EEHsxMrQOYVJUXE8igROkQjKZK7hEgXgCTS5oGJUhL8ZfxvVr2J5makUcYtaCZFzKJDlvl23JQGfA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me; spf=pass smtp.mailfrom=proton.me; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b=mWBD89Ur; arc=none smtp.client-ip=185.70.40.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=proton.me Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b="mWBD89Ur" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=6fptnopq2ffptbx2q4fbd7bngq.protonmail; t=1741355389; x=1741614589; bh=EEYoYNAuUuPoPs1W8X1jIbMyhvVpA6cLe6iGvpj1uPg=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=mWBD89UrSunFxSSed9piHZRVnTVTQbSfHGj68T4nj05bbQwvR4DgIxFkpHzZ/J6Zt Q1kHAQezzzYRAFj6jIH+35y9OadKXgOuHlSefrTqaS9YfNxMWMge7w3fXunyCjD1yR 90sIhMEiMhSHMyQv4KJUjHXihlyonOYxW6ZYYwKwjoI1LsCJaVU6ZePMpLR4Ez+sRy dO07ivR/bO690AQwCmNLOmVxjEP54qsiauNBQ9SyhFw7aYmrSJnuIDnD3/CRtY6ZiH ke30h7hELhG3moZxZR+uFvWWTO5Ig1MoOeCpfDdiZDPTzjte18xw82Zu7DCBeuRAzY hBX0mCFcydjBA== Date: Fri, 07 Mar 2025 13:49:43 +0000 To: Andreas Hindborg , Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich From: Benno Lossin Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , Alice Ryhl , Trevor Gross , Lyude Paul , Guangbo Cui <2407018371@qq.com>, Dirk Behme , Daniel Almeida , Tamir Duberstein , Markus Elfring , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v10 08/13] rust: hrtimer: implement `UnsafeHrTimerPointer` for `Pin<&mut T>` Message-ID: In-Reply-To: <20250307-hrtimer-v3-v6-12-rc2-v10-8-0cf7e9491da4@kernel.org> References: <20250307-hrtimer-v3-v6-12-rc2-v10-0-0cf7e9491da4@kernel.org> <20250307-hrtimer-v3-v6-12-rc2-v10-8-0cf7e9491da4@kernel.org> Feedback-ID: 71780778:user:proton X-Pm-Message-ID: 1f35bcd8df090977494af4ce67698d317ace72b0 Precedence: bulk X-Mailing-List: rust-for-linux@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 On Fri Mar 7, 2025 at 11:11 AM CET, Andreas Hindborg wrote: > Allow pinned mutable references to structs that contain a `HrTimer` node = to > be scheduled with the `hrtimer` subsystem. > > Acked-by: Frederic Weisbecker > Reviewed-by: Lyude Paul > Signed-off-by: Andreas Hindborg > --- > rust/kernel/time/hrtimer.rs | 2 + > rust/kernel/time/hrtimer/pin_mut.rs | 101 ++++++++++++++++++++++++++++++= ++++++ > 2 files changed, 103 insertions(+) > > diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs > index 2ca56397eade..d2791fd624b7 100644 > --- a/rust/kernel/time/hrtimer.rs > +++ b/rust/kernel/time/hrtimer.rs > @@ -441,3 +441,5 @@ unsafe fn timer_container_of(ptr: *mut $crate::time::= hrtimer::HrTimer<$timer_typ > pub use arc::ArcHrTimerHandle; > mod pin; > pub use pin::PinHrTimerHandle; > +mod pin_mut; > +pub use pin_mut::PinMutHrTimerHandle; > diff --git a/rust/kernel/time/hrtimer/pin_mut.rs b/rust/kernel/time/hrtim= er/pin_mut.rs > new file mode 100644 > index 000000000000..4f4a9e9602d8 > --- /dev/null > +++ b/rust/kernel/time/hrtimer/pin_mut.rs > @@ -0,0 +1,101 @@ > +// SPDX-License-Identifier: GPL-2.0 > + > +use super::HasHrTimer; > +use super::HrTimer; > +use super::HrTimerCallback; > +use super::HrTimerHandle; > +use super::RawHrTimerCallback; > +use super::UnsafeHrTimerPointer; > +use crate::time::Ktime; > +use core::pin::Pin; > + > +/// A handle for a `Pin<&mut HasHrTimer>`. When the handle exists, the t= imer might > +/// be running. > +pub struct PinMutHrTimerHandle<'a, T> > +where > + T: HasHrTimer, > +{ > + pub(crate) inner: Pin<&'a mut T>, I just noticed, if `T: Unpin`, this is unsound in combination with you creating another `Pin<&mut T>` reference below for the callback, since then we have two `&mut T` pointing to the same value. So you should store a raw pointer instead. --- Cheers, Benno