From: "Alexandre Courbot" <acourbot@nvidia.com>
To: "Alistair Popple" <apopple@nvidia.com>, "Lyude Paul" <lyude@redhat.com>
Cc: rust-for-linux@vger.kernel.org, dri-devel@lists.freedesktop.org,
dakr@kernel.org, acourbot@nvidia.com,
"Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
"Maxime Ripard" <mripard@kernel.org>,
"Thomas Zimmermann" <tzimmermann@suse.de>,
"John Hubbard" <jhubbard@nvidia.com>,
"Joel Fernandes" <joelagnelf@nvidia.com>,
"Timur Tabi" <ttabi@nvidia.com>,
linux-kernel@vger.kernel.org, nouveau@lists.freedesktop.org
Subject: Re: [PATCH v2 05/10] gpu: nova-core: gsp: Add GSP command queue handling
Date: Fri, 26 Sep 2025 11:20:25 +0900 [thread overview]
Message-ID: <DD2DFKZTFIGS.2HDVZRV6WGXHG@nvidia.com> (raw)
In-Reply-To: <fiwv6movnoliptvjdlxzx4rggv5a7mid4zyvmqowvw6kt5auhh@r4dmizzmykwv>
On Thu Sep 25, 2025 at 3:32 PM JST, Alistair Popple wrote:
<snip>
>> > + #[expect(unused)]
>> > + pub(crate) fn receive_msg_from_gsp<M: GspMessageFromGsp, R>(
>> > + &mut self,
>> > + timeout: Delta,
>> > + init: impl FnOnce(&M, SBuffer<core::array::IntoIter<&[u8], 2>>) -> Result<R>,
>> > + ) -> Result<R> {
>> > + let (driver_area, msg_header, slice_1) = wait_on(timeout, || {
>> > + let driver_area = self.gsp_mem.driver_read_area();
>> > + // TODO: find an alternative to as_flattened()
>> > + #[allow(clippy::incompatible_msrv)]
>> > + let (msg_header_slice, slice_1) = driver_area
>> > + .0
>> > + .as_flattened()
>> > + .split_at(size_of::<GspMsgElement>());
>> > +
>> > + // Can't fail because msg_slice will always be
>> > + // size_of::<GspMsgElement>() bytes long by the above split.
>> > + let msg_header = GspMsgElement::from_bytes(msg_header_slice).unwrap();
>>
>> Any reason we're not just using unwrap_unchecked() here then?
>
> Because whilst my assertions about the code are currently correct if it ever
> changes I figured it would be better to explicitly panic than end up with
> undefined behaviour. Is there some other advantage to using unwrap_unchecked()?
> I can't imagine there'd be much of a performance difference.
Here I think we should just use the `?` operator. The function already
returns a `Result` so it would fit.
I'd be willing to consider unwrapping is this can prevent an
obviously-unfallible method from having to return a `Result` - but here
this is not the case, and handling the error doesn't cost us more
than the `unwrap`, so let's do that.
<snip>
>> > +impl GspRpcHeader {
>> > + pub(crate) fn new(cmd_size: u32, function: u32) -> Self {
>> > + Self {
>> > + // TODO: magic number
>> > + header_version: 0x03000000,
>> > + signature: bindings::NV_VGPU_MSG_SIGNATURE_VALID,
>> > + function,
>> > + // TODO: overflow check?
>> > + length: size_of::<Self>() as u32 + cmd_size,
>>
>> (just curious, do you mean overflow as in arith overflow or overflow as in
>> going past the boundaries of the header?)
>
> Actually this snuck in from some of Alex's suggested code improvements (I had
> intended to credit him in the commit message! Will fix that) so maybe he can
> answer what he had in mind? I assumed arith overflow but maybe he meant ring
> buffer overflow or something.
I was thinking about arithmetic overflow, but maybe that was just
overthinking. :) We're probably not going to send a 4 GB payload anytime
soon...
next prev parent reply other threads:[~2025-09-26 2:20 UTC|newest]
Thread overview: 70+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-22 11:30 [PATCH v2 00/11] gpu: nova-core: Boot GSP to RISC-V active Alistair Popple
2025-09-22 11:30 ` [PATCH v2 01/10] gpu: nova-core: Set correct DMA mask Alistair Popple
2025-09-22 15:25 ` Boqun Feng
2025-09-22 16:08 ` Danilo Krummrich
2025-09-23 2:16 ` John Hubbard
2025-09-23 4:29 ` Alistair Popple
2025-09-26 12:00 ` Danilo Krummrich
2025-09-29 0:19 ` Alistair Popple
2025-09-29 7:06 ` Danilo Krummrich
2025-09-29 7:39 ` Alistair Popple
2025-09-29 12:49 ` Danilo Krummrich
2025-10-01 1:31 ` [PATCH v2 01/10] gpu: nova-core: Set correct DMA mask^[ Alistair Popple
2025-09-24 19:43 ` [PATCH v2 01/10] gpu: nova-core: Set correct DMA mask Lyude Paul
2025-09-22 11:30 ` [PATCH v2 02/10] gpu: nova-core: Create initial Gsp Alistair Popple
2025-09-23 14:20 ` Alexandre Courbot
2025-09-24 20:13 ` Lyude Paul
2025-09-24 20:50 ` John Hubbard
2025-09-24 21:07 ` Lyude Paul
2025-09-24 21:15 ` John Hubbard
2025-09-22 11:30 ` [PATCH v2 03/10] gpu: nova-core: gsp: Create wpr metadata Alistair Popple
2025-09-24 20:24 ` Lyude Paul
2025-09-26 1:24 ` Alexandre Courbot
2025-09-29 0:29 ` Alistair Popple
2025-09-29 14:54 ` Alexandre Courbot
2025-09-26 1:24 ` Alexandre Courbot
2025-09-29 0:38 ` Alistair Popple
2025-09-22 11:30 ` [PATCH v2 04/10] gpu: nova-core: Add a slice-buffer (sbuffer) datastructure Alistair Popple
2025-09-24 20:36 ` Lyude Paul
2025-09-29 0:44 ` Alistair Popple
2025-09-22 11:30 ` [PATCH v2 05/10] gpu: nova-core: gsp: Add GSP command queue handling Alistair Popple
2025-09-22 19:16 ` Timur Tabi
2025-09-24 22:03 ` Lyude Paul
2025-09-25 6:32 ` Alistair Popple
2025-09-26 2:20 ` Alexandre Courbot [this message]
2025-09-29 1:06 ` Alistair Popple
2025-09-29 7:24 ` Danilo Krummrich
2025-09-26 4:37 ` Alexandre Courbot
2025-09-29 6:19 ` Alistair Popple
2025-09-29 14:34 ` Alexandre Courbot
2025-09-29 14:38 ` Miguel Ojeda
2025-09-29 14:45 ` Alexandre Courbot
2025-09-30 11:41 ` Alistair Popple
2025-09-30 11:58 ` Miguel Ojeda
2025-10-01 0:42 ` Alistair Popple
2025-09-30 0:36 ` Alistair Popple
2025-09-30 10:33 ` Danilo Krummrich
2025-09-30 13:36 ` Alexandre Courbot
2025-09-22 11:30 ` [PATCH v2 06/10] gpu: nova-core: gsp: Create rmargs Alistair Popple
2025-09-24 22:05 ` Lyude Paul
2025-09-26 7:27 ` Alexandre Courbot
2025-09-29 6:36 ` Alistair Popple
2025-09-29 7:18 ` Danilo Krummrich
2025-09-29 7:49 ` Alistair Popple
2025-09-22 11:30 ` [PATCH v2 07/10] gpu: nova-core: gsp: Create RM registry and sysinfo commands Alistair Popple
2025-09-22 19:10 ` Timur Tabi
2025-09-23 4:40 ` Alistair Popple
2025-09-23 4:46 ` Timur Tabi
2025-09-24 22:11 ` Lyude Paul
2025-09-22 11:30 ` [PATCH v2 08/10] nova-core: falcon: Add support to check if RISC-V is active Alistair Popple
2025-09-22 19:12 ` Timur Tabi
2025-09-23 1:07 ` John Hubbard
2025-09-23 4:23 ` Timur Tabi
2025-09-23 4:42 ` Alistair Popple
2025-09-24 22:12 ` Lyude Paul
2025-09-22 11:30 ` [PATCH v2 09/10] nova-core: falcon: Add support to write firmware version Alistair Popple
2025-09-24 22:14 ` Lyude Paul
2025-09-22 11:30 ` [PATCH v2 10/10] nova-core: gsp: Boot GSP Alistair Popple
2025-09-24 22:15 ` Lyude Paul
2025-09-24 22:24 ` John Hubbard
2025-09-25 3:09 ` Timur Tabi
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=DD2DFKZTFIGS.2HDVZRV6WGXHG@nvidia.com \
--to=acourbot@nvidia.com \
--cc=a.hindborg@kernel.org \
--cc=airlied@gmail.com \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=apopple@nvidia.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=gary@garyguo.net \
--cc=jhubbard@nvidia.com \
--cc=joelagnelf@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=lyude@redhat.com \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=nouveau@lists.freedesktop.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=simona@ffwll.ch \
--cc=tmgross@umich.edu \
--cc=ttabi@nvidia.com \
--cc=tzimmermann@suse.de \
/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;
as well as URLs for NNTP newsgroup(s).