Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] gpu: nova-core: gsp: unchecked rpc_result and wrong reply
  type in RmFreeReply
- [Low] gpu: nova-core: RmControlReply::read() drains sbuffer after
  read_exact()
--

commit c67e31312d3a98810c1881e3bd0e412db7ac2488
Author: Agustín Pereira <[email protected]>

gpu: nova-core: gsp: add RM alloc/control/free RPCs and client/device API

This commit implements the GSP-RM object alloc, control, and free RPCs
along with RAII handle wrappers for RM clients, devices, subdevices, and
child objects.

> diff --git a/drivers/gpu/nova-core/gsp/commands.rs 
> b/drivers/gpu/nova-core/gsp/commands.rs
> index cdbb13674f082..80b8da1ad672c 100644
> --- a/drivers/gpu/nova-core/gsp/commands.rs
> +++ b/drivers/gpu/nova-core/gsp/commands.rs
[ ... ]
> @@ -329,3 +330,185 @@ fn read(
[ ... ]
> +impl<P: AsBytes + FromBytes + Zeroable> MessageFromGsp for RmControlReply<P> 
> {
> +    const FUNCTION: MsgFunction = MsgFunction::GspRmControl;
> +    type InitError = Error;
> +    type Message = fw::commands::GspRmControlHeader;
> +
> +    fn read(
> +        msg: &Self::Message,
> +        sbuffer: &mut SBufferIter<array::IntoIter<&[u8], 2>>,
> +    ) -> Result<Self, Self::InitError> {
> +        msg.status().into_result()?;
> +
> +        let mut params = P::zeroed();
> +        sbuffer.read_exact(params.as_bytes_mut())?;
> +        while sbuffer.next().is_some() {}
> +
> +        Ok(Self { params })
> +    }
> +}

[Severity: Low]
Why does RmControlReply::read() drain sbuffer after read_exact()?

sbuffer.read_exact(params.as_bytes_mut()) already consumes the full
size_of::<P>() reply payload.  Draining any remaining bytes afterwards
silently suppresses the "has unprocessed data" warning in
CmdqInner::receive_msg() when a GSP_RM_CONTROL reply payload is larger
than P.

[ ... ]

> +/// The reply from the GSP to [`RmFree`].
> +pub(super) struct RmFreeReply;
> +
> +impl MessageFromGsp for RmFreeReply {
> +    const FUNCTION: MsgFunction = MsgFunction::Free;
> +    type InitError = Error;
> +    type Message = fw::commands::GspRmFree;
> +
> +    fn read(
> +        msg: &Self::Message,
> +        _sbuffer: &mut SBufferIter<array::IntoIter<&[u8], 2>>,
> +    ) -> Result<Self, Self::InitError> {
> +        msg.status().into_result()?;
> +        Ok(RmFreeReply)
> +    }
> +}

[Severity: Medium]
Does GSP-RM report NV_VGPU_MSG_FUNCTION_FREE completion status in
rpc_free_v03_00.params.status or in the outer rpc_message_header_v
rpc_result field?

Unlike GSP_RM_ALLOC and GSP_RM_CONTROL, nouveau's r535_gsp_rpc_rm_free()
requests a zero-payload reply for FREE and checks rpc->rpc_result in the
outer RPC header.  In nova-core, CmdqInner::receive_msg() does not check
header.inner.rpc.rpc_result, while RmFreeReply requires a 16-byte
GspRmFree payload and checks params.status (which GspRmFree::new()
initializes to 0):

drivers/gpu/nova-core/gsp/cmdq.rs:CmdqInner::receive_msg() {
    ...
        // An early return here would leave the read pointer on this message.
        let result = if matches!(function, Ok(f) if f == M::FUNCTION) {
            let (cmd, contents_1) = 
M::Message::from_bytes_prefix(message.contents.0).ok_or(EIO)?;
    ...
}

As a result, RPC errors reported in rpc_result are missed, and if GSP-RM
returns an empty reply payload for FREE (like UnloadingGuestDriverReply,
which uses type Message = ()), GspRmFree::from_bytes_prefix() returns
Err(EIO) before advance_cpu_read_ptr() is reached, leaving the command
queue read pointer stuck on the unconsumed message.

-- 
Sashiko AI review · 
https://sashiko.dev/#/patchset/[email protected]?part=1

Reply via email to