On Mon Mar 2, 2026 at 11:22 PM JST, Gary Guo wrote: > On Mon Mar 2, 2026 at 11:42 AM GMT, Eliot Courtney wrote: >> Add a helper function which computes the size of a command. >> >> Tested-by: Zhi Wang <[email protected]> >> Signed-off-by: Eliot Courtney <[email protected]> >> --- >> drivers/gpu/nova-core/gsp/cmdq.rs | 11 ++++++++++- >> 1 file changed, 10 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/gpu/nova-core/gsp/cmdq.rs >> b/drivers/gpu/nova-core/gsp/cmdq.rs >> index 9f74f0898d90..4a663a5b3437 100644 >> --- a/drivers/gpu/nova-core/gsp/cmdq.rs >> +++ b/drivers/gpu/nova-core/gsp/cmdq.rs >> @@ -450,6 +450,15 @@ struct GspMessage<'a> { >> contents: (&'a [u8], &'a [u8]), >> } >> >> +/// Computes the total size of the command (including its variable-length >> payload) without the >> +/// [`GspMsgElement`] header. >> +fn command_size<M>(command: &M) -> usize >> +where >> + M: CommandToGsp, >> +{ >> + size_of::<M::Command>() + command.variable_payload_len() >> +} >> + > > This could just a provided method on `CommandToGsp`?
I discussed this with Alex before[1] and my idea was that it's odd to add it as a default trait method since implementors could override it when they really shouldn't be able to, since it needs to agree with the size of the command and the variable payload length. WDYT? Is there a clear convention of doing this over the kernel? It just feels odd to me although I agree it's useful. Would be perfect if there was an easy way to prevent it from being overridden. [1]: https://lore.kernel.org/all/[email protected]
