From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-40131.protonmail.ch (mail-40131.protonmail.ch [185.70.40.131]) (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 6020621ADC4 for ; Fri, 7 Mar 2025 13:51:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.70.40.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741355469; cv=none; b=gfJ4nMLxWFidXQrP17887F945au7qgZJR4unYRVU+KBqfuCrT8LadDTqNIxWXhkB4Mkwl1XwE/2xoR0uGzRNeoJQxlnSBj5dMtuSTPYk680lq4Gy+vm+lrP4ihSuFxOK0Jugk1TYUPMC/keAfgbMb8h4qyyPlLiJVXGEM4/ioSY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741355469; c=relaxed/simple; bh=yvJGPy1VFx0K6jKPXutCOnVSEUIflxIglSHngdnZmic=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=tAJwhV05jcX+k8XzCszAJu3LRwPsFjEWXRWjtJPdbsCE0Qx3EbnU3FHBZ3kbNr6AaEmRAKM2x4vzuBXKqvId0j3cY/JSMBxC5vb2a6IVwnCx/VjALFdWpDrROFTJTshK5emM9hF0FuH0j1wIF+I1g2a0Kuueov3JT1bkt48It1o= 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=bWKpYtaL; arc=none smtp.client-ip=185.70.40.131 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="bWKpYtaL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=ng65oqhcvbczrlbale3hstnoua.protonmail; t=1741355466; x=1741614666; bh=tElGIhgf67HZvxIrD/1jG0VGn45wzGBOfP+OypacSoI=; 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=bWKpYtaLOS0cuUusKzEF0DYrNOt3VY7fPZC96UtaMNUh6X/NjaTtCGum/W7TPV2CN w1pO3DASrvTDy/7l8488XC4Wa8radCDXOB1cpV3TDSDiZH+HMUVF9SSQXSUsRRi62P n1L9UHc/2tcW3d5cMJa/N/2orJNr1RsABZP1YBYxGu78UpEYdISS7aSMtCD58AMSSk rSbrKd9Jltp/UYNO1znSoBlf8MrVwbC3syTjRhccw2hK7nx/wc4qWp4a9geWtvr15X hJbEtvBNf887EEf4AtekdvTiTfwEkFZSIBQNuZ0jhkJHCUkpwBNldM0SuFIbvbwjae QgmS4mRa7Ra5Q== Date: Fri, 07 Mar 2025 13:51:01 +0000 To: Andreas Hindborg From: Benno Lossin Cc: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich , 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 07/13] rust: hrtimer: implement `UnsafeHrTimerPointer` for `Pin<&T>` Message-ID: In-Reply-To: <87msdx3qsg.fsf@kernel.org> References: <20250307-hrtimer-v3-v6-12-rc2-v10-0-0cf7e9491da4@kernel.org> <20250307-hrtimer-v3-v6-12-rc2-v10-7-0cf7e9491da4@kernel.org> <6-QyjoxR_6TYuJVEXwdFAZrhFz52ZDU_4-r64epTLFpOAMc3jM_REWS-v_7TzdcgYmq1j74UmTnhYW5HdT98bQ==@protonmail.internalid> <87msdx3qsg.fsf@kernel.org> Feedback-ID: 71780778:user:proton X-Pm-Message-ID: 97d428098d5b074b9a1647e0d6fec250d09e913c 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 2:37 PM CET, Andreas Hindborg wrote: > "Benno Lossin" writes: >> On Fri Mar 7, 2025 at 11:11 AM CET, Andreas Hindborg wrote: >>> +impl<'a, T> RawHrTimerCallback for Pin<&'a T> >>> +where >>> + T: HasHrTimer, >>> + T: HrTimerCallback =3D Self>, >>> +{ >>> + type CallbackTarget<'b> =3D Self; >>> + >>> + unsafe extern "C" fn run(ptr: *mut bindings::hrtimer) -> bindings:= :hrtimer_restart { >>> + // `HrTimer` is `repr(C)` >>> + let timer_ptr =3D ptr as *mut HrTimer; >>> + >>> + // SAFETY: By the safety requirement of this function, `timer_= ptr` >>> + // 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`. >> >> This justification seems wrong it talks about `HrTimer`, but here we >> have a `*const T`... Also see [1] (I am mainly interested in your >> justification for the lifetime). >> >> [1]: https://doc.rust-lang.org/std/ptr/index.html#pointer-to-reference-c= onversion > > How is this: > > // SAFETY: > // - By the safety requirement of this function, `timer_ptr` > // points to a `HrTimer` contained in an `T`. > // - The `PinHrTimerHandle` associated with this timer is guaran= teed to > // be alive until this method returns. As the handle borrows f= rom > // `T`, `T` is also guaranteed to be alive for the duration of= this > // function. Sounds good, if you can also explain (probably somewhere else, as every `RawHrTimerCallback` implementer will rely on this) why the handle lives for the duration of the callback. --- Cheers, Benno