[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251102225521.GN1235738@nvidia.com>
Date: Sun, 2 Nov 2025 18:55:21 -0400
From: Jason Gunthorpe <jgg@...dia.com>
To: Danilo Krummrich <dakr@...nel.org>
Cc: Zhi Wang <zhiw@...dia.com>, rust-for-linux@...r.kernel.org,
	bhelgaas@...gle.com, kwilczynski@...nel.org, ojeda@...nel.org,
	alex.gaynor@...il.com, boqun.feng@...il.com, gary@...yguo.net,
	bjorn3_gh@...tonmail.com, lossin@...nel.org, a.hindborg@...nel.org,
	aliceryhl@...gle.com, tmgross@...ch.edu,
	linux-kernel@...r.kernel.org, cjia@...dia.com, smitra@...dia.com,
	ankita@...dia.com, aniketa@...dia.com, kwankhede@...dia.com,
	targupta@...dia.com, zhiwang@...nel.org, alwilliamson@...dia.com,
	acourbot@...dia.com, joelagnelf@...dia.com, jhubbard@...dia.com
Subject: Re: [RFC 1/2] rust: introduce abstractions for fwctl
On Sun, Nov 02, 2025 at 07:33:10PM +0100, Danilo Krummrich wrote:
> On Thu Oct 30, 2025 at 5:03 PM CET, Zhi Wang wrote:
> > +/// Static vtable mapping Rust trait methods to C callbacks.
> > +pub struct FwCtlVTable<T: FwCtlOps>(PhantomData<T>);
> > +
> > +impl<T: FwCtlOps> FwCtlVTable<T> {
> > +    /// Static instance of `fwctl_ops` used by the C core to call into Rust.
> > +    pub const VTABLE: bindings::fwctl_ops = bindings::fwctl_ops {
> > +        device_type: T::DEVICE_TYPE,
> > +        uctx_size: core::mem::size_of::<FwCtlUCtx<T::UCtx>>(),
> 
> The fwctl code uses this size to allocate memory for both, struct fwctl_uctx and
> the driver's private data at the end of the allocation.
> 
> This means that it is not enough to just consider the size of T::UCtx, you also
> have to consider its required alignment, and, if required, allocate more memory.
Yes, the container_of() relationship must be such that the core struct
is first in the memory and any driver data is trailing. The C version
has a static_assertion to constrain this.
> All other callbacks should be correct as they are once the alignment is
> considered.
Yes, only alloc and put/free make this assumption.
Jason
Powered by blists - more mailing lists