From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from CY3PR05CU001.outbound.protection.outlook.com (mail-westcentralusazon11013022.outbound.protection.outlook.com [40.93.201.22]) (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 C22D32BEFEF; Wed, 3 Dec 2025 05:59:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.201.22 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764741592; cv=fail; b=srePA95/vQ5WKthVQWUpbemZKSVvsPQ0OMwjojgO7KlSm5ozTo2o7bR/DF+gSmNEIoqJKbeQjL0eJNobZSSuGrR9sz1ciyOwiThsqf+WNqPC4pQENQ8lKq02Uq1haWDCpQphT7ffeZ1XKyiATCQEYMH/V+I7YuSyd1VMgQej+XA= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764741592; c=relaxed/simple; bh=S8dFMz1nmoXwbCVaS2IEKS7/djFfy2i/pc4is1m16HU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=V4s4WF/aeIdHUt3XLZRajLPO9Wyqv4iGyzoKGDDLcd7LMK7m2a2QF9EUWB71FUPjrWJokeaY82g7RcNzmAYV7SbH0tIdHwIFrMeJrjFTmT2nB+EC1fOyibGKIrT3QUzJmQFhcdxYi63Mo4DFB4iFMKTZhx8gV7R/FHbNB63v6z0= 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=uo8B3x/m; arc=fail smtp.client-ip=40.93.201.22 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="uo8B3x/m" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=NYwQ1YeiznXjb0OROkGQrOtZE6+20zViUWWyY3gCf1ID4/wCRrr2w63R7FVtsCY4rXtYnpmOGX0ZSRKRr9B9mzOr2jlwNdBriM1QUAclHiFklq3IIjAbWoSJF/LMJg/srCH8qsi/xCp5F0LrxmputQ73D5jCgo9f3UAW196bdbJq/4SofBfCI42rrZihXY6qmP892wC5NSBEDhmWg8KlCqSFxUqKTmqgWyZ3i/HTJo3kSkwqUZZ9ISFPhn4eoiuIMrtUyQ+kvbw5gJ6irzH9z3r1qxcHcbgMZHXzq32p7gDlwg04JQADrY9p+Ycvzqku0jQl5ZACALvt60f2dZf+Iw== 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=d97c7DCQLklRIH9zlzr3fxq7AnL15SQKze5w9FarKFY=; b=v1kFj5hA7DPaV4GeryagCTscx6MW4uaulhO9Hw4mHo6p781UcJEeaRil/1bkLAdeevGof/2r06wigFLz6PXNserQWdBsWmpIcVR2qVxQFUpzTVs0ptcJeLKLpxSxFwH/KL7VfkW40XAoS/mCHZKhgl69V/mdTcbiyisETesX8EzKnLKZdkTdYTZYli/nb7wrdFTUr3+F1GYsKmXeGuTBgWV0zeXYivm88CLQeQprDByqnylc2Y6C+i1vZuqUm/cbDZ5T/V231TmgieJ5H/a6x6ujB0sK1eUPHcsq4KBErtD/JS7yOMbdvh5L7p83FrtZv9PMOURhQhSamS19ZnvZ5A== 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=d97c7DCQLklRIH9zlzr3fxq7AnL15SQKze5w9FarKFY=; b=uo8B3x/mBA/BwY0823vgP6RUNNj1GYkthKV9Xla3//28UwHaF6mXOXrG7SLJxlWvVmRRgd3utivs7FkB6kTy/7xkkga3xl0src5RsXnvAh+mtneh55uO5Maoe7kEaRVcsGcxjzybGwao82N5YTD0dXlTO+NUrCHaZ8bFXGe7A/MwmIsCdrsuswJa97aF2wcmg2I3EYVHabnG9048r9vYy0OVh86PzKiRuWogXFMi3dNNcTmPLcaNTxbd1kaCFXA8zrj+9uZeauRlrEEaK50qngfKOftJWMQpFcIafyw+iz6pJt86VEF5Xa9qqW0Hr16mRBm2MaxpyUgbu5jKn1uxLg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM3PR12MB9416.namprd12.prod.outlook.com (2603:10b6:0:4b::8) by PH7PR12MB8180.namprd12.prod.outlook.com (2603:10b6:510:2b6::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9388.9; Wed, 3 Dec 2025 05:59:40 +0000 Received: from DM3PR12MB9416.namprd12.prod.outlook.com ([fe80::8cdd:504c:7d2a:59c8]) by DM3PR12MB9416.namprd12.prod.outlook.com ([fe80::8cdd:504c:7d2a:59c8%7]) with mapi id 15.20.9366.012; Wed, 3 Dec 2025 05:59:40 +0000 From: John Hubbard To: Danilo Krummrich Cc: Alexandre Courbot , Joel Fernandes , Timur Tabi , Alistair Popple , Edwin Peer , Zhi Wang , David Airlie , Simona Vetter , Bjorn Helgaas , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , nouveau@lists.freedesktop.org, rust-for-linux@vger.kernel.org, LKML , John Hubbard Subject: [PATCH 10/31] gpu: nova-core: don't assume 64-bit firmware images Date: Tue, 2 Dec 2025 21:59:02 -0800 Message-ID: <20251203055923.1247681-11-jhubbard@nvidia.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251203055923.1247681-1-jhubbard@nvidia.com> References: <20251203055923.1247681-1-jhubbard@nvidia.com> X-NVConfidentiality: public Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SJ0P220CA0026.NAMP220.PROD.OUTLOOK.COM (2603:10b6:a03:41b::30) To DM3PR12MB9416.namprd12.prod.outlook.com (2603:10b6:0:4b::8) 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: DM3PR12MB9416:EE_|PH7PR12MB8180:EE_ X-MS-Office365-Filtering-Correlation-Id: 43279a9c-cc64-41a9-41a8-08de323125ec X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|366016|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?539oiJAW34fgV70GbVmdFwNuPY3REw1WdkTJ5Ya3FqukUSoozM7sEwQsBo1h?= =?us-ascii?Q?hXucmUthIGj+lzqSx9pum7Wi2rkFHhKfUw4bL9pCw0IWZyW4D2qWFCmasmPB?= =?us-ascii?Q?d/3qyOYU+zzX0fZE7VDVAIYE13h7aDgRpLYh5V5LESQMZded7tzi1QyZ0sLw?= =?us-ascii?Q?brMw2xPnD3ESN+rKX0y+Lz8jGjCY95jVQzhu/bT4enlQLh7VmNLE87aVmE9U?= =?us-ascii?Q?jFlejUGWgcb0xdv39jHk+i1UIxIbqUBMuwg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rNLdKM/2z8pFvKKCIPoWpcq7an6jjxzarZTyJRDQzT//Qne9eUPfY?= =?us-ascii?Q?re+RtKP6msIwIqx3VKqVFfuzkMfN2odqgXBVqr09n8XwzJmiCmuUFmr9g6dL?= =?us-ascii?Q?EjRmnXelEJvzhaS7crLfR5ab9HaXfvlFzZkNqyNlkTu/KG5vqeHvYSF0EcMA?= =?us-ascii?Q?J7N1TXTc/Jroivmzrr5NeeM+BeVhklUP1kfUj9e35fWuMmtIWw3xAjLB4OX1?= =?us-ascii?Q?uUUCXPuHvhVZCwzqW1fGmfzO+wx6VJZzPQ9u/H+9KTdhT/lnIPEXmFf8+LAG?= =?us-ascii?Q?hYQ+oyLW+O8abNDq0YtguE6Pqf/UtY+Y?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM3PR12MB9416.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(376014)(366016)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?yP2/KpVsGOVKyJPnW+6LYegrAcChQA5UZLCwsx6I5+fUyyRY6RJI/yoGP878?= =?us-ascii?Q?2V3I0o5TVteo+CuTfjBj5V5Pkt3kAsizy2pBl8UrUNvvWnAxHxNyG0+vxm6i?= =?us-ascii?Q?jM2F4ZjBs7tbko+2PHw6f3YvdaCjxDy6VXVetwDyLElSheqkD3ngCNuSt2B7?= =?us-ascii?Q?3PCPeIcQYHS/ZCNLIj6sqZi/UTTlXJ+9X2/djixnxu9DsVXmqM8cGsnLdcMR?= =?us-ascii?Q?jiM9BVBWFDhsWDyxr5AdfRHSKQCvzO4mMo6GtKNJ8Yyt7PVR2PnzqFF6VrRS?= =?us-ascii?Q?L/oQyvSMl+MCcCNLtr5LMR3IREOIRI1LLHyZiK6IODJHCOyk19SHjEbXFTcA?= =?us-ascii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/r+rSUZpDYr+fpeY+MJCgL5X0v?= =?us-ascii?Q?mViKSJa4MbZhA6of4d5xp4i9Krn2Xrogktr+7K5HzR/8M8Bh3jZ5ANuRihsF?= =?us-ascii?Q?cJ1a+KXaCaFVmC31pFnfSQdJGakt3Y86igApgdOy2JdmyI6CGBvbDwVBTfvr?= =?us-ascii?Q?aXv3xOdM8SDoV4wm7QUR9/gwNSn779HyCY6UOFv4gUW7C738zsMCfP1+z8BW?= =?us-ascii?Q?BFsLLy0sogHRqfbLH+4SbL6JWoa/B5OqhaXbICP404w2PNyQuOk5elEhri6I?= =?us-ascii?Q?c2AA91tfVYiJoVB7ABkj98Vd0m+W3XQ/ZaczFJz2kCcr3g8YfSCyAVlwK4e2?= =?us-ascii?Q?CbZnCybNb6O6Z6/c6VVIJKkREUHNbkw7wHjZLvNW?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 43279a9c-cc64-41a9-41a8-08de323125ec X-MS-Exchange-CrossTenant-AuthSource: DM3PR12MB9416.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Dec 2025 05:59:40.6010 (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: LYisyQCznJy5tUM6b5eeLw0gba8kqx8G+eklsqtmmgBshvnUjeFP9/y4gCwLLtn0Tx+RWllf7s+g3vMLTrEAOg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB8180 Add ElfHeader and ElfSectionHeader traits to abstract out differences between ELF32 and ELF64. Implement these for ELF64. This is in preparation for upcoming ELF32 section support, and for auto-selecting ELF32 or ELF64. Signed-off-by: John Hubbard --- drivers/gpu/nova-core/firmware.rs | 118 ++++++++++++++++++++---------- 1 file changed, 80 insertions(+), 38 deletions(-) diff --git a/drivers/gpu/nova-core/firmware.rs b/drivers/gpu/nova-core/firmware.rs index 5ed079a45ec2..1cb5897778f8 100644 --- a/drivers/gpu/nova-core/firmware.rs +++ b/drivers/gpu/nova-core/firmware.rs @@ -256,17 +256,60 @@ mod elf { use kernel::str::CStr; use kernel::transmute::FromBytes; - /// Newtype to provide a [`FromBytes`] implementation. + /// Trait to abstract over ELF header differences (32-bit vs 64-bit). + trait ElfHeader: FromBytes { + fn shnum(&self) -> u16; + fn shoff(&self) -> u64; + fn shstrndx(&self) -> u16; + } + + /// Trait to abstract over ELF section header differences (32-bit vs 64-bit). + trait ElfSectionHeader: FromBytes { + fn name(&self) -> u32; + fn offset(&self) -> u64; + fn size(&self) -> u64; + } + + /// Newtype to provide [`FromBytes`] and [`ElfHeader`] implementations. #[repr(transparent)] struct Elf64Hdr(bindings::elf64_hdr); // SAFETY: all bit patterns are valid for this type, and it doesn't use interior mutability. unsafe impl FromBytes for Elf64Hdr {} + impl ElfHeader for Elf64Hdr { + fn shnum(&self) -> u16 { + self.0.e_shnum + } + + fn shoff(&self) -> u64 { + self.0.e_shoff + } + + fn shstrndx(&self) -> u16 { + self.0.e_shstrndx + } + } + + /// Newtype to provide [`FromBytes`] and [`ElfSectionHeader`] implementations. #[repr(transparent)] struct Elf64SHdr(bindings::elf64_shdr); // SAFETY: all bit patterns are valid for this type, and it doesn't use interior mutability. unsafe impl FromBytes for Elf64SHdr {} + impl ElfSectionHeader for Elf64SHdr { + fn name(&self) -> u32 { + self.0.sh_name + } + + fn offset(&self) -> u64 { + self.0.sh_offset + } + + fn size(&self) -> u64 { + self.0.sh_size + } + } + /// Check if the section name at `strtab_offset + name_offset` equals `target`. fn section_name_eq(elf: &[u8], strtab_offset: u64, name_offset: u32, target: &str) -> bool { strtab_offset @@ -285,48 +328,47 @@ fn section_name_eq(elf: &[u8], strtab_offset: u64, name_offset: u32, target: &st .is_some_and(|s| s == target) } - /// Tries to extract section with name `name` from the ELF64 image `elf`, and returns it. - pub(super) fn elf64_section<'a, 'b>(elf: &'a [u8], name: &'b str) -> Option<&'a [u8]> { - let hdr = &elf - .get(0..size_of::()) - .and_then(Elf64Hdr::from_bytes)? - .0; - - // Get all the section headers. - let mut shdr = { - let shdr_num = usize::from(hdr.e_shnum); - let shdr_start = usize::try_from(hdr.e_shoff).ok()?; - let shdr_end = shdr_num - .checked_mul(size_of::()) - .and_then(|v| v.checked_add(shdr_start))?; - - elf.get(shdr_start..shdr_end) - .map(|slice| slice.chunks_exact(size_of::()))? - }; + fn elf_section_generic<'a, H, S>(elf: &'a [u8], name: &str) -> Option<&'a [u8]> + where + H: ElfHeader, + S: ElfSectionHeader, + { + let hdr = H::from_bytes(elf.get(0..size_of::())?)?; + + let shdr_num = usize::from(hdr.shnum()); + let shdr_start = usize::try_from(hdr.shoff()).ok()?; + let shdr_end = shdr_num + .checked_mul(size_of::()) + .and_then(|v| v.checked_add(shdr_start))?; + + // Get all the section headers as an iterator over byte chunks. + let shdr_bytes = elf.get(shdr_start..shdr_end)?; + let mut shdr_iter = shdr_bytes.chunks_exact(size_of::()); // Get the strings table. - let strhdr = shdr + let strhdr = shdr_iter .clone() - .nth(usize::from(hdr.e_shstrndx)) - .and_then(Elf64SHdr::from_bytes)?; + .nth(usize::from(hdr.shstrndx())) + .and_then(S::from_bytes)?; // Find the section which name matches `name` and return it. - shdr.find(|&sh| { - let Some(hdr) = Elf64SHdr::from_bytes(sh) else { - return false; - }; - - section_name_eq(elf, strhdr.0.sh_offset, hdr.0.sh_name, name) - }) - // Return the slice containing the section. - .and_then(|sh| { - let hdr = Elf64SHdr::from_bytes(sh)?; - let start = usize::try_from(hdr.0.sh_offset).ok()?; - let end = usize::try_from(hdr.0.sh_size) - .ok() - .and_then(|sh_size| start.checked_add(sh_size))?; - - elf.get(start..end) + shdr_iter.find_map(|sh_bytes| { + let sh = S::from_bytes(sh_bytes)?; + + if section_name_eq(elf, strhdr.offset(), sh.name(), name) { + let start = usize::try_from(sh.offset()).ok()?; + let end = usize::try_from(sh.size()) + .ok() + .and_then(|sz| start.checked_add(sz))?; + elf.get(start..end) + } else { + None + } }) } + + /// Extract the section with name `name` from the ELF64 image `elf`. + pub(super) fn elf64_section<'a>(elf: &'a [u8], name: &str) -> Option<&'a [u8]> { + elf_section_generic::(elf, name) + } } -- 2.52.0