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: <DB0ZN9DYID46.3IZ7G8I9WNNED@kernel.org>
Date: Tue, 01 Jul 2025 22:07:34 +0200
From: "Benno Lossin" <lossin@...nel.org>
To: "Danilo Krummrich" <dakr@...nel.org>, "Greg Kroah-Hartman"
 <gregkh@...uxfoundation.org>
Cc: "Matthew Maurer" <mmaurer@...gle.com>, "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@...nel.org>, "Alice Ryhl" <aliceryhl@...gle.com>,
 "Trevor Gross" <tmgross@...ch.edu>, "Rafael J. Wysocki"
 <rafael@...nel.org>, "Sami Tolvanen" <samitolvanen@...gle.com>, "Timur
 Tabi" <ttabi@...dia.com>, <linux-kernel@...r.kernel.org>,
 <rust-for-linux@...r.kernel.org>, "Dirk Behme" <dirk.behme@...bosch.com>
Subject: Re: [PATCH v8 4/6] rust: debugfs: Support arbitrary owned backing
 for File

On Tue Jul 1, 2025 at 5:10 PM CEST, Danilo Krummrich wrote:
> I think we can add an additional API like this:
>
> 	impl Dir {
> 	   pub fn create_file<T>(&self, data: impl PinInit<T>) -> impl PinInit<Self> {
> 	      pin_init!(Self {
> 	         data <- data,
> 	         ...
> 	      })
> 	   }
> 	}
>
> This allows us to do things like:
>
> 	#[pin_data]
> 	struct Firmware {
> 	   #[pin]
> 	   minor: debugfs::File<u32>,
> 	   #[pin]
> 	   major: debugfs::File<u32>,
> 	   #[pin]
> 	   buffer: debugfs::File<[u8]>,
> 	}
>
> 	impl Firmware {
> 	   pub fn new(&dir: debugfs::Dir, buffer: [u8]) -> impl PinInit<Self> {
> 	      pin_init!(Self {
> 	         minor <- dir.create_file("minor", 1),
> 	         major <- dir.create_file("major", 2),
> 	         buffer <- dir.create_file("buffer", buffer),
> 	      })
> 	   }
> 	}
>
> 	// This is the only allocation we need.
> 	let fw = KBox::pin_init(Firmware::new(...), GFP_KERNEL)?;
>
> With this everything is now in a single allocation and since we're using
> pin-init, Dir::create_file() can safely store pointers of the corresponding data
> in debugfs_create_file(), since this structure is guaranteed to be pinned in
> memory.

Yes! This is a textbook example of how to use pin-init in API design!

> Actually, we can also implement *only this*, since with this my previous example
> would just become this:
>
> 	struct GPU {
> 	   fw: debugfs::File<Firmware>,
> 	}
>
> 	let file = dir.create_file("firmware", Firmware::new());
> 	let file = KBox::pin_init(file, GFP_KERNEL)?;
>
> 	// debugfs::File<Firmware> dereferences to Firmware
> 	file.do_something();
>
> Given that, I think we should change things to use pin-init right away for the
> debugfs::File API.

Yeah I think it's a good idea to do that too.

---
Cheers,
Benno

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ