core/verb.c: fix kernel panic: always initialize struct ib_qp *qp->usecnt
PATCH 1/1 core/verb.c: fix kernel panic: always initialize struct ib_qp *qp->usecnt
We have just been investigating kernel panics related to cq->ibcq.event_handler() completion calls.
Reason is that ib_destroy_qp() fails with -EBUSY. Further investigation revealed qp->usecnt is not initialized. This counter was introduced in linux-3.2 by commit 0e0ec7e0638ef48e0c661873dfcc8caccab984c6 and is only initialized for IB_QPT_XRC_TGT, but also checked in ib_destroy_qp() for any qp type.
--- drivers/infiniband/core/verbs.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/infiniband/core/verbs.c +1 -1
@@ -421,6 +421,7 @@ struct ib_qp *ib_create_qp(struct ib_pd *pd, qp->uobject =NULL ; qp->qp_type = qp_init_attr->qp_type; +atomic_set (&qp->usecnt,0 );if (qp_init_attr->qp_type ==IB_QPT_XRC_TGT ) { qp->event_handler = __ib_shared_qp_event_handler; qp->qp_context = qp;
@@ -430,7 +431,6 @@ struct ib_qp *ib_create_qp(struct ib_pd *pd, qp->xrcd = qp_init_attr->xrcd;atomic_inc (&qp_init_attr->xrcd->usecnt);INIT_LIST_HEAD (&qp->open_list); -atomic_set (&qp->usecnt,0 ); real_qp = qp; qp = __ib_open_qp(real_qp, qp_init_attr->event_handler,
--
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): 20120119194641.1391553.39048.stgit-bi+AKbBUZKY6gyzm1THtWbp2dZbC/[email protected]
PiBXZSBoYXZlIGp1c3QgYmVlbiBpbnZlc3RpZ2F0aW5nIGtlcm5lbCBwYW5pY3MgcmVsYXRlZCB0 bw0KPiBjcS0+aWJjcS5ldmVudF9oYW5kbGVyKCkgY29tcGxldGlvbiBjYWxscy4NCj4gDQo+IFJl YXNvbiBpcyB0aGF0IGliX2Rlc3Ryb3lfcXAoKSBmYWlscyB3aXRoIC1FQlVTWS4gRnVydGhlciBp bnZ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ZHJpdmVycy9p bmZpbmliYW5kL2NvcmUvdmVyYnMuYw0KPiArKysgYi9kcml2ZXJzL2luZmluaWJhbmQvY29yZS92 ZXJicy5jDQo+IEBAIC00MjEsNiArNDIxLDcgQEAgc3RydWN0IGliX3FwICppYl9jcmVhdGVfcXAo c3RydWN0IGliX3BkICpwZCwNCj4gIAkJcXAtPnVvYmplY3QgICAgPSBOVUxMOw0KPiAgCQlxcC0+ cXBfdHlwZSAgICA9IHFwX2luaXRfYXR0ci0+cXBfdHlwZTsNCj4gDQo+ICsJCWF0b21pY19zZXQo JnFwLT51c2VjbnQsIDApOw0KPiAgCQlpZiAocXBfaW5pdF9hdHRyLT5xcF90eXBlID09IElCX1FQ VF9YUkNfVEdUKSB7DQo+ICAJCQlxcC0+ZXZlbnRfaGFuZGxlciA9IF9faWJfc2hhcmVkX3FwX2V2 ZW50X2hhbmRsZXI7DQo+ICAJCQlxcC0+cXBfY29udGV4dCA9IHFwOw0KPiBAQCAtNDMwLDcgKzQz MSw2IEBAIHN0cnVjdCBpYl9xcCAqaWJfY3JlYXRlX3FwKHN0cnVjdCBpYl9wZCAqcGQsDQo+ICAJ CQlxcC0+eHJjZCA9IHFwX2luaXRfYXR0ci0+eHJjZDsNCj4gIAkJCWF0b21pY19pbmMoJnFwX2lu aXRfYXR0ci0+eHJjZC0+dXNlY250KTsNCj4gIAkJCUlOSVRfTElTVF9IRUFEKCZxcC0+b3Blbl9s aXN0KTsNCj4gLQkJCWF0b21pY19zZXQoJnFwLT51c2VjbnQsIDApOw0KPiANCj4gIAkJCXJlYWxf cXAgPSBxcDsNCj4gIAkJCXFwID0gX19pYl9vcGVuX3FwKHJlYWxfcXAsIHFwX2luaXRfYXR0ci0+ ZXZlbnRfaGFuZGxlciwNCg0K
--
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): 1828884A29C6694DAF28B7E6B8A823732DC0C33E-P5GAC/[email protected]
Hmm, I think we do have serious problem with the hole approach. While the patch works for the kernel side, there is a problem with user space libraries. So I monitored our daemons and noticed ibv_destroy_cq() failed. The reason again seems to be the same issue as already fixed for kernel qp's. So in __ibv_create_qp() (libibverbs/src/verbs.c):
Quoted 9 lines
__ibv_create_qp()struct ibv_qp *qp = pd->context->ops.create_qp(pd, qp_init_attr); if (qp) { qp->context = pd->context; qp->qp_context = qp_init_attr->qp_context; qp->pd = pd; qp->send_cq = qp_init_attr->send_cq;
[...]
I *guess* the qp allocated by pd->context->ops.create_qp() does not have qp->usecnt initialized (not does it know anything about it). So its random value will fail the destruction later. A simple workaround that would work for us, is to extend the patch I send to
drivers/infiniband/core/verbs.c +1 -1
@@ -874,7 +874,7 @@ int ib_destroy_qp(struct ib_qp *qp)struct ib_srq *srq;int ret; -if (atomic_read (&qp->usecnt)) +if (qp->qp_type ==IB_QPT_XRC_TGT &&atomic_read (&qp->usecnt))return -EBUSY ;if (qp->real_qp != qp)
However, what is is with user space setting type to IB_QPT_XRC_TGT? I guess this could be solved by letting the kernel zero the memory returned by ->ops.create_qp(pd, qp_init_attr). Btw, I didn't figure out yet, how this translates at all in kernel space? Is this op directly going to the device driver?
But even if we are properly going to initialize the qp, what is with user space mischievously trying to crash the system by manipulating struct ib_qp *qp?
Thanks,
Bernd
--
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): 4F1992F6.9070103-mPn0NPGs4xGatNDF+KUbs4QuADTiUCJX@public.gmane.org
Quoted 11 lines · Bernd Schubert
I *guess* the qp allocated by
pd->context->ops.create_qp()does not haveqp->usecntinitialized (not does it know anything about it). So its random value will fail the destruction later. A simple workaround that would work for us, is to extend the patch I send todrivers/infiniband/core/verbs.c +0
-0
drivers/infiniband/core/verbs.c int ib_destroy_qp(struct ib_qp *qp) · line 880
Quoted 8 lines
drivers/infiniband/core/verbs.c +1
-1@@ -874,7 +874,7 @@ int ib_destroy_qp(struct ib_qp *qp) struct ib_srq *srq; int ret; - if (atomic_read(&qp->usecnt)) + if (qp->qp_type == IB_QPT_XRC_TGT && atomic_read(&qp->usecnt)) return -EBUSY; if (qp->real_qp != qp)
It looks like this is sufficient and correct without the other patch?
Quoted 11 lines
However, what is is with user space setting type to
IB_QPT_XRC_TGT? I guess this could be solved by letting the kernel zero the memory returned by ->ops.create_qp(pd,qp_init_attr).
Btw, I didn't figure out yet, how this translates at all in kernel space? Is this op directly going to the device driver?But even if we are properly going to initialize the qp, what is with user space mischievously trying to crash the system by manipulating struct
ib_qp*qp?
I don't follow this. Isn't *qp completely allocated and manipulated in the kernel? How can userspace touch it except by having the kernel do something via the uverbs interface?
- 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): CAL1RGDWSh3HpVY5dui549EoqhzTYaSnsCPGdEU+hPZ9NWx6ttw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Quoted 16 lines · Roland Dreier
Quoted 14 lines · Bernd Schubert
I *guess* the qp allocated by
pd->context->ops.create_qp()does not haveqp->usecntinitialized (not does it know anything about it). So its random value will fail the destruction later. A simple workaround that would work for us, is to extend the patch I send todrivers/infiniband/core/verbs.c +0
-0@@ -874,7 +874,7 @@ int ib_destroy_qp(struct ib_qp *qp) struct ib_srq *srq; int ret;
Quoted 7 lines
drivers/infiniband/core/verbs.c int ib_destroy_qp(struct ib_qp *qp) · line 880
Quoted 5 lines
drivers/infiniband/core/verbs.c +1
-1- if (atomic_read(&qp->usecnt)) + if (qp->qp_type == IB_QPT_XRC_TGT && atomic_read(&qp->usecnt)) return -EBUSY; if (qp->real_qp != qp)It looks like this is sufficient and correct without the other patch?
But maybe it's cleaner to initialize qp->usecnt in both ib_create_qp() and ib_uverbs_create_qp().
- 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): CAL1RGDW=XfCd3aCmB0mE1WcOUeDj=17=s2K0A3zpFmBF6Rg_Rg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Hi,
Roland Dreier wrote on 01/20/2012 07:43 PM:
Quoted 21 lines · Roland Dreier
Quoted 20 lines
Quoted 18 lines · Bernd Schubert
I *guess* the qp allocated by
pd->context->ops.create_qp()does not haveqp->usecntinitialized (not does it know anything about it). So its random value will fail the destruction later. A simple workaround that would work for us, is to extend the patch I send todrivers/infiniband/core/verbs.c +1
-1@@ -874,7 +874,7 @@ int ib_destroy_qp(struct ib_qp *qp)struct ib_srq *srq;int ret; -if (atomic_read (&qp->usecnt)) +if (qp->qp_type ==IB_QPT_XRC_TGT &&atomic_read (&qp->usecnt))return -EBUSY ;
Quoted 8 lines
Quoted 3 lines
drivers/infiniband/core/verbs.c int ib_destroy_qp(struct ib_qp *qp) · line 880
Quoted 1 line
drivers/infiniband/core/verbs.c +0
-0if (qp->real_qp != qp)It looks like this is sufficient and correct without the other patch?
But maybe it's cleaner to initialize
qp->usecntin bothib_create_qp()andib_uverbs_create_qp().- R.
is there any progress on this? We have already reached Linux stable 3.2.2 and IB still appears to be broken (at least for mthca) because of this.
Best regards,
Sven
--
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): 4F22CF82.2060606-mPn0NPGs4xGatNDF+KUbs4QuADTiUCJX@public.gmane.org
Roland Dreier
AppliedQuoted 2 lines · Sven Breuner
is there any progress on this? We have already reached Linux stable 3.2.2 and IB still appears to be broken (at least for mthca) because of this.
I've applied it and will send it to Linus soon.
- 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): CAL1RGDXXYG48d2P0h4G+z4W8HebjrQ7HTWyx5FqgB0_2OqC4Ng-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Hi Roland,
Roland Dreier wrote on 01/27/2012 06:20 PM:
Quoted 1 line
I've applied it and will send it to Linus soon.
thanks! Will you also take care of the Linux-stable (3.2.x) backport or should I send it for inclusion in Linux-stable?
Best regards,
Sven
--
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): 4F22F1C9.3090801-mPn0NPGs4xGatNDF+KUbs4QuADTiUCJX@public.gmane.org
Quoted 2 lines · Sven Breuner
thanks! Will you also take care of the Linux-stable (3.2.x) backport or should I send it for inclusion in Linux-stable?
I added the CC to stable in the commit so it should happen automatically. --
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
Quoted 32 lines · Roland Dreier
Quoted 11 lines · Bernd Schubert
I *guess* the qp allocated by
pd->context->ops.create_qp()does not haveqp->usecntinitialized (not does it know anything about it). So its random value will fail the destruction later. A simple workaround that would work for us, is to extend the patch I send todrivers/infiniband/core/verbs.c +0
-0drivers/infiniband/core/verbs.c int ib_destroy_qp(struct ib_qp *qp) · line 880
Quoted 8 lines
drivers/infiniband/core/verbs.c +1
-1@@ -874,7 +874,7 @@ int ib_destroy_qp(struct ib_qp *qp)struct ib_srq *srq;int ret; -if (atomic_read (&qp->usecnt)) +if (qp->qp_type ==IB_QPT_XRC_TGT &&atomic_read (&qp->usecnt))return -EBUSY ;if (qp->real_qp != qp)It looks like this is sufficient and correct without the other patch?
Quoted 8 lines
However, what is is with user space setting type to
IB_QPT_XRC_TGT? I guess this could be solved by letting the kernel zero the memory returned by ->ops.create_qp(pd,qp_init_attr).
Btw, I didn't figure out yet, how this translates at all in kernel space? Is this op directly going to the device driver?
Quoted 7 lines
Quoted 3 lines
But even if we are properly going to initialize the qp, what is with user space mischievously trying to crash the system by manipulating struct
ib_qp*qp?I don't follow this. Isn't *qp completely allocated and manipulated in the kernel? How can userspace touch it except by having the kernel do something via the uverbs interface?
Sorry, I first didn't see the ib_uverbs_create_qp() interface and copy_from/to_user() there.
Cheers,
Bernd
--
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
Quoted 9 lines · Bernd Schubert
We have just been investigating kernel panics related to
cq->ibcq.event_handler()completion calls.Reason is that
ib_destroy_qp()fails with-EBUSY. Further investigation revealedqp->usecntis not initialized. This counter was introduced in linux-3.2 by commit0e0ec7e0638ef48e0c661873dfcc8caccab984c6and is only initialized forIB_QPT_XRC_TGT, but also checked inib_destroy_qp()for any qp type.
Quoted 5 lines
Signed-off-by Bernd Schubert <[email protected]>Signed-off-by Sven Breuner <[email protected]>--- drivers/infiniband/core/verbs.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
<formletter>
This is not the correct way to submit patches for inclusion in the stable kernel tree. Please read Documentation/stable_kernel_rules.txt for how to do this properly.
</formletter>
--
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