net: mana: Add handler for sriov configure
PATCH v3 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.
---
v3:
Updated sriov disabling paths suggested by Paolo Abeni
v2:
No longer change VF autoprobe as discussed with Leon Romanovsky and Bjorn Helgaas.
--- .../net/ethernet/microsoft/mana/gdma_main.c | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+)
drivers/net/ethernet/microsoft/mana/gdma_main.c +26 -0
@@ -2456,6 +2456,8 @@ static void mana_gd_remove(struct pci_dev *pdev) {struct gdma_context *gc =pci_get_drvdata (pdev); +pci_disable_sriov (pdev); +mana_rdma_remove (&gc->mana_ib);mana_remove (&gc->mana, false);
@@ -2517,6 +2519,8 @@ static void mana_gd_shutdown(struct pci_dev *pdev)dev_info (&pdev->dev,"Shutdown was called\n" ); +pci_disable_sriov (pdev); +mana_rdma_remove (&gc->mana_ib);mana_remove (&gc->mana, true);
@@ -2525,6 +2529,27 @@ 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 { +if (pci_vfs_assigned (pdev)) { +dev_warn (&pdev->dev, +"Cannot disable SR-IOV while VFs are assigned\n" ); +return -EPERM ; + } + +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 ) },
@@ -2540,6 +2565,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 1 potential issue(s) to consider: - [High] Calling `pci_disable_sriov()` in the PF's `shutdown` path forces the teardown of already-shut-down…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Calling pci_disable_sriov() in the PF's shutdown path forces the teardown of already-shut-down VFs, triggering a dev_WARN_ONCE stack trace that can cause a kernel panic on shutdown. --
--- Patch [1]: [PATCH net-next v3] net: mana: Add handler for sriov configure --- commit 4f33a45546e7a470eda04866cd0e6294bcfd526c
Author: Haiyang Zhang <[email protected]>
net: mana: Add handler for sriov configure
This patch adds an SR-IOV configuration handler to the mana driver, allowing it to request or disable VFs. It also adds SR-IOV disable calls to the device remove and shutdown paths.
Quoted 4 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +0
-0
[ ... ]
drivers/net/ethernet/microsoft/mana/gdma_main.c static void mana_gd_shutdown(struct pci_dev *pdev) · line 2494
Quoted 6 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +2
-0@@ -2488,6 +2490,8 @@ static void mana_gd_shutdown(struct pci_dev *pdev)dev_info (&pdev->dev,"Shutdown was called\n" ); +pci_disable_sriov (pdev); +
[Severity: High]
Will this trigger a kernel warning during system shutdown when VFs are active?
During system shutdown, the driver core calls device_shutdown() iterating in reverse creation order. First, it calls mana_gd_shutdown() on the VFs, which partially tears down the VF and disables the PCI device:
mana_gd_shutdown()
...
pci_disable_device(pdev); Next, device_shutdown() calls mana_gd_shutdown() on the PF. Calling pci_disable_sriov() here destroys the VF PCI devices and unregisters them from the bus, which synchronously forces a call to the VF's remove callback:
mana_gd_remove()
...
pci_disable_device(pdev); Since pci_disable_device() is called unconditionally at the end of both mana_gd_shutdown() and mana_gd_remove(), this second call detects that the device is already disabled and fires a warning. On production systems with panic_on_warn=1, this converts a normal shutdown into a kernel panic.
Quoted 2 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +0
-0mana_rdma_remove (&gc->mana_ib);mana_remove (&gc->mana, true);
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Haiyang Zhang
maintainerQuoted 53 lines
-----Original Message-----
From: Haiyang Zhang <[email protected]>
Sent: Wednesday, July 8, 2026 4:59 PM
To: [email protected]; [email protected]; KY Srinivasan <[email protected]>; Haiyang Zhang <[email protected]>; Wei Liu <[email protected]>; Dexuan Cui <[email protected]>; Long Li <[email protected]>; Andrew Lunn <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Simon Horman <[email protected]>; Erni Sri Satya Vennela <[email protected]>; Dipayaan Roy <[email protected]>; Aditya Garg <[email protected]>; Shradha Gupta <[email protected]>; [email protected]
Cc: Paul Rosswurm <[email protected]>
Subject: [PATCH net-next v3] net: mana: Add handler for sriov configureFrom: 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.
Signed-off-by Haiyang Zhang <[email protected]>---
v3:
Updated sriov disabling paths suggested by Paolo Abeniv2:
No longer change VF autoprobe as discussed with Leon Romanovsky and
Bjorn Helgaas.--- .../net/ethernet/microsoft/mana/gdma_main.c | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+)drivers/net/ethernet/microsoft/mana/gdma_main.c +2
-0@@ -2456,6 +2456,8 @@ static void mana_gd_remove(struct pci_dev *pdev) {struct gdma_context *gc =pci_get_drvdata (pdev); +pci_disable_sriov (pdev); +mana_rdma_remove (&gc->mana_ib);mana_remove (&gc->mana, false);
drivers/net/ethernet/microsoft/mana/gdma_main.c static void mana_gd_shutdown(struct pci_dev *pdev) · line 2523
Quoted 5 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +2
-0@@ -2517,6 +2519,8 @@ static void mana_gd_shutdown(struct pci_dev *pdev)dev_info (&pdev->dev,"Shutdown was called\n" ); +pci_disable_sriov (pdev); +
I will remove this unnecessary pci_disable_sriov() as found by AI review, and submit an updated patch.
- Haiyang