cnic fixes.
Subsystems (2)
v2 cover cnic fixes.
Fix 2 sleeping function from invalid context bugs and 1 missing iscsi netlink message bug.
v2: Fixed typo in rcu_dereference_protected() and tested with CONFIG_PROVE_RCU
Michael Chan (3):
cnic: Don't take rcu_read_lock in cnic_rcv_netevent()
cnic: Don't take cnic_dev_lock in cnic_alloc_uio_rings()
cnic: Fix missing ISCSI_KEVENT_IF_DOWN message
drivers/net/ethernet/broadcom/cnic.c | 29 ++++++++++++++++------------- 1 files changed, 16 insertions(+), 13 deletions(-)
PATCH v2 1/3 cnic: Don't take rcu_read_lock in cnic_rcv_netevent()
Because the called function, such as bnx2fc_indicate_netevent(), can sleep, we cannot take rcu_lock(). To prevent the rcu protected ulp_ops from going away, we use the cnic_lock mutex and set the ULP_F_CALL_PENDING flag. The code already waits for ULP_F_CALL_PENDING flag to clear in cnic_unregister_device().
--- drivers/net/ethernet/broadcom/cnic.c | 15 +++++++++++---- 1 files changed, 11 insertions(+), 4 deletions(-)
drivers/net/ethernet/broadcom/cnic.c +11 -4
@@ -5624,20 +5624,27 @@ static void cnic_rcv_netevent(struct cnic_local *cp, unsigned long event, {int if_type; -rcu_read_lock ();for (if_type =0 ; if_type <MAX_CNIC_ULP_TYPE ; if_type++) {struct cnic_ulp_ops *ulp_ops;void *ctx; - ulp_ops =rcu_dereference (cp->ulp_ops[if_type]); -if (!ulp_ops || !ulp_ops->indicate_netevent) +mutex_lock (&cnic_lock); + ulp_ops =rcu_dereference_protected (cp->ulp_ops[if_type], +lockdep_is_held (&cnic_lock)); +if (!ulp_ops || !ulp_ops->indicate_netevent) { +mutex_unlock (&cnic_lock);continue ; + } ctx = cp->ulp_handle[if_type]; +set_bit (ULP_F_CALL_PENDING , &cp->ulp_flags[if_type]); +mutex_unlock (&cnic_lock); + ulp_ops->indicate_netevent (ctx, event, vlan_id); + +clear_bit (ULP_F_CALL_PENDING , &cp->ulp_flags[if_type]); } -rcu_read_unlock (); }/* netdev event handler */
Signature · 1 line
1.7.1
PATCH v2 2/3 cnic: Don't take cnic_dev_lock in cnic_alloc_uio_rings()
We are allocating memory with GFP_KERNEL under spinlock. Since this is the only call manipulating the cnic_udev_list and it is always under rtnl_lock, cnic_dev_lock can be safely removed.
--- drivers/net/ethernet/broadcom/cnic.c | 6 ------ 1 files changed, 0 insertions(+), 6 deletions(-)
drivers/net/ethernet/broadcom/cnic.c +0 -6
@@ -1039,21 +1039,17 @@ static int cnic_alloc_uio_rings(struct cnic_dev *dev, int pages)struct cnic_local *cp = dev->cnic_priv;struct cnic_uio_dev *udev; -read_lock (&cnic_dev_lock);list_for_each_entry (udev, &cnic_udev_list, list) {if (udev->pdev == dev->pcidev) { udev->dev = dev;if (__cnic_alloc_uio_rings (udev, pages)) { udev->dev =NULL ; -read_unlock (&cnic_dev_lock);return -ENOMEM ; } cp->udev = udev; -read_unlock (&cnic_dev_lock);return 0 ; } } -read_unlock (&cnic_dev_lock); udev =kzalloc (sizeof (struct cnic_uio_dev ),GFP_ATOMIC );if (!udev)
@@ -1067,9 +1063,7 @@ static int cnic_alloc_uio_rings(struct cnic_dev *dev, int pages)if (__cnic_alloc_uio_rings (udev, pages)) goto err_udev; -write_lock (&cnic_dev_lock);list_add (&udev->list, &cnic_udev_list); -write_unlock (&cnic_dev_lock);pci_dev_get (udev->pdev);
Signature · 1 line
1.7.1
PATCH v2 3/3 cnic: Fix missing ISCSI_KEVENT_IF_DOWN message
The iSCSI netlink message needs to be sent before the ulp_ops is cleared as it is sent through a function pointer in the ulp_ops. This bug causes iscsid to not get the message when the bnx2i driver is unloaded.
--- drivers/net/ethernet/broadcom/cnic.c | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-)
drivers/net/ethernet/broadcom/cnic.c +5 -3
@@ -608,6 +608,10 @@ static int cnic_unregister_device(struct cnic_dev *dev, int ulp_type)pr_err ("%s: Bad type %d\n" , __func__, ulp_type);return -EINVAL ; } + +if (ulp_type ==CNIC_ULP_ISCSI ) +cnic_send_nlmsg (cp,ISCSI_KEVENT_IF_DOWN ,NULL ); +mutex_lock (&cnic_lock);if (rcu_dereference (cp->ulp_ops[ulp_type])) {RCU_INIT_POINTER (cp->ulp_ops[ulp_type],NULL );
@@ -620,9 +624,7 @@ static int cnic_unregister_device(struct cnic_dev *dev, int ulp_type) }mutex_unlock (&cnic_lock); -if (ulp_type ==CNIC_ULP_ISCSI ) -cnic_send_nlmsg (cp,ISCSI_KEVENT_IF_DOWN ,NULL ); -else if (ulp_type ==CNIC_ULP_FCOE ) +if (ulp_type ==CNIC_ULP_FCOE ) dev->fcoe_cap =NULL ;synchronize_rcu ();
Signature · 1 line
1.7.1
David Miller
maintainerFrom: Michael Chan <[email protected]>
Date: Mon, 2 Jun 2014 23:08:45 -0700
Quoted 4 lines
Fix 2 sleeping function from invalid context bugs and 1 missing iscsi netlink message bug.
v2: Fixed typo in
rcu_dereference_protected()and tested withCONFIG_PROVE_RCU
Looks a lot better, series applied, thanks.