<feed xmlns='http://www.w3.org/2005/Atom'>
<title>user/sven/linux.git/rust/kernel/time, branch v6.17</title>
<subtitle>Linux Kernel
</subtitle>
<id>https://git.stealer.net/cgit.cgi/user/sven/linux.git/atom?h=v6.17</id>
<link rel='self' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/atom?h=v6.17'/>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/'/>
<updated>2025-07-16T22:55:35Z</updated>
<entry>
<title>rust: time: Pass correct timer mode ID to hrtimer_start_range_ns</title>
<updated>2025-07-16T22:55:35Z</updated>
<author>
<name>Lyude Paul</name>
<email>lyude@redhat.com</email>
</author>
<published>2025-07-10T22:51:13Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=23b128bba76776541dc09efaf3acf6242917e1f0'/>
<id>urn:sha1:23b128bba76776541dc09efaf3acf6242917e1f0</id>
<content type='text'>
While rebasing rvkms I noticed that timers I was setting seemed to have
pretty random timer values that amounted slightly over 2x the time value I
set each time. After a lot of debugging, I finally managed to figure out
why: it seems that since we moved to Instant and Delta, we mistakenly
began passing the clocksource ID to hrtimer_start_range_ns, when we should
be passing the timer mode instead. Presumably, this works fine for simple
relative timers - but immediately breaks on other types of timers.

So, fix this by passing the ID for the timer mode instead.

Signed-off-by: Lyude Paul &lt;lyude@redhat.com&gt;
Acked-by: Andreas Hindborg &lt;a.hindborg@kernel.org&gt;
Reviewed-by: FUJITA Tomonori &lt;fujita.tomonori@gmail.com&gt;
Fixes: e0c0ab04f678 ("rust: time: Make HasHrTimer generic over HrTimerMode")
Link: https://lore.kernel.org/r/20250710225129.670051-1-lyude@redhat.com
[ Removed cast, applied `rustfmt`, fixed `Fixes:` tag. - Miguel ]
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>Merge tag 'rust-timekeeping-for-v6.17' of https://github.com/Rust-for-Linux/linux into rust-next</title>
<updated>2025-07-16T21:45:08Z</updated>
<author>
<name>Miguel Ojeda</name>
<email>ojeda@kernel.org</email>
</author>
<published>2025-07-16T21:45:08Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=77580e801a981f0c24c886460840d1ed70c794ae'/>
<id>urn:sha1:77580e801a981f0c24c886460840d1ed70c794ae</id>
<content type='text'>
Pull timekeeping updates from Andreas Hindborg:

 - Make 'Instant' generic over clock source. This allows the compiler to
   assert that arithmetic expressions involving the 'Instant' use
   'Instants' based on the same clock source.

 - Make 'HrTimer' generic over the timer mode. 'HrTimer' timers take a
   'Duration' or an 'Instant' when setting the expiry time, depending on
   the timer mode. With this change, the compiler can check the type
   matches the timer mode.

 - Add an abstraction for 'fsleep'. 'fsleep' is a flexible sleep
   function that will select an appropriate sleep method depending on
   the requested sleep time.

 - Avoid 64-bit divisions on 32-bit hardware when calculating
   timestamps.

 - Seal the 'HrTimerMode' trait. This prevents users of the
   'HrTimerMode' from implementing the trait on their own types.

* tag 'rust-timekeeping-for-v6.17' of https://github.com/Rust-for-Linux/linux:
  rust: time: Add wrapper for fsleep() function
  rust: time: Seal the HrTimerMode trait
  rust: time: Remove Ktime in hrtimer
  rust: time: Make HasHrTimer generic over HrTimerMode
  rust: time: Add HrTimerExpires trait
  rust: time: Replace HrTimerMode enum with trait-based mode types
  rust: time: Add ktime_get() to ClockSource trait
  rust: time: Make Instant generic over ClockSource
  rust: time: Replace ClockId enum with ClockSource trait
  rust: time: Avoid 64-bit integer division on 32-bit architectures
</content>
</entry>
<entry>
<title>rust: types: rename Opaque::raw_get to cast_into</title>
<updated>2025-07-15T20:26:11Z</updated>
<author>
<name>Alice Ryhl</name>
<email>aliceryhl@google.com</email>
</author>
<published>2025-06-24T15:27:56Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=64fb810bce03a4e2b4d3ecbba04bb97da3536dd8'/>
<id>urn:sha1:64fb810bce03a4e2b4d3ecbba04bb97da3536dd8</id>
<content type='text'>
In the previous patch we added Opaque::cast_from() that performs the
opposite operation to Opaque::raw_get(). For consistency with this
naming, rename raw_get() to cast_from().

There are a few other options such as calling cast_from() something
closer to raw_get() rather than renaming this method. However, I could
not find a great naming scheme that works with raw_get(). The previous
version of this patch used from_raw(), but functions of that name
typically have a different signature, so that's not a great option.

Suggested-by: Danilo Krummrich &lt;dakr@kernel.org&gt;
Signed-off-by: Alice Ryhl &lt;aliceryhl@google.com&gt;
Acked-by: Benno Lossin &lt;lossin@kernel.org&gt;
Acked-by: Andreas Hindborg &lt;a.hindborg@kernel.org&gt;
Acked-by: Boqun Feng &lt;boqun.feng@gmail.com&gt;
Reviewed-by: Danilo Krummrich &lt;dakr@kernel.org&gt;
Acked-by: Danilo Krummrich &lt;dakr@kernel.org&gt;
Link: https://lore.kernel.org/r/20250624-opaque-from-raw-v2-2-e4da40bdc59c@google.com
[ Removed `HrTimer::raw_get` change. - Miguel ]
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: time: Add wrapper for fsleep() function</title>
<updated>2025-06-30T11:22:05Z</updated>
<author>
<name>FUJITA Tomonori</name>
<email>fujita.tomonori@gmail.com</email>
</author>
<published>2025-06-17T14:41:55Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=d4b29ddf82a458935f1bd4909b8a7a13df9d3bdc'/>
<id>urn:sha1:d4b29ddf82a458935f1bd4909b8a7a13df9d3bdc</id>
<content type='text'>
Add a wrapper for fsleep(), flexible sleep functions in
include/linux/delay.h which typically deals with hardware delays.

The kernel supports several sleep functions to handle various lengths
of delay. This adds fsleep(), automatically chooses the best sleep
method based on a duration.

fsleep() can only be used in a nonatomic context. This requirement is
not checked by these abstractions, but it is intended that klint [1]
or a similar tool will be used to check it in the future.

Link: https://rust-for-linux.com/klint [1]
Reviewed-by: Gary Guo &lt;gary@garyguo.net&gt;
Reviewed-by: Alice Ryhl &lt;aliceryhl@google.com&gt;
Reviewed-by: Fiona Behrens &lt;me@kloenk.dev&gt;
Tested-by: Daniel Almeida &lt;daniel.almeida@collabora.com&gt;
Reviewed-by: Andreas Hindborg &lt;a.hindborg@kernel.org&gt;
Signed-off-by: FUJITA Tomonori &lt;fujita.tomonori@gmail.com&gt;
Link: https://lore.kernel.org/r/20250617144155.3903431-3-fujita.tomonori@gmail.com
Signed-off-by: Andreas Hindborg &lt;a.hindborg@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: time: Seal the HrTimerMode trait</title>
<updated>2025-06-30T10:39:13Z</updated>
<author>
<name>FUJITA Tomonori</name>
<email>fujita.tomonori@gmail.com</email>
</author>
<published>2025-06-17T23:28:06Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=fc38b7ff879683669bd9ff5dc7e7b6aeeb07bf2a'/>
<id>urn:sha1:fc38b7ff879683669bd9ff5dc7e7b6aeeb07bf2a</id>
<content type='text'>
Prevent downstream crates or drivers from implementing `HrTimerMode`
for arbitrary types, which could otherwise leads to unsupported
behavior.

Introduce a `private::Sealed` trait and implement it for all types
that implement `HrTimerMode`.

Signed-off-by: FUJITA Tomonori &lt;fujita.tomonori@gmail.com&gt;
Reviewed-by: Boqun Feng &lt;boqun.feng@gmail.com&gt;
Link: https://lore.kernel.org/r/20250617232806.3950141-1-fujita.tomonori@gmail.com
Signed-off-by: Andreas Hindborg &lt;a.hindborg@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: time: Remove Ktime in hrtimer</title>
<updated>2025-06-24T17:52:47Z</updated>
<author>
<name>FUJITA Tomonori</name>
<email>fujita.tomonori@gmail.com</email>
</author>
<published>2025-06-10T13:28:23Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=69f66cf45814f45a161688fd087abe21e6d5afbd'/>
<id>urn:sha1:69f66cf45814f45a161688fd087abe21e6d5afbd</id>
<content type='text'>
Remove the use of `Ktime` from the hrtimer code, which was originally
introduced as a temporary workaround. The hrtimer has now been fully
converted to use the `Instant` and `Delta` types instead.

Reviewed-by: Andreas Hindborg &lt;a.hindborg@kernel.org&gt;
Signed-off-by: FUJITA Tomonori &lt;fujita.tomonori@gmail.com&gt;
Link: https://lore.kernel.org/r/20250610132823.3457263-6-fujita.tomonori@gmail.com
Signed-off-by: Andreas Hindborg &lt;a.hindborg@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: time: Make HasHrTimer generic over HrTimerMode</title>
<updated>2025-06-24T17:52:47Z</updated>
<author>
<name>FUJITA Tomonori</name>
<email>fujita.tomonori@gmail.com</email>
</author>
<published>2025-06-10T13:28:22Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=e0c0ab04f6785abaa71b9b8dc252cb1a2072c225'/>
<id>urn:sha1:e0c0ab04f6785abaa71b9b8dc252cb1a2072c225</id>
<content type='text'>
Add a `TimerMode` associated type to the `HasHrTimer` trait to
represent the operational mode of the timer, such as absolute or
relative expiration. This new type must implement the `HrTimerMode`
trait, which defines how expiration values are interpreted.

Update the `start()` method to accept an `expires` parameter of type
`&lt;Self::TimerMode as HrTimerMode&gt;::Expires` instead of the fixed `Ktime`.
This enables different timer modes to provide strongly typed expiration
values, such as `Instant&lt;C&gt;` or `Delta`.

The `impl_has_hr_timer` macro is also extended to allow specifying the
`HrTimerMode`. In the following example, it guarantees that the
`start()` method for `Foo` only accepts `Instant&lt;Monotonic&gt;`. Using a
`Delta` or an `Instant` with a different clock source will result in a
compile-time error:

struct Foo {
    #[pin]
    timer: HrTimer&lt;Self&gt;,
}

impl_has_hr_timer! {
    impl HasHrTimer&lt;Self&gt; for Foo {
        mode : AbsoluteMode&lt;Monotonic&gt;,
        field : self.timer
    }
}

This design eliminates runtime mismatches between expires types and
clock sources, and enables stronger type-level guarantees throughout
hrtimer.

Signed-off-by: FUJITA Tomonori &lt;fujita.tomonori@gmail.com&gt;
Reviewed-by: Andreas Hindborg &lt;a.hindborg@kernel.org&gt;
Link: https://lore.kernel.org/r/20250610132823.3457263-5-fujita.tomonori@gmail.com
[ changed conversion method names to `as_*` - Andreas ]
Signed-off-by: Andreas Hindborg &lt;a.hindborg@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: time: Add HrTimerExpires trait</title>
<updated>2025-06-24T17:52:47Z</updated>
<author>
<name>FUJITA Tomonori</name>
<email>fujita.tomonori@gmail.com</email>
</author>
<published>2025-06-10T13:28:21Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=d9fc00dc73542eef98db74085447c57174ca290d'/>
<id>urn:sha1:d9fc00dc73542eef98db74085447c57174ca290d</id>
<content type='text'>
Introduce the `HrTimerExpires` trait to represent types that can be
used as expiration values for high-resolution timers. Define a
required method, `into_nanos()`, which returns the expiration time as a
raw nanosecond value suitable for use with C's hrtimer APIs.

Also extend the `HrTimerMode` to use the `HrTimerExpires` trait.

This refactoring is a preparation for enabling hrtimer code to work
uniformly with both absolute and relative expiration modes.

Reviewed-by: Andreas Hindborg &lt;a.hindborg@kernel.org&gt;
Signed-off-by: FUJITA Tomonori &lt;fujita.tomonori@gmail.com&gt;
Link: https://lore.kernel.org/r/20250610132823.3457263-4-fujita.tomonori@gmail.com
[ changed conversion method names to `as_*` - Andreas ]
Signed-off-by: Andreas Hindborg &lt;a.hindborg@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: time: Replace HrTimerMode enum with trait-based mode types</title>
<updated>2025-06-24T13:12:19Z</updated>
<author>
<name>FUJITA Tomonori</name>
<email>fujita.tomonori@gmail.com</email>
</author>
<published>2025-06-10T13:28:20Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=ced9ccd21fbc8ca941e6a0c2820c2df89239ccb9'/>
<id>urn:sha1:ced9ccd21fbc8ca941e6a0c2820c2df89239ccb9</id>
<content type='text'>
Replace the `HrTimerMode` enum with a trait-based approach that uses
zero-sized types to represent each mode of operation. Each mode now
implements the `HrTimerMode` trait.

This refactoring is a preparation for replacing raw `Ktime` in HrTimer
with the `Instant` and `Delta` types, and for making `HrTimer` generic
over a `ClockSource`.

Reviewed-by: Andreas Hindborg &lt;a.hindborg@kernel.org&gt;
Signed-off-by: FUJITA Tomonori &lt;fujita.tomonori@gmail.com&gt;
Link: https://lore.kernel.org/r/20250610132823.3457263-3-fujita.tomonori@gmail.com
Signed-off-by: Andreas Hindborg &lt;a.hindborg@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: enable `clippy::ptr_as_ptr` lint</title>
<updated>2025-06-22T21:08:42Z</updated>
<author>
<name>Tamir Duberstein</name>
<email>tamird@gmail.com</email>
</author>
<published>2025-06-15T20:55:05Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=fcad9bbf9e1a7de6c53908954ba1b1a1ab11ef1e'/>
<id>urn:sha1:fcad9bbf9e1a7de6c53908954ba1b1a1ab11ef1e</id>
<content type='text'>
In Rust 1.51.0, Clippy introduced the `ptr_as_ptr` lint [1]:

&gt; Though `as` casts between raw pointers are not terrible,
&gt; `pointer::cast` is safer because it cannot accidentally change the
&gt; pointer's mutability, nor cast the pointer to other types like `usize`.

There are a few classes of changes required:
- Modules generated by bindgen are marked
  `#[allow(clippy::ptr_as_ptr)]`.
- Inferred casts (` as _`) are replaced with `.cast()`.
- Ascribed casts (` as *... T`) are replaced with `.cast::&lt;T&gt;()`.
- Multistep casts from references (` as *const _ as *const T`) are
  replaced with `core::ptr::from_ref(&amp;x).cast()` with or without `::&lt;T&gt;`
  according to the previous rules. The `core::ptr::from_ref` call is
  required because `(x as *const _).cast::&lt;T&gt;()` results in inference
  failure.
- Native literal C strings are replaced with `c_str!().as_char_ptr()`.
- `*mut *mut T as _` is replaced with `let *mut *const T = (*mut *mut
  T)`.cast();` since pointer to pointer can be confusing.

Apply these changes and enable the lint -- no functional change
intended.

Link: https://rust-lang.github.io/rust-clippy/master/index.html#ptr_as_ptr [1]
Reviewed-by: Benno Lossin &lt;benno.lossin@proton.me&gt;
Reviewed-by: Boqun Feng &lt;boqun.feng@gmail.com&gt;
Signed-off-by: Tamir Duberstein &lt;tamird@gmail.com&gt;
Acked-by: Viresh Kumar &lt;viresh.kumar@linaro.org&gt;
Acked-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
Acked-by: Tejun Heo &lt;tj@kernel.org&gt;
Acked-by: Danilo Krummrich &lt;dakr@kernel.org&gt;
Link: https://lore.kernel.org/r/20250615-ptr-as-ptr-v12-1-f43b024581e8@gmail.com
[ Added `.cast()` for `opp`. - Miguel ]
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
</feed>
