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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240610061705.rismfufmsmq44qt6@vireshk-i7>
Date: Mon, 10 Jun 2024 11:47:05 +0530
From: Viresh Kumar <viresh.kumar@...aro.org>
To: Manos Pitsidianakis <manos.pitsidianakis@...aro.org>
Cc: "Rafael J. Wysocki" <rafael@...nel.org>,
	Miguel Ojeda <miguel.ojeda.sandonis@...il.com>,
	Miguel Ojeda <ojeda@...nel.org>,
	Alex Gaynor <alex.gaynor@...il.com>,
	Wedson Almeida Filho <wedsonaf@...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>,
	Andreas Hindborg <a.hindborg@...sung.com>,
	Alice Ryhl <aliceryhl@...gle.com>, linux-pm@...r.kernel.org,
	Vincent Guittot <vincent.guittot@...aro.org>,
	Stephen Boyd <sboyd@...nel.org>, Nishanth Menon <nm@...com>,
	rust-for-linux@...r.kernel.org,
	Erik Schilling <erik.schilling@...aro.org>,
	Alex Benné e <alex.bennee@...aro.org>,
	Joakim Bech <joakim.bech@...aro.org>, Rob Herring <robh@...nel.org>,
	linux-kernel@...r.kernel.org
Subject: Re: [RFC PATCH V2 2/8] rust: Extend OPP bindings for the OPP table

On 07-06-24, 13:38, Manos Pitsidianakis wrote:
> On Fri, 07 Jun 2024 12:12, Viresh Kumar <viresh.kumar@...aro.org> wrote:
> > +/// OPP search types.
> > +#[derive(Copy, Clone, Debug, Eq, PartialEq)]
> > +pub enum SearchType {
> > +    /// Search for exact value.
> > +    Exact,
> > +    /// Search for highest value less than equal to value.
> > +    Floor,
> > +    /// Search for lowest value greater than equal to value.
> > +    Ceil,
> > +}
> 
> Seeing this enum made me think about memory layouts which are not stable in
> Rust and can change between compilations unless they have a specific `repr`.

Just to clarify, this enum is a Rust only entity. It doesn't have a C
counterpart..

> Not related to this series directly, has there been discussion about
> guaranteeing struct layouts in kernel APIs? It'd require a lot of things to
> happen to cause a problem (multiple users of an API in the kernel in
> separate compilation units maybe even compiled with different rustc
> versions).

I haven't followed the Rust discussions closely, hopefully someone
else can answer on this. But isn't repr(C) good enough to take care of
layout issues ? I must not be understanding it since you asked this :)

> > +    /// Find OPP table from device.
> > +    pub fn from_dev(dev: ARef<Device>) -> Result<Self> {
> > +        // SAFETY: The requirements are satisfied by the existence of `Device` and its safety
> > +        // requirements. Refcount of the OPP table is incremented as well.
> > +        let ptr = from_err_ptr(unsafe { bindings::dev_pm_opp_get_opp_table(dev.as_raw()) })?;
> > +
> > +        Ok(Self {
> > +            ptr,
> > +            dev: dev.clone(),
> 
> Clone is not probably not needed here, right? the argument value will be
> dropped after this.

Hmm, I was expecting the build system to raise an error for such
things. Tried both rustfmtcheck and CLIPPY=1 and this isn't reported.
Anyway, fixed it now (along with few other that CLIPPY=1 reported).

> > +    /// Finds OPP based on level.
> > +    pub fn opp_from_level(&self, mut level: u32, stype: SearchType) -> Result<ARef<OPP>> {
> > +        let rdev = self.dev.as_raw();
> > +
> > +        let ptr = from_err_ptr(match stype {
> > +            // SAFETY: The requirements are satisfied by the existence of `Device` and its
> > +            // safety requirements. The returned ptr will be owned by the new [`OPP`] instance.
> > +            SearchType::Exact => unsafe { bindings::dev_pm_opp_find_level_exact(rdev, level) },
> > +
> 
> Minor style comment, the empty lines between match patterns are unusual

Yeah, since there were a lot of comments and code, I added them to
make it more readable. rustfmt doesn't raise any issues with it, so I
guess I can keep them :)

Thanks Manos.

-- 
viresh

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ