gpu: nova-core: gsp: add continuation record support
Subsystems (3)
cover gpu: nova-core: gsp: add continuation record support
GSP commands over 16 pages need to be sent using "continuation records" which essentially means splitting the payload over multiple commands.
This series adds a command type ContinuationRecord which just writes its header and whatever payload it is given. It also adds a type WrappingCommand which supports splitting a large RPC into smaller ones.
The send pathway uses WrappingCommand to send all commands, but if the command fits into 16 pages, it still writes directly into the command queue. If it is larger than 16 pages and needs continuation records, it writes into a staging buffer, so there is one copy.
This patch series uses EIO for mis-sized commands to be consistent with the rest of the code.
Patch 6 introduces a single helper send_continuation_record. This is because the compiler can't properly infer the types without this.
---
Eliot Courtney (7):
gpu: nova-core: gsp: sort MsgFunction variants alphabetically
gpu: nova-core: gsp: add mechanism to wait for space on command queue
gpu: nova-core: gsp: add checking oversized commands
gpu: nova-core: gsp: clarify invariant on command queue
gpu: nova-core: gsp: unconditionally call variable payload handling
gpu: nova-core: gsp: support large RPCs via continuation record
gpu: nova-core: gsp: add tests for WrappingCommand
drivers/gpu/nova-core/gsp/cmdq.rs | 113 ++++++++++++++-- drivers/gpu/nova-core/gsp/commands.rs | 247 ++++++++++++++++++++++++++++++++++ drivers/gpu/nova-core/gsp/fw.rs | 102 +++++++------- 3 files changed, 401 insertions(+), 61 deletions(-)
---
base-commit: cea7b66a80412e2a5b74627b89ae25f1d0110a4b
change-id: 20260203-cmdq-continuation-b99f3d5966c3
Best regards,
Signature · 1 line
Eliot Courtney <[email protected]>
PATCH 1/7 gpu: nova-core: gsp: sort MsgFunction variants alphabetically
There is no particular order required here and keeping them alphabetical will help preventing future mistakes.
--- drivers/gpu/nova-core/gsp/fw.rs | 97 +++++++++++++++++++++-------------------- 1 file changed, 50 insertions(+), 47 deletions(-)
drivers/gpu/nova-core/gsp/fw.rs +50 -47
@@ -192,34 +192,34 @@ pub(crate) fn new(gsp_firmware: &GspFirmware, fb_layout: &FbLayout) -> Self {#[repr( u32 )] pub (crate )enum MsgFunction {// Common function codes -Nop = bindings::NV_VGPU_MSG_FUNCTION_NOP , -SetGuestSystemInfo = bindings::NV_VGPU_MSG_FUNCTION_SET_GUEST_SYSTEM_INFO , -AllocRoot = bindings::NV_VGPU_MSG_FUNCTION_ALLOC_ROOT , +AllocChannelDma = bindings::NV_VGPU_MSG_FUNCTION_ALLOC_CHANNEL_DMA , +AllocCtxDma = bindings::NV_VGPU_MSG_FUNCTION_ALLOC_CTX_DMA ,AllocDevice = bindings::NV_VGPU_MSG_FUNCTION_ALLOC_DEVICE ,AllocMemory = bindings::NV_VGPU_MSG_FUNCTION_ALLOC_MEMORY , -AllocCtxDma = bindings::NV_VGPU_MSG_FUNCTION_ALLOC_CTX_DMA , -AllocChannelDma = bindings::NV_VGPU_MSG_FUNCTION_ALLOC_CHANNEL_DMA , -MapMemory = bindings::NV_VGPU_MSG_FUNCTION_MAP_MEMORY , -BindCtxDma = bindings::NV_VGPU_MSG_FUNCTION_BIND_CTX_DMA ,AllocObject = bindings::NV_VGPU_MSG_FUNCTION_ALLOC_OBJECT , +AllocRoot = bindings::NV_VGPU_MSG_FUNCTION_ALLOC_ROOT , +BindCtxDma = bindings::NV_VGPU_MSG_FUNCTION_BIND_CTX_DMA ,Free = bindings::NV_VGPU_MSG_FUNCTION_FREE , -Log = bindings::NV_VGPU_MSG_FUNCTION_LOG ,GetGspStaticInfo = bindings::NV_VGPU_MSG_FUNCTION_GET_GSP_STATIC_INFO , -SetRegistry = bindings::NV_VGPU_MSG_FUNCTION_SET_REGISTRY , -GspSetSystemInfo = bindings::NV_VGPU_MSG_FUNCTION_GSP_SET_SYSTEM_INFO , +GetStaticInfo = bindings::NV_VGPU_MSG_FUNCTION_GET_STATIC_INFO ,GspInitPostObjGpu = bindings::NV_VGPU_MSG_FUNCTION_GSP_INIT_POST_OBJGPU ,GspRmControl = bindings::NV_VGPU_MSG_FUNCTION_GSP_RM_CONTROL , -GetStaticInfo = bindings::NV_VGPU_MSG_FUNCTION_GET_STATIC_INFO , +GspSetSystemInfo = bindings::NV_VGPU_MSG_FUNCTION_GSP_SET_SYSTEM_INFO , +Log = bindings::NV_VGPU_MSG_FUNCTION_LOG , +MapMemory = bindings::NV_VGPU_MSG_FUNCTION_MAP_MEMORY , +Nop = bindings::NV_VGPU_MSG_FUNCTION_NOP , +SetGuestSystemInfo = bindings::NV_VGPU_MSG_FUNCTION_SET_GUEST_SYSTEM_INFO , +SetRegistry = bindings::NV_VGPU_MSG_FUNCTION_SET_REGISTRY ,// Event codes GspInitDone = bindings::NV_VGPU_MSG_EVENT_GSP_INIT_DONE , +GspLockdownNotice = bindings::NV_VGPU_MSG_EVENT_GSP_LOCKDOWN_NOTICE , +GspPostNoCat = bindings::NV_VGPU_MSG_EVENT_GSP_POST_NOCAT_RECORD ,GspRunCpuSequencer = bindings::NV_VGPU_MSG_EVENT_GSP_RUN_CPU_SEQUENCER , -PostEvent = bindings::NV_VGPU_MSG_EVENT_POST_EVENT , -RcTriggered = bindings::NV_VGPU_MSG_EVENT_RC_TRIGGERED ,MmuFaultQueued = bindings::NV_VGPU_MSG_EVENT_MMU_FAULT_QUEUED ,OsErrorLog = bindings::NV_VGPU_MSG_EVENT_OS_ERROR_LOG , -GspPostNoCat = bindings::NV_VGPU_MSG_EVENT_GSP_POST_NOCAT_RECORD , -GspLockdownNotice = bindings::NV_VGPU_MSG_EVENT_GSP_LOCKDOWN_NOTICE , +PostEvent = bindings::NV_VGPU_MSG_EVENT_POST_EVENT , +RcTriggered = bindings::NV_VGPU_MSG_EVENT_RC_TRIGGERED ,UcodeLibOsPrint = bindings::NV_VGPU_MSG_EVENT_UCODE_LIBOS_PRINT , }
@@ -227,34 +227,34 @@ impl fmt::Display for MsgFunction {fn fmt (&self, f: &mut fmt::Formatter <'_>) -> fmt::Result {match self {// Common function codes -MsgFunction ::Nop =>write! (f,"NOP" ), -MsgFunction ::SetGuestSystemInfo =>write! (f,"SET_GUEST_SYSTEM_INFO" ), -MsgFunction ::AllocRoot =>write! (f,"ALLOC_ROOT" ), +MsgFunction ::AllocChannelDma =>write! (f,"ALLOC_CHANNEL_DMA" ), +MsgFunction ::AllocCtxDma =>write! (f,"ALLOC_CTX_DMA" ),MsgFunction ::AllocDevice =>write! (f,"ALLOC_DEVICE" ),MsgFunction ::AllocMemory =>write! (f,"ALLOC_MEMORY" ), -MsgFunction ::AllocCtxDma =>write! (f,"ALLOC_CTX_DMA" ), -MsgFunction ::AllocChannelDma =>write! (f,"ALLOC_CHANNEL_DMA" ), -MsgFunction ::MapMemory =>write! (f,"MAP_MEMORY" ), -MsgFunction ::BindCtxDma =>write! (f,"BIND_CTX_DMA" ),MsgFunction ::AllocObject =>write! (f,"ALLOC_OBJECT" ), +MsgFunction ::AllocRoot =>write! (f,"ALLOC_ROOT" ), +MsgFunction ::BindCtxDma =>write! (f,"BIND_CTX_DMA" ),MsgFunction ::Free =>write! (f,"FREE" ), -MsgFunction ::Log =>write! (f,"LOG" ),MsgFunction ::GetGspStaticInfo =>write! (f,"GET_GSP_STATIC_INFO" ), -MsgFunction ::SetRegistry =>write! (f,"SET_REGISTRY" ), -MsgFunction ::GspSetSystemInfo =>write! (f,"GSP_SET_SYSTEM_INFO" ), +MsgFunction ::GetStaticInfo =>write! (f,"GET_STATIC_INFO" ),MsgFunction ::GspInitPostObjGpu =>write! (f,"GSP_INIT_POST_OBJGPU" ),MsgFunction ::GspRmControl =>write! (f,"GSP_RM_CONTROL" ), -MsgFunction ::GetStaticInfo =>write! (f,"GET_STATIC_INFO" ), +MsgFunction ::GspSetSystemInfo =>write! (f,"GSP_SET_SYSTEM_INFO" ), +MsgFunction ::Log =>write! (f,"LOG" ), +MsgFunction ::MapMemory =>write! (f,"MAP_MEMORY" ), +MsgFunction ::Nop =>write! (f,"NOP" ), +MsgFunction ::SetGuestSystemInfo =>write! (f,"SET_GUEST_SYSTEM_INFO" ), +MsgFunction ::SetRegistry =>write! (f,"SET_REGISTRY" ),// Event codes MsgFunction ::GspInitDone =>write! (f,"INIT_DONE" ), +MsgFunction ::GspLockdownNotice =>write! (f,"LOCKDOWN_NOTICE" ), +MsgFunction ::GspPostNoCat =>write! (f,"NOCAT" ),MsgFunction ::GspRunCpuSequencer =>write! (f,"RUN_CPU_SEQUENCER" ), -MsgFunction ::PostEvent =>write! (f,"POST_EVENT" ), -MsgFunction ::RcTriggered =>write! (f,"RC_TRIGGERED" ),MsgFunction ::MmuFaultQueued =>write! (f,"MMU_FAULT_QUEUED" ),MsgFunction ::OsErrorLog =>write! (f,"OS_ERROR_LOG" ), -MsgFunction ::GspPostNoCat =>write! (f,"NOCAT" ), -MsgFunction ::GspLockdownNotice =>write! (f,"LOCKDOWN_NOTICE" ), +MsgFunction ::PostEvent =>write! (f,"POST_EVENT" ), +MsgFunction ::RcTriggered =>write! (f,"RC_TRIGGERED" ),MsgFunction ::UcodeLibOsPrint =>write! (f,"LIBOS_PRINT" ), } }
@@ -265,38 +265,41 @@ impl TryFrom<u32> for MsgFunction {fn try_from (value:u32 ) ->Result <MsgFunction > {match value { - bindings::NV_VGPU_MSG_FUNCTION_NOP =>Ok (MsgFunction ::Nop ), - bindings::NV_VGPU_MSG_FUNCTION_SET_GUEST_SYSTEM_INFO => { -Ok (MsgFunction ::SetGuestSystemInfo ) - } - bindings::NV_VGPU_MSG_FUNCTION_ALLOC_ROOT =>Ok (MsgFunction ::AllocRoot ), +// Common function codes + bindings::NV_VGPU_MSG_FUNCTION_ALLOC_CHANNEL_DMA =>Ok (MsgFunction ::AllocChannelDma ), + bindings::NV_VGPU_MSG_FUNCTION_ALLOC_CTX_DMA =>Ok (MsgFunction ::AllocCtxDma ), bindings::NV_VGPU_MSG_FUNCTION_ALLOC_DEVICE =>Ok (MsgFunction ::AllocDevice ), bindings::NV_VGPU_MSG_FUNCTION_ALLOC_MEMORY =>Ok (MsgFunction ::AllocMemory ), - bindings::NV_VGPU_MSG_FUNCTION_ALLOC_CTX_DMA =>Ok (MsgFunction ::AllocCtxDma ), - bindings::NV_VGPU_MSG_FUNCTION_ALLOC_CHANNEL_DMA =>Ok (MsgFunction ::AllocChannelDma ), - bindings::NV_VGPU_MSG_FUNCTION_MAP_MEMORY =>Ok (MsgFunction ::MapMemory ), - bindings::NV_VGPU_MSG_FUNCTION_BIND_CTX_DMA =>Ok (MsgFunction ::BindCtxDma ), bindings::NV_VGPU_MSG_FUNCTION_ALLOC_OBJECT =>Ok (MsgFunction ::AllocObject ), + bindings::NV_VGPU_MSG_FUNCTION_ALLOC_ROOT =>Ok (MsgFunction ::AllocRoot ), + bindings::NV_VGPU_MSG_FUNCTION_BIND_CTX_DMA =>Ok (MsgFunction ::BindCtxDma ), bindings::NV_VGPU_MSG_FUNCTION_FREE =>Ok (MsgFunction ::Free ), - bindings::NV_VGPU_MSG_FUNCTION_LOG =>Ok (MsgFunction ::Log ), bindings::NV_VGPU_MSG_FUNCTION_GET_GSP_STATIC_INFO =>Ok (MsgFunction ::GetGspStaticInfo ), - bindings::NV_VGPU_MSG_FUNCTION_SET_REGISTRY =>Ok (MsgFunction ::SetRegistry ), - bindings::NV_VGPU_MSG_FUNCTION_GSP_SET_SYSTEM_INFO =>Ok (MsgFunction ::GspSetSystemInfo ), + bindings::NV_VGPU_MSG_FUNCTION_GET_STATIC_INFO =>Ok (MsgFunction ::GetStaticInfo ), bindings::NV_VGPU_MSG_FUNCTION_GSP_INIT_POST_OBJGPU => {Ok (MsgFunction ::GspInitPostObjGpu ) } bindings::NV_VGPU_MSG_FUNCTION_GSP_RM_CONTROL =>Ok (MsgFunction ::GspRmControl ), - bindings::NV_VGPU_MSG_FUNCTION_GET_STATIC_INFO =>Ok (MsgFunction ::GetStaticInfo ), + bindings::NV_VGPU_MSG_FUNCTION_GSP_SET_SYSTEM_INFO =>Ok (MsgFunction ::GspSetSystemInfo ), + bindings::NV_VGPU_MSG_FUNCTION_LOG =>Ok (MsgFunction ::Log ), + bindings::NV_VGPU_MSG_FUNCTION_MAP_MEMORY =>Ok (MsgFunction ::MapMemory ), + bindings::NV_VGPU_MSG_FUNCTION_NOP =>Ok (MsgFunction ::Nop ), + bindings::NV_VGPU_MSG_FUNCTION_SET_GUEST_SYSTEM_INFO => { +Ok (MsgFunction ::SetGuestSystemInfo ) + } + bindings::NV_VGPU_MSG_FUNCTION_SET_REGISTRY =>Ok (MsgFunction ::SetRegistry ), + +// Event codes bindings::NV_VGPU_MSG_EVENT_GSP_INIT_DONE =>Ok (MsgFunction ::GspInitDone ), + bindings::NV_VGPU_MSG_EVENT_GSP_LOCKDOWN_NOTICE =>Ok (MsgFunction ::GspLockdownNotice ), + bindings::NV_VGPU_MSG_EVENT_GSP_POST_NOCAT_RECORD =>Ok (MsgFunction ::GspPostNoCat ), bindings::NV_VGPU_MSG_EVENT_GSP_RUN_CPU_SEQUENCER => {Ok (MsgFunction ::GspRunCpuSequencer ) } - bindings::NV_VGPU_MSG_EVENT_POST_EVENT =>Ok (MsgFunction ::PostEvent ), - bindings::NV_VGPU_MSG_EVENT_RC_TRIGGERED =>Ok (MsgFunction ::RcTriggered ), bindings::NV_VGPU_MSG_EVENT_MMU_FAULT_QUEUED =>Ok (MsgFunction ::MmuFaultQueued ), bindings::NV_VGPU_MSG_EVENT_OS_ERROR_LOG =>Ok (MsgFunction ::OsErrorLog ), - bindings::NV_VGPU_MSG_EVENT_GSP_POST_NOCAT_RECORD =>Ok (MsgFunction ::GspPostNoCat ), - bindings::NV_VGPU_MSG_EVENT_GSP_LOCKDOWN_NOTICE =>Ok (MsgFunction ::GspLockdownNotice ), + bindings::NV_VGPU_MSG_EVENT_POST_EVENT =>Ok (MsgFunction ::PostEvent ), + bindings::NV_VGPU_MSG_EVENT_RC_TRIGGERED =>Ok (MsgFunction ::RcTriggered ), bindings::NV_VGPU_MSG_EVENT_UCODE_LIBOS_PRINT =>Ok (MsgFunction ::UcodeLibOsPrint ), _ =>Err (EINVAL ), }
Signature · 1 line
2.53.0
PATCH 2/7 gpu: nova-core: gsp: add mechanism to wait for space on command queue
In reply to Eliot CourtneyAdd allocate_command_with_timeout which waits for space on the GSP command queue. It uses a similar timeout to nouveau.
Let send_command wait for space to free up in the command queue by calling allocate_command_with_timeout. This is required to support continuation records which can fill up the queue.
--- drivers/gpu/nova-core/gsp/cmdq.rs | 42 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-)
drivers/gpu/nova-core/gsp/cmdq.rs +39 -3
@@ -243,6 +243,16 @@ fn new(dev: &device::Device<device::Bound>) -> Result<Self> { } } +fn driver_bytes_available_to_write (&self) ->usize { +let tx = self.cpu_write_ptr (); +let rx = self.gsp_read_ptr (); +// `rx` and `tx` are both in `0..MSGQ_NUM_PAGES` per the invariants of `gsp_read_ptr` and +// `cpu_write_ptr`. The minimum value case is where `rx == 0` and `tx == MSGQ_NUM_PAGES - +// 1`, which gives `0 + MSGQ_NUM_PAGES - (MSGQ_NUM_PAGES - 1) - 1 == 0`. +let slots = (rx +MSGQ_NUM_PAGES - tx -1 ) %MSGQ_NUM_PAGES ; + num::u32_as_usize (slots) *GSP_PAGE_SIZE + } +/// Returns the region of the GSP message queue that the driver is currently allowed to read /// from. ///
@@ -311,6 +321,25 @@ fn allocate_command(&mut self, size: usize) -> Result<GspCommand<'_>> { }) } +/// Allocates a region on the command queue that is large enough to send a command of `size` +/// bytes, waiting for space to become available. +/// +/// This returns a [`GspCommand`] ready to be written to by the caller. +/// +/// # Errors +/// +/// - `ETIMEDOUT` if space does not become available within the timeout. +/// - `EIO` if the command header is not properly aligned. +fn allocate_command_with_timeout (&mut self, size:usize ) ->Result <GspCommand <'_>> { +read_poll_timeout ( + ||Ok (self.driver_bytes_available_to_write ()), + |available_bytes| *available_bytes >=size_of ::<GspMsgElement >() + size, +Delta ::ZERO , +Delta ::from_secs (1 ), + )?; + self.allocate_command (size) + } +// Returns the index of the memory page the GSP will write the next message to. // // # Invariants
@@ -480,11 +509,18 @@ fn notify_gsp(bar: &Bar0) { .write(bar); } +fn command_size <M >(command: &M ) ->usize +where +M :CommandToGsp , + { +size_of ::<M ::Command >() + command.variable_payload_len () + } +/// Sends `command` to the GSP. /// /// # Errors /// -/// - `EAGAIN` if there was not enough space in the command queue to send the command. +/// - `ETIMEDOUT` if space does not become available within the timeout. /// - `EIO` if the variable payload requested by the command has not been entirely /// written to by its [`CommandToGsp::init_variable_payload`] method. ///
@@ -495,8 +531,8 @@ pub(crate) fn send_command<M>(&mut self, bar: &Bar0, command: M) -> Result// This allows all error types, including `Infallible`, to be used for `M::InitError`. Error: From<M::InitError>, { -let command_size =size_of ::<M ::Command >() + command.variable_payload_len (); -let dst = self.gsp_mem.allocate_command (command_size)?; +let command_size =Self ::command_size (&command); +let dst = self.gsp_mem.allocate_command_with_timeout (command_size)?;// Extract area for the command itself. let (cmd, payload_1) =M ::Command ::from_bytes_mut_prefix (dst.contents.0 ).ok_or (EIO )?;
Signature · 1 line
2.53.0
Alexandre Courbot
maintainerRe: [PATCH 2/7] gpu: nova-core: gsp: add mechanism to wait for space on command queue
Quoted 5 lines · Eliot Courtney
Add
allocate_command_with_timeoutwhich waits for space on the GSP command queue. It uses a similar timeout to nouveau.Let
send_commandwait for space to free up in the command queue by callingallocate_command_with_timeout. This is required to
I'd name it just allocate_command_timeout, to follow the pattern of the existing read_poll_timeout - but actually we might not even need a new method (see below).
Quoted 12 lines
support continuation records which can fill up the queue.
Signed-off-by Eliot Courtney <[email protected]>--- drivers/gpu/nova-core/gsp/cmdq.rs | 42 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-)drivers/gpu/nova-core/gsp/cmdq.rs +0
-0
drivers/gpu/nova-core/gsp/cmdq.rs fn new(dev: &device::Device<device::Bound>) -> Result<Self> { · line 246
Quoted 4 lines
drivers/gpu/nova-core/gsp/cmdq.rs +1
-0@@ -243,6 +243,16 @@ fn new(dev: &device::Device<device::Bound>) -> Result<Self> { } } +fn driver_bytes_available_to_write (&self) ->usize {
For consistency with driver_write_area, shall we name this driver_write_area_size? And add a doccomment mentioning the returned value is in bytes.
drivers/gpu/nova-core/gsp/cmdq.rs fn new(dev: &device::Device<device::Bound>) -> Result<Self> { · line 249
Quoted 3 lines
drivers/gpu/nova-core/gsp/cmdq.rs +3
-0+let tx = self.cpu_write_ptr (); +let rx = self.gsp_read_ptr (); +// `rx` and `tx` are both in `0..MSGQ_NUM_PAGES` per the invariants of `gsp_read_ptr` and
Nit: missing empty line.
Quoted 13 lines
drivers/gpu/nova-core/gsp/cmdq.rs +6
-0+// `cpu_write_ptr`. The minimum value case is where `rx == 0` and `tx == MSGQ_NUM_PAGES - +// 1`, which gives `0 + MSGQ_NUM_PAGES - (MSGQ_NUM_PAGES - 1) - 1 == 0`. +let slots = (rx +MSGQ_NUM_PAGES - tx -1 ) %MSGQ_NUM_PAGES ; + num::u32_as_usize (slots) *GSP_PAGE_SIZE + } +/// Returns the region of the GSP message queue that the driver is currently allowed to read /// from. /// @@ -311,6 +321,25 @@ fn allocate_command(&mut self, size: usize) -> Result<GspCommand<'_>> { }) }
drivers/gpu/nova-core/gsp/cmdq.rs fn allocate_command(&mut self, size: usize) -> Result<GspCommand<'_>> { · line 333
Quoted 10 lines
drivers/gpu/nova-core/gsp/cmdq.rs +10
-0+/// Allocates a region on the command queue that is large enough to send a command of `size` +/// bytes, waiting for space to become available. +/// +/// This returns a [`GspCommand`] ready to be written to by the caller. +/// +/// # Errors +/// +/// - `ETIMEDOUT` if space does not become available within the timeout. +/// - `EIO` if the command header is not properly aligned. +fn allocate_command_with_timeout (&mut self, size:usize ) ->Result <GspCommand <'_>> {
Should the timeout be an argument? That way we can simply add it to allocate_command, and invoke it with Delta::ZERO whenever we don't want to wait. This is more explicit at the call site, removes the need to have two methods, and removes the redundant size check from allocate_command which is now done by this read_poll_timeout.
Quoted 13 lines
drivers/gpu/nova-core/gsp/cmdq.rs +9
-0+read_poll_timeout ( + ||Ok (self.driver_bytes_available_to_write ()), + |available_bytes| *available_bytes >=size_of ::<GspMsgElement >() + size, +Delta ::ZERO , +Delta ::from_secs (1 ), + )?; + self.allocate_command (size) + } +// Returns the index of the memory page the GSP will write the next message to. // // # Invariants
drivers/gpu/nova-core/gsp/cmdq.rs fn notify_gsp(bar: &Bar0) { · line 512
Quoted 4 lines
drivers/gpu/nova-core/gsp/cmdq.rs +1
-0@@ -480,11 +509,18 @@ fn notify_gsp(bar: &Bar0) { .write(bar); } +fn command_size <M >(command: &M ) ->usize
Shouldn't this be a member function of CommandToGsp? Please add some basic documentation for it as well. As a general rule, all methods, even basic ones, should have at least one line of doccomment.
Quoted 16 lines
drivers/gpu/nova-core/gsp/cmdq.rs +7
-1+ where + M: CommandToGsp, + { + size_of::<M::Command>() + command.variable_payload_len() + } +/// Sends `command` to the GSP. /// /// # Errors /// -/// - `EAGAIN` if there was not enough space in the command queue to send the command. +/// - `ETIMEDOUT` if space does not become available within the timeout. /// - `EIO` if the variable payload requested by the command has not been entirely /// written to by its [`CommandToGsp::init_variable_payload`] method. ///
drivers/gpu/nova-core/gsp/cmdq.rs pub(crate) fn send_command<M>(&mut self, bar: &Bar0, command: M) -> Result · line 534
Quoted 6 lines
drivers/gpu/nova-core/gsp/cmdq.rs +1
-2@@ -495,8 +531,8 @@ pub(crate) fn send_command<M>(&mut self, bar: &Bar0, command: M) -> Result// This allows all error types, including `Infallible`, to be used for `M::InitError`. Error: From<M::InitError>, { -let command_size =size_of ::<M ::Command >() + command.variable_payload_len (); -let dst = self.gsp_mem.allocate_command (command_size)?; +let command_size =Self ::command_size (&command);
The addition of command_size looks like an unrelated change - it is not really leveraged until patch 6 (although it is still valuable on its own). Can you move it to its own patch for clarity?
Re: [PATCH 2/7] gpu: nova-core: gsp: add mechanism to wait for space on command queue
Quoted 11 lines · Alexandre Courbot
drivers/gpu/nova-core/gsp/cmdq.rs fn allocate_command(&mut self, size: usize) -> Result<GspCommand<'_>> { · line 333
Quoted 10 lines
drivers/gpu/nova-core/gsp/cmdq.rs +10
-0+/// Allocates a region on the command queue that is large enough to send a command of `size` +/// bytes, waiting for space to become available. +/// +/// This returns a [`GspCommand`] ready to be written to by the caller. +/// +/// # Errors +/// +/// - `ETIMEDOUT` if space does not become available within the timeout. +/// - `EIO` if the command header is not properly aligned. +fn allocate_command_with_timeout (&mut self, size:usize ) ->Result <GspCommand <'_>> {
Quoted 5 lines
Should the timeout be an argument? That way we can simply add it to
allocate_command, and invoke it withDelta::ZEROwhenever we don't want to wait. This is more explicit at the call site, removes the need to have two methods, and removes the redundant size check fromallocate_commandwhich is now done by thisread_poll_timeout.
Good idea, thanks.
Quoted 5 lines
Quoted 1 line
+ fn command_size<M>(command: &M) -> usize
Shouldn't this be a member function of
CommandToGsp? Please add some basic documentation for it as well. As a general rule, all methods, even basic ones, should have at least one line of doccomment.
I thought about this, but adding a function to CommandToGsp with a default implementation seems odd to me, because implementors of that trait could override it, which does not really make sense. We have command size defined as the size of the struct plus the variable payload size. Adding a function to CommandToGsp would give two methods to calculate the command size which could differ. So, seems weird to me.
An alternative would be to make it a free standing function. This would let it be used by WrappingCommand later as well. WDYT?
Will make sure all functions have doccomment from now on, thanks.
Quoted 19 lines
Quoted 19 lines
drivers/gpu/nova-core/gsp/cmdq.rs +7
-1+ where + M: CommandToGsp, + { + size_of::<M::Command>() + command.variable_payload_len() + } +/// Sends `command` to the GSP. /// /// # Errors /// -/// - `EAGAIN` if there was not enough space in the command queue to send the command. +/// - `ETIMEDOUT` if space does not become available within the timeout. /// - `EIO` if the variable payload requested by the command has not been entirely /// written to by its [`CommandToGsp::init_variable_payload`] method. /// @@ -495,8 +531,8 @@ pub(crate) fn send_command<M>(&mut self, bar: &Bar0, command: M) -> Result// This allows all error types, including `Infallible`, to be used for `M::InitError`. Error: From<M::InitError>,
Quoted 8 lines
drivers/gpu/nova-core/gsp/cmdq.rs pub(crate) fn send_command<M>(&mut self, bar: &Bar0, command: M) -> Result · line 534
Quoted 4 lines
drivers/gpu/nova-core/gsp/cmdq.rs +1
-2{ -let command_size =size_of ::<M ::Command >() + command.variable_payload_len (); -let dst = self.gsp_mem.allocate_command (command_size)?; +let command_size =Self ::command_size (&command);The addition of
command_sizelooks like an unrelated change - it is not really leveraged until patch 6 (although it is still valuable on its own). Can you move it to its own patch for clarity?
Will do.
Alexandre Courbot
maintainerRe: [PATCH 2/7] gpu: nova-core: gsp: add mechanism to wait for space on command queue
Quoted 13 lines · Eliot Courtney
Quoted 5 lines
Quoted 1 line
+ fn command_size<M>(command: &M) -> usize
Shouldn't this be a member function of
CommandToGsp? Please add some basic documentation for it as well. As a general rule, all methods, even basic ones, should have at least one line of doccomment.I thought about this, but adding a function to CommandToGsp with a default implementation seems odd to me, because implementors of that trait could override it, which does not really make sense. We have command size defined as the size of the struct plus the variable payload size. Adding a function to CommandToGsp would give two methods to calculate the command size which could differ. So, seems weird to me.
Quoted 2 lines
An alternative would be to make it a free standing function. This would let it be used by WrappingCommand later as well. WDYT?
Using default trait methods even when they should not be overriden is common in the kernel, so I am not worried about that. But you are right that the use of this size is local to the command queue so maybe it's better to keep it as a (documented :)) method of it.
PATCH 3/7 gpu: nova-core: gsp: add checking oversized commands
In reply to Eliot CourtneyThe limit is 16 pages for a single command sent to the GSP. Return an error if allocate_command is called with a too large size.
--- drivers/gpu/nova-core/gsp/cmdq.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/gpu/nova-core/gsp/cmdq.rs +9 -1
@@ -122,6 +122,11 @@ fn read(/// Number of GSP pages making the [`Msgq`]. pub (crate )const MSGQ_NUM_PAGES :u32 =0x3f ; +/// Maximum size of a single GSP command in bytes. +/// +/// A single command can span up to 16 GSP pages. +pub (crate )const MSGQ_MSG_SIZE_MAX :usize =GSP_PAGE_SIZE *16 ; +/// Circular buffer of a [`Msgq`]. /// /// This area of memory is to be shared between the driver and the GSP to exchange commands or
@@ -329,8 +334,11 @@ fn allocate_command(&mut self, size: usize) -> Result<GspCommand<'_>> {/// # Errors /// /// - `ETIMEDOUT` if space does not become available within the timeout. -/// - `EIO` if the command header is not properly aligned. +/// - `EIO` if the command header is not properly aligned or sizing is impossible. fn allocate_command_with_timeout (&mut self, size:usize ) ->Result <GspCommand <'_>> { +if size_of ::<GspMsgElement >() + size >MSGQ_MSG_SIZE_MAX { +return Err (EIO ); + }read_poll_timeout ( ||Ok (self.driver_bytes_available_to_write ()), |available_bytes| *available_bytes >= size_of::<GspMsgElement>() + size,
Signature · 1 line
2.53.0
Alexandre Courbot
maintainerRe: [PATCH 3/7] gpu: nova-core: gsp: add checking oversized commands
Quoted 13 lines · Eliot Courtney
The limit is 16 pages for a single command sent to the GSP. Return an error if
allocate_commandis called with a too large size.Signed-off-by Eliot Courtney <[email protected]>--- drivers/gpu/nova-core/gsp/cmdq.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)drivers/gpu/nova-core/gsp/cmdq.rs +0
-0
drivers/gpu/nova-core/gsp/cmdq.rs fn read( · line 128
Quoted 7 lines
drivers/gpu/nova-core/gsp/cmdq.rs +4
-0@@ -122,6 +122,11 @@ fn read(/// Number of GSP pages making the [`Msgq`]. pub (crate )const MSGQ_NUM_PAGES :u32 =0x3f ; +/// Maximum size of a single GSP command in bytes. +/// +/// A single command can span up to 16 GSP pages. +pub (crate )const MSGQ_MSG_SIZE_MAX :usize =GSP_PAGE_SIZE *16 ;
Where does this limitation come from? Is there a value in OpenRM that we can add to the bindings as the source of truth?
drivers/gpu/nova-core/gsp/cmdq.rs fn allocate_command(&mut self, size: usize) -> Result<GspCommand<'_>> { · line 337
Quoted 10 lines
drivers/gpu/nova-core/gsp/cmdq.rs +2
-1+/// Circular buffer of a [`Msgq`]. /// /// This area of memory is to be shared between the driver and the GSP to exchange commands or @@ -329,8 +334,11 @@ fn allocate_command(&mut self, size: usize) -> Result<GspCommand<'_>> {/// # Errors /// /// - `ETIMEDOUT` if space does not become available within the timeout. -/// - `EIO` if the command header is not properly aligned. +/// - `EIO` if the command header is not properly aligned or sizing is impossible.
sizing is impossible should be its own error - probably EMSGSIZE (which would need to be added to kernel/error.rs in its own patch). Also the wording sounds a bit confusing to me, why not say "if the command is larger than MSGQ_MSG_SIZE_MAX"?
Re: [PATCH 3/7] gpu: nova-core: gsp: add checking oversized commands
Quoted 7 lines · Alexandre Courbot
drivers/gpu/nova-core/gsp/cmdq.rs fn read( · line 128
Quoted 4 lines
drivers/gpu/nova-core/gsp/cmdq.rs +4
-0+/// Maximum size of a single GSP command in bytes. +/// +/// A single command can span up to 16 GSP pages. +pub (crate )const MSGQ_MSG_SIZE_MAX :usize =GSP_PAGE_SIZE *16 ;Where does this limitation come from? Is there a value in OpenRM that we can add to the bindings as the source of truth?
This is a GSP protocol level limitation. And yes, there's a constant so I'll add that to the bindings. Thanks!
Quoted 16 lines
drivers/gpu/nova-core/gsp/cmdq.rs fn allocate_command(&mut self, size: usize) -> Result<GspCommand<'_>> { · line 337
Quoted 11 lines
drivers/gpu/nova-core/gsp/cmdq.rs +2
-1+/// Circular buffer of a [`Msgq`]. /// /// This area of memory is to be shared between the driver and the GSP to exchange commands or @@ -329,8 +334,11 @@ fn allocate_command(&mut self, size: usize) -> Result<GspCommand<'_>> {/// # Errors /// /// - `ETIMEDOUT` if space does not become available within the timeout. -/// - `EIO` if the command header is not properly aligned. +/// - `EIO` if the command header is not properly aligned or sizing is impossible.
sizing is impossibleshould be its own error - probablyEMSGSIZE(which would need to be added tokernel/error.rsin its own patch). Also the wording sounds a bit confusing to me, why not say "if the command is larger thanMSGQ_MSG_SIZE_MAX"?
Do you mean in its own patch in this series, or sent as a separate patch to a different tree (e.g. rfl)?
Tangential but I feel like some of the errors in this file are a bit odd, like the existing EIO if the command doesn't fit (which it always should). WDYT?
Alexandre Courbot
maintainerRe: [PATCH 3/7] gpu: nova-core: gsp: add checking oversized commands
Quoted 29 lines · Eliot Courtney
Quoted 7 lines · Alexandre Courbot
drivers/gpu/nova-core/gsp/cmdq.rs fn read( · line 128
Quoted 4 lines
drivers/gpu/nova-core/gsp/cmdq.rs +4
-0+/// Maximum size of a single GSP command in bytes. +/// +/// A single command can span up to 16 GSP pages. +pub (crate )const MSGQ_MSG_SIZE_MAX :usize =GSP_PAGE_SIZE *16 ;Where does this limitation come from? Is there a value in OpenRM that we can add to the bindings as the source of truth?
This is a GSP protocol level limitation. And yes, there's a constant so I'll add that to the bindings. Thanks!
Quoted 16 lines
drivers/gpu/nova-core/gsp/cmdq.rs fn allocate_command(&mut self, size: usize) -> Result<GspCommand<'_>> { · line 337
Quoted 11 lines
drivers/gpu/nova-core/gsp/cmdq.rs +2
-1+/// Circular buffer of a [`Msgq`]. /// /// This area of memory is to be shared between the driver and the GSP to exchange commands or @@ -329,8 +334,11 @@ fn allocate_command(&mut self, size: usize) -> Result<GspCommand<'_>> {/// # Errors /// /// - `ETIMEDOUT` if space does not become available within the timeout. -/// - `EIO` if the command header is not properly aligned. +/// - `EIO` if the command header is not properly aligned or sizing is impossible.
sizing is impossibleshould be its own error - probablyEMSGSIZE(which would need to be added tokernel/error.rsin its own patch). Also the wording sounds a bit confusing to me, why not say "if the command is larger thanMSGQ_MSG_SIZE_MAX"?
Quoted 2 lines
Do you mean in its own patch in this series, or sent as a separate patch to a different tree (e.g. rfl)?
Please send it with this series, it is small enough that we can probably get an Acked-by and merge it through the DRM tree.
Quoted 4 lines
Tangential but I feel like some of the errors in this file are a bit odd, like the existing EIO if the command doesn't fit (which it always should). WDYT?
There is certainly room for improvement - if you see room for improving (or better, removing!) errors, please don't hesitate!
PATCH 4/7 gpu: nova-core: gsp: clarify invariant on command queue
In reply to Eliot CourtneyClarify why using only the first returned slice from allocate_command for the message headers is okay.
--- drivers/gpu/nova-core/gsp/cmdq.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/nova-core/gsp/cmdq.rs +3 -1
@@ -542,7 +542,9 @@ pub(crate) fn send_command<M>(&mut self, bar: &Bar0, command: M) -> Resultlet command_size =Self ::command_size (&command);let dst = self.gsp_mem.allocate_command_with_timeout (command_size)?; -// Extract area for the command itself. +// Extract area for the command itself. The GSP message header and the command header +// together are guaranteed to fit entirely into a single page, so it's ok to only look +// at `dst.contents.0` here. let (cmd, payload_1) =M ::Command ::from_bytes_mut_prefix (dst.contents.0 ).ok_or (EIO )?;// Fill the header and command in-place.
Signature · 1 line
2.53.0
PATCH 5/7 gpu: nova-core: gsp: unconditionally call variable payload handling
In reply to Eliot CourtneyUnconditionally call the variable length payload code, which is a no-op if there is no such payload but could defensively catch some coding errors by e.g. checking that the allocated size is completely filled.
--- drivers/gpu/nova-core/gsp/cmdq.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
drivers/gpu/nova-core/gsp/cmdq.rs +7 -9
@@ -556,16 +556,14 @@ pub(crate) fn send_command<M>(&mut self, bar: &Bar0, command: M) -> Result command.init ().__init (core::ptr::from_mut (cmd))?; } -// Fill the variable-length payload. -if command_size >size_of ::<M ::Command >() { -let mut sbuffer = -SBufferIter ::new_writer ([&mut payload_1[..], &mut dst.contents.1 [..]]); - command.init_variable_payload (&mut sbuffer)?; - -if !sbuffer.is_empty () { -return Err (EIO ); - } +// Fill the variable-length payload, which may be empty. +let mut sbuffer =SBufferIter ::new_writer ([&mut payload_1[..], &mut dst.contents.1 [..]]); + command.init_variable_payload (&mut sbuffer)?; + +if !sbuffer.is_empty () { +return Err (EIO ); } +drop (sbuffer);// Compute checksum now that the whole message is ready. dst.header
Signature · 1 line
2.53.0
PATCH 6/7 gpu: nova-core: gsp: support large RPCs via continuation record
In reply to Eliot CourtneySplits large RPCs if necessary and sends the remaining parts using continuation records. RPCs that do not need continuation records continue to write directly into the command buffer. Ones that do write into a staging buffer first, so there is one copy.
Continuation record for receive is not necessary to support at the moment because those replies do not need to be read and are currently drained by retrying receive_msg on ERANGE.
--- drivers/gpu/nova-core/gsp/cmdq.rs | 47 ++++++++++++- drivers/gpu/nova-core/gsp/commands.rs | 124 ++++++++++++++++++++++++++++++++++ drivers/gpu/nova-core/gsp/fw.rs | 5 ++ 3 files changed, 173 insertions(+), 3 deletions(-)
drivers/gpu/nova-core/gsp/cmdq.rs +44 -3
@@ -29,6 +29,10 @@use crate ::{ driver::Bar0 , gsp::{ + commands::{ +ContinuationRecord , +WrappingCommand ,// + }, fw::{GspMsgElement ,MsgFunction ,
@@ -524,7 +528,7 @@ fn command_size<M>(command: &M) -> usizesize_of ::<M ::Command >() + command.variable_payload_len () } -/// Sends `command` to the GSP. +/// Sends `command` to the GSP, without splitting it. /// /// # Errors ///
@@ -533,13 +537,13 @@ fn command_size<M>(command: &M) -> usize/// written to by its [`CommandToGsp::init_variable_payload`] method. /// /// Error codes returned by the command initializers are propagated as-is. -pub (crate )fn send_command <M >(&mut self, bar: &Bar0 , command:M ) ->Result +fn send_single_command <M >(&mut self, bar: &Bar0 , command: &M ) ->Result where M :CommandToGsp ,// This allows all error types, including `Infallible`, to be used for `M::InitError`. Error :From <M ::InitError >, { -let command_size =Self ::command_size (&command); +let command_size =Self ::command_size (command);let dst = self.gsp_mem.allocate_command_with_timeout (command_size)?;// Extract area for the command itself. The GSP message header and the command header
@@ -590,6 +594,43 @@ pub(crate) fn send_command<M>(&mut self, bar: &Bar0, command: M) -> ResultOk (()) } +fn send_continuation_record (&mut self, bar: &Bar0 , cont: &ContinuationRecord <'_>) ->Result { + self.send_single_command (bar, cont) + } + +/// Sends `command` to the GSP. +/// +/// The command may be split into multiple messages if it is large. +/// +/// # Errors +/// +/// - `ETIMEDOUT` if space does not become available within the timeout. +/// - `EIO` if the variable payload requested by the command has not been entirely +/// written to by its [`CommandToGsp::init_variable_payload`] method. +/// +/// Error codes returned by the command initializers are propagated as-is. +pub (crate )fn send_command <M >(&mut self, bar: &Bar0 , command:M ) ->Result +where +M :CommandToGsp , +Error :From <M ::InitError >, + { +let msg_max_size =MSGQ_MSG_SIZE_MAX -size_of ::<GspMsgElement >(); +let mut wrapped =WrappingCommand ::new (command, msg_max_size)?; + + self.send_single_command (bar, &wrapped)?; + +while let Some (continuation) = wrapped.next_continuation_record () { +dev_dbg! ( + &self.dev, +"GSP RPC: send continuation: size=0x{:x}\n" , +Self ::command_size (&continuation), + ); + self.send_continuation_record (bar, &continuation)?; + } + +Ok (()) + } +/// Wait for a message to become available on the message queue. /// /// This works purely at the transport layer and does not interpret or validate the message
drivers/gpu/nova-core/gsp/commands.rs +124 -0
127 lines not on this page · raw message
drivers/gpu/nova-core/gsp/fw.rs +5 -0
@@ -199,6 +199,7 @@ pub(crate) enum MsgFunction { AllocObject = bindings::NV_VGPU_MSG_FUNCTION_ALLOC_OBJECT, AllocRoot = bindings::NV_VGPU_MSG_FUNCTION_ALLOC_ROOT, BindCtxDma = bindings::NV_VGPU_MSG_FUNCTION_BIND_CTX_DMA, + ContinuationRecord = bindings::NV_VGPU_MSG_FUNCTION_CONTINUATION_RECORD, Free = bindings::NV_VGPU_MSG_FUNCTION_FREE, GetGspStaticInfo = bindings::NV_VGPU_MSG_FUNCTION_GET_GSP_STATIC_INFO, GetStaticInfo = bindings::NV_VGPU_MSG_FUNCTION_GET_STATIC_INFO,
@@ -234,6 +235,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { MsgFunction::AllocObject => write!(f, "ALLOC_OBJECT"), MsgFunction::AllocRoot => write!(f, "ALLOC_ROOT"), MsgFunction::BindCtxDma => write!(f, "BIND_CTX_DMA"), + MsgFunction::ContinuationRecord => write!(f, "CONTINUATION_RECORD"), MsgFunction::Free => write!(f, "FREE"), MsgFunction::GetGspStaticInfo => write!(f, "GET_GSP_STATIC_INFO"), MsgFunction::GetStaticInfo => write!(f, "GET_STATIC_INFO"),
@@ -273,6 +275,9 @@ fn try_from(value: u32) -> Result<MsgFunction> { bindings::NV_VGPU_MSG_FUNCTION_ALLOC_OBJECT => Ok(MsgFunction::AllocObject), bindings::NV_VGPU_MSG_FUNCTION_ALLOC_ROOT => Ok(MsgFunction::AllocRoot), bindings::NV_VGPU_MSG_FUNCTION_BIND_CTX_DMA => Ok(MsgFunction::BindCtxDma), + bindings::NV_VGPU_MSG_FUNCTION_CONTINUATION_RECORD => { + Ok(MsgFunction::ContinuationRecord) + } bindings::NV_VGPU_MSG_FUNCTION_FREE => Ok(MsgFunction::Free), bindings::NV_VGPU_MSG_FUNCTION_GET_GSP_STATIC_INFO => Ok(MsgFunction::GetGspStaticInfo), bindings::NV_VGPU_MSG_FUNCTION_GET_STATIC_INFO => Ok(MsgFunction::GetStaticInfo),
Signature · 1 line
2.53.0
Alexandre Courbot
maintainerRe: [PATCH 6/7] gpu: nova-core: gsp: support large RPCs via continuation record
Quoted 8 lines · Eliot Courtney
Splits large RPCs if necessary and sends the remaining parts using continuation records. RPCs that do not need continuation records continue to write directly into the command buffer. Ones that do write into a staging buffer first, so there is one copy.
Continuation record for receive is not necessary to support at the moment because those replies do not need to be read and are currently drained by retrying
receive_msgon ERANGE.
Do they not need to be read at the moment, or is this a permanent thing? I hope it's the latter. ^_^;
Quoted 49 lines
Signed-off-by Eliot Courtney <[email protected]>--- drivers/gpu/nova-core/gsp/cmdq.rs | 47 ++++++++++++- drivers/gpu/nova-core/gsp/commands.rs | 124 ++++++++++++++++++++++++++++++++++ drivers/gpu/nova-core/gsp/fw.rs | 5 ++ 3 files changed, 173 insertions(+), 3 deletions(-)drivers/gpu/nova-core/gsp/cmdq.rs +7
-3@@ -29,6 +29,10 @@use crate ::{ driver::Bar0 , gsp::{ + commands::{ +ContinuationRecord , +WrappingCommand ,// + }, fw::{GspMsgElement ,MsgFunction ,@@ -524,7 +528,7 @@ fn command_size<M>(command: &M) -> usizesize_of ::<M ::Command >() + command.variable_payload_len () } -/// Sends `command` to the GSP. +/// Sends `command` to the GSP, without splitting it. /// /// # Errors /// @@ -533,13 +537,13 @@ fn command_size<M>(command: &M) -> usize/// written to by its [`CommandToGsp::init_variable_payload`] method. /// /// Error codes returned by the command initializers are propagated as-is. -pub (crate )fn send_command <M >(&mut self, bar: &Bar0 , command:M ) ->Result +fn send_single_command <M >(&mut self, bar: &Bar0 , command: &M ) ->Result where M :CommandToGsp ,// This allows all error types, including `Infallible`, to be used for `M::InitError`. Error :From <M ::InitError >, { -let command_size =Self ::command_size (&command); +let command_size =Self ::command_size (command);let dst = self.gsp_mem.allocate_command_with_timeout (command_size)?;// Extract area for the command itself. The GSP message header and the command header
drivers/gpu/nova-core/gsp/cmdq.rs pub(crate) fn send_command<M>(&mut self, bar: &Bar0, command: M) -> Result · line 599
Quoted 6 lines
drivers/gpu/nova-core/gsp/cmdq.rs +3
-0@@ -590,6 +594,43 @@ pub(crate) fn send_command<M>(&mut self, bar: &Bar0, command: M) -> ResultOk (()) } +fn send_continuation_record (&mut self, bar: &Bar0 , cont: &ContinuationRecord <'_>) ->Result { + self.send_single_command (bar, cont) + }
This one-liner method out of the blue is a bit surprising, and the first reflex is to try to inline it. Its reason to exist should be documented (you mention it in the cover letter, but that's not visible after this patch gets merged), but I'd lean towards removing it and just qualifying its unique caller:
// Turbofish needed because the compiler cannot infer M here.
self.send_single_command::<ContinuationRecord<'_>>(bar, &continuation)?;Fewer moving parts, and it makes it clear on the caller's side that a continuation record is just another command, like the truncated one sent before it.
Quoted 8 lines
drivers/gpu/nova-core/gsp/cmdq.rs +8
-0+ +/// Sends `command` to the GSP. +/// +/// The command may be split into multiple messages if it is large. +/// +/// # Errors +/// +/// - `ETIMEDOUT` if space does not become available within the timeout.
drivers/gpu/nova-core/gsp/cmdq.rs pub(crate) fn send_command<M>(&mut self, bar: &Bar0, command: M) -> Result · line 617
Quoted 10 lines
drivers/gpu/nova-core/gsp/cmdq.rs +10
-0+/// - `EIO` if the variable payload requested by the command has not been entirely +/// written to by its [`CommandToGsp::init_variable_payload`] method. +/// +/// Error codes returned by the command initializers are propagated as-is. +pub (crate )fn send_command <M >(&mut self, bar: &Bar0 , command:M ) ->Result +where +M :CommandToGsp , +Error :From <M ::InitError >, + { +let msg_max_size =MSGQ_MSG_SIZE_MAX -size_of ::<GspMsgElement >();
This could be a const.
drivers/gpu/nova-core/gsp/cmdq.rs pub(crate) fn send_command<M>(&mut self, bar: &Bar0, command: M) -> Result · line 618
Quoted 1 line
drivers/gpu/nova-core/gsp/cmdq.rs +1
-0+let mut wrapped =WrappingCommand ::new (command, msg_max_size)?;
The max_size argument is a bit unfortunate as it is a constant for non-testing purposes. Is there a way we can make testing work with the same limit as real-world use? That would also make our testing closer to reality, on top of making this argument unneeded.
drivers/gpu/nova-core/gsp/cmdq.rs pub(crate) fn send_command<M>(&mut self, bar: &Bar0, command: M) -> Result · line 629
Quoted 11 lines
drivers/gpu/nova-core/gsp/cmdq.rs +11
-0+ + self.send_single_command (bar, &wrapped)?; + +while let Some (continuation) = wrapped.next_continuation_record () { +dev_dbg! ( + &self.dev, +"GSP RPC: send continuation: size=0x{:x}\n" , +Self ::command_size (&continuation), + ); + self.send_continuation_record (bar, &continuation)?; + }
Btw, can we recover if a split message fails between two continuation records? I suspect the GSP will notice that the next message is not the expected continuation record and recover from there?
Quoted 16 lines
drivers/gpu/nova-core/gsp/cmdq.rs +4
-0+ +Ok (()) + } +/// Wait for a message to become available on the message queue. /// /// This works purely at the transport layer and does not interpret or validate the message drivers/gpu/nova-core/gsp/commands.rs +1
-0@@ -242,3 +242,127 @@ pub(crate) fn get_gsp_info(cmdq: &mut Cmdq, bar: &Bar0) -> Result<GetGspStaticIn } } } +
drivers/gpu/nova-core/gsp/commands.rs pub(crate) fn get_gsp_info(cmdq: &mut Cmdq, bar: &Bar0) -> Result<GetGspStaticIn · line 255
Quoted 10 lines
drivers/gpu/nova-core/gsp/commands.rs +10
-0+#[derive( Zeroable )] +pub (crate )struct Empty {} + +// SAFETY: `Empty` is a zero-sized type with no bytes, therefore it trivially has no uninitialized +// bytes. +unsafe impl AsBytes for Empty {} + +// SAFETY: `Empty` is a zero-sized type with no bytes, therefore it trivially has no uninitialized +// bytes. +unsafe impl FromBytes for Empty {}
Since commit 209c70953aa (on master, but not drm-rust-next yet) you can just use () as the Command type - that will let you remove Empty entirely. You'll then need to invoke pin_init::init_zeroed() in init.
Quoted 30 lines
drivers/gpu/nova-core/gsp/commands.rs +30
-0+ +/// The `ContinuationRecord` command. +pub (crate )struct ContinuationRecord <'a> { + data: &'a [u8 ], +} + +impl <'a>ContinuationRecord <'a> { +/// Creates a new `ContinuationRecord` command with the given data. +pub (crate )fn new (data: &'a [u8 ]) ->Self { +Self { data } + } +} + +impl <'a>CommandToGsp for ContinuationRecord <'a> { +const FUNCTION :MsgFunction =MsgFunction ::ContinuationRecord ; +type Command =Empty ; +type InitError =Infallible ; + +fn init (&self) ->impl Init <Self ::Command ,Self ::InitError > { +Empty ::init_zeroed () + } + +fn variable_payload_len (&self) ->usize { + self.data.len () + } + +fn init_variable_payload ( + &self, + dst: &mut SBufferIter <core::array::IntoIter <&mut [u8 ],2 >>, + ) ->Result {
drivers/gpu/nova-core/gsp/commands.rs pub(crate) fn get_gsp_info(cmdq: &mut Cmdq, bar: &Bar0) -> Result<GetGspStaticIn · line 295
Quoted 10 lines
drivers/gpu/nova-core/gsp/commands.rs +10
-0+ dst.write_all (self.data) + } +} + +/// Wrapper that splits a command across continuation records if needed. +pub (crate )struct WrappingCommand <C :CommandToGsp > { + inner:C , + offset:usize , + max_size:usize , + staging:KVVec <u8 >,
Since it is conditionally-used, staging should be an Option instead of assuming an empty state means it is unused. But hold on, I think we can do without any sort of conditional here.
drivers/gpu/nova-core/gsp/commands.rs pub(crate) fn get_gsp_info(cmdq: &mut Cmdq, bar: &Bar0) -> Result<GetGspStaticIn · line 296
Quoted 1 line
drivers/gpu/nova-core/gsp/commands.rs +1
-0+}
This deserves more doccomments, including on its members. But I would also like to entertain a slightly different design.
In this patch, WrappingCommand is always used, including for messages that don't need to be truncated. While the overhead is arguably negligible, this makes split messages pass as the norm, while they are a very rare exception.
Also WrappingCommand now becomes both a command and a provider of other commands, which I find hard to wrap (haha) my head around, and forces you to pass the command by reference in send_single_command because you need to use it again afterwards. The name is also not very descriptive (why does it wrap?). How about this instead:
send_command is the central path that all commands take, so it is the right place to check whether we need to use continuation records. If we don't, then we just send the command as-is, as we do today.
If we need to split, we do it through a private method of Cmdq that consumes the command and returns a tuple (SplitCommand<M>, ContinuationRecords)
SplitCommand<M> can be a wrapper around the original command, but that initializes the truncated part of its variable payload.
ContinuationRecords implements Iterator<Item = ContinuationRecord>. ContinuationRecord works mostly like your current version, except it owns its data (yes, more allocations, but they're smaller so the allocator might actually appreciate).
Since SplitCommand is only used when there is actually a split needed, staging does not need an empty state anymore, and the code of each type becomes simpler.
By doing so, you also don't need to pass the command by reference in send_single_command anymore.
drivers/gpu/nova-core/gsp/commands.rs pub(crate) fn get_gsp_info(cmdq: &mut Cmdq, bar: &Bar0) -> Result<GetGspStaticIn · line 300
Quoted 4 lines
drivers/gpu/nova-core/gsp/commands.rs +4
-0+ +impl <C :CommandToGsp >WrappingCommand <C > +where +Error :From <C ::InitError >,
This where is unneeded.
Re: [PATCH 6/7] gpu: nova-core: gsp: support large RPCs via continuation record
Quoted 18 lines · Alexandre Courbot
Quoted 7 lines
drivers/gpu/nova-core/gsp/cmdq.rs +7
-0+/// Sends `command` to the GSP. +/// +/// The command may be split into multiple messages if it is large. +/// +/// # Errors +/// +/// - `ETIMEDOUT` if space does not become available within the timeout. drivers/gpu/nova-core/gsp/cmdq.rs pub(crate) fn send_command<M>(&mut self, bar: &Bar0, command: M) -> Result · line 617
Quoted 10 lines
drivers/gpu/nova-core/gsp/cmdq.rs +10
-0+/// - `EIO` if the variable payload requested by the command has not been entirely +/// written to by its [`CommandToGsp::init_variable_payload`] method. +/// +/// Error codes returned by the command initializers are propagated as-is. +pub (crate )fn send_command <M >(&mut self, bar: &Bar0 , command:M ) ->Result +where +M :CommandToGsp , +Error :From <M ::InitError >, + { +let msg_max_size =MSGQ_MSG_SIZE_MAX -size_of ::<GspMsgElement >();
Quoted 8 lines
This could be a const.
Quoted 1 line
+ let mut wrapped =
WrappingCommand::new(command, msg_max_size)?;The
max_sizeargument is a bit unfortunate as it is a constant for non-testing purposes. Is there a way we can make testing work with the same limit as real-world use? That would also make our testing closer to reality, on top of making this argument unneeded.
Yeah good point, will do.
Quoted 16 lines
drivers/gpu/nova-core/gsp/cmdq.rs pub(crate) fn send_command<M>(&mut self, bar: &Bar0, command: M) -> Result · line 629
Quoted 12 lines
drivers/gpu/nova-core/gsp/cmdq.rs +11
-0+ + self.send_single_command (bar, &wrapped)?; + +while let Some (continuation) = wrapped.next_continuation_record () { +dev_dbg! ( + &self.dev, +"GSP RPC: send continuation: size=0x{:x}\n" , +Self ::command_size (&continuation), + ); + self.send_continuation_record (bar, &continuation)?; + }Btw, can we recover if a split message fails between two continuation records? I suspect the GSP will notice that the next message is not the expected continuation record and recover from there?
IIUC neither openrm or nouveau can recover from a failure during sending continuation records. What failure mode do you see happening that we could recover from?
Quoted 7 lines
Quoted 7 lines
drivers/gpu/nova-core/gsp/commands.rs +7
-0+#[derive( Zeroable )] +pub (crate )struct Empty {} + +// SAFETY: `Empty` is a zero-sized type with no bytes, therefore it trivially has no uninitialized +// bytes. +unsafe impl AsBytes for Empty {} +
Quoted 8 lines
drivers/gpu/nova-core/gsp/commands.rs pub(crate) fn get_gsp_info(cmdq: &mut Cmdq, bar: &Bar0) -> Result<GetGspStaticIn · line 255
Quoted 3 lines
drivers/gpu/nova-core/gsp/commands.rs +3
-0+// SAFETY: `Empty` is a zero-sized type with no bytes, therefore it trivially has no uninitialized +// bytes. +unsafe impl FromBytes for Empty {}Since commit
209c70953aa(on master, but not drm-rust-next yet) you can just use()as theCommandtype - that will let you removeEmptyentirely. You'll then need to invokepin_init::init_zeroed()ininit.
Great!
Quoted 36 lines
Quoted 36 lines
drivers/gpu/nova-core/gsp/commands.rs +36
-0+ +/// The `ContinuationRecord` command. +pub (crate )struct ContinuationRecord <'a> { + data: &'a [u8 ], +} + +impl <'a>ContinuationRecord <'a> { +/// Creates a new `ContinuationRecord` command with the given data. +pub (crate )fn new (data: &'a [u8 ]) ->Self { +Self { data } + } +} + +impl <'a>CommandToGsp for ContinuationRecord <'a> { +const FUNCTION :MsgFunction =MsgFunction ::ContinuationRecord ; +type Command =Empty ; +type InitError =Infallible ; + +fn init (&self) ->impl Init <Self ::Command ,Self ::InitError > { +Empty ::init_zeroed () + } + +fn variable_payload_len (&self) ->usize { + self.data.len () + } + +fn init_variable_payload ( + &self, + dst: &mut SBufferIter <core::array::IntoIter <&mut [u8 ],2 >>, + ) ->Result { + dst.write_all (self.data) + } +} + +/// Wrapper that splits a command across continuation records if needed. +pub (crate )struct WrappingCommand <C :CommandToGsp > {
Quoted 8 lines
drivers/gpu/nova-core/gsp/commands.rs pub(crate) fn get_gsp_info(cmdq: &mut Cmdq, bar: &Bar0) -> Result<GetGspStaticIn · line 295
Quoted 4 lines
drivers/gpu/nova-core/gsp/commands.rs +4
-0+ inner: C, + offset: usize, + max_size: usize, + staging: KVVec<u8>,Since it is conditionally-used,
stagingshould be anOptioninstead of assuming an empty state means it is unused. But hold on, I think we can do without any sort of conditional here.
Yeah you are right. I had used empty here since it makes next_continuation_record here more consistent in that it doesn't need to check for None then for length anyway, but it's special casing in init_variable_payload in a very optiony way regardless.
I reckon using Option we could put offset in there as well in a tuple, since if we want to use Option to avoid the special case of empty staging, we might as well use it to avoid having a conceptually useless offset field too.
Quoted 25 lines
Quoted 2 lines
+}
This deserves more doccomments, including on its members. But I would also like to entertain a slightly different design.
In this patch,
WrappingCommandis always used, including for messages that don't need to be truncated. While the overhead is arguably negligible, this makes split messages pass as the norm, while they are a very rare exception.Also
WrappingCommandnow becomes both a command and a provider of other commands, which I find hard to wrap (haha) my head around, and forces you to pass the command by reference insend_single_commandbecause you need to use it again afterwards. The name is also not very descriptive (why does it wrap?). How about this instead:
send_commandis the central path that all commands take, so it is the right place to check whether we need to use continuation records. If we don't, then we just send the command as-is, as we do today.If we need to split, we do it through a private method of
Cmdqthat consumes the command and returns a tuple(SplitCommand<M>, ContinuationRecords)
Quoted 7 lines
SplitCommand<M>can be a wrapper around the original command, but that initializes the truncated part of its variable payload.
ContinuationRecordsimplementsIterator<Item = ContinuationRecord>.ContinuationRecordworks mostly like your current version, except it owns its data (yes, more allocations, but they're smaller so the allocator might actually appreciate).
Is it really the case that more, smaller allocations is better if we are using KVVec rather than KVec? It feels like it would have overhead/fragmentation to me. Eager to learn if this is wrong though
Quoted 7 lines
Since
SplitCommandis only used when there is actually a split needed,stagingdoes not need an empty state anymore, and the code of each type becomes simpler.By doing so, you also don't need to pass the command by reference in
send_single_commandanymore.
I considered putting the continuation record logic inside cmdq, but I feel it's nicer to keep it out of the core command queue logic as much as possible, because it feels a bit noisy to have in the cmdq which hopefully can just concentrate on sending messages, not how those messages get made or how/when they get split.
I agree that it is a bit odd to have a command that also provides extra commands. By the way I considered doing an Iterator thing for WrappingCommand, but felt like it would introduce more complexity than it was worth and make it more confusing on the command that also produces commands front.
Another benefit to pulling the logic out of command queue is that it makes it a lot easier to test AFAICT. If we want to test the splitting, if the logic is a private method in the command queue that feels like it might end up more as an integration test.
But if we just want to avoid having a command which also produces commands, what if we created a separate type to hold the split state / decision and it would return a SplitCommand plus either an iterator or the iterator-like next_continuation_record, while being testable separately. WDYT?
Quoted 7 lines
drivers/gpu/nova-core/gsp/commands.rs pub(crate) fn get_gsp_info(cmdq: &mut Cmdq, bar: &Bar0) -> Result<GetGspStaticIn · line 300
Quoted 5 lines
drivers/gpu/nova-core/gsp/commands.rs +4
-0+ +impl <C :CommandToGsp >WrappingCommand <C > +where +Error :From <C ::InitError >,This
whereis unneeded.
Alexandre Courbot
maintainerRe: [PATCH 6/7] gpu: nova-core: gsp: support large RPCs via continuation record
On Wed Feb 18, 2026 at 6:00 PM JST, Eliot Courtney wrote:
<snip>
Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
drivers/gpu/nova-core/gsp/cmdq.rs +7
-0+ + self.send_single_command (bar, &wrapped)?; + +while let Some (continuation) = wrapped.next_continuation_record () { +dev_dbg! ( + &self.dev, +"GSP RPC: send continuation: size=0x{:x}\n" ,Quoted 8 lines
drivers/gpu/nova-core/gsp/cmdq.rs pub(crate) fn send_command<M>(&mut self, bar: &Bar0, command: M) -> Result · line 629
Quoted 4 lines
drivers/gpu/nova-core/gsp/cmdq.rs +4
-0+ Self::command_size(&continuation), + ); + self.send_continuation_record (bar, &continuation)?; + }Btw, can we recover if a split message fails between two continuation records? I suspect the GSP will notice that the next message is not the expected continuation record and recover from there?
Quoted 3 lines
IIUC neither openrm or nouveau can recover from a failure during sending continuation records. What failure mode do you see happening that we could recover from?
None in particular, I just want to confirm we have thought about it. If OpenRM considers this a catastrophic failure, doing the same in Nova is fair enough.
<snip>
Quoted 50 lines
Quoted 36 lines
Quoted 36 lines
drivers/gpu/nova-core/gsp/commands.rs +36
-0+ +/// The `ContinuationRecord` command. +pub (crate )struct ContinuationRecord <'a> { + data: &'a [u8 ], +} + +impl <'a>ContinuationRecord <'a> { +/// Creates a new `ContinuationRecord` command with the given data. +pub (crate )fn new (data: &'a [u8 ]) ->Self { +Self { data } + } +} + +impl <'a>CommandToGsp for ContinuationRecord <'a> { +const FUNCTION :MsgFunction =MsgFunction ::ContinuationRecord ; +type Command =Empty ; +type InitError =Infallible ; + +fn init (&self) ->impl Init <Self ::Command ,Self ::InitError > { +Empty ::init_zeroed () + } + +fn variable_payload_len (&self) ->usize { + self.data.len () + } + +fn init_variable_payload ( + &self, + dst: &mut SBufferIter <core::array::IntoIter <&mut [u8 ],2 >>, + ) ->Result { + dst.write_all (self.data) + } +} + +/// Wrapper that splits a command across continuation records if needed. +pub (crate )struct WrappingCommand <C :CommandToGsp > {Quoted 8 lines
drivers/gpu/nova-core/gsp/commands.rs pub(crate) fn get_gsp_info(cmdq: &mut Cmdq, bar: &Bar0) -> Result<GetGspStaticIn · line 295
Quoted 4 lines
drivers/gpu/nova-core/gsp/commands.rs +4
-0+ inner: C, + offset: usize, + max_size: usize, + staging: KVVec<u8>,Since it is conditionally-used,
stagingshould be anOptioninstead of assuming an empty state means it is unused. But hold on, I think we can do without any sort of conditional here.Yeah you are right. I had used empty here since it makes
next_continuation_recordhere more consistent in that it doesn't need to check for None then for length anyway, but it's special casing ininit_variable_payloadin a very optiony way regardless.
Quoted 4 lines
I reckon using Option we could put
offsetin there as well in a tuple, since if we want to use Option to avoid the special case of emptystaging, we might as well use it to avoid having a conceptually uselessoffsetfield too.
All the more reason not to handle the non-continuation case in this type. Let's keep it straightforward and responsible for only doing the splitting of messages - if we indeed need another type to be able to handle both cases, we can then compose one using an enum.
Quoted 29 lines
Quoted 29 lines
Quoted 3 lines
+}
This deserves more doccomments, including on its members. But I would also like to entertain a slightly different design.
In this patch,
WrappingCommandis always used, including for messages that don't need to be truncated. While the overhead is arguably negligible, this makes split messages pass as the norm, while they are a very rare exception.Also
WrappingCommandnow becomes both a command and a provider of other commands, which I find hard to wrap (haha) my head around, and forces you to pass the command by reference insend_single_commandbecause you need to use it again afterwards. The name is also not very descriptive (why does it wrap?). How about this instead:
send_commandis the central path that all commands take, so it is the right place to check whether we need to use continuation records. If we don't, then we just send the command as-is, as we do today.If we need to split, we do it through a private method of
Cmdqthat consumes the command and returns a tuple(SplitCommand<M>, ContinuationRecords)
SplitCommand<M>can be a wrapper around the original command, but that initializes the truncated part of its variable payload.
Quoted 8 lines
Quoted 4 lines
ContinuationRecordsimplementsIterator<Item = ContinuationRecord>.ContinuationRecordworks mostly like your current version, except it owns its data (yes, more allocations, but they're smaller so the allocator might actually appreciate).Is it really the case that more, smaller allocations is better if we are using KVVec rather than KVec? It feels like it would have overhead/fragmentation to me. Eager to learn if this is wrong though
Ah, for some reason I read KVec here. KVVec is fine, and thinking about it, we don't even need one allocation per continuation record: just one for the main command, and one for the continuation records iterator type, which the individual ContinuationRecords can refer to using a slice (basically, your current design).
Quoted 6 lines
Quoted 6 lines
Since
SplitCommandis only used when there is actually a split needed,stagingdoes not need an empty state anymore, and the code of each type becomes simpler.
Quoted 8 lines
Quoted 2 lines
By doing so, you also don't need to pass the command by reference in
send_single_commandanymore.I considered putting the continuation record logic inside cmdq, but I feel it's nicer to keep it out of the core command queue logic as much as possible, because it feels a bit noisy to have in the cmdq which hopefully can just concentrate on sending messages, not how those messages get made or how/when they get split.
Fair enough. Are you suggesting that we use a new type instead of a Cmdq function? If so, that looks good to me, it's basically turning the tuple return value I suggested into its own type with a constructor. That's arguably cleaner actually.
Quoted 6 lines
I agree that it is a bit odd to have a command that also provides extra commands. By the way I considered doing an Iterator thing for WrappingCommand, but felt like it would introduce more complexity than it was worth and make it more confusing on the command that also produces commands front.
Ah, with the ContinuationRecords borrowing from self it is difficult to implement Iterator on WrappingCommand indeed. The current method is fine, it's preferable to doing another copy and thankfully we don't need the full power of iterators here.
Quoted 11 lines
Another benefit to pulling the logic out of command queue is that it makes it a lot easier to test AFAICT. If we want to test the splitting, if the logic is a private method in the command queue that feels like it might end up more as an integration test.
But if we just want to avoid having a command which also produces commands, what if we created a separate type to hold the split state / decision and it would return a SplitCommand plus either an iterator or the iterator-like
next_continuation_record, while being testable separately. WDYT?
So basically, the simplified SplitCommand and its continuation records, which we wrap into an enum holding the decision of whether the command is split or not? That sounds fine.
I'd like to also keep the continuation records outside of SplitCommand, as this will let us pass the commands by value to send_command, which is a detail I like as it ensures we cannot send the same command twice without explicitly cloning it before.
PATCH 7/7 gpu: nova-core: gsp: add tests for WrappingCommand
In reply to Eliot CourtneyAdd tests for WrappingCommand. They cover boundary conditions at the split points to make sure the right number of continuation records are made. They also check that the data concatenated is correct.
--- drivers/gpu/nova-core/gsp/commands.rs | 123 ++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+)
drivers/gpu/nova-core/gsp/commands.rs +123 -0
@@ -366,3 +366,126 @@ fn init_variable_payload( } } } + +#[kunit_tests(nova_core_gsp_commands)] +mod tests { +use super ::*; + +struct TestPayload { + data:KVVec <u8 >, + } + +impl TestPayload { +fn generate_pattern (len:usize ) ->Result <KVVec <u8 >> { +let mut data =KVVec ::with_capacity (len,GFP_KERNEL )?; +for iin 0 ..len { + data.push (ias u8 ,GFP_KERNEL )?; + } +Ok (data) + } + +fn new (len:usize ) ->Result <Self > { +Ok (Self { + data:Self ::generate_pattern (len)?, + }) + } + } + +impl CommandToGsp for TestPayload { +const FUNCTION :MsgFunction =MsgFunction ::Nop ; +type Command =Empty ; +type InitError =Infallible ; + +fn init (&self) ->impl Init <Self ::Command ,Self ::InitError > { +Empty ::init_zeroed () + } + +fn variable_payload_len (&self) ->usize { + self.data.len () + } + +fn init_variable_payload ( + &self, + dst: &mut SBufferIter <core::array::IntoIter <&mut [u8 ],2 >>, + ) ->Result { + dst.write_all (self.data.as_slice ()) + } + } + +fn read_payload (cmd: &impl CommandToGsp ) ->Result <KVVec <u8 >> { +let len = cmd.variable_payload_len (); +let mut buf =KVVec ::from_elem (0u8 , len,GFP_KERNEL )?; +let mut sbuf =SBufferIter ::new_writer ([buf.as_mut_slice (), &mut []]); + cmd.init_variable_payload (&mut sbuf)?; +drop (sbuf); +Ok (buf) + } + +struct WrappingCommandTest { + payload_size:usize , + max_size:usize , + num_continuations:usize , + } + +fn check_wrapping (t:WrappingCommandTest ) ->Result { +let mut wrapped =WrappingCommand ::new (TestPayload ::new (t.payload_size)?, t.max_size)?; + +let mut buf =read_payload (&wrapped)?; +assert! (buf.len () <= t.max_size); + +let mut num_continuations =0 ; +while let Some (cont) = wrapped.next_continuation_record () { +let payload =read_payload (&cont)?; +assert! (payload.len () <= t.max_size); + buf.extend_from_slice (&payload,GFP_KERNEL )?; + num_continuations +=1 ; + } + +assert_eq! (num_continuations, t.num_continuations); +assert_eq! ( + buf.as_slice (), +TestPayload ::generate_pattern (t.payload_size)?.as_slice () + ); +Ok (()) + } + +#[test] +fn wrapping_command () ->Result { +check_wrapping (WrappingCommandTest { + payload_size:0 , + max_size:50 , + num_continuations:0 , + })?; +check_wrapping (WrappingCommandTest { + payload_size:50 , + max_size:50 , + num_continuations:0 , + })?; +check_wrapping (WrappingCommandTest { + payload_size:100 , + max_size:50 , + num_continuations:1 , + })?; +check_wrapping (WrappingCommandTest { + payload_size:101 , + max_size:100 , + num_continuations:1 , + })?; +check_wrapping (WrappingCommandTest { + payload_size:150 , + max_size:100 , + num_continuations:1 , + })?; +check_wrapping (WrappingCommandTest { + payload_size:300 , + max_size:100 , + num_continuations:2 , + })?; +check_wrapping (WrappingCommandTest { + payload_size:350 , + max_size:100 , + num_continuations:3 , + })?; +Ok (()) + } +}
Signature · 1 line
2.53.0
Quoted 2 lines · Eliot Courtney
GSP commands over 16 pages need to be sent using "continuation records" which essentially means splitting the payload over multiple commands.
Let's please include rust-for-linux on Cc for Nova patches, for a while longer at least.
thanks,
John Hubbard
Quoted 37 lines
This series adds a command type
ContinuationRecordwhich just writes its header and whatever payload it is given. It also adds a typeWrappingCommandwhich supports splitting a large RPC into smaller ones.The send pathway uses
WrappingCommandto send all commands, but if the command fits into 16 pages, it still writes directly into the command queue. If it is larger than 16 pages and needs continuation records, it writes into a staging buffer, so there is one copy.This patch series uses EIO for mis-sized commands to be consistent with the rest of the code.
Patch 6 introduces a single helper
send_continuation_record. This is because the compiler can't properly infer the types without this.Signed-off-by Eliot Courtney <[email protected]>---
Eliot Courtney (7):
gpu: nova-core: gsp: sort MsgFunction variants alphabetically
gpu: nova-core: gsp: add mechanism to wait for space on command queue
gpu: nova-core: gsp: add checking oversized commands
gpu: nova-core: gsp: clarify invariant on command queue
gpu: nova-core: gsp: unconditionally call variable payload handling
gpu: nova-core: gsp: support large RPCs via continuation record
gpu: nova-core: gsp: add tests for WrappingCommanddrivers/gpu/nova-core/gsp/cmdq.rs | 113 ++++++++++++++-- drivers/gpu/nova-core/gsp/commands.rs | 247 ++++++++++++++++++++++++++++++++++ drivers/gpu/nova-core/gsp/fw.rs | 102 +++++++------- 3 files changed, 401 insertions(+), 61 deletions(-)---
base-commit:cea7b66a80412e2a5b74627b89ae25f1d0110a4b
change-id: 20260203-cmdq-continuation-b99f3d5966c3Best regards,