From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from CH4PR04CU002.outbound.protection.outlook.com (mail-northcentralusazon11013034.outbound.protection.outlook.com [40.107.201.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5DBE8501F2D; Wed, 30 Sep 2026 14:57:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.201.34 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790780271; cv=fail; b=NtBHV7N+GeqnQ1w0pZ0MPJRwPYZayuEdcWbNZLgYb4n+mtLfzjZYLr/HVoEidXaoRfrMgaKgQk0BKxqvdiZ/e1w0snw57qfw7HkUkvTatGjJOU1xhQKF5ZB4bOVgxa7AKvr+LOxWIyti0zn0/f8i/ZDm7EIgorxGqO8YgO9hDmM= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790780271; c=relaxed/simple; bh=hks5jolWlGjqGZi2iUdjhRUHX15ltHjppOEoUvwlz34=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=IVBDiJSSddLhdMbsufn2lBUlChGifGBSZRTn1E9DZ29DPL1XRFbYM8Kei1Hos05GYeLnybayDPhRKUxYnj02ZG96l0O+D1CMSJCRxC2SAy42/eBO4xGE+uroC2rkFkk+vUa20DTKep8GRCkZd+2mFuc1eH3TjoOu11VWsegYx70= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=K8+YoYja; arc=fail smtp.client-ip=40.107.201.34 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) header.d=Nvidia.com header.i=@Nvidia.com header.b="K8+YoYja" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=hFU216zpxNs936JcUL3XJ1Ju401Q6Gngp0cBjDcf+ErejwudSfcCwHTnS4+RHP5ObROkORM5WEKINS8+Nald9xbQsBFOlrLHKq/fSvoQlyNdUMWsJVbq4FmtVYAnnkUojj6ukDiPmtL3Lwwu3zMRF/YiVYgiooaMP98uHliQjx/ks8xrgnM6+UQcjDGfd4ycPMz12L4uAAsZAP9PIDoQYvVADHrP7MpJeCmKu7XfinqKI2a+zm9K7fxAG1X6ojUAnI1UE6cmfPi2RQMiQTknu+AL44vwgtCVRo2MB0Vkb0l3PQMUpEAsvyI1A7o3ZwmQ57U8ssPz0k0QANu88DTltA== 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=lUlf6ymj9zm3KR0dDgoqueXKuPajA+kXGNbmKglmIV8=; b=jVaXnBLjV7frRQQKyjpXMYepHSmgRtoX4Wegh+niA81srZemTBY3GQt4u1P6KSqOe+1gyrll8HUiXhJpqyNSHnQvETL9B51q2EjYq1EVDMFe1sTcGtHvUwm55Nb8B08/N+fIlrSFB4YnBQMLcqy28p8ud8s3cPlEizkzDf4mf7HVM7Tsy0jqaIGfFedLtBLpNmb9x1eONFGSq80qDKUzilFQgjY6+yqYWelcn6f9ZB2ylZQTWyihH76lQO5/FRiQC4YFaFInEw34NF0h2NhNYAyhhjwODtxby2HBoCZzULp3mT2WhtmuC0GlBwFnvG2e53X6x803ImJzvm9S2GrJgQ== 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=lUlf6ymj9zm3KR0dDgoqueXKuPajA+kXGNbmKglmIV8=; b=K8+YoYjaHVXFj10pyeHa79uY1JFW3WI5PmCAK/wKDPTX8bfYuvZvBlL2z4S4x+bQrBRDxpfV8bVD529A9tVHN6evTFgdR0V/YF/HTMJe2VqM2DJp8b8EBV5zDvd9jZBKEe+SpMsHaqMevWms62AZA5SodNEBQgr9Ve36i6HvKJUPajIG6FQhkNroGcdNYEX2twVshwiNjWTqEq5pdxmhQHcJnb3dxESEpCBwzGuQZQx34wms49Y7kpkgScRNaAGGR5YGxqbXFeQqFp8Arz0h/eXo8Xz9QpViFYEIkVEAzvMruarDEkhUJSTf2ZSLax9giYisgF6jxap6DIIcXXYMSw== 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 DM3PR12MB9392.namprd12.prod.outlook.com (2603:10b6:0:44::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.472.15; Wed, 30 Sep 2026 14:57:07 +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.0472.015; Wed, 30 Sep 2026 14:57:07 +0000 From: Alexandre Courbot Date: Wed, 30 Sep 2026 23:55:43 +0900 Subject: [PATCH v3 4/9] gpu: nova-core: gsp: cmdq: split the transport part of the send path Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260930-cmdq-rpc-v3-4-91613f06520b@nvidia.com> References: <20260930-cmdq-rpc-v3-0-91613f06520b@nvidia.com> In-Reply-To: <20260930-cmdq-rpc-v3-0-91613f06520b@nvidia.com> To: John Hubbard , Danilo Krummrich , Alice Ryhl , David Airlie , Simona Vetter , Benno Lossin , Gary Guo Cc: Alistair Popple , Timur Tabi , Eliot Courtney , Zhi Wang , nova-gpu@lists.linux.dev, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, Alexandre Courbot X-Mailer: b4 0.15.2 X-ClientProxiedBy: TYCP286CA0351.JPNP286.PROD.OUTLOOK.COM (2603:1096:405:7c::20) To MW4PR12MB6873.namprd12.prod.outlook.com (2603:10b6:303:20c::17) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MW4PR12MB6873:EE_|DM3PR12MB9392:EE_ X-MS-Office365-Filtering-Correlation-Id: 7eac7398-7a4b-41f5-4bd6-08df1f031901 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|10070799003|1800799024|376014|7416014|23010399003|11063799006|10067099003|56012099006|6133799003|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: lpCrKdWVfWaTei4G1l5AkvIfOiFt7kxT8rOEoOd9hL1o/m8aD71Rr+EXMGMlNinvnl4qaa69/S6QTTX4DG2X7RZCd2mKUiJROm/0bQqy9/KLJYx3dS3P3soVBDZI43ix3mlURK5O/pUQnuTvef7Dd4bE0GynBiY/G5eg43JKRaJmvm/E5TA2OLXeVKe3nWsNFyjRycEIOjlqPFrgYebAfNt6Sh/sty/Mhm70kfYO851/37dFLgSf0KG9NKzZIpMbeuZJiyTc06KNCruX55gkn0HhUyzDYgD0FkpPVUoD7M3hKGJZOazjN/U8YrODONhkOF2R6+olNpg70/Z5PDPb/KyGcPq57mERDkDHQq8Q/OhrPZOrRcs1dMEFszZr73vYDc1L4DFcrrSXbfb8KGyXJ+f5Ax5HWgZsr6LjAahgIYW90vFzJAzEtJc0Sj94CnOqlulkRhhp19RqEnS3lrFRvFfZp335iaZiM1O85u8y0wkVIHd8O75SPonbWHmvu4Bo1Clcv147ww+NnNzTGAvj7ePgvxl7HelXFL0VT0hNjZ4HhzQDAb+gwHHMPCXm4FlO9bmprQeQKL3VjcKanJUpuuoiII05y0jDw+BE/pisO8e7InE+2wLLF/pLXfZDd5MJRKMWS4rjm95YGb/Vu8rZh5sja5HSG8JHY/FxhNKaW1s= 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)(10070799003)(1800799024)(376014)(7416014)(23010399003)(11063799006)(10067099003)(56012099006)(6133799003)(18002099003)(22082099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 2 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?Tkl1cWVxcDdFckJuMm44WE11ZHlMd2lhTEVvcjNjL0gzMFpMQVpPSlJITUxo?= =?utf-8?B?Tmp3OXVNVEczOThIb29zcVU5QzM3Ujd6dGlHZjluUjRqMFBSUWZxbGFyaXlV?= =?utf-8?B?cGVtYWdxTTJJci8xa0c1ZXJYbENLOXNJT3lhdXJ6UE1SekRSMEk5dExVOG03?= =?utf-8?B?a3dTQm5kU3E4Y3dVZ3hTY1puejFQUmgwQmZXWXZ2cldGU0E3UXJNeWVaS3Uw?= =?utf-8?B?RTlrQlQxbXF5MSs1U1ZtbzJFZitWV0gzMmljdWJGY2VUR0lpUlY5aXZabTcw?= =?utf-8?B?L29yMUpZODRUUVVZbUc0SUFOZ3NTdTNQVE1KYzBvU1NXUkdoc0ZnbGZWWFZV?= =?utf-8?B?NCtNTC9neWhiSVI5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JiQy9ZZ2ZJ?= =?utf-8?B?ZDhlbUpjalA4emZVOEhPNVdpUXlnWVhJaU5Ya1c0UWNJY3ZCb1JWV3pOc3c5?= =?utf-8?B?UG9mWEJaY0l5Nys1dmNnekYyMjByalcvSEtFUXdCZ2lheHUwL0hpR2d6eHdp?= =?utf-8?B?dHhZTzlIVk5LcnV0SmxCOVVYTFR0OHNUZ0wxaTQ3cTBuMUVDRVhhV3REakZh?= =?utf-8?Q?3AB8VnUF1HJKqNhvxIUrT4pLXzllBvHITRJq3+xDJgQZg?= X-MS-Exchange-AntiSpam-MessageData-1: W70O7V2UKmevKQ== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7eac7398-7a4b-41f5-4bd6-08df1f031901 X-MS-Exchange-CrossTenant-AuthSource: MW4PR12MB6873.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2026 14:57:07.5762 (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: 8fy7DZayjcgfbRiFcI+UuLmg6R7o4gMJJC6zPyDPK2/FtdUBVkkmm7FLHc2SSNOPe+xmoilt7QxQSq4spOwLXg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM3PR12MB9392 Introduce the `CommandElement` trait and `RpcCommandElement` wrapper type to define how messages (independently of their type) are sent through the transport layer. `send_single_command` becomes `send_command_element`, which allocates the queue slots, writes the element header, and delegates the writing of the message itself to the implementation of `CommandElement` before computing the checksum, advancing the write pointer and ringing the doorbell. The RPC part of `send_single_command` (writing the RPC header and the command payload) is now part of the `CommandElement` implementation. This sets things up for moving the RPC code into its own sub-module, leaving the transport agnostic of the message type. No functional change intended. Suggested-by: Eliot Courtney Signed-off-by: Alexandre Courbot --- drivers/gpu/nova-core/gsp/cmdq.rs | 133 +++++++++++++++++++++++--------------- 1 file changed, 80 insertions(+), 53 deletions(-) diff --git a/drivers/gpu/nova-core/gsp/cmdq.rs b/drivers/gpu/nova-core/gsp/cmdq.rs index bda79f23626d..d8a7716fc500 100644 --- a/drivers/gpu/nova-core/gsp/cmdq.rs +++ b/drivers/gpu/nova-core/gsp/cmdq.rs @@ -35,10 +35,7 @@ }, }; -use continuation::{ - ContinuationRecord, - SplitState, // -}; +use continuation::SplitState; use pin_init::pin_init_scope; @@ -67,6 +64,19 @@ /// reply type are sent using [`Cmdq::send_command_no_wait`]. pub(crate) struct NoReply; +/// Trait implemented by types that can be sent as a single command queue element. +/// +/// The command queue allocates `size()` bytes after the `GspMsgElement` header and calls `write()` +/// to fill them. +trait CommandElement { + /// Size in bytes of the element, not including the `GspMsgElement` header. + fn size(&self) -> usize; + + /// Writes the contents of the command into `dst`. `dev` is the queue's device (to be used for + /// logging), `seq` is the sequence number of the element. + fn write(&self, dev: &device::Device, seq: u32, dst: &mut GspCommand<'_>) -> Result; +} + /// Trait implemented by types representing a command to send to the GSP. /// /// The main purpose of this trait is to provide [`Cmdq`] with the information it needs to send @@ -129,6 +139,62 @@ fn size(&self) -> usize { } } +/// Wrapper type for sending a RPC command as a command queue element. +/// +/// [`CommandElement`] cannot be directly implemented for all [`CommandToGsp`] with a blanket +/// implementation as it would conflict with other future command types. +struct RpcCommandElement(M); + +impl CommandElement for RpcCommandElement +where + M: CommandToGsp, + Error: From, +{ + fn size(&self) -> usize { + self.0.size() + } + + fn write(&self, dev: &device::Device, seq: u32, dst: &mut GspCommand<'_>) -> Result { + let command = &self.0; + let size_in_bytes = command.size(); + // 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)?; + let rpc_header_init = RpcMessageHeader::init(size_in_bytes, M::FUNCTION); + // SAFETY: `dst.header.rpc_header_mut()` is a valid reference, and is not touched if the + // initializer fails. + unsafe { + pin_init::raw_try_init( + core::ptr::from_mut(dst.header.rpc_header_mut()), + rpc_header_init, + )?; + } + // SAFETY: `cmd` is a valid reference, and is not touched if the initializer fails. + unsafe { + pin_init::raw_try_init(core::ptr::from_mut(cmd), command.init())?; + } + + // 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); + } + + dev_dbg!( + dev, + "GSP RPC: send: seq# {}, function={:?}, length=0x{:x}\n", + seq, + M::FUNCTION, + size_in_bytes, + ); + + Ok(()) + } +} + /// Trait representing messages received from the GSP. /// /// This trait tells [`Cmdq::receive_msg`] how it can receive a given type of message. @@ -638,24 +704,18 @@ impl CmdqInner<'_> { /// Timeout for waiting for space on the command queue. const ALLOCATE_TIMEOUT: Delta = Delta::from_secs(1); - /// Sends `command` to the GSP, without splitting it. + /// Allocate enough send slots to store `command`, initialize them using + /// [`CommandElement::write`], and send the command to the GSP. /// /// # Errors /// /// - `EMSGSIZE` if the command exceeds the maximum queue element size. /// - `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. - fn send_single_command(&mut self, command: M) -> Result - where - M: CommandToGsp, - // This allows all error types, including `Infallible`, to be used for `M::InitError`. - Error: From, - { + /// Error codes returned by [`CommandElement::write`] are returned as-is. + fn send_command_element(&mut self, command: E) -> Result { let size_in_bytes = command.size(); - let dst = self + let mut dst = self .gsp_mem .allocate_command(size_in_bytes, Self::ALLOCATE_TIMEOUT)?; @@ -666,40 +726,8 @@ fn send_single_command(&mut self, command: M) -> Result pin_init::raw_try_init(core::ptr::from_mut(dst.header), msg_element_init)?; } - // 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)?; - let rpc_header_init = RpcMessageHeader::init(size_in_bytes, M::FUNCTION); - // SAFETY: `dst.header.rpc_header_mut()` is a valid reference, and is not touched if the - // initializer fails. - unsafe { - pin_init::raw_try_init( - core::ptr::from_mut(dst.header.rpc_header_mut()), - rpc_header_init, - )?; - } - // SAFETY: `cmd` is a valid reference, and is not touched if the initializer fails. - unsafe { - pin_init::raw_try_init(core::ptr::from_mut(cmd), command.init())?; - } - - // 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); - - dev_dbg!( - &self.dev, - "GSP RPC: send: seq# {}, function={:?}, length=0x{:x}\n", - self.seq, - M::FUNCTION, - size_in_bytes, - ); + // Write the message payload. + command.write(self.dev, self.seq, &mut dst)?; // Compute checksum now that the whole message is ready. dst.header @@ -735,13 +763,12 @@ fn send_command(&mut self, command: M) -> Result Error: From, { match SplitState::new(command)? { - SplitState::Single(command) => self.send_single_command(command), + SplitState::Single(command) => self.send_command_element(RpcCommandElement(command)), SplitState::Split(command, mut continuations) => { - self.send_single_command(command)?; + self.send_command_element(RpcCommandElement(command))?; while let Some(continuation) = continuations.next() { - // Turbofish needed because the compiler cannot infer M here. - self.send_single_command::>(continuation)?; + self.send_command_element(RpcCommandElement(continuation))?; } Ok(()) -- 2.55.0