From 536d8ddbc7cb8710fb6a8d6e20632611ca915fa0 Mon Sep 17 00:00:00 2001 From: Roland Dreier Date: Wed, 31 Jan 2007 10:38:50 -0800 Subject: [PATCH] Fix unset context breakage when a low-level driver does kernel bypass Commit 8b3d2254 ("The ibv_cmd_* create functions need to set context") breaks things when a low-level driver does not actually use an ibv_cmd_* function to create an object, since then the context member of that object never gets set. For example, libmthca does not nee to call into the kernel to create an AH, and hence ibv_destroy_ah() will crash because it tries to call a function pointer from the AH's context member, which never gets set. Fix this by adding back all the setting of context to the main verbs functions like ibv_create_ah() (but still leave the setting in the ibv_cmd_* create functions too). This means context gets set twice, but that doesn't really hurt anything. Once we branch off libibverbs 1.1 as stable, we can change the signatures of the ibv_cmd_* destroy functions to take an explicit context parameter, and get rid of setting context in the ibv_cmd_* create functions. Signed-off-by: Roland Dreier --- src/verbs.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/verbs.c b/src/verbs.c index 87b1c85..56513e4 100644 --- a/src/verbs.c +++ b/src/verbs.c @@ -138,7 +138,13 @@ default_symver(__ibv_query_pkey, ibv_query_pkey); struct ibv_pd *__ibv_alloc_pd(struct ibv_context *context) { - return context->ops.alloc_pd(context); + struct ibv_pd *pd; + + pd = context->ops.alloc_pd(context); + if (pd) + pd->context = context; + + return pd; } default_symver(__ibv_alloc_pd, ibv_alloc_pd); @@ -158,6 +164,7 @@ struct ibv_mr *__ibv_reg_mr(struct ibv_pd *pd, void *addr, mr = pd->context->ops.reg_mr(pd, addr, length, access); if (mr) { + mr->context = pd->context; mr->pd = pd; mr->addr = addr; mr->length = length; @@ -249,6 +256,7 @@ struct ibv_cq *__ibv_create_cq(struct ibv_context *context, int cqe, void *cq_co comp_vector); if (cq) { + cq->context = context; cq->cq_context = cq_context; cq->comp_events_completed = 0; cq->async_events_completed = 0; @@ -312,6 +320,7 @@ struct ibv_srq *__ibv_create_srq(struct ibv_pd *pd, srq = pd->context->ops.create_srq(pd, srq_init_attr); if (srq) { + srq->context = pd->context; srq->srq_context = srq_init_attr->srq_context; srq->pd = pd; srq->events_completed = 0; @@ -349,6 +358,7 @@ struct ibv_qp *__ibv_create_qp(struct ibv_pd *pd, 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; @@ -407,8 +417,10 @@ struct ibv_ah *__ibv_create_ah(struct ibv_pd *pd, struct ibv_ah_attr *attr) { struct ibv_ah *ah = pd->context->ops.create_ah(pd, attr); - if (ah) + if (ah) { + ah->context = pd->context; ah->pd = pd; + } return ah; } -- 2.46.0