From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.62.38 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796028158; b=z51Os3NHX1iSkzqMIsqfE4naB0/GzuLPtMF4JYmNDF2/W/JEZzUQxcb3aKAJXJEhP4Bl or2aRwr1aiCFeCmjPbJzuG6GYQ75VcivyO72qYSdL+woqe0C9rPYgrO6sw9Gw+efDGENz tOnNQwHYV+7BRBYbEeS3o3l22dg74Su6GH+d3g2PD9M58Yxc/wXlfl5g+ndqovnp23T7I 9ly5qqKUcHmJVZoaBwAjDUYC4dJeQoC27FWOTVgCHrF1Zv0rDzgAqNKUepM+b6Maj0M3x DZ37k06beQwQvKfomL30Shi7msK2aEg8/YS3MOaKkX0HlttXhZblysyZ8FEa90U+3NQ== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796028158; h=DMARC-Filter:DKIM-Signature:Received:Received:From:Date:Subject: Content-Type:Content-Transfer-Encoding:Message-Id:References: In-Reply-To:To:Cc:X-Mailer:X-ClientProxiedBy:MIME-Version: X-MS-PublicTrafficType:X-MS-TrafficTypeDiagnostic: X-MS-Office365-Filtering-Correlation-Id:X-MS-Exchange-SenderADCheck: X-MS-Exchange-AntiSpam-Relay:X-Microsoft-Antispam: X-Microsoft-Antispam-Message-Info:X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0: X-MS-Exchange-AntiSpam-MessageData-1:X-OriginatorOrg: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=lq7znzVK2L1/J2WsZnYDDaP7uc+Ql1+DkIdBd6iAFQQ=; b=BnfEwmHIrmwoKePNu3orsD6iWrVTRqZL8Htjd/yvet5j/PkLff2bSKpd0pfnmdwR7F8C cHtg8oXTWnKoR+A+2glcET8E9o8ZQys6jXPoVwFqwxUlioEaaD7pRjyrKXqlwRr3O1PHO /jdRjvpjFmoeLdfiuuwxCeF3P7yRv7dg25AjhK97Fo6n2WHIzvZF26z1m1SjQ+wVR/zM3 ynVpB/2Vmya35swngw6l3APlWrXbcql8s7YQJUqpEmcsSc6ebs9RiH7LxDBoke7kVGNxJ Rt83hHFcvMqYvy4ehuDkcVWpZKmTVUvoFPnyeyu/dZa5mnjT9jJ5llQUQ/sRwAZqBIg== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=QNT1yKRW; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.62.38 Received: from DM5PR21CU001.outbound.protection.outlook.com (mail-centralusazon11011038.outbound.protection.outlook.com [52.101.62.38]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 34AF1606A32A for ; Mon, 30 Nov 2026 08:42:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 34AF1606A32A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=QNT1yKRW ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=t5NGc4CJ6HMPk911MR/755fwuhiFxuXyuzkuM1BYjRgZSxlNZdC3H4NZN7nD7iFdNGQwFiz6NV/A4BNC41yH01IsmBuLqbpXCLt4fqF2237+UmXn6XI0LlSSk2cfdaBuqRU1VbQxEU2VG90QPiOI4q9yzvBr4/5XhiT06k1hw+VxLU3J7qSCkW1Iu+WqzXkRfm8WjXq1XT1wb7XFf91jAT5D1LlSb+AgTTAx2z1NJEDYvxjehemGKuhlRKQKb41cqCQGj4VgJcvf2PpmCikU7mwHDmdnU5BqWpXZIdZX2D9sPwjTV3uflRzvJV7rjAkKQIWZ11Gh2r1wWFGM2zOXoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=lq7znzVK2L1/J2WsZnYDDaP7uc+Ql1+DkIdBd6iAFQQ=; b=CWoTjPxFDaFs0xZLvte7lBxmFLnTMdbYPPve69ilYyOHiLilPDku7OVTKyy/0L8teRgi10LYKHhyfcGvTDVOLRJVz8MDPdvNyDpxa1XS8fmEs4STC4Dx6AnrHvalyzdLEIXvdXYwHAyi1CACYN9dBUZP3g/PNn+Y33NRYlIpex25XVjcBP84cz9ljXrXuARNI53vP8ZcRXEWc0ZgFt7KyWCgpev/DXhVraYaROKOj/Xi9i62YzKAHsV1yQOfWawT+gHVJAU/7kQmy3cRzM6Rqm8m4ZynAo1n0T83RIC/D1osoPazjvCW4sEo19VXxSDWyKWsNRaoUTIK5EZM6MnKjg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lq7znzVK2L1/J2WsZnYDDaP7uc+Ql1+DkIdBd6iAFQQ=; b=QNT1yKRWM5g0P0WYA94T2oCoFjEwIhBdVmrpu/IjNCvqEQJfTe/rtrdseZSqF399K4E7CeIrg/UfgYEhJJLOiGGlbeJhPDsozEJitf0J4dg8CWVNP8hGOg0riYn8m7pwG/Jccc/PXCWKKrlssWo23Ct9EeMj3fPx+/yin63mVod2qh0qmuhQQxm/uSQU77U0PCXq7FJ4yHZxBZHzsPGFckoSRJRwrlrbU/0juIo/dGfXU9xkXVJ6evswpsA5N1SE3b5kTAkZ8Akn0puYFHGulA3/YOPqOWLXRwGqfjPtC2ADWhSr6lFILdEIQaZZpKHc6wa0iXIpl6K5sjqAXysN4Q== Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from MW4PR12MB6873.namprd12.prod.outlook.com (2603:10b6:303:20c::17) by DS7PPF5A996E821.namprd12.prod.outlook.com (2603:10b6:f:fc02::946) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.13; Mon, 30 Nov 2026 08:42:36 +0000 Received: from MW4PR12MB6873.namprd12.prod.outlook.com ([fe80::a338:bd2c:3a38:ece1]) by MW4PR12MB6873.namprd12.prod.outlook.com ([fe80::a338:bd2c:3a38:ece1%5]) with mapi id 15.21.0662.001; Mon, 30 Nov 2026 08:42:35 +0000 From: Alexandre Courbot Date: Mon, 30 Nov 2026 17:42:27 +0900 Subject: [PATCH v3 01/11] gpu: nova-core: gsp: add the r000 queue element header Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261130-nova-r000-staging-v3-1-55aceca8e958@nvidia.com> References: <20261130-nova-r000-staging-v3-0-55aceca8e958@nvidia.com> In-Reply-To: <20261130-nova-r000-staging-v3-0-55aceca8e958@nvidia.com> To: Danilo Krummrich , Alice Ryhl , David Airlie , Simona Vetter Cc: John Hubbard , Alistair Popple , Timur Tabi , Eliot Courtney , Zhi Wang , nova-gpu@lists.linux.dev, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Alexandre Courbot X-Mailer: b4 0.16.0 X-ClientProxiedBy: TY4P286CA0053.JPNP286.PROD.OUTLOOK.COM (2603:1096:405:36e::18) To MW4PR12MB6873.namprd12.prod.outlook.com (2603:10b6:303:20c::17) X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MW4PR12MB6873:EE_|DS7PPF5A996E821:EE_ X-MS-Office365-Filtering-Correlation-Id: 476da6f1-0f6b-4572-1713-08df4ebde1f3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|1800799024|376014|23010399003|10070799003|10067099003|56012099006|261026121527099003|261026140227099003|261022115727099003|261022105027099003|261028144727099003|261021123027099003|261021121427099003|261102123227099003|261009220027099003|261009221727099003|261009223327099003|261009223027099003|261009221227099003|18002099003|22082099003|11063799006|3023799007; X-Microsoft-Antispam-Message-Info: MvAd8On/R/GlVKCJExpOxz/Hg4bak+sgH7V8JY5HzW+4f583cSxZ2rcjp6YRa62DIXJUp/PoticK4kS9iyX51yQ4i/JM+hzA3AGENNtGJIaCe1IHbW3fN2Og0HcgCvWaE88YyXmsprhRpofyMEWOafSLz4/wOI79hbS1JDWrm4ABATjNO5EzoZDEpaMyuQRCiE3U5GlkG6JHBBFHU6Rq4LD6EUU7IXirqbTKNlzHPIJtNyFdwaJDIqK3TldZN4DxPZIrz9Bin9DqCl4vcX5p6JmMxxXbIrP3xe97vxYbgeCK1tgPuJX58tcNHecHYO8E/92HAUMbnvj/88Pv5O9onyTbuzwJgbroMRL5f56o1mld93ctmRQbhsfceZJNMdB6m4+BUPDNObHlUib/tXiS+2AffOOJxMFsnMAk6XCoFIAYnyeJ3C0h+wT03Hy+vz/nUgiaYlvKEdxVm4NfdgEC0u4+hjLffzbIN7koH14m3mzUVnHCN2p29nW7gVzeaIAa3/UIy7CQZVe693eyfJNYoOZScWqZkGxDnyJEffAFtUqMStczgeWntlqyVTSIbEw3teCX0Aii/abhp/NKGX5jFKAA+o6Xuxm2dwjDpWUlIHf9MOlxMbW7WKQQyVZ4onl9mpKcrKzTgiLuJ2zIT7Wha46J8X8iE3HsxzM1YjrJFVc= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MW4PR12MB6873.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(1800799024)(376014)(23010399003)(10070799003)(10067099003)(56012099006)(261026121527099003)(261026140227099003)(261022115727099003)(261022105027099003)(261028144727099003)(261021123027099003)(261021121427099003)(261102123227099003)(261009220027099003)(261009221727099003)(261009223327099003)(261009223027099003)(261009221227099003)(18002099003)(22082099003)(11063799006)(3023799007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 2 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?U1lHanN1cnAxTUR3SzNaQS9xMWwwYklib2hDRktMN0dGYmVONDhhcFhON2Er?= =?utf-8?B?RVdoZnRCVTZjSlVyUWt2YUFsc2JQcEU5YzBKQTl6QUNjTklKOGFsZzZnL3Y2?= =?utf-8?B?WFFpVHRpWkRDNjZFSEJnbXA4VllyTThHSmtPOUVGV3pXVzI3QkFUYk9mV1E3?= =?utf-8?B?czRNRVhqKy9QS3RiM3hOZWtPWmoxOFFwU2U4c0x2OXk3djhaV0lrRnY3NVor?= =?utf-8?B?VUIxemVJM3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I4R0R5?= =?utf-8?B?bEdNWmRnQlZrVlprLzNYZ1lCL0lJVnJsZGRFK0d6eTB3YlRkdWhSNlM3bU5n?= =?utf-8?B?b2N3ZnFacFRpTkNOOHMwT3ZObUswZ1VxQ1V6MHVHNEJFL1lqQ3krcnRPcWhW?= =?utf-8?B?M0owU3JlN3pEdThZREN2dGdjc2hrUmxKdHo3RW1kTU84b1VmLy9LTytVeDRr?= =?utf-8?B?SHVIYzNuN3NmUmlSL2V6a0xVT1V5end0VFYrQ09VcENXMzJEaDQ2YzlFLzFq?= =?utf-8?B?RUJSbEw5TkRDRUZiZU8zd1dETzBTeHNpUXlSeVVWUXprd2NZekJia05YU1hX?= =?utf-8?Q?43QFn/sir2Ywgp7QErs0lqzBqdk0IU121RGKljGrCRhmt?= X-MS-Exchange-AntiSpam-MessageData-1: tOjWJoxSt+1pEw== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 476da6f1-0f6b-4572-1713-08df4ebde1f3 X-MS-Exchange-CrossTenant-AuthSource: MW4PR12MB6873.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2026 08:42:35.8663 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: riv9hkxX93AaRoNH3boHCzo/Bz2rOA4odTghb0Xw7TXYSjdANv5w8MHJsLzOY3/MVsNNQylTKdzh6ZoXd5cPsw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PPF5A996E821 From: John Hubbard The upcoming r000 firmware uses a new queue element header that includes MCTP and NVDM headers describing the type of message (RPC or GMC) that follows. Add that header as the `QueueElementHeader` type, along with the two NVDM types that the GSP queues use and the MCTP version and NVDM vendor checks that validating it requires. The type is written out field by field rather than wrapped around the generated binding, as `GSP_MSG_QUEUE_ELEMENT` keeps a 16-byte encryption tag, only used with confidential computing, in a union with its last two fields, making the binding 16 bytes larger than what the GSP expects on the queues. Static assertions check every field offset and the size of the type against the binding. The header has no user yet: it replaces `GspMsgElement` at the transport level in a later patch that switches to the r000 firmware, and is built as dead code until then. Signed-off-by: John Hubbard Co-developed-by: Alexandre Courbot Signed-off-by: Alexandre Courbot Reviewed-by: Eliot Courtney --- drivers/gpu/nova-core/gsp/fw.rs | 177 ++++++++++++++++++++++- drivers/gpu/nova-core/gsp/fw/r000_00/bindings.rs | 97 +++++++++++++ drivers/gpu/nova-core/mctp.rs | 27 +++- 3 files changed, 298 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/nova-core/gsp/fw.rs b/drivers/gpu/nova-core/gsp/fw.rs index 5c216d777dff..ee97a44a87d5 100644 --- a/drivers/gpu/nova-core/gsp/fw.rs +++ b/drivers/gpu/nova-core/gsp/fw.rs @@ -33,6 +33,11 @@ }, }; +use zerocopy_derive::{ + Immutable, + KnownLayout, // +}; + use crate::{ bounded_enum, fb::{ @@ -48,6 +53,11 @@ cmdq::Cmdq, // GSP_PAGE_SIZE, }, + mctp::{ + MctpHeader, + NvdmHeader, + NvdmType, // + }, num::{ self, FromSafeCast, // @@ -835,7 +845,7 @@ pub(crate) fn msg_length(&self) -> usize { size_of::() + self.rpc_header().rpc_length() } - /// Returns the number of elements (i.e. memory pages) used by this message. + /// Returns the number of slots (i.e. memory pages) used by this message. pub(crate) fn element_count(&self) -> u32 { self.inner.elemCount } @@ -901,6 +911,171 @@ pub(crate) fn function(&self) -> Result { } } +/// Header opening every element of the r000 GSP queues. +/// +/// A queue element is laid out as follows: +/// +/// ```text +/// +------------------------------------+ +/// | Queue element header | QueueElementHeader: MCTP magic, element length, +/// | | MCTP header, NVDM header, message length. +/// +------------------------------------+ +/// | Message header | RPC header or GMC API header. The NVDM type +/// | | selects between the two. +/// +------------------------------------+ +/// | Payload | Message-specific data. +/// +------------------------------------+ +/// ``` +/// +/// This is the `noEncryption` layout of the `GSP_MSG_QUEUE_ELEMENT` binding. That binding keeps +/// a 16-byte encryption tag, used only with confidential computing, in a union with the two +/// trailing fields of the queue element header, so wrapping the binding would make every element +/// 16 bytes larger than what the GSP expects. The fields are therefore declared again here, with +/// their offsets checked against the binding. +#[repr(C)] +#[derive(FromBytes, IntoBytes, Immutable, KnownLayout)] +pub(crate) struct QueueElementHeader { + /// Always [`Self::MCTP_MAGIC`]. + mctp_magic: u32, + /// Length in bytes of the whole element, this header included. + /// + /// Under confidential computing the GSP pads elements out to whole queue slots, so this can + /// be larger than `nvdm_payload_size` plus the size of this header, but never smaller. + mctp_payload_size: u32, + /// MCTP transport header of the element. + mctp_header: MctpHeader, + /// NVDM header of the message. + nvdm_header: NvdmHeader, + /// Length in bytes of the message following this header: the message header and its + /// payload. + nvdm_payload_size: u32, + reserved: u32, +} + +// Static validation of `QueueElementHeader` against its bindings type. +const _: () = { + use core::mem::offset_of; + + // Offsets of `QueueElementHeader`'s fields + + assert!( + offset_of!(QueueElementHeader, mctp_magic) + == offset_of!(r000_00::GSP_MSG_QUEUE_ELEMENT, mctpMagic) + ); + assert!( + offset_of!(QueueElementHeader, mctp_payload_size) + == offset_of!(r000_00::GSP_MSG_QUEUE_ELEMENT, mctpPayloadSize) + ); + assert!( + offset_of!(QueueElementHeader, mctp_header) + == offset_of!(r000_00::GSP_MSG_QUEUE_ELEMENT, mctpHeader) + ); + assert!( + offset_of!(QueueElementHeader, nvdm_header) + == offset_of!(r000_00::GSP_MSG_QUEUE_ELEMENT, nvdmHeader) + ); + + /// The `noEncryption` member of the union of `GSP_MSG_QUEUE_ELEMENT`, which holds the two + /// trailing fields of [`QueueElementHeader`]. + type QueueElementNoEncryption = r000_00::GSP_MSG_QUEUE_ELEMENT__bindgen_ty_1__bindgen_ty_2; + + // Offsets of fields under [`QueueElementNoEncryption`] within `GSP_MSG_QUEUE_ELEMENT`. + + const QUEUE_ELEMENT_NO_ENCRYPTION_OFFSET: usize = + offset_of!(r000_00::GSP_MSG_QUEUE_ELEMENT, __bindgen_anon_1) + + offset_of!(r000_00::GSP_MSG_QUEUE_ELEMENT__bindgen_ty_1, noEncryption); + + assert!( + offset_of!(QueueElementHeader, nvdm_payload_size) + == QUEUE_ELEMENT_NO_ENCRYPTION_OFFSET + + offset_of!(QueueElementNoEncryption, nvdmPayloadSize) + ); + assert!( + offset_of!(QueueElementHeader, reserved) + == QUEUE_ELEMENT_NO_ENCRYPTION_OFFSET + offset_of!(QueueElementNoEncryption, reserved) + ); + + // Ensure the size of `QueueElementHeader` matches the `noEncryption` layout. + + assert!( + size_of::() + == QUEUE_ELEMENT_NO_ENCRYPTION_OFFSET + size_of::() + ); +}; + +#[expect(dead_code)] +impl QueueElementHeader { + /// First word of every r000 queue element: `"MCTP"` in ASCII. + const MCTP_MAGIC: u32 = 0x4D43_5450; + + /// Creates the queue element header of an element carrying a message of NVDM type `nvdm_type` + /// and `message_len` bytes, message header included. + /// + /// # Errors + /// + /// - `EOVERFLOW` if a length does not fit its 32-bit field. + pub(crate) fn init(nvdm_type: NvdmType, message_len: usize) -> impl Init { + try_init!(QueueElementHeader { + mctp_magic: Self::MCTP_MAGIC, + mctp_payload_size: size_of::() + .checked_add(message_len) + .ok_or(EOVERFLOW)? + .try_into() + .map_err(|_| EOVERFLOW)?, + mctp_header: MctpHeader::single_packet(), + nvdm_header: NvdmHeader::new(nvdm_type), + nvdm_payload_size: message_len.try_into().map_err(|_| EOVERFLOW)?, + reserved: 0, + }) + } + + /// Returns the length of the whole element, this header included. + pub(crate) fn element_len(&self) -> usize { + usize::from_safe_cast(self.mctp_payload_size) + } + + /// Returns the length of the message following this header, message header included. + pub(crate) fn message_len(&self) -> usize { + usize::from_safe_cast(self.nvdm_payload_size) + } + + /// Returns the number of slots (i.e. memory pages) used by this element. + pub(crate) fn element_count(&self) -> u32 { + self.mctp_payload_size.div_ceil(cv!(GSP_PAGE_SIZE)) + } + + /// Returns the NVDM type of the message following this header, or `EINVAL` if it is not a + /// known one. + pub(crate) fn nvdm_type(&self) -> Result { + self.nvdm_header.nvdm_type() + } + + /// Validates the framing of the element. + /// + /// # Errors + /// + /// - `EIO` if the magic, the MCTP version or the NVDM vendor is wrong, or if the element + /// length is smaller than this header and the message together, or larger than the + /// maximum element size. + pub(crate) fn validate(&self) -> Result { + if self.mctp_magic != Self::MCTP_MAGIC + || !self.mctp_header.has_expected_version() + || !self.nvdm_header.has_nvidia_vendor() + { + return Err(EIO); + } + + let element_len = self.element_len(); + if element_len < size_of::() + self.message_len() + || element_len > GSP_MSG_QUEUE_ELEMENT_SIZE_MAX + { + return Err(EIO); + } + + Ok(()) + } +} + bounded_enum! { /// Commands of the GMC API. #[derive(Debug, Clone, Copy, PartialEq, Eq)] diff --git a/drivers/gpu/nova-core/gsp/fw/r000_00/bindings.rs b/drivers/gpu/nova-core/gsp/fw/r000_00/bindings.rs index 552299c98169..959e397c26aa 100644 --- a/drivers/gpu/nova-core/gsp/fw/r000_00/bindings.rs +++ b/drivers/gpu/nova-core/gsp/fw/r000_00/bindings.rs @@ -30,6 +30,49 @@ fn fmt(&self, fmt: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { fmt.write_str("__IncompleteArrayField") } } +#[repr(C)] +pub struct __BindgenUnionField(::core::marker::PhantomData); +impl __BindgenUnionField { + #[inline] + pub const fn new() -> Self { + __BindgenUnionField(::core::marker::PhantomData) + } + #[inline] + pub unsafe fn as_ref(&self) -> &T { + ::core::mem::transmute(self) + } + #[inline] + pub unsafe fn as_mut(&mut self) -> &mut T { + ::core::mem::transmute(self) + } +} +impl ::core::default::Default for __BindgenUnionField { + #[inline] + fn default() -> Self { + Self::new() + } +} +impl ::core::clone::Clone for __BindgenUnionField { + #[inline] + fn clone(&self) -> Self { + *self + } +} +impl ::core::marker::Copy for __BindgenUnionField {} +impl ::core::fmt::Debug for __BindgenUnionField { + fn fmt(&self, fmt: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { + fmt.write_str("__BindgenUnionField") + } +} +impl ::core::hash::Hash for __BindgenUnionField { + fn hash(&self, _state: &mut H) {} +} +impl ::core::cmp::PartialEq for __BindgenUnionField { + fn eq(&self, _other: &__BindgenUnionField) -> bool { + true + } +} +impl ::core::cmp::Eq for __BindgenUnionField {} pub type __u8 = ffi::c_uchar; pub type __u16 = ffi::c_ushort; pub type __u32 = ffi::c_uint; @@ -39,6 +82,60 @@ fn fmt(&self, fmt: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { pub type u32_ = __u32; pub type u64_ = __u64; #[repr(C)] +#[derive(Debug, Default, Copy, Clone, MaybeZeroable)] +pub struct GSP_MSG_QUEUE_ENCRYPTION_TAG { + pub authTagBuffer: [u8_; 16usize], +} +#[repr(C)] +#[derive(MaybeZeroable)] +pub struct GSP_MSG_QUEUE_ELEMENT { + pub mctpMagic: u32_, + pub mctpPayloadSize: u32_, + pub mctpHeader: u32_, + pub nvdmHeader: u32_, + pub __bindgen_anon_1: GSP_MSG_QUEUE_ELEMENT__bindgen_ty_1, +} +#[repr(C)] +#[derive(MaybeZeroable)] +pub struct GSP_MSG_QUEUE_ELEMENT__bindgen_ty_1 { + pub withEncryption: __BindgenUnionField, + pub noEncryption: __BindgenUnionField, + pub bindgen_union_field: [u32; 6usize], +} +#[repr(C)] +#[derive(Debug, Default, MaybeZeroable)] +pub struct GSP_MSG_QUEUE_ELEMENT__bindgen_ty_1__bindgen_ty_1 { + pub encryptionTag: GSP_MSG_QUEUE_ENCRYPTION_TAG, + pub nvdmPayloadSize: u32_, + pub reserved: u32_, + pub payload: __IncompleteArrayField, +} +#[repr(C)] +#[derive(Debug, Default, MaybeZeroable)] +pub struct GSP_MSG_QUEUE_ELEMENT__bindgen_ty_1__bindgen_ty_2 { + pub nvdmPayloadSize: u32_, + pub reserved: u32_, + pub payload: __IncompleteArrayField, +} +impl Default for GSP_MSG_QUEUE_ELEMENT__bindgen_ty_1 { + fn default() -> Self { + let mut s = ::core::mem::MaybeUninit::::uninit(); + unsafe { + ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +impl Default for GSP_MSG_QUEUE_ELEMENT { + fn default() -> Self { + let mut s = ::core::mem::MaybeUninit::::uninit(); + unsafe { + ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[repr(C)] #[derive(MaybeZeroable)] pub struct GMCAPI_HEADER { pub command: u32_, diff --git a/drivers/gpu/nova-core/mctp.rs b/drivers/gpu/nova-core/mctp.rs index f62e79f56b05..e1331337f9af 100644 --- a/drivers/gpu/nova-core/mctp.rs +++ b/drivers/gpu/nova-core/mctp.rs @@ -13,6 +13,11 @@ prelude::*, // }; +use zerocopy_derive::{ + Immutable, + KnownLayout, // +}; + use crate::{ bounded_enum, num, // @@ -28,11 +33,16 @@ pub(crate) enum NvdmType with TryFrom> { Cot = 0x14, /// FSP command response. FspResponse = 0x15, + /// RPC message to or from GSP-RM. + RmRpc = 0x25, + /// GMC (GPU Management Controller) API message to or from GSP-RM. + GmcApi = 0x26, } } bitfield! { /// MCTP transport header for NVIDIA firmware messages. + #[derive(FromBytes, IntoBytes, Immutable, KnownLayout)] pub(crate) struct MctpHeader(u32) { /// Start-of-message bit. 31:31 som; @@ -67,6 +77,11 @@ pub(crate) fn single_packet() -> Self { pub(crate) fn is_single_packet(self) -> bool { self.som().into_bool() && self.eom().into_bool() } + + /// Returns `true` if this MCTP header carries the version that this driver uses. + pub(crate) fn has_expected_version(self) -> bool { + self.version() == Self::VERSION + } } /// MCTP message type for PCI vendor-defined messages. @@ -74,6 +89,7 @@ pub(crate) fn is_single_packet(self) -> bool { bitfield! { /// NVIDIA Vendor-Defined Message header over MCTP. + #[derive(FromBytes, IntoBytes, Immutable, KnownLayout)] pub(crate) struct NvdmHeader(u32) { /// NVDM message type. 31:24 nvdm_type ?=> NvdmType; @@ -93,10 +109,17 @@ pub(crate) fn new(nvdm_type: NvdmType) -> Self { .with_nvdm_type(nvdm_type) } - /// Validates this header against the expected NVIDIA NVDM format and type. - pub(crate) fn validate(self, expected_type: NvdmType) -> bool { + /// Returns `true` if this NVDM header belongs to a PCI vendor-defined message from NVIDIA. + /// + /// The GPU firmware only ever sends such messages, so a mismatch is a sign of corruption. + pub(crate) fn has_nvidia_vendor(self) -> bool { u8::from(self.msg_type()) == MSG_TYPE_VENDOR_PCI && u16::from(self.vendor_id()) == Vendor::NVIDIA.as_raw() + } + + /// Validates this header against the expected NVIDIA NVDM format and type. + pub(crate) fn validate(self, expected_type: NvdmType) -> bool { + self.has_nvidia_vendor() && matches!(self.nvdm_type(), Ok(nvdm_type) if nvdm_type == expected_type) } } -- 2.56.1