Skip to contentSkip to conversation

iw_cm: Call provider listen_destroy function before changing state.

PATCH In review Steve Wise 3 participants 7 messages Feb 22, 2012 5 messages not in the archive InfiniBand

lore
Share & tools
lore

Steve Wise

author
#0 lore raw

PATCH 1/1 iw_cm: Call provider listen_destroy function before changing state.

When destroying a listening cmid, the iwcm first sets the cmid state to DESTROYING, then releases the lock and calls into the iwarp provider to destroy the listening endpoint. Since the cmid is not locked, its possible for the iwarp provider to pass a connection request event to the iwcm before the provider has destroyed the listening endpoint. This connect request will be silently dropped by the iwcm because the state of the cmid is DESTROYING. The iwarp provider, however, doesn't know the connect request was dropped. This causes the iwarp provider to never free up the resources from this connection because the assumption is the iwcm will _always_ either accept or reject this connection. The solution is to only change the cmid state after the iwarp provider has destroyed its listening endpoint, and thus no more connection requests will be posted.

---

 drivers/infiniband/core/iwcm.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/infiniband/core/iwcm.c +1 -1
index 1a696f7..3b43bba 100644
@@ -340,11 +340,11 @@ static void destroy_cm_id(struct iw_cm_id *cm_id)
 	spin_lock_irqsave(&cm_id_priv->lock, flags);
 	switch (cm_id_priv->state) {
 	case IW_CM_STATE_LISTEN:
-		cm_id_priv->state = IW_CM_STATE_DESTROYING;
 		spin_unlock_irqrestore(&cm_id_priv->lock, flags);
 		/* destroy the listening endpoint */
 		ret = cm_id->device->iwcm->destroy_listen(cm_id);
 		spin_lock_irqsave(&cm_id_priv->lock, flags);
+		cm_id_priv->state = IW_CM_STATE_DESTROYING;
 		break;
 	case IW_CM_STATE_ESTABLISHED:
 		cm_id_priv->state = IW_CM_STATE_DESTROYING;

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 20120222194337.21025.30754.stgit-T4OLL4TyM9aNDNWfRnPdfg@public.gmane.org

#2 lore raw

PiBkaWZmIC0tZ2l0IGEvZHJpdmVycy9pbmZpbmliYW5kL2NvcmUvaXdjbS5jIGIvZHJpdmVycy9p bmZpbmliYW5kL2NvcmUvaXdjbS5jDQo+IGluZGV4IDFhNjk2ZjcuLjNiNDNiYmEgMTAwNjQ0DQo+ IC0tLSBhL2RyaXZlcnMvaW5maW5pYmFuZC9jb3JlL2l3Y20uYw0KPiArKysgYi9kcml2ZXJzL2lu ZmluaWJhbmQvY29yZS9pd2NtLmMNCj4gQEAgLTM0MCwxMSArMzQwLDExIEBAIHN0YXRpYyB2b2lk IGRlc3Ryb3lfY21faWQoc3RydWN0IGl3X2NtX2lkICpjbV9pZCkNCj4gIAlzcGluX2xvY2tfaXJx c2F2ZSgmY21faWRfcHJpdi0+bG9jaywgZmxhZ3MpOw0KPiAgCXN3aXRjaCAoY21faWRfcHJpdi0+ c3RhdGUpIHsNCj4gIAljYXNlIElXX0NNX1NUQVRFX0xJU1RFTjoNCj4gLQkJY21faWRfcHJpdi0+ c3RhdGUgPSBJV19DTV9TVEFURV9ERVNUUk9ZSU5HOw0KPiAgCQlzcGluX3VubG9ja19pcnFyZXN0 b3JlKCZjbV9pZF9wcml2LT5sb2NrLCBmbGFncyk7DQoNCldoYXQgZG9lcyB0aGlzIHNwaW5sb2Nr IHByb3RlY3QgYWdhaW5zdCBpZiBhbGwgd2UgZG8gaXMgcmVhZCB0aGUgc3RhdGUgdW5kZXIgaXQ/ DQoNCg==
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

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

author
#4 lore raw
Quoted 12 lines · Sean

drivers/infiniband/core/iwcm.c static void destroy_cm_id(struct iw_cm_id *cm_id) · line 343

Quoted 10 lines
drivers/infiniband/core/iwcm.c +0 -1
index 1a696f7..3b43bba 100644
@@ -340,11 +340,11 @@ static void destroy_cm_id(struct iw_cm_id *cm_id)
  	spin_lock_irqsave(&cm_id_priv->lock, flags);
  	switch (cm_id_priv->state) {
  	case IW_CM_STATE_LISTEN:
-		cm_id_priv->state = IW_CM_STATE_DESTROYING;
  		spin_unlock_irqrestore(&cm_id_priv->lock, flags);

What does this spinlock protect against if all we do is read the state under it?

Probably nothing in this particular path. It seems to serialize adding/removing references to the qp and manipulating cm_id_priv->qp. But I don't want to revisit the entire serialization of this module. :)

But the point of the patch is to destroy the listening endpoint in the provider _before_ we stop accepting connect requests.

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 4F4549E9.3090102-7bPotxP6k4+P2YhJcF5u+vpXobYPEAuW@public.gmane.org

author
#6 lore raw
Quoted 14 lines · Steve Wise
Quoted 12 lines · Sean

drivers/infiniband/core/iwcm.c static void destroy_cm_id(struct iw_cm_id *cm_id) · line 343

Quoted 10 lines
drivers/infiniband/core/iwcm.c +0 -1
index 1a696f7..3b43bba 100644
@@ -340,11 +340,11 @@ static void destroy_cm_id(struct iw_cm_id *cm_id)
      spin_lock_irqsave(&cm_id_priv->lock, flags);
      switch (cm_id_priv->state) {
      case IW_CM_STATE_LISTEN:
-        cm_id_priv->state = IW_CM_STATE_DESTROYING;
          spin_unlock_irqrestore(&cm_id_priv->lock, flags);

What does this spinlock protect against if all we do is read the state under it?

Quoted 4 lines

Probably nothing in this particular path. It seems to serialize adding/removing references to the qp and manipulating cm_id_priv->qp. But I don't want to revisit the entire serialization of this module. :)

But the point of the patch is to destroy the listening endpoint in the provider _before_ we stop accepting connect requests.

Oh you were pointing out that I could rearrange the spin lock usage here since we no longer set the state in this one case? --
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#7 lore raw
In reply to a message not in the archive
Quoted 4 lines · Steve Wise

     spin_lock_irqsave(&cm_id_priv->lock, flags); switch (cm_id_priv->state) {
       case IW_CM_STATE_LISTEN:
-               cm_id_priv->state = IW_CM_STATE_DESTROYING;

Quoted 8 lines

               spin_unlock_irqrestore(&cm_id_priv->lock, flags); /* destroy the listening endpoint */ ret = cm_id->device->iwcm->destroy_listen(cm_id); spin_lock_irqsave(&cm_id_priv->lock, flags);
+               cm_id_priv->state = IW_CM_STATE_DESTROYING; break;
       case IW_CM_STATE_ESTABLISHED:
               cm_id_priv->state = IW_CM_STATE_DESTROYING;

This seems a bit wonky to me... with the old code, we set the state to DESTROYING inside the lock, so we know all previous connections were either done with their locked region or saw the new state.

Now we have a window where are done with destroy_listen() but the state is still not DESTROYING.

Is it possible to have the provider reject requests instead of silently dropping them? Would that be a better fix?

- R.
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): CAG4TOxMXTzLDynza4KOaccx2C+Nn0485Xk_hXgg_bG0CiCTSEQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

author
#9 lore raw
Quoted 18 lines · Roland Dreier

drivers/infiniband/core/iwcm.c static void destroy_cm_id(struct iw_cm_id *cm_id) · line 350

Quoted 12 lines · Steve Wise
      spin_lock_irqsave(&cm_id_priv->lock, flags);
        switch (cm_id_priv->state) {
        case IW_CM_STATE_LISTEN:
drivers/infiniband/core/iwcm.c +1 -1
-               cm_id_priv->state = IW_CM_STATE_DESTROYING;
                spin_unlock_irqrestore(&cm_id_priv->lock, flags);
                /* destroy the listening endpoint */
                ret = cm_id->device->iwcm->destroy_listen(cm_id);
                spin_lock_irqsave(&cm_id_priv->lock, flags);
+               cm_id_priv->state = IW_CM_STATE_DESTROYING;
                break;
        case IW_CM_STATE_ESTABLISHED:
                cm_id_priv->state = IW_CM_STATE_DESTROYING;

This seems a bit wonky to me... with the old code, we set the state to DESTROYING inside the lock, so we know all previous connections were either done with their locked region or saw the new state.

Quoted 6 lines

Now we have a window where are done with destroy_listen() but the state is still not DESTROYING.

Is it possible to have the provider reject requests instead of silently dropping them? Would that be a better fix?

Perhaps. Or the connect request event handler could return a status indicating whether or not it queued the request and will subsequently accept or reject it.

Quoted 1 line

- R.

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 4F45536A.3050501-7bPotxP6k4+P2YhJcF5u+vpXobYPEAuW@public.gmane.org

author
#11 lore raw
Quoted 19 lines · Steve Wise
Quoted 18 lines · Roland Dreier

drivers/infiniband/core/iwcm.c static void destroy_cm_id(struct iw_cm_id *cm_id) · line 350

Quoted 12 lines · Steve Wise
      spin_lock_irqsave(&cm_id_priv->lock, flags);
        switch (cm_id_priv->state) {
        case IW_CM_STATE_LISTEN:
drivers/infiniband/core/iwcm.c +1 -1
-               cm_id_priv->state = IW_CM_STATE_DESTROYING;
                spin_unlock_irqrestore(&cm_id_priv->lock, flags);
                /* destroy the listening endpoint */
                ret = cm_id->device->iwcm->destroy_listen(cm_id);
                spin_lock_irqsave(&cm_id_priv->lock, flags);
+               cm_id_priv->state = IW_CM_STATE_DESTROYING;
                break;
        case IW_CM_STATE_ESTABLISHED:
                cm_id_priv->state = IW_CM_STATE_DESTROYING;

This seems a bit wonky to me... with the old code, we set the state to DESTROYING inside the lock, so we know all previous connections were either done with their locked region or saw the new state.

Quoted 8 lines
Quoted 6 lines

Now we have a window where are done with destroy_listen() but the state is still not DESTROYING.

Is it possible to have the provider reject requests instead of silently dropping them? Would that be a better fix?

Perhaps. Or the connect request event handler could return a status indicating whether or not it queued the request and will subsequently accept or reject it.

Actually, the events are deferred and scheduled so my idea doesn't hold water.

I'll code up and test your reject idea.

Thanks,

Steve.

Quoted 2 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html