public inbox for rust-for-linux@vger.kernel.org
 help / color / mirror / Atom feed
From: Zhi Wang <zhiw@nvidia.com>
To: Joel Fernandes <joelagnelf@nvidia.com>
Cc: <rust-for-linux@vger.kernel.org>, <linux-pci@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>, <dakr@kernel.org>,
	<aliceryhl@google.com>, <jgg@nvidia.com>
Subject: Re: [PATCH v2 1/2] rust: introduce abstractions for fwctl
Date: Fri, 23 Jan 2026 12:25:02 +0200	[thread overview]
Message-ID: <20260123122502.006a01c3.zhiw@nvidia.com> (raw)
In-Reply-To: <29a1e16a-e50b-4d69-a6fd-41d11ca9e393@nvidia.com>

On Thu, 22 Jan 2026 16:17:55 -0500
Joel Fernandes <joelagnelf@nvidia.com> wrote:

> On Thu, Jan 22, 2026 at 10:42:30PM +0200, Zhi Wang wrote:
> > +    /// Called when a userspace RPC request is received.
> > +    fn fw_rpc(
> > +        uctx: &mut UserCtx<Self::UserCtx>,
> > +        scope: u32,
> > +        rpc_in: &mut [u8],
> > +        out_len: *mut usize,
> > +    ) -> Result<Option<KVec<u8>>, Error>;
> 
> Exposing a raw pointer in the trait API means drivers that want to
> "reuse input buffer" need to write unsafe code right?
> 
>     unsafe { *out_len = ... };
> 
> I believe the unsafe code should be confined to the abstraction layer
> instead, not in the driver.
> 
> How about using using an enum return type instead to properly wrap
> inplace versus driver allocated outputs?
> 
>     pub enum RpcOutput {
>         Allocated(KVec<u8>),
>         InPlace(usize),
>     }
> 
>     fn fw_rpc(
>         uctx: &mut UserCtx<Self::UserCtx>,
>         scope: u32,
>         rpc_in: &mut [u8],
>     ) -> Result<RpcOutput, Error>;
> 
> Then the abstraction handles the pointer write:
> 
>     match T::fw_rpc(ctx, scope, rpc_in_slice) {
>         Ok(RpcOutput::Allocated(kvec)) => {
>             ...
>         }
>         Ok(RpcOutput::InPlace(len)) => {
>             unsafe { *out_len = len };
> 	    ...
>         }
>     }
> 
> fw_rpc() as a bonus also gets 1 less function parameter and cleaner
> return signature.
> 

This is a good idea. Noted. :)

> --
> Joel Fernandes
> 


  reply	other threads:[~2026-01-23 10:25 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 [this message]
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
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=20260123122502.006a01c3.zhiw@nvidia.com \
    --to=zhiw@nvidia.com \
    --cc=aliceryhl@google.com \
    --cc=dakr@kernel.org \
    --cc=jgg@nvidia.com \
    --cc=joelagnelf@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=rust-for-linux@vger.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