[PATCH 3/5] gpu: nova-core: gsp: cmdq: reject GMC messages with inconsistent lengths
From: Alexandre Courbot
Date: Thu Dec 03 2026 - 23:16:54 EST
From: John Hubbard <jhubbard@xxxxxxxxxx>
GSP-RM writes the payload length of a GMC message twice, in the queue
element header and in the GMC API header. The driver currently only
fails when the element is too short for the payload length in the GMC
API header.
The two lengths must be equal, so fail with EIO when they differ.
Signed-off-by: John Hubbard <jhubbard@xxxxxxxxxx>
Signed-off-by: Alexandre Courbot <acourbot@xxxxxxxxxx>
---
drivers/gpu/nova-core/gsp/cmdq/gmc.rs | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
diff --git a/drivers/gpu/nova-core/gsp/cmdq/gmc.rs b/drivers/gpu/nova-core/gsp/cmdq/gmc.rs
index 0ddd319e15b7..6565a8fb0e96 100644
--- a/drivers/gpu/nova-core/gsp/cmdq/gmc.rs
+++ b/drivers/gpu/nova-core/gsp/cmdq/gmc.rs
@@ -204,13 +204,12 @@ pub(crate) struct GmcMessage<'a> {
}
impl<'a> GmcMessage<'a> {
- /// Validates the GMC layer of `element` and returns its GMC API header and its contents trimmed
- /// down to the GMC payload.
+ /// Validates the GMC layer of `element` and returns its GMC API header and its contents.
///
/// # Errors
///
- /// - `EIO` if the element is shorter than the GMC API header, or than the payload length
- /// advertised by the GMC API header.
+ /// - `EIO` if the element is shorter than the GMC API header, or if the GMC API header and
+ /// queue element header advertise different payload lengths.
pub(super) fn parse(dev: &device::Device, element: GspMessage<'a>) -> Result<GmcMessage<'a>> {
static_assert!(
size_of::<QueueElementHeader>() + size_of::<GmcApiHeader>() <= GSP_PAGE_SIZE
@@ -235,9 +234,22 @@ pub(super) fn parse(dev: &device::Device, element: GspMessage<'a>) -> Result<Gmc
payload_size,
);
+ // GSP-RM writes both lengths from the same payload, so a difference means that one of the
+ // two headers is corrupt, and the driver cannot know which.
+ let contents_len = slice_1.len() + slice_2.len();
+ if contents_len != payload_size {
+ dev_err!(
+ dev,
+ "GSP GMC: payload is {} bytes in the queue element header but {} in the GMC API header\n",
+ contents_len,
+ payload_size,
+ );
+ return Err(EIO);
+ }
+
Ok(GmcMessage {
header: gmc_header,
- contents: super::trim_message_slice((slice_1, slice_2), payload_size)?,
+ contents: (slice_1, slice_2),
})
}
--
2.56.1