net: mana: Add handler for sriov configure
PATCH v4 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.
---
v4:
Removed unnecessary pci_disable_sriov() from mana_gd_shutdown() as suggested by AI review.
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 | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+)
drivers/net/ethernet/microsoft/mana/gdma_main.c +24 -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);
@@ -2525,6 +2527,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 +2563,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:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Uncancelled background works (mana_serv_work and mana_dev_recovery_work) lead to Use-After-Free of gdma_context during device removal. --
--- Patch [1]: [PATCH net-next v4] net: mana: Add handler for sriov configure --- commit d651d90ceb3e1716b100c2eb4035662f066b67fa
Author: Haiyang Zhang <[email protected]>
net: mana: Add handler for sriov configure
This commit adds a callback function for the pci_driver / sriov_configure interface. It requests the NIC to provide a specific number of VFs, or disables VFs if the requested number is zero.
drivers/net/ethernet/microsoft/mana/gdma_main.c static void mana_gd_remove(struct pci_dev *pdev) · line 2462
Quoted 12 lines
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);
[Severity: High]
This is a pre-existing issue, but can this lead to a Use-After-Free of gdma_context if there are uncancelled background works?
When mana_gd_remove() executes, it eventually frees the gdma_context via vfree(gc) without flushing works like mana_serv_work or mana_dev_recovery_work that might be pending on the system_wq.
If a hardware event triggers mana_gd_process_eqe() and schedules serv_work before a hot-unplug, could the scheduled work run after mana_gd_remove() has freed the context?
The worker thread mana_serv_func() calls mana_serv_reset(), which does:
struct gdma_context *gc = pci_get_drvdata(pdev);
...
hwc = gc->hwc.driver_data;Since the PCI core only clears drvdata after remove() returns, this could dereference the freed gc memory. Should these background works be cancelled before freeing the context?
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
This patch was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Quoted 8 lines · On Fri, 10 Jul 2026 12:27:29 -0700 you wrote:
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.
[...]
Here is the summary with links:
- [net-next,v4] net: mana: Add handler for sriov configure
https://git.kernel.org/netdev/net-next/c/ce6b4d3216b6
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html