Re: [PATCH v6 05/34] gpu: nova-core: gsp: decode the FIFO engine table

From: Simon Song

Date: Fri Dec 04 2026 - 11:33:07 EST


On 12/2/2026 3:28 AM, Alok Kumar wrote:
[...]
> // Decode:
>
> +const MAX_FIFO_ENGINES: usize = 256;
> +
> +/// Bit mask for `NVGMC_SC_ENGINE_FLAGS_IS_HOST_DRIVEN`.
> +const ENGINE_FLAGS_IS_HOST_DRIVEN: u32 = 1 << 0;
> +
> +/// Host-driven GMC engine IDs in hardware FIFO order, including any repeated IDs.
> +///
> +/// # Invariants
> +///
> +/// `count` is at most [`MAX_FIFO_ENGINES`]. The first `count` slots are the retained engine IDs.
> +#[derive(Copy, Clone)]
> +pub(crate) struct FifoEngineList {
> + gmc_ids: [u32; MAX_FIFO_ENGINES],
> + count: usize,
> +}

with MAX_FIFO_ENGINES increased to 256, and FifoEngineList implemented with Copy, it could overflow the stack,
could we consider moving this to heap, similar to what's done in openRM?

something like this:

--- a/drivers/gpu/nova-core/gsp/fw/commands.rs
+++ b/drivers/gpu/nova-core/gsp/fw/commands.rs
@@ -331,19 +331,21 @@
/// Host-driven GMC engine IDs in hardware FIFO order, including any repeated IDs.
///
-/// # Invariants
-///
-/// `count` is at most [`MAX_FIFO_ENGINES`]. The first `count` slots are the retained engine IDs.
-#[derive(Copy, Clone)]
+/// The IDs are kept on the heap, so that the list can be moved without copying them.
pub(crate) struct FifoEngineList {
- gmc_ids: [u32; MAX_FIFO_ENGINES],
- count: usize,
+ gmc_ids: KVec<u32>,
}

impl FifoEngineList {
pub(crate) fn gmc_ids(&self) -> &[u32] {
- // PANIC: The type invariant bounds `count` by the array capacity.
- &self.gmc_ids[..self.count]
+ &self.gmc_ids
+ }
+
+ /// Returns a copy of the list.
+ pub(crate) fn try_clone(&self) -> Result<Self> {
+ let mut gmc_ids = KVec::with_capacity(self.gmc_ids.len(), GFP_KERNEL)?;
+ gmc_ids.extend_from_slice(&self.gmc_ids, GFP_KERNEL)?;
+ Ok(Self { gmc_ids })
}
}
@@ -450,12 +452,8 @@
/// Returns the host-driven engines in their firmware FIFO order.
- pub(crate) fn fifo_engine_list(&self) -> FifoEngineList {
- // INVARIANT: The list starts empty and appends at most one ID per supported input slot.
- let mut fifo_engine_list = FifoEngineList {
- gmc_ids: [0; MAX_FIFO_ENGINES],
- count: 0,
- };
+ pub(crate) fn fifo_engine_list(&self) -> Result<FifoEngineList> {
+ let mut gmc_ids = KVec::new();
for (&gmc_id, &flags) in self
.fifo_engine_gmc_ids
.iter()
@@ -463,13 +461,10 @@
if flags & ENGINE_FLAGS_IS_HOST_DRIVEN != 0 {
- // PANIC: At most one slot is filled per input, and the input has at most
- // MAX_FIFO_ENGINES entries, so the next retained ID always fits.
- fifo_engine_list.gmc_ids[fifo_engine_list.count] = gmc_id;
- fifo_engine_list.count += 1;
+ gmc_ids.push(gmc_id, GFP_KERNEL)?;
}
}
- fifo_engine_list
+ Ok(FifoEngineList { gmc_ids })
}

--- a/drivers/gpu/nova-core/gsp/commands.rs
+++ b/drivers/gpu/nova-core/gsp/commands.rs
@@ -70,8 +70,8 @@
/// Returns the host-driven engines in their firmware FIFO order.
- pub(crate) fn fifo_engine_list(&self) -> FifoEngineList {
- self.fifo_engine_list
+ pub(crate) fn fifo_engine_list(&self) -> &FifoEngineList {
+ &self.fifo_engine_list
}

--- a/drivers/gpu/nova-core/gsp/commands/gmc.rs
+++ b/drivers/gpu/nova-core/gsp/commands/gmc.rs
@@ -172,7 +172,7 @@
- fifo_engine_list: reply.fifo_engine_list(),
+ fifo_engine_list: reply.fifo_engine_list()?,

--- a/drivers/gpu/nova-core/vgpu.rs
+++ b/drivers/gpu/nova-core/vgpu.rs
@@ -164,10 +164,10 @@
- ) -> impl PinInit<Self> + use<'gpu> {
- let fifo_engine_list = info.fifo_engine_list();
+ ) -> Result<impl PinInit<Self> + use<'gpu>> {
+ let fifo_engine_list = info.fifo_engine_list().try_clone()?;
let vmmu_segment_size = info.vmmu_segment_size;
- pin_init!(Self {
+ Ok(pin_init!(Self {
@@ -180,7 +180,7 @@
fifo_engine_list,
}),
- })
+ }))

--- a/drivers/gpu/nova-core/gpu.rs
+++ b/drivers/gpu/nova-core/gpu.rs
@@ -634,7 +634,7 @@
&gsp_resources.boot_result.static_info,
TOTAL_CHANNELS,
- ),
+ )?,
GFP_KERNEL,