From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-0301.mail-europe.com (mail-0301.mail-europe.com [188.165.51.139]) (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 A729A18871F for ; Sun, 9 Mar 2025 10:05:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=188.165.51.139 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741514704; cv=none; b=sM1XFrlU4OpkWmPal2brlFJ4v/APq1ABZxq4b6UglmVjS+KH7Y8E4gL7rqMG8pXqvQaD1AK4XpkCLW356mNRNUoyHurSgvV8uS6Snrq7FzaPlvjiBEZAgnJvgUO7P72MqMmv5I7nlV5owH7h+ERvnhbr6EJd73jtwmpN1fUgXLE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741514704; c=relaxed/simple; bh=Y4RzcrAv3C3MxV3ublZX4KngWj4W06t5Aoo73M/dm1g=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Ngm5MDZJwLi7xl11mxMjhZoBWO04wEL3QxfXXOIZc0Bvfvyl78oyqioxv8/fxl36wn78lzYKl6ciDRZr3sd4hcWewN5gAoEAGz/LoHGxQaqBNTDLpaiTgeZA9s2NPb3CZetmdT+kuZ0xuNmjaBh2IKBunPVkJVRVWRhwSRvJm+Y= 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=c8qpYgle; arc=none smtp.client-ip=188.165.51.139 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="c8qpYgle" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1741514686; x=1741773886; bh=WOMrPVCPm5laEmGEnfGsypH0f9uJg3MVzLautjBZrNc=; 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=c8qpYgleB5OfSHNqeujYY0IZaJ97ylyVSuBwPRuoUBgSzYN8qTBqnzU5mixShkfW4 +ukZ0NRwFF7obe/0Q0z+tOXLXcUSJXTM/iU9avU4ZZltoQLiU04zsDVBLIZqQNjrJY QSX9XA4Od+FU1dvMV47r2zPL5YvHwo5oidkUB/fQHfXAI6cq1FMZAil43zbjwQ7SsL UoIXOXqIKVPKqJcZ/dF7NbVQvddaaL95unS5qeEyQGMnIxOrX9/TPIGIuKEnQ81/UA L+qDtRZd3K7IMh09d0XQCrJ0E23bHVazfmiiRiu36RZT4vYtaSaQd6H/kncS9PR//I QADTldYA8jSvQ== Date: Sun, 09 Mar 2025 10:04:42 +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 v11 08/13] rust: hrtimer: implement `UnsafeHrTimerPointer` for `Pin<&mut T>` Message-ID: In-Reply-To: <20250307-hrtimer-v3-v6-12-rc2-v11-8-7934aefd6993@kernel.org> References: <20250307-hrtimer-v3-v6-12-rc2-v11-0-7934aefd6993@kernel.org> <20250307-hrtimer-v3-v6-12-rc2-v11-8-7934aefd6993@kernel.org> Feedback-ID: 71780778:user:proton X-Pm-Message-ID: d7f9acef33476035d455c6cabdfd146334573b06 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 10:38 PM CET, Andreas Hindborg wrote: > +impl<'a, T> RawHrTimerCallback for Pin<&'a mut T> > +where > + T: HasHrTimer, > + T: HrTimerCallback =3D Self>, > +{ > + type CallbackTarget<'b> =3D Self; > + > + unsafe extern "C" fn run(ptr: *mut bindings::hrtimer) -> bindings::h= rtimer_restart { > + // `HrTimer` is `repr(C)` > + let timer_ptr =3D ptr as *mut HrTimer; > + > + // SAFETY: By the safety requirement of this function, `timer_pt= r` > + // points to a `HrTimer` contained in an `T`. > + let receiver_ptr =3D unsafe { T::timer_container_of(timer_ptr) }= ; > + > + // SAFETY: > + // - By the safety requirement of this function, `timer_ptr` > + // points to a `HrTimer` contained in an `T`. > + // - As per he safety requirements of the trait `HrTimerHandle`= , the > + // `PinMutHrTimerHandle` associated with this timer is guaran= teed to > + // be alive until this method returns. As the handle borrows = from > + // `T`, `T` is also guaranteed to be alive for the duration o= f this > + // function. Ah one more thing, I don't think that the second part is needed (i.e. that `T` is alive). How about: // - As per the safety requirements of the trait `HrTimerHandle`, = the `PinMutHrTimerHandle` // associated with this timer is guaranteed to be alive until this= method returns. That // handle borrows the `T` behind `receiver_ptr` mutably thus guara= nteeing the validity of // the reference created below. Can you also adjust the other instances of this in the other patches? Thanks! --- Cheers, Benno > + // - Because `PinMutTimerHandle` borrows mutably from `T`, the > + // reference we create here is guaranteed to be unique. > + let receiver_ref =3D unsafe { &mut *receiver_ptr }; > + > + // SAFETY: `receiver_ref` only exists as pinned, so it is safe t= o pin it > + // here. > + let receiver_pin =3D unsafe { Pin::new_unchecked(receiver_ref) }= ; > + > + T::run(receiver_pin).into_c() > + } > +} > > -- > 2.47.0