Skip to contentSkip to conversation

cnic: Fix ISCSI_KEVENT_IF_DOWN message handling.

PATCH Applied Michael Chan 6 participants 9 messages Jul 23, 2009 – Jul 30, 2009 1 message not in the archive

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cnic: Fix ISCSI_KEVENT_IF_DOWN message handling.

When a net device goes down or when the bnx2i driver is unloaded, the code was not generating the ISCSI_KEVENT_IF_DOWN message properly and this could cause the userspace driver to crash.

This is fixed by sending the message properly in the shutdown path. cnic_uio_stop() is also added to send the message when bnx2i is unregistering.

---
 drivers/net/cnic.c |   23 +++++++++++++++++++++--
 1 files changed, 21 insertions(+), 2 deletions(-)
drivers/net/cnic.c +21 -2
index 4d1515f..4869d77 100644
@@ -227,7 +227,7 @@ static int cnic_send_nlmsg(struct cnic_local *cp, u32 type,
 	}
 
 	rcu_read_lock();
-	ulp_ops = rcu_dereference(cp->ulp_ops[CNIC_ULP_ISCSI]);
+	ulp_ops = rcu_dereference(cnic_ulp_tbl[CNIC_ULP_ISCSI]);
 	if (ulp_ops)
 		ulp_ops->iscsi_nl_send_msg(cp->dev, msg_type, buf, len);
 	rcu_read_unlock();
@@ -319,6 +319,20 @@ static int cnic_abort_prep(struct cnic_sock *csk)
 	return 0;
 }
 
+static void cnic_uio_stop(void)
+{
+	struct cnic_dev *dev;
+
+	read_lock(&cnic_dev_lock);
+	list_for_each_entry(dev, &cnic_dev_list, list) {
+		struct cnic_local *cp = dev->cnic_priv;
+
+		if (cp->cnic_uinfo)
+			cnic_send_nlmsg(cp, ISCSI_KEVENT_IF_DOWN, NULL);
+	}
+	read_unlock(&cnic_dev_lock);
+}
+
 int cnic_register_driver(int ulp_type, struct cnic_ulp_ops *ulp_ops)
 {
 	struct cnic_dev *dev;
@@ -390,6 +404,9 @@ int cnic_unregister_driver(int ulp_type)
 	}
 	read_unlock(&cnic_dev_lock);
 
+	if (ulp_type == CNIC_ULP_ISCSI)
+		cnic_uio_stop();
+
 	rcu_assign_pointer(cnic_ulp_tbl[ulp_type], NULL);
 
 	mutex_unlock(&cnic_lock);
@@ -632,7 +649,6 @@ static void cnic_free_resc(struct cnic_dev *dev)
 	int i = 0;
 
 	if (cp->cnic_uinfo) {
-		cnic_send_nlmsg(cp, ISCSI_KEVENT_IF_DOWN, NULL);
 		while (cp->uio_dev != -1 && i < 15) {
 			msleep(100);
 			i++;
@@ -1057,6 +1073,9 @@ static void cnic_ulp_stop(struct cnic_dev *dev)
 	struct cnic_local *cp = dev->cnic_priv;
 	int if_type;
 
+	if (cp->cnic_uinfo)
+		cnic_send_nlmsg(cp, ISCSI_KEVENT_IF_DOWN, NULL);
+
 	rcu_read_lock();
 	for (if_type = 0; if_type < MAX_CNIC_ULP_TYPE; if_type++) {
 		struct cnic_ulp_ops *ulp_ops;
Signature · 1 line
1.5.6.GIT
maintainer Applied
#1 lore raw

From: "Michael Chan" <[email protected]>
Date: Wed, 22 Jul 2009 20:01:55 -0700

Quoted 9 lines

When a net device goes down or when the bnx2i driver is unloaded, the code was not generating the ISCSI_KEVENT_IF_DOWN message properly and this could cause the userspace driver to crash.

This is fixed by sending the message properly in the shutdown path. cnic_uio_stop() is also added to send the message when bnx2i is unregistering.

Applied.

#2 lore raw
In reply to Michael Chan
Quoted 30 lines · Michael Chan

When a net device goes down or when the bnx2i driver is unloaded, the code was not generating the ISCSI_KEVENT_IF_DOWN message properly and this could cause the userspace driver to crash.

This is fixed by sending the message properly in the shutdown path. cnic_uio_stop() is also added to send the message when bnx2i is unregistering.

---
 drivers/net/cnic.c |   23 +++++++++++++++++++++--
 1 files changed, 21 insertions(+), 2 deletions(-)
drivers/net/cnic.c +1 -1
index 4d1515f..4869d77 100644
@@ -227,7 +227,7 @@ static int cnic_send_nlmsg(struct cnic_local *cp, u32 type,
 	}
 
 	rcu_read_lock();
-	ulp_ops = rcu_dereference(cp->ulp_ops[CNIC_ULP_ISCSI]);
+	ulp_ops = rcu_dereference(cnic_ulp_tbl[CNIC_ULP_ISCSI]);
 	if (ulp_ops)
 		ulp_ops->iscsi_nl_send_msg(cp->dev, msg_type, buf, len);
 	rcu_read_unlock();
@@ -319,6 +319,20 @@ static int cnic_abort_prep(struct cnic_sock *csk)
 	return 0;
 }
 

drivers/net/cnic.c static int cnic_abort_prep(struct cnic_sock *csk) · line 331

Quoted 10 lines
drivers/net/cnic.c +10 -0
+static void cnic_uio_stop(void)
+{
+	struct cnic_dev *dev;
+
+	read_lock(&cnic_dev_lock);
+	list_for_each_entry(dev, &cnic_dev_list, list) {
+		struct cnic_local *cp = dev->cnic_priv;
+
+		if (cp->cnic_uinfo)
+			cnic_send_nlmsg(cp, ISCSI_KEVENT_IF_DOWN, NULL);

I don't think you can call this with the cnic_dev_lock held. They have the same sleeping restrictions as a spin_lock right? If so, the problem is that iscsi_nl_send_ms calls iscsi_offload_mesg which uses GFP_NOIO and can sleep.

#3 lore raw
Quoted 42 lines · Mike Christie

drivers/net/cnic.c static int cnic_send_nlmsg(struct

Quoted 18 lines · Michael Chan

When a net device goes down or when the bnx2i driver is unloaded, the code was not generating the ISCSI_KEVENT_IF_DOWN message properly and this could cause the userspace driver to crash.

This is fixed by sending the message properly in the shutdown path. cnic_uio_stop() is also added to send the message when bnx2i is unregistering.

---
 drivers/net/cnic.c |   23 +++++++++++++++++++++--
 1 files changed, 21 insertions(+), 2 deletions(-)
drivers/net/cnic.c +0 -0
index 4d1515f..4869d77 100644
@@ -227,7 +227,7 @@ static int cnic_send_nlmsg(struct

cnic_local *cp, u32 type,

drivers/net/cnic.c static int cnic_abort_prep(struct

Quoted 9 lines
drivers/net/cnic.c +1 -1
    }
 
    rcu_read_lock();
-   ulp_ops = rcu_dereference(cp->ulp_ops[CNIC_ULP_ISCSI]);
+   ulp_ops = rcu_dereference(cnic_ulp_tbl[CNIC_ULP_ISCSI]);
    if (ulp_ops)
            ulp_ops->iscsi_nl_send_msg(cp->dev, msg_type, buf, len);
    rcu_read_unlock();
@@ -319,6 +319,20 @@ static int cnic_abort_prep(struct

cnic_sock *csk)

Quoted 12 lines
drivers/net/cnic.c +9 -0
    return 0;
 }
 
+static void cnic_uio_stop(void)
+{
+   struct cnic_dev *dev;
+
+   read_lock(&cnic_dev_lock);
+   list_for_each_entry(dev, &cnic_dev_list, list) {
+           struct cnic_local *cp = dev->cnic_priv;
+
+           if (cp->cnic_uinfo)
Quoted 10 lines

drivers/net/cnic.c static int cnic_abort_prep(struct · line 331

Quoted 1 line
drivers/net/cnic.c +1 -0
+                   cnic_send_nlmsg(cp, ISCSI_KEVENT_IF_DOWN, NULL);

I don't think you can call this with the cnic_dev_lock held. They have
the same sleeping restrictions as a spin_lock right? If so, the problem
is that iscsi_nl_send_ms calls iscsi_offload_mesg which uses GFP_NOIO and can sleep.

In that case, can I send in a patch to change iscsi_offload_mesg() to use GFP_ATOMIC?

#4 lore raw
Quoted 53 lines · Michael Chan
Quoted 33 lines · Mike Christie

drivers/net/cnic.c static int cnic_send_nlmsg(struct

Quoted 18 lines · Michael Chan

When a net device goes down or when the bnx2i driver is unloaded, the code was not generating the ISCSI_KEVENT_IF_DOWN message properly and this could cause the userspace driver to crash.

This is fixed by sending the message properly in the shutdown path. cnic_uio_stop() is also added to send the message when bnx2i is unregistering.

---
 drivers/net/cnic.c |   23 +++++++++++++++++++++--
 1 files changed, 21 insertions(+), 2 deletions(-)
drivers/net/cnic.c +0 -0
index 4d1515f..4869d77 100644
@@ -227,7 +227,7 @@ static int cnic_send_nlmsg(struct

cnic_local *cp, u32 type,

drivers/net/cnic.c static int cnic_abort_prep(struct

Quoted 9 lines
drivers/net/cnic.c +1 -1
    }
 
    rcu_read_lock();
-   ulp_ops = rcu_dereference(cp->ulp_ops[CNIC_ULP_ISCSI]);
+   ulp_ops = rcu_dereference(cnic_ulp_tbl[CNIC_ULP_ISCSI]);
    if (ulp_ops)
            ulp_ops->iscsi_nl_send_msg(cp->dev, msg_type, buf, len);
    rcu_read_unlock();
@@ -319,6 +319,20 @@ static int cnic_abort_prep(struct

cnic_sock *csk)

Quoted 3 lines
drivers/net/cnic.c +0 -0
    return 0;
 }
 
Quoted 18 lines

drivers/net/cnic.c static int cnic_abort_prep(struct cnic_sock *csk) · line 331

Quoted 10 lines
drivers/net/cnic.c +10 -0
+static void cnic_uio_stop(void)
+{
+   struct cnic_dev *dev;
+
+   read_lock(&cnic_dev_lock);
+   list_for_each_entry(dev, &cnic_dev_list, list) {
+           struct cnic_local *cp = dev->cnic_priv;
+
+           if (cp->cnic_uinfo)
+                   cnic_send_nlmsg(cp, ISCSI_KEVENT_IF_DOWN, NULL);

I don't think you can call this with the cnic_dev_lock held. They have
the same sleeping restrictions as a spin_lock right? If so, the problem
is that iscsi_nl_send_ms calls iscsi_offload_mesg which uses GFP_NOIO and can sleep.

Quoted 3 lines

In that case, can I send in a patch to change iscsi_offload_mesg() to use GFP_ATOMIC?

Yes, I guess so.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#6 lore raw

PATCH 1/1 iscsi: Use GFP_ATOMIC in iscsi_offload_mesg().

Changing to GFP_ATOMIC because the only caller in cnic/bnx2i may be calling this function while holding spin_lock.

This problem was discovered by Mike Christie.

---
 drivers/scsi/scsi_transport_iscsi.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/scsi_transport_iscsi.c +2 -2
index 783e33c..b47240c 100644
@@ -990,7 +990,7 @@ int iscsi_offload_mesg(struct Scsi_Host *shost,
 	struct iscsi_uevent *ev;
 	int len = NLMSG_SPACE(sizeof(*ev) + data_size);
 
-	skb = alloc_skb(len, GFP_NOIO);
+	skb = alloc_skb(len, GFP_ATOMIC);
 	if (!skb) {
 		printk(KERN_ERR "can not deliver iscsi offload message:OOM\n");
 		return -ENOMEM;
@@ -1012,7 +1012,7 @@ int iscsi_offload_mesg(struct Scsi_Host *shost,
 
 	memcpy((char *)ev + sizeof(*ev), data, data_size);
 
-	return iscsi_multicast_skb(skb, ISCSI_NL_GRP_UIP, GFP_NOIO);
+	return iscsi_multicast_skb(skb, ISCSI_NL_GRP_UIP, GFP_ATOMIC);
 }
 EXPORT_SYMBOL_GPL(iscsi_offload_mesg);
 
Signature · 1 line
1.5.6.GIT
Acked-by on v1 1/1
#7 lore raw

Re: [PATCH] iscsi: Use GFP_ATOMIC in iscsi_offload_mesg().

Quoted 24 lines · Michael Chan

Changing to GFP_ATOMIC because the only caller in cnic/bnx2i may be calling this function while holding spin_lock.

This problem was discovered by Mike Christie.

---
  drivers/scsi/scsi_transport_iscsi.c |    4 ++--
  1 files changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/scsi_transport_iscsi.c +1 -1
index 783e33c..b47240c 100644
@@ -990,7 +990,7 @@ int iscsi_offload_mesg(struct Scsi_Host *shost,
  	struct iscsi_uevent *ev;
  	int len = NLMSG_SPACE(sizeof(*ev) + data_size);
 
-	skb = alloc_skb(len, GFP_NOIO);
+	skb = alloc_skb(len, GFP_ATOMIC);
  	if (!skb) {
  		printk(KERN_ERR "can not deliver iscsi offload message:OOM\n");
  		return -ENOMEM;

drivers/scsi/scsi_transport_iscsi.c int iscsi_offload_mesg(struct Scsi_Host *shost, · line 1018

Quoted 8 lines
drivers/scsi/scsi_transport_iscsi.c +1 -1
@@ -1012,7 +1012,7 @@ int iscsi_offload_mesg(struct Scsi_Host *shost,
 
  	memcpy((char *)ev + sizeof(*ev), data, data_size);
 
-	return iscsi_multicast_skb(skb, ISCSI_NL_GRP_UIP, GFP_NOIO);
+	return iscsi_multicast_skb(skb, ISCSI_NL_GRP_UIP, GFP_ATOMIC);
  }
  EXPORT_SYMBOL_GPL(iscsi_offload_mesg);
 

Using GFP_NOIO and changing the locking is my preference normally, but if the locking changes are going to be a problem, then this is ok with me since we can fail allocations in other parts of the code.

Dave Miller probably wants to take this in his tree since it fixes a bug with this patch
http://git.kernel.org/?p=linux/kernel/git/davem/net-2.6.git;a=commit;h=6d7760a88c25057c2c2243e5dfe2d731064bd31d

maintainer
#8 lore raw

Re: [PATCH] iscsi: Use GFP_ATOMIC in iscsi_offload_mesg().

From: Mike Christie <[email protected]>
Date: Wed, 29 Jul 2009 20:40:50 -0500

Quoted 7 lines · Michael Chan
Quoted 6 lines

Changing to GFP_ATOMIC because the only caller in cnic/bnx2i may be calling this function while holding spin_lock.

This problem was discovered by Mike Christie.

...

Quoted 5 lines

Dave Miller probably wants to take this in his tree since it fixes a bug with this patch
http://git.kernel.org/?p=linux/kernel/git/davem/net-2.6.git;a=commit;h=6d7760a88c25057c2c2243e5dfe2d731064bd31d

Yep I'll take it, thanks everyone.

#9 lore raw
In reply to Michael Chan
Quoted 54 lines · Michael Chan
Quoted 6 lines · Mike Christie
Quoted 5 lines · Michael Chan

When a net device goes down or when the bnx2i driver is unloaded, the code was not generating the ISCSI_KEVENT_IF_DOWN message properly and this could cause the userspace driver to crash.

This is fixed by sending the message properly in the shutdown

path.

Quoted 8 lines
Quoted 8 lines

cnic_uio_stop() is also added to send the message when bnx2i is unregistering.

---
 drivers/net/cnic.c |   23 +++++++++++++++++++++--
 1 files changed, 21 insertions(+), 2 deletions(-)
Quoted 13 lines

drivers/net/cnic.c static int cnic_send_nlmsg(struct

Quoted 5 lines
drivers/net/cnic.c +0 -0
index 4d1515f..4869d77 100644
@@ -227,7 +227,7 @@ static int cnic_send_nlmsg(struct

cnic_local *cp, u32 type,

Quoted 7 lines
drivers/net/cnic.c +1 -1
    }
 
    rcu_read_lock();
-   ulp_ops = rcu_dereference(cp->ulp_ops[CNIC_ULP_ISCSI]);
+   ulp_ops = rcu_dereference(cnic_ulp_tbl[CNIC_ULP_ISCSI]);
    if (ulp_ops)
            ulp_ops->iscsi_nl_send_msg(cp->dev, msg_type, buf,

len);

Quoted 6 lines

drivers/net/cnic.c static int cnic_abort_prep(struct

Quoted 2 lines
drivers/net/cnic.c +0 -0
    rcu_read_unlock();
@@ -319,6 +319,20 @@ static int cnic_abort_prep(struct

cnic_sock *csk)

Quoted 3 lines
drivers/net/cnic.c +0 -0
    return 0;
 }
 
Quoted 10 lines

drivers/net/cnic.c static int cnic_abort_prep(struct cnic_sock *csk)

Quoted 10 lines
drivers/net/cnic.c +10 -0
+static void cnic_uio_stop(void)
+{
+   struct cnic_dev *dev;
+
+   read_lock(&cnic_dev_lock);
+   list_for_each_entry(dev, &cnic_dev_list, list) {
+           struct cnic_local *cp = dev->cnic_priv;
+
+           if (cp->cnic_uinfo)
+                   cnic_send_nlmsg(cp, ISCSI_KEVENT_IF_DOWN,

NULL);

Quoted 6 lines

I don't think you can call this with the cnic_dev_lock held. They have
the same sleeping restrictions as a spin_lock right? If so, the problem
is that iscsi_nl_send_ms calls iscsi_offload_mesg which uses

Quoted 7 lines

GFP_NOIO

Quoted 3 lines

and can sleep.

In that case, can I send in a patch to change iscsi_offload_mesg() to use GFP_ATOMIC?

After this change, if iscsi_transport is unable to push the message to user daemon because of memory issues, will the original issue of uio crash re-appear?

Original issue: A did not notify B
Fix : A calls C to send message to B
if C cannot deliver message to B, original problem stays???

Quoted 9 lines

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "open-iscsi" group. To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/open-iscsi
-~----------~----~----~----~------~----~------~--~---