From nobody Wed Sep 30 15:28:46 2026 Received: from PH7PR06CU001.outbound.protection.outlook.com (mail-westus3azon11010010.outbound.protection.outlook.com [52.101.201.10]) (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 8A84D374E62 for ; Wed, 30 Sep 2026 03:43:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.201.10 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790739788; cv=fail; b=i9P5U/ppKFTeiGgn53fTC8WG+iUlYf504+nOEuUskmwvGfFdlw0RfJ2kT9Mh/0FFTCB5Qn9NgenNqQzdKZTThiKHcpCXSTQabgj1sA/Zdzkyj6r0V2su0pDVLMEBgxXtLtra9SNHBioJ5mICYdh6kMKt24qCrQlyx2Clgh1vGdU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790739788; c=relaxed/simple; bh=KQ75yHSFfpsOyDfBhLjPMYd6QBwvnzKlPz0Ws/YtzJY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=pT2Q4KP2PPRBN3XGyvdET+m92hFiSuIIqNkN62SosXz0oPytsZN0mPkhnWuq1GXusDOWJeACla6WnA0q5MDNe61pMEPBL6O9WyYHwk5qrYNQS0F1k1TOTg5hPBt6rIpcGl6+RntW6D3xuD5FBZnjUA6OwtxPP+d+c9vTedb/ULc= 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=ADbH/+Rd; arc=fail smtp.client-ip=52.101.201.10 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="ADbH/+Rd" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=RwYKEZ3MlMAFU4EChgNG/B15gVbApjg6O0mMXmXFxBGAuBJkzC7LsrnlKRtK3DSU9/3Od5TYX4RDTKCnFxunyrEZknwVFmZtZP5DGA7ICGExQh76ryDunT8HusAnT3FU5u7HXhptJqM4fN5wpq3qPs5WEOa9XfwcaRQTx3pTF0ukxUpn6n5jUbqVHSR1YZcfqg6i3xcr0Ku222LU/jILMjKgjorFb6OvAK06QfvLY7VvgPcd5IsqOL/1q0WWpRaBcIDUYQLxbplY5XrpItMhQp6h0l9YI90QWTQHs+KAZzVHwCPvb5nlzI4Q3q13cqfVu9TpqaJ+jD/AwAD2dgzxJw== 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=kE7LgGKlb/RH7lO7LGEGY+pNReRwFNpYsAGsVgNJLsY=; b=yiQJU2N922C5bJ32kL8nIc7dqbCuI88NdbP8awyMrP3D+QXuuU+8pAMGZkuvT6PucutuXbCKxul38M9xX6Y6vNqRgGUjgbbjdgPGEcvUB1YI3PY3HBNelvMrvoq5WdV/+PymOzc1gcfLItif4LC71n9rzR24vEKXZuXy1B9TFn4HqI55ZUrdHnmcKeaDoWSv47xtMLaMVpkM215cKiwvkk31r6N+kSi4RYthuPjbuEfwnuGm/n4bQDh2tHM9E9G4DxplgmOJoylyR6kUrUdapWmAkWyI5YA0rh7sAQRQahvHasKgmRNkJGQFF/dAA4K6ancRERf0KExjJTYROV+rrQ== 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=kE7LgGKlb/RH7lO7LGEGY+pNReRwFNpYsAGsVgNJLsY=; b=ADbH/+RdJrBtwZd03wHM/HYBax3trqw/2+UGl4XGQJhWt8izx8FpkRbqqtMMbjJ+Mo8Iu46QtJ2CUEaQwsonSPRbbiKh9GlqoRT0woSEXpyDWMpQ3IzpxzQfGLtyH3+god7eDKtOkZulFTzflt9ek25wVFftm2bTQXp2d6+BReKM3tTQg/BStbT/GZK9EmLkzT/YszKeeqnMSbv/lvT9YqbpWQpAjRXvAtyQVYmyAhy/KLtIYu0bxqWHE5xJKq+OIqJsAThwenv08FvbusmO1K2xEvjFZpVuIn6IW5iMHR/pvh3BCVn9ddulhbHToeNZFVnqiXjdQIuOByKoW4qI1w== Authentication-Results: mx.microsoft.com 1; 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 MN0PR12MB6248.namprd12.prod.outlook.com (2603:10b6:208:3c0::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.451.26; Wed, 30 Sep 2026 03:42:08 +0000 Received: from DM3PR12MB9416.namprd12.prod.outlook.com ([fe80::8cdd:504c:7d2a:59c8]) by DM3PR12MB9416.namprd12.prod.outlook.com ([fe80::8cdd:504c:7d2a:59c8%4]) with mapi id 15.21.0451.024; Wed, 30 Sep 2026 03:42:08 +0000 From: John Hubbard To: Danilo Krummrich , Alexandre Courbot Cc: Timur Tabi , Alistair Popple , Eliot Courtney , 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 , nova-gpu@lists.linux.dev, LKML , John Hubbard Subject: [PATCH v5 01/15] rust: pci: declare IrqType and IrqTypes with impl_flags Date: Tue, 29 Sep 2026 20:41:34 -0700 Message-ID: <20260930034148.590687-2-jhubbard@nvidia.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260930034148.590687-1-jhubbard@nvidia.com> References: <20260930034148.590687-1-jhubbard@nvidia.com> X-NVConfidentiality: public Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: PH8P221CA0060.NAMP221.PROD.OUTLOOK.COM (2603:10b6:510:349::9) To DM3PR12MB9416.namprd12.prod.outlook.com (2603:10b6:0:4b::8) 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: DM3PR12MB9416:EE_|MN0PR12MB6248:EE_ X-MS-Office365-Filtering-Correlation-Id: 96e54a56-0d07-4aee-c9fb-08df1ea4cdb3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|23010399003|366016|7416014|376014|10067099003|56012099006|11063799006|3023799007|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: iezeGlWoXp5jswcO8rXzLnqRWIb96lJGWZqe98SqTlhNGN9s2LZW1njRlM0+GJQCzWnDEHExentFHZeCXtmdL5G1WfcT0TKqm6lU3HglWAuEDw88e6XpFUWGNauUC7CcXmqR5TDt5M9PI/n2rrT5LThYhDVGWUt9Im7/BKWkwvYWi/5SKDFTbQjWinPxNJJjbjQGyjkFqFaqHC0oNGd/Op/8ZDqbsbJ7SB5y6VlXQZRCrMGy6H0oUKlXHRLkwuMn5KEmWIr46GF6YoIeSMRdc5XqYG2zj+SnQeN2YLprhjUW1EgmLGQdBV6pKqesbP+Rufd6W9QctQaqyPUmcv3TytaBBuscXwaCkUzr0GSY0iyv5k+/AbFD5gPDNtSZ7rPcj/0BaHAC/nBypBZXF1gH3ox64uzKeDkWFQunoTEdTVxXVFZtYw4RIBdkMEK/M3gbHCPZxFRUtBAETVTFf2aJfhqKDF6OgFAKUU0H1yMCCAlaJXIEsuFUtsZingkXDmPRGRtK6z0JLdUNU2XrvFkmtns3P+2T/sUbFX2DTHoEMHb1N6Ei7CUNntITr0ynOne69OWZb/LJVEcyOVGbNgMaSJQstoh2CFbGuiDIieG1IhMGh2/Kx/k+aMCDqHEsX6A4RGusJlfGWlZDeaVsRvzszd3cdBqp6Rf9upwXnYhII/I= 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)(1800799024)(23010399003)(366016)(7416014)(376014)(10067099003)(56012099006)(11063799006)(3023799007)(18002099003)(22082099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?Fi3K8i3WL28t+EUfqzt2TdkA8Ea9Z5DowlrTWnBjiZ7LLsYWbgkWVY48c3jT?= =?us-ascii?Q?GVrRwd0YsYBi6LjGjA8lcLsGt0zpbe2qemRrKTEW/RR07UmNWczkKLyLaQpT?= =?us-ascii?Q?0sucQJacE5lcXIZuT5TMjxnhM25HYTpBRKpBCadffuaquu/5e4/EIPAByn4w?= =?us-ascii?Q?lZi3LlL3onajAXuPN6sBZ+PLafsXiz7Z9E6unPIQ+nWnveMrM4f2TcbTFlJO?= =?us-ascii?Q?pOhqsWvSNxLI9aZkTowpT+ta5qRX+dLiqljdP0PIBO6yGdRPcPmEQvv7ohBN?= =?us-ascii?Q?FAQg2zgKZYpfVDM2EBfTQZUAWuu0mxZ60KlEompt2dzbX9+v9DkOOeaSYPHQ?= =?us-ascii?Q?5tB3jovSanYAf4NMKoEN2Ji6sN/QpUsbX1elhUPN1duqp5eUwZ2Hecdxh+YH?= =?us-ascii?Q?eg4WfWQNugD66l07saQeujn4hakX93jgXHIdbcn1Z6Ct+W6OcqRbmyPkQrbw?= =?us-ascii?Q?nI7HED7Wd/x3cFqCW2zQKRLxwCRBlO9l43oUQkf+hWztCyJEQgOCTkTbv/dm?= =?us-ascii?Q?Q6D3dwP1VG1U73h/j+xJc516eQwTSe6GBvadOIiKPjmYLOQWb0EFCL/R3yYu?= =?us-ascii?Q?2PRmeAA2zY8m90WIVQXi/HjyALH3NXAxgkjewIugCcqbBy3OuzOQXAbv8pHE?= =?us-ascii?Q?D4qtO1Jd4F62DDmsRPBZsOxvp7Hj9byKN+msetd9SsMOGrmskFHFt4cGCekw?= =?us-ascii?Q?TEJaluuzwaZsvyt9Ol70mkp/u3tDMsqeQbBOY9KtBRUn4rAc9r2KJARFykzK?= =?us-ascii?Q?tU6yoBFv1fEb87NBKTD9zTUoJNDxkPkbnH6ETwr3oxLtqkr6wz5cLDILGgBn?= =?us-ascii?Q?j70jqmkpcx+FC3taAd0kAuGzO4TQSZ2lOWll4zsRF/pAt3Xz9bX6hvC9ZO4Y?= =?us-ascii?Q?fVP+4HB/J4SmrZoUVlSrljjgdpw1lqCCBd9/yPGh8o+GuRY5W3LV7Z/aHj84?= =?us-ascii?Q?2zFRhJZqOkNVL2jDP49zhm05WwtxDP6gzRZRf80x2azKHHj5FipmJ31o6AbD?= =?us-ascii?Q?SbvyL5mkX5cwl7eaadkMvSGZDKTkbIsfnfXjgzMxsRC0sGeXrx6/qBvHhofG?= =?us-ascii?Q?L/0Me7nb4ZXVXI3juxbHLTVT42VSF+tyeOcvhygHBtokR9F8rjm6OfOJvh7/?= =?us-ascii?Q?5UlBcnGmXsk8XIKLm6QIzy7MkMjsxKhLFGM/HxL74WPR9fA6f2YhdW0+J6pl?= =?us-ascii?Q?73zurhv9HXR5vg+M7w6gI7+hDg0Q26x+Agvjdc0ADeWyqAjrEinbFkFmS+CA?= =?us-ascii?Q?aNG2PNoIh8DYdNa6mGnpqNGgQQ/QsId2nVn4iDqmswwdGvLGaC8bd3DmDU/w?= =?us-ascii?Q?gXJlzwzNJpYOocaJE3EefSSVssBlkdXjrPuVgUdAnaUYIJI21VgwidIbi4Bl?= =?us-ascii?Q?Qca6W8umQntoxltUE2P+b5WJGoF1Dr/qKEhhqOVqsTDdd6SYrrtALQ6jZBql?= =?us-ascii?Q?fQ3Wzw73ykBTAI6w8mT7ughqQ6gq6qn2S4Sg3J2YMd4Mr7vLjqWHqA6J8zKh?= =?us-ascii?Q?PoRisY/KgSjYv4tZI58DbG1+5HmUMR8evuqcXoH8vmxP08M2PG5gs3txO9yM?= =?us-ascii?Q?slr+GuW6YwJz4kvEbEv5neIodYWAat15jokzbyOh4AlhVPQLVg35Lm4+WHss?= =?us-ascii?Q?kzt+5sJ1In53xgqBzzo2y+RXPcCGqX/t/TIMa+UYXCrCr68RAOeR3UeEL5xy?= =?us-ascii?Q?r6e9bF3p2C+ZoGl+SdA8GpYyNAKO7MV8Nj9X9qXlzsoxNhI4nIgoGOK+w92+?= =?us-ascii?Q?nWCd9z6Mmg=3D=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 96e54a56-0d07-4aee-c9fb-08df1ea4cdb3 X-MS-Exchange-CrossTenant-AuthSource: DM3PR12MB9416.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2026 03:42:08.5645 (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: frPmRXVzQAGzup7tmTUSItRMuackn2IxIYtn+DGoKyzm14N0rgVrg8y8etdAVsd/aj7U76Y4j/kKRIttNBthkw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6248 Content-Type: text/plain; charset="utf-8" The kernel provides impl_flags! for declaring a bitmask type alongside the enum of its individual flags, generating the bit operators and the containment queries. IrqTypes open-coded that pattern with a with() builder, so a caller naming two interrupt types chained two calls onto IrqTypes::default(). Declare both types through impl_flags!, so the same set reads as IrqType::Msi | IrqType::MsiX. Suggested-by: Gary Guo Reviewed-by: Alexandre Courbot Signed-off-by: John Hubbard --- rust/kernel/pci/irq.rs | 68 +++++++++++++----------------------------- 1 file changed, 21 insertions(+), 47 deletions(-) diff --git a/rust/kernel/pci/irq.rs b/rust/kernel/pci/irq.rs index 6741046ec1c0..f074aad7f1d8 100644 --- a/rust/kernel/pci/irq.rs +++ b/rust/kernel/pci/irq.rs @@ -13,27 +13,26 @@ }; use core::num::NonZero; =20 -/// IRQ type flags for PCI interrupt allocation. -#[derive(Debug, Clone, Copy)] -pub enum IrqType { - /// INTx interrupts. - Intx, - /// Message Signaled Interrupts (MSI). - Msi, - /// Extended Message Signaled Interrupts (MSI-X). - MsiX, -} - -impl IrqType { - /// Convert to the corresponding kernel flags. - const fn as_raw(self) -> u32 { - match self { - IrqType::Intx =3D> bindings::PCI_IRQ_INTX, - IrqType::Msi =3D> bindings::PCI_IRQ_MSI, - IrqType::MsiX =3D> bindings::PCI_IRQ_MSIX, - } +crate::impl_flags!( + /// Set of IRQ types that can be used for PCI interrupt allocation. + #[derive(Debug, Clone, Copy, Default)] + pub struct IrqTypes(u32); + + /// IRQ type flags for PCI interrupt allocation. + #[derive(Debug, Clone, Copy)] + pub enum IrqType { + /// INTx interrupts. + Intx =3D bindings::PCI_IRQ_INTX, + + /// Message Signaled Interrupts (MSI). + Msi =3D bindings::PCI_IRQ_MSI, + + /// Extended Message Signaled Interrupts (MSI-X). + MsiX =3D bindings::PCI_IRQ_MSIX, } +); =20 +impl IrqType { /// Construct from raw value. #[inline] const fn from_raw(raw: u32) -> Self { @@ -45,33 +44,10 @@ const fn from_raw(raw: u32) -> Self { } } =20 -/// Set of IRQ types that can be used for PCI interrupt allocation. -#[derive(Debug, Clone, Copy, Default)] -pub struct IrqTypes(u32); - impl IrqTypes { /// Create a set containing all IRQ types (MSI-X, MSI, and INTx). pub const fn all() -> Self { - Self(bindings::PCI_IRQ_ALL_TYPES) - } - - /// Build a set of IRQ types. - /// - /// # Examples - /// - /// ```ignore - /// // Create a set with only MSI and MSI-X (no INTx interrupts). - /// let msi_only =3D IrqTypes::default() - /// .with(IrqType::Msi) - /// .with(IrqType::MsiX); - /// ``` - pub const fn with(self, irq_type: IrqType) -> Self { - Self(self.0 | irq_type.as_raw()) - } - - /// Get the raw flags value. - const fn as_raw(self) -> u32 { - self.0 + Self(Self::all_bits()) } } =20 @@ -203,9 +179,7 @@ impl Device { /// let vectors =3D dev.alloc_irq_vectors(1, 32, pci::IrqTypes::all())= ?; /// /// // Allocate MSI or MSI-X only (no INTx interrupts). - /// let msi_only =3D pci::IrqTypes::default() - /// .with(pci::IrqType::Msi) - /// .with(pci::IrqType::MsiX); + /// let msi_only =3D pci::IrqType::Msi | pci::IrqType::MsiX; /// let vectors =3D dev.alloc_irq_vectors(4, 16, msi_only)?; /// # Ok(()) /// # } @@ -222,7 +196,7 @@ pub fn alloc_irq_vectors( // - `pci_alloc_irq_vectors` internally validates all other parame= ters // and returns error codes. let ret =3D unsafe { - bindings::pci_alloc_irq_vectors(self.as_raw(), min_vecs, max_v= ecs, irq_types.as_raw()) + bindings::pci_alloc_irq_vectors(self.as_raw(), min_vecs, max_v= ecs, u32::from(irq_types)) }; to_result(ret)?; =20 --=20 2.55.0 From nobody Wed Sep 30 15:28:46 2026 Received: from CH1PR05CU001.outbound.protection.outlook.com (mail-northcentralusazon11010011.outbound.protection.outlook.com [52.101.193.11]) (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 8EFF3379C50 for ; Wed, 30 Sep 2026 03:43:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.193.11 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790739789; cv=fail; b=s7ajNoNY64XvZoKNp1L1n47HJd0Sv7K4f2GJAecLesYIvd3BbckjuFd9pOPAJLSd5KbORxRMmvePAFUdxTgFzrvxh0ZOj1oubIjS0AO7rHFI7B/b4N/e4kQPteV/aVpw6E6VFNC8Un9IqGaGUexXGQY+MPfhH4HJeZDIw9/bay4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790739789; c=relaxed/simple; bh=PHEEgZlGUSJn8PS45RQxtqM2X4fC4Swm+aR3phUqYHA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=IOruKvKGyDnujwP2x4+rkR6h01+HkMSQmTrGjLYE3oZF1VyF/B6Fs2vHW/PUzzlkRCZjh+hcqhPMpWVlN/bSwRr4tpj/k5OxbcUT2xwbccZGvIDPrS0nZlJmoMq8I0lOPmo3V2IKgK+XXvVFLswhsGZG/AqFDZ9bRPJei0DYYIg= 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=X68P+gUT; arc=fail smtp.client-ip=52.101.193.11 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="X68P+gUT" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=VS0przTW4vgtfnn2V+BsB99PtGlGTF+6km0hH5LFqOTuYR2GfHB3ZmwgmnlkYWDWZ7ZOA+vIXOB2o1+PbnFqF79NRE79rrsc6ashrQf0NxlGpAARSFlH6B10byLxnFpfqyJDOoqe0rGxqd2OCcw2SobF4Ji3GodgvkJQuNK1VcjtdK6DrHNBWDiaVTaCgUc2Ed6Yq3IZC5jtRIxz58a3Bs3L3hE69jTtq7nrc2fcmfaK0NajNwjXkg0QdZGOMQh1KbehtI4xYV1SM/r/6YYjYTPUnyGl4JDc75//rPb9J4I6ba9arypHG0tn4th2GHkvfvyMjGSsL3yZ5dU1yZTy2w== 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=xXmGQXXm1JUMMWqFnRtPDk3zWonekrtMqOZ1UvTJ4jk=; b=W3G82uhkDwJ3ONSjjhltXpdbR9NWhzSIhtLsabHXqUY0zQPrtdpK7EmyZ9cX/tU51vvyQmtDGx5/J1N8qOwmlsfY0WXcUZi3/p+salDbuTjnovx6U/AuFlR6tHLXxX9aVK7yHyX71x/ZKTfHdebpzzadzRPDvxlczZ/IhnFdJ2tKO+U0AFlfHJWfkSPqEpTKH8a6mE9C67Kuiec7Au+5bsg4Cpjkcmr+/0GNblfk9YFYyqgFpAudQLuNfOoYvhweGPlZdIXGet2HuaxVqk+xa/i+o2d+y5Rb1yPgVC97C3sCs8FAW7slx6g1Zl4bzAHXA+HQmhoC0nNo4MSeb0I7Vg== 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=xXmGQXXm1JUMMWqFnRtPDk3zWonekrtMqOZ1UvTJ4jk=; b=X68P+gUT8xKbuUAWUuDoYHXgfVfYPQxYPtDXasFeDmwUWd81ww/TA1y7Glx7/eXhd3IPZmwxSlXtQ5CMgWT+vq1OFxY34N7H6mquL9Ka6pgYU08CWN8haGtR+ZFy6OSSIdAtgZcPpzO0q5Hlo29jr/VxVXuS/misupp8QJ222Tipra0clcjfYD0x7AnGjNRim90UkJVpeBXIJIzsV5BQxUxU1d67Uc0EnKBg3LxBembGaoqh75vzGqZTLh0SNTq29FdApztW7EkJlc+3NMD90BZrNH3DTLY5byEIjzpwD7oXmiMEQxVU4mibciymdEH5XKabxMbfE90Oa8adGQ0TAQ== Authentication-Results: mx.microsoft.com 1; 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 MN0PR12MB6248.namprd12.prod.outlook.com (2603:10b6:208:3c0::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.451.26; Wed, 30 Sep 2026 03:42:10 +0000 Received: from DM3PR12MB9416.namprd12.prod.outlook.com ([fe80::8cdd:504c:7d2a:59c8]) by DM3PR12MB9416.namprd12.prod.outlook.com ([fe80::8cdd:504c:7d2a:59c8%4]) with mapi id 15.21.0451.024; Wed, 30 Sep 2026 03:42:10 +0000 From: John Hubbard To: Danilo Krummrich , Alexandre Courbot Cc: Timur Tabi , Alistair Popple , Eliot Courtney , 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 , nova-gpu@lists.linux.dev, LKML , Joel Fernandes , John Hubbard Subject: [PATCH v5 02/15] rust: sync: completion: add wait_for_completion_timeout() Date: Tue, 29 Sep 2026 20:41:35 -0700 Message-ID: <20260930034148.590687-3-jhubbard@nvidia.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260930034148.590687-1-jhubbard@nvidia.com> References: <20260930034148.590687-1-jhubbard@nvidia.com> X-NVConfidentiality: public Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: PH8P220CA0021.NAMP220.PROD.OUTLOOK.COM (2603:10b6:510:345::13) To DM3PR12MB9416.namprd12.prod.outlook.com (2603:10b6:0:4b::8) 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: DM3PR12MB9416:EE_|MN0PR12MB6248:EE_ X-MS-Office365-Filtering-Correlation-Id: 61e776c2-e1ca-44b8-3996-08df1ea4cea7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|23010399003|366016|7416014|376014|10067099003|56012099006|11063799006|6133799003|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: RwdhQE7nLKNpL+N6AhH/BUBnYjYdUVgSUf6bWo2vOQ/sojA1gH3PT/ZskPJqkZ0FmHnh2mnO1AHXV/Dj/V5Fnluh2We5szElCwcWbx1Tb/1xcVBsVg86c3gZ+rD21rs2bE1OGJZWxPOXANwR/jBeyEeRPNuh7VHf8+eFSo+zTCMn5q2yaleIWVm17DPXeS4vw4j1d6DEIhecY3iZTPUFU08DxxDBEZXoVbHoQ1ov4vDkzTYIGpA8YCH0hDMWHhBAb4Xl1UFhteHzgQAzIkoNL4rTc7bgY5ibyQHhfculWlafxdLTyF8hPga6nkJbUshkcwWVWWw7tLPK4/1wTalrpAJ+Tyb2cBdQuk4XZ4TsAVwmAy15IFEXTX2QR4kzd1lxjt9w7BNqQtJr0G3FVpUz6g23pqA3LP0vKKWqBOBZ4gd0JXRkH3AwCzuGYPCQWc8SoXIdnMg5oJdSCYo4ItugW2Rpsa+/rS2n4tMwZ8ReRL61phTVVqLNRMWu/ndGhSSNgb3NLzKl21HXed/ZtD5Ps8zK1TWau3pjP8cOOd2ScXaSLADO3acoJMxKnFvAFKtaY48SP3MVrl5PQyVuAIG16V6ZVxXFUuUYA895SNN4CNADzW0ETxE4+SBWyEoc6xX7A0qEsr9nL3GK1210vL11CgsF9OcBpw6zf+tBtnd7ITM= 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)(1800799024)(23010399003)(366016)(7416014)(376014)(10067099003)(56012099006)(11063799006)(6133799003)(18002099003)(22082099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?Sj4TLUNbfnoUduw5+jaz+G6GBXVX8DpEwQ9c6EfnBofuuUP3Ea0rUnTxWp44?= =?us-ascii?Q?WNuW0+VWa4HqcslfnyXFaOCJzEnyx88vAq8SdHwvSFurdxz7Aj2M0cWF6Rvt?= =?us-ascii?Q?4bmRUJyPyb01GtM19GvHp3vgnwx+qcdKnZqurmbhAqHLEmGJgUbEtZdEqFhJ?= =?us-ascii?Q?yzDXsCCUfZHMC4Ctv8aeDeSF6jMby8VDWiAz68x0Oc0fje0Mu3rVvTHraZs4?= =?us-ascii?Q?wFdfBmiYY3u2vL1Vhr9JGyNDaoOfH0qiC4Qe5P7gE3NR/ai204YhwXyLX8vP?= =?us-ascii?Q?EsCHaJSNAWWDb0DBtDtrRQs/nlbwsjMv7tl5Sy/ct9lHMYIk51P2MkxO0Ae4?= =?us-ascii?Q?ppdum+Id1ze7dBa4HKvnmC6XmjA+hKtxywvqGJtDTyq8jWsq4TWAdWefBf0w?= =?us-ascii?Q?rPsIDznKbuQiWzjRn+ZD6DGLoXfbWLOToE2lAgVOx1aiyN7LFNBvtR+cmiMC?= =?us-ascii?Q?v0gbSOr9LTblHrApYS6YbwJ5mAmotqVzaBCzddnYB4BB8cTNA+K7KGnZ8J5c?= =?us-ascii?Q?Lmh5K5cPMb/OgUeSDXjHVGbH5BayX61H6E+IQZUGijCtdwmzjzBkWE3iUB35?= =?us-ascii?Q?f7XfgvcaV9P9lypEsXR5dvRbe3KULkIL3Vpk/cjbsX8A9ns54NeUBN+kPKoG?= =?us-ascii?Q?pET046P6CjoEvrS/99Ovy/2m6DpesMr70EyXbx8V0rujFmk+6jLIld2WIS0F?= =?us-ascii?Q?pihc75pyzyNwijdeyjv+E78fDEXalbz5Uo7uMN16oYNMsJov4cyPGXHJaDfe?= =?us-ascii?Q?7jS/1rmtMUaK/bXdTUz5MdIVyNaF4hYSxez4OH2QiXx7GZDrQXZ+KjGzBIld?= =?us-ascii?Q?SrPHYuNq2L8U8MY6jc5k8NNTzAqeHa8JWHv93BMOAHA8kPjBBRvC77Eg0Esw?= =?us-ascii?Q?QV34vyqUJZTjLykBKrF+D69mct5tTLiFuyBL8teCrAK6zu9EgcIE4ExWVtrj?= =?us-ascii?Q?W8iFcJeEmWX0aTpKySV2pZ7sud1gGE7H6tcLNn0W4clVDWNKmWSLRtWBuAp3?= =?us-ascii?Q?2s5amtibBS93MwtlhgMVKSdGUO7EVDenmlNNj8APw4T5iXY2G+k2qg5PQXTg?= =?us-ascii?Q?zWHFgsq2sKqHc624TbvxQVOkacqyqKTKb7K0vbJWlQIBwEvRel9n6vkcw6aV?= =?us-ascii?Q?ldSjydd+T4pNaUF/bU8idx6XkXsm3E3xz1rRdjQI8MKxIT7vL2jOX1RsZ8p4?= =?us-ascii?Q?mpMxfIQ8Ce8df7Jj5F6EBixiYHlwkU14xS+xH4lf/YhlOi+bC2lqr6owBybP?= =?us-ascii?Q?ZmajnIanUqgdKHYDihZDaiDufLvYuVQdesUJSJ/0k86n1fbdz6TiejVvxbYU?= =?us-ascii?Q?JYm6+jOBhPSrtdAYjWjHazszzRlJWbMCfB5mPoEczHBMRWORVzzon8vIK+kH?= =?us-ascii?Q?DjD6KBqtPiCDR8ijP0CP8R+oQlAwZ5SodrIYvZXn3+7MPQhob1h1WBUlRD5w?= =?us-ascii?Q?uNgRrAYdwLAWFr3leoLJjWB6k54UfyxEpPC3pApDLhcnShaniFNklOsyW+Lo?= =?us-ascii?Q?i5n1yWNLn0+NHrA0miIpd6HNyIwkTAyvESXEKVVZ3nRwG3gqg3Uk0ivMozli?= =?us-ascii?Q?lPVVKKLDmKBgQdZBvYVHFTakvSKPyY1sUMrFV/RR3KVXNZz8HpOtHgEFKwuy?= =?us-ascii?Q?BXM0I+Vf1JGhIjX+GypbFaNC5QJDg6piOwJMTm0OtzFBBoPplxE/HIWrfX9u?= =?us-ascii?Q?w0o/zF/jMWOyJ2upQAuEOtb0Wh5lKqv0NQRXT0m6p6gCVKnpOxc5TAlKaZq6?= =?us-ascii?Q?+j5bPA7G9Q=3D=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 61e776c2-e1ca-44b8-3996-08df1ea4cea7 X-MS-Exchange-CrossTenant-AuthSource: DM3PR12MB9416.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2026 03:42:10.1910 (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: 6dYLxpLN8f5NgU9yzMOYUo3l5U2CbjN1i8CWuOpZ00tOIZqrm67qE4flqGEuwFYnTiR6qXCpsXlYc2VfeU6+EA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6248 Content-Type: text/plain; charset="utf-8" From: Joel Fernandes A driver that runs an interrupt self-test during probe waits for the handler to fire. wait_for_completion() has no timeout, so a broken interrupt path stalls probe indefinitely. Add a timeout variant of wait_for_completion(). Reviewed-by: Alexandre Courbot Signed-off-by: Joel Fernandes [jhubbard: return the remaining jiffies] Signed-off-by: John Hubbard --- rust/kernel/sync/completion.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/rust/kernel/sync/completion.rs b/rust/kernel/sync/completion.rs index 35ff049ff078..7e8b3c1c880e 100644 --- a/rust/kernel/sync/completion.rs +++ b/rust/kernel/sync/completion.rs @@ -6,7 +6,12 @@ //! //! C header: [`include/linux/completion.h`](srctree/include/linux/complet= ion.h) =20 -use crate::{bindings, prelude::*, types::Opaque}; +use crate::{ + bindings, + prelude::*, + time::Jiffies, + types::Opaque, // +}; =20 /// Synchronization primitive to signal when a certain task has been compl= eted. /// @@ -111,4 +116,20 @@ pub fn wait_for_completion(&self) { // SAFETY: `self.as_raw()` is a pointer to a valid `struct complet= ion`. unsafe { bindings::wait_for_completion(self.as_raw()) }; } + + /// Wait for completion of a task, with a timeout. + /// + /// This method waits for the completion of a task, or until `timeout`= elapses. It is not + /// interruptible. Returns the number of jiffies left when the task co= mpleted, or [`None`] if + /// `timeout` elapsed first. + /// + /// See also [`Completion::complete_all`]. + #[inline] + pub fn wait_for_completion_timeout(&self, timeout: Jiffies) -> Option<= Jiffies> { + // SAFETY: `self.as_raw()` is a pointer to a valid `struct complet= ion`. + match unsafe { bindings::wait_for_completion_timeout(self.as_raw()= , timeout) } { + 0 =3D> None, + remaining =3D> Some(remaining), + } + } } --=20 2.55.0 From nobody Wed Sep 30 15:28:46 2026 Received: from PH7PR06CU001.outbound.protection.outlook.com (mail-westus3azon11010010.outbound.protection.outlook.com [52.101.201.10]) (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 A8A683812F1 for ; Wed, 30 Sep 2026 03:43:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.201.10 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790739795; cv=fail; b=Yx3y74uZIfZFkaIJzicsnHelGFmAf0rIcdIGwm0u1vQSPZomOdYZw5d5ZRcnVPERrcfut4Mh0AHMtwi17fpnix0k7H1ziio+2O7p4fD+1klJldA1fQN4YEComzvCs8hJmWqRuWSwJUMDD/hUGpRkZesLcMI3a3n4KfQqwJMsBQ8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790739795; c=relaxed/simple; bh=u8Eir1BSZBSWu/deF06yKDypVIrGd7EbBlGDtJDxuEo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=rJserDmCfhIuIlBJ6+LY77kPNipgIo8DOlZxNGlpCjPwtuQwHR7NYIO78ByvepEfhI62XSvqpuUJS6wiInemhiLq022FdX3tT6+0uSubjY62kejiL2JphNFpkv8e5/jzpjI6Rcia7kt2+fmn4Fo3URlPGzao/ZYS0JHymKFwy7Y= 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=nqFyywEG; arc=fail smtp.client-ip=52.101.201.10 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="nqFyywEG" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=mK6u8fV15NJtBjGwldKadsjJo+9u24MDv4NJk+HSD0d3ak7okmWA/6j8mlzOlbq3oEBunuVlgcy6t4FdCck64mFt3el4RuPDdyGM7qtBUoV6brg+0sTsYnM0G1znzpwgf75Ky0nmj3n2DA88DxNCPVfAx6qrsCtHPz8X4kMmv6hinq3mF6FRZ/Nr/SoX0V7H8mMGEDaJU9Htqmg+w4uT1/B39WEpvYazSywkaGdToWqxhqDjNRdOc6WLFJrrX3g5s7JVpcEN1zRKpmL0p5S113iM0S4A5HNXA9ckbz+8e9dgzmEUVYVOW0tlHgZ3+9dxG2RLxfHiC+TXrDJGoNMaRA== 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=/LHFaBseORITmWpcVLnDveaGrc21ORrvUOoPIQCVxj8=; b=wufVisfDW92tZ69mnL2LEPxTjtkdnXmdF/dQcZW3+dLJ5Jzv94kVNYkHqzZCDwcO3Pr/Bajvq5gdVBhRDS7+6XinxbrkdKxEqqN9jVZAXRGXN1FUgdNyMK2SLi0A9Vbd7nDlygCr/CbDvBrYDTVpmr3bz774vd733DdrmkfuW08cShCN0kleyOfnRmD14WAHEfCeMDhX8XZunRFYnZ8DhWfBHFnpMp5PRvyVqhcFr9DHYUDmXQyqcpAxbm1QibWZ+RMwMSAXLpQfeXhT4BLa+WQrK7K0qsaF9rxKFxagkxEXFnFaBU8hugiWWWwav5gZRyh1pfktxbb4/aaWd2AYHA== 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=/LHFaBseORITmWpcVLnDveaGrc21ORrvUOoPIQCVxj8=; b=nqFyywEG3fVGe1+cLg5BSaTg1HvoBVBB38UbesTyWUMsO4lBv2y0eQWjjT36M7OZsGEp7+6JQppJ4JmUNGoZjsMyrDonRp1CWQP0w+nrkKNz6hVeQx5k64k5p+ei8pK0gfJpYsXy6CqiCyRnUqtrjPCX0ewx3aVo3SmUI/OW9xGGbLty9pev3GReJjRl7X5gdrE9sL4g7qidNzcBv6jAcE3SGdd2AhZ0ZD3MLdPVlKB+zHQ9hD/+g+ZWpSRszjR5DsjrdUf6PwhtyyozC4H3xnXN3/44rayr1P7/M7WIWhXAf/iUoTzqdr9/g9hOpm+6IttTg+KbrhlDdGdixGAEgA== Authentication-Results: mx.microsoft.com 1; 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 MN0PR12MB6248.namprd12.prod.outlook.com (2603:10b6:208:3c0::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.451.26; Wed, 30 Sep 2026 03:42:12 +0000 Received: from DM3PR12MB9416.namprd12.prod.outlook.com ([fe80::8cdd:504c:7d2a:59c8]) by DM3PR12MB9416.namprd12.prod.outlook.com ([fe80::8cdd:504c:7d2a:59c8%4]) with mapi id 15.21.0451.024; Wed, 30 Sep 2026 03:42:11 +0000 From: John Hubbard To: Danilo Krummrich , Alexandre Courbot Cc: Timur Tabi , Alistair Popple , Eliot Courtney , 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 , nova-gpu@lists.linux.dev, LKML , John Hubbard Subject: [PATCH v5 03/15] gpu: nova-core: add the GIN vector, leaf and subtree types Date: Tue, 29 Sep 2026 20:41:36 -0700 Message-ID: <20260930034148.590687-4-jhubbard@nvidia.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260930034148.590687-1-jhubbard@nvidia.com> References: <20260930034148.590687-1-jhubbard@nvidia.com> X-NVConfidentiality: public Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: PH8P221CA0055.NAMP221.PROD.OUTLOOK.COM (2603:10b6:510:349::8) To DM3PR12MB9416.namprd12.prod.outlook.com (2603:10b6:0:4b::8) 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: DM3PR12MB9416:EE_|MN0PR12MB6248:EE_ X-MS-Office365-Filtering-Correlation-Id: 515f8086-df2d-4c41-e7a8-08df1ea4cf90 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|23010399003|366016|7416014|376014|10067099003|56012099006|11063799006|6133799003|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: 9bwakWAx+7ED4UMSuVpNIcSIQOWzicQ/KQaLS3Dl24mpKmOwDn2L+8v1LyId2UnC36COPXGgYo+NpFx3UZpjBTSVZh5dnBcFbhXYTryE8cH8p3MoCUFmJRRY4K49GhlHkoHfomoPte7qrj2i0IuaRrfjDJwhqAlkREHtZ9tsqddVJOwUVh1yuWPn3mjL3afcqHumX3l1jUExrAjotHayoHeo+fXRv1HWClfqaQjLhhaItoLC+5iEV8pH2DJagrIZpdeSxufj0jegw+t6iiiFQFAY7SgUeQI9CP4X3NRm2OMMhitB/7bYrTVOykFoAeYrv9kidebQSsckG6cOC0In/8jvEM4acum6lEUV2dLkGZaAC5uUv41D9AfAovqkpmOREjhUX6xeCsq9G85/u7S9IzLG7zsCRQsxRbKNyiyc3v2yq7shRntZBiOwVG+UMueqFyAfhqACiPzxpWXhtFZseu9Qe+4PvY8aifxk2XmpvBK64DpeMp8PEnlzhJdC96pntJgqqmWQX0JK2uCtxOZNRRsyJL6MzXxIBUMBiU9qbk60K+DRTp+wTu9YW4vJ6IktCx3py8MpMC+qK9PBOWJf2vRFS/dRd7V8wpOv5W7NtIz2KViVDTR8OB87SwJ/r0buzaBnJNN+VfjOeb87T8z92ZV96sP0QEUoASy4s1YenHc= 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)(1800799024)(23010399003)(366016)(7416014)(376014)(10067099003)(56012099006)(11063799006)(6133799003)(18002099003)(22082099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?/QLQpVot40RuY07HoZRYkaveZPgx89V9PO04ugWAKIZ4Q6s5lDJCNVbIE+zC?= =?us-ascii?Q?Qp2B3JR1cmAC6Wp8XEhGmKtCf9RDfwNaU7daBtEeVRa9mPDWsyYxrTCpfSgc?= =?us-ascii?Q?KGZZRCeYEgi9IFtiPPHdrLyE0Ez7/zqRtTs00q5/yy+21K/zv4mvSwKGlgEj?= =?us-ascii?Q?2BTY3BOqCYK+0Iap3CuoCfR3xQ7LZjqqZoGu83eR7v0So7EwS555FeAmTMdL?= =?us-ascii?Q?OKLgYGikFpQKtaopYSNXbVtlSaz58WyPMNcU1IfbodWNSe1jpYEbzkzWFsIx?= =?us-ascii?Q?JKauWIpae8KtOabGBrMav8UaVNslzUAjKehPSd2A7KSoTELUzvLyWB0cuU0O?= =?us-ascii?Q?tYiyfPT0wy2n/Vl6820CWtTB+DnSzmCqigQr+AnxzMfc3C4pwjO8MyEeU0jR?= =?us-ascii?Q?dOZpBDa0REWvclRLGyD7EGnsmXgtT77VopBsW/yiYeJezxrXxXpAt37w9nRd?= =?us-ascii?Q?kmjotCcuA3Ov7XFojzKMjRQwR8nFmXqmJ2y4NdIFD1PzOEGr8BukJ4GVqAY3?= =?us-ascii?Q?w/5Ie5iCeJoGrZmQF9LhMz3U1qC24HvYVHJoOaxK3t7/+V74hyZGjdU9jwXs?= =?us-ascii?Q?phwtq4Sl/F67l0ROQVak0TN1ISniAvXGR9+u9fO0qhEVHOmCjFGFCQGYY/Dt?= =?us-ascii?Q?trDJLsEN4twvYPZxldn90VyYdpHUMRgCs/lUvmYy2Rgm96oURT7ORnQogoKi?= =?us-ascii?Q?6NWgWk+Nui+m6HUWFsgz7l/lT9ApoiZdYlpQu4wx37uHM9USwefftAdrnpun?= =?us-ascii?Q?F5KcGjBk1J0rEuEszEcDQ65nK0/Puk/Wy2n2U1k2BgwsnzDsJIryBf6I5fF1?= =?us-ascii?Q?GFf7/OWDzXnIlKoqHBiL3zLukMGZfYky1uOGoVha0YtlK0nWDHynsvEfJX0+?= =?us-ascii?Q?c8unzHxQvFX0Ix4di/y6ZKF61aK8haPa1d8YquHqlu0qHomqafawhTOuabMT?= =?us-ascii?Q?fEt4ugrIqUTPWfeAhh/c0QrOl+fLcDro7hroatYkxVHeafhVU7y2GaMvPuQ6?= =?us-ascii?Q?O3pj4toDxS0xQeufpFQrFdoJYmNUGEbYm9NEFySD3MDd/Rf+jItXd+bWfLvS?= =?us-ascii?Q?sn/7pBF/sRDBcog1iwc785QK12hzMhCAu6Lwqkj4OD6/HszsisrXhbwXSyWN?= =?us-ascii?Q?oGbNvE1cxiESx/Xuxf76R/LaRf1MrnVczWZG4J4CLCeWZh06zc2RhHpa2KOW?= =?us-ascii?Q?Ym04sJ7r8oaqqkMt+HTV5DpUHCWuoLbsvif64xXIIiqcEloyYcqksgoEo2Xl?= =?us-ascii?Q?aAMxvtH1QqyZZY2JsM1iYktxhjGnknrHAzyeMmLshKJ/q7tMWqxtPyLfXEsM?= =?us-ascii?Q?RFJyxKwdP+3C5tfriAREEyiWZU+thB8Roa4Q+sZvyBCtjiYs67WvpKCXMT37?= =?us-ascii?Q?YlM3RCq8fyhirMkFwx8/Cs/JnnKq2zbNN/3BsAr/W5GBnthSw0kXNbAwJg6w?= =?us-ascii?Q?nAv8mh2TIR8F2yDEIAtXnYzZbWl1GLg6PbJLMTQVvOHF/W6yT93kQ/DgUfw5?= =?us-ascii?Q?e6tpxlElwlPug0Yzp2glsqCfxvNgmffeOqxvzroXUTAB1dDtTKhcKBdSIo7B?= =?us-ascii?Q?3eZkmB/gc30b41XJv/Yeyk2XLt5Gtps1xLz2faV9g2ilnn4mWNW0osKtkUdf?= =?us-ascii?Q?uo4fTZxqZ+Vf9nMpkCLnExNAzlhMtTTtk3TV6uwysfXqUlz5090gd22QVx1W?= =?us-ascii?Q?st2G9EtYZwlPLzlmvD6qZyJ+YYj5FNxq2GI/hieFO0XdgsLxSF0V7sdRAVRS?= =?us-ascii?Q?0tnN8C4+YQ=3D=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 515f8086-df2d-4c41-e7a8-08df1ea4cf90 X-MS-Exchange-CrossTenant-AuthSource: DM3PR12MB9416.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2026 03:42:11.8219 (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: 0REyKxa88phhklJdpksBQvLlIeJkxz76+iYof6TqYKbSgrwKIEF5c2tGpwzWhwlZHj7dGg+tTKjKeQSm222H8A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6248 Content-Type: text/plain; charset="utf-8" GIN, the GPU Interrupt and Notification unit, is the GPU's interrupt controller. Each interrupt source has a GIN vector number, and the controller latches a pending vector in a two-level tree: one bit of a LEAF register, summarized two leaves at a time by one bit of the TOP register. A vector's number fixes its position in that tree: leaf =3D vector / 32 bit =3D vector % 32 subtree =3D leaf / 2 A tree implements either 8 or 16 leaves, depending on the GPU family. The leaf count sets both the number of subtrees and the highest vector that the tree carries. Without distinct types, a vector, a leaf index, a set of vectors within one leaf, a subtree and a set of subtrees are all plain integers. A caller can pass one where another belongs, and a register field can accept the wrong one. Add a type for each of those, and for the leaf count. A vector converts to its own leaf, bit and subtree. Its constructor rejects, at build time, a number beyond the widest supported tree, and a validation method rejects, at run time, a number beyond the leaves that the current tree implements. A leaf count yields the set of subtrees that it implements. The module has no user yet. Suggested-by: Danilo Krummrich Signed-off-by: John Hubbard --- drivers/gpu/nova-core/irq.rs | 12 + drivers/gpu/nova-core/irq/interrupt_tree.rs | 238 ++++++++++++++++++++ drivers/gpu/nova-core/nova_core.rs | 2 + 3 files changed, 252 insertions(+) create mode 100644 drivers/gpu/nova-core/irq.rs create mode 100644 drivers/gpu/nova-core/irq/interrupt_tree.rs diff --git a/drivers/gpu/nova-core/irq.rs b/drivers/gpu/nova-core/irq.rs new file mode 100644 index 000000000000..f1323f633a03 --- /dev/null +++ b/drivers/gpu/nova-core/irq.rs @@ -0,0 +1,12 @@ +// SPDX-License-Identifier: GPL-2.0 +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIA= TES. All rights reserved. + +//! GPU interrupt support. +//! +//! GIN, the GPU Interrupt and Notification unit, is the GPU's interrupt c= ontroller. It latches +//! every interrupt source in a two-level register tree and delivers the t= ree to the CPU as a +//! message-signaled PCI interrupt. +//! +//! See `Documentation/gpu/nova/core/interrupts.rst`. + +mod interrupt_tree; diff --git a/drivers/gpu/nova-core/irq/interrupt_tree.rs b/drivers/gpu/nova= -core/irq/interrupt_tree.rs new file mode 100644 index 000000000000..206e6940ce77 --- /dev/null +++ b/drivers/gpu/nova-core/irq/interrupt_tree.rs @@ -0,0 +1,238 @@ +// SPDX-License-Identifier: GPL-2.0 +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIA= TES. All rights reserved. + +//! Vector addressing in the GIN CPU interrupt tree. +//! +//! A [`GinVector`] names an interrupt source, a [`LeafIndex`] the leaf re= gister that latches it, +//! a [`LeafMask`] a set of vectors within one leaf, and a [`Subtree`] one= `TOP` bit. The types +//! keep the four from being confused with one another. +//! +//! See `Documentation/gpu/nova/core/interrupts.rst`. + +use kernel::{ + num::Bounded, + prelude::*, // +}; + +use crate::num; + +/// Number of vectors one leaf register carries, one per bit. +const VECTORS_PER_LEAF: u32 =3D u32::BITS; + +/// Number of leaves one subtree covers. +const LEAVES_PER_SUBTREE: u32 =3D 2; + +/// Number of subtrees the widest supported tree implements. +const MAX_NUM_SUBTREES: u32 =3D 8; + +/// Number of leaves the widest supported tree implements. +const MAX_NUM_LEAVES: u32 =3D MAX_NUM_SUBTREES * LEAVES_PER_SUBTREE; + +/// Number of bits needed to address every vector in the widest supported = tree. +const VECTOR_BITS: u32 =3D (MAX_NUM_LEAVES * VECTORS_PER_LEAF).ilog2(); + +/// Index of a leaf register within the widest supported tree. An 8-leaf t= ree implements only the +/// lower half of the range. +pub(super) type LeafIndex =3D Bounded; + +/// Number of leaves a tree implements. +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +#[repr(u32)] +pub(super) enum LeafCount { + /// Turing through Ada. + Eight =3D 8, + + /// Hopper and later. + Sixteen =3D 16, +} + +impl LeafCount { + pub(super) const fn into_u32(self) -> u32 { + // CAST: `LeafCount` is `repr(u32)`, so the cast is lossless. + self as u32 + } + + pub(super) const fn into_raw(self) -> usize { + num::u32_as_usize(self.into_u32()) + } + + /// Returns the number of subtrees a tree of this size implements. + pub(super) const fn subtree_count(self) -> u32 { + self.into_u32() / LEAVES_PER_SUBTREE + } + + /// Returns the set of every subtree a tree of this size implements. + pub(super) const fn subtree_set(self) -> SubtreeSet { + SubtreeSet((1u32 << self.subtree_count()) - 1) + } + + /// Returns the number of vectors a tree of this size carries. + pub(super) const fn vector_count(self) -> u32 { + self.into_u32() * VECTORS_PER_LEAF + } +} + +// `VECTOR_BITS` and `LeafCount::Sixteen` are written separately. This ass= ert keeps them in +// agreement about the widest supported tree. +static_assert!(1 << VECTOR_BITS =3D=3D LeafCount::Sixteen.vector_count()); + +/// Set of vectors within one leaf, one bit per vector. +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +pub(super) struct LeafMask(u32); + +impl LeafMask { + /// Returns the mask with every vector set. + pub(super) const fn all() -> Self { + Self(u32::MAX) + } + + pub(super) const fn from_raw(raw: u32) -> Self { + Self(raw) + } + + pub(super) const fn into_raw(self) -> u32 { + self.0 + } + + pub(super) const fn is_empty(self) -> bool { + self.0 =3D=3D 0 + } + + /// Returns whether every vector in `other` is also in this mask. + pub(super) const fn contains(self, other: Self) -> bool { + self.0 & other.0 =3D=3D other.0 + } +} + +impl From> for LeafMask { + fn from(vectors: Bounded) -> Self { + Self(vectors.get()) + } +} + +impl From for Bounded { + fn from(vectors: LeafMask) -> Self { + vectors.0.into() + } +} + +/// One subtree, held as the `TOP` bit that covers it. +/// +/// # Invariants +/// +/// Exactly one bit is set. +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +pub(super) struct Subtree(u32); + +impl Subtree { + /// Returns the subtree at index `idx`. + const fn new(idx: u32) -> Self { + // INVARIANT: shifting `1` left leaves exactly one bit set. + Self(1 << idx) + } + + /// Returns this subtree's index within the tree. + pub(super) const fn index(self) -> u32 { + self.0.trailing_zeros() + } + + pub(super) const fn into_raw(self) -> u32 { + self.0 + } +} + +/// Set of subtrees, one bit per subtree, in the layout of the `TOP` regis= ters. +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +pub(super) struct SubtreeSet(u32); + +impl SubtreeSet { + pub(super) const fn contains(self, subtree: Subtree) -> bool { + self.0 & subtree.into_raw() !=3D 0 + } + + pub(super) const fn is_empty(self) -> bool { + self.0 =3D=3D 0 + } + + pub(super) const fn intersection(self, other: Self) -> Self { + Self(self.0 & other.0) + } + + /// Returns one more than the highest index in this set, or `0` for an= empty set. An MSI-X + /// allocation that covers the set needs this many entries. + pub(super) const fn span(self) -> u32 { + u32::BITS - self.0.leading_zeros() + } + + /// Returns the subtrees of this set, lowest index first. + #[expect(dead_code)] + pub(super) fn iter(self) -> impl Iterator { + (0..u32::BITS) + .map(Subtree::new) + .filter(move |subtree| self.contains(*subtree)) + } +} + +impl From for SubtreeSet { + fn from(subtree: Subtree) -> Self { + Self(subtree.into_raw()) + } +} + +impl From> for SubtreeSet { + fn from(subtrees: Bounded) -> Self { + Self(subtrees.get()) + } +} + +impl From for Bounded { + fn from(subtrees: SubtreeSet) -> Self { + subtrees.0.into() + } +} + +/// A GIN interrupt vector, bounded to the widest tree that any supported = chipset implements. +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +pub(super) struct GinVector(Bounded); + +impl GinVector { + /// Returns vector number `VECTOR`. + /// + /// Fails to compile if `VECTOR` is beyond the widest supported tree. + pub(super) const fn new() -> Self { + Self(Bounded::::new::()) + } + + pub(super) const fn into_raw(self) -> u32 { + self.0.get() + } + + /// Returns this vector's leaf. + pub(super) fn leaf_index(self) -> LeafIndex { + // CALC: `self.0 / VECTORS_PER_LEAF`. + self.0.shr::<{ VECTORS_PER_LEAF.ilog2() }, _>().cast() + } + + /// Returns this vector's bit within its leaf. + pub(super) const fn leaf_mask(self) -> LeafMask { + LeafMask(1 << (self.0.get() % VECTORS_PER_LEAF)) + } + + /// Returns this vector's subtree. + pub(super) const fn subtree(self) -> Subtree { + Subtree::new(self.0.get() / (VECTORS_PER_LEAF * LEAVES_PER_SUBTREE= )) + } + + /// Checks that a tree with `leaves` leaves implements this vector. + /// + /// # Errors + /// + /// `EINVAL` if it does not. + pub(super) const fn validate(self, leaves: LeafCount) -> Result { + if self.0.get() >=3D leaves.vector_count() { + Err(EINVAL) + } else { + Ok(()) + } + } +} diff --git a/drivers/gpu/nova-core/nova_core.rs b/drivers/gpu/nova-core/nov= a_core.rs index 4f8ce4e4c187..8202c4982efa 100644 --- a/drivers/gpu/nova-core/nova_core.rs +++ b/drivers/gpu/nova-core/nova_core.rs @@ -18,6 +18,8 @@ mod fsp; mod gpu; mod gsp; +#[expect(dead_code)] +mod irq; mod mctp; mod mm; #[macro_use] --=20 2.55.0 From nobody Wed Sep 30 15:28:46 2026 Received: from PH7PR06CU001.outbound.protection.outlook.com (mail-westus3azon11010010.outbound.protection.outlook.com [52.101.201.10]) (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 C86B537CD22 for ; Wed, 30 Sep 2026 03:43:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.201.10 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790739791; cv=fail; b=uGzf8syGiFbn+HX64JijMnIP7WwGtC9IcfSKbuSWrLAnY1qVr592cs2n8+NhdLzZDPxXbNsCX8RAEAnb5gqOKmvxP3Pn4CB0J6bkNpCP2lqM2n1aPEjhfFbGO/IgzuhBU83etZPBwFNcMhQrP/xohqn6ydsFpW5e4tqRMjrJiG4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790739791; c=relaxed/simple; bh=sIEYod+YQt4Hh34VWRpSxJbbkhfzwD2cAcCxhOTGxpo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=glY5nuKtMCVvr5AA+rptplJbYKSZOpSthTbucY1JeR+8CgLE5ZYXsQbNnTcVRW47qPzO87ZOWKpHL8iGt83bUJKnEmFJJTkdSUNE4Rs5m0sCowWOq4WvLXiCEmI0FCMCgg3IBto5KN8wRbajHZB1+c/vdN5HlDQ1h7EV5qkY9Ks= 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=taTbGREX; arc=fail smtp.client-ip=52.101.201.10 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="taTbGREX" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=xZXJKLjNjn4BtLE9gYISQiWTB5Espo19z2eGZdOErnNVpxk0H6BR9nru4SP8Bc6aBaMhSiIxtPSd6T3YoUtVTrvAhRFekCWYWHaraibGnjnsXwRNQqsuuerGKzcEgx3FTyJRVgzv204w8KOdbxvH1AFNL+tC2ebgVqn0KGYfP7ReyLtkkOG2t1QAtah28cgslghehuaHOt41XFcZCBiP/YWFvcm9K1RYagOFkakWd0hzH7TIUKuLbf68cfogjdf8fu1TA09/f6IeI46o6309zrfTgYMHPaFOpjNGK2NM41bzNlxqLK6Yu+bSOrAwyuBxI/NtaH6Zi23jgJljDI0y+A== 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=dQctFBIhTHElMhQZDAbG0RPRPrZw5FwMzc5atf+bgRg=; b=Zxr9EFtIgAkMGk+J6GKWtbFB9YxSCOmFqergcNxQql7GecKFhgEVaucCazxlKe4btIh0K/H0oXmaah+mF/o7wZMwd9I4cWQlbirEniJAAeRv1CdFIIf1TLHFw9dNVwGTUv5uQRFq+d6ipxujlAedTe5xlZ1yaR5+zRDlNqurTAKNxyOv63+tNtCTznHL1kReGMiCRuZxmpsjsA9YKQTjBvSbVOxjirfcMU5K0LTe0qZPbb70AyUL7n2M94eiJh2//W9b9KScAEjSLr09DuXyxIJvbmInTEzHr97oOkGjoM/qP+L0ZQLXdSO9ohDL99ydDqoEMrcrU7m6PfrAvgO+NA== 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=dQctFBIhTHElMhQZDAbG0RPRPrZw5FwMzc5atf+bgRg=; b=taTbGREXQfKzPsudnIu9KJjW3InVim4oR5+Hb5ES5UZs5WVBwvG5w1zMDXrecCiBB/TTTA+sG3zvvDg871rYJee/RfkDYNpmxCfrPwY2+gpy6dgjuVr26JRTMbS6SSyb+u0EH6CVIbvtPzkgVJ7tYnYjCKb8/GI1uV3Km7rnTB64mxUGb03i0Az8w6krimzvYvEGv5kbuVZqnlSe9OcMhBX2irONqEK1sfD1I6Qko5akp4QIy3ndvcDkoEO9fscDVCoxujWf/xnMJgKHcTjCG7GBdrUIq4fzZk1Htg8KmRDrfpiXP+n0WdW8GRor0y5ytXi2pZp65F7QtZmG6Ois9w== Authentication-Results: mx.microsoft.com 1; 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 MN0PR12MB6248.namprd12.prod.outlook.com (2603:10b6:208:3c0::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.451.26; Wed, 30 Sep 2026 03:42:13 +0000 Received: from DM3PR12MB9416.namprd12.prod.outlook.com ([fe80::8cdd:504c:7d2a:59c8]) by DM3PR12MB9416.namprd12.prod.outlook.com ([fe80::8cdd:504c:7d2a:59c8%4]) with mapi id 15.21.0451.024; Wed, 30 Sep 2026 03:42:13 +0000 From: John Hubbard To: Danilo Krummrich , Alexandre Courbot Cc: Timur Tabi , Alistair Popple , Eliot Courtney , 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 , nova-gpu@lists.linux.dev, LKML , John Hubbard , Will Pierce Subject: [PATCH v5 04/15] gpu: nova-core: add the GIN CPU interrupt tree and MSI EOI registers Date: Tue, 29 Sep 2026 20:41:37 -0700 Message-ID: <20260930034148.590687-5-jhubbard@nvidia.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260930034148.590687-1-jhubbard@nvidia.com> References: <20260930034148.590687-1-jhubbard@nvidia.com> X-NVConfidentiality: public Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: PH0PR07CA0049.namprd07.prod.outlook.com (2603:10b6:510:e::24) To DM3PR12MB9416.namprd12.prod.outlook.com (2603:10b6:0:4b::8) 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: DM3PR12MB9416:EE_|MN0PR12MB6248:EE_ X-MS-Office365-Filtering-Correlation-Id: c7bdf11a-d7d3-44d4-0224-08df1ea4d096 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|23010399003|366016|7416014|376014|10067099003|56012099006|5023799004|11063799006|6133799003|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: XXW1E/u1ZNAMJavjBxBy0lam4z8VLuj1HA327EcYn3JibE7mefBY0lH4o7Agpjr9dHLc7l5u78eNhdWt60tpJsOzlW9Qq8o9rthIkN1+ghgSkkMC+ahF9N5nVua/QQtopd7p8yByTcaQnPmE1JQuaIbBzvPVveQk/X73hIg9j83Mu/T4TzUj3FuBOQRvkVDRyvyPCsPtPxO+MPC5i3QYkl4Zl/nUpqtzWJJnwO1wwMmhTZ4xRO1RyXvfKFh5lEvFvqunW82M9bK+FCxZJAINH9Ekqi+Qix52lk11JLzqyOaJOg6WWt41M7aIs4ZmZeOycJlji2GmM9uyvMuRPVU1Dj72iijLDCtEe9MpMuHAzH03D5ywVIKwVozD2G2wSwYdGrrOsnWPQ30Az4lLVe5OW0SLx0da5RWnFDCU8K5/vB2FOWNDzlaYvNfrs5GdzJGyP7Iu2NQP7vJDyb6jrWTmc1E6SDmVcOmn21R7wg+d0spgbokqE5x3rhPMl/sH6cOnorsjsvZT+4erT6KxzI50N1I1a800bTGYNboyV7tKwXOwxRnv6ZQumST6jJr/XH7ZHdolGYkUq+B3LRGAtYWenhoXaSiCpUOJ/geKbageVoYZTPYspzthqkDcHzgqHVlFqoRDWQnGfFXmW3uNczjFaeE4BpDM8drP3J41GcpHtNY= 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)(1800799024)(23010399003)(366016)(7416014)(376014)(10067099003)(56012099006)(5023799004)(11063799006)(6133799003)(18002099003)(22082099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?WGFvKBZfryGCFTLhocmh/RnHcn3zWUJc3v2MEKl9L3doBN6J0OJy26oNnSZo?= =?us-ascii?Q?JGkLoXSnA0aG49caCkJwn1AVnaNYeSgBZUIryEPhjUIpPO1VnXX0B6e3pkdu?= =?us-ascii?Q?t0fvKUAI10KBxpIAIb7rqVPThII2KWTN6MdLTT9exyNTdCrF39ejNizEcSVS?= =?us-ascii?Q?2eQHRKU7kh3CakKfLGqEnzgpBoIjvBFNkxCmbwdYk1OhJNWukTmO+SVzfbVh?= =?us-ascii?Q?TOPUi1+YquuonTlbkMC7StOi8W53UYpQ1B88ZrNRvAjzyiBl53e8kqvpcsGS?= =?us-ascii?Q?Yt0gU9+PJ+FvVsWw8pfO3tXP9nnDPUGppAO8fYcg56+Jvkj3+gL08HIhcDZy?= =?us-ascii?Q?yynRZBuaYz5GHHOMmsBecmznNTLHL5Ra/WHtOnjCsD9Ssn6NBDz9NlAJmUF2?= =?us-ascii?Q?lHqz0OnFeyLk7hE1/7uXZJFMeuuuanNpYTEqJGHS2CWP0nDM68iB/HO8cRZr?= =?us-ascii?Q?lNAZVegmV+dDX1ZMFx+u2+69IUsDOWlZn5E4g8IXEEGSEyAUKHohxjXyJT4R?= =?us-ascii?Q?axwBl90K5twmDELvEppRZ6ZScWjKDYwKRyLuLzJMqY9WPuiMux/CVqxDuPrb?= =?us-ascii?Q?LMxti4VLDpXUo7f/Q4Z6EzqAhsKohk4ShhEdIDw6WWcjsJOQZWBHk6sdECHO?= =?us-ascii?Q?nTj4QqyWcTncS2Ok12SRDFAQAHOGpiVpJfXw9FHQAAwzLu9kl5KBi/uNYhkm?= =?us-ascii?Q?wwXuuil9PF6yLaJ5avo0zkTn6USiKXyqZGakE3GaJOQ+fj3FUSsOECeG3hlr?= =?us-ascii?Q?+pE+o877CjHIR4So0lN7un6RjkNGnVI/lPQsvXQX2W9fT4tjj1FgcJ8VkdVi?= =?us-ascii?Q?bDX9epUcQlaEQBJn5FnJdJ8X9WTT1bekfe/8Y6dDgbKugE+FzS4FQ/BAfsRF?= =?us-ascii?Q?x2/rLpVCFz+SMtGTqK3eUihwh+NHf0hVLlUReXe+BvgJvYCMPfpyw1sBYuGS?= =?us-ascii?Q?OGAa4vL7X85diy4E6OKz40N7PE14t1CykmNNSEcg69xjMYwmDY3lHUIQBTTF?= =?us-ascii?Q?NQCWTzROm301L4mE3LhGEUK6itzMlFqlqZ5PF7QfI+EwPyZoIj9Kn2W3fJRN?= =?us-ascii?Q?rfnZ+9UpTw/X4IepnpKJ9WhgUQTDMgadRAHmcBFZQ+DmDVOUofbuu/9I/JZT?= =?us-ascii?Q?0cVrOv9BMZE5xoJ5sZgaLvLx9tnvp7gT1muP47N4hhXCfmQTks53Ym9fdtuR?= =?us-ascii?Q?0ZSk82aEV7ejoew0EA2afmFp47d1izsF/JEaECyf06H/WRmrAuf5R+4dqqrZ?= =?us-ascii?Q?CbxNiXuetxqu3aSeGaRAq+05PHbEHou5pfpTHGjPS000rtAvR36LEGILwo1z?= =?us-ascii?Q?EHBY2YlbkMQNHis84mAimgFAjkuDjJc9+C/MglwvU1V1BRnAPUIpEBHMxKiP?= =?us-ascii?Q?Fj381a9+CXrLwtESz0j7VNDhnPvezZs269rIWfWUUR7wlqQAYM2P557tFCJM?= =?us-ascii?Q?Vpd79d1pjdYEIy3nCA5J7mWE1k04CHkBHfBfeWqpyJX/MSvoS1Z8tajLhZFN?= =?us-ascii?Q?Ua9dRQp5HHaNl390FkT067OocjmqGf5ly7HItTzwDIYLhNUPOg+DhQPzDkFL?= =?us-ascii?Q?nsRrRuSUay80fHYUi61Eddg4jD9Odllc4ImYxfW+P/ozg949Dz+onXMCEhid?= =?us-ascii?Q?aND96uQsNGfsBd8+BKdyvkhrBlevgW4Ywj/wFezUVOFTPVk/9ZtoJy+xPx82?= =?us-ascii?Q?dVH8yO6uRlftqe1L2/+4pkna2q0SMoEW19EzwgLBl4+k8bMwlGkmn4JdbS1S?= =?us-ascii?Q?f/dsftp3WQ=3D=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: c7bdf11a-d7d3-44d4-0224-08df1ea4d096 X-MS-Exchange-CrossTenant-AuthSource: DM3PR12MB9416.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2026 03:42:13.4293 (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: Or/cYGOcmkPbqlyGsdWlvjCzM4jWB6Pf4h+ymwi5/7r9v0Yr3DBN5YS9unRhMqsfkal/WSO2Raj9c3oox4UZpg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6248 Content-Type: text/plain; charset="utf-8" GIN is the GPU's interrupt controller. It latches each interrupt source in a two-level tree of LEAF registers summarized by TOP, and raises the PCI interrupt when an enabled vector in an enabled subtree becomes pending. A message-signaled interrupt is delivered once per edge, and pre-Hopper MSI rearms delivery by writing the end-of-interrupt register in the BAR0 mirror of PCI configuration space. Add the CPU tree registers that receiving GSP interrupts and running the software-triggered self-test need: the leaf pending and enable arrays, the TOP enables, and the leaf trigger. Add the end-of-interrupt register, NV_XVE_CYA_2, alongside them. Use the NV_VIRTUAL_FUNCTION_PRIV_CPU_INTR_* names on every chipset. The pre-Hopper headers call the same tree NV_CTRL, but each function reaches its own tree through this aperture on both families. Declare the leaf arrays at 16 entries, the widest tree that any supported chipset implements. Leave the read-only TOP summary undeclared. A vector that latched while disabled does not appear in TOP, so nova-core never descends from it and reads every implemented leaf instead. Declare each leaf field as a set of vectors within one leaf and each TOP field as a set of subtrees, so that a set of subtrees cannot be written to a leaf register, nor the reverse. The trigger register's vector field is 12 bits wide, wider than any GIN vector, so a vector converts into it infallibly. Assisted-by: LLM Reviewed-by: Will Pierce Signed-off-by: John Hubbard --- drivers/gpu/nova-core/irq.rs | 1 + drivers/gpu/nova-core/irq/interrupt_tree.rs | 14 ++++ drivers/gpu/nova-core/irq/regs.rs | 88 +++++++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 drivers/gpu/nova-core/irq/regs.rs diff --git a/drivers/gpu/nova-core/irq.rs b/drivers/gpu/nova-core/irq.rs index f1323f633a03..1ec0bb055d3b 100644 --- a/drivers/gpu/nova-core/irq.rs +++ b/drivers/gpu/nova-core/irq.rs @@ -10,3 +10,4 @@ //! See `Documentation/gpu/nova/core/interrupts.rst`. =20 mod interrupt_tree; +mod regs; diff --git a/drivers/gpu/nova-core/irq/interrupt_tree.rs b/drivers/gpu/nova= -core/irq/interrupt_tree.rs index 206e6940ce77..279a43514b1f 100644 --- a/drivers/gpu/nova-core/irq/interrupt_tree.rs +++ b/drivers/gpu/nova-core/irq/interrupt_tree.rs @@ -16,6 +16,8 @@ =20 use crate::num; =20 +use super::regs::*; + /// Number of vectors one leaf register carries, one per bit. const VECTORS_PER_LEAF: u32 =3D u32::BITS; =20 @@ -31,6 +33,12 @@ /// Number of bits needed to address every vector in the widest supported = tree. const VECTOR_BITS: u32 =3D (MAX_NUM_LEAVES * VECTORS_PER_LEAF).ilog2(); =20 +/// Width of the vector field in the leaf trigger register. +const TRIGGER_VECTOR_BITS: u32 =3D { + let range =3D NV_VIRTUAL_FUNCTION_PRIV_CPU_INTR_LEAF_TRIGGER::VECTOR_R= ANGE; + num::u8_as_u32(*range.end() - *range.start() + 1) +}; + /// Index of a leaf register within the widest supported tree. An 8-leaf t= ree implements only the /// lower half of the range. pub(super) type LeafIndex =3D Bounded; @@ -236,3 +244,9 @@ pub(super) const fn validate(self, leaves: LeafCount) -= > Result { } } } + +impl From for Bounded { + fn from(vector: GinVector) -> Self { + vector.0.extend() + } +} diff --git a/drivers/gpu/nova-core/irq/regs.rs b/drivers/gpu/nova-core/irq/= regs.rs new file mode 100644 index 000000000000..4ddd01bcbb23 --- /dev/null +++ b/drivers/gpu/nova-core/irq/regs.rs @@ -0,0 +1,88 @@ +// SPDX-License-Identifier: GPL-2.0 +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIA= TES. All rights reserved. + +use kernel::io::register; + +use crate::driver::NovaRegisters; + +use super::interrupt_tree::{ + LeafMask, + SubtreeSet, // +}; + +// The GIN CPU interrupt tree, reached through the `NV_VIRTUAL_FUNCTION_PR= IV` aperture. See +// "Register naming" in `Documentation/gpu/nova/core/interrupts.rst`. The = leaf arrays are declared +// with 16 entries, the widest tree that any supported chipset implements. + +register! { + base: NovaRegisters; + + /// Pending bits of one leaf, one per vector. + /// + /// Vector `v` is bit `v % 32` of leaf `v / 32`. The bit is set when t= he vector's source + /// drives it, whether or not the vector is enabled. Writing a `1` cle= ars the bit, and a `0` + /// leaves it as it was. + pub(super) NV_VIRTUAL_FUNCTION_PRIV_CPU_INTR_LEAF(u32)[16] @ 0x00b8100= 0 { + /// The vectors pending in this leaf. + 31:0 vectors =3D> LeafMask; + } + + /// Enables vectors of one leaf. + /// + /// A `1` enables the matching vector, and a `0` leaves it as it was. + pub(super) NV_VIRTUAL_FUNCTION_PRIV_CPU_INTR_LEAF_EN_SET(u32)[16] @ 0x= 00b81200 { + /// Vectors to enable. + 31:0 vectors =3D> LeafMask; + } + + /// Disables vectors of one leaf. + /// + /// A `1` disables the matching vector, and a `0` leaves it as it was.= A disabled vector still + /// latches in `LEAF`, and `TOP` does not show it. + pub(super) NV_VIRTUAL_FUNCTION_PRIV_CPU_INTR_LEAF_EN_CLEAR(u32)[16] @ = 0x00b81400 { + /// Vectors to disable. + 31:0 vectors =3D> LeafMask; + } + + /// Enables subtrees. + /// + /// Bit `N` covers subtree `N`, which is leaves `2N` and `2N + 1`. A `= 1` enables the matching + /// subtree, and a `0` leaves it as it was. + /// + /// The hardware headers declare a one-element array, so nova-core dec= lares a scalar. + pub(super) NV_VIRTUAL_FUNCTION_PRIV_CPU_INTR_TOP_EN_SET(u32) @ 0x00b81= 608 { + /// Subtrees to enable. + 31:0 subtrees =3D> SubtreeSet; + } + + /// Disables subtrees, with the bit layout of `TOP_EN_SET`. + /// + /// A `1` disables the matching subtree, and a `0` leaves it as it was= . A disabled subtree + /// delivers nothing, and `TOP` still reports it. + pub(super) NV_VIRTUAL_FUNCTION_PRIV_CPU_INTR_TOP_EN_CLEAR(u32) @ 0x00b= 81610 { + /// Subtrees to disable. + 31:0 subtrees =3D> SubtreeSet; + } + + /// Latches a vector from software. Write-only. + /// + /// The write sets the pending bit of the vector in its `LEAF` registe= r, as if the vector's + /// source had raised it, and the vector reaches the CPU under the sam= e enables. Implemented on + /// every supported chipset. + pub(super) NV_VIRTUAL_FUNCTION_PRIV_CPU_INTR_LEAF_TRIGGER(u32) @ 0x00b= 81640 { + /// Vector to latch. + 11:0 vector; + } +} + +// PCI configuration-space mirror in BAR0. + +register! { + base: NovaRegisters; + + /// MSI end-of-interrupt register. Writing any value rearms MSI delive= ry. + /// + /// Only pre-Hopper MSI rearms through this register. See "Rearming PC= I interrupt delivery" + /// in `Documentation/gpu/nova/core/interrupts.rst`. + pub(super) NV_XVE_CYA_2(u32) @ 0x00088704 {} +} --=20 2.55.0 From nobody Wed Sep 30 15:28:46 2026 Received: from CH1PR05CU001.outbound.protection.outlook.com (mail-northcentralusazon11010011.outbound.protection.outlook.com [52.101.193.11]) (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 CC115221FB6 for ; Wed, 30 Sep 2026 03:43:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.193.11 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790739792; cv=fail; b=M67kK0LfMaB6bp3hVaN6z5L4/Y4mZM0AGirw8aIukP9Yr8A+wmXH2YwXDqjFs8juLC3N9BWPZDbrM2sqo01EV3dgF2jNP3yKUgszM7cEgwZr27CFASOKCyL9mzM3i7PDQPqmFL4SGoMgwEJdzw7CdqJBLlmWCMl7gVUyOl3Gdu4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790739792; c=relaxed/simple; bh=j3ebPshD/rSF4Pr+NgUdkPyyd04+APpu5PG/xfzx8Vg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=lL1RZrB9ihIzgEhyitYyKgce5x+cgNgTNYiZhi1Eg5TVUSWWYgO0Tjao1WUgv/te4s4S1Oc5NO4JK6Vauq/wI4hMogKSh0g41/9UiBxQo1X507o8ZNdUy6bxwjnezhojMjp03L3s0TynN3XRl+LrHwmTm+2PwzQ6bHVxLqJrUAw= 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=cNLqq5+t; arc=fail smtp.client-ip=52.101.193.11 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="cNLqq5+t" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=pwa6eV0iNVM02woDwU9RyDIHUFBVqH9ZVrEDNdDIGKGy28LBHjCXZ+MHgmN7QkfM3huRrrUjBjeT8DpuWDDDd9RXCxWplAB5PWp6K3mjj8L6BeLQ46lOgi6ahRybFn00QzgoXeGj3/mDQ00u7dAJKQwhwDaSevy+BjZnrIOG+Nr0yxLSG/Z7q/FQ6lPuL86bhwINWhPLIwdtlZ1oBDHObn54aFOaYAau6KYOJ6+BZCwinfq+tJmniiue4V2Tp0VOtqs/u+9h4ZpU6NsRk8bDz6MtjPUrAhOT0GUtL1onA3rYWRj5BrJLLxFmGUcnx4EBRzjiFiEu9BWnvos+ohT0gg== 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=t2VWx/RFrbcot4atdTAqI6b6sI07VKnG8eXOO8rbh3s=; b=qa+Wgv0OMZO0ME2Vz/psMLqZaJ+gEOha4zMmB31VSqt4v8olVJRFN3VvzURh2gU3eX9hCHDLngDyWKoYFfIhy54ysws3ZYoOc+gS2JNKNM8QnELx1pZcXYynhiVJAyfstPLot2E2vktbkXaQqdKfnSeHUnZK7fHjG3ERBr5s7J+D8kVXbF7WNwDmOIPXFTS91OHQe7kv4l95FbSb+PoEgdb4sR/dxqqsb8TJgZWLb0xmfH/SV02L9D6ulLLPRppuMTNyNylyQK+jpT/7W3j/BVtkuQKLS7xdY+bIOSz3HsHv0oSRV7EpGZ1f7o2gJKRly0CGJuYvGmvtRwVwXRhm9Q== 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=t2VWx/RFrbcot4atdTAqI6b6sI07VKnG8eXOO8rbh3s=; b=cNLqq5+tERo98Ol9/HOHjI/2jnakbbn8ULkUUaI46YY3I0YBVyc92g0xt+BikguJnUckuGzyhNGqz+9ugPVIa6rxPqx7v/1llEomzVWrX2fMR8GqV6T4M6W60PUQUKQCiIuFjYQvKo1Nxy9HpHQ+bI3ZXjyea4sqLnl6Uiqmxrsi42IKHmTj9bHEINoaJWv9783EThktRqmkvE1kp5LNSCGvJRxKY40edAZYj31QTwxmW+aMTMo9L0oVBIg1kYVTyUv/bi8bTpTFgoXxI5yqfkL4a7A9WYCz3EiUqemwFQi2SSQpphb/SNEtx+QK7t3yRNpM9DRzouM1nGMBbsCYPA== Authentication-Results: mx.microsoft.com 1; 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 MN0PR12MB6248.namprd12.prod.outlook.com (2603:10b6:208:3c0::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.451.26; Wed, 30 Sep 2026 03:42:14 +0000 Received: from DM3PR12MB9416.namprd12.prod.outlook.com ([fe80::8cdd:504c:7d2a:59c8]) by DM3PR12MB9416.namprd12.prod.outlook.com ([fe80::8cdd:504c:7d2a:59c8%4]) with mapi id 15.21.0451.024; Wed, 30 Sep 2026 03:42:14 +0000 From: John Hubbard To: Danilo Krummrich , Alexandre Courbot Cc: Timur Tabi , Alistair Popple , Eliot Courtney , 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 , nova-gpu@lists.linux.dev, LKML , John Hubbard , Will Pierce Subject: [PATCH v5 05/15] gpu: nova-core: add the per-architecture GIN CPU interrupt HAL Date: Tue, 29 Sep 2026 20:41:38 -0700 Message-ID: <20260930034148.590687-6-jhubbard@nvidia.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260930034148.590687-1-jhubbard@nvidia.com> References: <20260930034148.590687-1-jhubbard@nvidia.com> X-NVConfidentiality: public Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: PH8P222CA0002.NAMP222.PROD.OUTLOOK.COM (2603:10b6:510:2d7::31) To DM3PR12MB9416.namprd12.prod.outlook.com (2603:10b6:0:4b::8) 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: DM3PR12MB9416:EE_|MN0PR12MB6248:EE_ X-MS-Office365-Filtering-Correlation-Id: e2433b64-5242-46ee-b56f-08df1ea4d167 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|23010399003|366016|7416014|376014|10067099003|56012099006|5023799004|11063799006|6133799003|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: RHhrdn2EYAkoB61jOwKvD+3vCHp6BDsollX7Y+aE7gBbAcoNgcVEdvhL7CEV9qqm2BgvEVvJAq/sm3snCB5uWHfK/YBADZICRCwYHo3i80IveqUJLrukVCRyiVhrVHsukMoWBjqdsEsPQVy47WbfgMTkD2QYrALsLJDPQkubjuZ2vcWNw+JvD6RYbEtvklOCFCoaYAuDXiXHW//0admZdpoZi/fRmFiWGBvqt395oNPTaPyjhu54DwYYNeU7+eruHCwOqBP01ou++WWfFpIpSEMrlZkyZMaN+KEMy5n93MrBwBEZ2e17JKYJUMMWSDULc7KP6GWFB0BPVnA3dtCZ9zJ0RtNRU2z2AcrpFpvwWkO/ta1Ab/z/aw2DNU9CunT+87iYpP36IvlokApoePlEJQCS2ZSoeZAwbdju9gOLfX0NcijoyUFdDQiQPv0sCh+9sCfi5doV7XgI+3P7oDdPUi6tNetq3ScBU1L3mCvVU72j5cT+RuZw5BAVj255bkSxobclYEu2s9+Y9+rGzrz+PABPd7f0XBj92d8PmPvoULfHr9EjREFyRuE1yZRgoVLqu2BQpRSYwkM0bzzL6aDQMkf2NbmH7hLha11TkoB9GMgNBkB57HnfbQNHgp/jIVgPY3geBY0xu/PwmZy96hxtxhI9Uk2C/uQoi58o213CjQQ= 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)(1800799024)(23010399003)(366016)(7416014)(376014)(10067099003)(56012099006)(5023799004)(11063799006)(6133799003)(18002099003)(22082099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?dxLVg/QwO8Dau8qddOtwZ+f0eP/o6xdPn6sY09fRJWIGjZhL4YIClfSS14Yb?= =?us-ascii?Q?HRjl2zYUAnGtyydFhGTf47dkjhNwdukP7gvJb6naSFVDXsFXDQuxmIpCz/iv?= =?us-ascii?Q?fAwGBhJldQK05TjP7DAA1Lja//cOt5r5Qll7iapKPvkliH2dvtEuzyqhRtCO?= =?us-ascii?Q?zBzKR5Vh3mU8GlZ4ti9sj/EZ2KzXL0bQES3avUHBhyE4VLDMaqjLxZ/KKabp?= =?us-ascii?Q?ap/GlwHAqekxkISR767ZyhfbVW7A5+jXfmJWiMlZTT1dapxFK153s9Wl45UL?= =?us-ascii?Q?ilLROuwfcX/zJJDpYlH5PHaEYEfIgsGdU2YrPALFfEVK9hfwnQ86Uo/GDlGb?= =?us-ascii?Q?GcQYsgrynlzuR5OQGnNbITc2R07dobvWU2/BdIT1gZwQHa4ePS7HW+VnAkSd?= =?us-ascii?Q?gsawdfldu//FCajCD41iklBkVwHR/FqdqUwS5MEV00vBwUuzsqjeCTIKLICy?= =?us-ascii?Q?lnfsYqKhKlyM+1pu0rQLXA1o+nqRx1rBPutNuVkCgqGXmZHa9aO+WwCv+6g8?= =?us-ascii?Q?Ebp+dVFpU1K+gIC6TtppPgxXLb2ArLsgq4TSVnBiO+3QAqAv/l4jSZNMKqyZ?= =?us-ascii?Q?qsi0JWAX74xA3WuCCyp/UoLIMTGKmTKebRXTcbJBPrhjr0RAmmuziHHE1eZZ?= =?us-ascii?Q?9RoPd51K2//xjefas6K45G0OB3SY0Ygf5nv+7fwv68D3E85QYAdz0+vlSYVx?= =?us-ascii?Q?ZD+zEtTIy3AE0eD+Zw+HetGMUdnxI2P9hSBI/m7NcAFjVs+ydVT1tRomMaA5?= =?us-ascii?Q?Al4vpQXneGRnAbTYZEgZ1eEO4mYVRIVBM7WPYl7BcsNYzWT/657lttpOlOmo?= =?us-ascii?Q?2RsnsOFOHu+uMb7RsQhuneHe3R2EVfIv6dHlFp+Una2bPNbrzm+0A3zn11Pq?= =?us-ascii?Q?/DewgKfcYs5UQXYLJVd7xPGLClY7dr2wGKIcX4rX6X8WjJJqHvnnm9uKKmrw?= =?us-ascii?Q?zbDgdAEmugG4I8Es5fRmgqkepBoR8csYDAmMKReVAb8Uydst9hgykH/Q1s17?= =?us-ascii?Q?pE0wbuBSfDBHB0K/WOq1YI5CsRSkpz2vuaTlziES+4qUUW3xhvfuQw25I4ni?= =?us-ascii?Q?GWaFn8phJC6/FsXPdVhUad0jHQA9E9arNsjMepd2MrUO0IqdrNoJ4rjY5cCw?= =?us-ascii?Q?4+l9rOnJmG53I0BzT32PoGVzWzgGBt2/pqPZCOfPA1wwVpsvQuMdWkCGmOPA?= =?us-ascii?Q?tDTD3YSM4ikA40qsrK1BLh2FxDPvC4M9qeD1MZHYvgw5FIGWDupIM3uSteef?= =?us-ascii?Q?jQig9S8yWSduFNb4ozAif7/snTpsjmagnwDs6E6FEpYjtl6x1ZmldsTgqOJM?= =?us-ascii?Q?RfYEV8rnDjJstEP79UHAXKLJ5lozuJ8+u3i7KGVR++M+gMZlRByEYn2zVxam?= =?us-ascii?Q?EosOCTxCLjTL73AsDPaBlAJks8z9urqtwmcTe+3Lfu07HO5NFQtGRbHC+RTp?= =?us-ascii?Q?GC7u9vyhBx5ybSRt02ORgjh9TPhXDkeN4516sIuu5WVjrnmjrkM+P6nhnFyL?= =?us-ascii?Q?qg2rATlo/pYXtmc/+OixGJCDs3yAmD1OR7Z9fvHs+/G9GQidE1GA2Y12c0Qz?= =?us-ascii?Q?eq5PzJj7LizXLw6VoYEpbJcCWMwyoUZV3N1rNNJNPmvnCbOTwWYe1qxtpHP+?= =?us-ascii?Q?o+zdNgwVPHm4rGWOFKd8GweUiyJFwOknN/XF0up9x6zrdQmThxhaRu5d6ySK?= =?us-ascii?Q?gULcYiwqjihe56F58DYMUUL2CQfkjcrqh2aFYTRBjbkdL3piuEzcAZm8+5HE?= =?us-ascii?Q?RXxavH88AQ=3D=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: e2433b64-5242-46ee-b56f-08df1ea4d167 X-MS-Exchange-CrossTenant-AuthSource: DM3PR12MB9416.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2026 03:42:14.7889 (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: wTwjqFT5RFRONhMKwUApEWCpNUgpA8xFCU637O6DMisPWBNp6dy26MZ3PDuLE7DSfpqEjJmio4x96Sj/VMFTAQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6248 Content-Type: text/plain; charset="utf-8" The GIN CPU interrupt tree differs by GPU family in two ways: * The size of the tree. Turing, Ampere and Ada implement 8 leaves. Hopper and later families implement 16. * The write that rearms delivery. A message-signaled interrupt is delivered once per edge, and the PCI side delivers nothing more until the CPU rearms it. Before Hopper, MSI rearms by writing the end-of-interrupt register in the BAR0 mirror of PCI configuration space. On Hopper and later, MSI rearms by clearing and then setting the TOP enables of every serviced subtree, which produces a new edge. MSI-X rearms the same way on every family, but for the handler's own subtree only, since each subtree has its own table entry. Add an interrupt HAL that provides the leaf count and performs the rearm for each family. Name the interrupt type with two variants, MSI and MSI-X, since nova-core never allocates the level-triggered INTx that the kernel's PCI interrupt type also names. The HAL has no user yet. Assisted-by: LLM Reviewed-by: Will Pierce Signed-off-by: John Hubbard --- drivers/gpu/nova-core/irq.rs | 13 +++++ drivers/gpu/nova-core/irq/hal.rs | 67 ++++++++++++++++++++++++++ drivers/gpu/nova-core/irq/hal/gh100.rs | 40 +++++++++++++++ drivers/gpu/nova-core/irq/hal/tu102.rs | 43 +++++++++++++++++ 4 files changed, 163 insertions(+) create mode 100644 drivers/gpu/nova-core/irq/hal.rs create mode 100644 drivers/gpu/nova-core/irq/hal/gh100.rs create mode 100644 drivers/gpu/nova-core/irq/hal/tu102.rs diff --git a/drivers/gpu/nova-core/irq.rs b/drivers/gpu/nova-core/irq.rs index 1ec0bb055d3b..62c242b71dc8 100644 --- a/drivers/gpu/nova-core/irq.rs +++ b/drivers/gpu/nova-core/irq.rs @@ -9,5 +9,18 @@ //! //! See `Documentation/gpu/nova/core/interrupts.rst`. =20 +mod hal; mod interrupt_tree; mod regs; + +/// The message-signaled interrupt type that Linux granted. +/// +/// nova-core never requests INTx, so this has no variant for it, unlike [= `kernel::pci::IrqType`]. +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +enum MsiType { + /// A single message, which every subtree raises. + Msi, + + /// One table entry per subtree. + MsiX, +} diff --git a/drivers/gpu/nova-core/irq/hal.rs b/drivers/gpu/nova-core/irq/h= al.rs new file mode 100644 index 000000000000..387695cca37b --- /dev/null +++ b/drivers/gpu/nova-core/irq/hal.rs @@ -0,0 +1,67 @@ +// SPDX-License-Identifier: GPL-2.0 +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIA= TES. All rights reserved. + +//! Per-architecture differences in the GIN CPU interrupt tree. +//! +//! See "Per-architecture differences" in `Documentation/gpu/nova/core/int= errupts.rst`. + +mod gh100; +mod tu102; + +use kernel::{ + io::Io, + prelude::*, // +}; + +use crate::{ + driver::Bar0, + gpu::{ + Architecture, + Chipset, // + }, // +}; + +use super::{ + interrupt_tree::{ + LeafCount, + Subtree, + SubtreeSet, // + }, + regs::*, + MsiType, // +}; + +/// Clears and then sets the `TOP` enables of `subtrees`, which produces a= new delivery edge. +fn cycle_top_enables(bar: Bar0<'_>, subtrees: SubtreeSet) { + bar.write_reg(NV_VIRTUAL_FUNCTION_PRIV_CPU_INTR_TOP_EN_CLEAR::zeroed()= .with_subtrees(subtrees)); + bar.write_reg(NV_VIRTUAL_FUNCTION_PRIV_CPU_INTR_TOP_EN_SET::zeroed().w= ith_subtrees(subtrees)); +} + +/// The leaf count and the rearm of the GIN CPU tree, which differ by GPU = family. +pub(super) trait CpuInterruptHal: Send + Sync { + /// Returns the number of leaves the tree implements. + fn leaf_count(&self) -> LeafCount; + + /// Rearms PCI interrupt delivery after a handler serviced `subtree`. + /// + /// `serviced` is every subtree that nova-core services, for the Hoppe= r-plus MSI form, which + /// cycles the `TOP` enables of them all. See "Rearming PCI interrupt = delivery" in + /// `Documentation/gpu/nova/core/interrupts.rst`. + fn rearm_pci_irq( + &self, + bar: Bar0<'_>, + msi_type: MsiType, + serviced: SubtreeSet, + subtree: Subtree, + ); +} + +/// Returns the [`CpuInterruptHal`] for `chipset`'s architecture. +pub(super) fn cpu_interrupt_hal(chipset: Chipset) -> &'static dyn CpuInter= ruptHal { + match chipset.arch() { + Architecture::Turing | Architecture::Ampere | Architecture::Ada = =3D> tu102::TU102_HAL, + Architecture::Hopper | Architecture::BlackwellGB10x | Architecture= ::BlackwellGB20x =3D> { + gh100::GH100_HAL + } + } +} diff --git a/drivers/gpu/nova-core/irq/hal/gh100.rs b/drivers/gpu/nova-core= /irq/hal/gh100.rs new file mode 100644 index 000000000000..6e307c8d120b --- /dev/null +++ b/drivers/gpu/nova-core/irq/hal/gh100.rs @@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-2.0 +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIA= TES. All rights reserved. + +use crate::driver::Bar0; + +use super::{ + cycle_top_enables, + CpuInterruptHal, + LeafCount, + MsiType, + Subtree, + SubtreeSet, // +}; + +/// The CPU interrupt tree properties of Hopper and Blackwell. +struct Gh100; + +impl CpuInterruptHal for Gh100 { + fn leaf_count(&self) -> LeafCount { + LeafCount::Sixteen + } + + fn rearm_pci_irq( + &self, + bar: Bar0<'_>, + msi_type: MsiType, + serviced: SubtreeSet, + subtree: Subtree, + ) { + let subtrees =3D match msi_type { + MsiType::Msi =3D> serviced, + MsiType::MsiX =3D> subtree.into(), + }; + + cycle_top_enables(bar, subtrees); + } +} + +const GH100: Gh100 =3D Gh100; +pub(super) const GH100_HAL: &dyn CpuInterruptHal =3D &GH100; diff --git a/drivers/gpu/nova-core/irq/hal/tu102.rs b/drivers/gpu/nova-core= /irq/hal/tu102.rs new file mode 100644 index 000000000000..7e3aea946d05 --- /dev/null +++ b/drivers/gpu/nova-core/irq/hal/tu102.rs @@ -0,0 +1,43 @@ +// SPDX-License-Identifier: GPL-2.0 +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIA= TES. All rights reserved. + +use kernel::io::Io; + +use crate::{ + driver::Bar0, + irq::regs::NV_XVE_CYA_2, // +}; + +use super::{ + cycle_top_enables, + CpuInterruptHal, + LeafCount, + MsiType, + Subtree, + SubtreeSet, // +}; + +/// The CPU interrupt tree properties of Turing, Ampere, and Ada. +struct Tu102; + +impl CpuInterruptHal for Tu102 { + fn leaf_count(&self) -> LeafCount { + LeafCount::Eight + } + + fn rearm_pci_irq( + &self, + bar: Bar0<'_>, + msi_type: MsiType, + _serviced: SubtreeSet, + subtree: Subtree, + ) { + match msi_type { + MsiType::Msi =3D> bar.write(NV_XVE_CYA_2, 0u32.into()), + MsiType::MsiX =3D> cycle_top_enables(bar, subtree.into()), + } + } +} + +const TU102: Tu102 =3D Tu102; +pub(super) const TU102_HAL: &dyn CpuInterruptHal =3D &TU102; --=20 2.55.0 From nobody Wed Sep 30 15:28:46 2026 Received: from BN8PR05CU002.outbound.protection.outlook.com (mail-eastus2azon11011063.outbound.protection.outlook.com [52.101.57.63]) (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 27C4D374A1D for ; Wed, 30 Sep 2026 03:43:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.57.63 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790739796; cv=fail; b=RJ2F2VoYTe98NoO5yNOWEozevcvAJliQFYKGh35zUZf2bb1Qtkftx9baU+ZHpQRtyuu3SIQO6ZvUsBboKzjMAx3RAQkAFzbP5Zyu1cl6bjPkCS2iPLT9/XKPrF24/D4wQDZDPNnONjsTN+qEmjb4oBSas0o97i8VvhrpPT+d8aE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790739796; c=relaxed/simple; bh=KAxodlPE6bqpiwWCLbHY2NCa8InFSWHimOzTF5xdFIw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=eFiPECL5BGbYzwB3DcPyiIrVPmgsCh3LQNKXEuU/CUsRCh1zB4U2cf7smYxAn5gGc3K/3AMeBlldhODugzwwICtMAM0L573xY+OP03CNuqEocSQ7zehGOO1kJn+HOqr8c8LKljBIgMPtJ4rTGG3NTkMfNeoLQDW41DLVTElqYzs= 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=Vesd2+vR; arc=fail smtp.client-ip=52.101.57.63 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="Vesd2+vR" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=l2DkchECkMUxoRiBeVkPSa1gkjHPOdauuyLrrcAzUGgeawXlL6UJXSg6/YWkt/MrsdA3yQompCv1v+Pqyn/8EETjefdE7jXSUvXBlucp9idXTH+ijjQFbdABslyvadew7JNzbFs0zTCDQY0OD6hjOWbUHGU4YINqqSNoDzs9ejywzJa1zUq9u/MRO7oWz0lAhiIDc1BxzqJKI8nSJDXc9ElXlY13iA0A+hXQIoGKa7Dr/PTL/GF30/t/t5RzhOvEwyeZMRqEwBI/h+ATQzx5E9OjsIJC4+ux3TMgZsqeJj0raqKGCNRTwyuC5FIGlE47MAHE1bPJkf0W5RKhUN2cNQ== 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=fWKWRGTDc0vU9OB4itx4XwF+GsrQ54NBXSsi75MelWY=; b=iXFopP5SXZKdcGiK9it+KEwRyppVr6A5WTFyqCrbVTTeW+neDKtLv1mCZiQcRl0WTlMaRJzXAdXJtvV8/ke3Bw9ErI4hqEjSr3P18YcoVWhMG+Uf56VuyC8Y+ND+K9m8/FWF+d3QLlTjA/NVjugYK6zw0+FkNsibqbxdOUkaVjepb/JZiBnlJEhU9kfdcGZJMLSTCjPPJ+ByeSzZrTka1Gzc2yV0jN3REySP+1B/6OKMSs4zNQw8tvklvREHvrw+voY20/1/g6vmeGrAKuXwlhY+rEjEwF8AWtoVM8y42gTrhzX5jkNPIcjuqMot3umOJbOP0uXRbCDRRnWHHt5v7w== 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=fWKWRGTDc0vU9OB4itx4XwF+GsrQ54NBXSsi75MelWY=; b=Vesd2+vR46ULfwNjDRSyQV0M9PHzlWNQHcg3qyxPYXBUPC1f51oow3turoK9aTWx1fNxvRy4xrkGeZUcVFx/BUvHZBg8pC+716pQtISTXWIUNQCgquEfHWP0GDkpDvDBqpkH6B67xHF4J+RJbKuCmM5l1JLIHcLpYjWBI1EQrs8Y6IrK5THA2kY9OqC3GO2GC25X5wHxeHJAnSiEWjgfxEzdzuPZktEFXg3UDMGsclpJnpkDqz/KbR4BgQAXDDcTic0u6WiEf/r6eVaa9WNTR20q1WlCgg/wUjOK5kz6ysA1ij9JCv/KajdIV7Ooo3tWZN8oX/dRXXWPxC71ZuO3gQ== Authentication-Results: mx.microsoft.com 1; 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 MN0PR12MB6248.namprd12.prod.outlook.com (2603:10b6:208:3c0::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.451.26; Wed, 30 Sep 2026 03:42:16 +0000 Received: from DM3PR12MB9416.namprd12.prod.outlook.com ([fe80::8cdd:504c:7d2a:59c8]) by DM3PR12MB9416.namprd12.prod.outlook.com ([fe80::8cdd:504c:7d2a:59c8%4]) with mapi id 15.21.0451.024; Wed, 30 Sep 2026 03:42:16 +0000 From: John Hubbard To: Danilo Krummrich , Alexandre Courbot Cc: Timur Tabi , Alistair Popple , Eliot Courtney , 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 , nova-gpu@lists.linux.dev, LKML , Joel Fernandes , John Hubbard , Will Pierce Subject: [PATCH v5 06/15] gpu: nova-core: add the GIN interrupt tree and allocate its vectors Date: Tue, 29 Sep 2026 20:41:39 -0700 Message-ID: <20260930034148.590687-7-jhubbard@nvidia.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260930034148.590687-1-jhubbard@nvidia.com> References: <20260930034148.590687-1-jhubbard@nvidia.com> X-NVConfidentiality: public Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: PH0PR07CA0055.namprd07.prod.outlook.com (2603:10b6:510:e::30) To DM3PR12MB9416.namprd12.prod.outlook.com (2603:10b6:0:4b::8) 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: DM3PR12MB9416:EE_|MN0PR12MB6248:EE_ X-MS-Office365-Filtering-Correlation-Id: db0395cd-b79b-4e9d-c7ad-08df1ea4d259 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|23010399003|366016|7416014|376014|10067099003|56012099006|11063799006|6133799003|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: HPtNqJbDodoKGkn9/2NqFEAgdbMdYGPpoQvAnEW081UVoeichLXZWaAqWezw7/4S6t6wgzBeJmB4uUoTYQJj5ubDirT8RZwLsiVFOBBrFkeWa2KAUncvX7Y85+Q3SGhkjCCiVYQ0vB3d2/r1tEXJ1Sy2E+ENdGgcwAA/LnZ5msJki1rISQsFEl7ebCpWjxfc1DKMzsM9bQD88xg55qxy9cEXi+Add5c7SLx4486jzvYMbq/18QrXeklEZNvK+IURva6l9/4/0LtCKN+wtfV/YcX0R9qZH8Arc39FruHExH/JHc+2D5EG8/LhMoMiGmAImltl26QWYowb5rGafqwnSZGy3a4pAnSwsgtaXHg6XRgwpxX8YEshe7ToDCipC9+AkODsT8ISUSzRNxehJPm5d9KFXVZu77PaBMxgpllJFKmdXYcBaPoyAMYdZXMa1qY6gPgdUap0lFd3in7qyaLtyK78VI1InY497uXFTJeYX+2HSeSuDeLP6naT/MeAJ7Z47IB0mxAmquYEC2jz2HL9zRxab0DPSdcye5dSpe2PvRIAvqLVGpJqL71IGu/3rmCCaaqmjVtU8P7mW92x+ALZPC3etM+hy5q9fYs6GMiboBBsq9ig2gXj+fLb20JiDXNb0Jw9t9dlzLCEH4RQXO1z5wHZEtSP1vjucgs8Tv2M2gc= 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)(1800799024)(23010399003)(366016)(7416014)(376014)(10067099003)(56012099006)(11063799006)(6133799003)(18002099003)(22082099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?m9nZgJvCDmGVcQY6UzsdbAh2g41crkyDCzQem9fwVb5piNGgIidvC5X47XQq?= =?us-ascii?Q?UqYiQvXPmSdU6cmAaAfr737vwvYcVhNdqBKqt6hb87UPxwXvOmvm40NVnORy?= =?us-ascii?Q?JzA0X0iHNov2cYTD6yeMYooelM99GbseCxniACwhGVHe8nzld+afYDO8YebF?= =?us-ascii?Q?Zw1nfSTmJY8XwmbQXRnmdJVTeeIktmyjZD65LK8Bl5N3mKmRlh02dl+I1/JE?= =?us-ascii?Q?3NyW1U2xn+Jtj4imw2XGGD0hzno95RIe0E0wWK4Hh5IDYRvfYHwS5HGtH+pi?= =?us-ascii?Q?jzDFZTw1G8AOcPr4Y0hwHt2nWn3FTQzqVD1RZ2ObGBeVo23mOMqcyAn0tdRM?= =?us-ascii?Q?e0Bft4yPOkJ1o5YgGX3FzNHlBdBP6P38FJoBo8FBx4mAGGL319REuTpy1a/J?= =?us-ascii?Q?xSncPJGamRUVvsyW69BKqNuXGt+n1e8sooGLfrzC3o0YXdrBlB3nSGwnvNO6?= =?us-ascii?Q?exzGWcu3LpcE+3yqKuc0ByorlrVEZt3PGy8DAk/c/0aWqaTb1zx+TWYIDPSG?= =?us-ascii?Q?4A0NNDkedbSgWJ/nhZa9ZtV0oYyfR8Lc3sZzhxmNo4+EhhzukxekvNfcEjCb?= =?us-ascii?Q?3TRfzqZsJ230j0LWTn/vSYmXw1K3tlEZjucKaIrVlyXs6ke/NZPyD+5r/zfb?= =?us-ascii?Q?AiqYTaJ5wqO4v1pfHm1CrsRXUEVuR+h4h0Js/NMcQ5nfBIS9SbJ+grDBg0tj?= =?us-ascii?Q?7Irkn1z6dPGUiuhTAsg9+Oec/9oGaWxJYeDi+/i9huZQyObDESIprKbqZeKl?= =?us-ascii?Q?ghHyT0Wcoq9YU3eyTEZWzefEgZnd8Pgi2uSsxA67o+qLxporPIIVbe0SQoYo?= =?us-ascii?Q?F1JOlGLiGG049XnvFEU9+CJpH7N7U2nHgAp8BSzvnQ8x8JqGqaYvs7gzm/Nb?= =?us-ascii?Q?I862nbnvqH6FWH8r4VfhA+IZLydWyHJ+tYJALyiAtQoA8mTnon3hwtSCcpTO?= =?us-ascii?Q?wbqRUMvt9PG0k32dmRIlR2ZYtDMM48Q41+fmwMdrNxQNfhBTPMQ08ohb+q4Z?= =?us-ascii?Q?vAVw4ag5QVP1zCq2hST95qzc8f1nrCSfwx2/vkBTjTd0lGHN5pBCpZagTucE?= =?us-ascii?Q?TMR1XUc4l8do837fUUtx7QVGaPw0DGQM98FHD55uvMRzsowUgORMpSwWZ2LX?= =?us-ascii?Q?OSfYbPaf0T+ekQUepkZwhePpWql91v6dvTtO5fdEHNcs4vS9DVv/tKigM6Cq?= =?us-ascii?Q?zmuYxtVNjYx9pUOxGZ8M/wVKgyWW2jvTmUUKXXppPySzAvmedLFCnwbVZZFM?= =?us-ascii?Q?kFBQZOoPBG2MqfGQ+W6/W37UY2loVqrCyQE3a+CZkGhDI4uSGWJFzPm9BCeS?= =?us-ascii?Q?aTCVWclXPl4hf6DrcMKQmU+bmoV/1jyblUXjadgbpT2D/s59zlb/exg5CqOn?= =?us-ascii?Q?x09SxQCYCZ+UCPHtmlpBuoy1F71h6bfNVdEa6caowURWMBbqTSdexIh1ooSb?= =?us-ascii?Q?DgxuKeK+cfZscDRrfh6QWLRIT7kRb73L+iEY4Kz0YmcGbayW8TctCB6LA22b?= =?us-ascii?Q?UHRRo1VpFrkFF0Y74oEN5LPyStxpV1cr8S8WUSqd+jRlm9kGS4CMD74LavPN?= =?us-ascii?Q?m6tBHHsdjq1FCWesmch8vuR3x5CZnbZe2UYoMVx4Oxuv59aK7e83quh3vrPA?= =?us-ascii?Q?XiqSO5YcaDHToCKWX3jtJ0VG56a92eVmb2vCUorIPS+wEETSf2tM7GIKowFZ?= =?us-ascii?Q?znUVnBg+0+l34qOGrj9dB3D+SHCawtdZwptLbd2/UvwT2khiuoRpkEyfNNom?= =?us-ascii?Q?khP8WNdjoQ=3D=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: db0395cd-b79b-4e9d-c7ad-08df1ea4d259 X-MS-Exchange-CrossTenant-AuthSource: DM3PR12MB9416.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2026 03:42:16.3736 (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: 6H7Y9UMFf0Ln9wrPjxeknUrIULedpXl9ZdfNDh54/TFeIRrqd8/quHJALn4eTF1lHYSNtbBGQTGCP5gtTnadxA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6248 Content-Type: text/plain; charset="utf-8" From: Joel Fernandes Servicing a GIN leaf has a required order: read its pending bits, then clear them. Clearing a leaf first discards every vector latched in it, and the hardware keeps no record of what was discarded. The interrupt never arrives, and no register shows that it was ever pending. Every subtree enabled at TOP also needs an allocated PCI vector with a handler registered on it. Under MSI-X each subtree has its own table entry. Linux masks every entry until a driver requests its IRQ, and a masked entry sends no message. An enabled subtree whose entry was never requested raises interrupts that never reach a handler, while the leaf and TOP registers show them pending and enabled. Under MSI the whole tree raises a single message, so one entry serves every subtree. Add the CPU interrupt tree of one PCIe function. The tree allocates the PCI vectors for the subtrees that it services and hands out the request for each, so that the chipset is given once and the vectors live as long as the tree. Reading a leaf yields the handle that clears it, so that the wrong order does not compile. Building a tree fails if it names a subtree that the GPU does not implement. A reset disables every vector, clears every pending bit, rearms delivery, and leaves the serviced subtrees disabled at TOP, so that a handler registered afterwards receives no interrupt left over from boot. Request MSI-X entries 0 through the highest serviced subtree, since an MSI-X allocation cannot be sparse, and fall back to a single MSI message, never to INTx. Reviewed-by: Will Pierce Signed-off-by: Joel Fernandes [jhubbard: reworked on top of the GIN vector types: a leaf read yields the handle that clears it, enables are guarded, the leaf count and the rearm come from the interrupt HAL, the drain reads every implemented leaf rather than descending from TOP, the tree owns its PCI vectors, and a reset returns the tree to a known state before a handler is registered] Signed-off-by: John Hubbard --- drivers/gpu/nova-core/irq.rs | 2 +- drivers/gpu/nova-core/irq/interrupt_tree.rs | 298 +++++++++++++++++++- 2 files changed, 293 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/nova-core/irq.rs b/drivers/gpu/nova-core/irq.rs index 62c242b71dc8..b2cfe73af114 100644 --- a/drivers/gpu/nova-core/irq.rs +++ b/drivers/gpu/nova-core/irq.rs @@ -10,7 +10,7 @@ //! See `Documentation/gpu/nova/core/interrupts.rst`. =20 mod hal; -mod interrupt_tree; +pub(crate) mod interrupt_tree; mod regs; =20 /// The message-signaled interrupt type that Linux granted. diff --git a/drivers/gpu/nova-core/irq/interrupt_tree.rs b/drivers/gpu/nova= -core/irq/interrupt_tree.rs index 279a43514b1f..6e97828bbd42 100644 --- a/drivers/gpu/nova-core/irq/interrupt_tree.rs +++ b/drivers/gpu/nova-core/irq/interrupt_tree.rs @@ -1,22 +1,47 @@ // SPDX-License-Identifier: GPL-2.0 // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIA= TES. All rights reserved. =20 -//! Vector addressing in the GIN CPU interrupt tree. +//! The GIN CPU interrupt tree for one PCIe function. //! //! A [`GinVector`] names an interrupt source, a [`LeafIndex`] the leaf re= gister that latches it, //! a [`LeafMask`] a set of vectors within one leaf, and a [`Subtree`] one= `TOP` bit. The types //! keep the four from being confused with one another. //! +//! Servicing a leaf requires reading its pending bits before clearing the= m. Only +//! [`Tree::read_pending`] produces a [`LeafPending`], and only a [`LeafPe= nding`] clears a leaf, +//! so that the wrong order does not compile. This module does not seriali= ze access to the tree. +//! //! See `Documentation/gpu/nova/core/interrupts.rst`. =20 use kernel::{ + device::Bound, + io::{ + register::Array, + Io, // + }, + irq, num::Bounded, + pci::{ + self, + IrqType, // + }, prelude::*, // }; =20 -use crate::num; +use crate::{ + driver::Bar0, + gpu::Chipset, + num, // +}; =20 -use super::regs::*; +use super::{ + hal::{ + cpu_interrupt_hal, + CpuInterruptHal, // + }, + regs::*, + MsiType, // +}; =20 /// Number of vectors one leaf register carries, one per bit. const VECTORS_PER_LEAF: u32 =3D u32::BITS; @@ -78,6 +103,11 @@ pub(super) const fn subtree_set(self) -> SubtreeSet { pub(super) const fn vector_count(self) -> u32 { self.into_u32() * VECTORS_PER_LEAF } + + /// Returns every leaf a tree of this size implements. + pub(super) fn iter(self) -> impl Iterator { + (0..self.into_raw()).filter_map(LeafIndex::try_new) + } } =20 // `VECTOR_BITS` and `LeafCount::Sixteen` are written separately. This ass= ert keeps them in @@ -130,7 +160,7 @@ fn from(vectors: LeafMask) -> Self { /// /// Exactly one bit is set. #[derive(Clone, Copy, Debug, Eq, PartialEq)] -pub(super) struct Subtree(u32); +pub(crate) struct Subtree(u32); =20 impl Subtree { /// Returns the subtree at index `idx`. @@ -151,7 +181,7 @@ pub(super) const fn into_raw(self) -> u32 { =20 /// Set of subtrees, one bit per subtree, in the layout of the `TOP` regis= ters. #[derive(Clone, Copy, Debug, Eq, PartialEq)] -pub(super) struct SubtreeSet(u32); +pub(crate) struct SubtreeSet(u32); =20 impl SubtreeSet { pub(super) const fn contains(self, subtree: Subtree) -> bool { @@ -173,7 +203,6 @@ pub(super) const fn span(self) -> u32 { } =20 /// Returns the subtrees of this set, lowest index first. - #[expect(dead_code)] pub(super) fn iter(self) -> impl Iterator { (0..u32::BITS) .map(Subtree::new) @@ -250,3 +279,260 @@ fn from(vector: GinVector) -> Self { vector.0.extend() } } + +/// Disables `vectors` in `leaf`. +fn clear_leaf_enables(bar: Bar0<'_>, leaf: LeafIndex, vectors: LeafMask) { + bar.write( + Array::at(*leaf), + NV_VIRTUAL_FUNCTION_PRIV_CPU_INTR_LEAF_EN_CLEAR::zeroed().with_vec= tors(vectors), + ); +} + +/// Disables the subtrees in `serviced` at `TOP`. +fn clear_top_enables(bar: Bar0<'_>, serviced: SubtreeSet) { + bar.write_reg(NV_VIRTUAL_FUNCTION_PRIV_CPU_INTR_TOP_EN_CLEAR::zeroed()= .with_subtrees(serviced)); +} + +/// The CPU tree of one PCIe function, the subtrees that nova-core service= s, and the PCI vectors +/// that deliver them. +/// +/// A subtree may be enabled at `TOP` only once a handler is registered on= the PCI vector that +/// delivers it. See "The serviced-subtree invariant" in +/// `Documentation/gpu/nova/core/interrupts.rst`. +pub(crate) struct Tree<'a> { + bar: Bar0<'a>, + hal: &'static dyn CpuInterruptHal, + serviced: SubtreeSet, + /// The interrupt type that Linux granted for `vectors`. + pub(super) msi_type: MsiType, + vectors: pci::IrqVectorRegistration<'a>, +} + +impl<'a> Tree<'a> { + /// Creates the tree of `chipset` and allocates the PCI vectors for th= e subtrees in `serviced`. + /// + /// Requests MSI-X entries `0` through the highest subtree in `service= d`, since an allocation + /// cannot be sparse, and falls back to a single MSI message for the w= hole tree. + /// + /// # Errors + /// + /// `EINVAL` if `serviced` is empty or names a subtree that `chipset` = does not implement. + /// Otherwise, when neither interrupt type could be allocated, the err= or from the MSI request. + pub(crate) fn new( + pdev: &'a pci::Device, + bar: Bar0<'a>, + chipset: Chipset, + serviced: SubtreeSet, + ) -> Result { + let hal =3D cpu_interrupt_hal(chipset); + let num_leaves =3D hal.leaf_count(); + + if serviced.is_empty() || serviced.intersection(num_leaves.subtree= _set()) !=3D serviced { + return Err(EINVAL); + } + + let entries =3D serviced.span(); + let (vectors, msi_type) =3D pdev + .alloc_irq_vectors(entries, entries, IrqType::MsiX.into()) + .map(|vectors| (vectors, MsiType::MsiX)) + // Every subtree raises the one MSI message, so one MSI vector= serves the whole tree. + // See "Delivery over PCI" in `Documentation/gpu/nova/core/int= errupts.rst`. + .or_else(|_| { + pdev.alloc_irq_vectors(1, 1, IrqType::Msi.into()) + .map(|vectors| (vectors, MsiType::Msi)) + })?; + + Ok(Self { + bar, + hal, + serviced, + msi_type, + vectors, + }) + } + + /// Returns the [`irq::IrqRequest`] for the PCI vector that delivers `= subtree`. + /// + /// # Errors + /// + /// `EINVAL` if `subtree` is not one of the serviced subtrees. + pub(super) fn request_for(&self, subtree: Subtree) -> Result> { + if !self.serviced.contains(subtree) { + return Err(EINVAL); + } + + let entry =3D match self.msi_type { + MsiType::MsiX =3D> num::u32_as_usize(subtree.index()), + MsiType::Msi =3D> 0, + }; + + self.vectors.index(entry).map(Into::into) + } + + /// Rearms PCI interrupt delivery to the CPU after servicing `subtree`= , the one subtree that + /// the calling handler serves. + /// + /// A handler must call this before returning, or it receives no furth= er interrupts. + pub(super) fn rearm_pci_irq(&self, subtree: Subtree) { + self.hal + .rearm_pci_irq(self.bar, self.msi_type, self.serviced, subtree= ); + } + + /// Enables the serviced subtrees at `TOP`. + /// + /// Each of them must have a handler registered on its PCI vector. + pub(super) fn enable_top(&self) { + self.bar.write_reg( + NV_VIRTUAL_FUNCTION_PRIV_CPU_INTR_TOP_EN_SET::zeroed().with_su= btrees(self.serviced), + ); + } + + /// Disables the serviced subtrees at `TOP`. + pub(super) fn disable_top(&self) { + clear_top_enables(self.bar, self.serviced); + } + + /// Enables the serviced subtrees at `TOP` until the returned guard dr= ops. + pub(crate) fn enable_top_guarded(&self) -> TopEnableGuard<'a> { + self.enable_top(); + + TopEnableGuard { + bar: self.bar, + serviced: self.serviced, + } + } + + /// Enables `vectors` in `leaf`. + pub(super) fn enable_leaf(&self, leaf: LeafIndex, vectors: LeafMask) { + self.bar.write( + Array::at(*leaf), + NV_VIRTUAL_FUNCTION_PRIV_CPU_INTR_LEAF_EN_SET::zeroed().with_v= ectors(vectors), + ); + } + + /// Disables `vectors` in `leaf`. + pub(super) fn disable_leaf(&self, leaf: LeafIndex, vectors: LeafMask) { + clear_leaf_enables(self.bar, leaf, vectors); + } + + /// Enables `vectors` in `leaf` until the returned guard drops. + pub(super) fn enable_leaf_guarded( + &self, + leaf: LeafIndex, + vectors: LeafMask, + ) -> LeafEnableGuard<'a> { + self.enable_leaf(leaf, vectors); + + LeafEnableGuard { + bar: self.bar, + leaf, + vectors, + } + } + + /// Reads the pending bits of `leaf`, and returns the handle that clea= rs them. + pub(super) fn read_pending(&self, leaf: LeafIndex) -> LeafPending<'a> { + let pending =3D self + .bar + .read(NV_VIRTUAL_FUNCTION_PRIV_CPU_INTR_LEAF::at(*leaf)) + .vectors(); + + LeafPending { + bar: self.bar, + leaf, + pending, + } + } + + /// Disables every vector in every implemented leaf, including the sub= trees that nova-core does + /// not service. Call this only during probe. + pub(super) fn disable_all_leaves(&self) { + for leaf in self.hal.leaf_count().iter() { + self.disable_leaf(leaf, LeafMask::all()); + } + } + + /// Clears every pending bit in every implemented leaf, including the = subtrees that nova-core + /// does not service. + /// + /// The serviced subtrees are disabled at `TOP` on return. Call this o= nly during probe, with no + /// interrupt handler registered. + pub(super) fn drain(&self) { + self.disable_top(); + + // A vector that latched while disabled does not show in `TOP`, so= read every leaf rather + // than descending from it. + for leaf in self.hal.leaf_count().iter() { + self.read_pending(leaf).clear(); + } + } + + /// Disables every vector, clears every pending bit, and rearms PCI in= terrupt delivery. + /// + /// The serviced subtrees are disabled at `TOP` on return. Call this o= nly during probe, with + /// no interrupt handler registered. + pub(super) fn reset(&self) { + self.disable_all_leaves(); + self.drain(); + for subtree in self.serviced.iter() { + self.rearm_pci_irq(subtree); + } + + // A `TOP`-enable rearm leaves the subtrees that it cycles enabled= , and a subtree may be + // enabled only once a handler is registered on its vector. + self.disable_top(); + } +} + +/// The pending bits of one leaf as they were read, and the handle that cl= ears them. +pub(super) struct LeafPending<'a> { + bar: Bar0<'a>, + leaf: LeafIndex, + pending: LeafMask, +} + +impl LeafPending<'_> { + pub(super) fn vectors(&self) -> LeafMask { + self.pending + } + + /// Clears the vectors that were pending at the read. A vector that la= tched since stays pending. + pub(super) fn clear(&self) { + self.clear_vectors(self.pending); + } + + /// Clears `vectors` and no other bit. + pub(super) fn clear_vectors(&self, vectors: LeafMask) { + if !vectors.is_empty() { + self.bar.write( + Array::at(*self.leaf), + NV_VIRTUAL_FUNCTION_PRIV_CPU_INTR_LEAF::zeroed().with_vect= ors(vectors), + ); + } + } +} + +/// Disables a set of vectors in one leaf when dropped. +pub(super) struct LeafEnableGuard<'a> { + bar: Bar0<'a>, + leaf: LeafIndex, + vectors: LeafMask, +} + +impl Drop for LeafEnableGuard<'_> { + fn drop(&mut self) { + clear_leaf_enables(self.bar, self.leaf, self.vectors); + } +} + +/// Disables the serviced subtrees at `TOP` when dropped. +pub(crate) struct TopEnableGuard<'a> { + bar: Bar0<'a>, + serviced: SubtreeSet, +} + +impl Drop for TopEnableGuard<'_> { + fn drop(&mut self) { + clear_top_enables(self.bar, self.serviced); + } +} --=20 2.55.0 From nobody Wed Sep 30 15:28:46 2026 Received: from CH1PR05CU001.outbound.protection.outlook.com (mail-northcentralusazon11010011.outbound.protection.outlook.com [52.101.193.11]) (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 4FAC131ED83 for ; Wed, 30 Sep 2026 03:43:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.193.11 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790739787; cv=fail; b=EPP2KMMBg1t5TpfCACsRP7uyLahk1KsVkNyF9C2FJY6b7Hcad3GExK4D2LCUeaer3q0JVw32vicj+X44GKvHIiA2b6PyHivo2Ic3uMoxpnOwVqYab5LPR1+YGH7C4nG2fEnLmnKjhYSC88E5EIsyUYISrrhoykmpvGGlhXZvKjY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790739787; c=relaxed/simple; bh=U1H1eXBO2fPqW3l4S8DTyPmoxfGXqzEBv9PfLdbHbSU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=CGMAO9L8jVNRDBvROHh6x0jeHP7ftKHAEcxvD3gbGL90YxUXCEL+JtHSCV5BGEbg2SwDqtX1i+ZGRu9dpp5cMaDRfYHO7N5fGfbT/gNZOpPbCP1w2fCY9ZPMgDio6WCfqNYO2c5drgkFWibDW73TfrIhI3A0waOHIMvBHqzDP0I= 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=LJ2GbZrz; arc=fail smtp.client-ip=52.101.193.11 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="LJ2GbZrz" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=tfbYGQtGVvOqkSedCGK7FKF4LvCLl+AOnOZrucLIXWngzqb0BPhm/op7X1kDXmWq+UjUbASYhXdNLKchmTmFc5RDVu6ZOXS9qTFeMEQDRJVARLWKa3vcwzNn+5F2jsR2SpK5Xeioqc0f43nJ9J+h1d0ioZgtjx3si0NMz4JlWE9yy8cUymNygo9qdwNVg4/P+1y8PDh47daoCH1RtpEXZNJz2T3jE+ohfxZxBuxhnMJ4cEb/g0dHTn5nMcJUAm0lMcI3FS0SbzrrO435fZ0ady7PMqC+xH13ntr9lBnHM7UZ6i2ur+nRCXkmRH2/z/WpPBtzqySJL/kdLKx+cViIng== 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=RVGHRP6wSp407Ez7F7kaF2WIcP7joVnbci5HQFdYS3k=; b=fpWXqzxCPnQZUcgB61VZdsGnvoNgwfaE6Hxjuof9f6Tw+PsbpvUkIWCmxathivzgKS6B9VAOkxkzk7GEp+yqJyPIg9npJ40evMcsDF2bjCDxipQaAFWRMHHJos5bpDVA/DnU/FYfFPSlpWIPkoo3i4KwVJx9u7VM2RcCsjhcAEnnfJkuXlT0e13Rgc42JSkyICIfCa0aLCj/6jozqINTANkoSm4fpcbtKTDX23cIkca5EbRs+c663Xf/F3GpBIb6q4/GozPG1mf7yZQ0F8wO4DE+5cZwDVWE9bFevZp5T8mDmH8b+cUXY8i7mn8FJksg7EgZWEaUMXjg5louC3xP9Q== 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=RVGHRP6wSp407Ez7F7kaF2WIcP7joVnbci5HQFdYS3k=; b=LJ2GbZrzXATk2HamdZ3yNUP8F8/jusL4XRRDILsgqd4qvD1tjouNJUSa5638QJ1FRO9oF2mQLLbbkG8J7cSWOjo5v89W3pwEb+rLiZi2ePxrYaL1D4jmh0+3lhV0BNB/yoOpFIWGRemt/a1u+/+6xGMI91jzMAmGwMekoZxVCJ9f5wb/ktAw8Ge4n+q0pyxR9E4Una5QNvabiP7YILXvDDb3uPOdPfJJTm0af54kOQ+i4qhFae4Qh2bQTJ//pQfEcA3W2nMjwryKNxxhriT/hMwLbHs9Y4c2IWe2uswtN5JiyQbQ3vZf+bSX9L1OUKP8gNcaDvnU/TnmRUBaOU38OA== Authentication-Results: mx.microsoft.com 1; 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 MN0PR12MB6248.namprd12.prod.outlook.com (2603:10b6:208:3c0::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.451.26; Wed, 30 Sep 2026 03:42:17 +0000 Received: from DM3PR12MB9416.namprd12.prod.outlook.com ([fe80::8cdd:504c:7d2a:59c8]) by DM3PR12MB9416.namprd12.prod.outlook.com ([fe80::8cdd:504c:7d2a:59c8%4]) with mapi id 15.21.0451.024; Wed, 30 Sep 2026 03:42:17 +0000 From: John Hubbard To: Danilo Krummrich , Alexandre Courbot Cc: Timur Tabi , Alistair Popple , Eliot Courtney , 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 , nova-gpu@lists.linux.dev, LKML , John Hubbard Subject: [PATCH v5 07/15] gpu: nova-core: wait for GFW boot in probe, not in the Gpu constructor Date: Tue, 29 Sep 2026 20:41:40 -0700 Message-ID: <20260930034148.590687-8-jhubbard@nvidia.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260930034148.590687-1-jhubbard@nvidia.com> References: <20260930034148.590687-1-jhubbard@nvidia.com> X-NVConfidentiality: public Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: PH8P221CA0055.NAMP221.PROD.OUTLOOK.COM (2603:10b6:510:349::8) To DM3PR12MB9416.namprd12.prod.outlook.com (2603:10b6:0:4b::8) 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: DM3PR12MB9416:EE_|MN0PR12MB6248:EE_ X-MS-Office365-Filtering-Correlation-Id: 86789135-a92a-4fbf-6720-08df1ea4d325 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|23010399003|366016|7416014|376014|10067099003|56012099006|11063799006|6133799003|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: 5t6aPe2grHGlt6VLZXXvOc1oJN9ndjxIfcu6veYue/ws5gOHlktQb7mCwctOvldl8yPKa/GQ9JOEryJJYXCovCO+1QpsWSX6GRWUnsgawy58gTbPgRGts8i+aOtb6UtkmAXWBAAqY0NVq/d3cyhmDw2mdBEKYcLsUfGefpUwP3/gahWx2OPPp3nOEXkM2vT0aZRZg5/Og8Pc6tWUsxYLZTzHYRHyDYgs18XLAn/RtDtgQ9HyV9sZmlGebuOu1oN4ZrYKMDjbm9Scjg8LKp31rF1s6H9qIjGUj79l1nrbsyX7cmnblp8UeC/62FR8DRdIpMLDU39RWG3CPWier3f+l8agWDzqsxPxc7i/RWIoSvMg+al5c7K2pWFfcNZc0A+yqxofrNJy0169J85qFp5LvBYd6wpJoKZBHhJzUvLeQzPVZb6yNg7cU9w6IoCn6TvueZm4C2fA3uve9H8/l73UEHdqP5RMvKBvEfT9YYqjfZ3TsjWl89KWMmjGnvx+JN0jEHJ076nTtr7SYzRKDsspo44H41x+hOYoRds7WXW0wGHvQmaNuFcHJTA6XfbFWsB55U9/yuTAKCOB77nxx5mpU2Db4sI9WFyM9Np7M+H1ZklapMT7JodoIrWRviRpcnPYbgJaWzlh6Idv8eNXKdgH98JKB8zERlZ8aS9Q8YeyAOU= 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)(1800799024)(23010399003)(366016)(7416014)(376014)(10067099003)(56012099006)(11063799006)(6133799003)(18002099003)(22082099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?J/9OEBxMdRezBptSYpKkVCUK38PQwS4RoKGc2hUlR6SJ6IGBdYm9HZK7k/9P?= =?us-ascii?Q?NfJykNt13AT70xN0rSqSWK/nOMZvFXQgxxCcYJRFdYRNgXB1kN8HvhDhW1Ab?= =?us-ascii?Q?VhuByOKc56BDCp06rVb00OX5TcEnQt2WlY6AQxFm5IXJ87XzkUSIWBOZ/1T6?= =?us-ascii?Q?cwR2epi5TPbEp7zCrJedYaN9oFAQ1wQxfTzx9I1TozklDU/XLNI/k/y0B159?= =?us-ascii?Q?ud5hjAtQBKe6goBE3eXANPHtyuXVDmqVTeBf4N/HfPgRfB3q31AzObVqYNt7?= =?us-ascii?Q?bsuBfD/360Swpvkxfl9tg5FI+Kx+uA44UhA/mX4QXwXpAPNt2z5+1GoFrpZg?= =?us-ascii?Q?AonlF54Hc4zDPBzaOxuyODOxNXR/SvwaCnZqCySn4zl8vWnw2jK/82iyToIG?= =?us-ascii?Q?lX7NylmNnXPzYiEXT1/OxyMQ9U6S99ESzosI6K6vml2Nl0P4gWvPOTRhLE2Q?= =?us-ascii?Q?3rdUq9WWWk5uoY6BndtxK601mJEeOYb9+Zh2Rk+xDCoRFZxxB14Kw0eHlXjF?= =?us-ascii?Q?YbkFnp+wJWFUsSAPfPZA1nv4ipWMz9+oPb0SRIt4hmvMyqBxh+r8Ug5V+Gzt?= =?us-ascii?Q?waPL6/YL6NgnqJrFx3F/c8yUZDVxaZdd5rjfRN+i7fDDXykmSXAnqPq2oNQR?= =?us-ascii?Q?dDRXHXb/8/hZ+MD7Gbsvvhj96F04IMlsafCzJBI3deP9AC4sOJiOqtQIWjRY?= =?us-ascii?Q?Ex9skx2lkSB2OdnzgGK77ePvvKw7RQ1tmNrRakH5cbZBQDit79PzTiRkuLwI?= =?us-ascii?Q?hzaRO7c9rrbbpQzfduC+PO8CA4xufSO5bedq9CctI/ptBZdujPaiZBEw9Dza?= =?us-ascii?Q?UHTSy3YAjELDiBkCxOL4q6FsTCRFc0RsnzZHO+mip3/i8YQ98FOrUZZf4pym?= =?us-ascii?Q?XL8PFMfwAWOWq5WIjoo3jUzRFs+6DYbhRzzwNTkbyyKLmxoi/MiHnbqbC8LX?= =?us-ascii?Q?m3Iz56aOxraXMh+O0GlF8wj4QXKg9aO9Sf3E5XFhDBhOP6QubgyOv8mP8Q7O?= =?us-ascii?Q?p4cO3+Dh6/p4VMmQJ4wQam/A6feXFkfj9ahTcKUDbGpkPRb3AHQ+WgYCef3E?= =?us-ascii?Q?QVmzkpuADX1fbTMUouoYEEAvzMlyHzpWZi6fpCrCEfsqk7buQxI4OGv+SOdx?= =?us-ascii?Q?q8uTjc5Lmtf+8nX8o3rDITJfbI60pUTBLfZ6fwnQpUrIMZVsQW603qrJ6pRL?= =?us-ascii?Q?Qb/kxfI5JNYlgCzGUcfCX25w8NIttfg8i1yDFyFnZWQR0PBtTTSM1yOTjVm7?= =?us-ascii?Q?6wyzhi9RIr2rmO464Nm+NWqqVlj8lvBauWxxOoHL5Is9GO+oxVy1eBXiXo3Q?= =?us-ascii?Q?e9w9j5sYIuqvMaBplo03PWK+ydF49km8goiXACiUHlziH030A7KrFKNL7lxP?= =?us-ascii?Q?0XJ6wHrGWhoQcxEX8NkAQCLbRTBMs1dRqKtFKlNWXNm5a0tOZv+/SheOXvqq?= =?us-ascii?Q?Pxprjcd5Anlutlb/WVOxqHllobA9DVOJOc66f5xFZwgcbtn4SlnmePybva4R?= =?us-ascii?Q?NfDW5YkrnGteDBmMYTUS4bZPW59PwKYp9hfEWFM8hslX876YD39QhhDsliFk?= =?us-ascii?Q?pf59ZKqr6JUZ4Pp1UP3zUSbwcQDvgMd7WpHg0JcbuPnKiGkWZ9iU6RuLr6IL?= =?us-ascii?Q?RQ/f743y19278sy64dVI56p60LpQRwfwQp7oBsA3TIhoIWU+WqVebkzjc5e9?= =?us-ascii?Q?Xycxgj2fuIqawZQHSPCU+7rt3wMulabN2u6mZjy+SVnyfQh0BtCIOQzdoNEF?= =?us-ascii?Q?M3TjnrkSIw=3D=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 86789135-a92a-4fbf-6720-08df1ea4d325 X-MS-Exchange-CrossTenant-AuthSource: DM3PR12MB9416.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2026 03:42:17.7147 (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: GYbhLKO6Ha/1GCb5bG4dPK7S0XlWmH2yBKftHU+UdjF7iDrvrwUBq/Ld7BbxeBOuI7drOx8IqqLWWHQn/Itv6w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6248 Content-Type: text/plain; charset="utf-8" The GPU boots its own firmware, GFW, out of reset, and the driver must not program the GPU until GFW reports completion. nova-core waited for GFW inside the Gpu constructor, which also boots the GSP. Code that has to run after GFW and before GSP boot, such as a probe-time hardware self-test, had nowhere to go. Move the wait into probe, ahead of the Gpu constructor, and read the chipset there from a Spec that probe builds itself. Leave the DMA mask in the constructor, since it programs the host rather than the GPU. Assisted-by: LLM Signed-off-by: John Hubbard --- drivers/gpu/nova-core/driver.rs | 14 +++++++++++++- drivers/gpu/nova-core/gpu.rs | 26 +++++++++++++++++++------- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/nova-core/driver.rs b/drivers/gpu/nova-core/driver= .rs index 291a047e4d86..fc321c6a10b0 100644 --- a/drivers/gpu/nova-core/driver.rs +++ b/drivers/gpu/nova-core/driver.rs @@ -24,7 +24,11 @@ =20 use crate::{ api::NovaCoreApi, - gpu::Gpu, // + gpu::{ + self, + Gpu, + Spec, // + }, // }; =20 /// Counter for generating unique auxiliary device IDs. @@ -113,6 +117,14 @@ fn probe<'bound>( pdev.iomap_region(bar1_idx, c"nova-core/bar1")? }, =20 + _: { + let spec =3D Spec::new(pdev.as_ref(), bar)?; + + // We must wait for GFW_BOOT completion before doing any s= ignificant setup on + // the GPU. + gpu::wait_gfw_boot_completion(pdev.as_ref(), bar, spec.chi= pset)?; + }, + // TODO: Use self-referential pin-init syntax once available. gpu <- Gpu::new( pdev, diff --git a/drivers/gpu/nova-core/gpu.rs b/drivers/gpu/nova-core/gpu.rs index fb6f8a86a503..65715f906030 100644 --- a/drivers/gpu/nova-core/gpu.rs +++ b/drivers/gpu/nova-core/gpu.rs @@ -251,7 +251,7 @@ pub struct Spec { } =20 impl Spec { - fn new(dev: &device::Device, bar: Bar0<'_>) -> Result { + pub(crate) fn new(dev: &device::Device, bar: Bar0<'_>) -> Result= { // Some brief notes about boot0 and boot42, in chronological order: // // NV04 through NV50: @@ -397,10 +397,8 @@ pub(crate) fn new<'a>( dev_info!(dev,"NVIDIA ({})\n", spec); })?, =20 - // We must wait for GFW_BOOT completion before doing any signi= ficant setup on the GPU. _: { - let hal =3D hal::gpu_hal(spec.chipset); - let dma_mask =3D hal.dma_mask(); + let dma_mask =3D hal::gpu_hal(spec.chipset).dma_mask(); =20 // SAFETY: `Gpu` owns all DMA allocations for this device,= and we are // still constructing it, so no concurrent DMA allocations= can exist. @@ -412,9 +410,6 @@ pub(crate) fn new<'a>( // SAFETY: `Gpu` owns all DMA allocations for this device,= and we are // still constructing it, so no concurrent DMA allocations= can exist. unsafe { pdev.dma_set_max_seg_size(u32::MAX) }; - - hal.wait_gfw_boot_completion(bar) - .inspect_err(|_| dev_err!(dev, "GFW boot did not compl= ete\n"))?; }, =20 // Initialize this early because `gsp_resources` depends on it. @@ -533,6 +528,23 @@ pub(crate) fn run_selftests(self: Pin<&mut Self>, pdev= : &pci::Device, + bar: Bar0<'_>, + chipset: Chipset, +) -> Result { + hal::gpu_hal(chipset) + .wait_gfw_boot_completion(bar) + .inspect_err(|_| dev_err!(dev, "GFW boot did not complete\n")) +} + /// Reads the boot0 register and returns its raw value. pub(crate) fn boot_0_raw(bar: Bar0<'_>) -> u32 { bar.read(regs::NV_PMC_BOOT_0).into_raw() --=20 2.55.0 From nobody Wed Sep 30 15:28:46 2026 Received: from PH7PR06CU001.outbound.protection.outlook.com (mail-westus3azon11010010.outbound.protection.outlook.com [52.101.201.10]) (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 134D538889B for ; Wed, 30 Sep 2026 03:43:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.201.10 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790739803; cv=fail; b=PC/u0I7M6OSZ0fwB5KXa7NcT3obRZHgOOjHhILi1PZ1Xr/UFC/ucfW9J/GWJYbYTbJlD6W/yx5blAJiK/LELYIyAy0trZFzwtfPy+iWhxh6elaROH2mn+sPEv2acB9sKTjtS4VrUKKIOj6IyLnEexNwJIjvl4TwguL+MfxaBBeQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790739803; c=relaxed/simple; bh=FVWhUmSd0SxEGUVx4tSVvwevpZ69i+ampnTCakXEGNs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=dmYkIT1xqypDp3f/ucb6RpvvMOVA2trVYjZ6IfsEB0RUd04zN5sbtOoM3yu++mJD+HT371uh4VqlVPlmCNelHJXqKVAMLdrFaYudtScGTAjMEPw0nuz+dpaTY6eYwlXY+yr8AitQMH0b50rlWkETOCNpGUmv8jaW6+TlyXw0odc= 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=DLMHrE3j; arc=fail smtp.client-ip=52.101.201.10 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="DLMHrE3j" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=GeWPpHCvv20mZwobLcJTxHj+NU1DPTie87A7/Facz1pNb9SD94+2kyUDEsASywDf2iz+RG4sJndG2t9Us8EXb/nRfmpW+qDtsFOjrs0r5YVamg96+uDgIBcv9e3XgVCyOMnQK0DHHN40Rn9S2U+Gugjsh/3ljebHoJD94rPn/wL/8dGyPAhcpevN6nskyrRb4MqJOuW5w/nGwjoMoZi467oIbWJMYlLo2vacyfDcWa9yZ+LWbVX3xHNf7L3u+5kuywFQ71KiGL6FRI6bmahWrcQ4xy3NOjUY5pzUMSTxC30V7D3N8F7V4fX8JRLhC6vpHdZgfEg1AxetACv81ROAOQ== 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=Ho6StAlcm1htBHWlGuDoifK9WXX1zoWgXskF1xQLE20=; b=eC+FT4y1iKxS17DfaLtbnE/r3Ugrk6I8BXuZ29e/fIcjXA/9l8zbpZ+nDya9zmPZ6HV0aQkRwtHk+Te+kecm1JABQC+l99OO98lx4gOt4RFk6g8NjtkZFnc6us4gCtU1sOscvYqlGn8mAIOEmun0DQpToH6UGq/5d7YOtYbrMQxKIsdlXiKGnC1H2GbPcJyamj1rBGIuS/g88UImqBd4ctmJfQTZL2lMvLv2Uq+l2SitOlAnirJmFQsDXwAOIEf1Gl2Kv4V1w6QwygDEFuPjjQQ3DvGeqjttUSnR9D6vQrSUJWfN2c+YVKrGkFc/xL8GafuB/HF/9oEPDZ/Qg4Lr3Q== 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=Ho6StAlcm1htBHWlGuDoifK9WXX1zoWgXskF1xQLE20=; b=DLMHrE3jMH+NYn+edyhoOFbc6jiRxxyb0M3cJBCiS3yfiKHZrxcAaXCBha0hrlqw1s1548y5him+0cNYFWf6XxKqcLIxg5GeRumR0lnpqz7B3nxMcteSNW3p6Hm3sbCG4ShgWoerIY5abjqAoeS2CbixIjBanglKEnIPfwhX+7jLCFXZJYmEkpfEfEJ1d+8PX45nDWVk3UzuUJFQeNNHpc89K9KJHQyqdu1BtT0/C2EcXfsSjWrnBb0sXRFvenS4zilP6MP9EBQXa0dTYKA3oBCyAIyUzZZmW1BNjmAenZ5to7PBjWzeEKPX5NJqvEyrtU8SIBZBvzrjxJkkWA+hiw== Authentication-Results: mx.microsoft.com 1; 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 MN0PR12MB6248.namprd12.prod.outlook.com (2603:10b6:208:3c0::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.451.26; Wed, 30 Sep 2026 03:42:19 +0000 Received: from DM3PR12MB9416.namprd12.prod.outlook.com ([fe80::8cdd:504c:7d2a:59c8]) by DM3PR12MB9416.namprd12.prod.outlook.com ([fe80::8cdd:504c:7d2a:59c8%4]) with mapi id 15.21.0451.024; Wed, 30 Sep 2026 03:42:19 +0000 From: John Hubbard To: Danilo Krummrich , Alexandre Courbot Cc: Timur Tabi , Alistair Popple , Eliot Courtney , 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 , nova-gpu@lists.linux.dev, LKML , John Hubbard , Joel Fernandes Subject: [PATCH v5 08/15] gpu: nova-core: add an interrupt delivery self-test Date: Tue, 29 Sep 2026 20:41:41 -0700 Message-ID: <20260930034148.590687-9-jhubbard@nvidia.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260930034148.590687-1-jhubbard@nvidia.com> References: <20260930034148.590687-1-jhubbard@nvidia.com> X-NVConfidentiality: public Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: PH8P221CA0057.NAMP221.PROD.OUTLOOK.COM (2603:10b6:510:349::12) To DM3PR12MB9416.namprd12.prod.outlook.com (2603:10b6:0:4b::8) 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: DM3PR12MB9416:EE_|MN0PR12MB6248:EE_ X-MS-Office365-Filtering-Correlation-Id: d080d597-fdcd-4413-00c6-08df1ea4d409 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|23010399003|366016|7416014|376014|10067099003|56012099006|5023799004|11063799006|6133799003|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: KJsCw6MOBrUkQAXj+CZ3X+ouRBpjSehI55f4IDnXzNs9RK4nCcaPCZIEnZL80Zp0ueSrHbW0/TyRIPXDBEcUyX4QZxYD4fW7+4tNqnw0oFojDMM5VDRvou9YAzDJ66kc0DARX6EGQh8vggbeZY8Nw0egw7Zjy8BVxNjY/Z5gcMSnPRXHPAfzeBsyeUCofZyXRlM8Hs8aMUVE8pj25L4Kht6/dgP0aTmeo3YSUewOl7hAFM+9/w+tLRb7vanZ02aawUMpkpm2hFLds/SyhayQt2z/xV9fr2yM7mtPsFxCbQBskHfjCYYws8kDejPMxq9q28n91FgjrJmcYk+YJnbxYgHiw5DcJq0XUg/+09DtKsoF67Dhr5wABoBYyIEdCIARyFZxclZd67s05UOm4BJLVFY+A9Q2A/kcf7oiI4fJ/819llIbfFHmxh+I1COfmpecuCRcl2z+mExfPNbJVWCsRzMwL8zwkAanKADau0/gU+lbjayi7sfM/2BxqVbywwCw3ESrryXPj36EzgIVpfKE4XJnu3MafkiSSRh68gNYBR+w7ZTVzy85iVq1+WZsrN40PhCMKj8kxQvI2BEbuEjHlhlmuZzXc6se3MeiYf4jGuVTIIaPbyhQIXrqW4aLTFcbj/3qE6uF0hcQSaw+L8GY1X8VTqWH1Ie1EQooqXVSeBQ= 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)(1800799024)(23010399003)(366016)(7416014)(376014)(10067099003)(56012099006)(5023799004)(11063799006)(6133799003)(18002099003)(22082099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?gKBE7nig8lzdmfRnsPy6Rr27UDXLODJbH+NIzW6qaU3mTx5Toftl0KYooE02?= =?us-ascii?Q?p94C/YgW5yc4Jx3Rzry74q4IA2p3ezZpTimgImeyxnKkwbbHIoxoEQlfCeOB?= =?us-ascii?Q?4o/6sKDmJ1HIAzZumM3HPMFoq5tnFHpxduNxJgs8PRiNfM6AOm4v5kA5qWKF?= =?us-ascii?Q?n7iToQpWgn/S8cYp7SEyFIZxjgPRX1KTAPVC212gE+JKmp+d5F0TkpnWNfLb?= =?us-ascii?Q?+W+MaA65Sq3/wCc84cqt7vTHTfXBSHZRUZ5DIVrLK0mfQR3S+D8X9CfeVh36?= =?us-ascii?Q?Sr+P9rRwMtZqLjt0lrpkBpjoGJpLZ94wnLWashCBO0ZgwGJiTYveHT3RqZrB?= =?us-ascii?Q?EzpQPc6ZVqa+CnKgOyXSHANDUBrbckIeDQm89FDi3w/bbL8O1iI4Ro9sTkHN?= =?us-ascii?Q?u8w0zJfw3Uc1deu1JZn/vGEksfozrm/C/dkpYya3r529HW+K4i+oX9+ywYwg?= =?us-ascii?Q?EAU8d+lX1jwc4On7JiC/R7ATRY+PCJ2IuwgRfspTkdEtM8ifbV+k+bn9UV9k?= =?us-ascii?Q?7DeL+mRWA7C/oexBzCp7HH2PeHct6xs8S3ZCfb+ZcgOOPRDm1aqd9BAQckJK?= =?us-ascii?Q?AnSyLZplXbTVXrkeXfYQdger1cn6UuZEFl4jKHkU7ez8ZQH/MZWUm7Jd5XhA?= =?us-ascii?Q?j7f47OireM4ZT5iNeQv1BIagqvKVGnyD+rT5jtILwn59d0E7yrhBTZM4mi6m?= =?us-ascii?Q?tYWwDC/SSKb+kxovv1A2NbXvMTIroxuZV4XWXXR92fRd6MeVBqmdti6a1ZBX?= =?us-ascii?Q?4Jhy9PPsrm8gU+DcjxtBvc0UikJ/t+TxU4/8jDlzb3+SEte9ECh4hpztrDBL?= =?us-ascii?Q?lNgaL6bVwwuqHb3cVw3gzE/hJlK7GZ+bYRhrbW4ELNzp09BcF4PlhR6xrne3?= =?us-ascii?Q?zl5/tXjwThLmgqAwfVg4NrYL7EIy4NayMRpllMVifpCqVBSspAKy14xZfc0H?= =?us-ascii?Q?G+kt6kYLkFRhe6eWveNaAGPvaSQrSbb++WJDypbeYGOmeqjnfP0O19dGsGAK?= =?us-ascii?Q?8/GQynrYEkCmtNTnziYXQIbL2KIsp/vFpm59Ka4E1cf+zKsizrkIjDQTIHbH?= =?us-ascii?Q?o4d35rg3tj5dtFDyiBb8Lpen/enSqhYpyrvcE8H4XrXBnoviNRXB0p5fwEXB?= =?us-ascii?Q?AzH/DwK5uf0nskz7DECPnuYseAexTeF2Z/sUybBKMxwg493xwqSVmqSJNiig?= =?us-ascii?Q?ESb8HcDj+niW0ZgIqKTWCFBRWV/JXedAxgPYuhx8mhrB8TJAkqHOhkSU3clt?= =?us-ascii?Q?UqbwvRNsB0VInikDR+XqjpiONSjkpoe05v1PPC9Y/0wdoGVs/l7wxObJrKY9?= =?us-ascii?Q?rL/IvldZi02J3HkpNZGs5sxSm5OyzNbl/Tp34spDLfadSPMFlIRvfdBWwNp4?= =?us-ascii?Q?d2zaJZMOPxxpzZ8TkpXaIEAMISP9G/dTISsjORaITcUXEkeemwCfUbQnK/D3?= =?us-ascii?Q?o77kS+e/WXPty12rzb3UNBvrTjqbyjt5KwQTax3l9AstkVPD6IGOcQ0fmi+K?= =?us-ascii?Q?puwSuWSpl14Knc4kUOnhTsNJc6GAH+tnNy76sQc8yjJ4CEVTNzOpH54OSu5u?= =?us-ascii?Q?rHgsgtio7uaR1knhNHbgXqlHobdWkh57py3q8ztwRQ016WCIuItCSUvRkO7C?= =?us-ascii?Q?ml1InP/mDeG7SeuLVdpfIjUfZV8rUeXAMeX5TMUj3nDoCZ/7c2b73YaCQDyV?= =?us-ascii?Q?/0GW8u0rfE7X7HlxocA5pqQprEP8LnwltEUXF+tEQ50sr3VGdVPPvUNhvrlF?= =?us-ascii?Q?V0UiASLPEA=3D=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: d080d597-fdcd-4413-00c6-08df1ea4d409 X-MS-Exchange-CrossTenant-AuthSource: DM3PR12MB9416.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2026 03:42:19.2229 (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: cEXATZb1CXmXKSjPqnSrVWn4mi/2DnAYriu2uoTTKojBNR+z826YkOBo3O8chmiK5cfFOCvlPrNFt7MYKxqqIw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6248 Content-Type: text/plain; charset="utf-8" A GPU interrupt can be lost in the MSI or MSI-X allocation, in the GIN tree's enables, or in the rearm, and every one of those failures looks the same: no interrupt arrives, and no register or log line says which one broke. Add a probe-time self-test, built under NOVA_CORE_SELFTESTS, that latches the CPU doorbell vector through the GIN software trigger and waits for a registered handler to service it. One delivery would pass with a broken rearm, because the first message-signaled interrupt arrives whether or not the driver rearms, so the test triggers twice and waits for the first handler to finish before the second trigger. It runs after GFW boot and before GSP boot, on a quiesced tree, and fails probe unless both deliveries arrive, each finds only the doorbell pending, and the leaf ends clear. The doorbell has the same vector on every supported GPU, so the test names it without asking GSP-RM. It allocates the PCI vectors for the doorbell's subtree and releases them before returning, so under MSI-X the delivery also exercises that subtree's table entry. Assisted-by: LLM Co-developed-by: Joel Fernandes Signed-off-by: Joel Fernandes Signed-off-by: John Hubbard --- drivers/gpu/nova-core/Kconfig | 5 + drivers/gpu/nova-core/driver.rs | 5 + drivers/gpu/nova-core/irq.rs | 2 + drivers/gpu/nova-core/irq/doorbell_test.rs | 257 ++++++++++++++++++++ drivers/gpu/nova-core/irq/interrupt_tree.rs | 15 ++ drivers/gpu/nova-core/nova_core.rs | 2 +- 6 files changed, 285 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/nova-core/irq/doorbell_test.rs diff --git a/drivers/gpu/nova-core/Kconfig b/drivers/gpu/nova-core/Kconfig index 1934f17baa8b..2e11e46c99c7 100644 --- a/drivers/gpu/nova-core/Kconfig +++ b/drivers/gpu/nova-core/Kconfig @@ -24,4 +24,9 @@ config NOVA_CORE_SELFTESTS help Build the driver self-tests and run them when the GPU is probed. =20 + If the interrupt delivery test fails, the probe fails and the driver + does not bind to the GPU. A broken interrupt path would otherwise + show up later as a hang, far from its cause. Every other self-test + logs its failure and lets the probe continue. + If unsure, say N. diff --git a/drivers/gpu/nova-core/driver.rs b/drivers/gpu/nova-core/driver= .rs index fc321c6a10b0..6d45fec6d7cc 100644 --- a/drivers/gpu/nova-core/driver.rs +++ b/drivers/gpu/nova-core/driver.rs @@ -123,6 +123,11 @@ fn probe<'bound>( // We must wait for GFW_BOOT completion before doing any s= ignificant setup on // the GPU. gpu::wait_gfw_boot_completion(pdev.as_ref(), bar, spec.chi= pset)?; + + // The self-test disables and drains the whole tree, so it= has to run before + // `Gpu::new` boots the GSP. + #[cfg(CONFIG_NOVA_CORE_SELFTESTS)] + crate::irq::doorbell_test::run_selftest(pdev, bar, spec.ch= ipset)?; }, =20 // TODO: Use self-referential pin-init syntax once available. diff --git a/drivers/gpu/nova-core/irq.rs b/drivers/gpu/nova-core/irq.rs index b2cfe73af114..ff8b00a82442 100644 --- a/drivers/gpu/nova-core/irq.rs +++ b/drivers/gpu/nova-core/irq.rs @@ -9,6 +9,8 @@ //! //! See `Documentation/gpu/nova/core/interrupts.rst`. =20 +#[cfg(CONFIG_NOVA_CORE_SELFTESTS)] +pub(crate) mod doorbell_test; mod hal; pub(crate) mod interrupt_tree; mod regs; diff --git a/drivers/gpu/nova-core/irq/doorbell_test.rs b/drivers/gpu/nova-= core/irq/doorbell_test.rs new file mode 100644 index 000000000000..aef9f4c7f2e8 --- /dev/null +++ b/drivers/gpu/nova-core/irq/doorbell_test.rs @@ -0,0 +1,257 @@ +// SPDX-License-Identifier: GPL-2.0 +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIA= TES. All rights reserved. + +//! Interrupt delivery self-test. +//! +//! The test triggers the CPU doorbell vector from software, twice, and ch= ecks that each trigger +//! reaches a registered handler. It runs during probe under `CONFIG_NOVA_= CORE_SELFTESTS`. +//! +//! See "Self-test" in `Documentation/gpu/nova/core/interrupts.rst`. + +use core::pin::Pin; + +use kernel::{ + device::Bound, + irq, + pci, + prelude::*, + sync::{ + atomic::{ + Atomic, + Relaxed, // + }, + Completion, // + }, + time, // +}; + +use super::interrupt_tree::{ + GinVector, + LeafEnableGuard, + LeafMask, + Subtree, + TopEnableGuard, + Tree, // +}; + +use crate::{ + driver::Bar0, + gpu::Chipset, + selftest_assert, + selftest_assert_eq, // +}; + +/// The CPU doorbell vector. Every supported GPU uses this number, so the = test needs nothing from +/// GSP-RM, which is not running yet. +const DOORBELL_VECTOR: GinVector =3D GinVector::new::<129>(); + +/// The only subtree that this test services. +const DOORBELL_SUBTREE: Subtree =3D DOORBELL_VECTOR.subtree(); + +/// Time allowed for each delivery to arrive. +const DELIVERY_TIMEOUT_MS: time::Msecs =3D 1000; + +/// The self-test's interrupt handler. +/// +/// It clears only the doorbell's bit, rearms delivery, and never walks th= e tree. A missing rearm +/// shows up as a timeout on the second delivery. +#[pin_data] +struct DoorbellTestHandler<'a> { + tree: &'a Tree<'a>, + /// Completed by the first delivery. + #[pin] + first: Completion, + /// Completed by the second delivery. + #[pin] + second: Completion, + /// Deliveries that found the doorbell bit set. + irq_count: Atomic, + /// The doorbell leaf's pending bits, as read by the first delivery. + first_pending: Atomic, + /// The doorbell leaf's pending bits, as read by the second delivery. + second_pending: Atomic, +} + +impl irq::Handler for DoorbellTestHandler<'_> { + fn handle(&self) -> irq::IrqReturn { + let leaf =3D self.tree.read_pending(DOORBELL_VECTOR.leaf_index()); + let pending =3D leaf.vectors(); + if !pending.contains(DOORBELL_VECTOR.leaf_mask()) { + self.tree.rearm_pci_irq(DOORBELL_SUBTREE); + return irq::IrqReturn::None; + } + leaf.clear_vectors(DOORBELL_VECTOR.leaf_mask()); + // Rearm before completing, since the waiting thread triggers the = next doorbell as soon as + // it wakes. + self.tree.rearm_pci_irq(DOORBELL_SUBTREE); + + match self.irq_count.fetch_add(1, Relaxed) { + 0 =3D> { + self.first_pending.store(pending.into_raw(), Relaxed); + self.first.complete_all(); + } + 1 =3D> { + self.second_pending.store(pending.into_raw(), Relaxed); + self.second.complete_all(); + } + _ =3D> (), + } + + irq::IrqReturn::Handled + } +} + +/// The self-test's handler registration and the enables that deliver to i= t. +/// +/// Drops in the order that "Enabling the GSP event" in +/// `Documentation/gpu/nova/core/interrupts.rst` requires: the vector is d= isabled, then the +/// handler is freed, then the subtree is disabled. +struct SelftestResources<'a, 'r> { + _leaf_guard: LeafEnableGuard<'a>, + reg: Pin>>>, + _top_guard: TopEnableGuard<'a>, +} + +impl<'a> SelftestResources<'a, '_> { + fn handler(&self) -> &DoorbellTestHandler<'a> { + self.reg.handler() + } + + /// Disables the doorbell vector and waits for a handler in flight on = another CPU to finish. + /// + /// The handler's counters and the leaf's pending bits are final on re= turn. + fn quiesce_source(&self) { + self.handler() + .tree + .disable_leaf(DOORBELL_VECTOR.leaf_index(), DOORBELL_VECTOR.le= af_mask()); + self.reg.synchronize(); + } +} + +/// Runs the interrupt delivery self-test. +/// +/// Call this only during probe, before GSP boot: it disables every vector= in the tree and clears +/// every pending bit. On return, the doorbell's subtree is disabled at `T= OP`, and the test's PCI +/// vectors and handler are released. +/// +/// # Errors +/// +/// `EINVAL` if `chipset` does not implement the doorbell's subtree. `ETIM= EDOUT` if a delivery +/// does not arrive within [`DELIVERY_TIMEOUT_MS`]. `EIO` if a self-test a= ssertion fails. +/// Otherwise the error from allocating the PCI vectors or registering the= handler. +pub(crate) fn run_selftest(pdev: &pci::Device, bar: Bar0<'_>, chips= et: Chipset) -> Result { + let tree =3D Tree::new(pdev, bar, chipset, DOORBELL_SUBTREE.into())?; + let tree_ref =3D &tree; + let request =3D tree.request_for(DOORBELL_SUBTREE)?; + let doorbell =3D DOORBELL_VECTOR.leaf_index(); + let doorbell_mask =3D DOORBELL_VECTOR.leaf_mask(); + + dev_info!( + pdev, + "interrupt self-test: starting on vector {}, subtree {}, with {:?}= \n", + DOORBELL_VECTOR.into_raw(), + DOORBELL_SUBTREE.index(), + tree.msi_type, + ); + + // GFW boot can leave vectors enabled and pending. Registering a handl= er unmasks the PCI + // interrupt, and they would be delivered to a handler that services o= nly the doorbell. + tree.reset(); + + // A delivery proves nothing unless the doorbell bit starts out clear. + let pre_pending =3D tree.read_pending(doorbell).vectors(); + selftest_assert!( + pdev, + !pre_pending.contains(doorbell_mask), + "vector {} already pending, leaf[{}] is {:#x}", + DOORBELL_VECTOR.into_raw(), + doorbell.get(), + pre_pending.into_raw() + ); + + let handler_init =3D try_pin_init!(DoorbellTestHandler { + tree: tree_ref, + first <- Completion::new(), + second <- Completion::new(), + irq_count: Atomic::new(0), + first_pending: Atomic::new(0), + second_pending: Atomic::new(0), + }? Error); + + // Registration must precede any enable, or a delivery reaches no hand= ler. + let reg =3D KBox::pin_init( + // SAFETY: this registration is dropped before the enclosing funct= ion returns, so its + // `Drop`, which calls `free_irq()`, always runs. + unsafe { + irq::Registration::new( + request, + irq::Flags::TRIGGER_NONE, + c"nova-core-selftest", + handler_init, + ) + }, + GFP_KERNEL, + )?; + + let resources =3D SelftestResources { + _leaf_guard: tree.enable_leaf_guarded(doorbell, doorbell_mask), + _top_guard: tree.enable_top_guarded(), + reg, + }; + let handler =3D resources.handler(); + + tree.trigger(DOORBELL_VECTOR)?; + let mut completed =3D handler + .first + .wait_for_completion_timeout(time::msecs_to_jiffies(DELIVERY_TIMEO= UT_MS)) + .is_some(); + + // The second trigger waits for the first delivery, or the two could c= oalesce. + if completed { + tree.trigger(DOORBELL_VECTOR)?; + completed =3D handler + .second + .wait_for_completion_timeout(time::msecs_to_jiffies(DELIVERY_T= IMEOUT_MS)) + .is_some(); + } + + resources.quiesce_source(); + + let count =3D handler.irq_count.load(Relaxed); + let first_pending =3D LeafMask::from_raw(handler.first_pending.load(Re= laxed)); + let second_pending =3D LeafMask::from_raw(handler.second_pending.load(= Relaxed)); + let residual =3D tree.read_pending(doorbell).vectors(); + + if !completed { + dev_err!( + pdev, + "interrupt self-test: only {} of 2 deliveries arrived within {= } ms\n", + count, + DELIVERY_TIMEOUT_MS, + ); + return Err(ETIMEDOUT); + } + + selftest_assert_eq!(pdev, count, 2, "delivery count"); + + // Every other vector in the leaf is disabled and was drained, so requ= ire the exact mask. + selftest_assert_eq!(pdev, first_pending, doorbell_mask, "first deliver= y"); + selftest_assert_eq!(pdev, second_pending, doorbell_mask, "second deliv= ery"); + selftest_assert!( + pdev, + !residual.contains(doorbell_mask), + "vector {} still pending, leaf[{}] is {:#x}", + DOORBELL_VECTOR.into_raw(), + doorbell.get(), + residual.into_raw() + ); + + dev_info!( + pdev, + "interrupt self-test: passed, subtree {}, {} deliveries\n", + DOORBELL_SUBTREE.index(), + count, + ); + + Ok(()) +} diff --git a/drivers/gpu/nova-core/irq/interrupt_tree.rs b/drivers/gpu/nova= -core/irq/interrupt_tree.rs index 6e97828bbd42..4bb27cc8b6cd 100644 --- a/drivers/gpu/nova-core/irq/interrupt_tree.rs +++ b/drivers/gpu/nova-core/irq/interrupt_tree.rs @@ -444,6 +444,21 @@ pub(super) fn read_pending(&self, leaf: LeafIndex) -> = LeafPending<'a> { } } =20 + /// Sets the pending bit of `vector` in its leaf, as if the vector's s= ource had raised it. + /// + /// # Errors + /// + /// `EINVAL` if this tree does not implement `vector`. + #[cfg_attr(not(CONFIG_NOVA_CORE_SELFTESTS), expect(dead_code))] + pub(super) fn trigger(&self, vector: GinVector) -> Result { + vector.validate(self.hal.leaf_count())?; + self.bar.write_reg( + NV_VIRTUAL_FUNCTION_PRIV_CPU_INTR_LEAF_TRIGGER::zeroed().with_= vector(vector), + ); + + Ok(()) + } + /// Disables every vector in every implemented leaf, including the sub= trees that nova-core does /// not service. Call this only during probe. pub(super) fn disable_all_leaves(&self) { diff --git a/drivers/gpu/nova-core/nova_core.rs b/drivers/gpu/nova-core/nov= a_core.rs index 8202c4982efa..8c0761dedda4 100644 --- a/drivers/gpu/nova-core/nova_core.rs +++ b/drivers/gpu/nova-core/nova_core.rs @@ -18,7 +18,7 @@ mod fsp; mod gpu; mod gsp; -#[expect(dead_code)] +#[cfg_attr(not(CONFIG_NOVA_CORE_SELFTESTS), expect(dead_code))] mod irq; mod mctp; mod mm; --=20 2.55.0 From nobody Wed Sep 30 15:28:46 2026 Received: from CH1PR05CU001.outbound.protection.outlook.com (mail-northcentralusazon11010011.outbound.protection.outlook.com [52.101.193.11]) (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 8BDA235F19D for ; Wed, 30 Sep 2026 03:43:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.193.11 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790739799; cv=fail; b=EPEVsIoIaDu99o7BEaAAKFplZtuWuWFpYrTSjI5Wh0tfgtBd9+Uq4INRA2qmyEN+0lu2Wus7kyUr+YefOvGaFHGcIFItEbbMN4ciemYlHbEpc2jMnY6zhrYow0muBEOdb85ub4dAO0+/qavYotWuV1lwlEmnWiUpSzHRDKhM0KI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790739799; c=relaxed/simple; bh=1Kk7b3twWjNCMvIJQ1DXCJfJzwpnTygobjCzBaqHZRQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=ol/vEvsVWcJ3UeFq868HyTH6+7Wphntf6adnoy17siN+9b46ZQfV58vnk2fZXBh+lmP2psizQHV6l8rloNn8sGI86/SMllD4ZRp8+lHvA4xAA6avrOh5rKJ2IwbgXvQqx/aWcjY7PwsATtaO3wcby5DoTx7lEEd/ye2Ptn2tRbo= 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=WswZz+DA; arc=fail smtp.client-ip=52.101.193.11 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="WswZz+DA" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=qwjxl7xXF8vGrMlSfvKT6amO7jccu/CuPi/SVGfRw8a5ZqHo7HoadLAa0xl72Iezhwx92LRV1vFoLPRygTPgXF1NaYe+Iw+2ui8VsPbHydZUjJnHMMIGaf1UzaoxU/otL1lWdTlyBmdjm3euRn+lHprrBU9vKkUCzLub1gvBrmZSygwdTQINhsZ0Xlk60fEy1IDZZI0BizGQotGOO5TJZj/UBJ0swWZqzfn4NAs7GGasOPNGLhLbziypE88svUQBM3GjPH4vzWqAe2L6ZfeMTTQoEsQgInp3eMCSvUfZx9rpraoVW5zFklq981w2XEAEc5tx5g53+TX8YO3nn7sQGQ== 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=7gP4g9u+NALNUZlpxocV+7gJvw39s9yk8jrazeZP7Oc=; b=f2m3PqX1pDtvfxEawHkBfFIk4kvqn1dE1SKKugmWmej712+ekLN+kfe3Dhvlzr6jEtttmXohQcry80AzICyVDaw6TkFs7SZQlg+qq30iok+8XHIPmMJkhCBXU7dscylSeWLmVg/nCAbJ0yizeAePdf+dC2Z6VBtPwYpMfBXSuHDPGHsYC4d+utpAQnQPTnbosmrXjov+Q6ezzFRMeUwXRUnPtCVo0/PxGoB6ryyQBaADmpr2JviZT2tZ2ObzvCC8OoLoj7IGZux2vG+TdMe9oq+JEzpTMjDpZOQO0f6pmsdZE+lwQRx1DccyA2WRJlrQjYCHcWjZp+P/9NKYjnhfPA== 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=7gP4g9u+NALNUZlpxocV+7gJvw39s9yk8jrazeZP7Oc=; b=WswZz+DAOcsUd3F+y2VCWJ7lZwHdrQ4Zs/liHkicSQBY8jSieNeytdSsGKXXCZ1iMpCIRdDDhwEMCy/g086kVsxNVeVi6FWdD3F97++b0VDZBSj5qpFoAKsoJIewSSbwfhXP2ruMctNgMvn9h7gTUbvVHQCxgFWU2WhUZSAtXYUG/JfkAfma2Gxd2xwhBijzrcs5CGNZmtRQ/E1MqF1seRVnI4HyJsnuhgPzxL4ZrwN4n8U/s3gj/Qyt5fEPznd6IhwCIUvuKFq5nTD5Z07Vx/5h4rTEQRAaj3/tzct0bVGbE+i3Fc+r/meWjcDCzgyZAfWscBAoC4jgnMU/funGlw== Authentication-Results: mx.microsoft.com 1; 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 MN0PR12MB6248.namprd12.prod.outlook.com (2603:10b6:208:3c0::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.451.26; Wed, 30 Sep 2026 03:42:20 +0000 Received: from DM3PR12MB9416.namprd12.prod.outlook.com ([fe80::8cdd:504c:7d2a:59c8]) by DM3PR12MB9416.namprd12.prod.outlook.com ([fe80::8cdd:504c:7d2a:59c8%4]) with mapi id 15.21.0451.024; Wed, 30 Sep 2026 03:42:20 +0000 From: John Hubbard To: Danilo Krummrich , Alexandre Courbot Cc: Timur Tabi , Alistair Popple , Eliot Courtney , 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 , nova-gpu@lists.linux.dev, LKML , John Hubbard Subject: [PATCH v5 09/15] gpu: nova-core: log GSP events instead of discarding them Date: Tue, 29 Sep 2026 20:41:42 -0700 Message-ID: <20260930034148.590687-10-jhubbard@nvidia.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260930034148.590687-1-jhubbard@nvidia.com> References: <20260930034148.590687-1-jhubbard@nvidia.com> X-NVConfidentiality: public Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: PH8P222CA0022.NAMP222.PROD.OUTLOOK.COM (2603:10b6:510:2d7::33) To DM3PR12MB9416.namprd12.prod.outlook.com (2603:10b6:0:4b::8) 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: DM3PR12MB9416:EE_|MN0PR12MB6248:EE_ X-MS-Office365-Filtering-Correlation-Id: f47ce58c-367f-43a9-ebef-08df1ea4d4ee X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|23010399003|366016|7416014|376014|10067099003|56012099006|5023799004|11063799006|6133799003|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: vPhcBv/Uqxhca1hsjTpPAfP9itm00O047o6LkpjV9x/ofVSoA8FV/ARwjoEWs/d0NJIawkWyQhmDLM3XvIRb762K8jNrdIus2NYZwfU7FTS1UOTajEFUSOyWrebwlzs/3r4x5oxfrEkGwVzYm3cYJbZR7gO6/kYH8N0XnW1rdyD6b+IXfjx/alQ3D0acSjyFHPN7jDePo7oqkmRDW1GfZNRCEOFvzGNb0HVxf2jEcGO1BIiHAnzYOmt0HEyFoEpPfKmd9a6r3001m2dkVl9A97Mu1cIUcwLV5flQqKNYhxalrotVpDtcpTV76nOdY1MirD1NOPc+NfNxCZmIWIZREpyDSVZBa+1KXp3mUBf7lLgkGvhvYwoKNxK+O0DcnYkGgiL1rGDiF0yP2C7VN0Jd3tSny9/fkuJ054P7/uP/mrgzf9GfVWhzqaJazgwrad0KWOeQ7Q/23bee3K1HNT1D7fz49lxewjrLOw4lPm6ToaeHIAZPDi/p6TQJ1eWYxL1If1COM1cR5lQh/Kqu8///LsG+9AKz7XaWHdOkwz20Yf/ZNzi508Xa+seRUziIOkM4tWTjf58ndjm3id9m1W/laABDKii9s0FSSOY3tkAWx3a2iT2+mvRgSsyRel+kYCZeBW55R1WT1MMuZvh9CRHplWRihI672guTIANzlUQzELs= 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)(1800799024)(23010399003)(366016)(7416014)(376014)(10067099003)(56012099006)(5023799004)(11063799006)(6133799003)(18002099003)(22082099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?Srt0xZqUlJRcXMGgpNhjp1ziGAXioqU0A2QbWzMP931xEbw/OklTm3XawDON?= =?us-ascii?Q?L6OSnVtNEo7ETMynXfY1S02qs9T7pC+XmSA1i7Db/9LOFr0WOjUPZTb4LDpC?= =?us-ascii?Q?uBJQHGZngx8qlORvZFF+Fj15PfKqLaIi24BCFA5DsX8nXNp+8X5GMnOWddaN?= =?us-ascii?Q?1i5qZvnRO3GRF5OxeIQyazhqjZ3fAYN/cNsfILrvy7gnyJYVNMY88d6zLUmD?= =?us-ascii?Q?WlnpU8Jsir4HnjMvyvyerPt0fePrOlHGh+oAtS2pPljM3KMly1VnRkxouKwG?= =?us-ascii?Q?sBjS5zMqV1Ixu6zOX996PN2ot3gNce+dhZmHCRsJexnkF3cNUCprUVYgV3UX?= =?us-ascii?Q?4CY0lyciBxJjVzyCsWv3XH/2ZSGUg795oVBxk8UCiymRGfOYc0slfQ9zT2ns?= =?us-ascii?Q?BfLDjAQOtEYV14NbIyW2fbqEVJv3SRK3cnL6+glAz+3/EGoQB1hn+G9gyoWY?= =?us-ascii?Q?h50VPbJj53BJZfGJP1CQ3fgW2h8EbxAxwsQP80PZqStrQr1+0IT1BYQ1W6YD?= =?us-ascii?Q?bvOWcURFba12XeI4ULDmQQfrd32Oa4BTUhjLzKxhZxIi+BhRCBXgTAM1JItR?= =?us-ascii?Q?Nbijd889e+7BQBfsLFm8yxByucz0TRaSDBxQQbv6Xb0ccsw42w3QS9H1Idgd?= =?us-ascii?Q?hYO47PF3TvRULc/rJSzrGhV2cEBN4A5+YQZQ6GkZSWHgoteiMg4CVfZKoUhH?= =?us-ascii?Q?9UAJWucawYNPLxm+OAD+jRbDERthFvQsDky6YadYMKsnp+yLYeGm99cceDTq?= =?us-ascii?Q?dM6nc7e0Nlo9QuPIt4kXn+iU1WTklxYWbeiZ8bnUjimeNTvDKqe7Hl8HvUFm?= =?us-ascii?Q?KX7c5gGBKr0uZ9f74ZIeuXokVRvDK7WVOqCD4WtugwsF4EvmLyblr2Va6RUw?= =?us-ascii?Q?7roIXCioL5+hNoFbVOlDL3Y1L5Zv7IBSgDxlottN9Zl1Far78TC4+Z2uqKt0?= =?us-ascii?Q?V5pOLa737256k+UpA4Xd7VVpUcSaYszRK/oP5AQCVr0qqgixsHcgVyVJVtYU?= =?us-ascii?Q?JvKks7V1pdpMzXCHsT6aPO03kfpRGzPh8XEP1r6CPPnfULLfUpuJcHIwIkHu?= =?us-ascii?Q?T4b7dtM0vEsLR14tDtFM/m8i3RlsvZCtE30x+V3xyQyHmZafT+i1b11eDsfr?= =?us-ascii?Q?aqdoP2JRCmCIKb4AenCAGvxIIjZ+I+nRVEiw+YNVCy2e7zwiD/GkW4HaG1+E?= =?us-ascii?Q?PjngttDjRUBlLY9KKsEA8Ts+sFX4eeaL3IqeZCTqf8OgvjVEeJGlFe4VZA+x?= =?us-ascii?Q?9gaFTmXQatE7IQ7ZvF5bZBgtrawAg+4IdIm3YufZphCvPLDhoZYdPYgv07wc?= =?us-ascii?Q?6CJ4Yd9OjXUSqEbVCV8063+G+RCz6EdJuOmfxvguS4uO3SDbCsMfbjgzi4Fd?= =?us-ascii?Q?H0tjVyZodyRjxc6JMLJm6aTPLrsMlgZ4kF0t1Q8UHIbYGPdraI/liy1pPybT?= =?us-ascii?Q?G+YalpVLNI9QlSCotOqtByd6xviEOISnaaZAXAhHK2Q0KZA+S2KeQxNvjUVo?= =?us-ascii?Q?ppz0prQJqbCGnGQzh0v5K869fNwF9JN7SCsO/N2oYHFeXDyR25JwRZZO6B54?= =?us-ascii?Q?uEJGducyKn7s/0glEpG+vMjyc3zJSnkvMpuDCSuwytRc98wHqvmrz5mIRyCq?= =?us-ascii?Q?+QAVVPk0UwH2BhDR1BO4HYvFidOIKoCU15CQ9F6mqPQ6+evcSNtGH+4yrQG+?= =?us-ascii?Q?xWaulESkNnfyCVAPBvsNE9LLBxV0HcnKZD9MQ3CmOyyUAcmAr1h+p+qW6IKN?= =?us-ascii?Q?F8iI8gq/cQ=3D=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: f47ce58c-367f-43a9-ebef-08df1ea4d4ee X-MS-Exchange-CrossTenant-AuthSource: DM3PR12MB9416.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2026 03:42:20.6927 (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: Ge2kxq/YwKovUwx8KfljE2npfdz/pu2iWSIAQ9KZ4TQij6rpuu6+j4c5TI/gmY56Xwex+sMRH9Er8jybO2RuIQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6248 Content-Type: text/plain; charset="utf-8" The GSP posts unsolicited messages on the same queue that carries command replies: log records, OS error and robust-channel records, and lifecycle notices. nova-core discarded every message that was not the reply that a caller was waiting for, and an unrecognized function code aborted the in-flight command. The GSP's error reports never reached the kernel log. Log every non-reply message according to its function code, on the receive path that already reads it, and leave the in-flight command waiting for its reply. Event payloads, such as XID numbers and log contents, are not decoded. Assisted-by: LLM Signed-off-by: John Hubbard --- drivers/gpu/nova-core/gsp/cmdq.rs | 52 ++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/nova-core/gsp/cmdq.rs b/drivers/gpu/nova-core/gsp/= cmdq.rs index a5595da23407..4591f6c61ce6 100644 --- a/drivers/gpu/nova-core/gsp/cmdq.rs +++ b/drivers/gpu/nova-core/gsp/cmdq.rs @@ -559,8 +559,7 @@ fn notify_gsp(bar: Bar0<'_>) { =20 /// Sends `command` to the GSP and waits for the reply. /// - /// Messages with non-matching function codes are silently consumed un= til the expected reply - /// arrives. + /// Events that arrive before the reply are logged and consumed. /// /// The queue is locked for the entire send+receive cycle to ensure th= at no other command can /// be interleaved. @@ -819,8 +818,8 @@ fn wait_for_msg(&self, timeout: Delta) -> Result> { =20 /// Receive a message from the GSP. /// - /// The expected message type is specified using the `M` generic param= eter. If the pending - /// message has a different function code, `ERANGE` is returned and th= e message is consumed. + /// A message whose function code is `M::FUNCTION` is decoded and retu= rned. Any other message + /// is logged as an event. /// /// The read pointer is always advanced past the message, regardless o= f whether it matched. /// @@ -829,8 +828,7 @@ fn wait_for_msg(&self, timeout: Delta) -> Result> { /// - `ETIMEDOUT` if `timeout` has elapsed before any message becomes = available. /// - `EIO` if there was some inconsistency (e.g. message shorter than= advertised) on the /// message queue. - /// - `EINVAL` if the function code of the message was not recognized. - /// - `ERANGE` if the message had a recognized but non-matching functi= on code. + /// - `ERANGE` if the message was not the awaited reply. /// /// Error codes returned by [`MessageFromGsp::read`] are propagated as= -is. fn receive_msg(&mut self, timeout: Delta) -> Result= @@ -839,11 +837,11 @@ fn receive_msg(&mut self, timeout:= Delta) -> Result Error: From, { let message =3D self.wait_for_msg(timeout)?; - let function =3D message.header.function().map_err(|_| EINVAL)?; + let function =3D message.header.function(); + let seq =3D message.header.sequence(); =20 - // Extract the message. Store the result as we want to advance the= read pointer even in - // case of failure. - let result =3D if function =3D=3D M::FUNCTION { + // An early return here would leave the read pointer on this messa= ge. + let result =3D if matches!(function, Ok(f) if f =3D=3D M::FUNCTION= ) { let (cmd, contents_1) =3D M::Message::from_bytes_prefix(messag= e.contents.0).ok_or(EIO)?; let mut sbuffer =3D SBufferIter::new_reader([contents_1, messa= ge.contents.1]); =20 @@ -854,11 +852,13 @@ fn receive_msg(&mut self, timeout:= Delta) -> Result dev_warn!( &self.dev, "GSP message {:?} has unprocessed data\n", - function + M::FUNCTION ); } }) } else { + self.log_event(function, seq); + Err(ERANGE) }; =20 @@ -869,4 +869,34 @@ fn receive_msg(&mut self, timeout: = Delta) -> Result =20 result } + + /// Logs an event, meaning a message that no caller was waiting for. + /// + /// An OS error or robust-channel record is logged at error level and = an unknown function code + /// at warning level. Every other event is recorded only by the receiv= e trace in + /// [`Self::wait_for_msg`]. + fn log_event(&self, function: Result, seq: u32) { + match function { + Ok(MsgFunction::OsErrorLog) =3D> { + dev_err!(&self.dev, "GSP reported an OS error (seq {})\n",= seq); + } + Ok(MsgFunction::RcTriggered) =3D> { + dev_err!( + &self.dev, + "GSP triggered robust-channel recovery (seq {})\n", + seq + ); + } + // Nothing to do for the remaining known function codes. + Ok(_) =3D> {} + Err(raw) =3D> { + dev_warn!( + &self.dev, + "unknown GSP message function {:#x} (seq {})\n", + raw, + seq + ); + } + } + } } --=20 2.55.0 From nobody Wed Sep 30 15:28:46 2026 Received: from PH7PR06CU001.outbound.protection.outlook.com (mail-westus3azon11010010.outbound.protection.outlook.com [52.101.201.10]) (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 2FB173812D1 for ; Wed, 30 Sep 2026 03:43:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.201.10 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790739799; cv=fail; b=f+tCaJpODJ3OVDmPRh/vOO+kB3KEqjOrDKk9K1URqO3FHWfmRRNjPZCMmv8MKSkM4pvy8yNyxtbjOWq/p0BIUka2RbpV43YQIxvhleVM12cias7oNkbgoblkuqphq48TocnC4fZOrs4gGzlL6JVq3ieQu+nBt1WLlYWFV81AXDk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790739799; c=relaxed/simple; bh=6dHiwb/k3IAubSrStjK3X4qw/6JXIyzLyO0xlMnGrl8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=E3dg0i6f2PZ5PgZhTOzUSQVBgDZu9/5Ll93HzV37VdFKlP8fDmyGv0DdUBUtqMwzDbqrUQgVRvRbMkz5UfUJFHKzk4FApi8KTTd+hyPYZcHAm/VGa9MXRJGA844H2EpjmiyTEsGVM2t+pYXFBe4bk+ENErzrqksiWjQO5JNHY3k= 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=N+NzeA+f; arc=fail smtp.client-ip=52.101.201.10 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="N+NzeA+f" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=HousGSVMieKRO2M1dm51k58vezF0HUyb0kUoCfD6Oy4chx5wXMeDGZfNTzgsCv5a8SMIDYZLUFiCf3ZMhZBY/7tBTVt/Bgx1n7nI6rmdIkVsd8wIlEPZagdS9pHCqM3LhRWYdYN2pD4QpWIhVfbYYGB37b9LtyKLFBjHN4rdQHPyytPqjjGvI9IOdEhD0BX3G+hmtYA8ztoz04DNVaAxMtMxPBZEWc0XiguFqriQRURtOWJXkkhoNF6eMgM1dLWKgO2LTKwKNxFy8HZKUromJWiZXTd0CiiMqRubxSMmZIpxOgJhOihZWE0iIZPBcZbsiFL0+dXGMfn/zk1+O3VXUQ== 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=hok9xF6H90N0IEAbjg3wbh7NOy8uZmQbGdJ9sX1gmk4=; b=E6/6l03N4BtTHKv4W6JklZY/fKUtO/TxoKOcofSsS+d+U+wxQvbTvePB8iwkL1fV9/Mjh11VhaL9TJVxKk+nbldQAnkFR3DiB7Rs4joHUKagwR4cnuojWvZ39iO4yf7y1tgt6kk8vQFt00xz9sothI4S5oMebdmAzkbqucwn8mQT4VK7kX/EuWyoFmf4uVT3LYgRKl2vLmnXt3VvmAoAgrM+B4sPkmf7N9ruzXCMfWi7VAzSCV2XnvK6E/T2/gxk1f9SUv8gYVP+RHt4PR4nBPICH2FRkIWAyIqTobjcM+nEo6i07wCOQiN1GUEBvi/7b1pHfMeDlhmvXzCyqoDEhw== 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=hok9xF6H90N0IEAbjg3wbh7NOy8uZmQbGdJ9sX1gmk4=; b=N+NzeA+fd9AEeNa7Em+zKMzPlMmvpV4ffuy+XWjw85JgGC5xDMBGTAP9gPipquRCF9MF8u23ZAhY/mFZni6T7plUpi4fpPrziP1zJsvPS7viBJJws08FAPb8KpQbmMH0itti2cZOoIYfZ3zK1PHNGMexVzI831gzgrqNFQP/KnEqxruJ+xStdYOZtAlwr/KIR8EKXQRB+J7i3GNYQ0KoutjSgwKCU7i9ex/U4pPjjh3ZcBKPlbbPBjMnkdfG38V0PQs4qLAlBKAMGipeZpP3FGgvrLDMI9AH0j7NpkOXzeO0nppIrJV3favDa1GeEI/LP7dYFzzV5uBDsL4eD4+xFQ== Authentication-Results: mx.microsoft.com 1; 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 MN0PR12MB6248.namprd12.prod.outlook.com (2603:10b6:208:3c0::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.451.26; Wed, 30 Sep 2026 03:42:22 +0000 Received: from DM3PR12MB9416.namprd12.prod.outlook.com ([fe80::8cdd:504c:7d2a:59c8]) by DM3PR12MB9416.namprd12.prod.outlook.com ([fe80::8cdd:504c:7d2a:59c8%4]) with mapi id 15.21.0451.024; Wed, 30 Sep 2026 03:42:22 +0000 From: John Hubbard To: Danilo Krummrich , Alexandre Courbot Cc: Timur Tabi , Alistair Popple , Eliot Courtney , 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 , nova-gpu@lists.linux.dev, LKML , John Hubbard Subject: [PATCH v5 10/15] gpu: nova-core: return ENOMSG for an unmatched GSP message Date: Tue, 29 Sep 2026 20:41:43 -0700 Message-ID: <20260930034148.590687-11-jhubbard@nvidia.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260930034148.590687-1-jhubbard@nvidia.com> References: <20260930034148.590687-1-jhubbard@nvidia.com> X-NVConfidentiality: public Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: PH0PR07CA0037.namprd07.prod.outlook.com (2603:10b6:510:e::12) To DM3PR12MB9416.namprd12.prod.outlook.com (2603:10b6:0:4b::8) 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: DM3PR12MB9416:EE_|MN0PR12MB6248:EE_ X-MS-Office365-Filtering-Correlation-Id: dc6d32d0-a033-48ff-1cea-08df1ea4d5d3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|23010399003|366016|7416014|376014|10067099003|56012099006|5023799004|11063799006|3023799007|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: mkMetOFQeOvfE65hGTkqf1qMJsIbv6Ufz3ALGVpRuEc7sKm+oFZCcrvQN0Yov/zEKQW6YfIzl5Fs9InHgSumT9kzyQc+PHi/4Waye/M7KcMOHLd/5ZgDwzO/WeX0LYrEeOkjEKBY6XiEmZv5VusYm1Ivb0+bMv4/6JR6Movw40lgnLbi7zh7jW/eV2cZvEJCzwoJpUvoMpJgiZ968lUtANe2A5b/cTCtySACCcQANrwlNe10udWFhG6G+2aGQYLWn4mCs+pazR280tefFcz8ez1n4NT50PstqgvaVVegWmiFRPtAa1BBtKCWcEmqELNlSIye806E/exWbbj5qoq3cWs81eopVWzI9xaN8Gyr6DLycMroakpjSK0ADWGbzxJ+ztRVfAYfCYva7zi0K9PGSdSkc1sn5B2WmzteYkAi9kUmBYnAKF2LGe8Z9ZHaW7cCt+DyxwA3otSnxxDfpkLmuCjHFJqvQYiTOLWdrjq/2/dYIqX/g/EbnE2zNk8zkW3J9NuxEOpwrho0gNNz1hSTDosxtMuLaagw4IpkMm2N9e7v7nLFQRVO++wbCtk6u72A+aTMA0VCNNSx01Hjxfo0jpOVu8omV5ZD4y/uuhQNLXKJd3Md7XMjISeFAb2Uwjn8Ge49FA1Dv+NNvAtrICzhw97l0fhMsySD7iU53AtzWBo= 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)(1800799024)(23010399003)(366016)(7416014)(376014)(10067099003)(56012099006)(5023799004)(11063799006)(3023799007)(18002099003)(22082099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?B7OZCCr77Cf76Mo1gbFpBJszh7cCZXProViukfElQyDJb+q/3ynJxmuMuEDf?= =?us-ascii?Q?xNblFya1P/75EmpXRG6TMUy0FN3S8Qjth7nXSzwpKSbWqg9of+IXlp6ziJFc?= =?us-ascii?Q?icdG4+NaECCFjOU/T1Cnb7IdZLdb0nJiFGwtsQUvJR6g+fNgLkiljYrzDaAz?= =?us-ascii?Q?p1ADQ1twOBENvXxJKRYe2E/MEjriOOUUoWW///7UcIYWvt/pQEGP5UnHQsyS?= =?us-ascii?Q?+DFu1UxEIAArm7MVZ1MHGHVB/w/DJNJyYD8PKznmK0YIoay7KKxT1/WWuxLL?= =?us-ascii?Q?9m42/5foTABVux6Rrvpl6shqmVifT1NYQ5+Tl7dXCoyju5/kLskTI/fMavg5?= =?us-ascii?Q?KsVIykHy3agmXPahIV9sf5vsBfnQHSl8VdHXfHzawSt2VRCObQl8AemQMDss?= =?us-ascii?Q?aClBNruRa5IUnoD6GlhAOJpdN5J/rEsPIOhTbv4JB9vIiyl03lwaD/z6KuwF?= =?us-ascii?Q?nsg6NVSYIKIB2Hgn46fKgurSCzFfg/uIomw9I6tm7APDUX7HLn8x3e05g+OV?= =?us-ascii?Q?ojOneBuWsi0F8aXFWmEGmxzJi/BG07MLnVz2hY6TZCkYnfHxjc6mOc8IrcFD?= =?us-ascii?Q?ro/uz5LaULAdM3eHl0q9OlsFvTcK+nDJEyMFR5PGlFpS/D2NCP/g8rpnBjSM?= =?us-ascii?Q?BOmkCstDqXiik4W1voop4Zzbbb9TNzZpF9gNfbzjRWmy+aHJ2a9DHQkQRd9v?= =?us-ascii?Q?IsGy9H+evRxZL/ui2mAmebSXDsrLrTiVcYCEf9os53mO7fD5Q51yXA82Lfgs?= =?us-ascii?Q?WO7C3CWvIA6iyJCRbqb3SkAKQ48dQEKa8mG7ze8epOZsVnEmdwD5ynGTpWjs?= =?us-ascii?Q?nEy85nOFJ0EZ7xqVgdMMaclNx8GzfyP05ARxN3/4ibw2dVlWLosL+UZmlSLW?= =?us-ascii?Q?bPOH4Zzr6F5k6cqOB2kG8WzVtMwuQNAu8zgO575dpaQh6EkQktc7QtAMzFjM?= =?us-ascii?Q?aLr7EkG0lwls8+jbNfl1wMxLdV/ADvGHYLda5P8WaszhatoYiwxW0gPZSJ+N?= =?us-ascii?Q?Js6HButg5Rn1egdDBc7XWyH1ay6PKwgm/TXlH5YbAg5rkL680KhnESSkhHBT?= =?us-ascii?Q?CiROqQqGTFFynTQ4t1F3k7dJryXp7IMcOCy/D+qhybTWLw8FbeMVHntzFm6o?= =?us-ascii?Q?5vLjeDHMD7bagYjsTLH/sZsmML2a7ObpG67oV/K0UHIA7TtsA6H1yTkWR9X4?= =?us-ascii?Q?Z4Z/wVBl7gBFi7BLrp+pSPQYMLvZK94hA/SgpgFCK0knkiE+U7P56Jzo0LHL?= =?us-ascii?Q?rN95a+tuqljVwP3Ax/UGyVqKMA+yOIYz+6HgX8XncdtAigL3HKSHKg2P4Gq6?= =?us-ascii?Q?Fh6rD2E5Kr+099+H12gSGRl6n7CSTPeNkqfwp+wtlZhnMk6l9OnK/NOT0jM9?= =?us-ascii?Q?GbjMgrQIlP6FEgkqCpxnkW/GRpVMaWKdQdiqMrwKsqbTZ7gPjw8oCwnNNmpG?= =?us-ascii?Q?506CSKutpQAT40bJ/e8dPjt4dVzBLMjGuHmNRXm6+AeV57ntQnkOW7OVdZCS?= =?us-ascii?Q?vARL4jcV2G0m5nT6Xe6OmawUTVzLIGGR/lEQEhS0VUNI4eVu1IjHHdS3YQSg?= =?us-ascii?Q?QQJoodotbtNxFVu5/mVJJbgDbKeME25bKnodgkqgVjMlvF7wo+TUZEevPx3U?= =?us-ascii?Q?+PFYSmUXEKDBfYRssbdy+C1euayq/JKwabY1w3KreAanHuCujWoipTs1yJHC?= =?us-ascii?Q?NLhyv5NRdvS5i6B0fFcCoxmAXLD+gNA3msSSmuHn/Lfoa+szxkzWp1Cw8gJ3?= =?us-ascii?Q?aw59J2Yj1Q=3D=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: dc6d32d0-a033-48ff-1cea-08df1ea4d5d3 X-MS-Exchange-CrossTenant-AuthSource: DM3PR12MB9416.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2026 03:42:22.2089 (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: ylo/rPLH6Dvhw81PkgKzuotAOiN24i0OlyAyeBPPa2GREJxoMo9oEh9xxUquk4KkjXuv2WN8L+cEIzQAdQcoRQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6248 Content-Type: text/plain; charset="utf-8" The GSP posts unsolicited events on the same queue as command replies, so a receive that asks for one message type has to report that the message at the queue head was a different one. That case returned ERANGE, which means a value outside a valid range and says nothing about a message. Return ENOMSG, no message of the desired type, instead. Suggested-by: Gary Guo Suggested-by: Alexandre Courbot Assisted-by: LLM Signed-off-by: John Hubbard --- drivers/gpu/nova-core/gsp/cmdq.rs | 6 +++--- drivers/gpu/nova-core/gsp/commands.rs | 2 +- drivers/gpu/nova-core/gsp/sequencer.rs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/nova-core/gsp/cmdq.rs b/drivers/gpu/nova-core/gsp/= cmdq.rs index 4591f6c61ce6..ad2a14d08cb0 100644 --- a/drivers/gpu/nova-core/gsp/cmdq.rs +++ b/drivers/gpu/nova-core/gsp/cmdq.rs @@ -585,7 +585,7 @@ pub(crate) fn send_command(&self, command: M) -> Res= ult loop { match inner.receive_msg::(Self::RECEIVE_TIMEOUT) { Ok(reply) =3D> break Ok(reply), - Err(ERANGE) =3D> continue, + Err(ENOMSG) =3D> continue, Err(e) =3D> break Err(e), } } @@ -828,7 +828,7 @@ fn wait_for_msg(&self, timeout: Delta) -> Result> { /// - `ETIMEDOUT` if `timeout` has elapsed before any message becomes = available. /// - `EIO` if there was some inconsistency (e.g. message shorter than= advertised) on the /// message queue. - /// - `ERANGE` if the message was not the awaited reply. + /// - `ENOMSG` if the message was not the awaited reply. /// /// Error codes returned by [`MessageFromGsp::read`] are propagated as= -is. fn receive_msg(&mut self, timeout: Delta) -> Result= @@ -859,7 +859,7 @@ fn receive_msg(&mut self, timeout: D= elta) -> Result } else { self.log_event(function, seq); =20 - Err(ERANGE) + Err(ENOMSG) }; =20 // Advance the read pointer past this message. diff --git a/drivers/gpu/nova-core/gsp/commands.rs b/drivers/gpu/nova-core/= gsp/commands.rs index 59d7d7fb15e8..0c787fd689bf 100644 --- a/drivers/gpu/nova-core/gsp/commands.rs +++ b/drivers/gpu/nova-core/gsp/commands.rs @@ -191,7 +191,7 @@ pub(crate) fn wait_gsp_init_done(cmdq: &Cmdq<'_>) -> Re= sult { loop { match cmdq.receive_msg::(Cmdq::RECEIVE_TIMEOUT) { Ok(_) =3D> break Ok(()), - Err(ERANGE) =3D> continue, + Err(ENOMSG) =3D> continue, Err(e) =3D> break Err(e), } } diff --git a/drivers/gpu/nova-core/gsp/sequencer.rs b/drivers/gpu/nova-core= /gsp/sequencer.rs index dae34c11eb05..1782ed7d7ca6 100644 --- a/drivers/gpu/nova-core/gsp/sequencer.rs +++ b/drivers/gpu/nova-core/gsp/sequencer.rs @@ -346,7 +346,7 @@ pub(crate) fn run( let seq_info =3D loop { match cmdq.receive_msg::(Cmdq::RECEIVE_TIMEOUT) { Ok(seq_info) =3D> break seq_info, - Err(ERANGE) =3D> continue, + Err(ENOMSG) =3D> continue, Err(e) =3D> return Err(e), } }; --=20 2.55.0 From nobody Wed Sep 30 15:28:46 2026 Received: from BN8PR05CU002.outbound.protection.outlook.com (mail-eastus2azon11011063.outbound.protection.outlook.com [52.101.57.63]) (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 1237D3909A2 for ; Wed, 30 Sep 2026 03:43:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.57.63 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790739802; cv=fail; b=BO7P6Hw2gAm+OLGQ9HrenbIoS9/XLUqJeopihtJdOpClNLB76q9hwriQzt3z5QpdJpCSrmrqm4WQUSpgG3TJWXT90gIgQp13PfdQ65/NpOlsLRGTQY4NfaHAs5cOGasAwp1N8MFaAiozMQ+fAhkPdy+8ikMRUqi+q9BLTCFMSiw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790739802; c=relaxed/simple; bh=lUWQlpQLBXs2jwVGwknbQrTcE6ZOmjbru92R4mOEl1k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=uamnfY0lj/UOfQAs9duL6UqtTJ+Rfw+ce9Vp9ZFJmEgnaR2V27YEwtABW9fHolFQTxIiR4cPCapoLzGgwt8zPXHfUbzCd/rNUwDL2Bk4+2yodu3klQFN/+310cl2rneoKcJaULbL6pW0FxG7r2OoNG1hHtJsrD97F7dTsP2ELdc= 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=RN0ypfO3; arc=fail smtp.client-ip=52.101.57.63 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="RN0ypfO3" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=MJDA1JFtKhM8wLziHc4irLhcw5EeUYzjNQ9ixZ2/5FQvZextOeseUcK6scKSa0Y42010bwCDs2Hb43256NE4+HezzW2xgBC7cmEE5Bi/LjYs8Nqei7vRfEDqg6cciHsusGULUWNvovcDg7sGigrFM6gXfE4w5JgfrEAonPG7YVxYPs6TT81lVx1tnes+IAXrdXMjbfK57Tax7mXIqD7DAb5FLRctR/l4cjqtktRlxWEw0irH5OeqQIZb3AZ6UA9lcy9bLOq8csDaFMIfCty5yf25tpGLZWxsTVDJUvNh/8RBSfaa7U5g7gNUOkSG/SixieEcRbKyaNjJsAfwLLTRow== 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=HiOXOmILdLvTDf+atlsHOwQ3KyN1aiqmu44Bwj7gnJA=; b=quvLLRyne1/bFhhbkvsiUNXnv8+rjjNY05QLIIWpb5d9vcougQ5kUdeknKUg1XAr86y+K6oM0Tt7Ay7av71vPCVUDxdf7SN9dCRsDWj/rHvNTlRrmkn4al0Tk09Ol1y6gUWhijJrQRoYlDZBeYKhku1risqeCTWudCQC4WU1IArppMVj0EfWSfOrXcfLKO3VDs0cq5qg+iBQFWoVjjChx5YSQXCPc2vVI5/oGj3ys9ZYkbD51EHYF3O/GclhYdlI6o2T0XFdXDokitSFr7lNzG5p9c1YDJzqqqXAaxzwCGe0/CIGbb0tsPJYS7JJkCC/6XtVWrYqndvnf4sM2wjiew== 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=HiOXOmILdLvTDf+atlsHOwQ3KyN1aiqmu44Bwj7gnJA=; b=RN0ypfO3AvNnQOyHa1a5g2PRmVW1HFLAIiBriIyWLMO+8+exdmkzaHWVnYkSgQDg2wlSXbIhzhMzXnxvw09hxnS1E3IJqbJ+arFKHVkhR1unD3EXAQ1TwbqChyDahT1nwjrCvGR2MgxHocPQEJRtQeJ1IiEKns3Kqp7S8Lipfii5x4Hhl5m8iAPzr0x8l0FV4lrKpQC7UIV8sgmT2WtxH3pPpVFzZqgI9QDQ+1Yw6OmKZ/K8NpLL+HPZc+TTI+oAH0c9ARQ8mO4Z5erWfl6imevWHJS9Fa2KAWYPPQJA7cfhL6QCH0Om8xjw8Sl6mHUo5Gc7uaXKDdXJ70/F4+FNXA== Authentication-Results: mx.microsoft.com 1; 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 MN0PR12MB6248.namprd12.prod.outlook.com (2603:10b6:208:3c0::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.451.26; Wed, 30 Sep 2026 03:42:24 +0000 Received: from DM3PR12MB9416.namprd12.prod.outlook.com ([fe80::8cdd:504c:7d2a:59c8]) by DM3PR12MB9416.namprd12.prod.outlook.com ([fe80::8cdd:504c:7d2a:59c8%4]) with mapi id 15.21.0451.024; Wed, 30 Sep 2026 03:42:24 +0000 From: John Hubbard To: Danilo Krummrich , Alexandre Courbot Cc: Timur Tabi , Alistair Popple , Eliot Courtney , 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 , nova-gpu@lists.linux.dev, LKML , John Hubbard Subject: [PATCH v5 11/15] gpu: nova-core: bound a GSP wait by a single deadline Date: Tue, 29 Sep 2026 20:41:44 -0700 Message-ID: <20260930034148.590687-12-jhubbard@nvidia.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260930034148.590687-1-jhubbard@nvidia.com> References: <20260930034148.590687-1-jhubbard@nvidia.com> X-NVConfidentiality: public Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: PH0PR07CA0031.namprd07.prod.outlook.com (2603:10b6:510:e::6) To DM3PR12MB9416.namprd12.prod.outlook.com (2603:10b6:0:4b::8) 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: DM3PR12MB9416:EE_|MN0PR12MB6248:EE_ X-MS-Office365-Filtering-Correlation-Id: e597c530-8c5a-4e41-2706-08df1ea4d6e0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|23010399003|366016|7416014|376014|10067099003|56012099006|11063799006|6133799003|3023799007|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: lZIWViKbnqmJcDszob8IvFd5bk8NIR3KIRJprki5ck4suKgwEEv9HdvnepiJHE4Me29Y1avnuFScpu7YVafeKV/XeW7XglAaAv2ZWzW9D4Qk64306r4krwFYYULyIdIOO3epgj5GA2BL/vupVhg4KLZGnBLM7NnmY+H4nOua3YVYRaAK/9jwV3kTnDV91fH0AAqte39VckvgLUx5HExRre598sleIUzKkqC+bDLBsWJGycLxPv0iPyu4VqGu+dLSwpjn73pJ5jeMr1aoUdW6QpSBukLup5qNq0AZ1Bf0xK6WSqj1KsTQbW56GsjkOo5pK+qm9NdRSzayPM5gFVHpdT2PiS8CQuy3D+Vo9VH+DLNi/8spdbb7UPytQQubwCttxUmiLgO5BrOe4fb/mS2vzUXv5SI4lYMqpRiT+OrCXNy7W4jSWZMfVtgSbC75kfNjb3JsFyzDvOTrXXpVPyFF8nV6DzFG20rwI9r2Wv7C8lTkXIr05/nhY3MXzmHD6w7tsu4N4Js3HllAbdQpqifG26cc4Kr0Rm7LvEZUlshQbOMh3FfOfgfy96mD0Re3Zb8XYVIxmjFnFFIwakvoqZXObJpImw9DWxP/sRCsU6Y1Fj5tcbuYAgIadsMfitAvQPzLlWoThPiASBdYQkf4FganjltVzLBY3QjBs6Wixb+XLwY= 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)(1800799024)(23010399003)(366016)(7416014)(376014)(10067099003)(56012099006)(11063799006)(6133799003)(3023799007)(18002099003)(22082099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?wo3aqbh7DDbqb6nad6+wT8E2xhUGRv/dwwjrgpY9Oc3FNMq50MAzICBYY+ym?= =?us-ascii?Q?vrzDodo7GLDSgrjyjAKedF0+wY0RdYKmmQmZJBA3cIWYK/OiQZ5Isxr204/q?= =?us-ascii?Q?ubyEun6XYUrPT7REuGf8LsjgyhnAIExWyAGGY2hKEeH82ZJpyzBC3YkOBQtP?= =?us-ascii?Q?8gSJT2Z6Y5VOAyXKJcbUXf8/xRPZzgVZlZvRm+yj1bjfva7pS7EZp/3hAsp5?= =?us-ascii?Q?MUBKJpQojSHdAlz4SVomtPlmtWGQdCE5pgB81eCBNdeAyS2D//SufqUg2sLm?= =?us-ascii?Q?IMD34n9InthrDkNx6bgh3OHjh+lvlUUkUG4UG3LREqiJgvcum5XC4AvqK8DB?= =?us-ascii?Q?utY+nsrWLF/VxkHmJbIrblONq9FU89dVBV3Q+ReGpnjGth3be99524u+x+kR?= =?us-ascii?Q?6Offbs+fYRDzSGchhOf0JCrx6Zfs5jc5Z3lGQgkzRDyjYkRmcwZsHwBrMOa6?= =?us-ascii?Q?x2fW3ieQiH/sDFBgCOhWzuqSQ97ygE2L/xQGUtBzGiLR1LedcpC5JW6Nyct4?= =?us-ascii?Q?OYGrFXAAh4/2OJlryNxJLLtsxFqBJ8rw+VpgiHy2RGVzTjC9TxUBNu+vNYNe?= =?us-ascii?Q?b5KA3SyPHeDzcn/rIGO7tlvG5wEq2Rph54YV7Ve9c8GL/Wjk/k/v7rTBpxYx?= =?us-ascii?Q?YZ+dyYBMYj/5LA9PwtoemIgnIC7jm7RPgEAZ//Q3HCxXNv5bmII7lhRUltN8?= =?us-ascii?Q?p4Wlbdv0X5fjWbOgaYRSOYazbL7Mwo+QkpJ8gX/UivwvXvzx5lLIcnRIBijv?= =?us-ascii?Q?FutGIGEr9tqvG6J6oZRgLY/A/D61F1uKxSHRfPkyOeCH2NNMwmk4F3FFlP43?= =?us-ascii?Q?N3VAqe1Q+3VUsEeAv62krHwUad1bGRSsPfh3nn47v2EuD9rtRdlSdf0xX0iD?= =?us-ascii?Q?sewNQ/brApt+L/+krXri2c7bdJBhPY4BA65Fj35GeLxRSGAlyNEWPb4wmiKu?= =?us-ascii?Q?ohfQH64rEPHEWzwau4JN3ldIhk8WlNwT8y4t5VYdFlD60Zo4bOlkwm1wRLll?= =?us-ascii?Q?YJ5wZ3OY36CV+Qe+L7NC7FG36oEdh3zsgCrU8m7IUJZUkr36w1Yk68oxZOst?= =?us-ascii?Q?h+t9ni95bBTAoOzVdg7vj9QkMXWccRTwHLNE8H6H57vyLNCz3YNeULrDjH/B?= =?us-ascii?Q?m9jHOzdmIvjndZO7KoqP82L8Kq711js8Y820sLEMJj7f5bU82KNNFcFEFk75?= =?us-ascii?Q?ThOs1r4NJpHubn2LyPt0vetazxk/tYCjeBoNaA1zX09W60QWdxRMd3zhQQPG?= =?us-ascii?Q?4fYl1FXIXTNkBW2V1DQnuVVhb+zEe/O3qVfxHV2vO9ipdrtaSOMgt4H7Vn7t?= =?us-ascii?Q?6jWnVkBGtYF3c8AZyl6hx64ELFIZstHkXrrAV+Ir9bPmtOcp2B8LuqZppIYb?= =?us-ascii?Q?WfhJgT88Flv5bi85goBuT94zuwaGr1jv4n8r9D66Tg+FERwwSNJSGvlhqx1s?= =?us-ascii?Q?CsM88/nfb0KUXQSxFT0AuFtRZt33e1+t15SiMSTjPx26hrAuu+OiP38AMt9z?= =?us-ascii?Q?Lp1d2f7/LZoOOdg+ATlTvDbRBsXOTPsgP9ZxNfICmZaKDCYQjHVjAv6UPyAL?= =?us-ascii?Q?kNF/xA7K6CH5uzQXEP5CHJu1z93DVbpeeBqQzv5bn0UPy/YPmgf1Gwux6YiV?= =?us-ascii?Q?R0IX4HeniPkJ6Lgqh/1FpDaOTyEkWlhd4eCu0B64IgOm/y/ct3npj26QGNFX?= =?us-ascii?Q?NlHu+0TOARyQGezsF3H/6Wy6ZuxbaQY+5ISXgToiDCkZdBJ4z6r7E9QWFnPV?= =?us-ascii?Q?dTzLiYvAyQ=3D=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: e597c530-8c5a-4e41-2706-08df1ea4d6e0 X-MS-Exchange-CrossTenant-AuthSource: DM3PR12MB9416.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2026 03:42:23.9455 (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: Kiq0jfD8+GJcJtAsDC/sBuMjhtcTS+BJ57vpf3OpLMzhxKxHYOfuwT6YgREKlze3y7fMcU5qhmdNHIOFVUgBGw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6248 Content-Type: text/plain; charset="utf-8" The GSP posts unsolicited events on the same queue as command replies, so a caller waiting for one message consumes whatever arrives first and reads again. Every read started a fresh five-second timeout, so a steady stream of events extended the wait without bound. The two boot-time waits for an unsolicited event also released the queue mutex between reads, so a command sent from another thread could consume the event and leave the waiter to time out. Compute one deadline when the wait begins and pass the time remaining to each read, and hold the queue mutex across the whole wait. Put the loop in one helper that the command reply wait and both boot-time event waits share. Assisted-by: LLM Signed-off-by: John Hubbard --- drivers/gpu/nova-core/gsp/cmdq.rs | 72 ++++++++++++++++++++------ drivers/gpu/nova-core/gsp/commands.rs | 8 +-- drivers/gpu/nova-core/gsp/sequencer.rs | 8 +-- 3 files changed, 59 insertions(+), 29 deletions(-) diff --git a/drivers/gpu/nova-core/gsp/cmdq.rs b/drivers/gpu/nova-core/gsp/= cmdq.rs index ad2a14d08cb0..ae3808de44e2 100644 --- a/drivers/gpu/nova-core/gsp/cmdq.rs +++ b/drivers/gpu/nova-core/gsp/cmdq.rs @@ -28,7 +28,11 @@ }, Mutex, // }, - time::Delta, + time::{ + Delta, + Instant, + Monotonic, // + }, transmute::{ AsBytes, FromBytes, // @@ -130,7 +134,9 @@ fn size(&self) -> usize { =20 /// Trait representing messages received from the GSP. /// -/// This trait tells [`Cmdq::receive_msg`] how it can receive a given type= of message. +/// A reply that [`Cmdq::send_command`] waits for, or an event that [`Cmdq= ::await_msg`] waits for. +/// The receiver matches a message's function code against [`Self::FUNCTIO= N`] and decodes the +/// message with [`Self::read`]. pub(crate) trait MessageFromGsp: Sized { /// Function identifying this message from the GSP. const FUNCTION: MsgFunction; @@ -566,8 +572,9 @@ fn notify_gsp(bar: Bar0<'_>) { /// /// # Errors /// - /// - `ETIMEDOUT` if space does not become available to send the comma= nd, or if the reply is - /// not received within the timeout. + /// - `ETIMEDOUT` if space does not become available to send the comma= nd, or if the reply does + /// not arrive within [`Self::RECEIVE_TIMEOUT`] of the send, however= many events arrive + /// while waiting. /// - `EIO` if the variable payload requested by the command has not b= een entirely /// written to by its [`CommandToGsp::init_variable_payload`] method. /// @@ -582,13 +589,7 @@ pub(crate) fn send_command(&self, command: M) -> Re= sult let mut inner =3D self.inner.lock(); inner.send_command(command)?; =20 - loop { - match inner.receive_msg::(Self::RECEIVE_TIMEOUT) { - Ok(reply) =3D> break Ok(reply), - Err(ENOMSG) =3D> continue, - Err(e) =3D> break Err(e), - } - } + inner.await_msg() } =20 /// Sends `command` to the GSP without waiting for a reply. @@ -608,15 +609,25 @@ pub(crate) fn send_command_no_wait(&self, command:= M) -> Result self.inner.lock().send_command(command) } =20 - /// Receive a message from the GSP. + /// Waits for an unsolicited GSP event of type `M`. Events that arrive= before it are logged and + /// consumed. + /// + /// The queue mutex is held for the whole wait, up to [`Self::RECEIVE_= TIMEOUT`], so no other + /// caller can send a command or consume an event meanwhile. /// - /// See [`CmdqInner::receive_msg`] for details. - pub(crate) fn receive_msg(&self, timeout: Delta) ->= Result + /// # Errors + /// + /// - `ETIMEDOUT` if the event does not arrive within [`Self::RECEIVE_= TIMEOUT`] of the call, + /// however many other events arrive while waiting. + /// - `EIO` if a message fails framing or checksum validation. + /// + /// Error codes returned by [`MessageFromGsp::read`] are propagated as= -is. + pub(crate) fn await_msg(&self) -> Result where // This allows all error types, including `Infallible`, to be used= for `M::InitError`. Error: From, { - self.inner.lock().receive_msg(timeout) + self.inner.lock().await_msg() } } =20 @@ -870,6 +881,37 @@ fn receive_msg(&mut self, timeout: = Delta) -> Result result } =20 + /// Receives a message of type `M`, waiting up to [`Cmdq::RECEIVE_TIME= OUT`] from the call. + /// + /// Any other message that arrives first is logged as an event and doe= s not extend the + /// deadline. + /// + /// # Errors + /// + /// - `ETIMEDOUT` if no message of type `M` arrives before the deadlin= e, however many other + /// messages arrive while waiting. + /// - `EIO` if a message fails framing or checksum validation (see [`S= elf::wait_for_msg`]). + /// + /// Error codes returned by [`MessageFromGsp::read`] are propagated as= -is. + fn await_msg(&mut self) -> Result + where + // This allows all error types, including `Infallible`, to be used= for `M::InitError`. + Error: From, + { + let deadline =3D Instant::::now() + Cmdq::RECEIVE_TIMEO= UT; + loop { + let remaining =3D deadline - Instant::::now(); + if remaining.is_negative() { + break Err(ETIMEDOUT); + } + match self.receive_msg::(remaining) { + Ok(msg) =3D> break Ok(msg), + Err(ENOMSG) =3D> continue, + Err(e) =3D> break Err(e), + } + } + } + /// Logs an event, meaning a message that no caller was waiting for. /// /// An OS error or robust-channel record is logged at error level and = an unknown function code diff --git a/drivers/gpu/nova-core/gsp/commands.rs b/drivers/gpu/nova-core/= gsp/commands.rs index 0c787fd689bf..cdbb13674f08 100644 --- a/drivers/gpu/nova-core/gsp/commands.rs +++ b/drivers/gpu/nova-core/gsp/commands.rs @@ -188,13 +188,7 @@ fn read( =20 /// Waits for GSP initialization to complete. pub(crate) fn wait_gsp_init_done(cmdq: &Cmdq<'_>) -> Result { - loop { - match cmdq.receive_msg::(Cmdq::RECEIVE_TIMEOUT) { - Ok(_) =3D> break Ok(()), - Err(ENOMSG) =3D> continue, - Err(e) =3D> break Err(e), - } - } + cmdq.await_msg::().map(|_| ()) } =20 /// The `GetGspStaticInfo` command. diff --git a/drivers/gpu/nova-core/gsp/sequencer.rs b/drivers/gpu/nova-core= /gsp/sequencer.rs index 1782ed7d7ca6..250adc9fe74f 100644 --- a/drivers/gpu/nova-core/gsp/sequencer.rs +++ b/drivers/gpu/nova-core/gsp/sequencer.rs @@ -343,13 +343,7 @@ pub(crate) fn run( libos: &'a Coherent<'a, [LibosMemoryRegionInitArgument]>, bootloader_app_version: u32, ) -> Result { - let seq_info =3D loop { - match cmdq.receive_msg::(Cmdq::RECEIVE_TIMEOUT) { - Ok(seq_info) =3D> break seq_info, - Err(ENOMSG) =3D> continue, - Err(e) =3D> return Err(e), - } - }; + let seq_info =3D cmdq.await_msg::()?; =20 let sequencer =3D GspSequencer { bar: ctx.bar, --=20 2.55.0 From nobody Wed Sep 30 15:28:46 2026 Received: from BN8PR05CU002.outbound.protection.outlook.com (mail-eastus2azon11011063.outbound.protection.outlook.com [52.101.57.63]) (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 04BC636CDF2 for ; Wed, 30 Sep 2026 03:43:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.57.63 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790739799; cv=fail; b=iXgPfEFRhMTFe0zW5ujo+dN/VX56u9iParEeRmDPu8bAPDhrPc726wCahrZ0zNpaMeb8LZNW4Ilt4i0hgcAtBOqEqlhz8dRpJowWvJ3TBd6itPBDSDTkrS9uDCg4B9+ds0tSiukwsFhJzipBIQ4XMctMASRInAp+ztaP7GWBe5E= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790739799; c=relaxed/simple; bh=s/0ir5YCC5445AekmDKR7H/2GdsTRWKEzn7cck/3l3Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=UiAFg53iReJV7pcMEt+mc19o8PItBiNBNfJn91gtXGpsu2O6IYeTotOe2sZtHWY396LZ+25v+de9MWQ9zM41JUMuF7q4ym6mvvfpyj+DCdchpN3fwpReDhMxVQ6+8hs5PEZqa2JPm4NxGsB+K1wmRgx0UrCD5Gfni3QponeznzQ= 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=Wnw/3SBn; arc=fail smtp.client-ip=52.101.57.63 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="Wnw/3SBn" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=HVzOi1BKm2CQeMoYrT6fJy5964ozljOtCPbCPibawuv8hlhvUMq1CqlW2hRbdWhZoqyX37XyMlBCemA6E3wqyo9wiv9CeOSD4HlNEpgSM0aV/RTaZqxmOcp74zTp6oaxGFR/9JTKNLjFNeuqZGYdoO7ILFuPIcr5hKCJ48L/XtX+8qyBkgeGGaf1vW7rADTqh/zbKGUY2Ne2k4ArZCYinfdWOFSlK2RBaWNBdVCYbCgzdIfemUI92iA7rbzpkGNWl+mvYGgG+6IPH5C87B30+I6biSDF3DCa93+62Jle+M3SQYNVyPGNCgRIf4J2qwM3XGckAj7xtN3ZSssYnBRvQA== 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=bdm8xPtbHBIfDQSbbb3uBhqdGZ8cYBEgozG1rALy5no=; b=Cy4ofpdY6qyc2jWJ4bVDbahPeBVuWC/qYYALOaz6pEPqkVNUZG9SU5wm2qkzs77oN/qYTfVEE/o0ffRC22iFwz4rzOX2c3FhNTaBfM35wgBhNw/YKmKVOX+ivfkYXDyIzqdXE4g+uPy2+NfPOADmMf6P928Pj5gsmmw5LjyuWdJw9xUg+/A7Scd+ssuc5diIrPTCWwqVX00KN2RqSN+9+jKLm1vv9DCgDZi6N7Tch/JysmKLWGXSWVG7NiwuX7QIvLGsR7O/G1VgbwKN9Kmx4SmRQJRVlhEnRuNPg0RU8NJPXVMBBF8Kf5KUdB/ozL0gXbjOHhaNjz9npNTSs2yHcA== 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=bdm8xPtbHBIfDQSbbb3uBhqdGZ8cYBEgozG1rALy5no=; b=Wnw/3SBny1CXr3YvQATc1fbQpg7keWbIotlD1H+kdhFDHu02a+khWw6PGZeFL1LXM2cypOJIEHC8Pc8KBZCv/zNqFH0x6SGQiZoJ5Nbw0GJXgBnnu9q5buteQtd/Y3VuwkW9AUCeTLao2LvbdOezTSU9HGBw4O8c3UpEDqzaOyFQkvCgvOmmhU28rBhKZITx1TMu5QQh6FN3aiYm3+Em+2RdZig2CSE4NORlA+kT+P+sORHrMbGEQd6NwezZ9uA4v9J82NjH8HnwP9cntKZcXy8r/SrbdS5VW2A/imso++L3Ct2oA555TWW3L+pgB01fM+pEMlQmmsQIPaw4p1j2tA== Authentication-Results: mx.microsoft.com 1; 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 MN0PR12MB6248.namprd12.prod.outlook.com (2603:10b6:208:3c0::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.451.26; Wed, 30 Sep 2026 03:42:25 +0000 Received: from DM3PR12MB9416.namprd12.prod.outlook.com ([fe80::8cdd:504c:7d2a:59c8]) by DM3PR12MB9416.namprd12.prod.outlook.com ([fe80::8cdd:504c:7d2a:59c8%4]) with mapi id 15.21.0451.024; Wed, 30 Sep 2026 03:42:25 +0000 From: John Hubbard To: Danilo Krummrich , Alexandre Courbot Cc: Timur Tabi , Alistair Popple , Eliot Courtney , 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 , nova-gpu@lists.linux.dev, LKML , John Hubbard Subject: [PATCH v5 12/15] gpu: nova-core: add the falcon interrupt registers and HAL methods Date: Tue, 29 Sep 2026 20:41:45 -0700 Message-ID: <20260930034148.590687-13-jhubbard@nvidia.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260930034148.590687-1-jhubbard@nvidia.com> References: <20260930034148.590687-1-jhubbard@nvidia.com> X-NVConfidentiality: public Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: PH8P220CA0006.NAMP220.PROD.OUTLOOK.COM (2603:10b6:510:345::7) To DM3PR12MB9416.namprd12.prod.outlook.com (2603:10b6:0:4b::8) 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: DM3PR12MB9416:EE_|MN0PR12MB6248:EE_ X-MS-Office365-Filtering-Correlation-Id: bf752726-538c-42d6-b2c0-08df1ea4d7b4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|23010399003|366016|7416014|376014|10067099003|56012099006|5023799004|11063799006|6133799003|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: 5/ijn0QO0ebk4kImspB09dYbB+OvBBOTFp1CO85RaguNlB7u1lX6uVeqYMKvhx1BtMJ5sNUQiIsQb3wXeST9RytY9Zrf5+QMzjd/yo6aMxBw7KM43ydLw4NdVcMJwPA7QIH/H7WhlK7M/Q5jIC2LVksa50SwXnaCtJeZBIKq9n4r5pvgHwDwgKhB4lqrbIgTKk5GwAXNPQ+s05IjaMNRFjfcvhtt0GZb+dvCQwGvzjA2Mi+q8qoEfZzD14MnZGwpKuNskoxWx/ec6AzGI9HysY/HlTI93/3G5zV/SomOY69TAiCPXArAEwqwKqJbSWJvBTYDbcVzB0p8yHFq6KEoNXukz1GOWCdUQTjfuJJDjkm9nLCcpwqgwHosMlfWTZUc73BUkzf407Ze1U+woJGpoyvfxav2ra6UnPL+hYbI8TxRYXRacv7TWWmIcvpAGzmkJicTO2SPcM2Q8trYKjWY0TM0AWdz35bv7tVJQW5qHwJONbLGJMrfLew5wGHvk5TUEtu8Y0U18ZGh6iG5466+hDVVfRycFs8pX3eHI8344sTqXF5Dh/PZ4b/GeFRXVVxlM76NBu9oMbji1M8VEQ6w9lnrYosjiENC8Fo5oPbiQVL41MLLRqownzeRpUFKZvAky1cHXv2yfFHqkr4eLh5UsA== 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)(1800799024)(23010399003)(366016)(7416014)(376014)(10067099003)(56012099006)(5023799004)(11063799006)(6133799003)(18002099003)(22082099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?1CRQtP5qG9httochWdn+KypqKFSC18XrOMIJtTHptfgpaAYxgS3uiaQ/D/de?= =?us-ascii?Q?lDAg6zSDKxjlyyn52ok2h1Gg1X4ZOY1bVMXOe77N2vIlzrRsbo58ESb29vbP?= =?us-ascii?Q?goTfq+RKhpp9SXpdjJaSnfwkgPm6c6Xo74spGLsn8JK6JqaAaTGAKqpw+Lih?= =?us-ascii?Q?MUJR2TP1cjxDtVxl24R6eulYeAHYrcPz9mimo1JMCCXTAT/oJUqKPCD0M2Ux?= =?us-ascii?Q?k6e6x8MahiIzjGxF8p4CjfYNf/WhaaLwRmBwWnl+RNxviR510hR6VN4jEpBj?= =?us-ascii?Q?i+RvTWhWvW2Dkt/QUOobuQQlxXonfCNYyvT/TVs3BZUMPwoij8x28lagr/eE?= =?us-ascii?Q?h1qQCeqSI6ea8m0TFks/piJS0l2W8xMNjDEvsl7dDASbrB9ai+gBqC3oi0KP?= =?us-ascii?Q?CLQSIpdes8l6gK9IsMufLQxQMU9NDMXDWRI4l/U+Fzq4NLoRseXMH9vfpYPA?= =?us-ascii?Q?8yTJH+oWu2WgM/pxtdz7m7wJ5ilc0zSaElxaEFHJ3gqHPnhwZ5J+rEe5hgfC?= =?us-ascii?Q?u55WeBIiG12BkblbVtwtndzcz2XdMsjmTQUrvtVcyjKvsgynoYp261UwE3dw?= =?us-ascii?Q?4a5oInqOTwBko9np5UUV+dHQthrNDY3ebDqFx0aAa1Ki/LgWBzzayC7ZHkOC?= =?us-ascii?Q?bJ2D1FiLjfpksdy3iA3VkFxXD+Jkh87ipCB0prgh3yQ/wQUBgfEgDcHJx03k?= =?us-ascii?Q?GbOCN/x+RGOBA0piHw19V3JRHVBZXWn4hM5WoW2rSGwTGQPi1vXAgWK/J1im?= =?us-ascii?Q?zxf79ckq3glyugcGQ/bjRYWfDn0HbBrLK/wUpP9gMP6RqdqhdQEy19p0QE+I?= =?us-ascii?Q?lN//x9WE8PQYDdTonQ9586WC4e0TGf42Y4ce6P0u988U/jXyM2Uc9zwNE0mG?= =?us-ascii?Q?+3Pt+EQGycikexPr0cjQH6vCA39SEc4AAMrIuUBxz4y0WbLBsVTPJftPvr13?= =?us-ascii?Q?grGgen7mtWPnLnBkFizLQqI+vdKbOROERMSW9ijPjgxjo3otb8cPOwijkcVe?= =?us-ascii?Q?dbPmkV6xee68Hy12zJOim06zSKizIw8kfYR9hu1/zi3EvZHjnrg8OBVL6SEB?= =?us-ascii?Q?Mj32LNjXhaJf7E0a1gdDX5J4rABP5QNpgyRcYK9r9YIwoLsNS37MOq4zid8R?= =?us-ascii?Q?0mVHsjLu7FH98R59jmjjKjsl/sfHIfDH0xCUWXjE9QWl49V45gd8mXg4csTG?= =?us-ascii?Q?ee4DovHJw8jrtJ77j+8cIoHadKMgJD6qHWXQkX1XKSXqcXmKAQE6MlONjzA0?= =?us-ascii?Q?203WlhcNF/sTcJ+NrsSEiCkvkYFQRUf3xtvA4vfm7l+I5lo462mOibSO46WG?= =?us-ascii?Q?uLCWgBFxVlNloDDYqpSdIPppVK+lZJ4gE/KsbBvvGPn+VSEcAPftV9WLNx9U?= =?us-ascii?Q?iGGqCTH6UkWwS+y3nnPmSVsg6YireTEASqEl3NJRkMgPVZwDAwmulLtUj0+P?= =?us-ascii?Q?g6P32aNpLSXvu6c9xfF2q5YawbCC3TkYvMsfSVCUKsIW0TcWquR866qYqRqQ?= =?us-ascii?Q?z4ANC9DdDMkHYPkt05V+DufM5X2S6WR9YSGHmiWeIEFTco0/X7hLXaVdKImn?= =?us-ascii?Q?Hm5nMoX5tndmCwEp9wkp9uOI8i2obNgl6n5B5lRjuwscGFDJEWWR7hS4iIKM?= =?us-ascii?Q?316X+fLzaWHN3ojl2g15E6j8oodqTsIttl9jjLv4hzXcBy1EwkXaDDfIcaCZ?= =?us-ascii?Q?GUFXJegK0NtUwNJ7O0N9ktRljto0Tb0fe7X8d4jjV9e/HmBQYLEkZ4qnwP5b?= =?us-ascii?Q?AYtnpVFPEQ=3D=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: bf752726-538c-42d6-b2c0-08df1ea4d7b4 X-MS-Exchange-CrossTenant-AuthSource: DM3PR12MB9416.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2026 03:42:25.3595 (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: hRumqMr3ncFvIWcpqa92frNN8wwjhffItKgQElW3/9XxWoixwn9eEzdGRwb1JvKJqUx3GRfB857aZuJTNNAviQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6248 Content-Type: text/plain; charset="utf-8" A falcon latches each interrupt cause that is raised in its IRQSTAT register. On a RISC-V falcon, each cause is routed either to the host, meaning the CPU, or to the falcon's own core, and two routing registers hold that routing. The falcon signals the interrupt tree only when its set of host-routed causes goes from empty to non-empty, so a handler that clears the tree leaf while a cause is still latched has to write INTR_RETRIGGER, which makes the falcon re-emit its causes. Turing falcons have no INTR_RETRIGGER, and the routing registers have different offsets from GA102 on. Add IRQSTAT, INTR_RETRIGGER, and the two routing registers, the last at both sets of offsets, and add two falcon HAL methods: one intersects an IRQSTAT value with the routing registers, and one retriggers the falcon, or does nothing on Turing. GA100 keeps the Turing HAL, as it does for boot, and the retrigger register is a property of that HAL's instance. The two methods have no user yet. Assisted-by: LLM Signed-off-by: John Hubbard --- drivers/gpu/nova-core/falcon/hal.rs | 21 ++++++- drivers/gpu/nova-core/falcon/hal/ga102.rs | 16 ++++++ drivers/gpu/nova-core/falcon/hal/tu102.rs | 51 ++++++++++++++++- drivers/gpu/nova-core/regs.rs | 69 +++++++++++++++++++++++ 4 files changed, 154 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/nova-core/falcon/hal.rs b/drivers/gpu/nova-core/fa= lcon/hal.rs index 7e532889a1f4..2f02da52334e 100644 --- a/drivers/gpu/nova-core/falcon/hal.rs +++ b/drivers/gpu/nova-core/falcon/hal.rs @@ -12,6 +12,7 @@ Architecture, Chipset, // }, + regs, }; =20 mod ga102; @@ -70,6 +71,24 @@ fn signature_reg_fuse_version( /// these. For anything above, the PIO registers appear to be masked t= o the CPU, so DMA is the /// only usable method. fn load_method(&self) -> LoadMethod; + + /// Returns the causes in `latched` that are routed to the host, meani= ng the CPU, rather than + /// to the falcon's own RISC-V core. + /// + /// The causes routed to the core belong to the firmware running on it= , and the host does not + /// service them. + #[expect(dead_code)] + fn host_routed_causes( + &self, + falcon: &Falcon<'_, E>, + latched: regs::NV_PFALCON_FALCON_IRQSTAT, + ) -> regs::NV_PFALCON_FALCON_IRQSTAT; + + /// Retriggers the falcon, which then re-emits its host-routed causes = into the interrupt tree. + /// + /// Turing falcons have no retrigger register, so on Turing this does = nothing. + #[expect(dead_code)] + fn retrigger(&self, falcon: &Falcon<'_, E>); } =20 /// Returns a boxed falcon HAL adequate for `chipset`. @@ -86,7 +105,7 @@ pub(super) fn falcon_hal( } // GA100 boots like Turing so use Turing HAL Architecture::Ampere if chipset =3D=3D Chipset::GA100 =3D> { - KBox::new(tu102::Tu102::::new(), GFP_KERNEL)? as KBox> + KBox::new(tu102::Tu102::::ga100(), GFP_KERNEL)? as KBox> } Architecture::Ampere | Architecture::Ada diff --git a/drivers/gpu/nova-core/falcon/hal/ga102.rs b/drivers/gpu/nova-c= ore/falcon/hal/ga102.rs index f9a8444cf840..b0eb1901d213 100644 --- a/drivers/gpu/nova-core/falcon/hal/ga102.rs +++ b/drivers/gpu/nova-core/falcon/hal/ga102.rs @@ -169,4 +169,20 @@ fn reset_eng(&self, falcon: &Falcon<'_, E>) -> Result { fn load_method(&self) -> LoadMethod { LoadMethod::Dma } + + fn host_routed_causes( + &self, + falcon: &Falcon<'_, E>, + latched: regs::NV_PFALCON_FALCON_IRQSTAT, + ) -> regs::NV_PFALCON_FALCON_IRQSTAT { + let pfalcon2 =3D falcon.pfalcon2; + let mask =3D pfalcon2.read(regs::ga102::NV_PRISCV_RISCV_IRQMASK).v= alue(); + let dest =3D pfalcon2.read(regs::ga102::NV_PRISCV_RISCV_IRQDEST).v= alue(); + + regs::NV_PFALCON_FALCON_IRQSTAT::from(latched.into_raw() & mask & = dest) + } + + fn retrigger(&self, falcon: &Falcon<'_, E>) { + super::tu102::retrigger_ga100(falcon); + } } diff --git a/drivers/gpu/nova-core/falcon/hal/tu102.rs b/drivers/gpu/nova-c= ore/falcon/hal/tu102.rs index 7fc6e83c2566..bd66b7759ea6 100644 --- a/drivers/gpu/nova-core/falcon/hal/tu102.rs +++ b/drivers/gpu/nova-core/falcon/hal/tu102.rs @@ -5,6 +5,7 @@ use kernel::{ io::{ poll::read_poll_timeout, + register::Array, Io, // }, prelude::*, @@ -23,14 +24,42 @@ =20 use super::FalconHal; =20 -pub(super) struct Tu102(PhantomData); +/// The falcon HAL for Turing and GA100. GA100 boots like a Turing, but un= like Turing, it has a +/// retrigger register. +pub(super) struct Tu102 { + /// If `true`, the falcons have `NV_PFALCON_FALCON_INTR_RETRIGGER`. + #[expect(dead_code)] + has_intr_retrigger: bool, + _engine: PhantomData, +} =20 impl Tu102 { + /// Returns the HAL of Turing falcons. pub(super) fn new() -> Self { - Self(PhantomData) + Self { + has_intr_retrigger: false, + _engine: PhantomData, + } + } + + /// Returns the HAL of GA100 falcons: the Turing HAL, with the retrigg= er register. + pub(super) fn ga100() -> Self { + Self { + has_intr_retrigger: true, + _engine: PhantomData, + } } } =20 +/// Writes `NV_PFALCON_FALCON_INTR_RETRIGGER`. +#[expect(dead_code)] +pub(super) fn retrigger_ga100(falcon: &Falcon<'_, E>) { + falcon.pfalcon.write( + Array::at(0), + regs::NV_PFALCON_FALCON_INTR_RETRIGGER::zeroed().with_trigger(true= ), + ); +} + impl FalconHal for Tu102 { fn select_core(&self, _falcon: &Falcon<'_, E>) -> Result { Ok(()) @@ -79,4 +108,22 @@ fn reset_eng(&self, falcon: &Falcon<'_, E>) -> Result { fn load_method(&self) -> LoadMethod { LoadMethod::Pio } + + fn host_routed_causes( + &self, + falcon: &Falcon<'_, E>, + latched: regs::NV_PFALCON_FALCON_IRQSTAT, + ) -> regs::NV_PFALCON_FALCON_IRQSTAT { + let pfalcon2 =3D falcon.pfalcon2; + let mask =3D pfalcon2.read(regs::tu102::NV_PRISCV_RISCV_IRQMASK).v= alue(); + let dest =3D pfalcon2.read(regs::tu102::NV_PRISCV_RISCV_IRQDEST).v= alue(); + + regs::NV_PFALCON_FALCON_IRQSTAT::from(latched.into_raw() & mask & = dest) + } + + fn retrigger(&self, falcon: &Falcon<'_, E>) { + if self.has_intr_retrigger { + retrigger_ga100(falcon); + } + } } diff --git a/drivers/gpu/nova-core/regs.rs b/drivers/gpu/nova-core/regs.rs index 9978fb2803b0..88662da634dc 100644 --- a/drivers/gpu/nova-core/regs.rs +++ b/drivers/gpu/nova-core/regs.rs @@ -124,11 +124,25 @@ pub(crate) fn usable_fb_size(self) -> u64 { register! { base: PFalconRegisters; =20 + /// Clears the latch of every cause whose bit is written as `1`. Write= -only. + /// + /// The write ends the latch and not the source, so a cause driven fro= m outside the falcon + /// stays set. "Retriggering a falcon" in `Documentation/gpu/nova/core= /interrupts.rst` names + /// those causes. pub(crate) NV_PFALCON_FALCON_IRQSCLR(u32) @ 0x00000004 { 6:6 swgen0 =3D> bool; 4:4 halt =3D> bool; } =20 + /// Interrupt causes latched in the falcon, one bit per cause, whichev= er target each is routed + /// to. + /// + /// The causes routed to the host are the ones also set in `NV_PRISCV_= RISCV_IRQMASK` and + /// `NV_PRISCV_RISCV_IRQDEST`. + pub(crate) NV_PFALCON_FALCON_IRQSTAT(u32) @ 0x00000008 { + 6:6 swgen0 =3D> bool; + } + pub(crate) NV_PFALCON_FALCON_MAILBOX0(u32) @ 0x00000040 { 31:0 value =3D> u32; } @@ -256,6 +270,16 @@ pub(crate) fn usable_fb_size(self) -> u64 { 0:0 reset =3D> bool; } =20 + /// Makes the falcon re-emit its host-routed causes into the interrupt= tree. Write-only. + /// + /// Present from GA100 on. See "Retriggering a falcon" in + /// `Documentation/gpu/nova/core/interrupts.rst`. + /// + /// The hardware headers declare two elements, and OpenRM writes only = the first. + pub(crate) NV_PFALCON_FALCON_INTR_RETRIGGER(u32)[2] @ 0x000003e8 { + 0:0 trigger =3D> bool; + } + pub(crate) NV_PFALCON_FBIF_TRANSCFG(u32)[8] @ 0x00000600 { 2:2 mem_type =3D> FalconFbifMemType; 1:0 target ?=3D> FalconFbifTarget; @@ -414,6 +438,29 @@ pub(crate) mod gm107 { } } =20 +pub(crate) mod tu102 { + use kernel::io::register; + + use crate::falcon::PFalcon2Registers; + + // The RISC-V interrupt routing registers, at the offsets that Turing = and GA100 use. + + register! { + base: PFalcon2Registers; + + /// Enabled causes, one bit per cause. Read-only to the host. + pub(crate) NV_PRISCV_RISCV_IRQMASK(u32) @ 0x000002b4 { + 31:0 value =3D> u32; + } + + /// Causes routed to the host, one bit per cause. A clear bit rout= es the cause to the + /// RISC-V core. + pub(crate) NV_PRISCV_RISCV_IRQDEST(u32) @ 0x000002b8 { + 31:0 value =3D> u32; + } + } +} + pub(crate) mod ga100 { use kernel::io::register; =20 @@ -430,6 +477,28 @@ pub(crate) mod ga100 { } } =20 +pub(crate) mod ga102 { + use kernel::io::register; + + use crate::falcon::PFalcon2Registers; + + // The RISC-V interrupt routing registers, at the offsets that GA102 a= nd later use. + + register! { + base: PFalcon2Registers; + + /// Same as [`super::tu102::NV_PRISCV_RISCV_IRQMASK`], at the GA10= 2 offset. + pub(crate) NV_PRISCV_RISCV_IRQMASK(u32) @ 0x00000528 { + 31:0 value =3D> u32; + } + + /// Same as [`super::tu102::NV_PRISCV_RISCV_IRQDEST`], at the GA10= 2 offset. + pub(crate) NV_PRISCV_RISCV_IRQDEST(u32) @ 0x0000052c { + 31:0 value =3D> u32; + } + } +} + pub(crate) const NV_THERM_I2CS_SCRATCH_FSP_BOOT_COMPLETE_STATUS_SUCCESS: u= 32 =3D 0xff; =20 pub(crate) mod gh100 { --=20 2.55.0 From nobody Wed Sep 30 15:28:46 2026 Received: from CH1PR05CU001.outbound.protection.outlook.com (mail-northcentralusazon11010011.outbound.protection.outlook.com [52.101.193.11]) (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 EA7B4221FB6 for ; Wed, 30 Sep 2026 03:43:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.193.11 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790739805; cv=fail; b=ll3ggDlQywHaRTZ41xRjDTAuiFe16Qnb1SJOMFhgwgTQiFl8pqIRlnIuWTCwKwm7YzMntaCMkMMY3j+h42tkp0gjJTjHu6MJLS3e1uFD1yVaW9gHlLI4atEnNST36jWMNp0jYGa8S39b8EPhsxk6PBdi5SIGw0OQXDv35lbUdV8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790739805; c=relaxed/simple; bh=NmqoAzNSjQUC017ASwQ2K9aU/m98/3WCsXGFWbaqMsE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=ES1SFvknCWTPW2XjpkGkQ28Tip6Ay7wNyomE6Xlf8KuG1MA4M0wFh0nLn/pvGCL70Dz7RJATKgDvbzZdIIZb5ay+fFIYexzQ1BVH5KaWyhy6FLa60oEHUUkYn9f76jXQ0+WD18/mAU64nnePdwkHUIPQJ2l4Ps+en0/Or5pvRXI= 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=cZFpwC8A; arc=fail smtp.client-ip=52.101.193.11 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="cZFpwC8A" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Tny98AZKgTxwoNvtbQtoksPbYK74Rw2C3mkZn3pccbjT3hsDh3YefVvq/b7TSzVQN6VKl9IXMgWT1oFiv8ua1ij7bv1oKrk6m0smnEvWoIAw/k+6OxmtMXmJFVm/yMMPn4U7i4PLW/K+FZGyCC5G0XdJdR1JQQ9ndsP9VYrplFJoiFVJ57VAc++eLoL0s9gNrqf8mntPBCOGZozwNqErhAhIswTkDTMXaotJUjvZpJXZCjqjA+Vpdgu3MJaiyWccbdWFHK66d7q5m6akTwtFocQaNHTz2cQThSzqkhb/qUdPfoIz17ES5VW0RKxLUGDzi4ex27LrhNTWj6go6NecSA== 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=w0klTTmThqfnq1g1zv0tLNexSPgZha8ALAFLSHWh8aU=; b=SoW13k1UetpOuAR3wzOVWql0of25bi4GBhFXJN07ipIHMVrBkbccwQCROhNAFcqr8C3RZc6le7eH4//7PqtoeP3NnMn/QGCnPcF11bz5YfE1r0iOxmTO05jTDOWrRFB9OFDHjV2XSBayy0tvbkHpo2z+G2zOzFSy/BBW62V0Bn7F/hFIT2Lq3etL5jSXLwO+1yumsH0/bwxT0Se8f3LwSIsIST508xDmlm0/TLEHD8Xm+mZWUcFTzjHyyye/nAK03WKl9Hpb/eDkx6ebFKdohbtUoCXOT2fc+35DlYKstJ4c2CIyLmerTm9cD4+WJpPlicPdm6qz6wAm5YCMkaUOQg== 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=w0klTTmThqfnq1g1zv0tLNexSPgZha8ALAFLSHWh8aU=; b=cZFpwC8ADTaPMxIRyCJ9d1LWg8oQ2tQ4vRQzqVyo9hDhmAYO1YUk8I7gPusWwN7nZgPMy5TEjxM4c9N5d3kwwDW3vbVmhOhpXqEQCWlt6v+6t87WVrzTL3KiP/r5KIIFiO9e3biPmV6KPgZP5hHdQ+/iAC3XfmqKW5jFNH6jgiwepWLA7COvdhf33fOr6+bptTvhlmOjFtI6gMwI9/t7gpKgFhu5v/G+6eQlnKkdd9P5SrAp8Q8swSSKDGln80NK15RnQEcFtWztKGxQzXjE/J3tJe5EM47O2g2w34l1CjJ5msm9r+xfXfDpq5D51VGK9A6PD9K4zQqUGp2cSyG79g== Authentication-Results: mx.microsoft.com 1; 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 MN0PR12MB6248.namprd12.prod.outlook.com (2603:10b6:208:3c0::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.451.26; Wed, 30 Sep 2026 03:42:27 +0000 Received: from DM3PR12MB9416.namprd12.prod.outlook.com ([fe80::8cdd:504c:7d2a:59c8]) by DM3PR12MB9416.namprd12.prod.outlook.com ([fe80::8cdd:504c:7d2a:59c8%4]) with mapi id 15.21.0451.024; Wed, 30 Sep 2026 03:42:27 +0000 From: John Hubbard To: Danilo Krummrich , Alexandre Courbot Cc: Timur Tabi , Alistair Popple , Eliot Courtney , 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 , nova-gpu@lists.linux.dev, LKML , John Hubbard Subject: [PATCH v5 13/15] gpu: nova-core: service GSP events from the SWGEN0 interrupt Date: Tue, 29 Sep 2026 20:41:46 -0700 Message-ID: <20260930034148.590687-14-jhubbard@nvidia.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260930034148.590687-1-jhubbard@nvidia.com> References: <20260930034148.590687-1-jhubbard@nvidia.com> X-NVConfidentiality: public Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: PH8P221CA0066.NAMP221.PROD.OUTLOOK.COM (2603:10b6:510:349::6) To DM3PR12MB9416.namprd12.prod.outlook.com (2603:10b6:0:4b::8) 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: DM3PR12MB9416:EE_|MN0PR12MB6248:EE_ X-MS-Office365-Filtering-Correlation-Id: b8ae6b18-c916-4ddf-a672-08df1ea4d88a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|23010399003|366016|7416014|376014|10067099003|56012099006|5023799004|11063799006|6133799003|3023799007|7136999003|18002099003|22082099003|11062099010; X-Microsoft-Antispam-Message-Info: +3vx4ivud89NXt0O7D5QWAV5UWs0hs6mC1P+XF+cjYCuV4n6CKgkFL0n89uah4/2TwrBIYIZrxHGhOSxGfcazYdGnmxIK/G2HTVfv4Jgcb5ITYzHxGrULTr5H2bGKYNkl7fdENpdbPwy8mPHUoKbp22ll4LtWk3mKRRoPbpwicRcmQuNxQ4mF9T/zo2t7rCAnPqFcIUO0bgp4UFGT8fWhHYjL/LzN9ZiP5F5G0M3rEEKtLZMLM3ze6toXuayAtDLUM0ewdOx5ft/Gs/W4PZSoE31ZLoEaK+tdhqz6t0sytbUhOm1ZNZF510UV96NhOiq97/T1z1jfTswsbw+stKjT1GHTw6WIU6qFEdXK6up1OGni8sxUT2HG5yrHBUjZaqk7D9OIp8YrXFGBbeT4zIwt+J8skMpKG3xr/6gahCGBwnQI4EbT094IbWNkf3hTKo5a5sYxmuW7m2dvxHrIl3erG7hjCEGl80p+Vb/bBRcuudO9mtADEMIz/BiFhE20EaWHSfYn6cA4bvmTo/sdDk8kYy5Pp2m8mJz0QzSPoTRFHBIn0GXYAxtbdUqAUam6+owwPNIMBuCRl33YB+4uii7A2VbYyHIZic0QCPO+R6G2BdeWoB7fLn4t+Qv/nlUeGTI67DAWwU6xNqEzA2gKotEo2RI6sf33DmNzGefWIBwyBA= 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)(1800799024)(23010399003)(366016)(7416014)(376014)(10067099003)(56012099006)(5023799004)(11063799006)(6133799003)(3023799007)(7136999003)(18002099003)(22082099003)(11062099010);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?ggQpyb1g0+9V+lfF151t4nUHPQMIjgFgrrLjZL4fwbKZDBeEwJBTgn7zjO3G?= =?us-ascii?Q?63JDM6G2S9G6vKBuTHnJEQ+yo1IkmWxQAmqJ6wVXUHnPf6RrwK4XbEWBxUyg?= =?us-ascii?Q?PGhY5ShOqYGTIvk8NBeb34j5d+6TtFHngOFi6tiVS+vZ4cK2/GdEPkXRuyrk?= =?us-ascii?Q?QwTH/IWw5M5Z7smQa7Ebez8kZ1OZccvRNPZ25+ugrjBkrOXf+8pbcrcZKY6p?= =?us-ascii?Q?Ya5sXUWp8XbVuLvwgLUv8+PWqGHhGX4X3FmhfEkgvtAtyj94wWrfTJ0xb0Tx?= =?us-ascii?Q?se9sCUDgBy7/uraRvBSeHX2g2DkbmtLXEOvdK2pKpYsp04+cVtzkDL15Idw9?= =?us-ascii?Q?0HvOktfnuBp2G3u0RacsddoAmda8u4zq1uJ8G0OA2LOAD1wSMruUnY1ErVcD?= =?us-ascii?Q?CteEUwDWL3SOOL4GhQMnjQqW9sfIdvfTv5SN6IM+odoxVMQTB0SuG8PssB7s?= =?us-ascii?Q?u02D6ZKjMy+yT16Bpz5204XHbOcEw4/usNPTbaxMOZZ7fHXQ+jWyiLwGMop4?= =?us-ascii?Q?Lwm+8mGdrOe07Mr23XLNt+oidd+Ukh3jUk10p8NMpYr1U151WrAeO/aSIbv/?= =?us-ascii?Q?1HCL2GVRBMgLB5G0hgunPn7MRxd1K354BLK0aoxXIadeoH3VnD4nd9HGnjSj?= =?us-ascii?Q?4WWBc6xZFLbFq9fJGhiBZwqdvVmRqwMucg1szGO8WiR3Z7DDamLVFUHRLsDS?= =?us-ascii?Q?3+C5gLLkDsqSqbJf3g0E6r/vuckiyKX8MhDKFjqHcGV9KHKkkowQ2uulyMeI?= =?us-ascii?Q?U/NE4Y24pv3AV8uO905s2pwWEruWA3if880oA/zR4F5I9VwEJgsTVG7yDstp?= =?us-ascii?Q?QBBzaGQC8rqreYcf+7HxXcggKkHwIsTTHktsaFG0M044IrJoVJQDzW+rHZru?= =?us-ascii?Q?lCNiJq7OekJgk2S2icevE4+8/mJFqrHuB/13Ep4D4sIdal5Nqhhy2h+kWuUM?= =?us-ascii?Q?p6iD7/0XYuU4eDdF4B6gUyfx0IwPRsDFwfQgLalPD+Fee5aT9dN9SFkkNE0f?= =?us-ascii?Q?zZvbKBYIR4QMA5VOpEydDM1haZlHJbfOKkFjjm+mIPKWjcDtwQ32hqCX6PiI?= =?us-ascii?Q?xxV6TWRZpNe0Lt18eI/Lb2y9IjKk5xoAMr4/xpy2b9VCsek615HjO+mVMJ7/?= =?us-ascii?Q?M3HZ5I1bp3bRcm5D5IhuB/dTweX32JkkEVQIUMFtQw4X2eRp+/oii+uAJuE5?= =?us-ascii?Q?ItYu3tVlKDFiN6D2ng9+lQJDyc/fXTY3IK8TmbUuZGDq3ci/9xvzyAuZgjAA?= =?us-ascii?Q?+ZMFyZsU/nn5VkW+YiHefGaQb6S25uw5PwIkBhJjqwU0Oc/DVe0JhkXzAcS1?= =?us-ascii?Q?3bQ2GatJduDL6gNjKrpPj+HU6SC3CDsB8o8Dke0CUCr036wD2HxC+TMmmeol?= =?us-ascii?Q?GTCnHaH9B+3L2FDT4C4G6x+KK2KiHJXMH3me0k6asRl6f42kM0XNyZesinTv?= =?us-ascii?Q?2iKCxIlb0DL8ww+FEkaydZ9uL02yF+aPmw/wDDvb8hH6i/x6E6EipxJx23fX?= =?us-ascii?Q?ad9HirXE6FcDh10ysP/JukeBL4TuCZVl1JU0NMDFcOhj8rKbyLwRMmE3kt4r?= =?us-ascii?Q?TMiSpz9ZPFVEJ4//aexli4LXT2kLf5AVJd/tLZt/dPJu/gFOKTtgQhOFAoJi?= =?us-ascii?Q?NLxtd5s6D/wZe992Ee3Qpnk66r42oY11uh6jLGKNBfGNmGc1Avb6f5HzW0g4?= =?us-ascii?Q?dAG4O8PD6e64in6cf0fAC4xPhO0BYlarZVX6/K/+s4sOFczJXFZ68H14ba8t?= =?us-ascii?Q?uk81vQ8YHg=3D=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: b8ae6b18-c916-4ddf-a672-08df1ea4d88a X-MS-Exchange-CrossTenant-AuthSource: DM3PR12MB9416.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2026 03:42:26.8035 (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: s4tjzL8ueeuGShgaWT55n/u7EU4PCjPBlZwc51teUQqTJoMzVe8dPzVEc+MoQlfaULV936QcUhHriCsxAU0WNA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6248 Content-Type: text/plain; charset="utf-8" The GSP posts each message for the CPU to the GSP-to-CPU queue and then raises SWGEN0, a software-generated interrupt cause of its falcon. GIN delivers SWGEN0 to the CPU on vector 155. A thread waiting for a command reply was the only reader of the queue, so an event posted between commands stayed unread until the next command was sent. Register a threaded handler on the GSP vector. Draining the queue takes the command-queue mutex, which can sleep, so the top half reads and writes only registers and wakes the IRQ thread to drain the queue. Every existing read of the queue asks for one message type and waits on a deadline, so add a drain that logs and consumes whatever the GSP has already posted and returns at once. When a falcon cause other than SWGEN0 stays set after its latch is cleared, as the Blackwell fault-containment and ECC causes do, disable the GSP vector rather than retrigger the falcon. A retrigger would re-emit the cause at once, and the CPU would take the same interrupt again and again. Assisted-by: LLM Signed-off-by: John Hubbard --- drivers/gpu/nova-core/falcon/gsp.rs | 47 ++++- drivers/gpu/nova-core/falcon/hal.rs | 2 - drivers/gpu/nova-core/falcon/hal/tu102.rs | 2 - drivers/gpu/nova-core/gpu.rs | 96 +++++++++- drivers/gpu/nova-core/gsp/cmdq.rs | 40 ++++ drivers/gpu/nova-core/irq.rs | 1 + drivers/gpu/nova-core/irq/gsp.rs | 196 ++++++++++++++++++++ drivers/gpu/nova-core/irq/interrupt_tree.rs | 3 + drivers/gpu/nova-core/nova_core.rs | 1 - 9 files changed, 375 insertions(+), 13 deletions(-) create mode 100644 drivers/gpu/nova-core/irq/gsp.rs diff --git a/drivers/gpu/nova-core/falcon/gsp.rs b/drivers/gpu/nova-core/fa= lcon/gsp.rs index 4c96ae325fda..1faefaede9fe 100644 --- a/drivers/gpu/nova-core/falcon/gsp.rs +++ b/drivers/gpu/nova-core/falcon/gsp.rs @@ -47,13 +47,56 @@ fn pfalcon2(io: Bar0<'_>) -> Mmio<'_, super::PFalcon2Re= gisters> { } =20 impl<'a> Falcon<'a, Gsp> { - /// Clears the SWGEN0 bit in the Falcon's IRQ status clear register to - /// allow GSP to signal CPU for processing new messages in message que= ue. + /// Clears the SWGEN0 latch in the GSP falcon. + /// + /// While the latch is set, no later message signals the tree, so a ca= ller that consumed a + /// notification by polling must clear it. pub(crate) fn clear_swgen0_intr(&self) { self.pfalcon .write_reg(regs::NV_PFALCON_FALCON_IRQSCLR::zeroed().with_swge= n0(true)); } =20 + /// Reads the GSP falcon causes that are routed to the host, without c= learing any latch. + /// + /// Every one of them other than SWGEN0 reports a GSP fault. + pub(crate) fn read_host_intr(&self) -> regs::NV_PFALCON_FALCON_IRQSTAT= { + let latched =3D self.pfalcon.read(regs::NV_PFALCON_FALCON_IRQSTAT); + + self.hal.host_routed_causes(self, latched) + } + + /// Reads the host-routed causes and clears the SWGEN0 latch if it was= set. + /// + /// Returns the causes as read, before the clear. No other latch chang= es. + pub(crate) fn take_host_intr(&self) -> regs::NV_PFALCON_FALCON_IRQSTAT= { + let status =3D self.read_host_intr(); + + if status.swgen0() { + self.clear_swgen0_intr(); + } + + status + } + + /// Clears the latch of every interrupt cause set in `status`. + /// + /// A cause driven from outside the falcon is still set on return, and + /// [`Self::read_host_intr`] reports the causes that remain. + pub(crate) fn clear_intr(&self, status: regs::NV_PFALCON_FALCON_IRQSTA= T) { + self.pfalcon + .write_reg(regs::NV_PFALCON_FALCON_IRQSCLR::from(status.into_r= aw())); + } + + /// Retriggers the GSP falcon, which then re-emits its host-routed cau= ses into the tree. + /// + /// Call this only once every host cause is clear. A cause still set i= s re-emitted at once, and + /// its vector arrives again as soon as delivery is rearmed. + /// + /// Does nothing on Turing, whose falcons have no retrigger register. + pub(crate) fn retrigger_intr(&self) { + self.hal.retrigger(self); + } + /// Checks if GSP reload/resume has completed during the boot process. pub(crate) fn check_reload_completed(&self, timeout: Delta) -> Result<= bool> { read_poll_timeout( diff --git a/drivers/gpu/nova-core/falcon/hal.rs b/drivers/gpu/nova-core/fa= lcon/hal.rs index 2f02da52334e..2643a677caad 100644 --- a/drivers/gpu/nova-core/falcon/hal.rs +++ b/drivers/gpu/nova-core/falcon/hal.rs @@ -77,7 +77,6 @@ fn signature_reg_fuse_version( /// /// The causes routed to the core belong to the firmware running on it= , and the host does not /// service them. - #[expect(dead_code)] fn host_routed_causes( &self, falcon: &Falcon<'_, E>, @@ -87,7 +86,6 @@ fn host_routed_causes( /// Retriggers the falcon, which then re-emits its host-routed causes = into the interrupt tree. /// /// Turing falcons have no retrigger register, so on Turing this does = nothing. - #[expect(dead_code)] fn retrigger(&self, falcon: &Falcon<'_, E>); } =20 diff --git a/drivers/gpu/nova-core/falcon/hal/tu102.rs b/drivers/gpu/nova-c= ore/falcon/hal/tu102.rs index bd66b7759ea6..b25ac645a648 100644 --- a/drivers/gpu/nova-core/falcon/hal/tu102.rs +++ b/drivers/gpu/nova-core/falcon/hal/tu102.rs @@ -28,7 +28,6 @@ /// retrigger register. pub(super) struct Tu102 { /// If `true`, the falcons have `NV_PFALCON_FALCON_INTR_RETRIGGER`. - #[expect(dead_code)] has_intr_retrigger: bool, _engine: PhantomData, } @@ -52,7 +51,6 @@ pub(super) fn ga100() -> Self { } =20 /// Writes `NV_PFALCON_FALCON_INTR_RETRIGGER`. -#[expect(dead_code)] pub(super) fn retrigger_ga100(falcon: &Falcon<'_, E>) { falcon.pfalcon.write( Array::at(0), diff --git a/drivers/gpu/nova-core/gpu.rs b/drivers/gpu/nova-core/gpu.rs index 65715f906030..b042d68bec1e 100644 --- a/drivers/gpu/nova-core/gpu.rs +++ b/drivers/gpu/nova-core/gpu.rs @@ -34,10 +34,19 @@ fsp::Fsp, gsp::{ self, + cmdq::Cmdq, commands::GetGspStaticInfoReply, Gsp, GspBootContext, // }, + irq::{ + self, + gsp::GspIrq, + interrupt_tree::{ + TopEnableGuard, + Tree, // + }, // + }, mm::{ bar_user::BarUser, pagetable::MmuVersion, @@ -331,10 +340,53 @@ struct GspResources<'gpu> { unload_bundle: Option>, } =20 +/// The GSP event handler's registration and the enable of its subtree at = `TOP`. +/// +/// The two drop as a unit, the handler first, on the drop of [`Gpu`] and = on the error path of +/// its constructor alike, so that the subtree is disabled only after the = handler is freed. +#[pin_data] +struct GspSubtree<'a> { + #[pin] + irq: GspIrq<'a>, + /// Must be kept declared *after* `irq`. A handler still in flight ena= bles the subtree again + /// through its rearm. + _top: TopEnableGuard<'a>, +} + +impl<'a> GspSubtree<'a> { + /// Returns an initializer that registers the GSP event handler and th= en enables its subtree at + /// `TOP`. + /// + /// # Safety + /// + /// Callers must not `mem::forget()` the initialized `GspSubtree` or o= therwise prevent its + /// [`Drop`] implementation, which runs `free_irq`, from running. + unsafe fn new( + pdev: &'a pci::Device, + tree: &'a Tree<'a>, + falcon: &'a Falcon<'a, GspFalcon>, + cmdq: &'a Cmdq<'a>, + ) -> impl PinInit + 'a { + try_pin_init!(Self { + // SAFETY: this function's caller must not leak the `GspSubtre= e` that owns this + // registration, so the registration's `Drop` runs. + irq <- unsafe { GspIrq::new(pdev, tree, falcon, cmdq) }, + _top: tree.enable_top_guarded(), + }) + } +} + /// Structure holding the resources required to operate the GPU. #[pin_data] pub(crate) struct Gpu<'gpu> { pub(crate) spec: Spec, + /// GSP event interrupt registration, and the enable of its subtree. + /// + /// Must be kept declared *before* `gsp_resources`, so that the handle= r is unregistered, and + /// any in-flight run of it has finished, before the command queue tha= t it drains and the + /// falcon that it reads are freed, and before the GSP is unloaded. + #[pin] + _gsp_subtree: GspSubtree<'gpu>, /// Static GPU information as provided by the GSP. pub(crate) gsp_static_info: GetGspStaticInfoReply, /// GPU memory manager owning memory management resources. @@ -354,6 +406,14 @@ pub(crate) struct Gpu<'gpu> { /// Must be kept declared *after* `gsp_resources`, as the latter's `Pi= nnedDrop` implementation /// requires the sysmem flush page to be in place. sysmem_flush: SysmemFlush<'gpu>, + /// Borrow of `tree` that `_gsp_subtree` holds. A field that borrows a= sibling field is + /// self-referential, which `pin_init` cannot express, so the borrow i= s taken by hand. + tree_ref: &'gpu Tree<'gpu>, + /// The GIN CPU interrupt tree and the PCI vectors that deliver it. + /// + /// Must be kept declared *after* `_gsp_subtree`, which holds a borrow= of it. + #[pin] + tree: Tree<'gpu>, } =20 #[pinned_drop] @@ -397,6 +457,12 @@ pub(crate) fn new<'a>( dev_info!(dev,"NVIDIA ({})\n", spec); })?, =20 + tree: Tree::new(pdev, bar, spec.chipset, irq::gsp::GSP_SUBTREE= .into())?, + + // SAFETY: `tree` is initialized above, is pinned at a stable = address, and is dropped + // after every field that uses `tree_ref` (struct field drop o= rder). + tree_ref: unsafe { &*core::ptr::from_ref(tree.as_ref().get_ref= ()) }, + _: { let dma_mask =3D hal::gpu_hal(spec.chipset).dma_mask(); =20 @@ -422,12 +488,7 @@ pub(crate) fn new<'a>( =20 bar, =20 - gsp_falcon: Falcon::new( - dev, - spec.chipset, - bar - ) - .inspect(|falcon| falcon.clear_swgen0_intr())?, + gsp_falcon: Falcon::new(dev, spec.chipset, bar)?, =20 sec2_falcon: Falcon::new(dev, spec.chipset, bar)?, =20 @@ -451,6 +512,29 @@ pub(crate) fn new<'a>( })?, }), =20 + _: { + irq::gsp::quiesce(tree_ref, &gsp_resources.gsp_falcon); + }, + + // SAFETY: the GSP falcon and the command queue are fields of = `gsp_resources`, which + // is initialized above and pinned, so both references outlive= the registration. The + // registration is a field of `Gpu` and is never leaked, so it= s `Drop` runs, and field + // drop order runs it before either is freed. + _gsp_subtree <- unsafe { + GspSubtree::new( + pdev, + tree_ref, + &*core::ptr::from_ref(&gsp_resources.gsp_falcon), + &*core::ptr::from_ref(&gsp_resources.gsp.cmdq), + ) + }, + + // No interrupt announces the messages that the GSP posted dur= ing boot, before the + // SWGEN0 latch was cleared. + _: { + gsp_resources.gsp.cmdq.drain()?; + }, + gsp_static_info: { // Obtain and display basic GPU information. let info =3D gsp_resources.gsp.get_static_info()?; diff --git a/drivers/gpu/nova-core/gsp/cmdq.rs b/drivers/gpu/nova-core/gsp/= cmdq.rs index ae3808de44e2..1b2f346a237f 100644 --- a/drivers/gpu/nova-core/gsp/cmdq.rs +++ b/drivers/gpu/nova-core/gsp/cmdq.rs @@ -629,6 +629,20 @@ pub(crate) fn await_msg(&self) -> R= esult { self.inner.lock().await_msg() } + + /// Logs and consumes every message the GSP has already posted, and re= turns without waiting for + /// more. + /// + /// No caller is waiting for a reply while this holds the queue mutex,= so every message is + /// logged as an event. See "Draining the GSP-to-CPU queue" in + /// `Documentation/gpu/nova/core/interrupts.rst`. + /// + /// # Errors + /// + /// `EIO` if a message fails framing or checksum validation. + pub(crate) fn drain(&self) -> Result { + self.inner.lock().drain() + } } =20 /// Inner mutex protected state of [`Cmdq`]. @@ -941,4 +955,30 @@ fn log_event(&self, function: Result= , seq: u32) { } } } + + /// Logs and consumes every message the queue holds. + /// + /// # Errors + /// + /// `EIO` if a message fails framing or checksum validation, or if a m= essage's page count + /// overflows a `u32`. + fn drain(&mut self) -> Result { + while !self.gsp_mem.driver_read_area().0.is_empty() { + // A message is available, so this returns without waiting. + let msg =3D self.wait_for_msg(Delta::ZERO)?; + + let pages =3D + u32::try_from(msg.header.length().div_ceil(GSP_PAGE_SIZE))= .map_err(|_| { + dev_err!(&self.dev, "GSP drain: message length overflo= w\n"); + EIO + })?; + let function =3D msg.header.function(); + let seq =3D msg.header.sequence(); + + self.gsp_mem.advance_cpu_read_ptr(pages); + self.log_event(function, seq); + } + + Ok(()) + } } diff --git a/drivers/gpu/nova-core/irq.rs b/drivers/gpu/nova-core/irq.rs index ff8b00a82442..02f9bd84dd19 100644 --- a/drivers/gpu/nova-core/irq.rs +++ b/drivers/gpu/nova-core/irq.rs @@ -11,6 +11,7 @@ =20 #[cfg(CONFIG_NOVA_CORE_SELFTESTS)] pub(crate) mod doorbell_test; +pub(crate) mod gsp; mod hal; pub(crate) mod interrupt_tree; mod regs; diff --git a/drivers/gpu/nova-core/irq/gsp.rs b/drivers/gpu/nova-core/irq/g= sp.rs new file mode 100644 index 000000000000..bb504e104bb8 --- /dev/null +++ b/drivers/gpu/nova-core/irq/gsp.rs @@ -0,0 +1,196 @@ +// SPDX-License-Identifier: GPL-2.0 +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIA= TES. All rights reserved. + +//! The GSP event interrupt. +//! +//! The GSP posts messages to the GSP-to-CPU queue and raises SWGEN0, a so= ftware-generated cause +//! of its falcon. A threaded handler services it: the top half clears the= tree and falcon state, +//! and the IRQ thread drains the queue. +//! +//! See "The GSP event" in `Documentation/gpu/nova/core/interrupts.rst`. + +use kernel::{ + device, + irq, + pci, + prelude::*, // +}; + +use super::interrupt_tree::{ + GinVector, + LeafEnableGuard, + Subtree, + Tree, // +}; +use crate::{ + falcon::{ + gsp::Gsp as GspFalcon, + Falcon, // + }, + gsp::cmdq::Cmdq, + regs, // +}; + +/// The GSP event vector, which has the same number on every supported GPU. +const GSP_INTR_0_VECTOR: GinVector =3D GinVector::new::<155>(); + +/// The GSP event's subtree, the only one that nova-core services. +pub(crate) const GSP_SUBTREE: Subtree =3D GSP_INTR_0_VECTOR.subtree(); + +/// Clears the tree and falcon interrupt state that GSP boot leaves behind= , and rearms PCI +/// interrupt delivery. +/// +/// On return, no vector is enabled at its leaf, the serviced subtrees are= disabled at `TOP`, and +/// the SWGEN0 latch is clear, so the next message that the GSP posts sign= als the tree. +pub(crate) fn quiesce(tree: &Tree<'_>, falcon: &Falcon<'_, GspFalcon>) { + tree.reset(); + // The latch is cleared after the tree reset. The other order can leav= e the latch set with its + // leaf bit cleared. See "Enabling the GSP event" in interrupts.rst. + falcon.clear_swgen0_intr(); +} + +/// Threaded IRQ handler for the GSP event. +pub(crate) struct GspInterrupt<'a> { + falcon: &'a Falcon<'a, GspFalcon>, + cmdq: &'a Cmdq<'a>, + tree: &'a Tree<'a>, + /// For logging. The command queue's device reference is behind its mu= tex, which the top half + /// cannot take. + dev: &'a device::Device, +} + +impl GspInterrupt<'_> { + /// Clears the latch of every host-routed cause in `status` other than= SWGEN0, and logs them. + /// + /// Returns the causes still set after the clear. A cause driven from = outside the falcon stays + /// set, and only a device reset ends it. + fn clear_faults( + &self, + status: regs::NV_PFALCON_FALCON_IRQSTAT, + ) -> regs::NV_PFALCON_FALCON_IRQSTAT { + let faults =3D status.with_swgen0(false); + if faults.into_raw() =3D=3D 0 { + return faults; + } + + dev_err!( + &self.dev, + "unserviceable GSP falcon interrupt, IRQSTAT {:#x}\n", + status.into_raw() + ); + self.falcon.clear_intr(faults); + + self.falcon.read_host_intr().with_swgen0(false) + } +} + +impl irq::ThreadedHandler for GspInterrupt<'_> { + /// Top half, in hard interrupt context. Services the GSP vector only,= so another vector + /// pending in the same leaf stays pending. + fn handle(&self) -> irq::ThreadedIrqReturn { + let leaf =3D self.tree.read_pending(GSP_INTR_0_VECTOR.leaf_index()= ); + if !leaf.vectors().contains(GSP_INTR_0_VECTOR.leaf_mask()) { + self.tree.rearm_pci_irq(GSP_SUBTREE); + return irq::ThreadedIrqReturn::None; + } + leaf.clear_vectors(GSP_INTR_0_VECTOR.leaf_mask()); + + let status =3D self.falcon.take_host_intr(); + + let remaining_faults =3D self.clear_faults(status); + if remaining_faults.into_raw() =3D=3D 0 { + self.falcon.retrigger_intr(); + } else { + // Disabling the vector loses no notification: the falcon sign= als nothing further + // while a cause stays set. See "Retriggering a falcon" in int= errupts.rst. + self.tree.disable_leaf( + GSP_INTR_0_VECTOR.leaf_index(), + GSP_INTR_0_VECTOR.leaf_mask(), + ); + dev_err!( + &self.dev, + "GSP falcon cause {:#x} needs a device reset, GSP events a= re no longer serviced\n", + remaining_faults.into_raw() + ); + } + + self.tree.rearm_pci_irq(GSP_SUBTREE); + + if status.swgen0() { + irq::ThreadedIrqReturn::WakeThread + } else { + irq::ThreadedIrqReturn::Handled + } + } + + /// IRQ thread. Drains the GSP-to-CPU queue, which may sleep. + fn handle_threaded(&self) -> irq::IrqReturn { + if let Err(e) =3D self.cmdq.drain() { + // The failed message stays at the queue head, so every later = drain fails the same way. + self.tree.disable_leaf( + GSP_INTR_0_VECTOR.leaf_index(), + GSP_INTR_0_VECTOR.leaf_mask(), + ); + dev_err!( + &self.dev, + "GSP event drain failed ({:?}), the message queue is no lo= nger serviced\n", + e + ); + } + irq::IrqReturn::Handled + } +} + +/// The registered GSP event handler and the enable of its vector. +/// +/// The declaration order is the drop order, and it is required: the vecto= r is disabled before +/// `free_irq` runs. See "Enabling the GSP event" in `Documentation/gpu/no= va/core/interrupts.rst`. +#[pin_data] +pub(crate) struct GspIrq<'a> { + _leaf_guard: LeafEnableGuard<'a>, + #[pin] + reg: irq::ThreadedRegistration<'a, GspInterrupt<'a>>, +} + +impl<'a> GspIrq<'a> { + /// Returns an initializer that registers the threaded handler and the= n enables the GSP + /// vector at its leaf. + /// + /// An event that latched while the vector was disabled is delivered a= s soon as the GSP + /// subtree is enabled at `TOP`. + /// + /// # Errors + /// + /// `EINVAL` if `tree` does not service the GSP subtree. Otherwise the= error from + /// `request_threaded_irq`. + /// + /// # Safety + /// + /// Callers must not `mem::forget()` the initialized `GspIrq` or other= wise prevent its [`Drop`] + /// implementation, which runs `free_irq`, from running. + pub(crate) unsafe fn new( + pdev: &'a pci::Device, + tree: &'a Tree<'a>, + falcon: &'a Falcon<'a, GspFalcon>, + cmdq: &'a Cmdq<'a>, + ) -> impl PinInit + 'a { + let dev =3D pdev.as_ref(); + + try_pin_init!(Self { + // SAFETY: this function's caller must not leak the `GspIrq` t= hat owns this + // registration, so the registration's `Drop` runs. + reg <- unsafe { + irq::ThreadedRegistration::new( + tree.request_for(GSP_SUBTREE)?, + irq::Flags::TRIGGER_NONE, + c"nova-core", + Ok(GspInterrupt { falcon, cmdq, tree, dev }), + ) + }, + _leaf_guard: tree.enable_leaf_guarded( + GSP_INTR_0_VECTOR.leaf_index(), + GSP_INTR_0_VECTOR.leaf_mask(), + ), + }) + } +} diff --git a/drivers/gpu/nova-core/irq/interrupt_tree.rs b/drivers/gpu/nova= -core/irq/interrupt_tree.rs index 4bb27cc8b6cd..90d4d11e8ba3 100644 --- a/drivers/gpu/nova-core/irq/interrupt_tree.rs +++ b/drivers/gpu/nova-core/irq/interrupt_tree.rs @@ -124,10 +124,12 @@ pub(super) const fn all() -> Self { Self(u32::MAX) } =20 + #[cfg_attr(not(CONFIG_NOVA_CORE_SELFTESTS), expect(dead_code))] pub(super) const fn from_raw(raw: u32) -> Self { Self(raw) } =20 + #[cfg_attr(not(CONFIG_NOVA_CORE_SELFTESTS), expect(dead_code))] pub(super) const fn into_raw(self) -> u32 { self.0 } @@ -240,6 +242,7 @@ pub(super) const fn new() -> Self { Self(Bounded::::new::()) } =20 + #[cfg_attr(not(CONFIG_NOVA_CORE_SELFTESTS), expect(dead_code))] pub(super) const fn into_raw(self) -> u32 { self.0.get() } diff --git a/drivers/gpu/nova-core/nova_core.rs b/drivers/gpu/nova-core/nov= a_core.rs index 8c0761dedda4..a8f6dc22057b 100644 --- a/drivers/gpu/nova-core/nova_core.rs +++ b/drivers/gpu/nova-core/nova_core.rs @@ -18,7 +18,6 @@ mod fsp; mod gpu; mod gsp; -#[cfg_attr(not(CONFIG_NOVA_CORE_SELFTESTS), expect(dead_code))] mod irq; mod mctp; mod mm; --=20 2.55.0 From nobody Wed Sep 30 15:28:46 2026 Received: from CH1PR05CU001.outbound.protection.outlook.com (mail-northcentralusazon11010011.outbound.protection.outlook.com [52.101.193.11]) (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 42CB0381EB0 for ; Wed, 30 Sep 2026 03:43:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.193.11 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790739801; cv=fail; b=q5IY4YaT+IUkAmeUs85Du2r76Zl4syr6i7p75W7+78+7PtzlnjlafZRHSq6tOwTe7EkCeMKUCn/36ELDou2LphMth05UwjbSEHuRAC3V1o0TAaWGrSH0Mtna7GoU4j4Z8EKabuCpWhCuDIh4lpik+42wwLs/lhI8gyB6WYFo938= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790739801; c=relaxed/simple; bh=3Muv8VRNfEwUFkZHR7aiKqqN3oOoM8brmA4BE/XtFOo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=dT8cRZNQQIuExfkHw66YnYrr0XhdJlgl7uwsKHfu/Q1yCeg7dd32BJVMqrrehSqke6kLs8izn6vxeh22wa5uyIt9c9lz9fY0FhLHO22XYILLNSXhMPom0UjvLIGZnaUQHxwnYTYUD2/6/l0XLQYFSm37O3P9KXaZ6vP//FEWyLU= 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=UqcSyS2/; arc=fail smtp.client-ip=52.101.193.11 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="UqcSyS2/" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ZHfHfh5Daha6h4zJYwp5rYcLM4x0f0oxNoluWRc7SFVYGrSgRLi6Fr0YVs7M0AxMj4a/szMdbApnjWAxjYKl3fbmXzxzLixb+J3wNin7jmm/r9OGRvZYIr1BDpDjLYVrw+MyaNkHAQphlT5AOlywhCmO63JHjfsPYUPeYTJ9yhKY6qJfK2YciVEfANnHVDyzE4vWfwfOjKx/zlggdRbVe8zO0Pn5d+IsPwWdlwobA4ZzpP6Jx7zohn5W9Z/eRn5UmcHzfz+XfG8AopQdcxIvVwkYMgeEbAy/EATf32X0lUCvacYkzFl1vqxd5xbZBh7wa+36hyoYUXBdbmix0r9rCg== 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=0JI9JlyGTTJMDTNkMR010l411eJwx2lYbuk5Hibdjxo=; b=jgTmRMqnGAE4B+HCdgCrstRvigulaFemB7NGCarccCfuxhFMSx9nU2+7XPMKn3dbBiXxEbVeBca/F+WK3hNSCI2aXj215kDyW0ifBnnoSwHRLksHG9BwJ/aaOocoPRwOSv0lpsWpKaETPCRVCfm66TB0mWB7EbPcdQzrrmAzQsyxA8lPFewwEVGRMmlOuNOfuwmGau0kXPn4RxkWpBkVC37xiGvg3OOIWhL/Y7ItlVKrBFWq/fmRaNWJryXL1KVjjg+tD9+8vaxnD54aRhwO/ztY9EDeMaqvtnX06IHcC5csOvHo9o3+oFkSTHGhG3qvQNKg8V4U9937uNIBSDjRAA== 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=0JI9JlyGTTJMDTNkMR010l411eJwx2lYbuk5Hibdjxo=; b=UqcSyS2/V4GnyFuonrEp9DBCH5TQqWNhnYvCp6XtBE8UAx6rB0hPdLyKgRcCkiCIsgt9UejMRwcdJfN/0VPNIgml1Lu2vZ9ysdamiw8YkWTHxWChCailDv3jPgMPJDE+TGxUo7r3zsIpgOAeWU8AYZpMDACHaDJI3Aas9O79NHfbM9u6LaJzADrw22deWY+FPn+SCNb0/1f6CXhH8DZIALuHY9FAjdnH1scnA71tcZd4SZn8uAea/IZQ+J3Q4iV4J4AkvehpqxKDrESI3vbT61oY3Firi57/wXksCOyPtwoTmsI+bwvCWkHeXmqRmBc4xHSbrM+aKG9OJEIt7Ww1MA== Authentication-Results: mx.microsoft.com 1; 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 MN0PR12MB6248.namprd12.prod.outlook.com (2603:10b6:208:3c0::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.451.26; Wed, 30 Sep 2026 03:42:28 +0000 Received: from DM3PR12MB9416.namprd12.prod.outlook.com ([fe80::8cdd:504c:7d2a:59c8]) by DM3PR12MB9416.namprd12.prod.outlook.com ([fe80::8cdd:504c:7d2a:59c8%4]) with mapi id 15.21.0451.024; Wed, 30 Sep 2026 03:42:28 +0000 From: John Hubbard To: Danilo Krummrich , Alexandre Courbot Cc: Timur Tabi , Alistair Popple , Eliot Courtney , 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 , nova-gpu@lists.linux.dev, LKML , John Hubbard Subject: [PATCH v5 14/15] gpu: nova-core: add KUnit tests for the interrupt tree Date: Tue, 29 Sep 2026 20:41:47 -0700 Message-ID: <20260930034148.590687-15-jhubbard@nvidia.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260930034148.590687-1-jhubbard@nvidia.com> References: <20260930034148.590687-1-jhubbard@nvidia.com> X-NVConfidentiality: public Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: PH8P220CA0009.NAMP220.PROD.OUTLOOK.COM (2603:10b6:510:345::15) To DM3PR12MB9416.namprd12.prod.outlook.com (2603:10b6:0:4b::8) 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: DM3PR12MB9416:EE_|MN0PR12MB6248:EE_ X-MS-Office365-Filtering-Correlation-Id: 1e1083a6-2732-439c-d84b-08df1ea4d982 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|23010399003|366016|7416014|376014|10067099003|56012099006|5023799004|11063799006|6133799003|3023799007|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: 78GJhgTIL3ijn12ggmAovM2H5zx5gW9ZkbzBQQr6YJHqOH7L1vBUbRU7XQftqpE7FSMeBxlWRcvlvh+zXPfJbBJFRa0ne9Pr9i6XgBaLfDP/HmCo/mZWbZBn4e85KSGWpsspg6fbPnYpRlHOY+fRy09QB85ehd8WWVENOr6XVlBZ/KS0a5ubtex/ZvHRJuRM4PNqplGQURWOyjBNdfbuvRqlA4lWxJ/xVAd9IXvCl1MJsqdj8Z7xDsHgnaTNKp9Bel12j1MGqoeyiQVuQH6D5A77x7LuxJy/fusPF7fb4P2GF7j9bZ2oryj6XaCJbKOzP7AcZzLUS2MLXMGYGhMe4ShpvcXrfR/f3KMs+sdtCOWOiIP0/SZKuy6GIm+E7JW5/fVrV7ddrTh//x0/sGLtwOTTCcLr5uEJJl5+Q7VhjsnPCuSUCytqLaSdN0FzR7TTi/yIAFn1f5l5fmPNWdX0bAEMddrq1ure0+yltyXzYoA83VmV6YImWi2Lq9HQWZgULEeZMwRnoWfubGQi/5iV8RoPDGYuKm6kJpI40FzJ/tXKbE++hexPGWt5oZRhIfxA82rHp94z4auzeaLQFJUuvv8HBzx9TOW4Rugz9/W7M6jI3ewCYqR6xpkQtUpKZOke92t66/4FZm5b6uBhC5zVkWTnyvg39oNlYV3AIZdtRj4= 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)(1800799024)(23010399003)(366016)(7416014)(376014)(10067099003)(56012099006)(5023799004)(11063799006)(6133799003)(3023799007)(18002099003)(22082099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?eJmEUDsKHFbdiO9m7Htd56NdvFeAo8nI6tRA0zmCbYxg1EFLbGDgjBAY6v5Y?= =?us-ascii?Q?8NxGGSL1xkWcDYhjpzzGskaMFGItD61aYOCp2SvQ+D8k8ffpUlcGiXXV/31/?= =?us-ascii?Q?jMQ5apdN4IYpzing+c0MS7SZh9DvHX4Ovw+dx4RslLn95cmZC2iOGHZVB6+n?= =?us-ascii?Q?O1YYmcKJvqxufqzrVKHnOfzJQU3AIfGoNE6rGUoLsatscJLTOY8VJbuomVq+?= =?us-ascii?Q?PB4sAS/8RaLMQBXHk2sZtJsq/r9BB97ZZ9P451SHwFyVH2+63+Ro5LgNv0in?= =?us-ascii?Q?n9sturZQOQp6c3HBNFEuLsurofetxOuxZ7imdwQhaZMKmr0x7gMkeRL/YE88?= =?us-ascii?Q?YMK02ZwsbeFXahOGs5nGDHmi5meUivN8RS6YtyqAvAWK2sU+x1emOYafUfFR?= =?us-ascii?Q?cjtkwCsBrKWbuWAsS0uME5XJl2NoAyR1BSkdkUpifG8iNU/swpoz331FQ5gX?= =?us-ascii?Q?C2xNlu/DmkYqY/G0AHDeZxI49sv9TMl4+cn6TBFOHnQYL0Gk/YtcBZpI+aNr?= =?us-ascii?Q?TZKPJ6v+ZRWCD24WkG4cNN6/8Dm2JCJ62q/fCyZyvKvVFK0JHvJwEqrqMqnZ?= =?us-ascii?Q?EeWArKl2nsXWn2qIiZUM3KV3UJpPa16UYYGw6wwEJ11bRsK5hlEG0ebhkSy5?= =?us-ascii?Q?rZW8Z/zjOH+oghNTy6s00dkcN1bQjDFtP98T7d3XMhUuMlCr2femiAmIDw8Y?= =?us-ascii?Q?QukHMyi+37szU/TAipdxwu2YJcHyCmCFAwywtT56hyvwl2Anr3BFehMc0rXA?= =?us-ascii?Q?GmAzjdo7rV360ilfw8ywu3JGUjTobaeZZ/DJeW1/M9ylMkV3wURtuKhVmYmD?= =?us-ascii?Q?pf7yiFlp483l4Z7V4zMGGSPIMuJJLUvg+EkVd+LieD44HPEYcczb+q/DEzyY?= =?us-ascii?Q?Ck4EhKEv2uwKioIyJHTEhuovEtIR4X3VQvx0gOwJD4dR+a4aCqIsBz2LSj2K?= =?us-ascii?Q?YPtXr7dgEMvnyMK+r+44KxWZJsXzch+PqEeaYlE+OF8VVwySi4eGHgNObfTp?= =?us-ascii?Q?bcQfKfGCFOsNMq34fOW9lLM+dfoxLg55CAcQxeTtLPUbuy9DuL8vV0qpOvHN?= =?us-ascii?Q?aLoCw/zEWV+qV8DLZBZsBczTAE1MaesL2r9Keyw21ucoceqj+cn6M7DMhfRc?= =?us-ascii?Q?HXaJbHKGK7AMcsI/ySVfwdtM0Z4wlAF5dCebUGuMpQZBGSK8MoacfASM48Ku?= =?us-ascii?Q?OdrZZX5Glg2FRAfDxM0g4EG7HbL0nTTI6B9ZAYx1XbRCEa13w1733zYYDDA/?= =?us-ascii?Q?VwjyJU7xu6qZv77KalZSdL4PtIyN4na2kZ999QgoheUXwIfNvGqJFTJoq0fE?= =?us-ascii?Q?0i7Yy8TOI14lhcUi0fJ9SSWS8IDRQ+7+mm8PqSNmXOCtf+rlOAL730c0LGu/?= =?us-ascii?Q?i0RxrWkpjXOFEUgcovw/2nJoxELWOPbY4j25Zgm7muJFbRz/3qR0wJfVHATt?= =?us-ascii?Q?0yHzGp3lM9qP6RH2AOaWKSUOb5Aypa1E7hqyC5ouch8eQYyxEpH95GY3oD+V?= =?us-ascii?Q?DFj5BqNhpwNev/P6DlRvlyplQhwdfeMyqcIKGFWeOHiKR7Sdg3JypE18lgCi?= =?us-ascii?Q?n+4iFcyJ+N0OHjwwMIrlqOGjfZqdBkO5V5LZ/eLa7cLHKy7J4KF3Hi2552/a?= =?us-ascii?Q?EYwnyf/nd/CPIDxzmKtsdoG/gp0tBqf7KN1vFsTiTCgfzsJuMpvnqHhsGVX5?= =?us-ascii?Q?5YFnxM+NPhx847sPPSJgs88sa0364w7VH7Zml0UcrSVEF6GzTYjgPjIFZXDh?= =?us-ascii?Q?0Lw75fB4ww=3D=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1e1083a6-2732-439c-d84b-08df1ea4d982 X-MS-Exchange-CrossTenant-AuthSource: DM3PR12MB9416.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2026 03:42:28.3682 (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: M59XsyupaFRnKlBc5dayBy6OIReFYGxPVxJcblyPKG9bw8hKQ9V/14BegviV4mz/6j9RhzekgPhwBMJuqwMkdw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6248 Content-Type: text/plain; charset="utf-8" The vector arithmetic and the leaf and subtree sets touch no hardware, so KUnit can cover them without a GPU. A wrong leaf, bit or subtree for a vector would otherwise show up only as a lost interrupt on hardware. Add the nova_core_gin_tree suite. It checks that a leaf index stops at the widest supported tree, that a leaf count implies the right number of subtrees and vectors, that a leaf count enumerates every leaf in order, that a vector maps to the right leaf, bit and subtree, and that a vector beyond an 8-leaf tree is rejected there and accepted in a 16-leaf tree. It also exercises the subtree set operations and checks that every supported chipset implements the subtree that carries the GSP event. Assisted-by: LLM Signed-off-by: John Hubbard --- drivers/gpu/nova-core/irq/interrupt_tree.rs | 128 +++++++++++++++++++- 1 file changed, 127 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/nova-core/irq/interrupt_tree.rs b/drivers/gpu/nova= -core/irq/interrupt_tree.rs index 90d4d11e8ba3..590f921894b6 100644 --- a/drivers/gpu/nova-core/irq/interrupt_tree.rs +++ b/drivers/gpu/nova-core/irq/interrupt_tree.rs @@ -129,7 +129,10 @@ pub(super) const fn from_raw(raw: u32) -> Self { Self(raw) } =20 - #[cfg_attr(not(CONFIG_NOVA_CORE_SELFTESTS), expect(dead_code))] + #[cfg_attr( + not(any(CONFIG_NOVA_CORE_SELFTESTS, CONFIG_KUNIT =3D "y")), + expect(dead_code) + )] pub(super) const fn into_raw(self) -> u32 { self.0 } @@ -554,3 +557,126 @@ fn drop(&mut self) { clear_top_enables(self.bar, self.serviced); } } + +#[kunit_tests(nova_core_gin_tree)] +mod tests { + use super::*; + + /// A leaf index cannot name a leaf beyond the widest supported tree. + #[test] + fn leaf_index_bounds() { + assert!(LeafIndex::try_new(0).is_some()); + assert!(LeafIndex::try_new(15).is_some()); + assert!(LeafIndex::try_new(16).is_none()); + } + + /// The subtree count, the implemented-subtree set, and the vector cou= nt follow the leaf count. + #[test] + fn leaf_count_derives_subtrees_and_vectors() { + assert_eq!(LeafCount::Eight.subtree_count(), 4); + assert_eq!( + Bounded::::from(LeafCount::Eight.subtree_set()).get(), + 0x0f + ); + assert_eq!(LeafCount::Eight.vector_count(), 256); + + assert_eq!(LeafCount::Sixteen.subtree_count(), 8); + assert_eq!( + Bounded::::from(LeafCount::Sixteen.subtree_set()).get= (), + 0xff + ); + assert_eq!(LeafCount::Sixteen.vector_count(), 512); + } + + /// A tree enumerates every leaf that it implements, in order, and no = more. + #[test] + fn leaf_count_iter_covers_the_tree() { + for (count, expected) in [(LeafCount::Eight, 8usize), (LeafCount::= Sixteen, 16)] { + let mut seen =3D 0; + + for (index, leaf) in count.iter().enumerate() { + assert_eq!(leaf.get(), index); + seen +=3D 1; + } + + assert_eq!(seen, expected); + } + } + + /// A vector maps to its leaf, its bit within that leaf, and its subtr= ee. The doorbell (129) + /// and the GSP event (155) share a subtree. + #[test] + fn vector_maps_to_leaf_bit_and_subtree() { + let doorbell =3D GinVector::new::<129>(); + let gsp =3D GinVector::new::<155>(); + + assert_eq!(doorbell.leaf_index().get(), 4); + assert_eq!(doorbell.leaf_mask().into_raw(), 1 << 1); + assert_eq!(doorbell.subtree().index(), 2); + + assert_eq!(gsp.leaf_index().get(), 4); + assert_eq!(gsp.leaf_mask().into_raw(), 1 << 27); + assert_eq!(gsp.subtree().index(), 2); + + assert_eq!(doorbell.subtree(), gsp.subtree()); + } + + /// Both fixed vectors are within the 8-leaf tree, so every supported = chipset implements them. + #[test] + fn fixed_vectors_fit_the_narrowest_tree() { + assert!(GinVector::new::<129>().validate(LeafCount::Eight).is_ok()= ); + assert!(GinVector::new::<155>().validate(LeafCount::Eight).is_ok()= ); + + // The first vector beyond an 8-leaf tree. + assert!(GinVector::new::<256>().validate(LeafCount::Eight).is_err(= )); + assert!(GinVector::new::<256>().validate(LeafCount::Sixteen).is_ok= ()); + } + + /// A subtree set reports membership, intersection, and its span from = subtree 0. + #[test] + fn subtree_set_operations() { + let gsp =3D GinVector::new::<155>().subtree(); + + assert!(LeafCount::Eight.subtree_set().contains(gsp)); + assert!(!LeafCount::Eight.subtree_set().is_empty()); + + // The GSP needs no subtree above 2, so an MSI-X request covers en= tries 0 through 2. + assert_eq!(SubtreeSet::from(gsp).span(), 3); + + // A 16-leaf tree implements every subtree that an 8-leaf tree doe= s. + assert_eq!( + LeafCount::Sixteen + .subtree_set() + .intersection(LeafCount::Eight.subtree_set()), + LeafCount::Eight.subtree_set() + ); + } + + /// Iterating a subtree set yields each subtree once, lowest index fir= st, and nothing for an + /// empty set. + #[test] + fn subtree_set_iterates_its_members() { + assert!(LeafCount::Eight + .subtree_set() + .iter() + .map(Subtree::index) + .eq([0u32, 1, 2, 3])); + + let gsp =3D SubtreeSet::from(GinVector::new::<155>().subtree()); + assert!(gsp.iter().map(Subtree::index).eq([2u32])); + + let empty =3D SubtreeSet::from(Bounded::::new::<0>()); + assert_eq!(empty.iter().count(), 0); + } + + /// Every supported chipset implements the subtree that carries the GS= P event. + #[test] + fn gsp_subtree_is_implemented_everywhere() { + for &chipset in Chipset::ALL { + assert!(cpu_interrupt_hal(chipset) + .leaf_count() + .subtree_set() + .contains(crate::irq::gsp::GSP_SUBTREE)); + } + } +} --=20 2.55.0 From nobody Wed Sep 30 15:28:46 2026 Received: from CH1PR05CU001.outbound.protection.outlook.com (mail-northcentralusazon11010029.outbound.protection.outlook.com [52.101.193.29]) (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 C06F035F19D for ; Wed, 30 Sep 2026 03:42:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.193.29 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790739763; cv=fail; b=UFdgeWflgotLrs2DvKQCKw1EZj1ccCgUIlaFmQAvvbdmjE2MejYk8jtkiPad6gl1zPRwCr3BYI5ixf2z1oMR+xIR19OIc18n9zPI05RnnIq8x4HZO2eRxahnrMi8OUfzsAURvhKWT2uNnPA0+jxLIKwPrZg9MOIWQPG2yrmkk28= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790739763; c=relaxed/simple; bh=e8kDjyaIAVnfyMIAfimmbBM22VEH5K6NhC8+Mx0pJ+Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=NYCbiL3VMNP+TljI40j91Za3OvpmtKjUkis6pQdkpnbK+2CfOAsqGFIKopv38oIJuL0r+m3gynRbID6vfzgC4M9ZRBOaDe1wzOMZFPdA9+UwFfdM+OA00jffT92zCftcmGVS2U1+i+9LNxmHpT2zYq7uEPQ0OrV6DbNpHhYdJ3o= 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=PqO2utwl; arc=fail smtp.client-ip=52.101.193.29 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="PqO2utwl" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=sPUGHctOvVRmtsr1O73yfVcSMdfsPkCruSFcDFpOkF6sL1VPx1lsODT6isyGsRTsjrGjXc/C8dnBwbzL1El0gzI6f0ZSL4yMIEg0zlJQaZGdFQYXkNUNhq8vOcpjbc/S+gAKUCrt8CkmD7NerpTUzN7lsL6PoX23x99J/X/ZJblvnyHIaPd4qmTj1NNoCO5/9CxhS0DUUx2wyqcjAGW/xqENL2yW4bWjoi54ZA847nM8p+uBMo7+4FakP9LTrnZFjzbVMtftUPgNCSzLhGU3Zm2BOUitjJOJO4Ep6wdOG4V6ZSN3sVsL5aMuTROn5sjN6zYH/eUQILJ7X47nv9Y2hg== 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=kflWcHGENdBPFeoFlgW5+ATNneJCtyarq1SPD7UlXMQ=; b=o/eq/XBEW+EZTpa4IdodkxNpNrLX67qtI2MW7ZD0ZtngnnYQtEGL4UlqGwg577glzjRn8i40WZ6XNCFVIwymcOQ8hqi5HLx8sO9G8d6qE6jkYWaR3i/ZLPRi41MjyC/zycs3oe8pG2QwE5uIGNm7OBnwepb1w+Pfwrv6l1uoTlDoaDaC5t6Fji2lkzf9w4Z3yPEb09yXC/FUX0PW9VrfkLt8sYEcUjF+IZDWgxjEn2cihEQVzYUNWXmsFOfBs6lIpuIDEsY2igLGdQs8Is7cB8OKR/qXlCYeiuBPIyjkgC3JWLOL1xnjvPVGg6ZQGZYy2QbiNoZ0bBvrCxM1egvIlw== 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=kflWcHGENdBPFeoFlgW5+ATNneJCtyarq1SPD7UlXMQ=; b=PqO2utwlO2FoRoaWoHPVyBYI0pL3+7Qr+PbAQQmFJ/ULYVc4ITs9tRpSz1ZloMTa4AOx7DButawECVwDJApd4TzIW+Vj6sJzMdMSsLXnNKYB/fg2DbLZgyaDyzoOhYQWJaTwlb54YiCq/0/tlHEE9nJligW4+7fcGaCNpy8inH002sqG5UCx9MOYB1FmORHlc3hCA4OqeucikxmzgFTY0n0LysAzcRL0AF2RAIPTZ+gaWmDanhsnfs96V6EZuWIbiXlvMV/cXEKJTJMsCDD0iqn/jyGXJJViSm/ljcRptU7pJilzbr0YZaTxUTHYvwz3rwFVrbmPlKuFKcPI0U456Q== Authentication-Results: mx.microsoft.com 1; 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 DS0PR12MB7971.namprd12.prod.outlook.com (2603:10b6:8:14e::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.451.24; Wed, 30 Sep 2026 03:42:30 +0000 Received: from DM3PR12MB9416.namprd12.prod.outlook.com ([fe80::8cdd:504c:7d2a:59c8]) by DM3PR12MB9416.namprd12.prod.outlook.com ([fe80::8cdd:504c:7d2a:59c8%4]) with mapi id 15.21.0451.024; Wed, 30 Sep 2026 03:42:30 +0000 From: John Hubbard To: Danilo Krummrich , Alexandre Courbot Cc: Timur Tabi , Alistair Popple , Eliot Courtney , 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 , nova-gpu@lists.linux.dev, LKML , John Hubbard Subject: [PATCH v5 15/15] gpu: nova-core: document the GIN interrupt controller and GSP events Date: Tue, 29 Sep 2026 20:41:48 -0700 Message-ID: <20260930034148.590687-16-jhubbard@nvidia.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260930034148.590687-1-jhubbard@nvidia.com> References: <20260930034148.590687-1-jhubbard@nvidia.com> X-NVConfidentiality: public Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: PH8P222CA0010.NAMP222.PROD.OUTLOOK.COM (2603:10b6:510:2d7::8) To DM3PR12MB9416.namprd12.prod.outlook.com (2603:10b6:0:4b::8) 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: DM3PR12MB9416:EE_|DS0PR12MB7971:EE_ X-MS-Office365-Filtering-Correlation-Id: 365b5424-172d-440c-ed85-08df1ea4da5f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|366016|7416014|376014|1800799024|22082099003|18002099003|3023799007|6133799003|10067099003|11063799006|5023799004|56012099006; X-Microsoft-Antispam-Message-Info: qfPXL3y/I0/wvOEzhBfBuZ8S8uL08xUhy6SmPlHBd+d4aFjohZ6gfDEbviDcmE/HnW9o3I+J3G/R1HultPlhCKtplrGAErZLqL0kR//MvHJ+gAe+K+Kv39V4JI5wPvQiN7wDhCjrovESI4xi3tnz7YmUdjCYMkYAw0g0xMgXp3plIcXmAWIleeTybmxsSa+ey/ewvZKyTyUI0OsdOXJ5jx4uWH9tu5ePHHiJOmpnanKk6O2i+k+Rz7rsu7CRG631mKgUiNl94KhImsFUxy63PSBgKiFwfOy94ZMArSG8BywfYnMatu1ylpru9DnYKRngmwnxtpaL4x7sKnXHqpTqneUVuA3g7yLa3YaCHOvMYBE7Xg3CFef/wAItQfUjsAnCgwTjA7B0mwSYU47b/Zn36gB3KqThCq4gqKoPBDrmdvBSRgrWN+5Aj7atBsx3OVZcZfInV329fzI7Pwhfe20jFfu714buV0yquvnPhvEPgIjA//54+vN+iTKqRrW0uiGw0P7cg6JpKiBvDw9Pl3kIutwhFofQLSivwwtrs2Mix5D1DHw8lWdr7fcJU1Z2jm4ItpkTUOCaBeI2ptCr92OF9lJP/hAHK+i+QRAdjkC4tw2IRZRoIZKsDbwMgZqGBmlUgeSI6dx190OkyFpai+bHWPkeRwhUf6jl8p0eWGj6ff0= 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)(23010399003)(366016)(7416014)(376014)(1800799024)(22082099003)(18002099003)(3023799007)(6133799003)(10067099003)(11063799006)(5023799004)(56012099006);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?6YK/dxeUraJZjmCr/291DXZuu9i5wvNOvFLuaFKE1cLNN3mbQ3Y27a/OCLHO?= =?us-ascii?Q?ZgvsJPJXOP5Lq0cSoPwB8yCz4482rlcmjJOzULPdMMRuNTR+8oUO4AvltjF6?= =?us-ascii?Q?Frwg2f0/2/xqq39X9dKoDOREeXi6ftK5CkCY71MAAloTIZIcZdUxuhfx4zTo?= =?us-ascii?Q?sefJ9s3jiAsZyk10lYyJfpbYZPOmnOYBhT2vyPr5EnMQkOpTeFJkpp4PAVNL?= =?us-ascii?Q?wj4AYatnHFBboEi5TF5zxoTj/vuwaTW8avTQ2z5jDFsNM/LL8FKmXWqFulXH?= =?us-ascii?Q?DX+pHxQBGfIC5FY2ymtOuyrP+4BF1VgAMpUPsOnJJUnQdXmRo6zIEKVa+Dw+?= =?us-ascii?Q?zMhEX9yQfY6wxjmhuxhMqQt/JNSgC5Kdy9htI308q3k1gVQZ8E11Qot7s3Gc?= =?us-ascii?Q?aBg0CfS05Lr0mfVxLrn/9y+RgEas8Jeer1D/bJid80D1/5JqLZBgQv3IwD/z?= =?us-ascii?Q?3adVW3rmd/tGvfTfZTxcruGEa8vwqwf+GnHAsU7lyD5d4SwVLBlsGO6avUDP?= =?us-ascii?Q?TJ0cSs7SMSMv7sFclEClS0YZQjklFEWPr8tCS3kjGaG1FGC8ed7H/mbRzwEw?= =?us-ascii?Q?NFmn7VEtJftXXfB1iWWpko4J4XxBcxHLtEG3/LWCER2XKDNoUVXsxweyqQis?= =?us-ascii?Q?ESm9mA6VdTJPha3pWSKTWjYk5+lY6Vvlp1AxtYHcDZOv+1NRDM9KzSxyPsVf?= =?us-ascii?Q?+Mbj5UE9UvS2y9DFp4w5yBmvbOyuA/NM8//kW5kBJ5wm6EqpPWil9eEsqMuu?= =?us-ascii?Q?DztxIlUSBNBk0kKm5QH+1pMMF9qWbGKEAwYGBvdox0PAdoXmHUPWyl3pHxcB?= =?us-ascii?Q?wPyPtxch9XZU6QEkapCuBBkRQUxVmb6PapKwj5NAJ/DfJ+c+zx9kGV3fpbiq?= =?us-ascii?Q?wuWD385hPTiOXYI4TyY7D0PsdvDjQiiuzxtBVUx1bokT1f/LDwLJSoebLPLC?= =?us-ascii?Q?HFisu8oxeb01ITm3/YuJFQg5P9QxmDXwG7a9SeulvYvxGdCWlBi7Rspp8uXL?= =?us-ascii?Q?fWNsHdy/Uy1/pYprBoNE1ZdxCaS5sTVXsq8YTKAmrronDoWIiM9Av16Gafc3?= =?us-ascii?Q?5fcjl+QPysGmJfQ7vp1IMl8yqC3pB1c/sWJwVCQ2LQlp+zMUaOXW9NebY0ev?= =?us-ascii?Q?scmQHKJU9mhiHKtkNmmzeQWJy0tT/TZCt2TWq66j6vs0DqQQ1GKsfrwqr2yD?= =?us-ascii?Q?BF1BkaVGFZjqP6Lof8uKE7Z58KMs6BTjQlC2hD77mDHJcDGJo4I387wbDkYu?= =?us-ascii?Q?xsQJbeG4ara+VW0ztA+ZP7sy8h3ojTRKPPp2NmOfUgeVjp90ez4uzX9sLDMc?= =?us-ascii?Q?zu97IDIj7AZR+kCnTqJoNgSfODl8Ag81/LqIetEgeqk9FfeeSF3xb111JF4J?= =?us-ascii?Q?rWLLvZq9yiUnNk480QuWnY/87w9+LQ00ft6jdavCHZ4ij3KQb7B/72nQACvd?= =?us-ascii?Q?TAUOOkvb4QngSi/oTWnNhUhR2gOxPwePuZnmBcCki+qyNY2apWqsuDKduGYm?= =?us-ascii?Q?/edY7FfjQwrsgE8K5f/6ExujBjNvb8dMeMKrI35lOVMnMehlH4RmnabCuHRu?= =?us-ascii?Q?pUHj87BUYzZXgiou3SH+91jBg/epI6hKr6tDwSNLRzSHnRVj98BH9qg4idIy?= =?us-ascii?Q?QlhIhMrFv11PYyPQ/SO6PepgkXecRhEv9qIjEUbNIlokVBTwps5tYJ/SDBYo?= =?us-ascii?Q?UlA6KdZhyCLffnwEYZeaUmmhcp3WDGslNgP0DrJsM8KKq0kgbjy/nQ/PM1Ix?= =?us-ascii?Q?3pfJp/76Fg=3D=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 365b5424-172d-440c-ed85-08df1ea4da5f X-MS-Exchange-CrossTenant-AuthSource: DM3PR12MB9416.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2026 03:42:29.8784 (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: bw4n4vkRL2SYUzFM63DtkLekHFwMRRrF+TjTBS3Nni6PhwWT8IR9caLC+PSn3+1eeonPbrv1fMPR+gtGCmWFbA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB7971 Content-Type: text/plain; charset="utf-8" The interrupt code rests on hardware behavior that the code cannot show on its own: how GIN, the GPU's interrupt controller, records and delivers interrupts, what edge-triggered delivery requires of a handler, and how the GSP signals the CPU. Some of those requirements come from OpenRM rather than from the hardware manuals. Add a design document that records that behavior, the rules that nova-core follows because of it, and the terms that the code uses for it. The code comments cite the document by section rather than repeating it. Assisted-by: LLM Signed-off-by: John Hubbard --- Documentation/gpu/nova/core/interrupts.rst | 679 +++++++++++++++++++++ Documentation/gpu/nova/index.rst | 1 + 2 files changed, 680 insertions(+) create mode 100644 Documentation/gpu/nova/core/interrupts.rst diff --git a/Documentation/gpu/nova/core/interrupts.rst b/Documentation/gpu= /nova/core/interrupts.rst new file mode 100644 index 000000000000..bd6b35aa8dcd --- /dev/null +++ b/Documentation/gpu/nova/core/interrupts.rst @@ -0,0 +1,679 @@ +.. SPDX-License-Identifier: GPL-2.0 +.. SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIA= TES. All rights reserved. + +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +GPU interrupt handling: GIN and the GSP event +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +This document describes how nova-core receives interrupts from the GPU on = Turing +and later chipsets. It covers the GPU Interrupt and Notification unit (GIN= ), +which is the GPU's interrupt controller, and the GSP event, the interrupt = that +nova-core services in normal operation. + +Throughout, *CPU* means the CPU and the nova-core driver running on it. Th= e GPU +also has on-chip processors that run their own firmware and receive their = own +interrupts. The GSP (GPU System Processor) is one of them. + +Register names are the names from the GPU hardware reference headers. The +pre-Hopper headers call the controller ``NV_CTRL`` and the Hopper-plus hea= ders +call it ``NV_GIN``. This document calls it GIN throughout, because the tre= e that +nova-core services is the same on every supported chipset. "Register namin= g" +at the end says how the names map onto the headers. OpenRM, NVIDIA's +open-source GPU kernel driver, is cited wherever nova-core follows it. + +Terminology +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +The three levels of the controller, innermost first: + +leaf + One ``LEAF`` register. Each of its 32 bits is the pending bit of one + interrupt source. A Turing, Ampere, or Ada tree has 8 leaves. A Hopper= or + Blackwell tree has 16. + +subtree + Two consecutive leaves, summarized by one bit of ``TOP``. A subtree is= the + unit of enabling at ``TOP``, and under MSI-X it is the unit of deliver= y: + every interrupt from one subtree arrives on one MSI-X entry. + +tree + One ``TOP`` register and the leaves under it. Every PCIe function has = its + own tree, and nova-core services the CPU tree of one function. + +The hardware headers, OpenRM, and the Linux PCI API all use the word "vect= or", +each for a different number. This document gives each one its own name, an= d a +bare "vector" always means a GIN vector. + +GIN vector + The GPU-internal interrupt source number. It addresses one bit of one = leaf. + A 16-leaf tree holds vectors 0 through 511, and an 8-leaf tree holds 0 + through 255. The CPU doorbell is vector 129 and the GSP event is vector + 155. + +MSI-X entry + An index into the device's MSI-X table. One entry serves one subtree. + +PCI vector + One of the interrupts that ``pci_alloc_irq_vectors()`` allocates: an M= SI-X + entry, or the single MSI message. + +Linux IRQ number + What ``request_irq()`` takes, obtained from ``pci_irq_vector()`` for a= PCI + vector. Linux's ``struct msix_entry`` calls this number ``.vector`` as + well. + +The remaining terms, each named for the register or the specification that +defines it: + +enable, disable a vector + Writes to ``LEAF_EN_SET`` and ``LEAF_EN_CLEAR``. + +enable, disable a subtree + Writes to ``TOP_EN_SET`` and ``TOP_EN_CLEAR``. + +serviced subtree + A subtree that nova-core enables and has a handler for. + +rearm + Restoring PCI interrupt delivery after servicing an interrupt. See + "Rearming PCI interrupt delivery". + +mask + Reserved for the two places where hardware and the PCI specification u= se + the word: the MSI-X per-entry Vector Control mask bit, which Linux + controls, and the falcon interrupt masks. It never names a GIN enable. + +latched, pending + Two names for one state, a set ``LEAF`` bit. The vector's source sets = the + bit whether or not the vector is enabled. + +clear a vector + Write a 1 to the vector's bit in ``LEAF``. OpenRM calls the same opera= tion + ``intrClearLeafVector_HAL``. + +pending bits + The plain 32-bit value read from a ``LEAF`` register. + +notification + An interrupt whose only content is that something happened, such as a + posted message. Servicing a notification means reading what it announc= es. + The unit that raised it needs no attention. The GSP event is one. + +unit + Any block that raises an interrupt. "Engine" is reserved for the blocks + that do user work: GR, CE, NVDEC, and the like. + +falcon + One of the GPU's microcontrollers (see + Documentation/gpu/nova/core/falcon.rst). The GSP runs on the RISC-V co= re + inside its falcon. A falcon latches each of its interrupt causes and r= outes + it either to the host, meaning the CPU, or to its own core. + +The GIN controller +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +A GPU has many interrupt sources: the GSP, the copy engines, the graphics +engine, video decode and encode, the MMU fault path, timers, and others. G= IN +records which of them are pending and raises the PCI interrupt to the CPU. + +Trees +----- + +GIN keeps one tree for each destination it can deliver an interrupt to. Th= e CPU +has one tree per PCIe function, so the physical function and each virtual +function have their own. The GSP has a tree, and so do the other on-chip +processors that receive interrupts. Every tree has the same two-level layo= ut, +and a function reaches its own tree through the per-function register aper= ture. + +nova-core services the CPU tree of one function. A virtual function's tree +belongs to that function's driver, and a processor's tree belongs to the +firmware running on that processor. + +The two-level tree +------------------ + +A tree is a set of ``LEAF`` registers and one ``TOP`` register. + +* ``LEAF(i)`` is a 32-bit register that holds the pending bits of vectors + ``32i`` through ``32i + 31``. A set bit is a pending vector. +* ``TOP`` is a 32-bit read-only register. Bit ``N`` summarizes subtree ``N= ``, + which is ``LEAF(2N)`` and ``LEAF(2N + 1)``. The bit is set when an enabl= ed + vector is pending in either leaf. + +A tree with L leaves has L / 2 subtrees and uses TOP bits 0 through L / 2 = - 1. +The other TOP bits read 0. The leaves and subtrees that a chipset has are = its +implemented leaves and subtrees, and "Per-architecture differences" gives = the +counts. For an 8-leaf tree:: + + TOP bit 0 -> subtree 0 -> LEAF(0), LEAF(1) vectors 0..63 + TOP bit 1 -> subtree 1 -> LEAF(2), LEAF(3) vectors 64..127 + TOP bit 2 -> subtree 2 -> LEAF(4), LEAF(5) vectors 128..191 + TOP bit 3 -> subtree 3 -> LEAF(6), LEAF(7) vectors 192..255 + + LEAF(4), one bit per vector, holds vectors 128..159: + + bit 1 =3D vector 129 (CPU doorbell) + bit 27 =3D vector 155 (GSP event) + +A vector's number fixes its place in the tree:: + + leaf =3D vector / 32 + bit =3D vector % 32 + subtree =3D leaf / 2 + +Registers +--------- + +nova-core defines the tree's registers in the ``irq`` module's ``regs.rs``= . The +leaf registers are arrays indexed by leaf number. + +* ``LEAF(i)`` reads as the pending bits of leaf ``i``. Writing a 1 to a bit + clears that vector, and a 0 leaves the bit as it was. +* ``LEAF_EN_SET(i)`` and ``LEAF_EN_CLEAR(i)`` enable and disable the vecto= rs + of leaf ``i``, one bit per vector. +* ``TOP_EN_SET`` and ``TOP_EN_CLEAR`` enable and disable subtrees, one bit= per + subtree. +* ``LEAF_TRIGGER`` takes a vector number and latches that vector, exactly = as + the vector's own source would. It is write-only. The self-test uses it. + +nova-core does not read ``TOP``. "Servicing the tree" says why. + +Every set and clear register acts per bit: a 1 performs the action for that +bit, and a 0 leaves the bit alone. No register needs a read-modify-write. + +GIN delivers a vector to the CPU only when its leaf enable bit and its +subtree's TOP enable bit are both set. The enables do not affect the latch= . The +source of a disabled vector still sets its ``LEAF`` bit. ``TOP`` does not = show +that bit, so reading the leaf is the only way to see it. + +How a unit interrupt reaches the CPU +------------------------------------ + +A unit does not write a ``LEAF`` register. Each unit has an interrupt cont= rol +register that GSP firmware programs. The control register holds the unit's +vector, the GFID that identifies the PCIe function whose tree receives the +interrupt, and one enable bit per destination: the CPU, the GSP, and the o= ther +on-chip processors. When the unit has an event:: + + 1. The unit sends GIN an interrupt message carrying the vector, the GF= ID, + and the destination enables from its control register. + 2. In the tree of each destination that the message selects, GIN sets = bit + (vector % 32) of LEAF(vector / 32). + 3. If the vector and its subtree are enabled in the CPU tree, GIN rais= es + the PCI interrupt. + +Because firmware assigns the vectors, nova-core does not hardcode which ve= ctor +belongs to which unit, with two exceptions. The hardware headers of every +supported chipset define the GSP event as vector 155, and GSP firmware's o= wn +interrupt table uses that definition. The CPU doorbell is vector 129. Pre-= Hopper +hardware fixes that number, and GSP firmware keeps it on Hopper and later. +nova-core names both by number. A driver can fetch the full unit-to-vector +table from the GSP by RPC, and nouveau does. nova-core does not, because a +fixed vector needs no lookup. + +Edge-triggered delivery +----------------------- + +A ``LEAF`` bit is a latch. Its source sets it on a rising edge, and it sta= ys set +until the CPU clears it. A source that stays high does not set the bit aga= in. + +GIN raises the PCI interrupt for a subtree when the subtree's enabled pend= ing +state goes from low to high:: + + Per vector, in leaf i at bit b: + LEAF(i)[b] AND LEAF_EN(i)[b] + + Per subtree N, across leaves 2N and 2N + 1: + OR of every enabled pending bit -> TOP[N] + + Delivery for subtree N: + TOP[N] AND TOP_EN[N] -> rising edge -> PCI interrupt + +``TOP_EN`` applies after the summary, so disabling a subtree stops delivery +without changing what ``TOP`` reports. + +Three consequences: + +* Code that must find every pending vector reads the leaves. A vector that + latched while disabled is not in ``TOP``. +* Writing ``TOP_EN_SET`` for a subtree with an enabled pending bit produce= s a + new edge. GIN delivers an interrupt for a pending bit left uncleared as = soon + as its subtree is enabled again. +* A source that holds its signal high produces no new edge after the CPU + clears the leaf bit. Such a source has to re-emit its interrupt. The fal= cons + do that through ``INTR_RETRIGGER`` (see "Retriggering a falcon"). + +Delivery over PCI +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +GIN delivers the tree's interrupts to the CPU as MSI or MSI-X, whichever L= inux +grants. nova-core requests MSI-X first and falls back to MSI, and never us= es +INTx. + +MSI has a single message, and every subtree raises that one message, so one +Linux IRQ serves the whole tree. + +MSI-X gives each subtree its own table entry, at the index equal to the su= btree +number. Linux masks every entry until a driver requests its Linux IRQ numb= er, +and a masked entry sends no message: the GPU records the interrupt in the = MSI-X +pending bit array, where it stays until Linux unmasks the entry. An entry = that +the driver never requests is never unmasked. A driver that enables a subtr= ee +without requesting that subtree's entry loses every interrupt from that +subtree, with nothing reported: the leaf and TOP registers show the vector +pending and enabled while no handler runs. + +The serviced-subtree invariant +------------------------------ + +Every subtree enabled at ``TOP`` has an allocated PCI vector with a regist= ered +handler. + +MSI satisfies this with its single message. MSI-X needs one allocated entr= y per +serviced subtree, and a PCI allocation cannot be sparse, so nova-core requ= ests +entries 0 through the highest serviced subtree:: + + MSI-X, with subtree 2 serviced: + + subtree 0 -> entry 0 allocated, no handler, stays masked + subtree 1 -> entry 1 allocated, no handler, stays masked + subtree 2 -> entry 2 handler here, and its rearm covers subtree 2 + + MSI, with any serviced set: + + every serviced subtree -> the one allocated PCI vector, whose + handler's rearm covers the whole service= d set + +An allocated entry whose subtree nova-core does not service costs nothing.= The +entry stays masked, and a disabled subtree raises no interrupt. + +nova-core services one subtree. The GSP event, vector 155, is in leaf 4, w= hich +is in subtree 2. OpenRM's headers place its UVM_SHARED interrupt category = in +subtree 2 on every chipset that nova-core supports. The self-test doorbell, +vector 129, is in the same leaf, and the test allocates its own vectors fo= r it +(see "Self-test"). + +Rearming PCI interrupt delivery +------------------------------- + +A message-signaled interrupt is delivered once per edge, and the PCI side +delivers no further interrupt until the CPU rearms it. The rearm operation +depends on the GPU family and on the interrupt type that Linux granted: + +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Architecture Type Rearm operation +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Turing through Ada MSI write the configuration-mirror EOI register +Hopper and later MSI clear then set the serviced TOP enables +Any MSI-X clear then set the handler's own TOP enable +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +The end-of-interrupt register is ``NV_XVE_CYA_2`` in the BAR0 mirror of PCI +configuration space, and the value written does not matter. The ``TOP_EN`` +cycle produces a new delivery edge. The MSI forms cover every serviced sub= tree, +because one message serves all of them. The MSI-X form covers one subtree, +because each serviced subtree has its own entry and its own handler. + +A handler rearms once per delivered interrupt, on every path, including the +path where it finds its vector not pending. A handler that skips the rearm +receives no further interrupts. + +OpenRM makes the same split. It writes the configuration-space EOI for MSI= on +pre-Hopper chipsets, and cycles the TOP enables of the subtrees that it +services for Hopper-plus MSI and for MSI-X. + +Servicing the tree +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Servicing a leaf has a required order: read its pending bits, then clear t= hem. +Clearing a leaf before reading it discards every vector latched in it, and= no +register reports the loss. In nova-core, reading a leaf produces the handl= e that +clears it, so that the wrong order does not compile. The handle clears exa= ctly +the bits that it read, so a vector that latched after the read stays pendi= ng. + +A handler clears its bit before it services the vector. Clearing afterwards +would discard an interrupt that the source raised while the handler ran. + +nova-core services the tree in two ways. + +The notification path services one vector. It reads the vector's leaf, cle= ars +only the vector's bit, and rearms. The subtree stays enabled, and a vector +pending beside it in the same leaf keeps its bit set for the code that ser= vices +that vector. The GSP event handler takes this path, and so does the self-t= est +handler. + +The startup drain walks the whole tree, because it must clear whatever is +pending across every subtree rather than one known vector. It disables the +serviced subtrees at ``TOP``, reads and clears every implemented leaf, and +leaves the subtrees disabled for its caller to enable once the caller is r= eady +for deliveries. The drain reads every leaf rather than descending from ``T= OP``, +because sources latch vectors during boot while those vectors are disabled= , and +``TOP`` does not show them. OpenRM's stall-interrupt path reads every leaf= for +the same reason. + +The two paths as register operations:: + + Startup drain, run once during probe: + write TOP_EN_CLEAR =3D serviced stop new deliveries + for each implemented leaf i: + pending =3D read LEAF(i) + write LEAF(i) =3D pending clear what was read + (returns with TOP_EN still clear) + + Notification, the subtree stays enabled: + pending =3D read LEAF(leaf) is the handler's bit set? + write LEAF(leaf) =3D bit clear that one bit + rearm PCI interrupt delivery + +The drain clears every pending bit, including bits that nova-core never +services. An uncleared bit holds its subtree in the pending state, and ena= bling +that subtree again would deliver an interrupt for a vector that no handler +services. + +The drain's ``TOP_EN_CLEAR`` is not a rearm, and pre-Hopper MSI rearms thr= ough +the configuration mirror, which the drain never writes. An interrupt deliv= ered +before probe had no handler to rearm it, so the tree reset rearms explicit= ly +after the drain. A TOP-enable rearm leaves the serviced subtrees enabled, = so +the reset then disables them again. + +nova-core does not serialize access to the tree. The GSP event handler +touches only its own leaf, and the drain runs during probe, before that ha= ndler +is registered. + +Per-architecture differences +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D + +The tree is the same on every supported GPU except for its size, which cha= nges +at Hopper: + +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D= =3D =3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D +GPUs Leaves Subtrees Implemented subtrees +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D= =3D =3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D +Turing, Ampere, Ada 8 4 ``0x0f`` +Hopper, Blackwell 16 8 ``0xff`` +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D= =3D =3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D + +The interrupt HAL provides the leaf count, and the subtree count and the +implemented-subtree set derive from it. A subtree that the chipset does not +implement has no TOP bit, so building a tree that services one fails with +``EINVAL``. Vectors 129 and 155 are in the 8-leaf tree, so every supported +chipset has them. + +OpenRM's headers assign every interrupt category of a 16-leaf tree to leav= es 0 +through 11. The drain reads all 16, because a vector can be latched in any +implemented leaf. + +The HAL performs the rearm as well (see "Rearming PCI interrupt delivery")= . Two +falcon properties also differ by family, and the falcon HAL carries them: +Turing falcons have no ``INTR_RETRIGGER``, and the RISC-V routing registers +moved at GA102 (see "Retriggering a falcon"). + +The GSP event +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +When the GSP has output for the CPU, it writes messages into the GSP-to-CPU +queue in shared memory and raises SWGEN0, one of the software-generated +interrupt causes of the GSP falcon. SWGEN0 is routed to the host, at vector +155, leaf 4 bit 27, in subtree 2. + +The queue carries notifications (log records, error records, lifecycle eve= nts) +and command replies. A thread waiting for a reply reads the queue itself, = so +the interrupt is only the trigger to drain the queue (see "Draining the +GSP-to-CPU queue"). + +The falcon latches every cause that it raises, SWGEN0 among them, in its +``IRQSTAT`` register. The handler services the host-routed causes and clea= rs +their latches, and then it writes ``INTR_RETRIGGER`` so that the falcon re= -emits +any cause that latched in the meantime. "Retriggering a falcon" has the de= tails. + +Draining the queue takes the command-queue mutex and walks shared memory, = so it +cannot run in hard interrupt context. nova-core registers a threaded handl= er, +under the name ``nova-core`` in ``/proc/interrupts``. The top half runs in= hard +interrupt context and reads and writes only registers, and it wakes the IRQ +thread to drain the queue:: + + GSP writes messages into the GSP-to-CPU queue + GSP raises SWGEN0 + GIN sets bit 27 of LEAF(4), and subtree 2 becomes pending + PCI interrupt -> Linux IRQ -> top half, in hard interrupt context: + read LEAF(4), and if bit 27 is clear, rearm and return + clear bit 27 (the subtree stays enabled) + read the falcon causes routed to the host, clearing SWGEN0 if set + for every other host cause: log it, clear its latch, and read the + host causes back + if the clear ended all of them: retrigger the falcon + otherwise: disable vector 155 at its leaf and skip the retrigger + rearm PCI interrupt delivery + wake the IRQ thread if SWGEN0 was set + IRQ thread, which may sleep: + take the command-queue mutex and drain the GSP-to-CPU queue + +A halt and a posted message can be pending together, so the top half servi= ces +every cause that the status reports. + +A drain fails when a message's framing or checksum is bad (see "Draining t= he +GSP-to-CPU queue"). The message stays at the queue head, so every later dr= ain +would fail the same way, and the IRQ thread disables vector 155 and logs t= he +failure, which leaves the queue unserviced until the device is reset. + +The handler, the self-test, and the rest of the driver read BAR0 through o= ne +shared mapping. nova-core unregisters an interrupt handler when the device +unbinds, so a handler runs only while the mapping exists. + +Retriggering a falcon +--------------------- + +A falcon signals the tree when its set of host-routed causes goes from emp= ty to +non-empty. A cause left latched keeps the set non-empty, so no later cause +signals the tree, and the vector is lost. For a cause that stays latched, = the +handler can clear the tree leaf first or the falcon latch first, and the l= oss +is the same. + +``IRQSTAT`` latches every cause in the falcon, including the causes routed= to +the falcon's own RISC-V core and owned by the firmware running on it. A ho= st +handler owns only the causes that ``PRISCV_RISCV_IRQMASK`` and +``PRISCV_RISCV_IRQDEST`` both select, so it intersects ``IRQSTAT`` with bo= th +before it reads or clears a cause. OpenRM computes the same intersection in +``kflcnRiscvReadIntrStatus``. GA100 keeps the Turing offsets of the two ro= uting +registers and GA102 moves them, so the offsets change at GA102 rather than= at +the Ampere boundary. The handler masks no cause: ``PRISCV_RISCV_IRQMASK`` = is +read-only to the host, and ``FALCON_IRQMASK`` has no effect on host routin= g on +a RISC-V falcon. + +``INTR_RETRIGGER`` makes the falcon re-emit its host-routed causes into the +tree, which supplies the transition that clearing the leaf lost. The handl= er +writes ``INTR_RETRIGGER`` only on a path where it ended every cause that it +read, because a re-emitted cause that stays set arrives again at once and +on every pass after that. + +``IRQSCLR`` ends a latch and does not end the source behind it, so a cause +driven from outside the falcon stays set after the write. On Blackwell the +fault-containment and ECC causes are driven that way: they appear in +``IRQSTAT`` but come from ``PRISCV_RISCV_FAULT_CONTAINMENT_SRCSTAT`` and +``PGSP_ECC_INTR_STATUS``, and only a device reset ends them. So the handler +clears the latch of every host cause other than SWGEN0, reads the host cau= ses +back, and retriggers only when the read-back is empty. When a cause is sti= ll +set, the handler disables vector 155 instead and reports that the device n= eeds +a reset. Disabling loses no notification: the cause that is still set hold= s the +host-routed set non-empty, so the falcon would signal nothing further eith= er +way. OpenRM makes the same choice, and ``kgspService_TU102`` skips +``kflcnIntrRetrigger`` once it has recorded a fatal error. + +The handler cannot distinguish a fault cause that arrives after the clear = from +one that the clear failed to end, so it disables the vector in that case t= oo. +Both mean that the GSP has faulted. + +Turing falcons have no ``INTR_RETRIGGER``, so a Turing handler cannot re-c= reate +a transition that it has lost. It must leave no host cause latched: it rea= ds the +host-routed status once and takes every cause that the status reports, rat= her +than stopping at the first one that it recognizes. One window stays open. A +cause that arrives after the handler has read the status is not in the val= ue +that the handler clears, so it stays latched after the leaf has been clear= ed, +and no later cause from that falcon signals the tree. OpenRM has the same = window +on Turing, where ``kflcnIntrRetrigger`` does nothing. + +Enabling the GSP event +---------------------- + +SWGEN0 is a latch, and the GSP drives no new edge into the tree while it s= tays +set. nova-core's GSP boot code consumes the GSP's notifications by polling= the +queue, which leaves the latch set and leaves pending bits in the tree. The +handoff from polling to interrupts has a required order:: + + disable every implemented vector drop enables left by boot, or by a + driver that ran before this one + drain the tree clear stale pending bits + rearm PCI interrupt delivery required under pre-Hopper MSI, whi= ch + no later step rearms + disable subtree 2 at TOP a TOP-enable rearm enabled it again + clear the SWGEN0 latch so the next message makes an edge + register the threaded handler no delivery can reach it yet + enable vector 155 at LEAF(4) the subtree is still disabled + enable subtree 2 at TOP deliveries become possible here + drain the GSP-to-CPU queue messages posted before the clear + +The first four steps are the tree reset. nova-core runs them, and clears t= he +latch, before it registers the handler. Registering unmasks the PCI interr= upt, +and GIN would then deliver a vector that boot left enabled to a handler th= at +services one vector and has no way to service any other. OpenRM clears eve= ry +leaf enable at the same point for the same reason. + +nova-core clears the latch after the drain. If nova-core cleared the latch +first, a message posted before the drain could set it again, along with bi= t 27 +of LEAF(4). The drain would then clear the leaf bit while the latch stays = set, +and no later message would signal the tree. Clearing after the drain can +instead leave the leaf bit pending with the latch already clear. Enabling = the +subtree then delivers one interrupt whose ``IRQSTAT`` reads zero. The top = half +clears the leaf bit, rearms, and does not wake the IRQ thread, and the que= ue +drain that follows reads the message. + +Clearing the latch makes the first interrupt possible. A message that the = GSP +posted before that clear produces no interrupt, so the sequence ends by +draining the queue. + +The subtree is enabled at ``TOP`` only once the handler is registered. A +TOP-enable rearm sets the enables that it cycles, so the reset disables the +serviced subtrees again after its rearm, and the tree reaches the registra= tion +with subtree 2 disabled under every rearm method. On teardown nova-core di= sables +the vector at its leaf, so that no vector in the subtree can be delivered,= then +calls ``free_irq()``, and disables the subtree last. Disabling the subtree +earlier would let a handler still in flight enable it again through the +``TOP_EN`` cycle of its rearm, which would leave the subtree enabled with = no +handler registered. The driver's ``Gpu`` object, which owns the tree, hold= s the +subtree enable, and a handler's registration holds only the enable of its = own +vector, so that tearing down one handler does not disable a subtree that a= nother +handler shares. nova-core tears down the registration before it frees the = queue +that the handler drains and the falcon that the handler reads, and before = it +unloads the GSP. + +Draining the GSP-to-CPU queue +----------------------------- + +The queue carries command replies and unsolicited events, and a message's +function code says which it is. + +* A function code that matches the awaited reply: the message is decoded a= nd + returned to the caller that sent the command. +* Anything else is an event. An OS error record and a robust-channel record + are logged at error level, and an unrecognized function code at warning + level. The other known events (GSP logs, libos prints, assertion records, + lifecycle notices) need no action and get no line of their own, because = the + receive trace at debug level already records every message's arrival with + its sequence number, function code, and length. + +The sequence number takes no part in the match, because the GSP does not e= cho +the command's sequence number on every reply. On r570 the reply to +``UnloadingGuestDriver`` carries sequence 0. + +The read pointer advances past every message that passes framing and check= sum +validation, whether it matched or was an event. A matched message that is = too +short to decode is the exception, and it stays at the queue head. + +A message's length is inside the region that the checksum covers, so once = the +framing or the checksum fails there is no trustworthy length with which to= skip +the message. Such a message also stays at the queue head, and every later +receive fails on it with ``EIO`` until the device is reset. + +The polling path and the IRQ thread both read the queue under the command-= queue +mutex. Replies and events share one queue and one read pointer, so one loc= k is +held across the whole drain. A thread waiting for a reply logs each event = that +arrives before the reply and keeps waiting. One deadline of 5 seconds appl= ies to +the whole wait, rather than a fresh timeout after each message, and the th= read +holds the mutex for the whole wait, so that no other caller consumes the m= essage +that it waits for. + +With one lock, a drain waits for an in-flight command's receive to finish = or +time out. For log and error records that delay does not matter. + +Self-test +=3D=3D=3D=3D=3D=3D=3D=3D=3D + +The self-test confirms that an interrupt injected at the GPU is delivered = to a +registered handler. It runs during probe, after the GPU's boot firmware, G= FW, +has completed, and before nova-core boots the GSP, because the test disabl= es +and drains the whole tree, including the GSP's leaf. The test is built only +under ``CONFIG_NOVA_CORE_SELFTESTS``, like the other probe-time hardware t= ests. +Those other tests log a failure and let probe continue. A failed delivery = test +fails probe, because an interrupt path that does not work leaves the driver +unable to make progress later, in a place that says nothing about the caus= e. + +The test writes ``LEAF_TRIGGER`` with vector 129, the CPU doorbell, at lea= f 4 +bit 1. The vector then takes the ordinary path to the CPU under the ordina= ry +enables. The doorbell keeps the same number on every supported chipset, so= the +test names it without asking the GSP, which is not running yet. + +The test allocates PCI vectors for subtree 2 and resets the tree, which +disables every vector, drains the tree, and rearms delivery. It checks tha= t the +doorbell bit starts out clear. It registers a non-threaded handler with a +completion, under the name ``nova-core-selftest`` in ``/proc/interrupts``,= and +enables the vector and the subtree. It triggers the doorbell, waits up to = 1000 +ms for the first delivery, triggers it again, and waits up to 1000 ms for = the +second. The handler takes the notification path: it clears only its own bi= t and +rearms, and never walks the tree. + +The test triggers twice, and the second trigger waits for the first handle= r to +finish. One delivery would prove nothing about the rearm, because the first +message-signaled interrupt arrives whether the driver rearms or not, and t= wo +triggers in a row could coalesce into one delivery. A handler that walked = the +tree would prove nothing either: on every configuration except pre-Hopper = MSI +the rearm is a ``TOP_EN`` cycle, so a walk that enabled ``TOP`` again would +rearm delivery whether the handler asked for it or not. + +The test passes only if both deliveries arrive, each finds the doorbell bi= t and +nothing else pending in leaf 4, and the bit is clear once the vector is +disabled. Anything else fails probe. Requiring the exact pending bits on t= he +second delivery shows that the first handler's clear reached the hardware.= No +other vector in leaf 4 can be pending, because the test disabled every vec= tor +and runs before GSP boot. + +The test releases its PCI vectors and its handler before returning, so the +driver's own allocation covers the GSP subtree and nothing else. Sharing t= he +driver's allocation would have let the test pass only because the doorbell= and +the GSP event happen to be in the same subtree. + +The test exercises the path from the GPU to the handler without GSP firmwa= re, +which helps when bringing up PCI, MSI, MSI-X, and passthrough setups. Under +MSI-X a pass also shows that the delivery arrived on the entry belonging t= o the +serviced subtree. + +The vector arithmetic and the leaf and subtree sets depend on no hardware,= and +KUnit tests cover them instead. + +Register naming +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +nova-core uses the ``NV_VIRTUAL_FUNCTION_PRIV_CPU_INTR_*`` names for the C= PU +tree on every supported chipset. That is the per-function aperture: each P= CIe +function reaches its own tree through it, at the same offsets. The control= ler +also has a central aperture that exposes every function's tree. The pre-Ho= pper +headers name it ``NV_CTRL_CPU_INTR_*`` and the Hopper-plus headers +``NV_GIN_CPU_INTR_*``. nova-core does not use it. OpenRM's kernel-side code +for the controller is the ``Intr`` object. + +Scope +=3D=3D=3D=3D=3D + +nova-core services the CPU tree of one function and nothing else. It imple= ments +no virtual-function tree management and no GFID routing, which belong to t= he +physical function's driver or to firmware in a virtualized setup, and no M= IG +(multi-instance GPU) support. It services none of the subtrees that the +hardware headers reserve for the stall interrupts of the host-driven engin= es. diff --git a/Documentation/gpu/nova/index.rst b/Documentation/gpu/nova/inde= x.rst index 59b206238498..224caef9ea42 100644 --- a/Documentation/gpu/nova/index.rst +++ b/Documentation/gpu/nova/index.rst @@ -35,3 +35,4 @@ vGPU manager VFIO driver and the nova-drm driver. core/falcon core/tlv core/pramin + core/interrupts --=20 2.55.0