From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from PH0PR06CU001.outbound.protection.outlook.com (mail-westus3azon11011025.outbound.protection.outlook.com [40.107.208.25]) (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 58A7A3101C8; Mon, 22 Jun 2026 15:04:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.208.25 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782140693; cv=fail; b=VzXPS8xohOmq+Dng+++Nc3+lw9Ly4ZUVKJeOmfxFr5rh58c0l4xPA2yGOgo1NBe9X/XuRLQZXiOQ/+cz0dbobQh7+0BwZ2o+lTurCRBbEHJ4//Hx7g8PyElSmRhUPh/L/DZNyrWaIUwP8lVskZ+rrizJ5hzwYf06QoHPk3WUWFQ= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782140693; c=relaxed/simple; bh=jdcSaSlWnk3El478l4Fy6nJ1Rf4GW8P48+G2CkWod7U=; h=Content-Type:Date:Message-Id:From:To:Cc:Subject:References: In-Reply-To:MIME-Version; b=T9waHCeJE3p/zEVPN+KD4vvgci8PU5+g/aOEFqUiv0h2pW/RTTL/HceZ9tjv8TF/79raKbBxZayS7We9eDnPR7ZY/2lbsIZFQ6w9nbl03SeSXbEq+Lr8g6Uv7mwbEKPjbof9MAkXODQC9HPYitHwDID6lSyZapVjHE6RFISKqbY= 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=j3xWgp1n; arc=fail smtp.client-ip=40.107.208.25 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="j3xWgp1n" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=j4zzIyYdbBJqtIZTlTYvPceniRp/hjGuT+L/UE1oHF9qScmpBlbJC1ve115B1hPn5x65JLBk2NSo+8pIiQQMxzque1AB3WGQcNFU3i/k0loD1MLcDhllW1kigoQ3Mr3WaVTIvmBFsfCc3TidnJ0neuaWiTYQ/uxGSnOJXO1bTQaU6LFQvpCByde15Ei5ZgEKlmnuIZeAWPW8iDw+bEmBHKujZ6JYcUkMY8WKVubBVTBXXa/GLyS7JNEtpDZBTlg13glEtfgkQ8xRI1x+3Leltx0Wah72cAR9QIy+VUxh1WYJx0jkTAV3r8lx7J29WrQyCRx0hEazh7aKAsiZfXnfSQ== 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=c4dAB//9V3Nx8nEkHHY8I/OXoQ0E+/8k7aGIZLFpYic=; b=nMcQRI2/FK6iKceMNgw4Pemw20igRv8d/SvjxZBCb+bGCiiWgkmm/8Q10Dd5ifUOdIiOntVMR+91BfTFhy1UbDKTN9C1a6G2iQNpcTeqhSuF+SUwNrdnK9ljhTBBYHfr8r0YbgVeR4ywAI///knVHTcP9BggiCUi+xvRyyYm0jaDm0FToUVrTL948iTesMv/A5d4823BkjXQjzCOk/f2/8ls+5XsZ4FKszmy0bcaeD0DjIns7Dd9dKrn6QUIrXIWwH5N1boLeuXyyONHeEXVQfX3pNoSgBBmIAoNnhhHSKijsrJxPDL2LMbFuBoiT/iIMgP7G2OsDWysZucmkL897g== 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=c4dAB//9V3Nx8nEkHHY8I/OXoQ0E+/8k7aGIZLFpYic=; b=j3xWgp1nFzNTPMsS7hMpIT+ajeR+EvMk9NJ/BcygPplkiHEQ5s2Hxm2PRPFoPQuZZkntGnqszAmkhAVdTIIkXxqL/8nm0HPC1D1ypae3EzM8haGksnUm4aqaNVZGD5UKUscw9Njb2BqJ8tVZUjcxJ47bxtjvWcUTzls+W/OEZUKehPLXNVM3DJ8g+SZLfaHewfVPEtiOsPkHnQEA9d+EmzftjbY1vtr4x5TpuQJeKnVhNY7D22Dq+wGbSuLjuZmeYlgfM8v1wnR/CtLJQgwhIkUh1Msu4XGe9iN3XYo4fcLcIdop8bXxGcLaKWtaY1BH2v1zKNrRmnKdJeFOJOeaXQ== 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 DM6PR12MB4313.namprd12.prod.outlook.com (2603:10b6:5:21e::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.139.20; Mon, 22 Jun 2026 15:04:44 +0000 Received: from CH2PR12MB3990.namprd12.prod.outlook.com ([fe80::7de1:4fe5:8ead:5989]) by CH2PR12MB3990.namprd12.prod.outlook.com ([fe80::7de1:4fe5:8ead:5989%4]) with mapi id 15.21.0139.018; Mon, 22 Jun 2026 15:04:44 +0000 Content-Type: text/plain; charset=UTF-8 Date: Tue, 23 Jun 2026 00:04:40 +0900 Message-Id: From: "Alexandre Courbot" To: "Eliot Courtney" Cc: "Danilo Krummrich" , "Alice Ryhl" , "David Airlie" , "Simona Vetter" , "Gary Guo" , "John Hubbard" , "Alistair Popple" , "Timur Tabi" , "Zhi Wang" , , , , , "dri-devel" Subject: Re: [PATCH 3/6] gpu: nova-core: gsp: move boot code into local closure Content-Transfer-Encoding: quoted-printable References: <20260619-nova-bootcontext-v1-0-45193cd0a2e5@nvidia.com> <20260619-nova-bootcontext-v1-3-45193cd0a2e5@nvidia.com> In-Reply-To: X-ClientProxiedBy: TY4P286CA0044.JPNP286.PROD.OUTLOOK.COM (2603:1096:405:36e::15) 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_|DM6PR12MB4313:EE_ X-MS-Office365-Filtering-Correlation-Id: d97c30b5-26b4-4e6b-cf7e-08ded06f97ab X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|10070799003|1800799024|366016|376014|7416014|56012099006|3023799007|11063799006|4143699003|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: +umEuMKCRAT1akODWznMpao2a4wH+orpRZGbB38A6Y+d08F1If6ZlgsMxhYz39VyuDDjCjxl9EPirAe3tFAUnSwW2EL2drrAiDrnK8ce0aiU4Rym9BxGINXIK0vOuoZbE8p3N3fTc1w2qzc0IGJLOlpJ4SlEPxg6UIDumHoZOCE6nhYsI2N4v+Fwq5Piiks7IImOSHBPOyHuKC/HeqXA9OT1I2AS9h/7i1wyK4ehTCC6G99NgVKL6+Z0MFmkqgJ6ISuJLs171O9ex9vvQjomRjNZZJZUJqJhJsz3ulSmt7YJ/Xq7qzvIyWOfJFutUT1vjglGRcSbUIib6cNyfshXAHrOmpmppLCvHcZkH2+4kvRo4OsMvqsDyzN+32dbOt/f5mIh8LayrTc/3PtlaiF9ehkAck/hDlPXsljCrdHuaqOcgPYREmR1Heyvt4AyZIbYggQv/W4gyHWD8St1A9c2R3ejJ3x7jjf8l+M7LBv2/rOhexNcYCRF2lTn3l0O64saM0duxZOJaaKynprb732ISLRcO/21NGrxPapkK+YJhbSVcAWw3QLBb6fvO/WVmDctglzvzpp3bOxadoRy8my2NXG2xla7plX0/T9fzHWHKwz7BZG+bzMBeMSHsJSzXkN3g1mPdrW6nsCqkL1Lg9yFUM9ZMiWONoIVvUNuSkGKuB4= 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)(23010399003)(10070799003)(1800799024)(366016)(376014)(7416014)(56012099006)(3023799007)(11063799006)(4143699003)(18002099003)(22082099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 2 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?M1R1MzZIR092V3BINUZWMjM4R21BaUd6Q091V2pWc0RWWGU1SlZtTk9ETG13?= =?utf-8?B?TGdRU2ZkN1lERGdtZjZ0eWl2bUtiNTdxZ29tZ3NOb1VuYlNjdFJFUnltYXVM?= =?utf-8?B?SmQ3NmZId3VLc1JZU2k0SWlacXRneVdvTHRSd2pJSG5nYmdoOXFsRzlKTTQr?= =?utf-8?B?d081NCtQa2w0bkY1WWEvUFYwWThTOXNkTWZnNktvSnQxREVMbHVkNWtUdW4r?= =?utf-8?B?TTZraDBFTEVaMzN3V2xibURSUzFJWjZEbjVod1dyRmpxcVY4MFZZbWd1ZkdH?= =?utf-8?B?RE9aOGVUamEvRlQweGFRenZyTHhtNm92Y2daNGNHY1BBcldEQzdnV1d3U1Jj?= =?utf-8?B?Z3dsVnIwemZ5cExMVmo2WXlKck41WHNSdGVkcEJCaDhSc215QzJJT1ZoRkpr?= =?utf-8?B?V0ZhUC9OS25aRmpOamswdnlVaUwx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9sME16RXNZVHlQ?= =?utf-8?B?cVhxdU5GZk96YWJyeXBYMXZZd0J0Q1NrMHFKMkpEZmtLMHlHZUt4a3Ruamti?= =?utf-8?B?dVRSRUVTZHZ0WG82Qkt4ZjF2SXczY3crQ1JJV0tmYVBINnBTU2I1QXpCKzBa?= =?utf-8?Q?vbyVKB+tGQxxkiEFA5S2Ot5nVP/xcLRKMSttWM8S1WCOq?= X-MS-Exchange-AntiSpam-MessageData-1: yh1dY9EwfJIZcg== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: d97c30b5-26b4-4e6b-cf7e-08ded06f97ab X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB3990.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jun 2026 15:04:44.1625 (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: kRDgp5DLGq52PDXD5uPOSXHPPiTNpeTMxtCg+jmVci75JqjkWd9FLy8FSES78+Kyxmb0ZQvMhacfuI8V+mPrSA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4313 On Mon Jun 22, 2026 at 4:57 PM JST, Eliot Courtney wrote: > On Fri Jun 19, 2026 at 10:42 PM JST, Alexandre Courbot wrote: >> The next patch aims at replacing the cumbersome `BootUnloadGuard` with a >> more local and less intrusive mechanism to run the GSP unload sequence >> upon GSP boot failure. Doing so requires running the boot code in a >> local closure, which changes its indentation and would make other >> changes difficult to track in the diff. Thus, this preparatory patch >> moves said boot code into a local closure that is run upon construction, >> so the next patch does not need to re-indent code that changes. >> >> This is a mechanical preparatory patch to make the next patch easier to >> read. No functional change intended. >> >> Signed-off-by: Alexandre Courbot >> --- > > I agree with removing BootUnloadGuard, but I think it's not great to do > a bunch of lifting into closures then manually handling the result. It's > error prone imo (we already had several bugs relating to this kind of > thing). Instead, what about just using ScopeGuard directly? This lets us > avoid lifting into closures (which is a bit noisy) and avoids manual > result handling for failures (which is a bit error prone). With the > `GspBootContext` it's fairly easy to do now: > > ``` > let unload_guard =3D ScopeGuard::new_with_data(unload_bundle, |unload_bun= dle| { > let _ =3D gsp.unload(ctx, unload_bundle); > }); > ``` Yes, initially I wanted to use `ScopeGuard` but ran into issues when trying to make the references mutable. However it looks like you have been able to overcome these issues, thanks for taking the time to craft a patch! > > I confirmed that it's also compatible with the v2 of this series that > has the mutable Fsp - you can stash the context inside the ScopeGuard > data (then making a &mut reference to the stashed context for brevity) > or have a separate unload context type that doesn't use FSP or something > (could later be type parametrized along with Gsp, for example). > > For example here is a rough diff on top of this patch series (you can > change the Result> returns to like > Result> if you want to centralise teh error > handling of a failed unloadbundle although currently it can only fail in > one location): Yes, looking at it it looks like a cleaner approach than using closures. The only thing that I saw as a regression is that now each HAL needs to call `Gsp::unload` itself in its own `ScopeGuard`. I don't think that's the HAL's work - `Gsp::boot` should be the centralized point where this happens. But we can make both work if `unload_bundle` is passed as an output argument to `GspHal::boot` instead of being returned: let mut guard =3D ScopeGuard::new_with_data((ctx, None), ...); let (ctx, unload_bundle) =3D &mut *guard; // `unload_bundle` is a mutable reference to the // `Option` in `guard`. hal.boot(&self, ctx, unload_bundle, &fb_layout, &wpr_meta)?; The boot method can fill `unload_bundle` early, and if it returns an error then the `ScopeGuard` will be able to use it. Also, and that's nice, the HALs don't need to use `ScopeGuard`. But output arguments aren't really something we expect to see in Rust. Another alternative would be to separate the unload bundle construction from `GspHal::boot`: let unload_bundle =3D hal.build_unload_bundle(ctx, ...); let guard =3D ScopeGuard::new_with_data((ctx, unload_bundle), ...); hal.boot(...)?; It removes the "1 boot -> 1 unload bundle" symmetry, but on the other hand it also splits concerns more clearly. And it removes the awkward return type of `GspHal::boot`, which come to think of it was another smell that things were not in the right place. The main drawback I see is that we now need to build `Vbios` twice for TU102, since it is needed both for the unload bundle and for booting. But the solution is the same as what the v2 of this series does to `Fsp`: the BIOS is a GPU-wide subdevice that is likely to be used elsewhere, not something to be confined in a GSP HAL. So I say, let's extract it and make it also part of `GspBootContext`. How does that sound?