Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2C8A4463B75 for ; Wed, 26 Aug 2026 16:29:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787761766; cv=none; b=V1UGPHyRukKop/KAFAICJEHz0zeV+2VT0b8DX67Pn5cTTt59uNUs4nx3mkQ/Htr7aTks5L98GmFDOd6xzilc38Nz0UZ114FpxaeO7b+Pvfehn5dqzvgBuNgG9ag00zvgSoc4vEEf2NUsQbq18eGKC0RNKPN3ZaoTA0ou9VWs0e8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787761766; c=relaxed/simple; bh=umWQcDWL+vKkAg6SI7BxeZrCQcDKXpYAG37pQ+lD/To=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MC9AG4vgZJh80Vq3c6BAtiLbEGP8xMeJK45ywQSc3hUDdvLSuOMb8wDwEr3W8bvyu4Zh6YJvPTP7p7lZU+zXEq/aRBgeDdDY8Z1JOZigdm/S9tTDDK07u9HIl576TIFFwXWuFi0c623uykgAMjMY5W3hE59++tZsXd82goVtkUY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fireburn.co.uk; spf=none smtp.mailfrom=fireburn.co.uk; dkim=pass (2048-bit key) header.d=fireburn-co-uk.20251104.gappssmtp.com header.i=@fireburn-co-uk.20251104.gappssmtp.com header.b=AC8kRLfE; arc=none smtp.client-ip=209.85.221.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=fireburn.co.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=fireburn.co.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=fireburn-co-uk.20251104.gappssmtp.com header.i=@fireburn-co-uk.20251104.gappssmtp.com header.b="AC8kRLfE" Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-482e1bfcc63so50379f8f.1 for ; Wed, 26 Aug 2026 09:29:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fireburn-co-uk.20251104.gappssmtp.com; s=20251104; t=1787761758; x=1788366558; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=RC90Kt3yL2qKSR4SdatW3E2dscmtZrN96AZ/Od58+hU=; b=AC8kRLfEnooy0wTnEumuPOhP/qPoe+q5XgGGt3ETWWbhmn0ChK4BmzIWR1sPtU8/E/ +1fIQn+32Xjwj/VLLsWBh3y2a+AdUxhNpjBLcsd/SiyX097awa/9JWo6H39/RrHaE2fg p8ELFMagJASeTeH44iFmaindmwMNMXlxKLPHVFbb3JgVu5/oVhEV0GjQWi0VM3J7ioOK +GE5MAb2AiA08zv+21+wD2KIYJOErRs96QQJBR0KzU+Y/KjBihvwwi/Vugx/Sk/EPVu5 16bShvOAHUjNGnrgynNxgfsdDqKOFegTflxrOjnDLy3Vuw2qLO/y+la97nxdlQIF7bnd KZTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787761758; x=1788366558; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=RC90Kt3yL2qKSR4SdatW3E2dscmtZrN96AZ/Od58+hU=; b=ZUW4M4ITIWU+wUtBH6gD5DRY4PtrkpKiJuSxBpr0k2x3xmVKxpA3QQnjLQnYaiBtUT zzEqKfpW8l9sNk8vCjyYq7lwYWB3KAGKNx/ghEtjUSi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002:a05:6000:25ee:b0:482:ea3e:882a with SMTP id ffacd0b85a97d-482eab75e7dmr419934f8f.6.1787761758366; Wed, 26 Aug 2026 09:29:18 -0700 (PDT) Received: from axion.fireburn.co.uk ([2a01:4b00:d309:1c00:caf1:6b20:8531:818c]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-482e27ab574sm3232342f8f.14.2026.08.26.09.29.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Aug 2026 09:29:17 -0700 (PDT) From: Mike Lothian To: rust-for-linux@vger.kernel.org Cc: Mike Lothian , Andreas Hindborg , Boqun Feng , FUJITA Tomonori , Frederic Weisbecker , Lyude Paul , Thomas Gleixner , Anna-Maria Behnsen , John Stultz , Stephen Boyd , Miguel Ojeda , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Danilo Krummrich , Daniel Almeida , Tamir Duberstein , Alexandre Courbot , =?UTF-8?q?Onur=20=C3=96zkan?= , linux-kernel@vger.kernel.org Subject: [PATCH 7/9] rust: hrtimer: expose interrupt state in hard callbacks Date: Wed, 26 Aug 2026 17:28:41 +0100 Message-ID: <20260826162851.2497-8-mike@fireburn.co.uk> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260826162851.2497-1-mike@fireburn.co.uk> References: <20260826162851.2497-1-mike@fireburn.co.uk> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Hard hrtimer modes guarantee that their callbacks run with local interrupts disabled. Carry that guarantee through HrTimerCallbackContext so users of IRQ-aware locks do not need to assert the callback context themselves. Assisted-by: Claude:claude-opus-5 Signed-off-by: Mike Lothian --- rust/kernel/time/hrtimer.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index 2d7f1131a813..a55b3ce53735 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -404,7 +404,7 @@ //! [`Arc`]: kernel::sync::Arc use super::{ClockSource, Delta, Instant}; -use crate::{prelude::*, types::Opaque}; +use crate::{interrupt::LocalInterruptDisabled, prelude::*, types::Opaque}; use core::{marker::PhantomData, ptr::NonNull}; use pin_init::PinInit; @@ -900,6 +900,11 @@ pub trait HrTimerMode: private::Sealed { type Expires: HrTimerExpires; } +/// A timer mode whose callback runs with local interrupts disabled. +/// +/// This trait is sealed by [`HrTimerMode`]. +pub trait HardHrTimerMode: HrTimerMode {} + /// Timer that expires at a fixed point in time. pub struct AbsoluteMode(PhantomData); @@ -982,6 +987,7 @@ impl HrTimerMode for AbsoluteHardMode { type Clock = C; type Expires = Instant; } +impl HardHrTimerMode for AbsoluteHardMode {} /// Timer with relative expiration, handled in hard irq context. pub struct RelativeHardMode(PhantomData); @@ -991,6 +997,7 @@ impl HrTimerMode for RelativeHardMode { type Clock = C; type Expires = Delta; } +impl HardHrTimerMode for RelativeHardMode {} /// Timer with absolute expiration, pinned to CPU and handled in hard irq context. pub struct AbsolutePinnedHardMode(PhantomData); @@ -1000,6 +1007,7 @@ impl HrTimerMode for AbsolutePinnedHardMode { type Clock = C; type Expires = Instant; } +impl HardHrTimerMode for AbsolutePinnedHardMode {} /// Timer with relative expiration, pinned to CPU and handled in hard irq context. pub struct RelativePinnedHardMode(PhantomData); @@ -1009,6 +1017,7 @@ impl HrTimerMode for RelativePinnedHardMode { type Clock = C; type Expires = Delta; } +impl HardHrTimerMode for RelativePinnedHardMode {} /// Privileged smart-pointer for a [`HrTimer`] callback context. /// @@ -1065,6 +1074,16 @@ pub fn forward(&mut self, now: HrTimerInstant, interval: Delta) -> u64 { pub fn forward_now(&mut self, duration: Delta) -> u64 { self.forward(HrTimerInstant::::now(), duration) } + + /// Returns proof that local interrupts are disabled for a hard timer callback. + pub fn local_interrupt_disabled(&self) -> &LocalInterruptDisabled + where + T::TimerMode: HardHrTimerMode, + { + // SAFETY: `Self` can only be constructed while running this timer's callback, and the + // `HardHrTimerMode` bound guarantees that the callback runs in hard interrupt context. + unsafe { LocalInterruptDisabled::assume_disabled() } + } } /// Use to implement the [`HasHrTimer`] trait.