From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 8E08921B8F5; Fri, 7 Mar 2025 14:21:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741357299; cv=none; b=qRhS3cOsN+qrkxQ7uNRnPe6wx4Dy5uZDuBiuDfPqvBbxG8dzDb8uhLDbomTNiQtWbL6BeOOrNNTeim9tDv7xr/MvPabfYHGxIHoUTHygPve89Xr2eYQ1ieoN+8qHtKeHXVquVR4X1Jzr562u+lbPTeR7hIqL/wFRPJuF93297bI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741357299; c=relaxed/simple; bh=ZOH/UQqsCWGldN/FcM22hIc5UpsP7++UJ+LlHVDdh84=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=rGBVOg/uFMjJaG9dY6OzUg1Hp/qxDybgyVAVf8jPZsV3AjYyeOXdSTafHuSyAT4QpWuIF3bA1M7dg+aACLz+Ax1vZB/Mbi/iAy/lZL4x0wPc8JR7OF5XDsbLACcs+reiisL7nTW9ZLnDhUm+cvh4BE+I9NE+6Yy7iaqs6sranKo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TjKCq9u8; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TjKCq9u8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F3D63C4CED1; Fri, 7 Mar 2025 14:21:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741357299; bh=ZOH/UQqsCWGldN/FcM22hIc5UpsP7++UJ+LlHVDdh84=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=TjKCq9u8CpdnMTR84V2WKhTuTKhwoERz/DSmHx9cZfEDJTzR+5GJQflc9HELadOuf 63WZOgavwoD0V6xWAbGKogb4/3BOetshMpPHZGuNyiyIVXMEL4keD13qYyWaKhZs1N /tX6g4Qa+gn9L7aPHdtdZXHH6+295BjS8vFlzCEiSH5RGMIVcC4ZyHtpzKCaUELaPK lSe8hFN+m3zyviGmVccDrDmIXirhgGbgPvRCL2Uh0+jFljuz80SsYSD3d/K+6iigHn uQKikPDAZcXtpCqVgabnRx60rKdAbn5rXsL3uy09Zt28D10Hc7cTPyNnhckVcyF6bN IqAamvcf+50ew== From: Andreas Hindborg To: "Benno Lossin" Cc: "Miguel Ojeda" , "Anna-Maria Behnsen" , "Frederic Weisbecker" , "Thomas Gleixner" , "Danilo Krummrich" , "Alex Gaynor" , "Boqun Feng" , "Gary Guo" , =?utf-8?Q?Bj?= =?utf-8?Q?=C3=B6rn?= Roy Baron , "Alice Ryhl" , "Trevor Gross" , "Lyude Paul" , "Guangbo Cui" <2407018371@qq.com>, "Dirk Behme" , "Daniel Almeida" , "Tamir Duberstein" , "Markus Elfring" , , Subject: Re: [PATCH v10 07/13] rust: hrtimer: implement `UnsafeHrTimerPointer` for `Pin<&T>` In-Reply-To: (Benno Lossin's message of "Fri, 07 Mar 2025 13:51:01 +0000") 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> User-Agent: mu4e 1.12.7; emacs 29.4 Date: Fri, 07 Mar 2025 15:21:31 +0100 Message-ID: <87ikok3or8.fsf@kernel.org> 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 "Benno Lossin" writes: > 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 = Self>, >>>> +{ >>>> + type CallbackTarget<'b> = Self; >>>> + >>>> + unsafe extern "C" fn run(ptr: *mut bindings::hrtimer) -> bindings::hrtimer_restart { >>>> + // `HrTimer` is `repr(C)` >>>> + let timer_ptr = 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 = 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-conversion >> >> 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 guaranteed to >> // be alive until this method returns. As the handle borrows from >> // `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. It is in the safety requirement for the `HrTimerHandle` trait already. Should I reference it here? Best regards, Andreas Hindborg