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: <CAH5fLgixWd862P_mma0BObtT=gm9fTzQOZot62aet1qx4mai+g@mail.gmail.com>
Date: Fri, 7 Feb 2025 10:32:16 +0100
From: Alice Ryhl <aliceryhl@...gle.com>
To: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc: Lyude Paul <lyude@...hat.com>, rust-for-linux@...r.kernel.org, 
	Maíra Canal <mairacanal@...eup.net>, 
	Miguel Ojeda <ojeda@...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>, Andreas Hindborg <a.hindborg@...nel.org>, 
	Trevor Gross <tmgross@...ch.edu>, Danilo Krummrich <dakr@...nel.org>, 
	"Rafael J. Wysocki" <rafael@...nel.org>, Wedson Almeida Filho <wedsonaf@...il.com>, 
	Mika Westerberg <mika.westerberg@...ux.intel.com>, 
	Xiangfei Ding <dingxiangfei2009@...il.com>, open list <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v2] rust/kernel: Add faux device bindings

On Fri, Feb 7, 2025 at 10:25 AM Greg Kroah-Hartman
<gregkh@...uxfoundation.org> wrote:
>
> On Thu, Feb 06, 2025 at 07:40:45PM -0500, Lyude Paul wrote:
> > This introduces a crate for working with faux devices in rust, along with
> > adding sample code to show how the API is used. Unlike other types of
> > devices, we don't provide any hooks for device probe/removal - since these
> > are optional for the faux API and are unnecessary in rust.
> >
> > Signed-off-by: Lyude Paul <lyude@...hat.com>
> > Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
> > Cc: Maíra Canal <mairacanal@...eup.net>

> > +impl AsRef<device::Device> for Registration {
> > +    fn as_ref(&self) -> &device::Device {
> > +        // SAFETY: The underlying `device` in `faux_device` is guaranteed by the C API to be
> > +        // a valid initialized `device`.
> > +        unsafe { device::Device::as_ref(addr_of_mut!((*self.as_raw()).dev)) }
>
> Just curious, this is returning an incremented "struct device" to the
> caller, right?  And then when it goes out of scope it will have the
> reference decremented?  And do you need a wrapper in C to get to ".dev"
> of the faux_device structure or are you ok doing it like this?

This uses the &_ pointer type which does not involve any refcount
increments or decrements. What you describe only happens if the
ARef<_> pointer type is used instead.

Safety is ensured by the borrow checker that fails compilation if the
returned reference is used after the Registration object is destroyed
- i.e. it's assumed that the value is safe to access without refcount
increments as long as the Registration is still alive.

Alice

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ