From: "Danilo Krummrich" <dakr@kernel.org>
To: "Jason Gunthorpe" <jgg@nvidia.com>
Cc: "Zhi Wang" <zhiw@nvidia.com>, <rust-for-linux@vger.kernel.org>,
<linux-pci@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<aliceryhl@google.com>, <bhelgaas@google.com>,
<kwilczynski@kernel.org>, <ojeda@kernel.org>,
<alex.gaynor@gmail.com>, <boqun.feng@gmail.com>,
<gary@garyguo.net>, <bjorn3_gh@protonmail.com>,
<lossin@kernel.org>, <a.hindborg@kernel.org>, <tmgross@umich.edu>,
<markus.probst@posteo.de>, <helgaas@kernel.org>,
<cjia@nvidia.com>, <smitra@nvidia.com>, <ankita@nvidia.com>,
<aniketa@nvidia.com>, <kwankhede@nvidia.com>,
<targupta@nvidia.com>, <acourbot@nvidia.com>,
<joelagnelf@nvidia.com>, <jhubbard@nvidia.com>,
<zhiwang@kernel.org>, <daniel.almeida@collabora.com>
Subject: Re: [PATCH v2 1/2] rust: introduce abstractions for fwctlg
Date: Wed, 28 Jan 2026 16:49:07 +0100 [thread overview]
Message-ID: <DG0CABK2DQE8.1TDN35GOJ0DYI@kernel.org> (raw)
In-Reply-To: <20260128145906.GZ1134360@nvidia.com>
On Wed Jan 28, 2026 at 3:59 PM CET, Jason Gunthorpe wrote:
> On Wed, Jan 28, 2026 at 03:01:25PM +0100, Danilo Krummrich wrote:
>> There is no second memory allocation. In the implementation of
>> fwctl::Device::new() above we call _fwctl_alloc_device() with a size (and
>> layout) such that this allocation is suitable to initialize the second argument
>> (i.e. data: impl PinInit<T, Error>) within this allocation.
>
> You are talking about your suggestions now right?
Correct, I'm talking about my proposal.
> Because what I see in Zi's patch doesn't match any of this?
>
> + bindings::_fwctl_alloc_device(
> + parent.as_raw(),
> + ops,
> + core::mem::size_of::<bindings::fwctl_device>(),
> + )
>
> That is not allocating any memory for driver use ...
Yes, the patch doesn't do any of that.
> What you are explaining sounds good to me, though I don't quite get
> the PinInit<> flow but I trust you on that. :)
So, it would basically look like this:
pub struct Device<T> {
dev: Opaque<bindings::fwctl_device>,
data: T,
}
Where T is the type of the driver specific fwctl device data.
impl<T> Device<T> {
pub fn new(
parent: &device::Device,
data: impl PinInit<T::Data, Error>
) -> Result<ARef<Self>> {
let layout = Kmalloc::aligned_layout(Layout::new::<Self>());
// SAFETY: ...
let raw_fwctl: *mut Self = unsafe {
bindings::_fwctl_alloc_device(
parent.as_raw(),
&Self::VTABLE,
layout.size(),
)
}
.cast();
let raw_fwctl = NonNull::new(from_err_ptr(raw_fwctl)?).ok_or(ENOMEM)?;
// Get the pointer to `Self::data`.
let raw_data = unsafe { &raw mut (*raw_fwctl.as_ptr().data) };
// Initialize the `data` initializer within the memory pointed
// to by `raw_data`.
unsafe { data.__pinned_init(raw_data) }.inspect_err(|_| {
// Find the `struct fwctl_device` pointer from the `Self`
// pointer.
let fwctl_dev = unsafe { Self::into_fwcl_device(raw_fwctl) };
// Since we failed to execute the initializer of `data`,
// unwind, i.e. drop our reference to `fwctl_dev`.
unsafe { bindings::fwctl_put(fwctl_dev) };
})?;
// The initializer was successful, hence return `Self` as
// `ARef<Self>`.
Ok(unsafe { ARef::from_raw(raw_fwctl) })
}
}
So, essentially the driver passes an initializer of its private data and we
"write" this initializer into the extra memory allocated with
_fwctl_alloc_device().
next prev parent reply other threads:[~2026-01-28 15:49 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-22 20:42 [PATCH v2 0/2] rust: introduce abstractions for fwctl Zhi Wang
2026-01-22 20:42 ` [PATCH v2 1/2] " Zhi Wang
2026-01-22 21:17 ` Joel Fernandes
2026-01-23 10:25 ` Zhi Wang
2026-01-26 17:48 ` Gary Guo
2026-01-27 19:59 ` Zhi Wang
2026-01-26 18:19 ` Jason Gunthorpe
2026-01-27 19:57 ` Zhi Wang
2026-01-27 20:07 ` Danilo Krummrich
2026-01-28 0:04 ` Jason Gunthorpe
2026-01-28 1:21 ` Danilo Krummrich
2026-01-28 13:20 ` [PATCH v2 1/2] rust: introduce abstractions for fwctlg Jason Gunthorpe
2026-01-28 14:01 ` Danilo Krummrich
2026-01-28 14:59 ` Jason Gunthorpe
2026-01-28 15:49 ` Danilo Krummrich [this message]
2026-01-28 15:56 ` Jason Gunthorpe
2026-01-28 16:35 ` Danilo Krummrich
2026-01-28 16:39 ` Jason Gunthorpe
2026-01-28 17:26 ` Zhi Wang
2026-01-28 17:30 ` Zhi Wang
2026-01-28 17:39 ` Jason Gunthorpe
2026-01-28 17:40 ` Danilo Krummrich
2026-01-28 11:36 ` [PATCH v2 1/2] rust: introduce abstractions for fwctl Zhi Wang
2026-01-28 11:41 ` Danilo Krummrich
2026-01-27 20:09 ` Danilo Krummrich
2026-01-22 20:42 ` [PATCH v2 2/2] samples: rust: fwctl: add sample code " Zhi Wang
2026-01-22 20:58 ` Jason Gunthorpe
2026-01-22 21:06 ` Danilo Krummrich
2026-01-22 21:16 ` John Hubbard
2026-01-23 10:23 ` Zhi Wang
2026-01-26 17:59 ` Gary Guo
2026-01-22 21:32 ` [PATCH v2 0/2] rust: introduce abstractions " Danilo Krummrich
2026-01-23 10:14 ` Zhi Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DG0CABK2DQE8.1TDN35GOJ0DYI@kernel.org \
--to=dakr@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=aniketa@nvidia.com \
--cc=ankita@nvidia.com \
--cc=bhelgaas@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=cjia@nvidia.com \
--cc=daniel.almeida@collabora.com \
--cc=gary@garyguo.net \
--cc=helgaas@kernel.org \
--cc=jgg@nvidia.com \
--cc=jhubbard@nvidia.com \
--cc=joelagnelf@nvidia.com \
--cc=kwankhede@nvidia.com \
--cc=kwilczynski@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=markus.probst@posteo.de \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=smitra@nvidia.com \
--cc=targupta@nvidia.com \
--cc=tmgross@umich.edu \
--cc=zhiw@nvidia.com \
--cc=zhiwang@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox