net: mana: Add handler for sriov configure
Subsystems (5)
PATCH 1/1 net: mana: Add handler for sriov configure
From: Haiyang Zhang <[email protected]>
Add callback function for the pci_driver, sriov_configure.
Also disable VF autoprobe when it runs as PF driver on bare metal, since the hardware side may not have the VF ready immediately.
Export pci_vf_drivers_autoprobe() so the driver can toggle the VF autoprobe flag.
--- .../net/ethernet/microsoft/mana/gdma_main.c | 20 +++++++++++++++++++ drivers/pci/iov.c | 1 + 2 files changed, 21 insertions(+)
drivers/net/ethernet/microsoft/mana/gdma_main.c +20 -0
@@ -2094,6 +2094,11 @@ static int mana_gd_probe(struct pci_dev *pdev, const struct pci_device_id *ent) gc->numa_node =dev_to_node (&pdev->dev); gc->is_pf =mana_is_pf (pdev->device); + +/* Disable VF autoprobe on BM */ +if (gc->is_pf) +pci_vf_drivers_autoprobe (pdev, false); + gc->bar0_va = bar0_va; gc->dev = &pdev->dev;xa_init (&gc->irq_contexts);
@@ -2262,6 +2267,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_VF_DEVICE_ID ) },
@@ -2276,6 +2295,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 )
drivers/pci/iov.c +1 -0
@@ -1127,6 +1127,7 @@ void pci_vf_drivers_autoprobe(struct pci_dev *dev, bool auto_probe)if (dev->is_physfn) dev->sriov->drivers_autoprobe = auto_probe; } +EXPORT_SYMBOL_GPL (pci_vf_drivers_autoprobe);/** * pci_iov_bus_range - find bus range used by Virtual Function
Signature · 1 line
2.34.1
Quoted 9 lines · Haiyang Zhang
From: Haiyang Zhang <[email protected]>
Add callback function for the
pci_driver,sriov_configure.Also disable VF autoprobe when it runs as PF driver on bare metal, since the hardware side may not have the VF ready immediately.
Export
pci_vf_drivers_autoprobe()so the driver can toggle the VF autoprobe flag.
Technically pci_vf_drivers_autoprobe() doesn't *toggle* the autoprobe flag. That would mean setting it to the opposite of its current value.
Here I would say "so the driver can prevent autoprobing of the VFs", which is the intent.
Out of curiosity, how do the VFs eventually get probed? I guess there's some other mechanism that tells you when they're ready, and you manually use sysfs 'sriov_drivers_autoprobe' to enable probing, then bind drivers to them via sysfs?
The prevention of autoprobing sounds like a critical part of this change; might be worth saying something in the subject, because "add sriov configure" doesn't include much information.
Quoted 1 line
Signed-off-by Haiyang Zhang <[email protected]>
I assume this would go via a net tree since that's where the bulk of the changes are.
Quoted 65 lines
--- .../net/ethernet/microsoft/mana/gdma_main.c | 20 +++++++++++++++++++ drivers/pci/iov.c | 1 + 2 files changed, 21 insertions(+)drivers/net/ethernet/microsoft/mana/gdma_main.c +20
-0@@ -2094,6 +2094,11 @@ static int mana_gd_probe(struct pci_dev *pdev, const struct pci_device_id *ent) gc->numa_node =dev_to_node (&pdev->dev); gc->is_pf =mana_is_pf (pdev->device); + +/* Disable VF autoprobe on BM */ +if (gc->is_pf) +pci_vf_drivers_autoprobe (pdev, false); + gc->bar0_va = bar0_va; gc->dev = &pdev->dev;xa_init (&gc->irq_contexts);@@ -2262,6 +2267,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_VF_DEVICE_ID ) },@@ -2276,6 +2295,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 )drivers/pci/iov.c +1
-0@@ -1127,6 +1127,7 @@ void pci_vf_drivers_autoprobe(struct pci_dev *dev, bool auto_probe)if (dev->is_physfn) dev->sriov->drivers_autoprobe = auto_probe; } +EXPORT_SYMBOL_GPL (pci_vf_drivers_autoprobe);/** * pci_iov_bus_range - find bus range used by Virtual Function Signature · 1 line
2.34.1
Haiyang Zhang
maintainerQuoted 31 lines
-----Original Message-----
From: Bjorn Helgaas <[email protected]>
Sent: Friday, May 8, 2026 6:38 PM
To: Haiyang Zhang <[email protected]>
Cc: [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]>; Bjorn Helgaas <[email protected]>; Simon Horman <[email protected]>; Shradha Gupta <[email protected]>; Dipayaan Roy <[email protected]>; Erni Sri Satya Vennela <[email protected]>; [email protected]; linux- [email protected]; Paul Rosswurm <[email protected]>
Subject: [EXTERNAL] Re: [PATCH net-next] net: mana: Add handler for sriov configureQuoted 9 lines · Haiyang Zhang
From: Haiyang Zhang <[email protected]>
Add callback function for the
pci_driver,sriov_configure.Also disable VF autoprobe when it runs as PF driver on bare metal, since the hardware side may not have the VF ready immediately.
Export
pci_vf_drivers_autoprobe()so the driver can toggle the VF autoprobe flag.
Quoted 6 lines
Technically
pci_vf_drivers_autoprobe()doesn't *toggle* the autoprobe flag. That would mean setting it to the opposite of its current value.Here I would say "so the driver can prevent autoprobing of the VFs", which is the intent.
Thanks, I will change the wording.
Quoted 5 lines
Out of curiosity, how do the VFs eventually get probed? I guess there's some other mechanism that tells you when they're ready, and you manually use sysfs '
sriov_drivers_autoprobe' to enable probing, then bind drivers to them via sysfs?
We have a user program talking to the Azure backplane to get that information. @Paul Rosswurm, do you have more details?
Quoted 3 lines
The prevention of autoprobing sounds like a critical part of this change; might be worth saying something in the subject, because "add sriov configure" doesn't include much information.
How about "Add handler for sriov configure with VF autoprobe off"?
Thanks,
- Haiyang
Quoted 42 lines · Haiyang Zhang
Quoted 29 lines
-----Original Message-----
From: Bjorn Helgaas <[email protected]>
Sent: Friday, May 8, 2026 6:38 PM
To: Haiyang Zhang <[email protected]>
Cc: [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]>; Bjorn Helgaas <[email protected]>; Simon Horman <[email protected]>; Shradha Gupta <[email protected]>; Dipayaan Roy <[email protected]>; Erni Sri Satya Vennela <[email protected]>; [email protected]; linux- [email protected]; Paul Rosswurm <[email protected]>
Subject: [EXTERNAL] Re: [PATCH net-next] net: mana: Add handler for sriov configureQuoted 9 lines · Haiyang Zhang
From: Haiyang Zhang <[email protected]>
Add callback function for the
pci_driver,sriov_configure.Also disable VF autoprobe when it runs as PF driver on bare metal, since the hardware side may not have the VF ready immediately.
Export
pci_vf_drivers_autoprobe()so the driver can toggle the VF autoprobe flag.Quoted 6 lines
Technically
pci_vf_drivers_autoprobe()doesn't *toggle* the autoprobe flag. That would mean setting it to the opposite of its current value.Here I would say "so the driver can prevent autoprobing of the VFs", which is the intent.
Thanks, I will change the wording.
Quoted 5 lines
Out of curiosity, how do the VFs eventually get probed? I guess there's some other mechanism that tells you when they're ready, and you manually use sysfs '
sriov_drivers_autoprobe' to enable probing, then bind drivers to them via sysfs?
Quoted 8 lines
We have a user program talking to the Azure backplane to get that information. @Paul Rosswurm, do you have more details?
Quoted 3 lines
The prevention of autoprobing sounds like a critical part of this change; might be worth saying something in the subject, because "add sriov configure" doesn't include much information.
How about "Add handler for sriov configure with VF autoprobe off"?
OK by me :)
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] Missing `pci_disable_sriov()` in PF driver's `remove` and `shutdown` paths causes resource leaks…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Missing pci_disable_sriov() in PF driver's remove and shutdown paths causes resource leaks and potential Use-After-Free.
- [Medium] Missing VF assignment check in mana_sriov_configure causes silent failure when disabling SR-IOV.
--
commit 1f4061f22025ea097273f720b3bccac577e7d805
Author: Haiyang Zhang <[email protected]>
net: mana: Add handler for sriov configure
This commit adds the sriov_configure callback to the mana pci_driver to handle SR-IOV configuration. It also exports pci_vf_drivers_autoprobe() and disables VF autoprobe when running as a PF driver on bare metal.
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 2268
Quoted 3 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +0
-0@@ -2262,6 +2267,20 @@ static void mana_gd_shutdown(struct pci_dev *pdev)pci_disable_device (pdev); }
Does this code need to explicitly call pci_disable_sriov() during driver remove and shutdown?
If the PF driver is unbound while VFs are enabled, the PCI core logs a warning but does not automatically disable SR-IOV. With the VFs remaining active, could they interact with dead hardware or trigger host-side PF events that rely on the freed gdma_context, resulting in a use-after-free?
drivers/net/ethernet/microsoft/mana/gdma_main.c static void mana_gd_shutdown(struct pci_dev *pdev) · line 2281
Quoted 12 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +12
-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); + +return err ? err : numvfs;
If VFs are currently assigned to a guest VM (e.g., via VFIO), the PCI core's sriov_disable() will internally abort the teardown. Because pci_disable_sriov() returns void, will this function return 0 and falsely signal to userspace that the disable operation succeeded?
Should this code check pci_vfs_assigned(pdev) and return -EPERM, or use the generic pci_sriov_configure_simple() helper instead?
Quoted 2 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +2
-0+} +
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 47 lines · Bjorn Helgaas
Quoted 46 lines · Haiyang Zhang
Quoted 29 lines
-----Original Message-----
From: Bjorn Helgaas <[email protected]>
Sent: Friday, May 8, 2026 6:38 PM
To: Haiyang Zhang <[email protected]>
Cc: [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]>; Bjorn Helgaas <[email protected]>; Simon Horman <[email protected]>; Shradha Gupta <[email protected]>; Dipayaan Roy <[email protected]>; Erni Sri Satya Vennela <[email protected]>; [email protected]; linux- [email protected]; Paul Rosswurm <[email protected]>
Subject: [EXTERNAL] Re: [PATCH net-next] net: mana: Add handler for sriov configureQuoted 9 lines · Haiyang Zhang
From: Haiyang Zhang <[email protected]>
Add callback function for the
pci_driver,sriov_configure.Also disable VF autoprobe when it runs as PF driver on bare metal, since the hardware side may not have the VF ready immediately.
Export
pci_vf_drivers_autoprobe()so the driver can toggle the VF autoprobe flag.Quoted 6 lines
Technically
pci_vf_drivers_autoprobe()doesn't *toggle* the autoprobe flag. That would mean setting it to the opposite of its current value.Here I would say "so the driver can prevent autoprobing of the VFs", which is the intent.
Thanks, I will change the wording.
Quoted 5 lines
Out of curiosity, how do the VFs eventually get probed? I guess there's some other mechanism that tells you when they're ready, and you manually use sysfs '
sriov_drivers_autoprobe' to enable probing, then bind drivers to them via sysfs?We have a user program talking to the Azure backplane to get that information. @Paul Rosswurm, do you have more details?
Quoted 6 lines
Quoted 4 lines
Quoted 3 lines
The prevention of autoprobing sounds like a critical part of this change; might be worth saying something in the subject, because "add sriov configure" doesn't include much information.
How about "Add handler for sriov configure with VF autoprobe off"?
OK by me :)
Bjorn,
I believe it is the wrong decision to allow toggling a user‑visible knob without the user’s awareness. In this case, they can either disable autoprobe on the PF or rely on EPROBE_DEFER. In all cases, the same functionality can be achieved without changing PCI autoprobe code.
Thanks.
Quoted 1 line
Quoted 33 lines · Leon Romanovsky
Quoted 32 lines · Bjorn Helgaas
Quoted 31 lines · Haiyang Zhang
Quoted 11 lines · Haiyang Zhang
Quoted 9 lines
From: Haiyang Zhang <[email protected]>
Add callback function for the
pci_driver,sriov_configure.Also disable VF autoprobe when it runs as PF driver on bare metal, since the hardware side may not have the VF ready immediately.
Export
pci_vf_drivers_autoprobe()so the driver can toggle the VF autoprobe flag.Quoted 6 lines
Technically
pci_vf_drivers_autoprobe()doesn't *toggle* the autoprobe flag. That would mean setting it to the opposite of its current value.Here I would say "so the driver can prevent autoprobing of the VFs", which is the intent.
Thanks, I will change the wording.
Quoted 5 lines
Out of curiosity, how do the VFs eventually get probed? I guess there's some other mechanism that tells you when they're ready, and you manually use sysfs '
sriov_drivers_autoprobe' to enable probing, then bind drivers to them via sysfs?We have a user program talking to the Azure backplane to get that information. @Paul Rosswurm, do you have more details?
Quoted 3 lines
The prevention of autoprobing sounds like a critical part of this change; might be worth saying something in the subject, because "add sriov configure" doesn't include much information.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
How about "Add handler for sriov configure with VF autoprobe off"?
OK by me :)
I believe it is the wrong decision to allow toggling a user‑visible knob without the user’s awareness. In this case, they can either disable autoprobe on the PF or rely on
EPROBE_DEFER. In all cases, the same functionality can be achieved without changing PCI autoprobe code.
OK, Haiyang, can you drop my ack please? If Leon's solutions don't work for you, continue this conversation and we can explore alternatives.
Bjorn
Haiyang Zhang
maintainerQuoted 68 lines
-----Original Message-----
From: Bjorn Helgaas <[email protected]>
Sent: Wednesday, May 13, 2026 3:05 PM
To: Leon Romanovsky <[email protected]>
Cc: Haiyang Zhang <[email protected]>; Haiyang Zhang <[email protected]>; Paul Rosswurm <[email protected]>; [email protected]; [email protected]; KY Srinivasan <[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]>; Bjorn Helgaas <[email protected]>; Simon Horman <[email protected]>; Shradha Gupta <[email protected]>; Dipayaan Roy <[email protected]>; Erni Sri Satya Vennela <[email protected]>; [email protected]; linux- [email protected]
Subject: Re: [EXTERNAL] Re: [PATCH net-next] net: mana: Add handler for sriov configureQuoted 8 lines · Leon Romanovsky
Quoted 7 lines · Bjorn Helgaas
Quoted 6 lines · Haiyang Zhang
Quoted 6 lines · Haiyang Zhang
Quoted 5 lines
From: Haiyang Zhang <[email protected]>
Add callback function for the
pci_driver,sriov_configure.Also disable VF autoprobe when it runs as PF driver on bare
metal,
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
since the hardware side may not have the VF ready immediately.
Export
pci_vf_drivers_autoprobe()so the driver can toggle theVF
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
autoprobe flag.
Technically
pci_vf_drivers_autoprobe()doesn't *toggle* theautoprobe
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
flag. That would mean setting it to the opposite of its current value.
Here I would say "so the driver can prevent autoprobing of the
VFs",
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
which is the intent.
Thanks, I will change the wording.
Quoted 3 lines
Out of curiosity, how do the VFs eventually get probed? I guess there's some other mechanism that tells you when they're ready,
and
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
you manually use sysfs '
sriov_drivers_autoprobe' to enableprobing,
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 1 line
then bind drivers to them via sysfs?
We have a user program talking to the Azure backplane to get that
information.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
@Paul Rosswurm, do you have more details?
Quoted 2 lines
The prevention of autoprobing sounds like a critical part of this change; might be worth saying something in the subject, because
"add
Quoted 5 lines
Quoted 4 lines
Quoted 2 lines
Quoted 1 line
sriov configure" doesn't include much information.
How about "Add handler for sriov configure with VF autoprobe off"?
OK by me :)
Quoted 8 lines
Quoted 4 lines
I believe it is the wrong decision to allow toggling a user‑visible knob without the user’s awareness. In this case, they can either disable autoprobe on the PF or rely on
EPROBE_DEFER. In all cases, the same functionality can be achieved without changing PCI autoprobe code.OK, Haiyang, can you drop my ack please? If Leon's solutions don't work for you, continue this conversation and we can explore alternatives.
Sure, I will submit an updated patch without changing VF autoprobe.
Thanks,
- Haiyang