lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <878qpsvn1m.fsf@kernel.org>
Date: Wed, 26 Feb 2025 14:43:49 +0100
From: Andreas Hindborg <a.hindborg@...nel.org>
To: "Lyude Paul" <lyude@...hat.com>
Cc: "Miguel Ojeda" <ojeda@...nel.org>,  "Anna-Maria Behnsen"
 <anna-maria@...utronix.de>,  "Frederic Weisbecker" <frederic@...nel.org>,
  "Thomas Gleixner" <tglx@...utronix.de>,  "Danilo Krummrich"
 <dakr@...nel.org>,  "Alex Gaynor" <alex.gaynor@...il.com>,  "Boqun Feng"
 <boqun.feng@...il.com>,  "Gary Guo" <gary@...yguo.net>,  Björn Roy Baron
 <bjorn3_gh@...tonmail.com>,  "Benno Lossin" <benno.lossin@...ton.me>,
  "Alice Ryhl" <aliceryhl@...gle.com>,  "Trevor Gross" <tmgross@...ch.edu>,
  "Guangbo Cui" <2407018371@...com>,  "Dirk Behme" <dirk.behme@...il.com>,
  "Daniel Almeida" <daniel.almeida@...labora.com>,  "Tamir Duberstein"
 <tamird@...il.com>,  <rust-for-linux@...r.kernel.org>,
  <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v9 04/13] rust: hrtimer: allow timer restart from timer
 handler

"Lyude Paul" <lyude@...hat.com> writes:

> On Tue, 2025-02-25 at 09:58 +0100, Andreas Hindborg wrote:
>> "Lyude Paul" <lyude@...hat.com> writes:
>>
>> > On Mon, 2025-02-24 at 13:03 +0100, Andreas Hindborg wrote:
>> >
>> > Also, I feel like I might have asked this a few versions ago so hopefully i'm
>> > not asking again: but what's the reason for us not just using the
>> > discriminants of `HrTimerRestart` here:
>> >
>> > /// Restart policy for timers.
>> > #[repr(u32)]
>> > pub enum HrTimerRestart {
>> >     /// Timer should not be restarted.
>> >     NoRestart = bindings::hrtimer_restart_HRTIMER_NORESTART,
>> >     /// Timer should be restarted.
>> >     Restart = bindings::hrtimer_restart_HRTIMER_RESTART,
>> > }
>>
>> I forget if we discussed this, but it does not make much of a
>> difference, does it?
>>
>> With a Rust enum, we get a smaller storage type maybe with better
>> support for niche optimizations? And then pay a bit more for conversion.
>> All in all, I don't think it makes much difference.
>
> No idea about performance wise, but I -think- it would actually cut down on
> the code that you need - particularly for the larger enums here. Mainly
> because you only would need to manually specify each variant for converting
> from bindings::hrtimer_restart to HrTimerRestart, but not the other way
> around:
>
>    /// Restart policy for timers.
>    #[repr(u32)]
>    pub enum HrTimerRestart {
>        /// Timer should not be restarted.
>        NoRestart = bindings::hrtimer_restart_HRTIMER_NORESTART,
>        /// Timer should be restarted.
>        Restart = bindings::hrtimer_restart_HRTIMER_RESTART,
>    }
>
>    impl From<bindings::hrtimer_restart> for HrTimerRestart {
>        fn from(value: u32) -> Self {
>            match value {
>                bindings::hrtimer_restart_HRTIMER_NORESTART => Self::NoRestart,
>                _ => Self::Restart,
>            }
>        }
>    }
>
>    impl From<HrTimerRestart> for bindings::hrtimer_restart {
>        fn from(value: HrTimerRestart) -> Self {
>            value as Self
>        }
>    }

I was implementing this, and it is fine for `HrTimerRestart`, but for
`HrTimerMode` it does not work out. We have multiple flags with the same
value:

  error[E0081]: discriminant value `2` assigned more than once
    --> /home/aeh/src/linux-rust/hrtimer/rust/kernel/time/hrtimer.rs:689:1
      |
  689 | pub enum HrTimerMode {
      | ^^^^^^^^^^^^^^^^^^^^
  ...
  695 |     Pinned = bindings::hrtimer_mode_HRTIMER_MODE_PINNED,
      |              ------------------------------------------ `2` assigned here
  ...
  702 |     AbsolutePinned = bindings::hrtimer_mode_HRTIMER_MODE_ABS_PINNED,
      |                      ---------------------------------------------- `2` assigned here


Which is unfortunate. I'll keep the old style for this one and convert
the others where applicable.


Best regards,
Andreas Hindborg



Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ