From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from SN4PR2101CU001.outbound.protection.outlook.com (mail-southcentralusazon11012067.outbound.protection.outlook.com [40.93.195.67]) (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 6C65133F8A1; Thu, 18 Dec 2025 13:28:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.195.67 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766064488; cv=fail; b=exeQ8tHbSMiOCrNlYEQqAUKxt6Gcn36RWIEpUOXdiwU276YNXSZpwgd4IOSyMVqeLFmHbZSpxCchEnZOKMVX2XktFUfp/+W2pHOTpBMACgJQBsqASKmi5xJjISAzl5vr4W3QjOO4c7/RyK62FgfOIR5KHsWt67sAvROKEhOVTEI= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766064488; c=relaxed/simple; bh=U20AOvnzHdYRAj544Sz40vXJxGxVMB+bnTtDmaRXxWI=; h=Content-Type:Date:Message-Id:Cc:Subject:From:To:References: In-Reply-To:MIME-Version; b=mLTAYkh7cz8NbFwhHKTv+QGV9Ejq25bLhcnghWkVA0/DFGXfKyofsVfhAucGEE2U2uE5bi/gSmb9Y2LUbyuONF2RNQLenGFpakJWhlMmFBwsHa2lzv+HjMS/u9UeZXx/3NF6ncOQFH/zRGO5nXqZkEAUpiIqepJQqC92mQir+Dw= 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=dIpkRhVF; arc=fail smtp.client-ip=40.93.195.67 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="dIpkRhVF" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=osVGLCKDA2BTxiaJhcJx2SjRUuQu74e8V0fK04WmBjXtM4Bx4pZD20iahgaiIyNxpK7va6evokzqy/93kVTsfdHJdjWsnW2ENCfDe9beCVJe95A7ZaVEasEpoxurS6W7ynZNE8Nu4KefePIkyj0MfLfNvS32YDtRffDTmxLA0P4wx5tQ0gCNlQ+50QVECexrqg/819VKEIbD0DHHArCH/3rKgY65i/Hk9WWXNqdEV85HucFkA5767xpej+Q5vy+YGY54qLvN15Sf3AOpVcSxfCrbeOJZxQ+wqORdC1oR/0MBUiaC1C+wx290QQGxI6sdd1XqLqR9EdolelTrsuq8Mg== 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=5rFzKHsDaZ3RJcr6S1R91nXKIyUD9DkwKR71jQxND8k=; b=tgibJ2wWEmoBsE4EGIlbx2ZvEN54FZm5QTmw/NAQtEZtfuwoUGMIZHkWIJQ/FJFmsA0S3RmE6Ph5vOguPL24hc6DFPYCxm3G8FOtTQgi9cNkp3RkPCJu5Dls8F6iK2dRuO5wtX6tCw4oraHsaLSDgIWLGwJaOzoymKvBOclDGVof2ver932ITIxLJztIltGGwnkPIIH+/UNg4Qi6zsmBGwFvyxJIUy87c4oUgQZqUgqAQe9+xmsLrTKuFbYz9INJlWZf/KWg3+dYfrDJEUa3XxuspiaI+ZsXyOFZ4reRYG1mxzcri75NJjMxETdlWitDhuqriLc0+aseZvwvq/NiaA== 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=5rFzKHsDaZ3RJcr6S1R91nXKIyUD9DkwKR71jQxND8k=; b=dIpkRhVFDpustSx+WM37wNn5vvbQAIGcDyaS8PgrbjLkRZOLF8uhZtjgiLLNyZIAxbtFyKAp0NuLXpO4hksImvaA9/aDp7gUdRao7t3U8q+Kr40alubtuLDzqqkqSpdykgcLvtYJsM4RCX4TUreGKYzeTRz431IAs+kQgN8S826+GcsRPjJ0lLN3D/vF1mjF3RQ2D9HZpj4y+5GaM70BNC6uaBhK/bqcXM9kyPPnsOgfvwI5hfyZBp+zl4zvIIy5NSc/mrQTMNWdi2pbnZMhsmnzbzF9SHB2rZ0xpIY9sne+6Ss+76nXy7p/HFbScrqeFHS3bVirwCv7qLp4bmWIlQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CH2PR12MB3990.namprd12.prod.outlook.com (2603:10b6:610:28::18) by DM4PR12MB9069.namprd12.prod.outlook.com (2603:10b6:8:b8::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9434.8; Thu, 18 Dec 2025 13:28:00 +0000 Received: from CH2PR12MB3990.namprd12.prod.outlook.com ([fe80::7de1:4fe5:8ead:5989]) by CH2PR12MB3990.namprd12.prod.outlook.com ([fe80::7de1:4fe5:8ead:5989%6]) with mapi id 15.20.9434.001; Thu, 18 Dec 2025 13:28:00 +0000 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Thu, 18 Dec 2025 22:27:57 +0900 Message-Id: Cc: "Danilo Krummrich" , "Alice Ryhl" , "Simona Vetter" , "Bjorn Helgaas" , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , "Miguel Ojeda" , "Boqun Feng" , "Gary Guo" , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , "Benno Lossin" , "Andreas Hindborg" , "Trevor Gross" , "Alistair Popple" , "Eliot Courtney" , "nouveau@lists.freedesktop.org" , "dri-devel@lists.freedesktop.org" , "linux-kernel@vger.kernel.org" , "linux-pci@vger.kernel.org" , "rust-for-linux@vger.kernel.org" Subject: Re: [PATCH 6/7] gpu: nova-core: send UNLOADING_GUEST_DRIVER GSP command GSP upon unloading From: "Alexandre Courbot" To: "Joel Fernandes" , "Alexandre Courbot" X-Mailer: aerc 0.21.0-0-g5549850facc2 References: <20251216-nova-unload-v1-0-6a5d823be19d@nvidia.com> <20251216-nova-unload-v1-6-6a5d823be19d@nvidia.com> In-Reply-To: X-ClientProxiedBy: TYCP301CA0053.JPNP301.PROD.OUTLOOK.COM (2603:1096:400:384::20) To CH2PR12MB3990.namprd12.prod.outlook.com (2603:10b6:610:28::18) Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PR12MB3990:EE_|DM4PR12MB9069:EE_ X-MS-Office365-Filtering-Correlation-Id: 9b229ae2-4d3f-4348-8de6-08de3e3943ad X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|366016|376014|10070799003|1800799024; X-Microsoft-Antispam-Message-Info: =?utf-8?B?cGt0c1FidkhBT2hkR0VhcHd5VDBwMjBvZ2c2U0JwcU1QejRDaGlsWDJUZXEz?= =?utf-8?B?UytXWnlCLzNkNHZ0Rk9pWmRXOStlOWlvaC9jYVFXajgvNTNnNGY3ZVZwTXRO?= =?utf-8?B?SVZ6TXhCMW5WcUVZYXJvM2M4bXVxOW1LcEwyUXUzSW1SMGpzeFZHVUh2bmVZ?=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ycti4i/SOHXv?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH2PR12MB3990.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(366016)(376014)(10070799003)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?VlVKbjNUQUtEdnl3T2IvaXpLekxST3FOS2hVd3llanJ2Ni9KSEZWejg4VnEy?= =?utf-8?B?MmlCNGdLVkQyVitmcnpRR2pKZnhoZ041K1pzc1lXdjdFTVNZOVMwMGFJOTBh?= =?utf-8?B?Yy83V1ltT1oxbHNGcUZhNUJSdld4VlNJVFl2ZVQ1VzNzeUE3cms4bmdhZHhk?= =?utf-8?B?dko4ZWU5MktwZEtMRVF1UHJEdW9kNHpKYk9pQkN0VU54S0hOYWZKZFlyWVY3?= =?utf-8?B?SGpNZDcwUHNsa2FQbUdiUWZNSFRxY0x6UVd0R0lDcUJDVjZ2T0ZGejQ4RHls?= =?utf-8?B?QjZ0Q05WSHRTc2J1ZXNTNXFFNDhEdFhrdklacm9iTG9jRXl6eitrU2FncnlT?= =?utf-8?B?Rmx5K1JHeXhHVzE5L1FxQi9pdXgwdVEvQjEyeGpTakFaVitWTmJxcEtNWUVR?= =?utf-8?B?eThwSURiL3UySkpFc2ZkZExneG1DRUdmbXNrQWZXeXIyM1A5dWthSUdDYkZE?= =?utf-8?B?bUczTjNjRGVQNjQ3YTZqUzBpQjBzSDBIZ0xxNFE5ZjZLeG5XRmlEMmFlRFpD?= =?utf-8?B?TGhEUTFvaEtuUDJZT2VtWVlEQU43ZXdOYnVTQlZCNnZ3U05lbW9ZTFNUazhx?= =?utf-8?B?c3NwTzJnMHpzS2VNNVRQVkNuVVI5MHNWV3dwS1RTb3hsRVFjUm9xTDJBbTk4?= =?utf-8?B?TGI0WHkxOUNLcXlYU3hMW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utf-8?B?RWFjeEZBZGdYUm1FRXNhVys4ZEhZbDZ5TmVScXM2eE9TZ2tVRnhBZGR6bFB6?= =?utf-8?B?UW1tN29Mbnl5TUVJR3hNSDRHaXlKU0ZDTGFTYnJuRElaaVFOTXAvYUFzOEdL?= =?utf-8?B?OGZyM2Z3RCtoNlVmSjg4emFuV0xEeDVyT1F4NW5hNTJITGtvQ1Vqd3JFL3Y0?= =?utf-8?B?bzA1YUpOdUNlNnZhZWpzd1VWVDBiSjJQMndlQUpmY2owa3V0R0NzRWQ5blZE?= =?utf-8?B?K2F4Q2JjeUxlaExKck5ISHkySGZkTXVLVTZrcE1sSzU3RjBiYWZNVERIRmJu?= =?utf-8?B?eUhZbWllYzhiSkxuUE5pQW9XbEpGRTd3ak9FVGNhUzI5SHB2VWlTdDhtd05p?= =?utf-8?B?UVJJWkZaRmY4cEI3dUN1dkJMd0pYS2hjZkNTcStudGU0T2dwcmFyazYrS2Nl?= =?utf-8?B?L1V4TzhLcE9MSkNwNG9zVzNVWXc2WkVwc0lleFRDUUZPYmttZ3o3UUFBOVRX?= =?utf-8?B?UXpyRnRjaXk5MkQwOHd5STJRckhtYk5ZRm0vU1FlcEJwR2ZqRGlidTQ4VzZh?= =?utf-8?B?cmNsbWtNZzNtMDZaSjJPZEVUQk1uNU03bE9wakxCT3NmNmRYZXdhMnRkb3Np?= =?utf-8?Q?iqWR8DhD3F5RYFQGKLuXF8QNinRH/H4mpWW211JmhJ2Y?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9b229ae2-4d3f-4348-8de6-08de3e3943ad X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB3990.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Dec 2025 13:28:00.6514 (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: 02Px0BN0bjKFmb6CGLzVbePgGP8VHu5jSLLlU+nfP0VPJfTOE1o+vnpt7hnE1uMq9U9C2ZFISGhoQELXw11MRg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB9069 On Wed Dec 17, 2025 at 12:39 AM JST, Joel Fernandes wrote: > Hi Alex, > > Just did a quick pass, will do a proper review later: > >> On Dec 16, 2025, at 12:13=E2=80=AFAM, Alexandre Courbot wrote: >>=20 >> =EF=BB=BFCurrently, the GSP is left running after the driver is unbound.= This is >> not great for several reasons, notably that it can still access shared >> memory areas that the kernel will now reclaim (especially problematic on >> setups without an IOMMU). >>=20 >> Fix this by sending the `UNLOADING_GUEST_DRIVER` GSP command when >> unbinding. This stops the GSP and let us proceed with the rest of the >> unbind sequence in the next patch. >>=20 >> Signed-off-by: Alexandre Courbot >> --- >> drivers/gpu/nova-core/gpu.rs | 5 +++ >> drivers/gpu/nova-core/gsp/boot.rs | 42 +++++++++++++++++= ++++++ >> drivers/gpu/nova-core/gsp/commands.rs | 42 +++++++++++++++++= ++++++ >> drivers/gpu/nova-core/gsp/fw.rs | 4 +++ >> drivers/gpu/nova-core/gsp/fw/commands.rs | 27 +++++++++++++++ >> drivers/gpu/nova-core/gsp/fw/r570_144/bindings.rs | 8 +++++ >> 6 files changed, 128 insertions(+) >>=20 >> diff --git a/drivers/gpu/nova-core/gpu.rs b/drivers/gpu/nova-core/gpu.rs >> index ef6ceced350e..b94784f57b36 100644 >> --- a/drivers/gpu/nova-core/gpu.rs >> +++ b/drivers/gpu/nova-core/gpu.rs >> @@ -291,6 +291,9 @@ pub(crate) fn new<'a>( >>=20 >> /// Called when the corresponding [`Device`](device::Device) is unbo= und. >> /// >> + /// Prepares the GPU for unbinding by shutting down the GSP and unr= egistering the sysmem flush >> + /// memory page. >> + /// >> /// Note: This method must only be called from `Driver::unbind`. >> pub(crate) fn unbind(self: Pin<&mut Self>, dev: &device::Device) { >> let this =3D self.project(); >> @@ -299,6 +302,8 @@ pub(crate) fn unbind(self: Pin<&mut Self>, dev: &dev= ice::Device) { >> return; >> }; >>=20 >> + let _ =3D kernel::warn_on_err!(this.gsp.unload(dev, bar, this.g= sp_falcon,)); >> + >> this.sysmem_flush.unregister(bar); >> } >> } >> diff --git a/drivers/gpu/nova-core/gsp/boot.rs b/drivers/gpu/nova-core/g= sp/boot.rs >> index ca7efdaa753b..e12e1d3fd53f 100644 >> --- a/drivers/gpu/nova-core/gsp/boot.rs >> +++ b/drivers/gpu/nova-core/gsp/boot.rs >> @@ -32,6 +32,7 @@ >> }, >> gpu::Chipset, >> gsp::{ >> + cmdq::Cmdq, >> commands, >> sequencer::{ >> GspSequencer, >> @@ -231,4 +232,45 @@ pub(crate) fn boot( >>=20 >> Ok(()) >> } >> + >> + /// Shutdowns the GSP and wait until it is offline. >> + fn shutdown_gsp( >> + cmdq: &mut Cmdq, >> + bar: &Bar0, >> + gsp_falcon: &Falcon, >> + suspend: bool, >> + ) -> Result<()> { >> + // Send command to shutdown GSP and wait for response. >> + commands::unload_guest_driver(cmdq, bar, suspend)?; >> + >> + // Wait until GSP signals it is suspended. >> + const LIBOS_INTERRUPT_PROCESSOR_SUSPENDED: u32 =3D 0x8000_0000; >> + read_poll_timeout( >> + || Ok(gsp_falcon.read_mailbox0(bar)), >> + |&mb0| mb0 =3D=3D LIBOS_INTERRUPT_PROCESSOR_SUSPENDED, >> + Delta::ZERO, >> + Delta::from_secs(5), >> + ) >> + .map(|_| ()) >> + } >> + >> + /// Attempts to unload the GSP firmware. >> + /// >> + /// This stops all activity on the GSP. >> + pub(crate) fn unload( >> + self: Pin<&mut Self>, >> + dev: &device::Device, >> + bar: &Bar0, >> + gsp_falcon: &Falcon, >> + ) -> Result { >> + let this =3D self.project(); >> + >> + /* Shutdown the GSP */ >> + >> + Self::shutdown_gsp(this.cmdq, bar, gsp_falcon, false) >> + .inspect_err(|e| dev_err!(dev, "unload guest driver failed:= {:?}", e))?; >> + dev_dbg!(dev, "GSP shut down\n"); >> + >> + Ok(()) >> + } >> } >> diff --git a/drivers/gpu/nova-core/gsp/commands.rs b/drivers/gpu/nova-co= re/gsp/commands.rs >> index 2050771f9b53..0bcfca8c7e42 100644 >> --- a/drivers/gpu/nova-core/gsp/commands.rs >> +++ b/drivers/gpu/nova-core/gsp/commands.rs >> @@ -225,3 +225,45 @@ pub(crate) fn get_gsp_info(cmdq: &mut Cmdq, bar: &B= ar0) -> Result> } >> } >> } >> + >> +impl CommandToGsp for UnloadingGuestDriver { >> + const FUNCTION: MsgFunction =3D MsgFunction::UnloadingGuestDriver; >> + type Command =3D Self; >> + type InitError =3D Infallible; >> + >> + fn init(&self) -> impl Init { >> + *self >> + } >> +} >> + >> +pub(crate) struct UnloadingGuestDriverReply; >> + >> +impl MessageFromGsp for UnloadingGuestDriverReply { >> + const FUNCTION: MsgFunction =3D MsgFunction::UnloadingGuestDriver; >> + type InitError =3D Infallible; >> + type Message =3D (); >> + >> + fn read( >> + _msg: &Self::Message, >> + _sbuffer: &mut SBufferIter>, >> + ) -> Result { >> + Ok(UnloadingGuestDriverReply) >> + } >> +} >> + >> +/// Send the [`UnloadingGuestDriver`] command to the GSP and await the = reply. >> +pub(crate) fn unload_guest_driver( >> + cmdq: &mut Cmdq, >> + bar: &Bar0, >> + suspend: bool, >> +) -> Result { >> + cmdq.send_command(bar, UnloadingGuestDriver::new(suspend))?; >> + >> + loop { >> + match cmdq.receive_msg::(Delta::from= _secs(5)) { >> + Ok(resp) =3D> return Ok(resp), >> + Err(ERANGE) =3D> continue, >> + Err(e) =3D> return Err(e), >> + } > > This outer loop can go on infinitely, lets bound it? > > Either outer timeout or bounded number of tries. Bounded tries better sin= ce it has inner timeout. Yes. And what we really want is a more generic way to do this, because this pattern occurs with several commands so far (and more to come). > >> + } >> +} >> diff --git a/drivers/gpu/nova-core/gsp/fw.rs b/drivers/gpu/nova-core/gsp= /fw.rs >> index 09549f7db52d..228464fd47a0 100644 >> --- a/drivers/gpu/nova-core/gsp/fw.rs >> +++ b/drivers/gpu/nova-core/gsp/fw.rs >> @@ -209,6 +209,7 @@ pub(crate) enum MsgFunction { >> GspInitPostObjGpu =3D bindings::NV_VGPU_MSG_FUNCTION_GSP_INIT_POST_O= BJGPU, >> GspRmControl =3D bindings::NV_VGPU_MSG_FUNCTION_GSP_RM_CONTROL, >> GetStaticInfo =3D bindings::NV_VGPU_MSG_FUNCTION_GET_STATIC_INFO, >> + UnloadingGuestDriver =3D bindings::NV_VGPU_MSG_FUNCTION_UNLOADING_G= UEST_DRIVER, >>=20 >> // Event codes >> GspInitDone =3D bindings::NV_VGPU_MSG_EVENT_GSP_INIT_DONE, >> @@ -249,6 +250,9 @@ fn try_from(value: u32) -> Result { >> } >> bindings::NV_VGPU_MSG_FUNCTION_GSP_RM_CONTROL =3D> Ok(MsgFun= ction::GspRmControl), >> bindings::NV_VGPU_MSG_FUNCTION_GET_STATIC_INFO =3D> Ok(MsgFu= nction::GetStaticInfo), >> + bindings::NV_VGPU_MSG_FUNCTION_UNLOADING_GUEST_DRIVER =3D> = { >> + Ok(MsgFunction::UnloadingGuestDriver) >> + } >> bindings::NV_VGPU_MSG_EVENT_GSP_INIT_DONE =3D> Ok(MsgFunctio= n::GspInitDone), >> bindings::NV_VGPU_MSG_EVENT_GSP_RUN_CPU_SEQUENCER =3D> { >> Ok(MsgFunction::GspRunCpuSequencer) >> diff --git a/drivers/gpu/nova-core/gsp/fw/commands.rs b/drivers/gpu/nova= -core/gsp/fw/commands.rs >> index 85465521de32..c7df4783ad21 100644 >> --- a/drivers/gpu/nova-core/gsp/fw/commands.rs >> +++ b/drivers/gpu/nova-core/gsp/fw/commands.rs >> @@ -125,3 +125,30 @@ unsafe impl AsBytes for GspStaticConfigInfo {} >> // SAFETY: This struct only contains integer types for which all bit pat= terns >> // are valid. >> unsafe impl FromBytes for GspStaticConfigInfo {} >> + >> +/// Payload of the `UnloadingGuestDriver` command and message. >> +#[repr(transparent)] >> +#[derive(Clone, Copy, Debug, Zeroable)] >> +pub(crate) struct UnloadingGuestDriver { >> + inner: bindings::rpc_unloading_guest_driver_v1F_07, >> +} >> + >> +impl UnloadingGuestDriver { >> + pub(crate) fn new(suspend: bool) -> Self { >> + Self { >> + inner: bindings::rpc_unloading_guest_driver_v1F_07 { > > We should go through intermediate firmware representation than direct bin= dings access? Only if the size of the bindings justifies it - here having an opaque wrapper just just well, and spares us some code down the line as we would have to initialize the bindings anyway. > > >> + bInPMTransition: if suspend { 1 } else { 0 }, > > Then this can just be passed as a bool. > >> + bGc6Entering: 0, >> + newLevel: if suspend { 3 } else { 0 }, Note to self to figure out these magic numbers. :)