From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.100.140 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796228393; b=0Jn/x2SDjnj34NRWKzsKyXMMjCPuypmtUWagkIHR197+Tb3CR8Y8AWX1wbZR+JGwxtCT iVvyaypdfZKJcLWz5iNZBOsF4URnARlu9JEYJq4dT63yE+tlMxTrWwqVTkWJL7RVOgWF0 nK5nQNJqIDXXSLBIc8yycHIuCuavlqzqv+fUoXwGC0Q0BhORMcsmI5EdbKnyRJg80f3wY hgcV0OEn81eqSm+z2XOzxGDm3dvl8kCAj4gB7Uhqd4lVfGmTajNbFp30dSmHg41rpoJ1I FzjMCtljPuiwJDZpspcbhwqRZwRj551ocQnvVWqgLSVuXWqxNn8pGlo09yuL429GqZg== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796228393; h=DMARC-Filter:DKIM-Signature:Received:Received: Content-Transfer-Encoding:Content-Type:Date:Message-Id:Cc:Subject: From:To:X-Mailer:References:In-Reply-To:X-ClientProxiedBy: MIME-Version:X-MS-PublicTrafficType:X-MS-TrafficTypeDiagnostic: X-MS-Office365-Filtering-Correlation-Id:X-MS-Exchange-SenderADCheck: X-MS-Exchange-AntiSpam-Relay:X-Microsoft-Antispam: X-Microsoft-Antispam-Message-Info:X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=nHD81jToijdm7C9Mmdc2IfpcyMlCeou40ImlFHajj84=; b=NvPTsYwEd59h94rqZZt/5GLyZ+/AG220Od2T3H3vS2aF5beS6dv0ZKNkvCCI1WAoLYEj nyPlEna//SfAmDh2csdGKRm8h1q90lGWSKFXvFtQtXJOpIQRn0FoKoarSlIp3QxkjLKcG ES7OXbzg2ObxPn6I8/NuTnHlxK6Zm3+n/wvEYViiYuVbQhEsQfi57dXzb2VHr2vOLVOjl 7Ky+yD19vWx/HbochKGgDrOn/AXKW/FyzMzoT++HEzNoyCy3lDe/B23EEF92qXBP2dLaS 3xZlHx0UUuuwzcPzgvgP6SoOcfWtrJVoY/sdoI6JkoKnNaEfEvvlXdHSyPiF/ODk6OQ== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=garyguo.net; spf=pass smtp.mailfrom=garyguo.net; dkim=pass header.d=garyguo.net header.i=@garyguo.net header.a=rsa-sha256 header.s=selector1 header.b=rtaHsncJ; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.100.140 Received: from CWXP265CU009.outbound.protection.outlook.com (mail-ukwestazon11021140.outbound.protection.outlook.com [52.101.100.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1CB32606A31A for ; Wed, 2 Dec 2026 16:19:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1CB32606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=garyguo.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=garyguo.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=garyguo.net header.i=@garyguo.net header.a=rsa-sha256 header.s=selector1 header.b=rtaHsncJ ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ZNgK9Za4vxfxPAvGAx5MqBzG4HkXGmLZk7oQLd5kO/I/khO8fCSdh4H+Dp69qQAABmalywcCR9OnomkoYgJ0WVvHvzrjFoPbctEYxGITwOHQvKn6tgBL0GKwXYOcUgTzxdNlLoqhTJDpvUyYU8Gs/4+YbYjyPZA/ynKDhaFXNEEgkaOcY2QJhbrm1I1H2uHnv6HXv97Np1SosB88C7PQKdj1bZ5GApLwc21jEJpv/3BsMXOlYvjr0UVRr8m0zdxd2NKWkSYWXf7+2/B6sAM3F/U1vVoaAOOCIFhJCl7Z6TRiNWbwxfvX1wat8WkOckqiU+oIxWycU9LrP/7YQQpTvA== 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=nHD81jToijdm7C9Mmdc2IfpcyMlCeou40ImlFHajj84=; b=YCA6Ap2X1myh5LWHIkmyN6EodNg+7SFwhSP1Zhme1fLythT99YraZs9V2Zg+JvVtpBjSui2K2L7hTj6+o0WAil9EKtJcjL6x8HHQjg8j51ujJdugjUDQ7hFCdVx0k7uKvSG1Ce92FV77QmIdLHfOW5YEYc1EAf1shUB5w3ep95x5sen5OWM6KJ2ss+h2FQbWbWhyfdxKFMjChgwvWd/DHumtTczsruQZzQ5b+oaDck4KwrqNb83nymdIIW3k9aq6zauSL5zqcZQJIUxJrNQmnDd3WEuZA4g36vlQ6g48nsw7IrEzHXslC3Um+LWu13pIassts0ft/JcNLhY5Ro836Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=garyguo.net; dmarc=pass action=none header.from=garyguo.net; dkim=pass header.d=garyguo.net; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=garyguo.net; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=nHD81jToijdm7C9Mmdc2IfpcyMlCeou40ImlFHajj84=; b=rtaHsncJOIbsuxvqg086bOtw025a7nnbG3q0epF0JYZWEtmWOfjeJabYQQ3z7PnSSczTJHtmIH0B/JEnAl/u8fLibwSP7UeIW5vqefo0hgNtwzi11wSTK4ySQ9wuHYAX8cwHam2qLC+YMRHzgr9RAfIU6OuZyvylbr1ulsKCtXU= Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=garyguo.net; Received: from CWLP265MB6051.GBRP265.PROD.OUTLOOK.COM (2603:10a6:400:1cb::9) by CWYP265MB9334.GBRP265.PROD.OUTLOOK.COM (2603:10a6:400:29b::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.10; Wed, 2 Dec 2026 16:19:48 +0000 Received: from CWLP265MB6051.GBRP265.PROD.OUTLOOK.COM ([fe80::55f6:f98b:7fad:c6e3]) by CWLP265MB6051.GBRP265.PROD.OUTLOOK.COM ([fe80::55f6:f98b:7fad:c6e3%2]) with mapi id 15.21.0688.009; Wed, 2 Dec 2026 16:19:48 +0000 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Wed, 02 Dec 2026 16:19:47 +0000 Message-Id: Cc: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , "Liam R. Howlett" , , "Lorenzo Stoakes" Subject: Re: [PATCH v4 3/5] rust: vfio: add PCI variant driver abstractions From: "Gary Guo" To: "Simon Song" , , , , , , X-Mailer: aerc 0.22.0 References: <20261127224928.1511382-1-xinmengs@nvidia.com> <20261127224928.1511382-4-xinmengs@nvidia.com> In-Reply-To: <20261127224928.1511382-4-xinmengs@nvidia.com> X-ClientProxiedBy: LO4P265CA0274.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:37a::6) To CWLP265MB6051.GBRP265.PROD.OUTLOOK.COM (2603:10a6:400:1cb::9) X-Mailing-List: nova-gpu@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CWLP265MB6051:EE_|CWYP265MB9334:EE_ X-MS-Office365-Filtering-Correlation-Id: a0c8cb07-a215-4eb3-e215-08df509015e7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|366016|1800799024|7416014|376014|10070799003|4143699003|5023799004|18002099003|6133799003|261009223027099003|3023799007|22082099003|260925021911599003|56012099006|10067099003|260925022911599003|260925021311599003|261102130727099003|261021123027099003|261026121527099003|261102123227099003|261021121427099003|261028144727099003|261022113327099003|261022105027099003|261022075727099003|261026140227099003; X-Microsoft-Antispam-Message-Info: p529jj35DY/x8Tddg0/18Zams0ZubjH39XKRIPl5bfrPxCxtnsZ5Quq+DbNTQ9Xj7G6mSW8y3xYlPhTI8TY9+nx+vusIfV0YFdHcxudCljXcrFfAsGa3Nt5O+32TvVJmZ1rVIjGyOSe9+QJCWIJFQPobem3Q0gxdpWNv95oKnZJ+F545tMhKa8xn5bKq/3CTLfL927u9++TNcYpp08f6QPrr8/UYBOo3RocQgEc4bcRt8FlalDUpC/CkvQNcUoZDuacyup0Nc1rao8UpuNgSHA6qq6ZuKPz+9hH/hytJLrxZugqJShkP+d37iuKM45+HFLNRbP/dNj7tEuApyVoTOqm6tIocc76sg10xlwLseM1WoMnjJQyd/XkZC032f3+Xxa/XtveU2HwLnOtI5rvIOsr5As/b5i/5Y+WgEnrsPoCviHjueLwYX0QdBZsQwPyXW1Rjp1j3EBGpHjH7HujXAjAdH1LXEooBjfpeoNOK9Io+Ygr0vIbsUwA1zLeKKHLVTypNi8XJWM/HliHtSuNDR7tuWB2EG1youct79dokXjLtPuaWPQG94xHPPVs21v8NXLjHREATibIjb5dvRUKT7Qjte9sQ6v7RHSh1HHEHMvxJhcSuooxrOaqn/xMCVpBS5CmkGzIuR2gkkTR3yjCeAMJQ5bSEuD24jmSLiR02IQ0= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CWLP265MB6051.GBRP265.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230040)(23010399003)(366016)(1800799024)(7416014)(376014)(10070799003)(4143699003)(5023799004)(18002099003)(6133799003)(261009223027099003)(3023799007)(22082099003)(260925021911599003)(56012099006)(10067099003)(260925022911599003)(260925021311599003)(261102130727099003)(261021123027099003)(261026121527099003)(261102123227099003)(261021121427099003)(261028144727099003)(261022113327099003)(261022105027099003)(261022075727099003)(261026140227099003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?ZllzTXpMZmxtM2tJT01BUFhrUDJxelhtcjBqVjZZak9jdnJzU282YkpPOS9I?= =?utf-8?B?VzZ1enp5MzJtR3VpM004VFY2S2VScXRJQTl5dkt5b2o2bjFZNkx1eHFSMi9L?= =?utf-8?B?UG5RZTJIOTd1ZHd5bmI3ZmNZQlY4R2lRZVBSNHlVbUx5N0Z1cDErbkhpY0Ix?= =?utf-8?B?aFFZVCtBNjdsSXRrSThiamc4dDRJNDB1b2hXU1VVUHF0TnNKVWVVQllqOW9q?= =?utf-8?B?aVVMUmtpY0U1MWtsYXd5N3k5eUd1OTMrODJiWkx5NFJ1akR1VEJRcXZhNFdL?= =?utf-8?B?UDh3U0RLRGlLNjVwb2w1dUU4OGF2NFBpaFYyOXk3S1hSOWZhOGFWRFlNTlpj?= =?utf-8?B?ZU1QZWtYdlhkWXVWVU5xZkJYY0JESUtBUUVaL1JCTHROZUFzS0d5cmM5amdN?= =?utf-8?B?c0txMkNwbW1DRkE1S2crQlV4ajhGYTg3Rjd4T1VZeERCeU1pTVhHdkljVHBV?= =?utf-8?B?RCtUOEZ6TE1lVXpzb1pORWgxV3o1c2tZR2JDb0c0bUFXdEJxYTBNNlVvYldj?= =?utf-8?B?Y1FCbWVHdzhqUVZBT0x5em04U2xZNG1Qdmp2QXpyZ1V2RTF1L3hrTkdJRkRE?= =?utf-8?B?MHEwNzN2RFc0aU5uaTdpS0FXVjRkSk5ERmxjRDlaaHdkRWE2MDlrQXR2dDZi?= =?utf-8?B?MHcxZHVSc3FxUE9QQmlwcmhZcWhGdGVEZVl5TlozRG1XZXlldTNkOGtycDJI?= =?utf-8?B?TElFQ1VKM0FiVEY0cDNrSEs5VXhKSW52bW95TWVKSHBPMTJvaWVybUxVSnFp?= =?utf-8?B?TUFmR3ZnTkcvQzNqNmFIQlVyZytPMGVaNnQvdE9MQUM3SEMyT29uRlR1dGVB?= =?utf-8?B?Q1FMS1U2UVpTZmFubDFUQkd3SnNPNlRMRWlSejdhbU9BWlNEY29VV3RkOFVR?= =?utf-8?B?SEJBdUN5bFdJWW9zR1ZTSnJhTWF4OWhlaXhYdUJrWE42MTdFbWNPVnVacVBz?= =?utf-8?B?TkIrVnpOb1JNclVBV3gyb0Y2RlZDL0o0cVJBQ01wMC9OZXFGaXY4VHM4YVZW?= =?utf-8?B?UkhYeHJQbjVRZEZqaU81cjMwRURwdWxZTFBqVDFvMit6eVVYTWErOTFPM3ND?= =?utf-8?B?L1duOFFMSE4wUGVXWW9CVkpKQUdnWEdoZm1jaUplWVYyVVlxdHVPSzNUUm9R?= =?utf-8?B?bHg4Q3NKVVJlWnpNWVZoQnVETG9uZWx4NEJtWXVFdmlnRUltQzVtVWV3VVlt?= =?utf-8?B?QXVDSHBmTFNySnB6eUIrQ0xNMWdlNEZBMVRhOVdIL0tLVFV0QS9FYjJDZE1u?= =?utf-8?B?RmFnaTRaUmZuT1MzSmN1MXdpVVlaYnI5VCt6R0ZpQnFHUXBuY3FQTzRXaisr?= =?utf-8?B?UkhMZDZRVnFBb0wyVTdBcnZlM082UXBOY3FuSzJFTFVGMDJGU2pkZkRMM05p?= =?utf-8?B?dEEvWXFjcGQ5L0dMNXA3SGYwbTR2QnZLTjVpMU03K0JadEdJc0N5WFFkMzY1?= =?utf-8?B?bUFZcENLOUEyaWY0MCt0a2FkZVJCbllpOE4wYXAwMUNHVVFnOTdqYmxHUGhs?= =?utf-8?B?VE05UlFqRXJCaCsybmlSZTh3MlpZV25tVkdBTjVwellqb3pSVVBvaTB0OVB0?= =?utf-8?B?aWNUU3JhUjZKQ2ZXekxYRVdzUWc0cFdyRjdxS2M4Y253TGMxc3BlQ21XbFpw?= =?utf-8?B?My9DS3BsQkpFRXkrMzFQVlVYeDlwb2d1NDJ6MUczNDFuRURpczJrY3hIRS9y?= =?utf-8?B?cHdLbi9xMGdDL2JleDFvQlhXaEpXU0ZscVplOFhIeFA3ajZHWk9rYXdackRF?= =?utf-8?B?eThicXRWaDZZUHIwcEtpY2M4VGtnOEd1Q3VmY05SOEh1WUhpanJPWWZocjFD?= =?utf-8?B?ZU94U2ZLc3JPT2NMYThIam9pQ1VHcHRCQ2lTS0tKaUI3aFlFcndFNlNMWmU3?= =?utf-8?B?eHZjL0pXUkNHdlF2OUpsOFM5YmY0Wm41SXdPTTJDTDlhTmdJYnF2K0ltUThG?= =?utf-8?B?SWUwZzlVVm5ta3NmdGl4TGdZOWVOWXZmZmdmQlR6UXpnNXhSVzl5TXk3L2hW?= =?utf-8?B?aWE5TFBpVSsxZ2pDZFdtR1BqK1RkV0xBbzNVWTZNODFJeUZKajNob0FxYk54?= =?utf-8?B?VWIyekFGWUplVFN3cEZ2TTJpT1p5bk8vZWN0ME1TUkliY0xMWmMreUJvZm5U?= =?utf-8?B?NmJkelY1MzJvRWE1QWgzbmdqbm52TDhoVlNKTzBycWxzcEk0Zm9GQmlkaVBJ?= =?utf-8?B?dmxRY0J3SENueDl3WTY2SDR5cHZlRUtremlNMnFEUDRCKzZBbGNzQnl2dEFY?= =?utf-8?B?Q2JxeFpDQzJHMElKbjlCalZkanY2OGZvNzQ1OXRWVHorMDMvQ2Z1OUkzMnM0?= =?utf-8?B?b3pGZElTalQ2RTVhQnhqNlZ6ZmZFeFllTHEyZGg5Ym1CeHpUSVVadz09?= X-OriginatorOrg: garyguo.net X-MS-Exchange-CrossTenant-Network-Message-Id: a0c8cb07-a215-4eb3-e215-08df509015e7 X-MS-Exchange-CrossTenant-AuthSource: CWLP265MB6051.GBRP265.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2026 16:19:48.4471 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bbc898ad-b10f-4e10-8552-d9377b823d45 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 9b6LZksX0QLpFK+41NWEdYe7U65Eumazot9q7t8DltgPILaScpKtS7oJEL9qgtknoZoT36kd1EesX2sPErPA8w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CWYP265MB9334 On Fri Nov 27, 2026 at 10:49 PM GMT, Simon Song wrote: > From: Danilo Krummrich > > Add Rust abstractions for PCI drivers that extend vfio-pci-core with > device-specific operations. > > Provide Operations, Device and Registration with separate registration > and first-open/last-close data. Allow open data to borrow registration > data, undo PCI enablement if open fails, and drop open data before > closing the core device. > > Let a driver register its VFIO device with Registration::new(), for > example from its PCI probe callback, and unregister it by dropping the > Registration. Let drivers forward PCI reset and error callbacks through > the Registration. Let vfio-pci-core select its VGA arbitration > callbacks. Because runtime PM support follows in a separate patch > series, keep the device active while it is registered. > > Restrict core I/O helpers to their corresponding callback contexts. Add > region mapping helpers, and wire up VFIO core support for device > features, matching, IOMMUFD and PASID. Allow drivers to export physical > BARs as DMA buffers with per-region length limits. > > Add pci::ErsResult::from_raw() for the result of the VFIO PCI core's > error handler. > > Signed-off-by: Danilo Krummrich > Signed-off-by: Zhi Wang > Signed-off-by: Simon Song > --- > rust/bindings/bindings_helper.h | 2 + > rust/kernel/pci.rs | 12 + > rust/kernel/vfio.rs | 24 +- > rust/kernel/vfio/pci.rs | 812 ++++++++++++++++++++++++++++++++ > 4 files changed, 842 insertions(+), 8 deletions(-) > create mode 100644 rust/kernel/vfio/pci.rs > > diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_hel= per.h > index a5781bc1ea85f..b052f1e874e25 100644 > --- a/rust/bindings/bindings_helper.h > +++ b/rust/bindings/bindings_helper.h > @@ -94,6 +94,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -117,6 +118,7 @@ const size_t RUST_CONST_HELPER_ARCH_SLAB_MINALIGN =3D= ARCH_SLAB_MINALIGN; > const size_t RUST_CONST_HELPER_ARCH_KMALLOC_MINALIGN =3D ARCH_KMALLOC_MI= NALIGN; > const size_t RUST_CONST_HELPER_PAGE_SIZE =3D PAGE_SIZE; > const unsigned int RUST_CONST_HELPER_VFIO_DEVICE_RESET =3D VFIO_DEVICE_R= ESET; > +const unsigned int RUST_CONST_HELPER_VFIO_DEVICE_PCI_HOT_RESET =3D VFIO_= DEVICE_PCI_HOT_RESET; > const size_t RUST_CONST_HELPER_GENLMSG_DEFAULT_SIZE =3D GENLMSG_DEFAULT_= SIZE; > const gfp_t RUST_CONST_HELPER_GFP_ATOMIC =3D GFP_ATOMIC; > const gfp_t RUST_CONST_HELPER_GFP_KERNEL =3D GFP_KERNEL; > diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs > index 3fa6831fe34d8..d6f5b0a9dfc7f 100644 > --- a/rust/kernel/pci.rs > +++ b/rust/kernel/pci.rs > @@ -428,6 +428,18 @@ pub enum ErsResult { > } > =20 > impl ErsResult { > + #[cfg_attr(not(CONFIG_VFIO_PCI_CORE =3D "y"), expect(dead_code))] > + pub(crate) fn from_raw(result: bindings::pci_ers_result_t) -> Option= { > + match result { > + bindings::pci_ers_result_PCI_ERS_RESULT_NONE =3D> Some(Self:= :None), > + bindings::pci_ers_result_PCI_ERS_RESULT_CAN_RECOVER =3D> Som= e(Self::CanRecover), > + bindings::pci_ers_result_PCI_ERS_RESULT_NEED_RESET =3D> Some= (Self::NeedReset), > + bindings::pci_ers_result_PCI_ERS_RESULT_DISCONNECT =3D> Some= (Self::Disconnect), > + bindings::pci_ers_result_PCI_ERS_RESULT_RECOVERED =3D> Some(= Self::Recovered), > + _ =3D> None, > + } > + } > + > fn as_raw(self) -> bindings::pci_ers_result_t { > match self { > Self::None =3D> bindings::pci_ers_result_PCI_ERS_RESULT_NONE= , > diff --git a/rust/kernel/vfio.rs b/rust/kernel/vfio.rs > index f49ff5931df56..ff8b17819ca58 100644 > --- a/rust/kernel/vfio.rs > +++ b/rust/kernel/vfio.rs > @@ -3,7 +3,12 @@ > //! Virtual Function I/O (VFIO) devices and callback data. > //! > //! `DeviceBase` combines a C VFIO device structure with the data its ca= llbacks use. > -//! [`Device`] is an alias of it for `struct vfio_device`. > +//! [`Device`] and the bus-specific devices are aliases of it, such as > +#![cfg_attr( > + CONFIG_VFIO_PCI_CORE =3D "y", > + doc =3D "[`vfio::pci::Device`](kernel::vfio::pci::Device)." > +)] > +#![cfg_attr(not(CONFIG_VFIO_PCI_CORE =3D "y"), doc =3D "`vfio::pci::Devi= ce`.")] > //! > //! C header: [`include/linux/vfio.h`](srctree/include/linux/vfio.h) > =20 > @@ -28,6 +33,9 @@ > ptr::NonNull, // > }; > =20 > +#[cfg(CONFIG_VFIO_PCI_CORE =3D "y")] > +pub mod pci; > + > /// Reset the VFIO device. > pub const DEVICE_RESET: u32 =3D bindings::VFIO_DEVICE_RESET; > =20 > @@ -91,7 +99,7 @@ impl IoContext for GetRegionInfo {} > =20 > /// The data the driver of a [`Device`] shares with its callbacks. > /// > -/// Bus-specific operations traits extend this trait. > +/// Bus-specific operations traits, such as `vfio::pci::Operations`, ext= end this trait. > pub trait Operations: Sized + Send + Sync + 'static { > /// Data owned by the registration and passed to VFIO callbacks. > /// > @@ -127,7 +135,7 @@ struct CallbackData { > /// `raw` is the first field, so the `vfio_device` at the beginning of `= Raw` is also at the > /// beginning of `Self`, as `vfio_alloc_device()` requires. > /// > -/// Use the alias [`Device`]. > +/// Use the aliases [`Device`] and `vfio::pci::Device`. > /// > /// # Invariants > /// > @@ -148,7 +156,7 @@ pub struct DeviceBase { > /// A VFIO device, wrapping `struct vfio_device`. > pub type Device =3D DeviceBase; > =20 > -#[expect(dead_code)] > +#[cfg_attr(not(CONFIG_VFIO_PCI_CORE =3D "y"), expect(dead_code))] There're so many of these attr. How about only enabling vfio abstraction if it's not going to be dead_code,= or do a global `#![cfg_attr(not(CONFIG_VFIO_PCI_CORE =3D "y"), expect(dead_cod= e)]`? > impl DeviceBase { > /// Initializes the Rust fields of a newly allocated device. > /// > @@ -193,7 +201,7 @@ fn as_raw_vfio(&self) -> *mut bindings::vfio_device { > } > } > =20 > -#[expect(dead_code)] > +#[cfg_attr(not(CONFIG_VFIO_PCI_CORE =3D "y"), expect(dead_code))] > impl DeviceBase { > /// Publishes the registration data passed to callbacks. > /// > @@ -240,7 +248,7 @@ unsafe fn close(&self) { > } > } > =20 > -#[expect(dead_code)] > +#[cfg_attr(not(CONFIG_VFIO_PCI_CORE =3D "y"), expect(dead_code))] > impl DeviceBase { > /// Creates the open data from the registration data. > /// > @@ -284,7 +292,7 @@ unsafe fn open<'a, 'reg: 'a, I>( > } > } > =20 > -#[expect(dead_code)] > +#[cfg_attr(not(CONFIG_VFIO_PCI_CORE =3D "y"), expect(dead_code))] > impl DeviceBase { > /// Returns the registration data and the open data, for an I/O call= back. > /// > @@ -345,7 +353,7 @@ unsafe impl Sync for DeviceBase {} > =20 > /// Capability buffer supplied by VFIO for a region-info callback. > pub struct InfoCap<'a> { > - #[expect(dead_code)] > + #[cfg_attr(not(CONFIG_VFIO_PCI_CORE =3D "y"), expect(dead_code))] > raw: &'a mut bindings::vfio_info_cap, > } > =20 > diff --git a/rust/kernel/vfio/pci.rs b/rust/kernel/vfio/pci.rs > new file mode 100644 > index 0000000000000..6805915414b55 > --- /dev/null > +++ b/rust/kernel/vfio/pci.rs > @@ -0,0 +1,812 @@ > +// SPDX-License-Identifier: GPL-2.0 > + > +//! VFIO PCI variant driver abstractions. > +//! > +//! Provides Rust abstractions for writing VFIO PCI variant drivers (als= o known > +//! as "VFIO PCI core" drivers). A [`Registration`] struct registers the= VFIO > +//! device and owns its registration data, tying resource lifetimes to t= he PCI > +//! driver's binding scope. > +//! > +//! C header: [`include/linux/vfio_pci_core.h`](srctree/include/linux/vf= io_pci_core.h) > + > +use super::{ > + DeviceBase, > + InfoCap, > + UserBuf, // > +}; > +pub use super::{ > + DeviceContext, > + GetRegionInfo, > + IoContext, > + Ioctl, > + Mmap, > + Normal, > + Open, > + Read, > + Write, // > +}; > + > +use crate::{ > + alloc::allocator::Kmalloc, > + bindings, > + device, > + error::{ > + from_err_ptr, > + from_result, > + to_result, // > + }, > + mm::virt::VmaNew, > + pci, > + prelude::*, > + sync::aref::ARef, > + types::NotThreadSafe, > + uaccess::UserPtr, // > +}; > +use core::{ > + alloc::Layout, > + ptr::NonNull, // > +}; > + > +/// Reset the PCI slot or bus containing a VFIO device. > +pub const DEVICE_PCI_HOT_RESET: u32 =3D bindings::VFIO_DEVICE_PCI_HOT_RE= SET; > + > +/// Index of the PCI configuration-space region. > +pub const CONFIG_REGION_INDEX: u32 =3D bindings::VFIO_PCI_CONFIG_REGION_= INDEX; Can these be new types? > + > +/// The trait for VFIO PCI variant driver implementations. > +/// > +/// Unimplemented I/O callbacks leave their corresponding VFIO hooks uns= et. To get the > +/// behavior of the PCI core, implement the callback and call the corres= ponding core helper of > +/// [`Device`]. > +/// > +/// # Lifetime of the callback data > +/// > +/// [`Registration`] owns the [`RegistrationData`](super::Operations::Re= gistrationData), which > +/// borrows from the PCI binding scope, and each callback borrows it. Ca= llbacks are generic over > +/// the lifetime of the registration data, so they cannot store callback= -local references in it. > +#[vtable] > +pub trait Operations: super::Operations { > + /// The name of the VFIO driver. > + const NAME: &'static CStr; > + > + /// Called when the first file descriptor is opened for this device. > + /// > + /// `vfio_pci_core_enable()` has already succeeded; if this returns = an > + /// error, `vfio_pci_core_disable()` is called automatically. The re= turned > + /// open data is dropped before PCI core close on the last close. > + /// > + /// Exported DMA buffers do not keep the open data alive; PCI core c= lose > + /// revokes them after the open data is dropped. > + fn open_device<'a, 'reg: 'a>( > + dev: &'a Device, As mentioned in patch 1, the lifetime here allows `dev` escaping into `Self::OpenData` (there's still `Send`/`Sync` bound preventing it, but the lifetime still isn't correct). > + reg_data: &'a Self::RegistrationData<'reg>, > + ) -> impl PinInit, Error> + 'a; > + > + /// Handle a VFIO ioctl. > + /// > + /// The default `vfio_pci_core_ioctl()` is available via > + /// [`Device::core_ioctl()`] for delegation. > + /// > + /// [`Device::core_ioctl()`]: Device#method.core_ioctl > + #[optional] > + fn ioctl<'reg>( > + _dev: &Device, > + _reg_data: &Self::RegistrationData<'reg>, > + _open_data: Pin<&Self::OpenData<'_, 'reg>>, If the API is from-scratch Rust design I'd actually make this two traits, w= ith these ioctls implemented on `OpenData` as a trait, and the `open_device` an= d other non-open-data methods only on `RegistrationData`. That said, this isn't too bad either so I guess it's okay. > + _cmd: u32, > + _arg: usize, > + ) -> Result; > + > + /// Read from the device. > + /// > + /// `buf` is a user-space buffer provided by the VFIO core. Use > + /// [`Device::core_read()`] to delegate the default read, and > + /// [`UserBuf::write_overlapping()`] to override specific bytes afte= rwards. > + /// > + /// [`Device::core_read()`]: Device#method.core_read > + #[optional] > + fn read<'reg>( > + _dev: &Device, > + _reg_data: &Self::RegistrationData<'reg>, > + _open_data: Pin<&Self::OpenData<'_, 'reg>>, > + _buf: &mut UserBuf, > + _ppos: &mut Position<'_>, > + ) -> Result; > + > + /// Write to the device, delegating to [`Device::core_write()`] if a= ppropriate. > + /// > + /// [`Device::core_write()`]: Device#method.core_write > + #[optional] > + fn write<'reg>( > + _dev: &Device, > + _reg_data: &Self::RegistrationData<'reg>, > + _open_data: Pin<&Self::OpenData<'_, 'reg>>, > + _buf: &mut UserBuf, > + _ppos: &mut Position<'_>, > + ) -> Result; > + > + /// Map a device region, delegating to [`Device::core_mmap()`] if ap= propriate. > + /// > + /// [`Device::core_mmap()`]: Device#method.core_mmap > + #[optional] > + fn mmap<'reg>( > + _dev: &Device, > + _reg_data: &Self::RegistrationData<'reg>, > + _open_data: Pin<&Self::OpenData<'_, 'reg>>, > + _mapping: &mut Mapping<'_>, > + ) -> Result; > + > + /// Prepare for PCI reset, including resets initiated during enable = or close. > + fn reset_prepare(_reg_data: &Self::RegistrationData<'_>) {} > + > + /// Finish PCI reset. > + fn reset_done(_reg_data: &Self::RegistrationData<'_>) -> Result { > + Ok(()) > + } > + > + /// Fill in region info capabilities. > + /// > + /// The default `vfio_pci_ioctl_get_region_info()` is available via > + /// [`Device::core_get_region_info()`] for delegation. > + /// > + /// [`Device::core_get_region_info()`]: Device#method.core_get_regio= n_info > + #[optional] > + fn get_region_info<'reg>( > + _dev: &Device, > + _reg_data: &Self::RegistrationData<'reg>, > + _open_data: Pin<&Self::OpenData<'_, 'reg>>, > + _info: &mut bindings::vfio_region_info, Don't expose raw bindings directly into abstracted API? > + _caps: &mut InfoCap<'_>, This is double indirection as `InfoCap` isn't a transparent wrapper (also d= ouble lifetime). > + ) -> Result; > + > + /// Returns a limit on the length of a region that may be exported a= s a DMA buffer. > + /// > + /// `None` selects the length of the PCI resource, which also caps a= returned limit. A > + /// device without this callback does not support DMA buffer export. > + #[optional] > + fn dmabuf_len<'reg>( > + _reg_data: &Self::RegistrationData<'reg>, > + _open_data: Pin<&Self::OpenData<'_, 'reg>>, > + _region_index: u32, > + ) -> Result>; > +} > + > +/// A VFIO PCI file position, encoding a region index and an offset with= in that region. > +pub struct Position<'a> { > + raw: &'a mut i64, > +} > + > +impl Position<'_> { > + /// Commit a temporary position only after the operation succeeds. > + /// > + /// This preserves the original position if a read succeeds but a su= bsequent > + /// user copy fails. > + pub fn with_temporary( > + &mut self, > + operation: impl FnOnce(&mut Position<'_>) -> Result, > + ) -> Result { > + let mut next =3D *self.raw; > + let result =3D operation(&mut Position { raw: &mut next })?; > + *self.raw =3D next; > + Ok(result) > + } > + > + /// Returns the PCI region index. > + pub fn region_index(&self) -> u32 { > + ((*self.raw as u64) >> bindings::VFIO_PCI_OFFSET_SHIFT) as u32 > + } > + > + /// Returns the byte offset within the current region. > + pub fn region_offset(&self) -> u64 { > + (*self.raw as u64) & ((1u64 << bindings::VFIO_PCI_OFFSET_SHIFT) = - 1) > + } > +} > + > +/// Mapping metadata supplied by VFIO while the current thread holds the= mmap lock. > +/// > +/// The underlying VMA can only be passed back to the core mmap operatio= n. > +pub struct Mapping<'a> { > + vma: &'a VmaNew, > + _not_thread_safe: NotThreadSafe, > +} > + > +impl Mapping<'_> { > + fn page_offset(&self) -> u64 { > + self.vma.pgoff() as u64 > + } > + > + /// Returns the PCI region index encoded in the mapping offset. > + pub fn region_index(&self) -> u32 { > + (self.page_offset() >> (bindings::VFIO_PCI_OFFSET_SHIFT as usize= - crate::page::PAGE_SHIFT)) > + as u32 > + } > + > + /// Returns the byte offset within the PCI region. > + fn region_offset(&self) -> u64 { > + let mask =3D ((1u64 << bindings::VFIO_PCI_OFFSET_SHIFT) - 1) >> = crate::page::PAGE_SHIFT; > + (self.page_offset() & mask) << crate::page::PAGE_SHIFT > + } > + > + /// Returns the exclusive end of the requested mapping within the PC= I region. > + pub fn region_end(&self) -> Result { > + self.region_offset() > + .checked_add(self.vma.size() as u64) > + .ok_or(EOVERFLOW) > + } > +} > + > +/// A VFIO PCI variant device, wrapping `struct vfio_pci_core_device`. > +/// > +/// Callback contexts expose only their matching core helper and cannot = be > +/// refcounted or shared across threads. > +/// > +/// # Invariants > +/// > +/// In addition to the invariants of `DeviceBase`: > +/// > +/// - The wrapped `vfio_pci_core_device` was initialized by `vfio_pci_co= re_init_dev()`. > +/// - The callback data follows the VFIO registration and first-open/las= t-close lifetimes. > +/// Open data is destroyed before PCI core close, and registration dat= a is > +/// released after PCI core unregistration has drained callbacks. > +pub type Device =3D DeviceBase; > + > +static_assert!(core::mem::offset_of!(bindings::vfio_pci_core_device, vde= v) =3D=3D 0); > + > +impl Device { > + /// Allocate a VFIO PCI device for subsequent registration. > + pub fn new(pdev: &pci::Device>) -> Result> { > + let size =3D Kmalloc::aligned_layout(Layout::new::()).size= (); > + > + // SAFETY: The bound PCI device and static ops are valid. The al= location > + // includes the full Rust wrapper with kmalloc-compatible size a= nd alignment. > + let raw =3D from_err_ptr(unsafe { > + bindings::_vfio_alloc_device(size, pdev.as_ref().as_raw(), &= Self::OPS) > + })?; This doesn't make sure alignment is correct. > + let this =3D NonNull::new(raw.cast::()).ok_or(ENOMEM)?; > + > + // SAFETY: `vfio_pci_core_init_dev()` initialized the C device i= n this new allocation, > + // which nothing else can access yet. `vfio_pci_core_device` beg= ins with its > + // `vfio_device`, as asserted above. > + // INVARIANT: The layout and the initialized `raw` are as just d= escribed. > + unsafe { Self::init(this.as_ptr()) }; > + > + // SAFETY: No registration or callbacks can observe this allocat= ion yet. > + unsafe { (*this.as_ref().as_raw()).pci_ops =3D &Self::PCI_OPS }; > + > + // SAFETY: `this` owns the initial VFIO device reference. > + Ok(unsafe { ARef::from_raw(this) }) > + } > +} > > [snip] > > + > +/// Build the `vfio_device_ops` vtable for a variant driver `T`. > +/// > +/// The open callback and the implemented I/O callbacks dispatch to `T`;= unimplemented I/O > +/// callbacks are not installed. Other installed callbacks use VFIO core= functions or wrappers. > +macro_rules! build_ops { > + ($T:ty) =3D> { > + bindings::vfio_device_ops { > + #[allow(clippy::disallowed_methods)] > + name: <$T>::NAME.as_ptr().cast_mut().cast(), > + init: Some(bindings::vfio_pci_core_init_dev), > + release: Some(bindings::vfio_pci_core_release_dev), > + open_device: Some(open_device_cb::<$T>), > + close_device: Some(close_device_cb::<$T>), > + ioctl: if <$T>::HAS_IOCTL { > + Some(ioctl_cb::<$T>) > + } else { > + None > + }, None here (and below) means returning EINVAL instead of forwarding to core callbacks. Is this what's whated? Most existing vfio pci variant drivers fo= rward un-implemented callbacks. Perhaps it's worth changing the C side to switch the meaning, but regardles= s we should consider what's actually the desired behaviour when people use Rust abstraction's trait "provided methods". > + read: if <$T>::HAS_READ { > + Some(read_cb::<$T>) > + } else { > + None > + }, > + write: if <$T>::HAS_WRITE { > + Some(write_cb::<$T>) > + } else { > + None > + }, > + mmap: if <$T>::HAS_MMAP { > + Some(mmap_cb::<$T>) > + } else { > + None > + }, > + request: Some(bindings::vfio_pci_core_request), > + get_region_info_caps: if <$T>::HAS_GET_REGION_INFO { > + Some(get_region_info_cb::<$T>) > + } else { > + None > + }, > + match_: Some(bindings::vfio_pci_core_match), > + match_token_uuid: Some(bindings::vfio_pci_core_match_token_u= uid), > + device_feature: Some(bindings::vfio_pci_core_ioctl_feature), > + #[cfg(CONFIG_IOMMUFD)] > + bind_iommufd: Some(bindings::vfio_iommufd_physical_bind), > + #[cfg(not(CONFIG_IOMMUFD))] > + bind_iommufd: None, > + #[cfg(CONFIG_IOMMUFD)] > + unbind_iommufd: Some(bindings::vfio_iommufd_physical_unbind)= , > + #[cfg(not(CONFIG_IOMMUFD))] > + unbind_iommufd: None, > + #[cfg(CONFIG_IOMMUFD)] > + attach_ioas: Some(bindings::vfio_iommufd_physical_attach_ioa= s), > + #[cfg(not(CONFIG_IOMMUFD))] > + attach_ioas: None, > + #[cfg(CONFIG_IOMMUFD)] > + detach_ioas: Some(bindings::vfio_iommufd_physical_detach_ioa= s), > + #[cfg(not(CONFIG_IOMMUFD))] > + detach_ioas: None, > + #[cfg(CONFIG_IOMMUFD)] > + pasid_attach_ioas: Some(bindings::vfio_iommufd_physical_pasi= d_attach_ioas), > + #[cfg(not(CONFIG_IOMMUFD))] > + pasid_attach_ioas: None, > + #[cfg(CONFIG_IOMMUFD)] > + pasid_detach_ioas: Some(bindings::vfio_iommufd_physical_pasi= d_detach_ioas), > + #[cfg(not(CONFIG_IOMMUFD))] > + pasid_detach_ioas: None, > + dma_unmap: None, > + } > + }; > +} > + > +/// The registration of a VFIO PCI variant device. > +/// > +/// Owns both the VFIO device reference and the registration data, tying > +/// resource lifetimes to the PCI binding scope `'a`. The device is regi= stered > +/// on construction and unregistered when the `Registration` is dropped. > +pub struct Registration<'a, T: Operations> { > + dev: ARef>, > + reg_data: Pin>>, > +} > + > +impl Device { > + const OPS: bindings::vfio_device_ops =3D build_ops!(T); > + > + const PCI_OPS: bindings::vfio_pci_device_ops =3D bindings::vfio_pci_= device_ops { > + #[cfg(CONFIG_VFIO_PCI_DMABUF)] > + get_dmabuf_phys: if T::HAS_DMABUF_LEN { > + Some(get_dmabuf_phys_cb::) > + } else { > + None > + }, > + #[cfg(not(CONFIG_VFIO_PCI_DMABUF))] > + get_dmabuf_phys: None, > + }; > +} > + > +impl<'a, T: Operations> Registration<'a, T> { > + /// Register a previously allocated VFIO PCI device with its callbac= k data. > + /// > + /// `dev` must have been allocated for `pdev`, and can be registered= only once. `D` is the > + /// PCI driver bound to `pdev`. > + /// > + /// # Safety > + /// > + /// The returned `Registration` must be stored in the bus device pri= vate data of `D`, the > + /// driver bound to `pdev`, and must not be leaked: it has to be dro= pped while that driver > + /// is being unbound from `pdev`, or when its probe fails. > + pub unsafe fn new( > + pdev: &'a pci::Device>, > + dev: &Device, > + reg_data: impl PinInit, Error>, > + ) -> Result { > + const_assert!( > + D::DRIVER_MANAGED_DMA.is_some(), > + "VFIO drivers must manage DMA ownership" > + ); > + const_assert!( > + !D::HAS_SRIOV_ENABLE && !D::HAS_SRIOV_DISABLE, > + "VFIO PCI variant drivers do not support SR-IOV configuratio= n" > + ); D has no association with `pci::Device` at all so it can be completely arbi= trary and the checks here don't really serve any soundness purpose. Best, Gary > + > + // SAFETY: `dev` holds a live VFIO allocation; only compare its = parent pointer. > + if unsafe { (*dev.as_raw_vfio()).dev } !=3D pdev.as_ref().as_raw= () { > + return Err(EINVAL); > + } > + > + let reg_data: Pin>> =3D KBox::pin_i= nit(reg_data, GFP_KERNEL)?; > + let ptr =3D NonNull::from(Pin::get_ref(reg_data.as_ref())); > + > + // SAFETY: `dev` belongs to `pdev`, whose device lock serializes= publication. The > + // returned `Registration` keeps the pinned data alive until it = has unregistered `dev`; > + // if registration fails below, `dev` remains unregistered and n= ever accesses the data. > + unsafe { dev.publish_registration_data(ptr) }?; > + > + // Registering `dev` allows runtime suspend of `pdev`. The VFIO = PCI core expects the PCI > + // driver's runtime PM callbacks to call into it, which these ab= stractions do not provide > + // yet, so keep `pdev` runtime active while `dev` is registered. > + // TODO: Replace this with the runtime PM handling of the PCI bu= s once it is available. > + // > + // SAFETY: `pdev` is a valid device. This is `pm_runtime_get_syn= c()`, which takes a usage > + // reference even if it fails. > + #[cfg(CONFIG_PM)] > + let ret =3D unsafe { > + bindings::__pm_runtime_resume(pdev.as_ref().as_raw(), bindin= gs::RPM_GET_PUT as c_int) > + }; > + #[cfg(not(CONFIG_PM))] > + let ret =3D 0; > + > + to_result(ret) > + .and_then(|()| { > + // SAFETY: `dev` is initialized, has published its regis= tration data and has not > + // been registered before. The caller holds the PCI devi= ce lock of its parent. > + to_result(unsafe { bindings::vfio_pci_core_register_devi= ce(dev.as_raw()) }) > + }) > + .inspect_err(|_| { > + // SAFETY: `pdev` is a valid device, and the usage refer= ence taken above is > + // dropped here. This is `pm_runtime_put()`. > + #[cfg(CONFIG_PM)] > + unsafe { > + bindings::__pm_runtime_idle( > + pdev.as_ref().as_raw(), > + (bindings::RPM_GET_PUT | bindings::RPM_ASYNC) as= c_int, > + ) > + }; > + })?; > + > + Ok(Self { > + dev: dev.into(), > + reg_data, > + }) > + } > + > + /// Prepare the variant driver's state for a PCI reset. > + pub fn reset_prepare(&self) { > + T::reset_prepare(&self.reg_data); > + } > + > + /// Complete the variant driver's state update after a PCI reset. > + pub fn reset_done(&self) -> Result { > + T::reset_done(&self.reg_data) > + } > + > + /// Signal the VFIO error interrupt and return the PCI recovery resu= lt. > + pub fn error_detected(&self) -> pci::ErsResult { > + // SAFETY: This owner keeps the initialized VFIO core device ali= ve. > + let result =3D unsafe { bindings::vfio_pci_core_aer_err_detected= (self.dev.as_raw()) }; > + // The VFIO PCI core only returns results `pci::ErsResult` repre= sents. > + pci::ErsResult::from_raw(result).unwrap_or(pci::ErsResult::None) > + } > +} > + > +impl Drop for Registration<'_, T> { > + fn drop(&mut self) { > + // SAFETY: `new()` registered the device. By its safety requirem= ents, this runs with the > + // PCI device lock held, either from the PCI remove callback or = while probe fails. > + // Unregistration drains the VFIO callbacks, the only users of t= he registration data > + // besides this owner, before the data is released. > + unsafe { bindings::vfio_pci_core_unregister_device(self.dev.as_r= aw()) }; > + > + // SAFETY: `new()` took the usage reference dropped here on the = parent device of `dev`. > + // By the safety requirements of `new()`, that device is still b= ound, so the pointer is > + // valid. This is `pm_runtime_put()`. > + #[cfg(CONFIG_PM)] > + unsafe { > + bindings::__pm_runtime_idle( > + (*self.dev.as_raw_vfio()).dev, > + (bindings::RPM_GET_PUT | bindings::RPM_ASYNC) as c_int, > + ) > + }; > + } > +}