summaryrefslogtreecommitdiff
path: root/rust/kernel/time/hrtimer/tbox.rs
diff options
context:
space:
mode:
authorLyude Paul <lyude@redhat.com>2025-08-21 15:32:44 -0400
committerAndreas Hindborg <a.hindborg@kernel.org>2025-09-04 16:54:39 +0200
commit3f2a5ba784b808109cac0aac921213e43143a216 (patch)
tree8b02ea0e50ee18252b5ae4bcc57f9b8aabc4e815 /rust/kernel/time/hrtimer/tbox.rs
parent3efb9ce91c5279d7ea73563d1fb136077f52dd2e (diff)
rust: hrtimer: Add HrTimerCallbackContext and ::forward()
With Linux's hrtimer API, there's a number of methods that can only be called in two situations: * When we have exclusive access to the hrtimer and it is not currently active * When we're within the context of an hrtimer callback context This commit handles the second situation and implements hrtimer_forward() support in the context of a timer callback. We do this by introducing a HrTimerCallbackContext type which is provided to users during the RawHrTimerCallback::run() callback, and then add a forward() function to the type. Signed-off-by: Lyude Paul <lyude@redhat.com> Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com> Reviewed-by: Andreas Hindborg <a.hindborg@kernel.org> Link: https://lore.kernel.org/r/20250821193259.964504-5-lyude@redhat.com Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
Diffstat (limited to 'rust/kernel/time/hrtimer/tbox.rs')
-rw-r--r--rust/kernel/time/hrtimer/tbox.rs9
1 files changed, 8 insertions, 1 deletions
diff --git a/rust/kernel/time/hrtimer/tbox.rs b/rust/kernel/time/hrtimer/tbox.rs
index ec08303315f2..aa1ee31a7195 100644
--- a/rust/kernel/time/hrtimer/tbox.rs
+++ b/rust/kernel/time/hrtimer/tbox.rs
@@ -3,6 +3,7 @@
use super::HasHrTimer;
use super::HrTimer;
use super::HrTimerCallback;
+use super::HrTimerCallbackContext;
use super::HrTimerHandle;
use super::HrTimerMode;
use super::HrTimerPointer;
@@ -119,6 +120,12 @@ where
// `data_ptr` exist.
let data_mut_ref = unsafe { Pin::new_unchecked(&mut *data_ptr) };
- T::run(data_mut_ref).into_c()
+ // SAFETY:
+ // - By C API contract `timer_ptr` is the pointer that we passed when queuing the timer, so
+ // it is a valid pointer to a `HrTimer<T>` embedded in a `T`.
+ // - We are within `RawHrTimerCallback::run`
+ let context = unsafe { HrTimerCallbackContext::from_raw(timer_ptr) };
+
+ T::run(data_mut_ref, context).into_c()
}
}