bnxt_en: Take RTNL before netif_close() when aborting FW reset
PATCH 1/1 bnxt_en: Take RTNL before netif_close() when aborting FW reset
netif_close() must be called with RTNL held in addition to the netdev instance lock: __dev_close_many() asserts it, and the NETDEV_GOING_DOWN and NETDEV_DOWN notifier chains it runs rely on it for serialization.
Commit 004b5008016a ("eth: bnxt: remove most dependencies on RTNL") replaced rtnl_lock() with netdev_lock() in bnxt_fw_reset_task() and bnxt_fw_reset(). That is sufficient for the paths that only tear the NIC down internally with __bnxt_close_nic(), but the abort paths close the netdev via bnxt_fw_reset_abort() -> netif_close(), and the error path in bnxt_fw_reset() calls netif_close() directly. Those now run without RTNL and trigger a WARN_ONCE() cascade when a firmware reset is aborted:
RTNL: assertion failed at net/core/dev.c (1740)
WARNING: net/core/dev.c:1740 at __dev_close_many+0x1be/0x1f0 Workqueue: bnxt_pf_wq bnxt_fw_reset_task [bnxt_en] Call Trace: netif_close_many+0xb5/0x190 netif_close+0xa2/0xd0 bnxt_fw_reset_task.cold+0x8d/0x213 [bnxt_en] process_one_work+0x19d/0x3a0 worker_thread+0x1af/0x320 kthread+0xe3/0x120
followed by the same assertion from call_netdevice_notifiers_info(), fib_rules_event(), inetdev_event(), rtnl_fill_ifinfo(), devlink_compat_phys_port_name_get() and ip_mc_down().
This was observed on a machine in real use with a BCM57504 (4 PFs, FW 236.1.153.0) running v7.1.6: the firmware crashed, announced a "Fatal firmware reset event" and then failed to come back within the advertised max wait, so bnxt_fw_reset_task() aborted the reset on all ports:
bnxt_en 0000:c1:00.1 eno16905np1: Firmware reset aborted bnxt_en 0000:c1:00.1 eno16905np1: fw_health_status 0x448100
Take RTNL (before the netdev instance lock, matching the OPENING state which already uses rtnl_trylock()) in the fw_reset_abort path of bnxt_fw_reset_task() and route the POLL_VF abort through that same path. In bnxt_fw_reset() go back to bnxt_rtnl_lock_sp() so that its netif_close() error path is covered as well; bnxt_reset() and bnxt_rx_ring_reset() already take RTNL from bnxt_sp_task() the same way.
The bug was found by inspecting the kernel log of the affected machine and the driver source; the fix was prepared with the help of an AI coding assistant (Gemini based) and reviewed by the submitter. It is build tested (allmodconfig with W=1, plus the same change on top of v7.1.6 built as a module for the affected BCM57504 host). The aborted reset path itself only runs when the firmware fails to return from a reset, which could not be reproduced on demand.
--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +5 -4
@@ -14798,7 +14798,7 @@ static int bnxt_get_registered_vfs(struct bnxt *bp)void bnxt_fw_reset (struct bnxt *bp) {bnxt_ulp_stop (bp); -bnxt_lock_sp (bp); +bnxt_rtnl_lock_sp (bp);if (test_bit (BNXT_STATE_OPEN , &bp->state) && !test_bit (BNXT_STATE_IN_FW_RESET , &bp->state)) {struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
@@ -14844,7 +14844,7 @@ void bnxt_fw_reset(struct bnxt *bp)bnxt_queue_fw_reset_work (bp, tmo); } fw_reset_exit: -bnxt_unlock_sp (bp); +bnxt_rtnl_unlock_sp (bp); }static void bnxt_chk_missed_irq (struct bnxt *bp)
@@ -15495,9 +15495,8 @@ static void bnxt_fw_reset_task(struct work_struct *work) bp->fw_reset_timestamp = jiffies;netdev_lock (bp->dev);if (test_bit (BNXT_STATE_ABORT_ERR , &bp->state)) { -bnxt_fw_reset_abort (bp, rc);netdev_unlock (bp->dev); - goto ulp_start; + goto fw_reset_abort; }bnxt_fw_reset_close (bp);if (bp->fw_cap &BNXT_FW_CAP_ERR_RECOVER_RELOAD ) {
@@ -15630,9 +15629,11 @@ static void bnxt_fw_reset_task(struct work_struct *work)netdev_err (bp->dev,"fw_health_status 0x%x\n" , sts); } fw_reset_abort: +rtnl_lock ();netdev_lock (bp->dev);bnxt_fw_reset_abort (bp, rc);netdev_unlock (bp->dev); +rtnl_unlock (); ulp_start:if (!rc)bnxt_ulp_start (bp);
base-commit: fcc00b15cb21a6de76826e5012b2c758505f5e65
Signature · 1 line
2.56.0.313.g2479322e68-goog
Quoted 53 lines · Bryan Cochrane
netif_close()must be called with RTNL held in addition to the netdev instance lock:__dev_close_many()asserts it, and theNETDEV_GOING_DOWNandNETDEV_DOWNnotifier chains it runs rely on it for serialization.Commit
004b5008016a("eth: bnxt: remove most dependencies on RTNL") replacedrtnl_lock()withnetdev_lock()inbnxt_fw_reset_task()andbnxt_fw_reset(). That is sufficient for the paths that only tear the NIC down internally with__bnxt_close_nic(), but the abort paths close the netdev viabnxt_fw_reset_abort()->netif_close(), and the error path inbnxt_fw_reset()callsnetif_close()directly. Those now run without RTNL and trigger aWARN_ONCE()cascade when a firmware reset is aborted:RTNL: assertion failed at
net/core/dev.c(1740)WARNING: net/core/dev.c:1740 at __dev_close_many+0x1be/0x1f0 Workqueue: bnxt_pf_wq bnxt_fw_reset_task [bnxt_en] Call Trace: netif_close_many+0xb5/0x190 netif_close+0xa2/0xd0 bnxt_fw_reset_task.cold+0x8d/0x213 [bnxt_en] process_one_work+0x19d/0x3a0 worker_thread+0x1af/0x320 kthread+0xe3/0x120followed by the same assertion from
call_netdevice_notifiers_info(),fib_rules_event(),inetdev_event(),rtnl_fill_ifinfo(),devlink_compat_phys_port_name_get()andip_mc_down().This was observed on a machine in real use with a BCM57504 (4 PFs, FW 236.1.153.0) running v7.1.6: the firmware crashed, announced a "Fatal firmware reset event" and then failed to come back within the advertised max wait, so
bnxt_fw_reset_task()aborted the reset on all ports:
bnxt_en0000:c1:00.1 eno16905np1: Firmware reset abortedbnxt_en0000:c1:00.1 eno16905np1:fw_health_status0x448100Take RTNL (before the netdev instance lock, matching the OPENING state which already uses
rtnl_trylock()) in thefw_reset_abortpath ofbnxt_fw_reset_task()and route thePOLL_VFabort through that same path. Inbnxt_fw_reset()go back tobnxt_rtnl_lock_sp()so that itsnetif_close()error path is covered as well;bnxt_reset()andbnxt_rx_ring_reset()already take RTNL frombnxt_sp_task()the same way.The bug was found by inspecting the kernel log of the affected machine and the driver source; the fix was prepared with the help of an AI coding assistant (Gemini based) and reviewed by the submitter. It is build tested (allmodconfig with W=1, plus the same change on top of v7.1.6 built as a module for the affected BCM57504 host). The aborted reset path itself only runs when the firmware fails to return from a reset, which could not be reproduced on demand.
Quoted 3 lines
Fixes 004b5008016a ("eth: bnxt: remove most dependencies on RTNL")Signed-off-by Bryan Cochrane <[email protected]>
Michael Chan
maintainerdrivers/net/ethernet/broadcom/bnxt/bnxt.c static int bnxt_get_registered_vfs(struct bnxt *bp) · line 14801
Quoted 13 lines · Bryan Cochrane
drivers/net/ethernet/broadcom/bnxt/bnxt.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)drivers/net/ethernet/broadcom/bnxt/bnxt.c +1
-1@@ -14798,7 +14798,7 @@ static int bnxt_get_registered_vfs(struct bnxt *bp)void bnxt_fw_reset (struct bnxt *bp) {bnxt_ulp_stop (bp); -bnxt_lock_sp (bp); +bnxt_rtnl_lock_sp (bp);
Thanks for the patch. This isignificantly increases the scope of the rtnl_lock to cover the whole FW reset sequence. I'm concerned that with a large number of VFs running in the same kernel, the rtnl_lock contention will cause some of the VFs to fail recovery.
The abort path should generally be rare. I think it may be better to have a more localized fix for the abort path without increasing the scope of the rtnl_lock for the entire FW reset path.
Michael Chan
maintainerQuoted 6 lines · Michael Chan
Quoted 3 lines · Bryan Cochrane
drivers/net/ethernet/broadcom/bnxt/bnxt.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
Quoted 16 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c static int bnxt_get_registered_vfs(struct bnxt *bp) · line 14801
Quoted 10 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +1
-1@@ -14798,7 +14798,7 @@ static int bnxt_get_registered_vfs(struct bnxt *bp)void bnxt_fw_reset (struct bnxt *bp) {bnxt_ulp_stop (bp); -bnxt_lock_sp (bp); +bnxt_rtnl_lock_sp (bp);Thanks for the patch. This isignificantly increases the scope of the
rtnl_lockto cover the whole FW reset sequence. I'm concerned that with a large number of VFs running in the same kernel, thertnl_lockcontention will cause some of the VFs to fail recovery.
Looking more closely, I think the case that requires the rtnl_lock is very narrow. Only a PF with active VFs will need it in case bnxt_get_registered_vfs() fails. For example, all the VFs now will take the rtnl_lock for no reason and will cause unnecessary contention. I suggest fixing this bnxt_get_registered_vfs() failure more locally without increasing the scope of the rtnl_lock. Thanks.