From nobody Sun Feb 8 16:33:40 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 2DED332D7F1 for ; Thu, 5 Feb 2026 21:00:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770325224; cv=none; b=gDuIgT6uSy8HhfmQiTfYXamyrzpPA2pRDXlsKo1MdCuehbkP21rLsskiPHvuhGgO5Dpwo6CW6ym3761kalD9TOZtRd3JwphmkZyaMPQDR1MmJqW4uLc5/8vVs+W0WUT0hnKQYdf7J25kd8C95xeXWiK8mUzUqLLzmEypk3zFY3k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770325224; c=relaxed/simple; bh=O9mLxT+roBXO/RmpnwI+KoBGja1TUjQ0eNURQ1PhU0s=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TvtG7EgztkeZ3Q0RqdOZco03qI04MNFU5oasJ3FL69OC0NwOLm7mvEygTMCng2FdGzu+zF7mHYKoN9h51IU021Newa9EnSYPHCGgzGkwPj5+GL3n80f1l3mC74Em90b/A42HNkQjWIfe1MqN+yztpDo9aM4l+6xRLr4prmN1xRg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=LdHqN68o; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=l63Hji6B; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="LdHqN68o"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="l63Hji6B" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770325223; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aJ0fgGiJg3nMFc2XePDEX8wab9GDsnp8jWnAJ4AGTN4=; b=LdHqN68opCoSgzb+dsyWblg2ZcRcFHaWg/1Bq1b6STfHTwLLSWon7VzcscsFoaKt7bhuSw hKrpgv7xP/lTAhGbBeKVqGg+WJdc7dxUKqK5tLR7DZYs1NLKYDGFyxTsUSZN4PnqEXq5gg qwSGP5uIGEBHop8Th/+1wD82iAWs0dg= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-628-hflwXgE8N0SZzcH9hvXfEg-1; Thu, 05 Feb 2026 16:00:22 -0500 X-MC-Unique: hflwXgE8N0SZzcH9hvXfEg-1 X-Mimecast-MFC-AGG-ID: hflwXgE8N0SZzcH9hvXfEg_1770325222 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-8c6b315185aso574006085a.2 for ; Thu, 05 Feb 2026 13:00:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1770325222; x=1770930022; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=aJ0fgGiJg3nMFc2XePDEX8wab9GDsnp8jWnAJ4AGTN4=; b=l63Hji6BoB+gi5w9+vH+QOiMSrTaBkovo7wlFr9QrBSpNQx1PMtfiVF8aSNhSZdop1 gHgF6SFjveuaG3P/pEhboRU7+te0EKaKX2J0Yf07V0eDTJhbBzwlPfyBzoZJ/EFX1FuK AAKueD239fXy8qJe418NzkqlicNjDaowWCGDsDXSeGoOuWIdpoTBbmUZP/4i5ct9KTg6 DtQRwAyArq3F+4C23iccquX9x6DfAGXRouA1gbqLKcj6PQhc6PXrEdVIxVyh1UlBdQR2 84Afe0bwx6eJnq1C++gyuyQeD1WfHmuPfei/7ZZqG97XyPlFWMsImB+dMCQJB80Z1+Z4 yUaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770325222; x=1770930022; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=aJ0fgGiJg3nMFc2XePDEX8wab9GDsnp8jWnAJ4AGTN4=; b=MWei0HGy7OULxTRfgSkct18z0Ro0a8okw9qymQgaJfBYRcElV0IfYdaqoi8PBE5wQM x7krsByDnmJTver9n7IRmv4dsnmg8jsc1JpVm50rY4oPzpRvdvS1fsNLM9cQv33wCgCy x4TeRNdwcn0zKguN23BaqwK5oEQTh32w0EASJObTuskvTChv2p5B2nwPVg8uIsD22d0s r5FybtGNgEjrlUxXsKMuoa5jK2XL8sN17q8ZgG1OKjWo1ce9TJY2tgA8jgSWbfkYi6l9 UedHaV8z2H3VA4tfLa+AKnaMDfdcnBgsd9vC5wvrT8JqYPOPfu0FKmrG+k9c54rHLwtV XXng== X-Forwarded-Encrypted: i=1; AJvYcCVQnDHpDTdVAACDY7fk+h8LY4sF56mD8uYMdnGaKbnHVtp0Pxiom/5NBaxPKXxPxNrHPiQCRz5IVMGmUN4=@vger.kernel.org X-Gm-Message-State: AOJu0YyznMf0qekXPRZ3aVBmWC87b9Y8pMFcXaEZlKtLWQPufV/D2fdn b1jHl75TSVsfSrTPV94sE2ttxq7PFjPQTQMM8+S4+I6mDADGwHITn14vfqD+jHr58w9rF4qu+CN 9ZfNHXU7wGPi0sYuzy5cSbWFI8oYV8LaI9MpSW0//H+/KFCieHof7+AOXddt0Q5OgAg== X-Gm-Gg: AZuq6aJ6eCFNtUUOwHeEODXVF6ddyRSkj+jvv+1i1E7UxwWSlFoj6FZtJMJfc1z4J6u tKXgFfVNSgXLp3A6ya+RrVjDLRZvJ6cMF4I1kvNedWlqEbpJOyy1asvl/ezARQSjazVv7c3TV8k EhupXHTj5o3afmq5hSsMTKI+CAPwrq+Hicck9rDkNoYwrFM7pFai7KlrZTJda/jutrDeMcbYJjV /2rLsgN/rN59EnNRWBeqt80vxbyuq0nwEVDhezsrVrgglG2SecBZkfxA2tk3nqNq0TdWJJGFcMQ KgBTvnnETo8arI5YnxzA98hSDT7TS+m1iY4Nhll6cbVdo1xaGlxZ6Uut2AgHA86Cn+X9A4DqXmR K7VfJDIoSumMJXwY= X-Received: by 2002:a05:620a:7085:b0:8b2:e70c:427a with SMTP id af79cd13be357-8caf0d3d77cmr64317285a.44.1770325221696; Thu, 05 Feb 2026 13:00:21 -0800 (PST) X-Received: by 2002:a05:620a:7085:b0:8b2:e70c:427a with SMTP id af79cd13be357-8caf0d3d77cmr64305385a.44.1770325220994; Thu, 05 Feb 2026 13:00:20 -0800 (PST) Received: from [172.16.1.8] ([2607:f2c0:b010:9000:4c85:f148:4c91:943a]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8caf9fdf692sm17571285a.44.2026.02.05.13.00.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Feb 2026 13:00:20 -0800 (PST) From: Peter Colberg Date: Thu, 05 Feb 2026 15:59:48 -0500 Subject: [PATCH v2 01/10] PCI: add driver flag to opt into disabling SR-IOV on remove() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260205-rust-pci-sriov-v2-1-ef9400c7767b@redhat.com> References: <20260205-rust-pci-sriov-v2-0-ef9400c7767b@redhat.com> In-Reply-To: <20260205-rust-pci-sriov-v2-0-ef9400c7767b@redhat.com> To: Danilo Krummrich , Bjorn Helgaas , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Abdiel Janulgue , Daniel Almeida , Robin Murphy , Greg Kroah-Hartman , Dave Ertman , Ira Weiny , Leon Romanovsky , David Airlie , Simona Vetter , Jonathan Corbet , Xu Yilun , Tom Rix , Moritz Fischer , "Rafael J. Wysocki" Cc: linux-pci@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Alexandre Courbot , Alistair Popple , Joel Fernandes , John Hubbard , Zhi Wang , nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-doc@vger.kernel.org, linux-fpga@vger.kernel.org, driver-core@lists.linux.dev, Peter Colberg , Jason Gunthorpe X-Mailer: b4 0.14.2 Add a flag managed_sriov to the pci_driver structure that allows a driver to opt into disabling the Single Root I/O Virtualization (SR-IOV) capability of the device when the driver is unbound. Add a new function pci_iov_disable() that is invoked before the remove() callback of a PCI driver and checks for the presence of the new flag. If the flag is set, invoke the sriov_configure() callback to allow the driver to gracefully disable SR-IOV. Warn if the driver fails to do so and forcibly disable SR-IOV using sriov_disable(). Since a (broken) driver may theoretically re-enable SR-IOV during its remove() callback, extend pci_iov_remove() to forcibly disable SR-IOV after remove() if needed and only if the flag managed_sriov is set. Altogether the flag ensures that when a Virtual Function (VF) is bound to a driver, the corresponding Physical Function (PF) is bound to a driver, too, since the VF devices are destroyed when the PF driver is unbound. This guarantee is a prerequisite for exposing a safe Rust API that allows a VF driver to obtain the PF device for a VF device and subsequently access the device private data of the PF device. Suggested-by: Danilo Krummrich Signed-off-by: Peter Colberg --- Changes in v2: - Move logic to disable SR-IOV on remove() from Rust to C. - Add driver flag managed_sriov to opt into disabling SR-IOV on remove(). --- drivers/pci/iov.c | 41 ++++++++++++++++++++++++++++++++++++++++- drivers/pci/pci-driver.c | 3 ++- drivers/pci/pci.h | 2 ++ include/linux/pci.h | 8 ++++++++ 4 files changed, 52 insertions(+), 2 deletions(-) diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index 00784a60ba80bb55ff2790d8f87e15a90c652a24..5b6ed251b4b1e940ec5781bb10d= d5c58d3609fc8 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -1011,20 +1011,59 @@ void pci_iov_release(struct pci_dev *dev) sriov_release(dev); } =20 +/** + * pci_iov_disable - disable SR-IOV before PF driver is detached + * @dev: the PCI device + * + * Invoke sriov_configure() callback to allow the driver to gracefully dis= able + * SR-IOV. Warn if the driver fails to do so and forcibly disable SR-IOV. + */ +void pci_iov_disable(struct pci_dev *dev) +{ + struct pci_driver *drv =3D dev->driver; + struct pci_sriov *iov =3D dev->sriov; + + if (WARN_ON(!drv)) + return; + + if (!dev->is_physfn || !iov->num_VFs || !drv->managed_sriov) + return; + + if (!drv->sriov_configure) { + sriov_disable(dev); + return; + } + + drv->sriov_configure(dev, 0); + + if (WARN_ON(iov->num_VFs)) + sriov_disable(dev); +} + /** * pci_iov_remove - clean up SR-IOV state after PF driver is detached * @dev: the PCI device */ void pci_iov_remove(struct pci_dev *dev) { + struct pci_driver *drv =3D dev->driver; struct pci_sriov *iov =3D dev->sriov; =20 + if (WARN_ON(!drv)) + return; + if (!dev->is_physfn) return; =20 iov->driver_max_VFs =3D iov->total_VFs; - if (iov->num_VFs) + + if (iov->num_VFs && !drv->managed_sriov) { pci_warn(dev, "driver left SR-IOV enabled after remove\n"); + return; + } + + if (WARN_ON(iov->num_VFs)) + sriov_disable(dev); } =20 /** diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c index 7c2d9d59625868886d61d8d4045d656ee0165776..e44593c67d147cd70d2d1a8a436= a26857b0e446a 100644 --- a/drivers/pci/pci-driver.c +++ b/drivers/pci/pci-driver.c @@ -462,6 +462,7 @@ static void pci_device_remove(struct device *dev) struct pci_dev *pci_dev =3D to_pci_dev(dev); struct pci_driver *drv =3D pci_dev->driver; =20 + pci_iov_disable(pci_dev); if (drv->remove) { pm_runtime_get_sync(dev); /* @@ -475,8 +476,8 @@ static void pci_device_remove(struct device *dev) pm_runtime_put_noidle(dev); } pcibios_free_irq(pci_dev); - pci_dev->driver =3D NULL; pci_iov_remove(pci_dev); + pci_dev->driver =3D NULL; =20 /* Undo the runtime PM settings in local_pci_probe() */ pm_runtime_put_sync(dev); diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 0e67014aa0013a7086c3a45d576d4b1ca2bb159f..53692e138ed347bfcf6d5923ddd= 418e9860399d7 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -826,6 +826,7 @@ static inline void pci_restore_pasid_state(struct pci_d= ev *pdev) { } #ifdef CONFIG_PCI_IOV int pci_iov_init(struct pci_dev *dev); void pci_iov_release(struct pci_dev *dev); +void pci_iov_disable(struct pci_dev *dev); void pci_iov_remove(struct pci_dev *dev); void pci_iov_update_resource(struct pci_dev *dev, int resno); resource_size_t pci_sriov_resource_alignment(struct pci_dev *dev, int resn= o); @@ -860,6 +861,7 @@ static inline int pci_iov_init(struct pci_dev *dev) return -ENODEV; } static inline void pci_iov_release(struct pci_dev *dev) { } +static inline void pci_iov_disable(struct pci_dev *dev) { } static inline void pci_iov_remove(struct pci_dev *dev) { } static inline void pci_iov_update_resource(struct pci_dev *dev, int resno)= { } static inline resource_size_t pci_sriov_resource_alignment(struct pci_dev = *dev, diff --git a/include/linux/pci.h b/include/linux/pci.h index b5cc0c2b99065d4a1ee4581275362e79726a2145..768a02b12ff73aeb4dc3dc33fcc= a7c46b524c3c0 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -997,6 +997,13 @@ struct module; * how to manage the DMA themselves and set this flag so that * the IOMMU layer will allow them to setup and manage their * own I/O address space. + * @managed_sriov: Disable SR-IOV on remove(). + * If set, the Single Root I/O Virtualization (SR-IOV) + * capability of the device is disabled when the driver is + * unbound from the device, by calling sriov_configure() + * before remove(). The presence of this flag guarantees + * that when a Virtual Function (VF) is bound to a driver, + * the Physical Function (PF) is bound to a driver, too. */ struct pci_driver { const char *name; @@ -1015,6 +1022,7 @@ struct pci_driver { struct device_driver driver; struct pci_dynids dynids; bool driver_managed_dma; + bool managed_sriov; }; =20 #define to_pci_driver(__drv) \ --=20 2.52.0 From nobody Sun Feb 8 16:33:40 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 0B810330D54 for ; Thu, 5 Feb 2026 21:00:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770325232; cv=none; b=mU8tR4BBjox1tHPU2177x/jex5TAbG3x2T7qbeKHQqgPpsX+sgfi0XPKN8X0fFUtzmFYSC4k9IE5MTbWGoBUcjLozJiVY9RhaighJdUZPH2rDbVc27AtGxMjy06I5MPp2xQZzxbgi+6ZogCfky0vxNfY+2WzImtDY2Gv1HPvGCQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770325232; c=relaxed/simple; bh=rV6qi9tLa8BSeGhd9naq45rlh6qRoKLszIak7MQlwuA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=jPP/pcmFDmJK7GnBHaytbyOYx8FgF0ElJKVHMkfUfQ1AjlquZOkpeAuurD5e3pjyM3EHELpYK1nj5PlVdN1rJv6+ezhHDOzXKaWhreHp7hIzoT2tczKD+IqFTodKrBa5DFv9X0Ust58juXQ1X5f57i1EcsFL3Rb90ot8P4TBP0Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=KrHs0+GG; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=iNQUL1jP; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="KrHs0+GG"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="iNQUL1jP" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770325231; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Bysblly79RF2LtPRkhZUIzq0xEXxTiQQ0zgHTCq8A+8=; b=KrHs0+GGOd+vGTQCZp4h36tHklekRsWBJ0dpmIzI3EN8pUqAuinneoeT4TzJ7TLN6WXkeC Ji7E1HfII7RpIjYxrPLmFXkQqHMF+CFPYVsEy53GchuoZVlhYUardt6EjvYO2VI52PJgnS 5jasQfySb3KT9WHRQ63wLE6zXNqTctY= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-385-b0CRFt8uMLeUWwFt3AJmbw-1; Thu, 05 Feb 2026 16:00:30 -0500 X-MC-Unique: b0CRFt8uMLeUWwFt3AJmbw-1 X-Mimecast-MFC-AGG-ID: b0CRFt8uMLeUWwFt3AJmbw_1770325226 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-8947c4398c4so48674366d6.3 for ; Thu, 05 Feb 2026 13:00:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1770325226; x=1770930026; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Bysblly79RF2LtPRkhZUIzq0xEXxTiQQ0zgHTCq8A+8=; b=iNQUL1jP89zrmBUwVLtCf2XcxkBYGOCQKW2q/yXbwaOEhhuQ80Nj3Z/A2848uKzAWg whmXlMMeybeaoFBrQWWQHAVjVbaUWqWetgo7ORf3w75UskWm7vAYuPGVactwqscs3+9Q kIQtJ4yLCz6XCLkrymSYCJ72ma92TpElJ5rF2vk8PpvqD5slOfKuFH5UBhiB83hr6j1K 6IFQBdK8yz48V+KnpdafVuHZwXFppsyhAZ2Kj2VbwJfCXXEdx5JnFT5kc2xSgh/D8rhl QM3H5nQOIL153PPCrb3bTpZj+UlbNpWKnGfjbntBrJkqkGwn7xnifOwBt6MaBbJ6OAZH Emlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770325226; x=1770930026; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=Bysblly79RF2LtPRkhZUIzq0xEXxTiQQ0zgHTCq8A+8=; b=qyvFBl+/dYBt3K0ozXXUzewwhFsUEy1obHlVUT6tqRbnFS2cDi9U7JRfy2tXOWtL5B k8rXu+hR4t3uU6AvcmGphu89Qe+bbZkMcBfwZ6rsGs304pWyVCRh5Po2pzI4/C7G+ov3 HtmnKaBvJIelw6zgd4xSBBVSxfjxDqCYfrBTQ1rNzYzzgrLZcmKrmjWjnwa2fgqjVYf/ ZbqEanpY/k8NOmeh5pmfYPYwftesCxtSleT8eqMQ8ZSd0u3KYPJlp0tJljMkQAZ3YAvU uqawTah95jzODiEe2U1671urYCl6+fJXQQdkV4Csb271OCBJepUu4Eg8+p+R5/1TtzgV CAkA== X-Forwarded-Encrypted: i=1; AJvYcCW0ijU6sjsCuWXg6Ny2GHyls3+hmQB9sU+7pjQv8br1HmS+p2DXF4Tg6VzCGoF01LE8i0DQM0Qnq65wtI0=@vger.kernel.org X-Gm-Message-State: AOJu0YzOCGl0TBHUfIxgf0RRshxFCduMhJZrUmByJ/vRoTI6DGPYb6qf ZWQRh6JUDUNl6ymCgHoVX+3oOfF25kQX1l4AdNhBBynZw1CkJfcvpgOFTchzEcr+xaVtFUAILe2 AU21990fRt7M18PMHv2eglp5ZOvF8bupCnfJDF9XKcIAlG8Jfg8fEXnv2L5/CF0YDiA== X-Gm-Gg: AZuq6aLoxF1a1Fu4s35DGKhX0L6xV1IpDp9VX74xh5PFS6aANh4NVDulbDtYSm2wE1Z 9v3iaqzzsCPUi2eFR4URGQxR8zfeMzTE1JvnDiX0hm8MBDQXQKaU51OcaQiMDxUqlytcxJrJS2m xhLPS5jYT+2fts4sT0lHoBBq8AK7ZzS3aKZjIOmRS/pe25P1Z4go4e4rmmhBenxCk4xvICnprDp V+YGiyYvlU1AcJLzTp9lqhCQdu59Qg6CGeD9R5m1WQcv/VEuNSlgzOoWoqTpiZS/aQ5UC6NeaqT 98kDLpg2d/+cMWkA7KLGeC1nbo9eph69Rg6QJUFH8n4J+3fjHmZfhJSSjCD5JrVIODT2hp4fAh8 MJ2xPfopeQdzEyQc= X-Received: by 2002:ad4:5c45:0:b0:882:6cd3:7f64 with SMTP id 6a1803df08f44-8953cc8c1c3mr6670766d6.44.1770325225661; Thu, 05 Feb 2026 13:00:25 -0800 (PST) X-Received: by 2002:ad4:5c45:0:b0:882:6cd3:7f64 with SMTP id 6a1803df08f44-8953cc8c1c3mr6669906d6.44.1770325225055; Thu, 05 Feb 2026 13:00:25 -0800 (PST) Received: from [172.16.1.8] ([2607:f2c0:b010:9000:4c85:f148:4c91:943a]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8caf9fdf692sm17571285a.44.2026.02.05.13.00.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Feb 2026 13:00:22 -0800 (PST) From: Peter Colberg Date: Thu, 05 Feb 2026 15:59:49 -0500 Subject: [PATCH v2 02/10] fpga: dfl-pci: set driver flag to disable SR-IOV on remove() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260205-rust-pci-sriov-v2-2-ef9400c7767b@redhat.com> References: <20260205-rust-pci-sriov-v2-0-ef9400c7767b@redhat.com> In-Reply-To: <20260205-rust-pci-sriov-v2-0-ef9400c7767b@redhat.com> To: Danilo Krummrich , Bjorn Helgaas , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Abdiel Janulgue , Daniel Almeida , Robin Murphy , Greg Kroah-Hartman , Dave Ertman , Ira Weiny , Leon Romanovsky , David Airlie , Simona Vetter , Jonathan Corbet , Xu Yilun , Tom Rix , Moritz Fischer , "Rafael J. Wysocki" Cc: linux-pci@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Alexandre Courbot , Alistair Popple , Joel Fernandes , John Hubbard , Zhi Wang , nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-doc@vger.kernel.org, linux-fpga@vger.kernel.org, driver-core@lists.linux.dev, Peter Colberg , Jason Gunthorpe X-Mailer: b4 0.14.2 Set the flag managed_sriov in the pci_driver structure to show how a PCI driver may opt into disabling the Single Root I/O Virtualization (SR-IOV) capability of the device when the driver is removed. Merge the function cci_remove_feature_devs() into cci_pci_remove(). Signed-off-by: Peter Colberg --- Changes in v2: - Demonstrate flag managed_sriov for dfl-pci driver. --- drivers/fpga/dfl-pci.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/drivers/fpga/dfl-pci.c b/drivers/fpga/dfl-pci.c index 602807d6afcc09af9e1d53368b41460ef86545d8..7965c307f9b79bdd2c2c3277d51= 9ab2c4e701797 100644 --- a/drivers/fpga/dfl-pci.c +++ b/drivers/fpga/dfl-pci.c @@ -125,15 +125,6 @@ static int cci_init_drvdata(struct pci_dev *pcidev) return 0; } =20 -static void cci_remove_feature_devs(struct pci_dev *pcidev) -{ - struct cci_drvdata *drvdata =3D pci_get_drvdata(pcidev); - - /* remove all children feature devices */ - dfl_fpga_feature_devs_remove(drvdata->cdev); - cci_pci_free_irq(pcidev); -} - static int *cci_pci_create_irq_table(struct pci_dev *pcidev, unsigned int = nvec) { unsigned int i; @@ -425,10 +416,11 @@ static int cci_pci_sriov_configure(struct pci_dev *pc= idev, int num_vfs) =20 static void cci_pci_remove(struct pci_dev *pcidev) { - if (dev_is_pf(&pcidev->dev)) - cci_pci_sriov_configure(pcidev, 0); + struct cci_drvdata *drvdata =3D pci_get_drvdata(pcidev); =20 - cci_remove_feature_devs(pcidev); + /* remove all children feature devices */ + dfl_fpga_feature_devs_remove(drvdata->cdev); + cci_pci_free_irq(pcidev); } =20 static struct pci_driver cci_pci_driver =3D { @@ -437,6 +429,7 @@ static struct pci_driver cci_pci_driver =3D { .probe =3D cci_pci_probe, .remove =3D cci_pci_remove, .sriov_configure =3D cci_pci_sriov_configure, + .managed_sriov =3D true, }; =20 module_pci_driver(cci_pci_driver); --=20 2.52.0 From nobody Sun Feb 8 16:33:40 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 60CBD32E6B0 for ; Thu, 5 Feb 2026 21:00:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770325231; cv=none; b=HGquAix99RLuYNNo1Cu2b1bi5qK9+zVCT3ZJpBTEr8j+hYvebxxDWPCh0PZ+3Ex4d4EIVKQOGcvcWYsL+EyApcwyLsAQXNk8VDjTuL8KfNRfZj8dFvMa34EePPOtC/nNHqQkDD4YYcYKLc1nUeaZ2tgS+PpqKCx4+eok4OCNUMg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770325231; c=relaxed/simple; bh=riWgsBPSndqsTyNSBaBQnrA0qKc+QrXqhP1pn0jiqnc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=jQSpcVcN+jJS8Qj91iscONT627Ndbt8sS14MSINShTriySjvN/rlck70ZXxUIrHnlBYri0ISMHmdIidLaH3IZ+BYpwlfE+E4uTNeIzMheueMWQukcO7qvCz1e8xlVgmngmyIcgUdYsnp0YeDOrcSrSuViWpozzlzzZ1AAv/cxYA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=H0ZRIEHh; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=iRQ1KruH; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="H0ZRIEHh"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="iRQ1KruH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770325230; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uwZoKA9DaqBTJxMiA47H9MG2vtbRUN7ZZJ7Lzm/5+UE=; b=H0ZRIEHhn9IClltPaBIxuQgNOIgA6n4dMg7V14ZAq9iDdf/u0MZsJ06n8tPw+bOrmAJ/yC OQ12EMW/+jl6mY1PelMIw2sgAkGnM/a6CCkheSuyKR67uWlwy6vRq1tAWHhg7Vr2qINRYH mOUwI4wS+fSjt7r9gujmGj5IBZsV9+w= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-302-601TreE4OUSen6MHAi612g-1; Thu, 05 Feb 2026 16:00:28 -0500 X-MC-Unique: 601TreE4OUSen6MHAi612g-1 X-Mimecast-MFC-AGG-ID: 601TreE4OUSen6MHAi612g_1770325228 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-8947d477a09so47148006d6.2 for ; Thu, 05 Feb 2026 13:00:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1770325228; x=1770930028; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=uwZoKA9DaqBTJxMiA47H9MG2vtbRUN7ZZJ7Lzm/5+UE=; b=iRQ1KruH8WOO+2fOzQQ9ZvO3FqFxJ3BHf7SWNDqyzIIf2UpnEWPece5mi1vIHZLBZx NccuRsIXikfp6Ycsxr7YebXUyNvUIcyFESY+y1GiVC/OQ7UZN9Yqme5nNQuc/UryngQT ns2MUDY18ZDNfhI7tK+LhqYQ6aDNlgGl2TrFWIP8CdYMM1r1H1qHVI9q+O/CWwIoPIfV BF+l36MRKk6Y3yOvUPvDpXvSUIxEqiDQEkR0lbDuSYBnfpMykESfRuMc1oxIC7olLskB rXdr6c32ykv2K08QE39GoSw4B+xAWC/AMqogQ2BHcBY9dWkibXVWqFk6BS6LSoTkVRv/ QmRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770325228; x=1770930028; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=uwZoKA9DaqBTJxMiA47H9MG2vtbRUN7ZZJ7Lzm/5+UE=; b=sJD/AMnMWj3cNWovFCD6LhNLwmfF0AUdrPSNNaAq/D3IsCTZRQNYzLIj1Y38dx7dnX ej7qM02ZIDt50gMS/g+GoQ0hk6rx9WnrmHMxL/Hr5ZvQ3Xi8/V6nMmkTidzH4/4zmDal KDTzn0HjCXQamTzgEeKymdAOxopVQZ8sz8w3fhO2HfUgZdiQ/T8aalT3rtGx6oESgwWB fMIFvCaUUw454EEPqvgLbcW/iwb2R0D2DJOFGZqh14/yIyRsEbqhQc6WP9za9CA0u6V2 RinBQUu4CdEJUQqPK1BG/XkamKwl20+dldbEs9fYptRdFki2VBtwweBOx4HqjmJpc13E VnsQ== X-Forwarded-Encrypted: i=1; AJvYcCV/KRcIswvJfY3vXdOft9jL90IGMrgY+HGnSstTQYYPL1c6zfsR8tMSSI+TDQpsTv336uI8v/HvxC3maKU=@vger.kernel.org X-Gm-Message-State: AOJu0YzpYZEluTHgd03D9JyUEsjP/pMzobR560CAdJ/Vb4l8vNjMoFB9 Lit816bjHWWIZ8X3WTNxCjkR1olmlGFRO1YNmsjzAl78CQpNbEGbX4T7caTq7uJme1XZPmFiWmn xfSw3UbCSn5qt1HGsjq5dOA63iPvJ1NVYcJcFWiar95rpIuvWbilkvz55wV4Bnq5xGw== X-Gm-Gg: AZuq6aIq3iCAD1cU0lagI/D1h0I9SBIbEqwDc0oKeh6RFMaYz13BXcstyEXiUnaq/xJ Viu6+Up8MYiFgGEMFmF08A+3MSnyN4H/RQvCTzRSlzY+EniwAFNOFjHRYxCKdL1OD2JHxCy5sLh RyBlDy9apv7mn/ZZeAS3NPsPCiVtj2PBYQTlwdjwRnPDJLFvonhX11XeJS2/12gbn+4qmu4qIw8 aGNlxdH7mixizzitBVZTaw5ES9HQEM0vA5FibRO6p00TrIliR4T0aQhPR0DiwEcQIKxA92qYy2y kaySNqZjr1Isbyyasb+g/iA89647W9miAV7wBsTsbiRYbcPLT/gycOiBQPHrXtrqevtS9PVKhHN UjebRiF9wGkKof9Q= X-Received: by 2002:ad4:4ea6:0:b0:894:61c8:947f with SMTP id 6a1803df08f44-8953c83ab92mr6627636d6.25.1770325227617; Thu, 05 Feb 2026 13:00:27 -0800 (PST) X-Received: by 2002:ad4:4ea6:0:b0:894:61c8:947f with SMTP id 6a1803df08f44-8953c83ab92mr6626756d6.25.1770325226981; Thu, 05 Feb 2026 13:00:26 -0800 (PST) Received: from [172.16.1.8] ([2607:f2c0:b010:9000:4c85:f148:4c91:943a]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8caf9fdf692sm17571285a.44.2026.02.05.13.00.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Feb 2026 13:00:26 -0800 (PST) From: Peter Colberg Date: Thu, 05 Feb 2026 15:59:50 -0500 Subject: [PATCH v2 03/10] rust: pci: add {enable,disable}_sriov(), to control SR-IOV capability Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260205-rust-pci-sriov-v2-3-ef9400c7767b@redhat.com> References: <20260205-rust-pci-sriov-v2-0-ef9400c7767b@redhat.com> In-Reply-To: <20260205-rust-pci-sriov-v2-0-ef9400c7767b@redhat.com> To: Danilo Krummrich , Bjorn Helgaas , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Abdiel Janulgue , Daniel Almeida , Robin Murphy , Greg Kroah-Hartman , Dave Ertman , Ira Weiny , Leon Romanovsky , David Airlie , Simona Vetter , Jonathan Corbet , Xu Yilun , Tom Rix , Moritz Fischer , "Rafael J. Wysocki" Cc: linux-pci@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Alexandre Courbot , Alistair Popple , Joel Fernandes , John Hubbard , Zhi Wang , nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-doc@vger.kernel.org, linux-fpga@vger.kernel.org, driver-core@lists.linux.dev, Peter Colberg , Jason Gunthorpe X-Mailer: b4 0.14.2 Add methods to enable and disable the Single Root I/O Virtualization (SR-IOV) capability for a PCI device. The wrapped C methods take care of validating whether the device is a Physical Function (PF), whether SR-IOV is currently disabled (or enabled), and whether the number of requested VFs does not exceed the total number of supported VFs. Set the flag managed_sriov to always disable SR-IOV when a Rust PCI driver is unbound from a PF device. This ensures that when a Virtual Function (VF) is bound to a driver, the corresponding Physical Function (PF) is bound to a driver, too, which is a prerequisite for exposing a safe Rust API that allows a VF driver to obtain the PF device for a VF device and subsequently access the private data of the PF driver. Suggested-by: Danilo Krummrich Signed-off-by: Peter Colberg --- Changes in v2: - Set flag managed_sriov to disable SR-IOV on remove(). - Use to_result() to handle error in enable_sriov(). - Note Bound device context in SAFETY comments. --- rust/kernel/pci.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs index af74ddff6114db3c2ce8e228c5a953cd0769e8a5..e1cab1574a3d309d25bf5267c0b= 0d8da8fb66d44 100644 --- a/rust/kernel/pci.rs +++ b/rust/kernel/pci.rs @@ -82,6 +82,7 @@ unsafe fn register( (*pdrv.get()).probe =3D Some(Self::probe_callback); (*pdrv.get()).remove =3D Some(Self::remove_callback); (*pdrv.get()).id_table =3D T::ID_TABLE.as_ptr(); + (*pdrv.get()).managed_sriov =3D true; } =20 // SAFETY: `pdrv` is guaranteed to be a valid `DriverType`. @@ -458,6 +459,38 @@ pub fn set_master(&self) { // SAFETY: `self.as_raw` is guaranteed to be a pointer to a valid = `struct pci_dev`. unsafe { bindings::pci_set_master(self.as_raw()) }; } + + /// Enable the Single Root I/O Virtualization (SR-IOV) capability for = this device, + /// where `nr_virtfn` is number of Virtual Functions (VF) to enable. + #[cfg(CONFIG_PCI_IOV)] + pub fn enable_sriov(&self, nr_virtfn: i32) -> Result { + // SAFETY: + // `self.as_raw` returns a valid pointer to a `struct pci_dev`. + // + // `pci_enable_sriov()` checks that the enable operation is valid: + // - the device is a Physical Function (PF), + // - SR-IOV is currently disabled, and + // - `nr_virtfn` does not exceed the total number of supported VFs. + // + // The Core device context inherits from the Bound device context, + // which guarantees that the PF device is bound to a driver. + to_result(unsafe { bindings::pci_enable_sriov(self.as_raw(), nr_vi= rtfn) }) + } + + /// Disable the Single Root I/O Virtualization (SR-IOV) capability for= this device. + #[cfg(CONFIG_PCI_IOV)] + pub fn disable_sriov(&self) { + // SAFETY: + // `self.as_raw` returns a valid pointer to a `struct pci_dev`. + // + // `pci_disable_sriov()` checks that the disable operation is vali= d: + // - the device is a Physical Function (PF), and + // - SR-IOV is currently enabled. + // + // The Core device context inherits from the Bound device context, + // which guarantees that the PF device is bound to a driver. + unsafe { bindings::pci_disable_sriov(self.as_raw()) }; + } } =20 // SAFETY: `pci::Device` is a transparent wrapper of `struct pci_dev`. --=20 2.52.0 From nobody Sun Feb 8 16:33:40 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 4BE44330B3B for ; Thu, 5 Feb 2026 21:00:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770325232; cv=none; b=i8bACQbu4+9jFVuPURP10qkmjLCMSC2rcoQUh8+eHEpl8hkd2em27BGk3yv/TxJlI5UrfkBrhhGgfdwigmlvunMtq47MUBKT0PoF1E9SliE32wGx6bNGPQxFvaz/oYRkp1wt4pbcLt2HwnBrOLcFhCi0wb9/iwDsT2CwWLFy/KY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770325232; c=relaxed/simple; bh=jkpwy4GP+toHnd9AMJZipLXyNcEvG6BNgGl4osE5Tb4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=p8CTAv+hrPD1SnHZpGCmvzSDCQnoSgAiX/4/PDh76vKpyzBuH6qqJ1Ok0a79PmNtnAWX7D9RP2MbGXJPAW0XKnZiYFbUyIbGuguAxevZ09MmQPucbBTVFDcSSTsyed3onlKXbbldOUmYbDzIXfDLBndPx5//tbS6fCsViCfWSQs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=hzqmQK0C; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=JAnT6UMa; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="hzqmQK0C"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="JAnT6UMa" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770325231; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ADQ8gPT48rFRIIyS12cDuNBpt1e1vav+7FNrnrbDyrE=; b=hzqmQK0CNvw3Cu+thmIafXiIRu6LYRd9MaV1VLxPVbQp+UHewitiTiJdIpsAuVCCruhsb0 jwjBpTuqadazh0fQwMiSviFysQ7ofSMaiTcFL+MAZbppJsoKmwUdRagIpLpbOmeqGSid+A swy7nAsk5UhoimflF1ZEE9ezCMp+UNE= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-80-1Trd43CqN5aMR3ygXPljWQ-1; Thu, 05 Feb 2026 16:00:30 -0500 X-MC-Unique: 1Trd43CqN5aMR3ygXPljWQ-1 X-Mimecast-MFC-AGG-ID: 1Trd43CqN5aMR3ygXPljWQ_1770325230 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-8c70e610242so380967785a.2 for ; Thu, 05 Feb 2026 13:00:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1770325230; x=1770930030; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=ADQ8gPT48rFRIIyS12cDuNBpt1e1vav+7FNrnrbDyrE=; b=JAnT6UMaNIA9JW4/9YywS/xvrZb4nwmW5NiyPOLO8yVQSY+mdc8d3gqkqAOZqP/MAY +Q/GL31jy3sc5qJ5UI+lsh9kSb86w3cJ82EjvVMerNxNPgjxAGWsa2SRKBZ4o1w4qsyK C9bJlasRoEWQSammJg9CGCwCi8n+mRfqnhESsE6qnI/9+TrkGrQy1HjjHfWZh3B/d/Dp 8u37WFqfkvjVVe9qHYMgRLdwAmcyc48H5wYe5WcmgDxWdu5rQWgorZb38wxBHLO43lNX jAE/Mpbv+2mz/klOPrR68r+XLPysPlgWp6tXoze7oc41ooP4y5XuI2uduf8M3wlBzm35 mz6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770325230; x=1770930030; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=ADQ8gPT48rFRIIyS12cDuNBpt1e1vav+7FNrnrbDyrE=; b=Zu/vSO7tMcCQb7q3hBT6WTCnus3/ohcxyEoLuDnkyTg11LC0xbBTz15R2guwPDY3Gj vOEApumhzonkyK95+LRjAxBpxw1hsDiTfF+vzxvpLpw4EJiuw3MBshbIMbTV7Q5lcQc2 0tLXAXkzg15JsoQqSqQBKg0z2JVtQ90YReSaO+SgSk+SIb3CIiX/Cj20UDACnbIiik4u jHV//F6yk69cilZaRDLTjplyg4mHVZa1Fcef9jH9pWJkMhLfQ9rjRcCjGjQYvmd7McwU sOeiSaRKOg4S+XoPjN6qTE5ExyGdys6wD2lB9QwZt8DulIpr6mgwdMBpqcWk0VjIbaSI I0Xw== X-Forwarded-Encrypted: i=1; AJvYcCV9LJIbgdqSFgk0zjTloeil/IEXTsRpOfY8NHDIqKPe7DcfoQXHhbw+VqEheEMEkIc0VkdthONv8stjscU=@vger.kernel.org X-Gm-Message-State: AOJu0Yx+TXxfeKZaze4y5BxLf2m6l43Ome9Dx3+9xXMQbmZfEMyN+Bh8 huAVVyVe+tiD8eAZ3kG5DExhFgprIdE7oZpsQFnmQOAQhpCP6NxUhAQSooI4K87WPU4TAYM0WsL p/TmTpINuUb/PfFiPGwAEBsqnNMJnISMl1BTDFJqhABNjwlX9uI1rZQl8BPz9F7xV2GJxL9kVlg == X-Gm-Gg: AZuq6aK0uIYkRK4+PqOOuDvpPNmsw3J3SMzzAIxIL488s873U4+5KjiTEhYNfqv4Omu 3+oraHxbW7kZl11hSnQ+Mlzgul0E2z3JO3dAU9SOklpwusjgJ/98cM5vx3lw39biPM4HSHurbU+ DGDyXFUWwOsWF4YHqp97yjEzDOlxher9tgOg15zJrLKbtRRuYanz4pprD/pI5j+72PCrDPTSSET 236LqVV6p1STDvmDAX/ilyogYZ9CaRD+T2/IasXqF6hDqcSOpye/EE+tS875BVGj2vqy4rPfR9Y c2IdEUL3rXqyIj/5kwnUHCuTPVgMGb71QtRatzBLUY/g30G86Qf7IEHqo5vRCCz7xovsqZodl6X Prda4PMfjJSQTvg0= X-Received: by 2002:a05:620a:28cf:b0:8ca:d5cb:6842 with SMTP id af79cd13be357-8caf0c44afdmr60948285a.44.1770325229802; Thu, 05 Feb 2026 13:00:29 -0800 (PST) X-Received: by 2002:a05:620a:28cf:b0:8ca:d5cb:6842 with SMTP id af79cd13be357-8caf0c44afdmr60935085a.44.1770325228925; Thu, 05 Feb 2026 13:00:28 -0800 (PST) Received: from [172.16.1.8] ([2607:f2c0:b010:9000:4c85:f148:4c91:943a]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8caf9fdf692sm17571285a.44.2026.02.05.13.00.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Feb 2026 13:00:28 -0800 (PST) From: Peter Colberg Date: Thu, 05 Feb 2026 15:59:51 -0500 Subject: [PATCH v2 04/10] rust: pci: add vtable attribute to pci::Driver trait Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260205-rust-pci-sriov-v2-4-ef9400c7767b@redhat.com> References: <20260205-rust-pci-sriov-v2-0-ef9400c7767b@redhat.com> In-Reply-To: <20260205-rust-pci-sriov-v2-0-ef9400c7767b@redhat.com> To: Danilo Krummrich , Bjorn Helgaas , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Abdiel Janulgue , Daniel Almeida , Robin Murphy , Greg Kroah-Hartman , Dave Ertman , Ira Weiny , Leon Romanovsky , David Airlie , Simona Vetter , Jonathan Corbet , Xu Yilun , Tom Rix , Moritz Fischer , "Rafael J. Wysocki" Cc: linux-pci@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Alexandre Courbot , Alistair Popple , Joel Fernandes , John Hubbard , Zhi Wang , nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-doc@vger.kernel.org, linux-fpga@vger.kernel.org, driver-core@lists.linux.dev, Peter Colberg , Jason Gunthorpe X-Mailer: b4 0.14.2 Add the #[vtable] attribute to pci::Driver trait and implementations, to prepare a subsequent patch that adds an optional bus callback sriov_configure() to enable or disable the SR-IOV capability. Suggested-by: Danilo Krummrich Signed-off-by: Peter Colberg --- Changes in v2: - Add missing #[vtable] attribute in PCI driver trait example. - Add missing #[vtable] attribute in nova-core driver. --- drivers/gpu/nova-core/driver.rs | 1 + rust/kernel/pci.rs | 2 ++ samples/rust/rust_dma.rs | 1 + samples/rust/rust_driver_auxiliary.rs | 1 + samples/rust/rust_driver_pci.rs | 1 + 5 files changed, 6 insertions(+) diff --git a/drivers/gpu/nova-core/driver.rs b/drivers/gpu/nova-core/driver= .rs index b8b0cc0f2d93599358c8cd6562d23c27e4654a87..3944077adf550ac91422ca1cb23= 5365b8502586e 100644 --- a/drivers/gpu/nova-core/driver.rs +++ b/drivers/gpu/nova-core/driver.rs @@ -65,6 +65,7 @@ pub(crate) struct NovaCore { ] ); =20 +#[vtable] impl pci::Driver for NovaCore { type IdInfo =3D (); const ID_TABLE: pci::IdTable =3D &PCI_TABLE; diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs index e1cab1574a3d309d25bf5267c0b0d8da8fb66d44..a4c27c674bd8bdf5e3316789d38= d566e90b93fe2 100644 --- a/rust/kernel/pci.rs +++ b/rust/kernel/pci.rs @@ -278,6 +278,7 @@ macro_rules! pci_device_table { /// ] /// ); /// +/// #[vtable] /// impl pci::Driver for MyDriver { /// type IdInfo =3D (); /// const ID_TABLE: pci::IdTable =3D &PCI_TABLE; @@ -292,6 +293,7 @@ macro_rules! pci_device_table { ///``` /// Drivers must implement this trait in order to get a PCI driver registe= red. Please refer to the /// `Adapter` documentation for an example. +#[vtable] pub trait Driver: Send { /// The type holding information about each device id supported by the= driver. // TODO: Use `associated_type_defaults` once stabilized: diff --git a/samples/rust/rust_dma.rs b/samples/rust/rust_dma.rs index 9c45851c876ef33414eb0071c42a2fb4ac3f1e78..ae6f7328b830e32bcaf7f8b5f8b= 1f117135ebf8e 100644 --- a/samples/rust/rust_dma.rs +++ b/samples/rust/rust_dma.rs @@ -51,6 +51,7 @@ unsafe impl kernel::transmute::FromBytes for MyStruct {} [(pci::DeviceId::from_id(pci::Vendor::REDHAT, 0x5), ())] ); =20 +#[vtable] impl pci::Driver for DmaSampleDriver { type IdInfo =3D (); const ID_TABLE: pci::IdTable =3D &PCI_TABLE; diff --git a/samples/rust/rust_driver_auxiliary.rs b/samples/rust/rust_driv= er_auxiliary.rs index c20961f168356c6bbe0faefc0079d7a90b013684..67a17f4b4657b5f91a4fc603ca7= 025478d79df2d 100644 --- a/samples/rust/rust_driver_auxiliary.rs +++ b/samples/rust/rust_driver_auxiliary.rs @@ -66,6 +66,7 @@ struct ParentDriver { [(pci::DeviceId::from_id(pci::Vendor::REDHAT, 0x5), ())] ); =20 +#[vtable] impl pci::Driver for ParentDriver { type IdInfo =3D (); =20 diff --git a/samples/rust/rust_driver_pci.rs b/samples/rust/rust_driver_pci= .rs index 4dfb8a6a47077d2c565b09f7c7822f7f5e2641c8..fe4db08d42a74abb5865c759682= 49b58bedc01fd 100644 --- a/samples/rust/rust_driver_pci.rs +++ b/samples/rust/rust_driver_pci.rs @@ -92,6 +92,7 @@ fn config_space(pdev: &pci::Device) { } } =20 +#[vtable] impl pci::Driver for SampleDriver { type IdInfo =3D TestIndex; =20 --=20 2.52.0 From nobody Sun Feb 8 16:33:40 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 89A38332EDD for ; Thu, 5 Feb 2026 21:00:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770325236; cv=none; b=XmnwDKUOyCus2+nXUND9nGKrZUh1qRWWJ1bES5L5J+xNkfaLI8Ol+nGf+nf9apAc2qhB9TBHUfH6f62RSSG0kHUqB+/Ro3yOMKXWs7ylSr+rguUjsLRMg8XWn3tNBeXQoiFczCVL+P+JBPVKZbS3s9Hz6V/NRiAdeD1kba+SqqE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770325236; c=relaxed/simple; bh=mGjHnViOpaBiawwKiFLL50tHLKnItFMnpZghT+ZkbZU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=axuTIYiZrD3xde40G9GHdtcQhmj7lJqGvCaShJ70QbhWztNyQA4OuBtWDox2aeHTKMtz6r6EZ0Mvx/4oxs+rEo74pTscueQhGcMj+Sq7dk5H/X7llH+dKggIePQ2NuRbtGy6Jro/Ojrz1MoRAGoRhdP5lLZPj3AvZOPFTatyzh0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=BkR6J3qx; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=NyH4KrWd; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="BkR6J3qx"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="NyH4KrWd" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770325235; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uO9Iu/KQjA0pe5Uf917htRnrSxjGLQG0IESxKRcUlqo=; b=BkR6J3qxMh/xW/fYGRiRqIKN6RxaOCkv+xwYzN2Z1uTge58PmFwQHOR6Gv8v6Eym1mGTB2 DwKN2yI8T+wj9Du0l8KIWMGNA8v8u6UAbLXPnFsBAr4Oet/zrpDofqQ+zM+TsjfBVTLqHL okDU7i0MmY43yoCJ93N2ENZcqs4NsTc= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-434-0EHZsyjJNU6pyON6z_rAbQ-1; Thu, 05 Feb 2026 16:00:34 -0500 X-MC-Unique: 0EHZsyjJNU6pyON6z_rAbQ-1 X-Mimecast-MFC-AGG-ID: 0EHZsyjJNU6pyON6z_rAbQ_1770325234 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-8c7166a4643so399880185a.0 for ; Thu, 05 Feb 2026 13:00:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1770325234; x=1770930034; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=uO9Iu/KQjA0pe5Uf917htRnrSxjGLQG0IESxKRcUlqo=; b=NyH4KrWd6cNBomc8qRF6hx6sAp1857MB7L0Ph/btt9d++Nxjm1FeiL8WsvTLTCUWcH uXzcYcylzL/QJDuTFBx0tO3Sk8PM++945NqeW1j5NG8IDVXM2rlTCwEBR0LITTlOF+f6 a4QzmGV4gY2wTSMmAf5P55/+sLvEdIl7q9WsqjUJU5OkeV//n6C+rYilwASX7sx6DuyC zo/47iuc5EJzXjkAWEczYQBPXXnpQqyjY8nm9V3vKUVzqJ8+L58hDooDq3JHH7zF2OsX R0lIjhiyg6CQvb1Adyuft8MPNTN45z5SZj0NOi7Molf7Qb1VPrXzNGgf3uwUmVo8W3H8 LCyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770325234; x=1770930034; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=uO9Iu/KQjA0pe5Uf917htRnrSxjGLQG0IESxKRcUlqo=; b=Gs60kVor7xuIQcZh1Sw43m1ZSW/STvioKrxEAoKdsEluff9m9OcaQVV+MLlp8wkLKd P0Pyf7O8Gzu7ZxCsyCtAg18cImg6ZK+SgiTBqB7lzXFytxZ8vXIhziuME0yTynYj9aP/ UrVCUJhIUrdepy2uLCC3R+5WSuj1dItv1boJ98yLj54ditM0I8SrrLpqQdHNWLhgPdJw OSnEji4ic0h275Klhb57lT4wLUTuISndKnVvrBQ4/N3ASpKe23Fo3u8yHCPf1UkUrcFA Km2h7EjgrAtELWfSr/lQv6UBykP6Lxlddh7mfkMOpEaMPp5V9HMnbyba3ysDqNjeIcqM Jvfg== X-Forwarded-Encrypted: i=1; AJvYcCVcxbZaN3mt4fd60nosy6CkMeQAHJLDs6yHu+JxQIHAf0DsBNcxX5mIRHHveMjcpD3PQEK+egAoqZzSijw=@vger.kernel.org X-Gm-Message-State: AOJu0Yy2BfXm1R96ZHxJC9ja1eQgZxhl/6BdDnUtyxIcDTsxIoxDTUPm w5kcENIcXDFEUsec9Jpojt22amu9ZajQCyUNlCoUL8Y5Ncfqwr3Q/ZLvr/CfW2Yh4LEeLonTGSP wLv4/LtWrrp+e+Zx5g9xCix1aW88HfyS+c0Oy7werkiFCuuUD8nuzk/3aG2scBTEETQ== X-Gm-Gg: AZuq6aKD+4WwjpCz6QPTZzLMsAWWTxRFdXWd9HeS5hn/lqavn+K29p6q9hiPLV+AQAo 9zFRkc7iEwouC5awZdr5Qwxe7l2KkZiNnSI2bXBgtbdCRAtdJhGghRdt06hCVGOTEyQ1g/kY/5s S5bcw5PDQ3/XYXZVrMKqLVtJV0lb8PYI2iKIQH9aLfQXjKfJ3HxBr4SO8zm3h/LLtAXGe9+Eql6 4w0LcO2Omrjum8M/bd6GuHWXRSK48y8TNpJwv1W9sEA9b/jJfK8QWqGlu5bQTaGdLUs+gnPfqr9 GsiXPIEFa4sy8aB+Fuq1Fy7rQRLiFg/6dUd3g6w3Y7a6FAwvTTgcYxek5kEXUrOGCpWAuKCu2RG EPcpulVekxbaP5JQ= X-Received: by 2002:a05:620a:bc9:b0:8b2:f35c:16df with SMTP id af79cd13be357-8caf1bc2af6mr57816285a.79.1770325232255; Thu, 05 Feb 2026 13:00:32 -0800 (PST) X-Received: by 2002:a05:620a:bc9:b0:8b2:f35c:16df with SMTP id af79cd13be357-8caf1bc2af6mr57795985a.79.1770325230865; Thu, 05 Feb 2026 13:00:30 -0800 (PST) Received: from [172.16.1.8] ([2607:f2c0:b010:9000:4c85:f148:4c91:943a]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8caf9fdf692sm17571285a.44.2026.02.05.13.00.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Feb 2026 13:00:30 -0800 (PST) From: Peter Colberg Date: Thu, 05 Feb 2026 15:59:52 -0500 Subject: [PATCH v2 05/10] rust: pci: add bus callback sriov_configure(), to control SR-IOV from sysfs Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260205-rust-pci-sriov-v2-5-ef9400c7767b@redhat.com> References: <20260205-rust-pci-sriov-v2-0-ef9400c7767b@redhat.com> In-Reply-To: <20260205-rust-pci-sriov-v2-0-ef9400c7767b@redhat.com> To: Danilo Krummrich , Bjorn Helgaas , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Abdiel Janulgue , Daniel Almeida , Robin Murphy , Greg Kroah-Hartman , Dave Ertman , Ira Weiny , Leon Romanovsky , David Airlie , Simona Vetter , Jonathan Corbet , Xu Yilun , Tom Rix , Moritz Fischer , "Rafael J. Wysocki" Cc: linux-pci@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Alexandre Courbot , Alistair Popple , Joel Fernandes , John Hubbard , Zhi Wang , nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-doc@vger.kernel.org, linux-fpga@vger.kernel.org, driver-core@lists.linux.dev, Peter Colberg , Jason Gunthorpe X-Mailer: b4 0.14.2 Add an optional bus callback sriov_configure() to pci::Driver trait, using the vtable attribute to query if the driver implements the callback. The callback is invoked when a user-space application writes the number of VFs to the sysfs file `sriov_numvfs` to enable SR-IOV, or zero to disable SR-IOV for a PCI device. Suggested-by: Danilo Krummrich Signed-off-by: Peter Colberg --- rust/kernel/pci.rs | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 56 insertions(+) diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs index a4c27c674bd8bdf5e3316789d38d566e90b93fe2..88bd114970431bf8c3edef94c1d= 48567d895eaf6 100644 --- a/rust/kernel/pci.rs +++ b/rust/kernel/pci.rs @@ -83,6 +83,10 @@ unsafe fn register( (*pdrv.get()).remove =3D Some(Self::remove_callback); (*pdrv.get()).id_table =3D T::ID_TABLE.as_ptr(); (*pdrv.get()).managed_sriov =3D true; + #[cfg(CONFIG_PCI_IOV)] + if T::HAS_SRIOV_CONFIGURE { + (*pdrv.get()).sriov_configure =3D Some(Self::sriov_configu= re_callback); + } } =20 // SAFETY: `pdrv` is guaranteed to be a valid `DriverType`. @@ -135,6 +139,20 @@ extern "C" fn remove_callback(pdev: *mut bindings::pci= _dev) { =20 T::unbind(pdev, data); } + + #[cfg(CONFIG_PCI_IOV)] + extern "C" fn sriov_configure_callback( + pdev: *mut bindings::pci_dev, + nr_virtfn: c_int, + ) -> c_int { + // SAFETY: The PCI bus only ever calls the sriov_configure callbac= k with a valid pointer to + // a `struct pci_dev`. + // + // INVARIANT: `pdev` is valid for the duration of `sriov_configure= _callback()`. + let pdev =3D unsafe { &*pdev.cast::>(= ) }; + + from_result(|| T::sriov_configure(pdev, nr_virtfn)) + } } =20 /// Declares a kernel module that exposes a single PCI driver. @@ -325,6 +343,44 @@ pub trait Driver: Send { fn unbind(dev: &Device, this: Pin<&Self>) { let _ =3D (dev, this); } + + /// Single Root I/O Virtualization (SR-IOV) configure. + /// + /// Called when a user-space application enables or disables the SR-IO= V capability for a + /// [`Device`] by writing the number of Virtual Functions (VF), `nr_vi= rtfn` or zero to the + /// sysfs file `sriov_numvfs` for this device. Implementing this callb= ack is optional. + /// + /// Further, and unlike for a PCI driver written in C, when a PF devic= e with enabled VFs is + /// unbound from its bound [`Driver`], the `sriov_configure()` callbac= k is invoked to disable + /// SR-IOV before the `unbind()` callback. This guarantees that when a= VF device is bound to a + /// driver, the underlying PF device is bound to a driver, too. + /// + /// Upon success, this callback must return the number of VFs that wer= e enabled, or zero if + /// SR-IOV was disabled. + /// + /// See [PCI Express I/O Virtualization]. + /// + /// [PCI Express I/O Virtualization]: https://docs.kernel.org/PCI/pci-= iov-howto.html + /// + /// # Examples + /// + /// ``` + /// # use kernel::{device::Core, pci, prelude::*}; + /// #[cfg(CONFIG_PCI_IOV)] + /// fn sriov_configure(dev: &pci::Device, nr_virtfn: i32) -> Res= ult { + /// if nr_virtfn =3D=3D 0 { + /// dev.disable_sriov(); + /// } else { + /// dev.enable_sriov(nr_virtfn)?; + /// } + /// Ok(nr_virtfn) + /// } + /// ``` + #[cfg(CONFIG_PCI_IOV)] + fn sriov_configure(dev: &Device, nr_virtfn: i32) -> Resu= lt { + let _ =3D (dev, nr_virtfn); + build_error!(crate::error::VTABLE_DEFAULT_ERROR) + } } =20 /// The PCI device representation. --=20 2.52.0 From nobody Sun Feb 8 16:33:40 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 3527A332EB9 for ; Thu, 5 Feb 2026 21:00:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770325236; cv=none; b=uKRciaKtmlb8+RfuSAdw0VhZHBq9bFgAm70TVk1woE4EvEYzLb+mj1c95RFnrzUoWJIA5BX9V3qrkn7SsyWMXsNZul+QkalPHDHqRe64ARztG6Vdj48zaNEnHeSqPTl1mxNACAEAL9iFUi4Cn0VyB/X3h9w2cli0q1eMHiHPIqU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770325236; c=relaxed/simple; bh=goR6NT6+KiuW9XKjlJCHBNrcq9pPIxNj+WVW2jrpGs0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=CPih7aET46CHQITJPXXCREGGKsX9vg8cqSzGJiEE8NJdX54ZidI6i99lX8UvUFE2OMn0bkhgSGqfW2sJp+L3fFMLLMd6Ori+uqPjtRELeA0Xwk/ZxKuwq2V+mRdowhMC7cq/VVWPx84owtkQmN60PX3cBk4kiR9xUtcH2RWaeiE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=B838K7RV; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=QbJ6YRsm; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="B838K7RV"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="QbJ6YRsm" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770325235; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qEZ/NIGEd7tvljUjuiPoVXU22CsIWWTrf8BQDchgWf0=; b=B838K7RVZ3xvEyVUrLjkRi2Mv926uLlnBlH/Jc+7jGLN2q9RyTqfAOEt0Iijwy4e4UWe+/ 9A1FMzTVr3CXgWlv+YhyVsuT+/E/7MWpaLVaLcs3rIMKqYD3HWBhYz7BGsryJG8T4yAFcO TDiiEu0dxWIQfEmkXWXxiBMqaySVAWU= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-332-9bw-SOxMPnynmPFMYWATwQ-1; Thu, 05 Feb 2026 16:00:34 -0500 X-MC-Unique: 9bw-SOxMPnynmPFMYWATwQ-1 X-Mimecast-MFC-AGG-ID: 9bw-SOxMPnynmPFMYWATwQ_1770325233 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-894766748f9so85881886d6.1 for ; Thu, 05 Feb 2026 13:00:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1770325233; x=1770930033; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=qEZ/NIGEd7tvljUjuiPoVXU22CsIWWTrf8BQDchgWf0=; b=QbJ6YRsm+Bp7e4TG7/79hxn8+evKLC73comgETOLNF75gBfZwyaiE4g0SzGd9tA0AV Kn02G4hDOALkgCDanHrG9Gy43LVj8eTuRJyGbM1jzJn/+ECbEmhNJ82hFDUGHQ3evob6 07CuUDOxhefiwxG6+iVC0ykQJpIRbSDvy0HU/ohlxB+kAiBH4MPHfN8f5RKfklXKZau4 Rqrd6apfjGELR/SVIxtKbz4q1SB2OjAa+jLDxJVhrY3HuvxLhWVG4KWNia9kY0X9IVp9 I0R4IR4xHmYbGX4nHoblTYQjJ/UPOETOJcpg1i4p+taieciQ+fungMNd/LQlG7UnzpHo vkNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770325233; x=1770930033; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=qEZ/NIGEd7tvljUjuiPoVXU22CsIWWTrf8BQDchgWf0=; b=gmZjxRYSe/hxzSuQUpk6u/7c+KBwZQOs+hcBBxkTxBoSP3DyKCVXOVbIpmF+TrWf9E teMHQ2GIAy5iLij2w3+YRVeCvdAL8JiBp7t3lnoAdZ43BzAs5P0UD150mjNInl30jjjO 0X/uTrLgPl49HRQ9BPd0XOTGDzocpdeDlcoxsnu9wufRRpMK2znIqwfzw7m7915ukeyv SroJ9WdiSXn309oDSYS94OSMLzl0QJGZMXyVd2BMO1iBRYzqSibMKfuf5aflo7JmxRyL Y62RohbjNc2LVpLf6ew8s0a/SumfbJ8LVFnRnHkXhFMrwKyp0BiPex310oDqqFWhtwM2 AfGw== X-Forwarded-Encrypted: i=1; AJvYcCXBtGL1MV83F4jdxKXU/8e3HPwZKFT2xp/gdb3rpBVqgPDDrQ0Pph49JfN3x80eWN06UtY6nSXo3xmqJLg=@vger.kernel.org X-Gm-Message-State: AOJu0YzN0o2QGXNlAnN8gOeUcbpzaSDWTmrWCmfuO2/HxI5tgsiYBdKs 9M6bXPGu1HPRn6dWffzDTSv+lhR/FgGUL5ctlJcv4bHdRPhksTBmu4AfkfEwpfiZa8/qcnelw21 zjxv1MYgTOYpGAlXFqRGW+aL1vicPVTmvVy5JQPfoO7vt9DrNk8ISTRRkDevN24bSWw== X-Gm-Gg: AZuq6aLu4rOnWS24nQJphzBr193rOvw2QlfvR+o/+HY90vjRyLMC1bVU1h6oCy2m6om bb233xHt/K/nVVeauyppvO8ndHHcIm/S+xMtJyUdrB5Jks6opRPrm1ENube6Oy0AliHthv+5k5k EjREU1czTHYTEB/rggiNGsgOg5KCJCbx8iHNE3jh1Pm/iw1+v1LSRT49WOyVnxr0hTKoxVbMcZs KvNqOpvi4fH392HtPkPIEuYuVMj8ajS0vRCQCowrxXr2ioUDgVJkumndH4jmX4bfO196fuGeQ5u fBVXdwsZkIFmowzyXa5x9rfeWdztcc1WM0xJ+Wxz7LeMKCDz8HNj0B4vGzqK86yddll3Fw6Qjif TPRmBbpJPwY1xclU= X-Received: by 2002:a05:6214:4017:b0:88a:3681:1d96 with SMTP id 6a1803df08f44-8953cd9c94fmr5941876d6.63.1770325233451; Thu, 05 Feb 2026 13:00:33 -0800 (PST) X-Received: by 2002:a05:6214:4017:b0:88a:3681:1d96 with SMTP id 6a1803df08f44-8953cd9c94fmr5941106d6.63.1770325232827; Thu, 05 Feb 2026 13:00:32 -0800 (PST) Received: from [172.16.1.8] ([2607:f2c0:b010:9000:4c85:f148:4c91:943a]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8caf9fdf692sm17571285a.44.2026.02.05.13.00.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Feb 2026 13:00:32 -0800 (PST) From: Peter Colberg Date: Thu, 05 Feb 2026 15:59:53 -0500 Subject: [PATCH v2 06/10] rust: pci: add is_virtfn(), to check for VFs Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260205-rust-pci-sriov-v2-6-ef9400c7767b@redhat.com> References: <20260205-rust-pci-sriov-v2-0-ef9400c7767b@redhat.com> In-Reply-To: <20260205-rust-pci-sriov-v2-0-ef9400c7767b@redhat.com> To: Danilo Krummrich , Bjorn Helgaas , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Abdiel Janulgue , Daniel Almeida , Robin Murphy , Greg Kroah-Hartman , Dave Ertman , Ira Weiny , Leon Romanovsky , David Airlie , Simona Vetter , Jonathan Corbet , Xu Yilun , Tom Rix , Moritz Fischer , "Rafael J. Wysocki" Cc: linux-pci@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Alexandre Courbot , Alistair Popple , Joel Fernandes , John Hubbard , Zhi Wang , nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-doc@vger.kernel.org, linux-fpga@vger.kernel.org, driver-core@lists.linux.dev, Peter Colberg , Jason Gunthorpe X-Mailer: b4 0.14.2 From: John Hubbard Add a method to check if a PCI device is a Virtual Function (VF) created through Single Root I/O Virtualization (SR-IOV). Signed-off-by: John Hubbard Reviewed-by: Alistair Popple Reviewed-by: Joel Fernandes Signed-off-by: Peter Colberg --- Changes in v2: - Add #[inline] to is_virtfn(). This patch was originally part of the series "rust: pci: expose is_virtfn() and reject VFs in nova-core" and modified as follows: - Replace true -> `true` in doc comment. - Shorten description and omit justification specific to nova-core. Link: https://lore.kernel.org/rust-for-linux/20250930220759.288528-2-jhubba= rd@nvidia.com/ --- rust/kernel/pci.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs index 88bd114970431bf8c3edef94c1d48567d895eaf6..db05641186c3a42922e2b6a463d= e9c1b099a4673 100644 --- a/rust/kernel/pci.rs +++ b/rust/kernel/pci.rs @@ -484,6 +484,13 @@ pub fn resource_start(&self, bar: u32) -> Result { Ok(unsafe { bindings::pci_resource_start(self.as_raw(), bar.try_in= to()?) }) } =20 + /// Returns `true` if this device is a Virtual Function (VF). + #[inline] + pub fn is_virtfn(&self) -> bool { + // SAFETY: `self.as_raw` is a valid pointer to a `struct pci_dev`. + unsafe { (*self.as_raw()).is_virtfn() !=3D 0 } + } + /// Returns the size of the given PCI BAR resource. pub fn resource_len(&self, bar: u32) -> Result { if !Bar::index_is_valid(bar) { --=20 2.52.0 From nobody Sun Feb 8 16:33:40 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 3866B33372D for ; Thu, 5 Feb 2026 21:00:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770325238; cv=none; b=IzLmvdHkGI30Ng2qcFrI8qOdzr+5t/dKx54v2VJC2KO7l3V8SmMXIyHbVtz85jlL+YrkTdV70SVkQi40yQhaVmWwbuo8h7FkubvgUbyd7DTsjBWxUG1J/osphQ0NdKtEzQhxba64ZLqsmerokNTUjPzuRY9OosE+c6LNy0JTZOk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770325238; c=relaxed/simple; bh=0n3HUB5a0dbq5Vp3zcn3fKughLCja0FW1cbYz+y6V0c=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=s76I0HDm4IeOxgHA/g3J6HYoWCl+h4aRqxsWPr7GNH/DKCJLAcEF2K0MPaYZ5v+J/8QMYupOqEvH5D4i4WIR7iOH1ocCa7DvUReO+M4huSaUj7uV0V3A1QEGpmk0NZag5ex+999SCj4PlGIN8Zi+RBo1qQDQhmPdKJbKiCT5l0c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=S5Bnq9Zw; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=DJRyOtFk; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="S5Bnq9Zw"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="DJRyOtFk" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770325237; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2gGPFCPOPX/fBbf5qQfZiwEzewT+3Ulk7LVkRWF8dEo=; b=S5Bnq9ZwrCaHAWjhsveZG8+FeBF8WPKG05djIc2YY5sjWU6PJ0DHkEWWaVjkacvJCpynza colUDhZgNV1Sk5epkD4tZQYrlGbgMatF1pFQHGAiwfNxm3ZFpsGLxkHFkuj/Bnsg5vyW12 s01Crg7fOXDOmkXzS14aVhhxR3PUFtM= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-151-62MG920-OhyA25GLwDCv_w-1; Thu, 05 Feb 2026 16:00:36 -0500 X-MC-Unique: 62MG920-OhyA25GLwDCv_w-1 X-Mimecast-MFC-AGG-ID: 62MG920-OhyA25GLwDCv_w_1770325236 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-8c71655aa11so469339385a.3 for ; Thu, 05 Feb 2026 13:00:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1770325236; x=1770930036; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=2gGPFCPOPX/fBbf5qQfZiwEzewT+3Ulk7LVkRWF8dEo=; b=DJRyOtFkMsI56US+c6NOdfhByUFio75q00vlHZbra4em7TLWYHg9rKAmMm/epAyWPs hSFC4G2LSEtPVxaHk9ZQ4KYKrCJIPyHSTxLvpRhPnsCSlwHI7y4sa7TyjNPBZzbgVR8C 09B4gK0amQJqQ1YJgAPeyN7dchCz13rbztccDwQs3D/IW1PBauK2zHGpkNo48saBL0AN CAoA0uXDdII9Sr6m6UW3FtuaHeICm5Nkm+32CFSXF4ZAlHeDf9ULVCE5eXlXYg4GdIPm OD4Pr3b5c7Qt4j0+0EnfKZs/vUY7C51qDB79wc3my5PkBCU28vzICduaq9X7WofM1jv6 xIXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770325236; x=1770930036; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=2gGPFCPOPX/fBbf5qQfZiwEzewT+3Ulk7LVkRWF8dEo=; b=cv8QKNvSjd68RVZ6+Q+4k9wfen+vbPJXk1IwbKREZM1DFaDTc9mo18shSnDtce7ReE kERB5aaujUdky9rK9XXslmxIj+NBgx9lf/GBroklbcQgjpnIN7iWbvXfiqSEJ2HLLNc6 m4XYMXedBv961wgFd8VgcmAt94QL+s1rjLjG9Awf5RYKfVfpE+vVssdpuaLbF555LRTm VqfEXGryDLPLVlVzTpaeYmqBxRl+uo+BEiLoMlmcG49ZoOluZ92CkN4yaT1Og6H3Kh/S EoUDi/sEq7t4soqTWMNlIQe731LGlhQxwY6OhUWBRibDnQvpG7OkXJW7aJafHCELlL9w WJkg== X-Forwarded-Encrypted: i=1; AJvYcCXX6xzzPSsTCkcRXzXdDPV2C1nRoDEDONB6IC2v55a7IbguctJCpgsAczuRjHs0Oqm5GVccUEajSFSc0V8=@vger.kernel.org X-Gm-Message-State: AOJu0YxpQSA6kZdkMf9k3RSseWqb7YdGaxL4kmpiHlyJAntNak2ISDV3 K+AwaPJ7VUJ3vcwWCK3n9k08CuKAKY7rVDSd6nBxWsLFCZhTdM2x2cBysUPhc7A69nFn6w4J+03 RkThb0OzANUDScFWQaw1MxSFcbeAiGyDWXdxQw7SQB6Em2hKtn+at926QHfvnSGJQbQ== X-Gm-Gg: AZuq6aIi6LSX6JDhbffR55BcNC5pG3vGhcefMk00VMd09ZxAOSY6FNNVJYmB4AHmkFb HH9/hG2DWSd9deWUIVezqS06fAtnTgZxsYZ+PqDmsVSLGr8Yg95z3OzRUUL6pnof4PgpSBdMZNq omdSBQIWX1627xjsPkd2yFB4etHuawJTgKV926oLgTB2A8N1tvD4/VNRl9xP6YI9KVCc2q2YtZL 82GzviAK9jvKtVB/cj2KpGwOR09iTxy/wM2K5NMOTpSG8xmzkr9T9SCMUOR0MYu+gobwK0Hcyq8 hU9XMQWv1Ugy8a5NPLjQ97NEWok1GnINNqI9tazKdWBJO6tNwCDqvg1QOBHkr+fWjPqnXVI1cZj eq3IzFsNAj3mvlBI= X-Received: by 2002:a05:620a:1a04:b0:8ca:4438:b8f4 with SMTP id af79cd13be357-8caf13fedb3mr61787985a.67.1770325235573; Thu, 05 Feb 2026 13:00:35 -0800 (PST) X-Received: by 2002:a05:620a:1a04:b0:8ca:4438:b8f4 with SMTP id af79cd13be357-8caf13fedb3mr61780085a.67.1770325234922; Thu, 05 Feb 2026 13:00:34 -0800 (PST) Received: from [172.16.1.8] ([2607:f2c0:b010:9000:4c85:f148:4c91:943a]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8caf9fdf692sm17571285a.44.2026.02.05.13.00.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Feb 2026 13:00:34 -0800 (PST) From: Peter Colberg Date: Thu, 05 Feb 2026 15:59:54 -0500 Subject: [PATCH v2 07/10] rust: pci: add is_physfn(), to check for PFs Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260205-rust-pci-sriov-v2-7-ef9400c7767b@redhat.com> References: <20260205-rust-pci-sriov-v2-0-ef9400c7767b@redhat.com> In-Reply-To: <20260205-rust-pci-sriov-v2-0-ef9400c7767b@redhat.com> To: Danilo Krummrich , Bjorn Helgaas , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Abdiel Janulgue , Daniel Almeida , Robin Murphy , Greg Kroah-Hartman , Dave Ertman , Ira Weiny , Leon Romanovsky , David Airlie , Simona Vetter , Jonathan Corbet , Xu Yilun , Tom Rix , Moritz Fischer , "Rafael J. Wysocki" Cc: linux-pci@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Alexandre Courbot , Alistair Popple , Joel Fernandes , John Hubbard , Zhi Wang , nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-doc@vger.kernel.org, linux-fpga@vger.kernel.org, driver-core@lists.linux.dev, Peter Colberg , Jason Gunthorpe X-Mailer: b4 0.14.2 Add a method to check if a PCI device is a Physical Function (PF). Reviewed-by: Joel Fernandes Signed-off-by: Peter Colberg --- Changes in v2: - Replace VF -> PF in doc comment of is_physfn(). - Add #[inline] to is_physfn(). --- rust/kernel/pci.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs index db05641186c3a42922e2b6a463de9c1b099a4673..df39ad3f0d5fd898b034609efb0= 3368f83c2a2e9 100644 --- a/rust/kernel/pci.rs +++ b/rust/kernel/pci.rs @@ -484,6 +484,13 @@ pub fn resource_start(&self, bar: u32) -> Result { Ok(unsafe { bindings::pci_resource_start(self.as_raw(), bar.try_in= to()?) }) } =20 + /// Returns `true` if this device is a Physical Function (PF). + #[inline] + pub fn is_physfn(&self) -> bool { + // SAFETY: `self.as_raw` is a valid pointer to a `struct pci_dev`. + unsafe { (*self.as_raw()).is_physfn() !=3D 0 } + } + /// Returns `true` if this device is a Virtual Function (VF). #[inline] pub fn is_virtfn(&self) -> bool { --=20 2.52.0 From nobody Sun Feb 8 16:33:40 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 C744233372D for ; Thu, 5 Feb 2026 21:00:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770325242; cv=none; b=j7MCy0CBJObF5H5/qUiqxAbYB+eIveLU80KHyqz/TS86lcSdoiYEtyBbUG4ldw8jqRC5wZ29S4/NeZgVW/tsh5MDY1ylXk7C6KXxg1cg4gcQtV2s27GZX4xnL15ZF4J/7NW9bWyzWbI+LPyFaSQYYYeiqIshcY5x0xK2vFY20ts= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770325242; c=relaxed/simple; bh=zYEg72eTegIm4aBsUkMl8q2KG4rMnFZIPR9seQA5Ej8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dOUAuR+jgXWnairPljeF74eeG/C3zplwKMHRUTdyXOwwnOLv0LEC1qmxV8vh2W0lVl5hPZEFYw7zhNNSLvSsXFeCGyztcPj+kIPH3KTpngCPBM5xiyDdttwyV5ahXcFucphs4l4E0rmE5yBZ5fruSHQhdpH60+yLbAs26A7eDmQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=FYvZLoxV; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=Gs5Y8Fe2; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="FYvZLoxV"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="Gs5Y8Fe2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770325241; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iChE2sHYyL+SE0NwtrGJ4SsAVC7actOKSXH6xK1kyOw=; b=FYvZLoxVgoqVzvuA7Uq6AUpuCQ6ebSCCJWihz1p4UAp35QsBg1qSayR+zrjIaJsQSW/Gtw +v5B9kmQ72f0wjN5tQ4EVre7EWyET8QADstc7vRKbWejIkGsYl4mq13G8bIY4uaeRF4dEy Cjy0uoo6lgQt1v714kugcNUiM2SRuTk= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-633-rU0eKXX7MrmUfW9xYZfopw-1; Thu, 05 Feb 2026 16:00:38 -0500 X-MC-Unique: rU0eKXX7MrmUfW9xYZfopw-1 X-Mimecast-MFC-AGG-ID: rU0eKXX7MrmUfW9xYZfopw_1770325237 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-8c52c921886so168322585a.2 for ; Thu, 05 Feb 2026 13:00:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1770325237; x=1770930037; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=iChE2sHYyL+SE0NwtrGJ4SsAVC7actOKSXH6xK1kyOw=; b=Gs5Y8Fe2u1BVoCIIfWVuAew+NDxTEBwKtArLqZiGDPZRBy1dLP5zzIZkpljltmJLqb DWtXoxV7aWQquJVxNxIyqTOtnFxWhCWOdqzrmVVRsWV7zRtEffiutjAUTinG2YJ2hF1c aAYuC38vKOzLkb6Mskb5QZfPwURt76blJKMctWKkjof7EkQeOu/6ScyVfK8kzonahC/B ewbYpxD9JnLYuYA7HbZA0IoRoS0w77nlC2ACRzjeKdEAx2ckDqVLg1ITuDS5F0Yf+7h0 ox+Eg+RQ+QiJEEUBt8YekPRmNT4L/oi9zVLmflGCBEoXdgybS0bY+X09kEIpF8ZttdgI 3kkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770325237; x=1770930037; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=iChE2sHYyL+SE0NwtrGJ4SsAVC7actOKSXH6xK1kyOw=; b=D8wJSsytP828dY9sZ+b5IvCXtlX71H67yIJIpbZwQh2aQ55Nq7IWB0vBeIgGUvaxGG sY6Awi85nTRdsKXm5ADeJ+J0fmiHVL6aHYLgbxUe7iLqAsX0T/6L6HZYQMeR/HziGY7p szQ6wT6mM8DBNAvQKKxUMeDmKCjyamHkWLVbhQFqJbCF2HRWELxsjyfvyJfIn2M9OlrJ LmwYxfi1J6lqrL1ECJY6spPh2FQ09gRNX7S4LhX5tapJ45vn2SNeIeiUm/KuZGRWRxUk 8CSRKKBffd5uK0upZTUcT4k27sRg6ilfiag6qx9MYhx21ZaiI+AKPP7q3FgbsH4+6lZU GaEA== X-Forwarded-Encrypted: i=1; AJvYcCXVUi/vAkm1T0roYS0wVzDrSsAyoK6uWM9qqtbjP+trbA8ERMSSE6UisMC03awePJEGgm5yeDZZ5KtpBpA=@vger.kernel.org X-Gm-Message-State: AOJu0YwyeRVUJcRMru5TC2WUddYQlXBHhhfOAJbhzJxS/gfolpZ5kkEw jtwiS7vx5w3h6qQpuWsA7VNT04sbfGgZ2zlE76c+7qmayspzkiNe8FOLmijTu9P2r4KKVyXJlcM KsE5mondUIJdeM/ucDPx1UTB6yPt3zrsOJve0v0If8Kv0e4z7y39Uj/St7kdOwlTZCw== X-Gm-Gg: AZuq6aLRhJvtkzKS0cNrIerXe9V3EjxWg1bLKHujbTRiZ6BkDkHPLsLhACjN1ZB9Y7r zNxJW3zlJbRn4PQMZoqhisa9m1Z+gIEouPmfygRNGJDzlpXNxLYZnD8ncjgiq++rlVQ6BbfOE4b 8T6UiwQwlK7V1L2j4b7INRL2mbM6tnmksHTktk7puXg6t7FglP5tS5V40BR9hjinJGrgH7hEATU LTj8uG04mJRhdvc8EHQB6UsfVQ5HJxudreHpPMZRIgd7Ga8Q9vHeJQYIIAwXimtUFHTX++f6Ir9 IioNNgkG8lzD7xkWH9DXOz8Yv1sm1yhas4ewG3CA3lno6WzxBwKsnQbrD+KhAdy7ND1m3QdYeIu 5+F0yRvnAyk/MXos= X-Received: by 2002:a05:620a:44cf:b0:8c5:3067:903c with SMTP id af79cd13be357-8caeeb50f3emr72337785a.11.1770325237554; Thu, 05 Feb 2026 13:00:37 -0800 (PST) X-Received: by 2002:a05:620a:44cf:b0:8c5:3067:903c with SMTP id af79cd13be357-8caeeb50f3emr72328985a.11.1770325236916; Thu, 05 Feb 2026 13:00:36 -0800 (PST) Received: from [172.16.1.8] ([2607:f2c0:b010:9000:4c85:f148:4c91:943a]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8caf9fdf692sm17571285a.44.2026.02.05.13.00.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Feb 2026 13:00:36 -0800 (PST) From: Peter Colberg Date: Thu, 05 Feb 2026 15:59:55 -0500 Subject: [PATCH v2 08/10] rust: pci: add num_vf(), to return number of VFs Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260205-rust-pci-sriov-v2-8-ef9400c7767b@redhat.com> References: <20260205-rust-pci-sriov-v2-0-ef9400c7767b@redhat.com> In-Reply-To: <20260205-rust-pci-sriov-v2-0-ef9400c7767b@redhat.com> To: Danilo Krummrich , Bjorn Helgaas , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Abdiel Janulgue , Daniel Almeida , Robin Murphy , Greg Kroah-Hartman , Dave Ertman , Ira Weiny , Leon Romanovsky , David Airlie , Simona Vetter , Jonathan Corbet , Xu Yilun , Tom Rix , Moritz Fischer , "Rafael J. Wysocki" Cc: linux-pci@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Alexandre Courbot , Alistair Popple , Joel Fernandes , John Hubbard , Zhi Wang , nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-doc@vger.kernel.org, linux-fpga@vger.kernel.org, driver-core@lists.linux.dev, Peter Colberg , Jason Gunthorpe X-Mailer: b4 0.14.2 Add a method to return the number of Virtual Functions (VF) enabled for a Physical Function (PF). Signed-off-by: Peter Colberg --- rust/kernel/pci.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs index df39ad3f0d5fd898b034609efb03368f83c2a2e9..581930d0afe98ccc29d729e4d9a= ab75b4144e46c 100644 --- a/rust/kernel/pci.rs +++ b/rust/kernel/pci.rs @@ -498,6 +498,13 @@ pub fn is_virtfn(&self) -> bool { unsafe { (*self.as_raw()).is_virtfn() !=3D 0 } } =20 + /// Returns the number of Virtual Functions (VF) enabled for a Physica= l Function (PF). + #[cfg(CONFIG_PCI_IOV)] + pub fn num_vf(&self) -> i32 { + // SAFETY: `self.as_raw` is a valid pointer to a `struct pci_dev`. + unsafe { bindings::pci_num_vf(self.as_raw()) } + } + /// Returns the size of the given PCI BAR resource. pub fn resource_len(&self, bar: u32) -> Result { if !Bar::index_is_valid(bar) { --=20 2.52.0 From nobody Sun Feb 8 16:33:40 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 4363033065B for ; Thu, 5 Feb 2026 21:00:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770325243; cv=none; b=adzFnuhU9h3CY3rnXHQ/JiGCujCMwU87CSQkhl1wMjJeUnwg8/q4mMskz6+u7DymcUIlKNcm99ns1pip/mlBHNK/8cXUMibvQXBZji+wS/Gyo/Vui9mt1tathDbE3djhwFlQcF5n7bIMj3hbwwMYqKZmJl7tukZWKi/ORXdfxek= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770325243; c=relaxed/simple; bh=KLbaRgHVZXPc1lQS39X/po8u/6fvm7lynlb8kx1LgCw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nH/UxE17fI/FYtOsHAgxLBIJg6gf6wYIyPk7HvwMJFVM57bH0uqOImGJi2GAWbM81STb+k7VFqyWfEcxD5aHWO+lB5q9/K1RcjQ181FNbUfWOuTh/cuzHvEBs39CVRfkcYGs8NGJqnIvPDR3qIidzChBDyick4+c89dRL0f0lLY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=FoAjm2F0; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=M/IJ5Nn2; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="FoAjm2F0"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="M/IJ5Nn2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770325242; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=swhoxBv4zwo4dFRpNRtMjzIqauuYaXTIl/FyLukXQWY=; b=FoAjm2F0+C0lIDsMprrIgJ8Jwa8OkDVMqK0lixuZ+YVQeY0fqll3qYfI6Hk5ebcu3rnBsF NFLpw5V4lpvPfuyE4d0qBhv4K2f3aISa/9jPrHf5TEa6407DKGuTbMG+G1zG9JTGRdDJM4 HThLzERRi9FNIsfArESOH+OgH4LN/BU= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-318-EJkHhi5ANg2iX9v0ukDuTA-1; Thu, 05 Feb 2026 16:00:41 -0500 X-MC-Unique: EJkHhi5ANg2iX9v0ukDuTA-1 X-Mimecast-MFC-AGG-ID: EJkHhi5ANg2iX9v0ukDuTA_1770325240 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-8c538971a16so350705185a.1 for ; Thu, 05 Feb 2026 13:00:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1770325240; x=1770930040; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=swhoxBv4zwo4dFRpNRtMjzIqauuYaXTIl/FyLukXQWY=; b=M/IJ5Nn2e1zalLsMQcV9xn3IR5HsYWg+UoIwOxvJw3JOyFy3zy58Fgpz3X9QVp5T4e v8MBIZbu2lZO/4xgsxmBakehdR+/fq/ciGNRZC17eebxAwU03NF5hoFqJWF/V8ZZU7TO MkGnSAkS+dytExI1EnUzeX7yI8rGPu67zK12ZeGsW7eLMhU8uEvgFu1jaqNlPuAVVPvN KOtZl37pFa2ox0zYI9N3CFOG2Sd323BokctBP/4wiIZ8swqYjRbCFHZ6ydK2btG24clA X2ubOs89UvivxzAPnAPiQxI31xgOS8UwpX/UlWgNZEE+86ga5VPfOJMp1709UWe471Hs +0Fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770325240; x=1770930040; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=swhoxBv4zwo4dFRpNRtMjzIqauuYaXTIl/FyLukXQWY=; b=Z/sMf3QxyVQJUnb8edYgs+ODk9nZMxvkam89M52uhNfcZW3mBk4U4CpIqdxczgx2OG nLvUpVkInsO4fS4UV2KR9/F9HSyjSxDyBN0+Ujig0LmnhHyP+kCYavh7nANM7Ixff2To tFEF5Q9k7yu9eNCedgE+EnrRGu9XsBylPgKWwz+eP06l4EsXGnmZqY88nNIOgMIr83Wz oNXNR2kzw6pLj8FHxCv+F5HMN8OV80g+FGGPUmf/qxRgznu08rLnzcw2fyXL0VHaixji lMrn2Os2C4xdtgHut5yN17UWUQGBwIgUFHap6ZhG18PInmOITeDYq4rdPPnoIqYdH+JI U6pQ== X-Forwarded-Encrypted: i=1; AJvYcCX07g+wBlcqT6c9hQXIbugDt2OYaxXfDIy+52Qh01D/kjIO7rYmrUf8iQnsxG/nxucB3cbB1iwEo7H7WNU=@vger.kernel.org X-Gm-Message-State: AOJu0YzzSkYEnlGJxXiMkyPgnVoiCU8sWNUVNC4QMNaBunUW5/DUicl0 HCfwVG6j878tCOKZIhQ16F39Ask4kVmuNcj0eERyxwkqB87Ox6ozzH5BTZrAaDFaTwqrb8H0ZVO 7fMRs0AER7ub9UYp6waw8D6afNZj9otI70FjkCpqYKX+uZ6FjCXGHbCQZa4StJcASnYVastXCwA == X-Gm-Gg: AZuq6aIZampO2jE8yb96B1o5ZzZdTeftDzRZDgPJNr23Ak1i3nmVSfu8hdR1iCEDPJ0 oCXKSMuusBakwn178nkVaMqTmDSiRVb6sRj85pzf9BPNn3QQTjvbFrWHrFUdNeQF2o1Y+oDP2aF 80Myl5YnDWBDYK015TyF87pd93eqn9P1c5/fYuWbGvoMAw76/P1LLHTRzv8VxZ/DlDnZXTCGkhu lZ0fS3kKPRU+3Z++pDLoCele8MqStRSG4Yttfe5biTL0tOvyntEBChHVGCI2mM4NNsqYbe4CNNY VrqydYdhFfn2+dTiO4oBkydge49t0ZCj0OjDCYGuj8a98u2WTokWEfdvGfjT9RDi1Oi795MFA7z X+nYWD5Hx5KkNYc0= X-Received: by 2002:a05:620a:3953:b0:8b2:eae0:bbf4 with SMTP id af79cd13be357-8caf0487af1mr60625785a.19.1770325239526; Thu, 05 Feb 2026 13:00:39 -0800 (PST) X-Received: by 2002:a05:620a:3953:b0:8b2:eae0:bbf4 with SMTP id af79cd13be357-8caf0487af1mr60617885a.19.1770325238937; Thu, 05 Feb 2026 13:00:38 -0800 (PST) Received: from [172.16.1.8] ([2607:f2c0:b010:9000:4c85:f148:4c91:943a]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8caf9fdf692sm17571285a.44.2026.02.05.13.00.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Feb 2026 13:00:38 -0800 (PST) From: Peter Colberg Date: Thu, 05 Feb 2026 15:59:56 -0500 Subject: [PATCH v2 09/10] rust: pci: add physfn(), to return PF device for VF device Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260205-rust-pci-sriov-v2-9-ef9400c7767b@redhat.com> References: <20260205-rust-pci-sriov-v2-0-ef9400c7767b@redhat.com> In-Reply-To: <20260205-rust-pci-sriov-v2-0-ef9400c7767b@redhat.com> To: Danilo Krummrich , Bjorn Helgaas , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Abdiel Janulgue , Daniel Almeida , Robin Murphy , Greg Kroah-Hartman , Dave Ertman , Ira Weiny , Leon Romanovsky , David Airlie , Simona Vetter , Jonathan Corbet , Xu Yilun , Tom Rix , Moritz Fischer , "Rafael J. Wysocki" Cc: linux-pci@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Alexandre Courbot , Alistair Popple , Joel Fernandes , John Hubbard , Zhi Wang , nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-doc@vger.kernel.org, linux-fpga@vger.kernel.org, driver-core@lists.linux.dev, Peter Colberg , Jason Gunthorpe X-Mailer: b4 0.14.2 Add a method to return the Physical Function (PF) device for a Virtual Function (VF) device in the bound device context. Unlike for a PCI driver written in C, guarantee that when a VF device is bound to a driver, the underlying PF device is bound to a driver, too, by always setting the flag managed_sriov in the pci_driver structure. In case SR-IOV has been enabled by a C driver that has not set the flag managed_sriov in pci_driver, return an error from physfn(). This change depends on commit a995fe1a3aa7 ("rust: driver: drop device private data post unbind") to also uphold the safety guarantee in case a (broken) PF driver re-enables SR-IOV in its unbind() callback. That commit extends the lifetime of the device private data beyond the remove_callback() wrapper. In particular, that commit ensures that the device private data for the PF device is still alive until after the function pci_iov_remove() is called and forcibly re-disables SR_IOV, which means the data can be safely accessed by VF drivers until then. Suggested-by: Danilo Krummrich Signed-off-by: Peter Colberg --- Changes in v2: - Uphold safety guarantee when PF driver is written in C. - Let physfn() return error if driver flag managed_sriov is unset. --- rust/kernel/pci.rs | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++= +++ 1 file changed, 53 insertions(+) diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs index 581930d0afe98ccc29d729e4d9aab75b4144e46c..3b11f73a9f2b69a02fe003b8fea= dd61864adc8c0 100644 --- a/rust/kernel/pci.rs +++ b/rust/kernel/pci.rs @@ -525,6 +525,59 @@ pub fn pci_class(&self) -> Class { } } =20 +impl Device { + /// Returns the Physical Function (PF) device for a Virtual Function (= VF) device. + /// + /// # Examples + /// + /// The following example illustrates how to obtain the private driver= data of the PF device, + /// where `vf_pdev` is the VF device of reference type `&Device`= or `&Device`. + /// + /// ``` + /// # use kernel::{device::Core, pci}; + /// /// A PCI driver that binds to both the PF and its VF devices. + /// struct MyDriver; + /// + /// impl MyDriver { + /// fn connect(vf_pdev: &pci::Device) -> Result { + /// let pf_pdev =3D vf_pdev.physfn()?; + /// let pf_drvdata =3D pf_pdev.as_ref().drvdata::()?; + /// Ok(()) + /// } + /// } + /// ``` + #[cfg(CONFIG_PCI_IOV)] + pub fn physfn(&self) -> Result<&Device> { + if !self.is_virtfn() { + return Err(EINVAL); + } + + // SAFETY: `self.as_raw()` returns a valid pointer to a `struct pc= i_dev`. + // `physfn` is a valid pointer to a `struct pci_dev` since `is_vir= tfn()` is `true`. + let pf_dev =3D unsafe { (*self.as_raw()).__bindgen_anon_1.physfn }; + + // SAFETY: `pf_dev` is a valid pointer to a `struct pci_dev`. + // `driver` is either NULL or a valid pointer to a `struct pci_dri= ver`. + let pf_drv =3D unsafe { (*pf_dev).driver }; + if pf_drv.is_null() { + return Err(EINVAL); + } + + // SAFETY: `pf_drv` is a valid pointer to a `struct pci_driver`. + if !unsafe { (*pf_drv).managed_sriov } { + return Err(EINVAL); + } + + // SAFETY: `physfn` may be cast to a `Device` since= the + // driver flag `managed_sriov` forces SR-IOV to be disabled when t= he + // PF driver is unbound, i.e., all VF devices are destroyed. This + // guarantees that the underlying PF device is bound to a driver + // when the VF device is bound to a driver, which is the case since + // `Device::physfn()` requires a `&Device` reference. + Ok(unsafe { &*pf_dev.cast() }) + } +} + impl Device { /// Enable memory resources for this device. pub fn enable_device_mem(&self) -> Result { --=20 2.52.0 From nobody Sun Feb 8 16:33:40 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 441413358B0 for ; Thu, 5 Feb 2026 21:00:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770325244; cv=none; b=BfiFBNntH5o1WPjZ7E+uIxZ/qo78TzLPX41eSKPnUt7V6VFfZZCQhyPI4td18r2/D6k10JsF+VFEeLkhfI8GpqbZWLN7JwldFrGLD+yfnEU7drOXhnM3rTYj4soUYd1LfU60nInjv1ZDDp6BbqOAKFnsJRrIrBAgvHNm9xdusws= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770325244; c=relaxed/simple; bh=DsoH5kljF8z69G5m/2pqjtsvxAd0CBzUg2OXfZWFlWQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=oHaIAGG4/fXHy18ZRwTeqxhxnSMX45qhU10OlCs0h7dfYu3NeDqLJ5zpPU+ufqQ1+M/2P73z05PoD+NOy63XSmzpY9M7WxArfPGp44RTizk8pEVqNHuuJP9tomfThgixgDzB6rYSAVQCNIbRCuJe0x1AZuvRWkpApTlC0z5dgRc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=FPMn4KQw; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=CjE4iDbo; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="FPMn4KQw"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="CjE4iDbo" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770325243; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BMqbQ59ZEPX4CdhRYiH6E8cBHnvUegI817wkrdE94SY=; b=FPMn4KQwmZNXeuAr8sNW6WPxBDpRpriID8WzbvdMYaxY0NX0l6kzkYcm6LvAIxlEZn2Cac SGl4ptaD5jgKBvN5RUtuSUWO8v+CgqVrU7fV7CaVglrt9/SdpMP1WI7I7b5AYrtNhpvGpP Jg0CvBm+5xr6fWqiWCBO2ZIk7vZVnJY= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-540-iWFiV1QvNaqwExO4GvqTew-1; Thu, 05 Feb 2026 16:00:42 -0500 X-MC-Unique: iWFiV1QvNaqwExO4GvqTew-1 X-Mimecast-MFC-AGG-ID: iWFiV1QvNaqwExO4GvqTew_1770325242 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-8c882774f0dso375467785a.2 for ; Thu, 05 Feb 2026 13:00:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1770325242; x=1770930042; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=BMqbQ59ZEPX4CdhRYiH6E8cBHnvUegI817wkrdE94SY=; b=CjE4iDbooIbm7LD2lFBUtHrDtjNdg6ej4gJapSytdW3ZHcfY81WAGs76gRo+IhcRom oZtGSpz9mdDjhSfkPyBDBxryBh6nCIq2Q6u+ClWtnxQDwdTgtJZuDN1rW0WdW1yqwDm/ 7S7m9ug1WNAwnZ8oq6LX/fHq+DzaG4nE3MRsJOuG9Zv+6l/uoGpwX1KxOXRjthEV39ZV iMUf5Xyxc+v7g0Q/J1jeFOiV4J0+GH9kS7Q+Z2clN1X/MnkI6OAwAcJhuXB/WgdV1BVu fddIDwvUc1TEgoaF4nuwf31zjYcmpU5Tk1OThAo1gr7ATQqWW5pxXGbfEzgB+e0Wm07u vBuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770325242; x=1770930042; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=BMqbQ59ZEPX4CdhRYiH6E8cBHnvUegI817wkrdE94SY=; b=bg+9u3bAkf/v6xLRBu03tZtcasKMFzFI+v3UqqFnppt1yvQ7a6pSXPNg6fJXMiSbU1 kNQHDDSt31kSZAvLud3BP/CnGQeUpqT2q76H/BombmnQhbXugtrEUzDFsMole7JXwWhI E75ECoFLVB+HwBN8klJFnkVRbG67/U+Q/HUfYIsFw3b8yjU4zIQLI5hWfCZMmvZ5n5AB 6xYTce56FQTJvt1XrFagHf2HRcvR+tH7YI7milNfR0FqIu1ers3Nx0hQ9wDszminv3Dx bqy4eZ6KWBClnSaX19inZdi5KgX5oZ1gDZKIWAU5CwwOaPh8gFCEOfqwwpRKf4ADyMv6 I0Mg== X-Forwarded-Encrypted: i=1; AJvYcCXWJYuX6REVfI0fXpnMfooJ0BwAtxYGN+Y+dOeKdwp5xgoOG6ts8wKS+ICxTGQHWdbmx7ucgsg5Fh+7Z0k=@vger.kernel.org X-Gm-Message-State: AOJu0YwHMH6D44QrzwKgchHkbV9hSPS067j6xAiK7RUUujmf4MjhPbCf MgLNzNhogMXhyjFdAW6CqQtmx1CSSsTdKoJNxPt1Cfey8qZIaW93wxgsOIfMEq2thMXolS1aWdi RXEblVm7jaXmBUk54V1RYHav3qmQOI88hWLr5PQ0UdbjUm7W0REJj5hEbWSR47taugw== X-Gm-Gg: AZuq6aIPlSIzUPfReXTyzD7NeegiszML8b9WOC3GsLRX2KIGH7BXq2zVVGUZWZ/FA5/ YROrkyOAHxAduh5f6iT0Vm9yE7tzZo4SCaGrEI1KQmD2AL2+n3TQF2hJ5BrOemPpgBSYmaKNY9O 6mqc0Y/4Is9DpkT8J0RaFIPuie5y7FCl/a4vxmpYuId5Zup8pY6tYGDxKhjHEZquHHvgKtRDcIH i9DwRjMXrAJbAoEywyw9WxL9uJX4D/2sULC9ZgrxG9hWcItNVyVgndR50lz3VoQcgPmy9vQhezV LlFs+GXUR/MDm7PUY857kloECiNiouE92Z1a6c1Vlbx73qtFMpDn7Z3zSEh46VM96oeP8bLJkYM K/OnVNlYvm7kPFjs= X-Received: by 2002:a05:620a:28c5:b0:8ca:3854:8110 with SMTP id af79cd13be357-8caf130789cmr57432885a.72.1770325241417; Thu, 05 Feb 2026 13:00:41 -0800 (PST) X-Received: by 2002:a05:620a:28c5:b0:8ca:3854:8110 with SMTP id af79cd13be357-8caf130789cmr57425985a.72.1770325240837; Thu, 05 Feb 2026 13:00:40 -0800 (PST) Received: from [172.16.1.8] ([2607:f2c0:b010:9000:4c85:f148:4c91:943a]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8caf9fdf692sm17571285a.44.2026.02.05.13.00.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Feb 2026 13:00:40 -0800 (PST) From: Peter Colberg Date: Thu, 05 Feb 2026 15:59:57 -0500 Subject: [PATCH v2 10/10] samples: rust: add SR-IOV driver sample Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260205-rust-pci-sriov-v2-10-ef9400c7767b@redhat.com> References: <20260205-rust-pci-sriov-v2-0-ef9400c7767b@redhat.com> In-Reply-To: <20260205-rust-pci-sriov-v2-0-ef9400c7767b@redhat.com> To: Danilo Krummrich , Bjorn Helgaas , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Abdiel Janulgue , Daniel Almeida , Robin Murphy , Greg Kroah-Hartman , Dave Ertman , Ira Weiny , Leon Romanovsky , David Airlie , Simona Vetter , Jonathan Corbet , Xu Yilun , Tom Rix , Moritz Fischer , "Rafael J. Wysocki" Cc: linux-pci@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Alexandre Courbot , Alistair Popple , Joel Fernandes , John Hubbard , Zhi Wang , nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-doc@vger.kernel.org, linux-fpga@vger.kernel.org, driver-core@lists.linux.dev, Peter Colberg , Jason Gunthorpe X-Mailer: b4 0.14.2 Add a new SR-IOV driver sample that demonstrates how to enable and disable the Single Root I/O Virtualization capability for a PCI device. The sample may be exercised using QEMU's 82576 (igb) emulation. Link: https://www.qemu.org/docs/master/system/devices/igb.html Signed-off-by: Peter Colberg --- Changes in v2: - Use "kernel vertical" style on imports. - Demonstrate how to reach driver data of PF device from VF device. --- MAINTAINERS | 1 + samples/rust/Kconfig | 11 ++++ samples/rust/Makefile | 1 + samples/rust/rust_driver_sriov.rs | 127 ++++++++++++++++++++++++++++++++++= ++++ 4 files changed, 140 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index b277baee5eb6725b3a5126cefb6eef6190b02413..96dffd777c24473063baaeda017= f64b15e8c0ab9 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -20242,6 +20242,7 @@ F: rust/helpers/pci.c F: rust/kernel/pci.rs F: rust/kernel/pci/ F: samples/rust/rust_driver_pci.rs +F: samples/rust/rust_driver_sriov.rs =20 PCIE BANDWIDTH CONTROLLER M: Ilpo J=C3=A4rvinen diff --git a/samples/rust/Kconfig b/samples/rust/Kconfig index c49ab910634596aea4a1a73dac87585e084f420a..f244df89c4fc9d741915f581de7= 6107e8eb0121b 100644 --- a/samples/rust/Kconfig +++ b/samples/rust/Kconfig @@ -128,6 +128,17 @@ config SAMPLE_RUST_DRIVER_PLATFORM =20 If unsure, say N. =20 +config SAMPLE_RUST_DRIVER_SRIOV + tristate "SR-IOV Driver" + depends on PCI_IOV + help + This option builds the Rust SR-IOV driver sample. + + To compile this as a module, choose M here: + the module will be called rust_driver_sriov. + + If unsure, say N. + config SAMPLE_RUST_DRIVER_USB tristate "USB Driver" depends on USB =3D y diff --git a/samples/rust/Makefile b/samples/rust/Makefile index 6c0aaa58ccccfd12ef019f68ca784f6d977bc668..19d700f8210151e298cc049dacc= 249a121d0f2c4 100644 --- a/samples/rust/Makefile +++ b/samples/rust/Makefile @@ -11,6 +11,7 @@ obj-$(CONFIG_SAMPLE_RUST_DRIVER_I2C) +=3D rust_driver_i2= c.o obj-$(CONFIG_SAMPLE_RUST_I2C_CLIENT) +=3D rust_i2c_client.o obj-$(CONFIG_SAMPLE_RUST_DRIVER_PCI) +=3D rust_driver_pci.o obj-$(CONFIG_SAMPLE_RUST_DRIVER_PLATFORM) +=3D rust_driver_platform.o +obj-$(CONFIG_SAMPLE_RUST_DRIVER_SRIOV) +=3D rust_driver_sriov.o obj-$(CONFIG_SAMPLE_RUST_DRIVER_USB) +=3D rust_driver_usb.o obj-$(CONFIG_SAMPLE_RUST_DRIVER_FAUX) +=3D rust_driver_faux.o obj-$(CONFIG_SAMPLE_RUST_DRIVER_AUXILIARY) +=3D rust_driver_auxiliary.o diff --git a/samples/rust/rust_driver_sriov.rs b/samples/rust/rust_driver_s= riov.rs new file mode 100644 index 0000000000000000000000000000000000000000..84d057629c7b03d743179a4e05c= cc092f814bf6b --- /dev/null +++ b/samples/rust/rust_driver_sriov.rs @@ -0,0 +1,127 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! Rust SR-IOV driver sample based on QEMU's 82576 ([igb]) emulation. +//! +//! To make this driver probe, QEMU must be run with `-device igb`. +//! +//! Further, enable [vIOMMU] with interrupt remapping using, e.g., +//! +//! `-M q35,accel=3Dkvm,kernel-irqchip=3Dsplit -device intel-iommu,intrema= p=3Don,caching-mode=3Don` +//! +//! and append `intel_iommu=3Don` to the guest kernel arguments. +//! +//! [igb]: https://www.qemu.org/docs/master/system/devices/igb.html +//! [vIOMMU]: https://wiki.qemu.org/Features/VT-d + +use kernel::{ + device::Core, + pci, + prelude::*, + sync::aref::ARef, // +}; + +use core::any::TypeId; + +#[pin_data(PinnedDrop)] +struct SampleDriver { + pdev: ARef, + private: TypeId, +} + +kernel::pci_device_table!( + PCI_TABLE, + MODULE_PCI_TABLE, + ::IdInfo, + [ + // E1000_DEV_ID_82576 + (pci::DeviceId::from_id(pci::Vendor::INTEL, 0x10c9), ()), + // E1000_DEV_ID_82576_VF + (pci::DeviceId::from_id(pci::Vendor::INTEL, 0x10ca), ()) + ] +); + +#[vtable] +impl pci::Driver for SampleDriver { + type IdInfo =3D (); + + const ID_TABLE: pci::IdTable =3D &PCI_TABLE; + + fn probe(pdev: &pci::Device, _info: &Self::IdInfo) -> impl PinIn= it { + pin_init::pin_init_scope(move || { + dev_info!( + pdev.as_ref(), + "Probe Rust SR-IOV driver sample (PCI ID: {}, 0x{:x}).\n", + pdev.vendor_id(), + pdev.device_id() + ); + + if pdev.is_virtfn() { + let physfn =3D pdev.physfn()?; + let drvdata =3D physfn.as_ref().drvdata::()?; + + assert!(physfn.is_physfn()); + + dev_info!( + pdev.as_ref(), + "Parent device is PF (PCI ID: {}, 0x{:x}).\n", + physfn.vendor_id(), + physfn.device_id() + ); + + dev_info!( + pdev.as_ref(), + "We have access to the private data of {:?}.\n", + drvdata.private + ); + } + + pdev.enable_device_mem()?; + pdev.set_master(); + + Ok(try_pin_init!(Self { + pdev: pdev.into(), + private: TypeId::of::() + })) + }) + } + + fn sriov_configure(pdev: &pci::Device, nr_virtfn: i32) -> Result= { + assert!(pdev.is_physfn()); + + if nr_virtfn =3D=3D 0 { + dev_info!( + pdev.as_ref(), + "Disable SR-IOV (PCI ID: {}, 0x{:x}).\n", + pdev.vendor_id(), + pdev.device_id() + ); + pdev.disable_sriov(); + } else { + dev_info!( + pdev.as_ref(), + "Enable SR-IOV (PCI ID: {}, 0x{:x}).\n", + pdev.vendor_id(), + pdev.device_id() + ); + pdev.enable_sriov(nr_virtfn)?; + } + + assert_eq!(pdev.num_vf(), nr_virtfn); + Ok(nr_virtfn) + } +} + +#[pinned_drop] +impl PinnedDrop for SampleDriver { + fn drop(self: Pin<&mut Self>) { + dev_info!(self.pdev.as_ref(), "Remove Rust SR-IOV driver sample.\n= "); + } +} + +kernel::module_pci_driver! { + type: SampleDriver, + name: "rust_driver_sriov", + authors: ["Peter Colberg"], + description: "Rust SR-IOV driver", + license: "GPL v2", +} --=20 2.52.0