From: Mengyuan Lou <mengyuanlou@net-swift.com>
To: netdev@vger.kernel.org
Cc: jiawenwu@trustnetic.com, duanqiangwen@net-swift.com,
linglingzhang@net-swift.com, andrew+netdev@lunn.ch,
davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, hramamurthy@google.com,
Mengyuan Lou <mengyuanlou@net-swift.com>
Subject: [PATCH net v2] net: libwx: fix PM suspend/resume flow for VF drivers
Date: Sat, 29 Aug 2026 17:14:23 +0800 [thread overview]
Message-ID: <20260829091423.83097-1-mengyuanlou@net-swift.com> (raw)
In the current wxvf_suspend() and wxvf_resume() implementations, power
management operations lack synchronization with network device
configuration, and proper hardware cleanup/restoration lifecycle
handling is missing.
Specifically:
1. Operations are not guarded by rtnl_lock(), leading to potential race
conditions with concurrent netdevice callbacks.
2. The suspend path leaves background work and timers running, omits
disabling TX queues/NAPI instances, and fails to release IRQ and ring
resources when the interface is up.
3. The resume path does not re-enable the PCI device with MEM access, lacks
re-allocation and request of MSI-X IRQs/resources, and missing proper
unroll error handling upon failures.
Fix these issues with the following changes:
- Synchronize both suspend and resume handlers under rtnl_lock().
- In wxvf_suspend(), synchronously cancel background timers/service tasks,
clear state flags, bring down queues and NAPI, free IRQ/resources if
running, and clear PCI bus master flag before disabling the device.
- In wxvf_resume(), re-enable the PCI device via pci_enable_device_mem(),
re-initialize the interrupt scheme, and for running interfaces,
re-allocate resources, re-request MSI-X IRQs, triggering
WX_FLAG_NEED_DO_RESET for subsequent HW reset handling, and attach the
device. Complete error handling paths are added to rollback safely on
failures.
Fixes: 377d180bd71c ("net: wangxun: add txgbevf build")
Signed-off-by: Mengyuan Lou <mengyuanlou@net-swift.com>
---
Changelogs:
v2:
- Refactored the suspend and resume logic to eliminate full netdevice close/open
cycles in favor of lightweight interrupt and queue manipulation:
* In wxvf_suspend(), replaced wxvf_close() with explicit queue stopping
(netif_tx_disable), carrier drop, NAPI disabling (wx_napi_disable_all), IRQ
releasing (wx_free_irq), and resource freeing (wx_free_resources).
* In wxvf_resume(), replaced wxvf_open() with granular resource allocation
(wx_setup_resources), MSI-X IRQ requesting (wx_request_msix_irqs_vf), and deferred
hardware reconfiguration via WX_FLAG_NEED_DO_RESET flag.
- Dropped the addition of device_link_add() to parent PF in ngbevf and txgbevf probe()
paths to keep the patch focused strictly on libwx PM suspend/resume flow.
v1: https://lore.kernel.org/netdev/20260826095243.16939-1-mengyuanlou@net-swift.com/
---
.../net/ethernet/wangxun/libwx/wx_vf_common.c | 62 ++++++++++++++++++-
1 file changed, 59 insertions(+), 3 deletions(-)
diff --git a/drivers/net/ethernet/wangxun/libwx/wx_vf_common.c b/drivers/net/ethernet/wangxun/libwx/wx_vf_common.c
index 26de78e9a69e..8a212e36c3d8 100644
--- a/drivers/net/ethernet/wangxun/libwx/wx_vf_common.c
+++ b/drivers/net/ethernet/wangxun/libwx/wx_vf_common.c
@@ -15,10 +15,26 @@ int wxvf_suspend(struct device *dev_d)
{
struct pci_dev *pdev = to_pci_dev(dev_d);
struct wx *wx = pci_get_drvdata(pdev);
+ struct net_device *netdev;
- netif_device_detach(wx->netdev);
+ netdev = wx->netdev;
+ timer_delete_sync(&wx->service_timer);
+ cancel_work_sync(&wx->service_task);
+ clear_bit(WX_STATE_SERVICE_SCHED, wx->state);
+
+ rtnl_lock();
+ netif_device_detach(netdev);
+ if (netif_running(netdev)) {
+ netif_tx_disable(netdev);
+ netif_carrier_off(netdev);
+ wx_napi_disable_all(wx);
+ wx_free_irq(wx);
+ wx_free_resources(wx);
+ }
wx_clear_interrupt_scheme(wx);
+ pci_clear_master(pdev);
pci_disable_device(pdev);
+ rtnl_unlock();
return 0;
}
@@ -34,12 +50,52 @@ int wxvf_resume(struct device *dev_d)
{
struct pci_dev *pdev = to_pci_dev(dev_d);
struct wx *wx = pci_get_drvdata(pdev);
+ struct net_device *netdev;
+ int err;
+
+ netdev = wx->netdev;
+ err = pci_enable_device_mem(pdev);
+ if (err) {
+ dev_err(&pdev->dev, "Cannot enable PCI device from suspend\n");
+ return err;
+ }
pci_set_master(pdev);
- wx_init_interrupt_scheme(wx);
- netif_device_attach(wx->netdev);
+ rtnl_lock();
+
+ err = wx_init_interrupt_scheme(wx);
+ if (err)
+ goto err_pci;
+
+ /* Since vf resume before than pf, only the vf interrupt and software
+ * resources need to be initialized. The hardware configuration will be
+ * reconfigured in reset subtask.
+ */
+ if (netif_running(netdev)) {
+ err = wx_setup_resources(wx);
+ if (err)
+ goto err_clear_int;
+
+ err = wx_request_msix_irqs_vf(wx);
+ if (err)
+ goto err_free_resources;
+
+ wxvf_up_complete(wx);
+ set_bit(WX_FLAG_NEED_DO_RESET, wx->flags);
+ }
+
+ netif_device_attach(netdev);
+ rtnl_unlock();
return 0;
+err_free_resources:
+ wx_free_resources(wx);
+err_clear_int:
+ wx_clear_interrupt_scheme(wx);
+err_pci:
+ rtnl_unlock();
+ pci_disable_device(pdev);
+ return err;
}
EXPORT_SYMBOL(wxvf_resume);
--
2.30.1
next reply other threads:[~2026-08-29 9:15 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-29 9:14 Mengyuan Lou [this message]
2026-09-03 0:16 ` [net,v2] net: libwx: fix PM suspend/resume flow for VF drivers netdev-bot+sashiko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260829091423.83097-1-mengyuanlou@net-swift.com \
--to=mengyuanlou@net-swift.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=duanqiangwen@net-swift.com \
--cc=edumazet@google.com \
--cc=hramamurthy@google.com \
--cc=jiawenwu@trustnetic.com \
--cc=kuba@kernel.org \
--cc=linglingzhang@net-swift.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox