Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] gpu: nova-core: gsp: alloc_object() does not tie RmObject to
  parent lifetime
- [Low] gpu: nova-core: gsp: unaligned buffer in
  rm_control_roundtrip_and_error()
--

commit 3fa3eea017ee1413da688a66f0c79d30aaad55dc
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 allocation, control, and free RPC
commands along with RAII handle wrappers for RM clients, devices,
subdevices, and child objects.

> diff --git a/drivers/gpu/nova-core/gsp/rm.rs b/drivers/gpu/nova-core/gsp/rm.rs
> new file mode 100644
> index 0000000000000..29bddfb699de8
> --- /dev/null
> +++ b/drivers/gpu/nova-core/gsp/rm.rs
> @@ -0,0 +1,640 @@

[ ... ]

> +    /// Allocates an arbitrary RM child object under `parent` using typed 
> parameters `P`.
> +    #[expect(dead_code)]
> +    pub(crate) fn alloc_object<P: AsBytes + FromBytes>(
> +        &self,
> +        parent: RmHandle,
> +        object: RmHandle,
> +        class: u32,
> +        params: &P,
> +    ) -> Result<RmObject<'_, 'gsp>> {
> +        self.cmdq.send_command(RmAlloc::new(
> +            self.handle.raw(),
> +            parent.raw(),
> +            object.raw(),
> +            class,
> +            params,
> +        ))?;
> +
> +        Ok(RmObject {
> +            cmdq: self.cmdq,
> +            client_handle: self.handle,
> +            handle: object,
> +        })
> +    }

[Severity: Low]
Can an RmObject returned by RmClient::alloc_object() outlive its parent
RmDevice, RmSubdevice, or RmObject?

Unlike RmClient::alloc_device() and RmDevice::alloc_subdevice(),
alloc_object() takes parent by value as a Copy RmHandle and ties the
returned RmObject's lifetime only to &self (the RmClient).  If the parent
object is dropped first, GSP-RM frees the child in its resource database,
and later RmObject::control() or Drop::drop() calls on the surviving
RmObject will operate on an already-freed handle.

[ ... ]

> +        // Simulate a non-zero NV_STATUS error in reply header 
> (`NV_ERR_NO_MEMORY`).
> +        let mut err_hdr_bytes = [0u8; size_of::<GspRmControlHeader>()];
> +        err_hdr_bytes.copy_from_slice(hdr.as_bytes());
> +        // `status` is the 4th `u32` field (byte offset 12) in 
> `rpc_gsp_rm_control_v03_00`.
> +        err_hdr_bytes[12..16].copy_from_slice(&0x51u32.to_le_bytes());
> +        let err_hdr = 
> GspRmControlHeader::from_bytes(&err_hdr_bytes).ok_or(EIO)?;

[Severity: Low]
Can GspRmControlHeader::from_bytes(&err_hdr_bytes) fail spuriously with EIO
when err_hdr_bytes is not 4-byte aligned on the stack?

err_hdr_bytes is a [u8; 24] array with 1-byte alignment, whereas
GspRmControlHeader requires 4-byte alignment and FromBytes::from_bytes()
returns None when slice_ptr.is_aligned() is false:

rust/kernel/transmute.rs:FromBytes::from_bytes() {
    ...
        if bytes.len() == size && slice_ptr.is_aligned() {
            // SAFETY: Size and alignment were just checked.
            unsafe { Some(&*slice_ptr) }
        } else {
            None
        }
}

Using GspRmControlHeader::from_bytes_copy(&err_hdr_bytes) or mutating the
aligned KBox<GspRmControlHeader> in place avoids depending on stack
alignment.

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

Reply via email to