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.61.1 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795965073; b=Cb6DbOkNfa0ynhMsvn2g39ub90r23DKbY8Fe8i6RifR8I41TFP+L6ctNhyw+aNtf5h+5 RCz7pALaIoH4KGCGBYygBKUU6T/A/P3oVSy2o4KWJyhkHx3bxHzQmCoaVoJz2YN7Ksslo DqlxmwCJgvAVpPwnk9UZCpJiUGvEz6QIEPbcvAxHClPpsADbods6R8Mt1jsX/moVScik8 0B5wJzXnlysaBBl5M6Ou3Wg1riMAFvWn3Crl6yCpZ1VIQeeIRmFzGQ5Q+x6yCBnI5dJUI cm5GKy6+IFKD8QWWfU917g4mFTmoMs7cHiyczq5ywqXbd2ZizmHwmTO5yMYCgY1ReUQ== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795965073; 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=5LdpZCgfxfKtxCRTWvDfQk4tVzL2UonaZSf61FVPdEI=; b=zY73xf2C3MoSGDuqhz749ble8g2AM8tCvNMIJAjX3LlyiAZ/jtAQVAmkyE1yl4KS56Ts upFdVSbHMbqAGfOv5SiHloMp1BMU3rS4fZhj+TSCpgj+adrwYsNKBFo608hLCeDbYKxMN TURJ2nmBKI00gmghr0WYSGCPhOZyECOzQ4fL1ww0UxC2UBHutfFv0+b+MR9tqbRGi4n/8 LPKaZTjnOCsPgfG0vlq1AiD89Gu95s9+qV7u/0w2BYIjlYuh4jMI9xlyfuL12V7bgd8LT J2AEz85hAxHOTub86mT41yg64YYZG/uRTYaN1wcjZFt6OglkuYKUXOLon8IRy1hqWZQ== 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=NXVUynAM; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.61.1 Received: from DM1PR04CU001.outbound.protection.outlook.com (mail-centralusazon11010001.outbound.protection.outlook.com [52.101.61.1]) (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 B1993606A33D for ; Sun, 29 Nov 2026 15:11:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B1993606A33D 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=NXVUynAM ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=N5gDL5rFXvi2tw9gjup70Ioabrv7SUcL92u4EYzjxHX8S1s7mOIzgbkL8ZsjzI8+3034orZJcwRhlrnSJcD69kZbmwzSH0QC80NbyDMmjuH9Rs4CL3NjEgpzPfAVZIsSq+GlK/nwGaQfpuUO15dEhypCsr13RLVMB+wwHab56vWv0i7nbk9tcVZ0jk+0JqZ2L+BYLk9e8pacOMXKrUplrA9dDykgteeackyrmRE8/aT3Q1uP3rdsSEzvISGXUvKsiVo95evK7FnK7I3ZIUeNV3XHEAVViSAp5QmGCXHIAe93c+R+uOQZnUlJfgAHbuY4XJRy2Jlumvb9YX3TcmWW5Q== 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=5LdpZCgfxfKtxCRTWvDfQk4tVzL2UonaZSf61FVPdEI=; b=zDtHLIJnworh2BI7h7nHJtKa7hqfUzB4hdtUq6L5ZT24KwE87j44uTKp0idUIEhzM9XErLj887n1LonckEStK15JVRk8VmF2jG3nbV/9NzMhjnA/j7MjsaRlML+yqmvcipQJGY1P0mDT/Oq77UUkE0hiNSGqKgc5cgb82YPX9nxl32v9ybdhdg+tCiTQhffR2W99DVh/XqcdQxMkIgieDixmEXQGpy41D4CBIcmGLh1MtnFAY0G3qgdyFOFVavaeTDwGPig1DUX8W05j/fmE8SrUG1qX5VpSCNOEeeJARCWTUvTovyE8ZKDk04vsQxC25HHez8qk2YQJWpjEjIcW1A== 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=5LdpZCgfxfKtxCRTWvDfQk4tVzL2UonaZSf61FVPdEI=; b=NXVUynAM2k1GomabAl2MwiobTyhCCMhe4rv2SPNHGbHDsPgm1wJFTVWCgLrFgvSPABQEhtnnC/2F1dkOy2lhVBgHkCNtqLRT/Tb0JUFkIwhHzm6gR9bfcGtUyp3AwTL0M0aX5gR+vASmO05KC8LpU0e7KDZ0DWiN0vuh1py2bOJlcofcQsHWy+oEx33k50mwmktEHHugcjjuEDyYxpWesa/VhxHrVwys/E4pv3xn7O2pkyg3U9ewdNCseKtJ7DUgqHW33N/1nNXoJoXl2Bn051B6Deq1XrzCdrjWvujM48+j94zofBHNMOKVvcZ8hh7DRwlRYKCtOS+9FW2ryv5r5A== 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 IA3PR12MB524589.namprd12.prod.outlook.com (2603:10b6:208:705::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.11; Sun, 29 Nov 2026 15:11:10 +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; Sun, 29 Nov 2026 15:11:10 +0000 From: Alexandre Courbot Date: Mon, 30 Nov 2026 00:11:00 +0900 Subject: [PATCH v2 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-v2-1-afd079026a61@nvidia.com> References: <20261130-nova-r000-staging-v2-0-afd079026a61@nvidia.com> In-Reply-To: <20261130-nova-r000-staging-v2-0-afd079026a61@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: TYZPR03CA0008.apcprd03.prod.outlook.com (2603:1096:405:1d1::20) 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_|IA3PR12MB524589:EE_ X-MS-Office365-Filtering-Correlation-Id: 2b4c19f0-c799-4742-e82e-08df4e2b006c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|23010399003|1800799024|10070799003|11063799006|261009221227099003|261009223327099003|261009220027099003|261009223027099003|261009221727099003|22082099003|18002099003|3023799007|10067099003|56012099006|261102123227099003|261028144727099003|261026140227099003|261026121527099003|261021121427099003|261021123027099003|261022105027099003|261022115727099003; X-Microsoft-Antispam-Message-Info: d8Zv2UmrI9cRUqn9cFsGs0I8btkxFqcC86Xe1EXPFguo7kZawXUHD3VTP3Vy6Xt21gcMATuEM8lY8ksMCQZDBsHmAPVcEWmBF/iIk609NRCDCjmQGZdz76ITtMJVRgfJxAXqgGqBqvQUzlmkhbq1MmEC7nylXTiUkyvhdO6UMNdj/U11A9L2sI+2Bzke7IMZFJyoSmxk5AZcTbJRJtqc73rvRXprFy02O19YK9oxZWIRMBoKKocM7x1rxWOAcObIRkZSkD7juLClpoKpqfE5QCSc1mMcSVpmwTjyugQIkQMpM7I8jCFPlY47+XhIIpZMbe2CHmoWIRA9R5F7D7CRjz9SQc8sYIKRbsLCu6Gw6kmQqRDOb6Sf3e4jGxrr/Gil/0d/QPy4HFcEyfFyQ5RxGyRkwiizSyjQH7nNIORgKM2HbLHaxsZxYkX19tk44qESXv1Z38c1g2TkfVOqBdr7vQe78ZC5mM+2pXfIwDFDuiAsLSbxMWGPJl42s4x5RQ8u/VE5PGGkmQU7doPDjAJAnYPuh3uAnGU1wVO/VDQlNofPe7pscZvHkFFA1hGgpPT5q2u24Jlny44O2V+4qz0wRGxOq7M6Q0KDr9e6TIvi3IGPpD9+c0ZRgEX42VrMEv7jTqnEP0NY5TmbWf1hVV1pfzwnrFh+2DaPhHe3Edc9zrE= 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)(376014)(23010399003)(1800799024)(10070799003)(11063799006)(261009221227099003)(261009223327099003)(261009220027099003)(261009223027099003)(261009221727099003)(22082099003)(18002099003)(3023799007)(10067099003)(56012099006)(261102123227099003)(261028144727099003)(261026140227099003)(261026121527099003)(261021121427099003)(261021123027099003)(261022105027099003)(261022115727099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 2 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?UTN6WEpiSVFhYXRGMHdDREFtZE9zS0I2OXNyWHBzQS9aeXBDMlcwMCtnVE9k?= =?utf-8?B?Uk5JT0NwV1FJRGFKU2ZvN0RKNGt4WkkzM1BYU25ZZmdwdHc4Y2JOb3k5cDlU?= =?utf-8?B?cWQ0QXdEUjZ5RkdDbldNaGN1dGxxdXR4OHA0OWxBemNwSUlUSjJwNXIwalRP?= =?utf-8?B?Ky9KVXVPc28wSjdUTys4OFlFUHhWZFI5RTN1bTJZZythSitWNmE4RjY5Rm1u?= =?utf-8?B?aEVEb3lpcFZNeG5jZkpaU0Faem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i?= =?utf-8?B?dkRUZ0QvUk5iN0RlcytKYW14eFdndVdKQnp6aWdEMnRKM2kzN1J0VENqbkdi?= =?utf-8?B?NitRaEppdndhd0tFNTk5czdoVzhLNWVSYW56b0lFbDdpQWJGVDlvM0Z1RVpH?= =?utf-8?B?UmtkbFZlc05oWkR1bTE0SytIVjhpT0s2UE1SeWFnQkdmVnQzNnJ1TTJWUVlG?= =?utf-8?B?NFZPQ1dVTWQ5M1ZlY29UTzFHVGpxbGhNYUsvS04yS05kanBTazJDdzdXWUIw?= =?utf-8?B?M25HeWJDYzZiSk05NWpVN3NGd1NINk1Bc0JFMm1jbGJmUjNLRk0rTU5ZWkhF?= =?utf-8?Q?9f6HlvEgpNaYpjGmv8j2rfisgQXvlbm1UEgfh6gANpRdq?= X-MS-Exchange-AntiSpam-MessageData-1: jfRpOUGb0yP19Q== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2b4c19f0-c799-4742-e82e-08df4e2b006c X-MS-Exchange-CrossTenant-AuthSource: MW4PR12MB6873.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Nov 2026 15:11:10.8500 (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: yFVpaGhe3TkIZzhSE0+J+QEOaNRAL/dTIGx93ulVuzWPAOJYj5Led2bmHfwrEY2kOnTjymEuywXrPwar4Unkug== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA3PR12MB524589 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 --- drivers/gpu/nova-core/gsp/fw.rs | 183 ++++++++++++++++++++++- drivers/gpu/nova-core/gsp/fw/r000_00/bindings.rs | 97 ++++++++++++ drivers/gpu/nova-core/mctp.rs | 27 +++- 3 files changed, 304 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/nova-core/gsp/fw.rs b/drivers/gpu/nova-core/gsp/fw.rs index 5c216d777dff..937cbbc24e93 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,177 @@ pub(crate) fn function(&self) -> Result { } } +/// First word of every r000 queue element: `"MCTP"` in ASCII. +const MCTP_MAGIC: u32 = 0x4D43_5450; + +/// 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 [`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 + + static_assert!( + offset_of!(QueueElementHeader, mctp_magic) + == offset_of!(r000_00::GSP_MSG_QUEUE_ELEMENT, mctpMagic) + ); + static_assert!( + offset_of!(QueueElementHeader, mctp_payload_size) + == offset_of!(r000_00::GSP_MSG_QUEUE_ELEMENT, mctpPayloadSize) + ); + static_assert!( + offset_of!(QueueElementHeader, mctp_header) + == offset_of!(r000_00::GSP_MSG_QUEUE_ELEMENT, mctpHeader) + ); + static_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`]. + // Using `allow` instead of `expect` as rustc 1.85 ignores uses from `static_assert!` and + // reports this as dead code. + #[allow(dead_code)] + type QueueElementNoEncryption = r000_00::GSP_MSG_QUEUE_ELEMENT__bindgen_ty_1__bindgen_ty_2; + + // Offsets of fields under [`QueueElementNoEncryption`] within `GSP_MSG_QUEUE_ELEMENT`. + + // Using `allow` instead of `expect` as rustc 1.85 ignores uses from `static_assert!` and + // reports this as dead code. + #[allow(dead_code)] + 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); + + static_assert!( + offset_of!(QueueElementHeader, nvdm_payload_size) + == QUEUE_ELEMENT_NO_ENCRYPTION_OFFSET + + offset_of!(QueueElementNoEncryption, nvdmPayloadSize) + ); + static_assert!( + offset_of!(QueueElementHeader, reserved) + == QUEUE_ELEMENT_NO_ENCRYPTION_OFFSET + offset_of!(QueueElementNoEncryption, reserved) + ); + + // Ensure the size of `QueueElementHeader` matches the `noEncryption` layout. + + static_assert!( + size_of::() + == QUEUE_ELEMENT_NO_ENCRYPTION_OFFSET + size_of::() + ); +}; + +#[expect(dead_code)] +impl QueueElementHeader { + /// 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: 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 { + num::u32_as_usize(self.mctp_payload_size) + } + + /// Returns the length of the message following this header, message header included. + pub(crate) fn message_len(&self) -> usize { + num::u32_as_usize(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 != 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::().saturating_add(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..2058303dfbb9 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 { + u32::from(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