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]
Date: Thu, 28 Mar 2024 10:00:16 -0300
From: Wedson Almeida Filho <wedsonaf@...il.com>
To: Benno Lossin <benno.lossin@...ton.me>
Cc: rust-for-linux@...r.kernel.org, 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>, 
	Andreas Hindborg <a.hindborg@...sung.com>, Alice Ryhl <aliceryhl@...gle.com>, 
	linux-kernel@...r.kernel.org, Wedson Almeida Filho <walmeida@...rosoft.com>
Subject: Re: [PATCH 2/2] samples: rust: add in-place initialisation sample

On Wed, 27 Mar 2024 at 10:53, Benno Lossin <benno.lossin@...ton.me> wrote:
>
> On 27.03.24 04:23, Wedson Almeida Filho wrote:
> > diff --git a/samples/rust/rust_inplace.rs b/samples/rust/rust_inplace.rs
> > new file mode 100644
> > index 000000000000..ba8d051cac56
> > --- /dev/null
> > +++ b/samples/rust/rust_inplace.rs
> > @@ -0,0 +1,42 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +
> > +//! Rust minimal in-place sample.
> > +
> > +use kernel::prelude::*;
> > +
> > +module! {
> > +    type: RustInPlace,
> > +    name: "rust_inplace",
> > +    author: "Rust for Linux Contributors",
> > +    description: "Rust minimal in-place sample",
> > +    license: "GPL",
> > +}
> > +
> > +#[pin_data(PinnedDrop)]
> > +struct RustInPlace {
> > +    numbers: Vec<i32>,
> > +}
> > +
> > +impl kernel::InPlaceModule for RustInPlace {
> > +    fn init(_module: &'static ThisModule) -> impl PinInit<Self, Error> {
> > +        pr_info!("Rust minimal sample (init)\n");
>
> This text needs updating.

Fixed in v2.

>
> > +        pr_info!("Am I built-in? {}\n", !cfg!(MODULE));
> > +        try_pin_init!(Self {
> > +            numbers: {
> > +                let mut numbers = Vec::new();
> > +                numbers.push(72, GFP_KERNEL)?;
> > +                numbers.push(108, GFP_KERNEL)?;
> > +                numbers.push(200, GFP_KERNEL)?;
> > +                numbers
> > +            },
> > +        })
>
> I think it might be useful to also have a field that needs pin-init, eg
> a `Mutex` or similar. What about placing the `Vec` inside of a mutex?

I'm not sure this belongs in a "minimal" example.

But I added it in v2 because we're already violating minimality with
vectors anyway. Perhaps we should later have minimal samples and
rename these to something else.

> --
> Cheers,
> Benno
>
> > +    }
> > +}
> > +
> > +#[pinned_drop]
> > +impl PinnedDrop for RustInPlace {
> > +    fn drop(self: Pin<&mut Self>) {
> > +        pr_info!("My numbers are {:?}\n", self.numbers);
> > +        pr_info!("Rust minimal inplace sample (exit)\n");
> > +    }
> > +}
> > --
> > 2.34.1
> >
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ