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 B9B0917A319; Sun, 9 Mar 2025 10:09:15 +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=1741514955; cv=none; b=BZmzy1hEFvqDCGwivI9X3goYlUrZweEJPdmpre12HKG0HPiQhe62mDhnaT9+WMejVZFMifm7LzM+3OJQk/jEykROH/4v7fNMrB6F9C+IMEW6pFsOFt/YzosF+VHe4J3lfBq0QLUmCXlgRgJPH6Z//5/TXPuL/4n3oClL4yhPHA0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741514955; c=relaxed/simple; bh=C+xJjy9a26xtFek9Ow+eRfDFQ+TSQpx/FEE82qaeMGc=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=UmiFx16t2N6nL2FSWzD3XprjQLgTXlu1DnfJ7aN0TVpKLz9XfAvZKiuB1TKSMpZ2CFQGhAhm5jMUKWdQwnqdbMz0rshNwz5LB6weHoa6BLVM1nBTIdjaZJGkt9RXJUu31TJ1vYbVmvuQe6DocVLJ8GnVOH6OGOSUJKSS7iXTD/U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AQRt95xC; 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="AQRt95xC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D7925C4CEE5; Sun, 9 Mar 2025 10:09:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741514955; bh=C+xJjy9a26xtFek9Ow+eRfDFQ+TSQpx/FEE82qaeMGc=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=AQRt95xC+vKHVwna4eEQQbF3pqShSVfVlquCNh3I0Bg1FWTznowlP15s9nRDBD9Ct rdCvuJUL84sqpIx3zNq2umd9Np3ZA7GAxqF0+yPsiUr0QL1s6RS67+V4SHwCYced1G j2LHc4TEWH8kTdgE062oWVwDRduOZ4MBeAnGSDuSrqlBPQT3Uh/AL1fjFE8NIAbgkH i7TjWbE4uiNNQqdFGc9dqTbSzzwTEhuYHX6C/vu7ORxyDvgjMFfvVLuFYQJQwIjj5S JsTYkk3OzPtK08iBQaEfMkxIo26uSbkmGhrRrgKMxs2oLsEsB4VAsk3wkJW5541DOh zI5JDH2NYyqsw== 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 v11 08/13] rust: hrtimer: implement `UnsafeHrTimerPointer` for `Pin<&mut T>` In-Reply-To: (Benno Lossin's message of "Sun, 09 Mar 2025 10:04:42 +0000") References: <20250307-hrtimer-v3-v6-12-rc2-v11-0-7934aefd6993@kernel.org> <20250307-hrtimer-v3-v6-12-rc2-v11-8-7934aefd6993@kernel.org> User-Agent: mu4e 1.12.7; emacs 29.4 Date: Sun, 09 Mar 2025 11:08:59 +0100 Message-ID: <87frjmldms.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 10:38 PM CET, Andreas Hindborg wrote: >> +impl<'a, T> RawHrTimerCallback for Pin<&'a mut 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`. >> + // - As per he safety requirements of the trait `HrTimerHandle`, the >> + // `PinMutHrTimerHandle` 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. > > 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 guaranteeing the validity of > // the reference created below. OK. > > Can you also adjust the other instances of this in the other patches? > Thanks! Yes! Best regards, Andreas Hindborg