net: mana: Add handler for sriov configure
PATCH v2 1/1 net: mana: Add handler for sriov configure
From: Haiyang Zhang <[email protected]>
Add callback function for the pci_driver / sriov_configure.
It asks the NIC to provide certain number of VFs, or disable VFs if the request is zero.
---
v2:
No longer change VF autoprobe as discussed with Leon Romanovsky and Bjorn Helgaas.
--- drivers/net/ethernet/microsoft/mana/gdma_main.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
drivers/net/ethernet/microsoft/mana/gdma_main.c +15 -0
@@ -2446,6 +2446,20 @@ static void mana_gd_shutdown(struct pci_dev *pdev)pci_disable_device (pdev); } +static int mana_sriov_configure (struct pci_dev *pdev,int numvfs) +{ +int err =0 ; + +dev_info (&pdev->dev,"Requested num VFs: %d\n" , numvfs); + +if (numvfs >0 ) + err =pci_enable_sriov (pdev, numvfs); +else +pci_disable_sriov (pdev); + +return err ? err : numvfs; +} +static const struct pci_device_id mana_id_table[] = { {PCI_DEVICE (PCI_VENDOR_ID_MICROSOFT ,MANA_PF_DEVICE_ID ) }, {PCI_DEVICE (PCI_VENDOR_ID_MICROSOFT ,MANA_PF2_DEVICE_ID ) },
@@ -2461,6 +2475,7 @@ static struct pci_driver mana_driver = { .suspend = mana_gd_suspend, .resume = mana_gd_resume, .shutdown = mana_gd_shutdown, + .sriov_configure = mana_sriov_configure, };static int __init mana_driver_init (void )
Signature · 1 line
2.34.1
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] Disabling SR-IOV without checking if Virtual Functions (VFs) are assigned to a guest VM. - [High]…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Disabling SR-IOV without checking if Virtual Functions (VFs) are assigned to a guest VM.
- [High] Missing SR-IOV cleanup during PF driver removal and shutdown.
--
commit 3df823cc57367f69930deb6dc48172ce7d77e785
Author: Haiyang Zhang <[email protected]>
net: mana: Add handler for sriov configure
Add callback function for the pci_driver / sriov_configure.
It asks the NIC to provide certain number of VFs, or disable VFs if the request is zero.
drivers/net/ethernet/microsoft/mana/gdma_main.c static void mana_gd_shutdown(struct pci_dev *pdev) · line 2497
Quoted 7 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +0
-0@@ -2496,6 +2496,20 @@ static void mana_gd_shutdown(struct pci_dev *pdev)pci_disable_device (pdev); }
[Severity: High]
With the addition of SR-IOV support in this patch, do mana_gd_shutdown() and mana_gd_remove() need to call pci_disable_sriov()?
If a user enables VFs via sysfs and then unbinds the driver or shuts down the system, could this omission introduce a regression where orphaned, dead VF PCI devices are left in the kernel?
Accessing these orphaned VFs might trigger use-after-free crashes or hardware faults, as the underlying PF hardware and driver context have been destroyed.
drivers/net/ethernet/microsoft/mana/gdma_main.c static void mana_gd_shutdown(struct pci_dev *pdev) · line 2458
Quoted 10 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +10
-0+static int mana_sriov_configure (struct pci_dev *pdev,int numvfs) +{ +int err =0 ; + +dev_info (&pdev->dev,"Requested num VFs: %d\n" , numvfs); + +if (numvfs >0 ) + err =pci_enable_sriov (pdev, numvfs); +else +pci_disable_sriov (pdev);
[Severity: High]
Should this path check if the VFs are currently assigned to a guest VM before disabling SR-IOV?
If a privileged user writes 0 to sriov_numvfs while VFs are actively assigned to a VM (e.g., via vfio-pci), could forcefully removing the PCI devices cause a regression resulting in host IOMMU faults and guest kernel panics?
Would it be better to check pci_vfs_assigned(pdev) here, or use the pci_sriov_configure_simple() helper to safely enforce this?
Quoted 3 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +3
-0+ +return err ? err : numvfs; +}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Paolo Abeni
maintainerFrom: AI Reviewer <[email protected]>
This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible. Full review at: https://sashiko.dev/
---
net: mana: Add handler for sriov configure
Add callback function for the pci_driver / sriov_configure.
It asks the NIC to provide certain number of VFs, or disable VFs if the request is zero.
drivers/net/ethernet/microsoft/mana/gdma_main.c static void mana_gd_shutdown(struct pci_dev *pdev) · line 2497
Quoted 7 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +0
-0@@ -2496,6 +2496,20 @@ static void mana_gd_shutdown(struct pci_dev *pdev)pci_disable_device (pdev); }
[Severity: High]
With the addition of SR-IOV support in this patch, do mana_gd_shutdown() and mana_gd_remove() need to call pci_disable_sriov()?
If a user enables VFs via sysfs and then unbinds the driver or shuts down the system, could this omission introduce a regression where orphaned, dead VF PCI devices are left in the kernel?
Accessing these orphaned VFs might trigger use-after-free crashes or hardware faults, as the underlying PF hardware and driver context have been destroyed.
drivers/net/ethernet/microsoft/mana/gdma_main.c static void mana_gd_shutdown(struct pci_dev *pdev) · line 2458
Quoted 10 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +10
-0+static int mana_sriov_configure (struct pci_dev *pdev,int numvfs) +{ +int err =0 ; + +dev_info (&pdev->dev,"Requested num VFs: %d\n" , numvfs); + +if (numvfs >0 ) + err =pci_enable_sriov (pdev, numvfs); +else +pci_disable_sriov (pdev);
[Severity: High]
Should this path check if the VFs are currently assigned to a guest VM before disabling SR-IOV?
If a privileged user writes 0 to sriov_numvfs while VFs are actively assigned to a VM (e.g., via vfio-pci), could forcefully removing the PCI devices cause a regression resulting in host IOMMU faults and guest kernel panics?
Would it be better to check pci_vfs_assigned(pdev) here, or use the pci_sriov_configure_simple() helper to safely enforce this?
Quoted 3 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +3
-0+ +return err ? err : numvfs; +}
Signature · 1 line
This is an AI-generated review.
Haiyang Zhang
maintainerQuoted 57 lines
-----Original Message-----
From: Paolo Abeni <[email protected]>
Sent: Wednesday, July 8, 2026 4:09 AM
To: [email protected]
Cc: [email protected]; [email protected]; KY Srinivasan <[email protected]>; Haiyang Zhang <[email protected]>; [email protected]; Dexuan Cui <[email protected]>; Long Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; Paul Rosswurm <[email protected]>
Subject: [EXTERNAL] Re: [PATCH net-next v2] net: mana: Add handler for sriov configureFrom: AI Reviewer <[email protected]>
This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible. Full review at:
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fsashiko.
dev%2F&data=05%7C02%7Chaiyangz%40microsoft.com%7C27add93a1c4b4c0c7b4808ded cc833d4%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C639190949593984694%7C Unknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJX aW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=qLm%2BrL1nEF6% 2FlF2%2Fmed2mnc%2BVR4Vp9P6G6i5Im1PquU%3D&reserved=0
---
net: mana: Add handler for sriov configureAdd callback function for the
pci_driver/sriov_configure.It asks the NIC to provide certain number of VFs, or disable VFs if the request is zero.
Review
Quoted 1 line
(quoted diff) +0
-0
b/drivers/net/ethernet/microsoft/mana/gdma_main.cdrivers/net/ethernet/microsoft/mana/gdma_main.c static void mana_gd_shutdown(struct pci_dev
Quoted 4 lines
index
e8b7ffb47eb98..f7a79874fd0eb100644drivers/net/ethernet/microsoft/mana/gdma_main.c +0
-0@@ -2496,6 +2496,20 @@ static void mana_gd_shutdown(struct pci_dev*pdev)
drivers/net/ethernet/microsoft/mana/gdma_main.c static void mana_gd_shutdown(struct pci_dev *pdev) · line 2447
Quoted 2 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +0
-0pci_disable_device (pdev); }[Severity: High]
With the addition of SR-IOV support in this patch, domana_gd_shutdown()andmana_gd_remove()need to callpci_disable_sriov()?If a user enables VFs via sysfs and then unbinds the driver or shuts down the
system, could this omission introduce a regression where orphaned, dead VF PCI
devices are left in the kernel?
Quoted 4 lines
Accessing these orphaned VFs might trigger use-after-free crashes or hardware
faults, as the underlying PF hardware and driver context have been destroyed.
Will fix.
Quoted 17 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c static void mana_gd_shutdown(struct pci_dev *pdev) · line 2458
Quoted 11 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +10
-0+static int mana_sriov_configure (struct pci_dev *pdev,int numvfs) +{ +int err =0 ; + +dev_info (&pdev->dev,"Requested num VFs: %d\n" , numvfs); + +if (numvfs >0 ) + err =pci_enable_sriov (pdev, numvfs); +else +pci_disable_sriov (pdev);[Severity: High]
Should this path check if the VFs are currently assigned to a guest VM before
disabling SR-IOV?
Quoted 8 lines
If a privileged user writes 0 to
sriov_numvfswhile VFs are actively assigned
to a VM (e.g., via vfio-pci), could forcefully removing the PCI devices cause
a regression resulting in host IOMMU faults and guest kernel panics?Would it be better to check
pci_vfs_assigned(pdev)here, or use thepci_sriov_configure_simple()helper to safely enforce this?
Will update.
I will send out an updated patch soon.
Thanks,
- Haiyang