From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from SN4PR2101CU001.outbound.protection.outlook.com (mail-southcentralusazon11012071.outbound.protection.outlook.com [40.93.195.71]) (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 45119457E45; Fri, 11 Sep 2026 11:18:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.195.71 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789125512; cv=fail; b=o08A21rZyRAFnQ4kVhEMybkie2VrZoDVlgSYCKw5ZsKmrnpC6hG6kI38o/0pnO4plpqHiADWjQmQJjWHj7WfpeqIRsQ6hVWv9q+po26HRDKBgF6gyTGMoIgpWGypcPYTcavh+INnEvuHWO/a6sYpNjc31uSjG3uUAcbP+iqPuxg= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789125512; c=relaxed/simple; bh=6HGbU93HwIizUjXVmwjpHN+GIpmykiwFIrUSNONQx9I=; h=Content-Type:Date:Message-Id:Cc:Subject:From:To:References: In-Reply-To:MIME-Version; b=SYDV9aXZsBuDbErNKpskIYikWlhrF4lzb4BRhWyysGkLwg+7O6YoXQU+5rf8xKgH81ApZa1QXM2oSNQO76eu3laFiKqxKIG2iv4NE1zLwz9US+86KlFeOXtzq6PJPNRLseYXiGvnk1Vx294QdpEVt+cZc29ih1MwE03t2RoeWHU= 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=pI8eYSHi; arc=fail smtp.client-ip=40.93.195.71 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="pI8eYSHi" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=B/pGyHraacd7SvYI6u/GrCv1QtbdBt2QUYhSgaYYNPsp1SLaBpXUbOsjoh/lmQnu537yh4qcnX0nAQlIUnci2bRn3USFfouE8dlyfb0Fz9c6bRBeOEPuv+SNLjTcxwET4s2pe9f4K2ZizVMnZp6IHPV+RrX/PH7U5pm168WCKg3Ozwra9Wh+sH0Hgo08TevpHeWk6osmVt1j4rXyCN1aisoG0Ky+68Bu/nfsKRupINEp266eVmHbuTVebNgiroJxtQ2Icxd5I0bioPMCIT2DERZVK+9q1QsKuqQzIY1XQujLHDABz4z59LV24b3mii8aClnItKvng2ntrDEkPAiWsA== 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=hafCoMGT2yi/aNJd3ECDQBlQRBJosGNrkmau4HUUGYE=; b=gmiWE4589Aa5q83DBMGoLP3WB57IE8r6249pmiAhHWTOhIIVlIIMH6m66k/Ig6KHd2hgAFpFmbFvdAELooBJ0VCZ7jZIEV3PuaI1S8MRXwTJas58ek11G8A+9ztAjhM994xRlLCiT1qxV1bN2mEpJ6mkcN2Z8WOPdnZDNmEQ1h9w8q7TpWPdebk+y2kT/3oPhSP04vPmeZkTEdMC8BdHhw393lKlWjlZEaRwxtgbBIQnVxzgkWagMYFci83vY0OhDDhrSB+4dsccHaPtTskRWKR/BRQ+7InVeD0W51v75M8eAIy1D9G1a5MN8/P1UCoNYmoNiuLKgUilgiT2THjQPQ== 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=hafCoMGT2yi/aNJd3ECDQBlQRBJosGNrkmau4HUUGYE=; b=pI8eYSHiCQk3Kn0Bvy69FyJOeQbFAyuTbpd/vtr0XLYG15vtxWajsGsd+3I7rNAiFl6cCxzwpMILhCI+SsqmdAl5nqOheKMJgtl7wK1xfCpcGDRcXo3Fy+hviHtCC1+EQxLb2xIbKdDdUMYvua8UZwnerLRIKj3tbxrCbwJ/kr/KW8LLhdDzKUIKrvuTvQT2nqdjHp62roScQoELpG+iU9MI6e3ZRejMnwiWV5Xmp2xrJUw6pCqf9W4g4UYLYMIcqVg2Nb1ZTDYjZneOd7pqW/QdnkdZTOSWgvHsaJnhyF35+1H9uiRlP0h2kgy9zbXADqPnYwzgb7VtR3t3eFyM8Q== Authentication-Results: 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 IA0PR12MB8975.namprd12.prod.outlook.com (2603:10b6:208:48f::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.406.9; Fri, 11 Sep 2026 11:18:19 +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.0406.007; Fri, 11 Sep 2026 11:18:19 +0000 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Fri, 11 Sep 2026 20:18:16 +0900 Message-Id: Cc: "Danilo Krummrich" , "Lorenzo Stoakes" , "Vlastimil Babka" , "Liam R. Howlett" , "Uladzislau Rezki" , "Miguel Ojeda" , "Boqun Feng" , "Gary Guo" , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , "Benno Lossin" , "Andreas Hindborg" , "Alice Ryhl" , "Trevor Gross" , "Daniel Almeida" , "Tamir Duberstein" , =?utf-8?q?Onur_=C3=96zkan?= , "David Airlie" , "Simona Vetter" , "John Hubbard" , "Alistair Popple" , "Timur Tabi" , , , , , "dri-devel" Subject: Re: [PATCH v2 6/8] gpu: nova-core: add NVKV typed encoding From: "Alexandre Courbot" To: "Eliot Courtney" References: <20260827-b4-nvkv-v2-0-0de9d5c8658c@nvidia.com> <20260827-b4-nvkv-v2-6-0de9d5c8658c@nvidia.com> In-Reply-To: X-ClientProxiedBy: TYCPR01CA0199.jpnprd01.prod.outlook.com (2603:1096:405:7a::13) 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_|IA0PR12MB8975:EE_ X-MS-Office365-Filtering-Correlation-Id: e1d3b4bf-c564-49ad-8602-08df0ff661b1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|23010399003|376014|7416014|10070799003|1800799024|18002099003|22082099003|3023799007|5023799004|56012099006|11063799006|4143699003|10067099003; X-Microsoft-Antispam-Message-Info: BBpTYrKKc+L9Hf7h6nc5TJpIdY/wJNXTi6L1gOTfbqKAI87UW1z52Zoi+0Ho6wQezEvhrdV6Riexi8OEkRSizYS7H4X6QqDAXwRZy6rO7LkIkrEbn4hdz8KkKrOroN0xpqeOfHPk96L7NfGy39G3UaO4bQDGVkr9l09UYUoHSJsv0zPaFU/rlhWfDve9DMwU+rEEbpBIVpLurR8CJ1EQGKL1lGRNoDqP5ledHiORa7MJocfxd4XGfu+1Gwv80KA2nXwnd5wF9wBqvJf8VC0iqmJtNlcmFYWvfxx9NmibfPq8AjpeRdRBF/SXHlzVGg1hBZFMiQ3XK4d84QaXrPPk9TdEFmjLMaPDg+F3WoqhomgWaz8fgcgfpKz5C1RoUS3wCeYhRWVrVKRTpeG6ehY8MPsIDDzSoZzUmoOMrGh0zUSg077qXV+WRpeIFTsvHAm69ppxdgysMctsUEQv4GIAu7i1ZdRIsXVJV7A4dLf39WlTGLAHqNrp3e9x0aymkacHaSbkqpMR12Wfv/hutX/mmlrjwtF0oBbrzgkwEv9OPw8/OrUNeGW3gIF35+subJCuqhhutvCGAx/1AefnGYGmxcfAb8vrXiMnYYb0CUhDpDVCRCJPCynmfLSu49bjqFhclSIvknAi8xEPyZx3aqDzc+NWRPZeQ4oAs+FL+yRJpCs= 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)(23010399003)(376014)(7416014)(10070799003)(1800799024)(18002099003)(22082099003)(3023799007)(5023799004)(56012099006)(11063799006)(4143699003)(10067099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 2 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?TXoxQkU4VGZvOHRlbXd5V040azZaMzExcjlwZlp6R1ZDaGNtN0VXU0NxbFh6?= =?utf-8?B?OTcvMjdJdlpqOXo3TWJreC9UQktCaGRacWcyY3RYVG1qUFJmeWJ2UklLVVpS?= =?utf-8?B?TXdySzBxaHFIT1R3VHcrYS9abXV2R3V6QWZTeDRnbWVSTU4vZ2pIbTdzR2hl?= =?utf-8?B?NDlPYzRHL1VRY1lFRUVCKzhEZVVFMmptZ0o0R1l3OGxXc1lONEsvM0R3UUg4?= =?utf-8?B?Z1ZSakp3K1ZMRXUxTENPVldONU5tMFR2b0J1Q3JNRStmQ0dOWWRZZ05y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VZcS90MmhaMlVEbExwN3Rxd3FGeFFjdXBQckVvOUdpdFlHZFR5bFFn?= =?utf-8?B?UXplbVJRVEJKRnpRZytlbDRCZ3JtUmg1MHh0WFNrM0o3SWM1MlRTQmpWeG80?= =?utf-8?B?U1YyK3FPbHQ2eTNGNVBxYjk2bnhEVjNFZ1Z3NjY1SFNxSXpvZWwzcXk3eXM3?= =?utf-8?B?cXg3dXo4THlONUhPdU5yN0FGN0dFNHdkSzZPTkpXSk82ZXlybnFBZkZ5MXBU?= =?utf-8?B?MENMZEJXeDBoUDEvVDF0d251VGxyM0VUeHAveTZ2Y2NUSndwVWNyZlVnK1V6?= =?utf-8?Q?61UaA7uPZ+kBzdgcZ5pFQP8O12BxpjH3rZ0gPnZbJKorY?= X-MS-Exchange-AntiSpam-MessageData-1: AXXBKRh/UYgj8w== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: e1d3b4bf-c564-49ad-8602-08df0ff661b1 X-MS-Exchange-CrossTenant-AuthSource: MW4PR12MB6873.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Sep 2026 11:18:18.9283 (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: fMEgTxkRg3ok7g1okTlLnnBTophYx8OQuoTbASANSYHG2DUiFSlJNBiUxX1ogEd1ZrcVnNP2Sx+zMhudW4ORfw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8975 On Fri Sep 11, 2026 at 2:28 PM JST, Eliot Courtney wrote: > On Fri Sep 11, 2026 at 2:17 PM JST, Alexandre Courbot wrote: >> On Thu Sep 10, 2026 at 5:10 PM JST, Alexandre Courbot wrote: >>> On Thu Aug 27, 2026 at 11:12 PM JST, Eliot Courtney wrote: >>>> For struct-like GMCAPI messages encoding field by field manually is >>>> noisy. Add some type machinery and a macro to automate encoding of >>>> struct-like messages. The `Encodeable` trait can be implemented by any >>>> type to say that it can be encoded into an NVKV `Encoder`. Add a simpl= e >>>> `nvkv_encode!` macro that works on structs and encodes each field in >>>> order. Provide some base types, such as `Key` which statically >>>> associates a NVKV key with some value, to avoid having to make a lot o= f >>>> newtypes and implement `Encodeable` on them. >>>> >>>> Signed-off-by: Eliot Courtney >>>> --- >>>> drivers/gpu/nova-core/gsp/nvkv.rs | 49 ++++++++- >>>> drivers/gpu/nova-core/gsp/nvkv/encode.rs | 178 ++++++++++++++++++++++= +++++++++ >>>> 2 files changed, 226 insertions(+), 1 deletion(-) >>>> >>>> diff --git a/drivers/gpu/nova-core/gsp/nvkv.rs b/drivers/gpu/nova-core= /gsp/nvkv.rs >>>> index cbeee7f376b6..10dcbb9e602c 100644 >>>> --- a/drivers/gpu/nova-core/gsp/nvkv.rs >>>> +++ b/drivers/gpu/nova-core/gsp/nvkv.rs >>>> @@ -10,8 +10,13 @@ >>>> //! naturally maps to storing a &str with the GPU name. >>>> =20 >>>> #![expect(unused_imports)] >>>> +#![cfg_attr(not(CONFIG_KUNIT), expect(unused_macros))] >>>> =20 >>>> -use core::ops::Deref; >>>> +use core::marker::PhantomData; >>>> +use core::ops::{ >>>> + Deref, >>>> + DerefMut, // >>>> +}; >>>> =20 >>>> use kernel::{ >>>> alloc::{ >>>> @@ -92,6 +97,48 @@ fn deref(&self) -> &Self::Target { >>>> /// The index of an NVKV value. >>>> pub(crate) type Index =3D Bounded; >>>> =20 >>>> +/// A static association between an NVKV key `KEY_ID` and the storage= of its value. >>>> +/// >>>> +/// Use with the encoder or decoder macros `nvkv_encode!` and `nvkv_d= ecode!` to let them know how to >>>> +/// map the value `Key` to/from encoded data. For brev= ity, `As` inserts an additional >>>> +/// conversion (`From`) to avoid having to implement [`Encodable`] fo= r many types. For example, >>>> +/// enums that are easily convertible to a u32 can have `As =3D u32` = and rely on the existing encoding >>>> +/// for u32. >>>> +#[repr(transparent)] >>>> +pub(crate) struct Key(pub(crate) T,= PhantomData); >>> >>> Does the `T` need to be `pub(crate)`? The series builds fine with it >>> being private. >>> >>> Also the relationship between `Key` and `IndexedKey` is a bit unclear >>> with the current type layout. IIUC `Key` is basically a specialization >>> of `IndexedKey` with an index of 0. And yet `Key` is declared in the >>> root `nvkv` module while `IndexedKey` is in the `encode` submodule... >>> I'm also wondering whether it would make sense to make the relationship >>> completely explicit by making `Key` a newtype embedding a `IndexedKey` >>> with the invariant that the index is `0`, but not sure about that one s= o >>> your call. >> >> Ah, I guess that's because `IndexedKey` is local to `encoder`. In this >> case keeping it there does indeed make sense. After complaining about >> the visibility of other declarations, I should have noticed that one >> too. :P >> >> What worries me more is the fact that no index larger than `0` is ever >> created. This looks more and more like a bug to me. > > We currently don't send anything that wants an index other than zero. > But, in the future we will. The way I did this so far is by having > 'IndexedKey' which represents the most general thing that can properly > encode anything accepted by the NVKV format. Since it's cumbersome to > and rare to use, I added Key as a wrapper on top. It would be possible > to hard code 0 in the index and only have `Key` but then we'd just have > to change it later. Since nothing wants to set a non-zero index > currently, it's private to `encoder`. But surely we should be able to test the non-zero path, even if we don't have any real-life user at the moment, right? As this is part of the NVKV spec, we should ensure this is correct. If `IndexedKey` is supposed to move down one module when it gains a user, I think we should place it in its expected destination from the get-go.