bnx2x: Revising locking scheme for MAC configuration
PATCH 1/1 bnx2x: Revising locking scheme for MAC configuration
On very rare occasions, repeated load/unload stress test in the presence of our storage driver (bnx2i/bnx2fc) causes a kernel panic in bnx2x code (NULL pointer dereference). Stack traces indicate the issue happens during MAC configuration; thorough code review showed that indeed several races exist in which one thread can iterate over the list of configured MACs while another deletes entries from the same list.
This patch adds a varient on the single-writer/Multiple-reader lock mechanism - It utilizes an already exsiting bottom-half lock, using it so that Whenever a writer is unable to continue due to the existence of another writer/reader, it pends its request for future deliverance.
The writer / last readers will check for the existence of such requests and perform them instead of the original initiator.
This prevents the writer from having to sleep while waiting for the lock to be accessible, which might cause deadlocks given the locks already held by the writer.
Another result of this patch is that setting of Rx Mode is now made in sleepable context - Setting of Rx Mode is made under a bottom-half lock, which was always nontrivial for the bnx2x driver, as the HW/FW configuration requires wait for completions.
Since sleep was impossible (due to the sleepless-context), various mechanisms were utilized to prevent the calling thread from sleep, but the truth was that when the caller thread (i.e, the one calling ndo_set_rx_mode()) returned, the Rx mode was still not set in HW/FW.
bnx2x_set_rx_mode() will now overtly schedule for the Rx changes to be configured by the sp_rtnl_task which hold the RTNL lock and is sleepable context.
---
Dave, this is a relatively large fix for a relatively small (and rare) bug - thus we're designating it to `net-next'.
Please consider applying the patch.
Thanks,
Yuval
--- drivers/net/ethernet/broadcom/bnx2x/bnx2x.h | 2 +- drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c | 16 +- drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h | 1 + drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c | 56 ++-- drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c | 299 ++++++++++++++++++++-- drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h | 16 +- drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.c | 10 +- 7 files changed, 340 insertions(+), 60 deletions(-)
drivers/net/ethernet/broadcom/bnx2x/bnx2x.h +1 -1
@@ -1331,7 +1331,7 @@ enum {BNX2X_SP_RTNL_ENABLE_SRIOV ,BNX2X_SP_RTNL_VFPF_MCAST ,BNX2X_SP_RTNL_VFPF_CHANNEL_DOWN , -BNX2X_SP_RTNL_VFPF_STORM_RX_MODE , +BNX2X_SP_RTNL_RX_MODE , BNX2X_SP_RTNL_HYPERVISOR_VLAN, };
drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c +9 -7
@@ -2060,7 +2060,11 @@ void bnx2x_squeeze_objects(struct bnx2x *bp) rparam.mcast_obj = &bp->mcast_obj;__set_bit (RAMROD_DRV_CLR_ONLY , &rparam.ramrod_flags); -/* Add a DEL command... */ +/* Add a DEL command... - Since we're doing a driver cleanup only, +* we take a lock surrounding both the initial send and the CONTs, +* as we don't want a true completion to disrupt us in the middle. +*/ +netif_addr_lock_bh (bp->dev); rc =bnx2x_config_mcast (bp, &rparam,BNX2X_MCAST_CMD_DEL );if (rc <0 ) BNX2X_ERR("Failed to add a new DEL command to a multi-cast object: %d\n",
@@ -2072,11 +2076,13 @@ void bnx2x_squeeze_objects(struct bnx2x *bp)if (rc <0 ) {BNX2X_ERR ("Failed to clean multi-cast object: %d\n" , rc); +netif_addr_unlock_bh (bp->dev);return ; } rc =bnx2x_config_mcast (bp, &rparam,BNX2X_MCAST_CMD_CONT ); } +netif_addr_unlock_bh (bp->dev); }#ifndef BNX2X_STOP_ON_ERROR
@@ -2432,9 +2438,7 @@ int bnx2x_load_cnic(struct bnx2x *bp) }/* Initialize Rx filter. */ -netif_addr_lock_bh (bp->dev); -bnx2x_set_rx_mode (bp->dev); -netif_addr_unlock_bh (bp->dev); +bnx2x_set_rx_mode_inner (bp);/* re-read iscsi info */ bnx2x_get_iscsi_info (bp);
@@ -2704,9 +2708,7 @@ int bnx2x_nic_load(struct bnx2x *bp, int load_mode)/* Start fast path */ /* Initialize Rx filter. */ -netif_addr_lock_bh (bp->dev); -bnx2x_set_rx_mode (bp->dev); -netif_addr_unlock_bh (bp->dev); +bnx2x_set_rx_mode_inner (bp);/* Start the Tx */ switch (load_mode) {
drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h +1 -0
@@ -418,6 +418,7 @@ int bnx2x_set_eth_mac(struct bnx2x *bp, bool set);* netif_addr_lock_bh() */ void bnx2x_set_rx_mode (struct net_device *dev); +void bnx2x_set_rx_mode_inner (struct bnx2x *bp);/** * bnx2x_set_storm_rx_mode - configure MAC filtering rules in a FW.
drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c +33 -23
100 lines not on this page · raw message
drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c +272 -27
427 lines not on this page · raw message
drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h +15 -1
@@ -285,6 +285,12 @@ struct bnx2x_vlan_mac_obj {* entries. */ struct list_head head; +/* Implement a simple reader/writer lock on the head list. +* all these fields should only be accessed under the exe_queue lock +*/ +u8 head_reader;/* Num. of readers accessing head list */ +bool head_exe_request;/* Pending execution request. */ +unsigned long saved_ramrod_flags;/* Ramrods of pending execution */ /* TODO: Add it's initialization in the init functions */ struct bnx2x_exe_queue_obj exe_queue;
@@ -1302,8 +1308,16 @@ void bnx2x_init_vlan_mac_obj(struct bnx2x *bp,struct bnx2x_credit_pool_obj *macs_pool, struct bnx2x_credit_pool_obj *vlans_pool); +int bnx2x_vlan_mac_h_read_lock (struct bnx2x *bp, +struct bnx2x_vlan_mac_obj *o); +void bnx2x_vlan_mac_h_read_unlock (struct bnx2x *bp, +struct bnx2x_vlan_mac_obj *o); +int bnx2x_vlan_mac_h_write_lock (struct bnx2x *bp, +struct bnx2x_vlan_mac_obj *o); +void bnx2x_vlan_mac_h_write_unlock (struct bnx2x *bp, +struct bnx2x_vlan_mac_obj *o);int bnx2x_config_vlan_mac (struct bnx2x *bp, -struct bnx2x_vlan_mac_ramrod_params *p); +struct bnx2x_vlan_mac_ramrod_params *p); int bnx2x_vlan_mac_move(struct bnx2x *bp, struct bnx2x_vlan_mac_ramrod_params *p,
drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.c +9 -1
@@ -491,12 +491,20 @@ static inline void bnx2x_vfop_credit(struct bnx2x *bp,* and a valid credit counter */ if (!vfop->rc && args->credit) { -int cnt =0 ;struct list_head *pos; +int read_lock; +int cnt =0 ; + + read_lock =bnx2x_vlan_mac_h_read_lock (bp, obj); +if (read_lock) +DP (BNX2X_MSG_SP ,"Failed to take vlan mac read head; continuing anyway\n" );list_for_each (pos, &obj->head) cnt++; +if (!read_lock) +bnx2x_vlan_mac_h_read_unlock (bp, obj); +atomic_set (args->credit, cnt); } }
Signature · 1 line
1.8.1.227.g44fe835
From: "Yuval Mintz" <[email protected]>
Date: Thu, 1 Aug 2013 17:30:59 +0300
Quoted 26 lines
On very rare occasions, repeated load/unload stress test in the presence of our storage driver (bnx2i/bnx2fc) causes a kernel panic in bnx2x code (NULL pointer dereference). Stack traces indicate the issue happens during MAC configuration; thorough code review showed that indeed several races exist in which one thread can iterate over the list of configured MACs while another deletes entries from the same list.
This patch adds a varient on the single-writer/Multiple-reader lock mechanism - It utilizes an already exsiting bottom-half lock, using it so that Whenever a writer is unable to continue due to the existence of another writer/reader, it pends its request for future deliverance.
The writer / last readers will check for the existence of such requests and perform them instead of the original initiator.
This prevents the writer from having to sleep while waiting for the lock to be accessible, which might cause deadlocks given the locks already held by the writer.Another result of this patch is that setting of Rx Mode is now made in sleepable context - Setting of Rx Mode is made under a bottom-half lock, which was always nontrivial for the bnx2x driver, as the HW/FW configuration requires wait for completions.
Since sleep was impossible (due to the sleepless-context), various mechanisms were utilized to prevent the calling thread from sleep, but the truth was that when the caller thread (i.e, the one callingndo_set_rx_mode()) returned, the Rx mode was still not set in HW/FW.
Quoted 7 lines
bnx2x_set_rx_mode()will now overtly schedule for the Rx changes to be configured by thesp_rtnl_taskwhich hold the RTNL lock and is sleepable context.Signed-off-by Yuval Mintz <[email protected]>Signed-off-by Ariel Elior <[email protected]>Signed-off-by Eilon Greenstein <[email protected]>
Applied to net-next, thanks.