From nobody Wed Dec 17 21:27:10 2025 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 5E48D20CCE4; Fri, 6 Dec 2024 19:35:57 +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=1733513757; cv=none; b=WWNdFfWTcHi4ECPuq8uhHNwKdAlt59gzhPnM/xY8uEr3+VE6EPe46OYNcJu5LKaC/H4Q1zittOHHYxzS6OuLmBJZXpq+ERuYRhI88cK6PI5uXofA8ZUlH/utwj3XPLi0EL0nfnZRRediK6TZfU16VGwWBeuReFg/iNJo8/X9+fY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733513757; c=relaxed/simple; bh=YPhq18Bquk8BuL/sZQan8btRfhn1YbXyifWT40yfIzQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KlyZRhJuZQiKGBzey8/U6CpEAD7dDa7EXDroSgupC0tDc/pmekXKGY+O5YSE8uwpoVf2rFkWdYFOiLgt1yFWSYsoFpB1cKlfvvUwDo0wIdjZNUXCjePk4fgD7g1RsCZS3GT0MT5V4bDnelLN029+rFd0tv9wD64VaDzn12igVw4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HcuPaAQU; 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="HcuPaAQU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 77867C4CEDD; Fri, 6 Dec 2024 19:35:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733513757; bh=YPhq18Bquk8BuL/sZQan8btRfhn1YbXyifWT40yfIzQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=HcuPaAQUjUXeIy/Kw+o+9DNdR8nJRw5NYO5NqWu3ZbWsKzHECnGldFbGOvMJivl70 20mPoPMBSjxeINpXR/o/io3t5MqHhe1bF8DdPJhmGPD927ooeEd7cG1d4W64Zdl793 RLv1FU28Uj3CLOPklAhiOpERFrzntO/wWykaz0Zwp0VC3TaffsPgnm83WLPwM8D+1x NShe2AHgtZf0Q5yQLFZC/0+gNZ6Snj0nf89IQlpqJWPPWoE68YA+nl2zdjlUDx6s7T 548K31mFiXKwg5WqxAFC4C7Rta4sPKLA2bfZABgbHp4etRVDAWmxQKRWsfZrJTFHz0 xQEJJpt9dQ+ng== From: Andreas Hindborg Date: Fri, 06 Dec 2024 20:32:58 +0100 Subject: [PATCH v4 06/14] rust: hrtimer: add `UnsafeTimerPointer` Precedence: bulk X-Mailing-List: linux-kernel@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 Message-Id: <20241206-hrtimer-v3-v6-12-rc2-v4-6-6cb8c3673682@kernel.org> References: <20241206-hrtimer-v3-v6-12-rc2-v4-0-6cb8c3673682@kernel.org> In-Reply-To: <20241206-hrtimer-v3-v6-12-rc2-v4-0-6cb8c3673682@kernel.org> To: Miguel Ojeda , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Danilo Krummrich Cc: Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Lyude Paul , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Hindborg X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2124; i=a.hindborg@kernel.org; h=from:subject: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kNBQTNOTzgzUWViS3YwZmJzRk9LS3U4eHJ0ZEly QVIySUc0eC9GTUVlTW5OMzU1T3F1QwpicUF6VmpPVjdvUmlWQjRwTnNIeTFmZkFscEk4UWhpcyt lTTBJSjF6REpPWUkxWDQxb2VCUW1SL2h5bjVUUXhWCmNXMk9MeHZmb01ZeHZBPT0KPXV5RWEKLS 0tLS1FTkQgUEdQIE1FU1NBR0UtLS0tLQo= X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 Add a trait to allow unsafely queuing stack allocated timers. Signed-off-by: Andreas Hindborg --- rust/kernel/time/hrtimer.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index 632b28a8a6338e2841c59412f22268ff86410a8f..fab9bf2612ceaa1ce936ab9b9bc= 31b018a1a9aef 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -142,6 +142,39 @@ pub trait TimerPointer: Sync + Sized { fn start(self, expires: Ktime) -> Self::TimerHandle; } =20 +/// Unsafe version of [`TimerPointer`] for situations where leaking the +/// `TimerHandle` returned by `start` would be unsound. This is the case f= or +/// stack allocated timers. +/// +/// Typical implementers are pinned references such as [`Pin<&T>`]. +/// +/// # Safety +/// +/// Implementers of this trait must ensure that instances of types impleme= nting +/// [`UnsafeTimerPointer`] outlives any associated [`TimerPointer::TimerHa= ndle`] +/// instances. +/// +/// [`Pin<&T>`]: Box +pub unsafe trait UnsafeTimerPointer: Sync + Sized { + /// A handle representing a running timer. + /// + /// # Safety + /// + /// If the timer is running, or if the timer callback is executing whe= n the + /// handle is dropped, the drop method of `TimerHandle` must not return + /// until the timer is stopped and the callback has completed. + type TimerHandle: TimerHandle; + + /// Start the timer after `expires` time units. If the timer was alrea= dy + /// running, it is restarted at the new expiry time. + /// + /// # Safety + /// + /// Caller promises keep the timer structure alive until the timer is = dead. + /// Caller can ensure this by not leaking the returned `Self::TimerHan= dle`. + unsafe fn start(self, expires: Ktime) -> Self::TimerHandle; +} + /// Implemented by [`TimerPointer`] implementers to give the C timer callb= ack a /// function to call. // This is split from `TimerPointer` to make it easier to specify trait bo= unds. --=20 2.46.0