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: <20251007080402.1a6d19ea@nimda.home>
Date: Tue, 7 Oct 2025 08:04:02 +0300
From: Onur Özkan <work@...rozkan.dev>
To: Boqun Feng <boqun.feng@...il.com>
Cc: rust-for-linux@...r.kernel.org, ojeda@...nel.org, alex.gaynor@...il.com,
 gary@...yguo.net, bjorn3_gh@...tonmail.com, lossin@...nel.org,
 aliceryhl@...gle.com, tmgross@...ch.edu, dakr@...nel.org,
 linux-kernel@...r.kernel.org, acourbot@...dia.com, airlied@...il.com,
 simona@...ll.ch, maarten.lankhorst@...ux.intel.com, mripard@...nel.org,
 tzimmermann@...e.de, corbet@....net, lyude@...hat.com,
 linux-doc@...r.kernel.org
Subject: Re: [PATCH 1/3] rust: xarray: abstract `xa_alloc`

On Mon, 6 Oct 2025 16:09:42 -0700
Boqun Feng <boqun.feng@...il.com> wrote:

> HI Onur,
> 
> On Mon, Oct 06, 2025 at 07:30:22PM +0300, Onur Özkan wrote:
> > Implements `alloc` function to `XArray<T>` that wraps
> > `xa_alloc` safely.
> > 
> > Resolves a task from the nova/core task list under the "XArray
> > bindings [XARR]" section in "Documentation/gpu/nova/core/todo.rst"
> > file.
> > 
> 
> Having this information is good, however I feel it's better if you
> explain/expand what exact the usage will be on the XArray, otherwise,
> it'll be hard for people to dig in the history and find out why we add
> this. Thanks!
> 

Very true, thanks.

-Onur

> Regards,
> Boqun
> 
> > Signed-off-by: Onur Özkan <work@...rozkan.dev>
> > ---
> >  rust/kernel/xarray.rs | 39 +++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 39 insertions(+)
> > 
> > diff --git a/rust/kernel/xarray.rs b/rust/kernel/xarray.rs
> > index a49d6db28845..1b882cd2f58b 100644
> > --- a/rust/kernel/xarray.rs
> > +++ b/rust/kernel/xarray.rs
> > @@ -266,6 +266,45 @@ pub fn store(
> >              Ok(unsafe { T::try_from_foreign(old) })
> >          }
> >      }
> > +
> > +    /// Allocates an empty slot within the given limit range and
> > stores `value` there.
> > +    ///
> > +    /// May drop the lock if needed to allocate memory, and then
> > reacquire it afterwards.
> > +    ///
> > +    /// On success, returns the allocated id.
> > +    ///
> > +    /// On failure, returns the element which was attempted to be
> > stored.
> > +    pub fn alloc(
> > +        &mut self,
> > +        limit: bindings::xa_limit,
> > +        value: T,
> > +        gfp: alloc::Flags,
> > +    ) -> Result<u32, StoreError<T>> {
> > +        build_assert!(
> > +            T::FOREIGN_ALIGN >= 4,
> > +            "pointers stored in XArray must be 4-byte aligned"
> > +        );
> > +
> > +        let new = value.into_foreign();
> > +        let mut id: u32 = 0;
> > +
> > +        // SAFETY:
> > +        // - `self.xa.xa` is valid by the type invariant.
> > +        // - `new` came from `T::into_foreign`.
> > +        let ret =
> > +            unsafe { bindings::__xa_alloc(self.xa.xa.get(), &mut
> > id, new, limit, gfp.as_raw()) }; +
> > +        if ret < 0 {
> > +            // SAFETY: `__xa_alloc` doesn't take ownership on
> > error.
> > +            let value = unsafe { T::from_foreign(new) };
> > +            return Err(StoreError {
> > +                value,
> > +                error: Error::from_errno(ret),
> > +            });
> > +        }
> > +
> > +        Ok(id)
> > +    }
> >  }
> > 
> >  // SAFETY: `XArray<T>` has no shared mutable state so it is `Send`
> > iff `T` is `Send`. --
> > 2.51.0
> > 


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ