Skip to content

Commit af8d703

Browse files
srabinovjgunthorpe
authored andcommitted
RDMA/restrack: Resource-tracker should not use uobject pointers
Having uobject pointer embedded in ib core objects is not aligned with a future shared ib_x model. The resource tracker only does this to keep track of user/kernel objects - track this directly instead. Signed-off-by: Shamir Rabinovitch <shamir.rabinovitch@oracle.com> Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
1 parent 813e90b commit af8d703

File tree

8 files changed

+46
-42
lines changed

8 files changed

+46
-42
lines changed

drivers/infiniband/core/cma.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ static void _cma_attach_to_dev(struct rdma_id_private *id_priv,
494494
id_priv->id.route.addr.dev_addr.transport =
495495
rdma_node_get_transport(cma_dev->device->node_type);
496496
list_add_tail(&id_priv->list, &cma_dev->id_list);
497-
rdma_restrack_add(&id_priv->res);
497+
rdma_restrack_kadd(&id_priv->res);
498498
}
499499

500500
static void cma_attach_to_dev(struct rdma_id_private *id_priv,

drivers/infiniband/core/core_priv.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,10 @@ static inline struct ib_qp *_ib_create_qp(struct ib_device *dev,
297297
*/
298298
if (attr->qp_type < IB_QPT_XRC_INI) {
299299
qp->res.type = RDMA_RESTRACK_QP;
300-
rdma_restrack_add(&qp->res);
300+
if (uobj)
301+
rdma_restrack_uadd(&qp->res);
302+
else
303+
rdma_restrack_kadd(&qp->res);
301304
} else
302305
qp->res.valid = false;
303306

drivers/infiniband/core/cq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ struct ib_cq *__ib_alloc_cq(struct ib_device *dev, void *private,
162162

163163
cq->res.type = RDMA_RESTRACK_CQ;
164164
rdma_restrack_set_task(&cq->res, caller);
165-
rdma_restrack_add(&cq->res);
165+
rdma_restrack_kadd(&cq->res);
166166

167167
switch (cq->poll_ctx) {
168168
case IB_POLL_DIRECT:

drivers/infiniband/core/restrack.c

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -139,27 +139,6 @@ static struct ib_device *res_to_dev(struct rdma_restrack_entry *res)
139139
}
140140
}
141141

142-
static bool res_is_user(struct rdma_restrack_entry *res)
143-
{
144-
switch (res->type) {
145-
case RDMA_RESTRACK_PD:
146-
return container_of(res, struct ib_pd, res)->uobject;
147-
case RDMA_RESTRACK_CQ:
148-
return container_of(res, struct ib_cq, res)->uobject;
149-
case RDMA_RESTRACK_QP:
150-
return container_of(res, struct ib_qp, res)->uobject;
151-
case RDMA_RESTRACK_CM_ID:
152-
return !res->kern_name;
153-
case RDMA_RESTRACK_MR:
154-
return container_of(res, struct ib_mr, res)->pd->uobject;
155-
case RDMA_RESTRACK_CTX:
156-
return true;
157-
default:
158-
WARN_ONCE(true, "Wrong resource tracking type %u\n", res->type);
159-
return false;
160-
}
161-
}
162-
163142
void rdma_restrack_set_task(struct rdma_restrack_entry *res,
164143
const char *caller)
165144
{
@@ -175,17 +154,17 @@ void rdma_restrack_set_task(struct rdma_restrack_entry *res,
175154
}
176155
EXPORT_SYMBOL(rdma_restrack_set_task);
177156

178-
void rdma_restrack_add(struct rdma_restrack_entry *res)
157+
static void rdma_restrack_add(struct rdma_restrack_entry *res)
179158
{
180159
struct ib_device *dev = res_to_dev(res);
181160

182161
if (!dev)
183162
return;
184163

185-
if (res->type != RDMA_RESTRACK_CM_ID || !res_is_user(res))
164+
if (res->type != RDMA_RESTRACK_CM_ID || rdma_is_kernel_res(res))
186165
res->task = NULL;
187166

188-
if (res_is_user(res)) {
167+
if (!rdma_is_kernel_res(res)) {
189168
if (!res->task)
190169
rdma_restrack_set_task(res, NULL);
191170
res->kern_name = NULL;
@@ -201,7 +180,28 @@ void rdma_restrack_add(struct rdma_restrack_entry *res)
201180
hash_add(dev->res.hash, &res->node, res->type);
202181
up_write(&dev->res.rwsem);
203182
}
204-
EXPORT_SYMBOL(rdma_restrack_add);
183+
184+
/**
185+
* rdma_restrack_kadd() - add kernel object to the reource tracking database
186+
* @res: resource entry
187+
*/
188+
void rdma_restrack_kadd(struct rdma_restrack_entry *res)
189+
{
190+
res->user = false;
191+
rdma_restrack_add(res);
192+
}
193+
EXPORT_SYMBOL(rdma_restrack_kadd);
194+
195+
/**
196+
* rdma_restrack_uadd() - add user object to the reource tracking database
197+
* @res: resource entry
198+
*/
199+
void rdma_restrack_uadd(struct rdma_restrack_entry *res)
200+
{
201+
res->user = true;
202+
rdma_restrack_add(res);
203+
}
204+
EXPORT_SYMBOL(rdma_restrack_uadd);
205205

206206
int __must_check rdma_restrack_get(struct rdma_restrack_entry *res)
207207
{

drivers/infiniband/core/uverbs_cmd.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ static int ib_uverbs_get_context(struct uverbs_attr_bundle *attrs)
262262
fd_install(resp.async_fd, filp);
263263

264264
ucontext->res.type = RDMA_RESTRACK_CTX;
265-
rdma_restrack_add(&ucontext->res);
265+
rdma_restrack_uadd(&ucontext->res);
266266

267267
/*
268268
* Make sure that ib_uverbs_get_ucontext() sees the pointer update
@@ -472,7 +472,7 @@ static int ib_uverbs_alloc_pd(struct uverbs_attr_bundle *attrs)
472472
memset(&resp, 0, sizeof resp);
473473
resp.pd_handle = uobj->id;
474474
pd->res.type = RDMA_RESTRACK_PD;
475-
rdma_restrack_add(&pd->res);
475+
rdma_restrack_uadd(&pd->res);
476476

477477
ret = uverbs_response(attrs, &resp, sizeof(resp));
478478
if (ret)
@@ -788,7 +788,7 @@ static int ib_uverbs_reg_mr(struct uverbs_attr_bundle *attrs)
788788
mr->uobject = uobj;
789789
atomic_inc(&pd->usecnt);
790790
mr->res.type = RDMA_RESTRACK_MR;
791-
rdma_restrack_add(&mr->res);
791+
rdma_restrack_uadd(&mr->res);
792792

793793
uobj->object = mr;
794794

@@ -1066,7 +1066,7 @@ static struct ib_ucq_object *create_cq(struct uverbs_attr_bundle *attrs,
10661066
resp.response_length = uverbs_response_length(attrs, sizeof(resp));
10671067

10681068
cq->res.type = RDMA_RESTRACK_CQ;
1069-
rdma_restrack_add(&cq->res);
1069+
rdma_restrack_uadd(&cq->res);
10701070

10711071
ret = uverbs_response(attrs, &resp, sizeof(resp));
10721072
if (ret)

drivers/infiniband/core/uverbs_std_types_cq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ static int UVERBS_HANDLER(UVERBS_METHOD_CQ_CREATE)(
126126
obj->uobject.user_handle = user_handle;
127127
atomic_set(&cq->usecnt, 0);
128128
cq->res.type = RDMA_RESTRACK_CQ;
129-
rdma_restrack_add(&cq->res);
129+
rdma_restrack_uadd(&cq->res);
130130

131131
ret = uverbs_copy_to(attrs, UVERBS_ATTR_CREATE_CQ_RESP_CQE, &cq->cqe,
132132
sizeof(cq->cqe));

drivers/infiniband/core/verbs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ struct ib_pd *__ib_alloc_pd(struct ib_device *device, unsigned int flags,
277277

278278
pd->res.type = RDMA_RESTRACK_PD;
279279
rdma_restrack_set_task(&pd->res, caller);
280-
rdma_restrack_add(&pd->res);
280+
rdma_restrack_kadd(&pd->res);
281281

282282
if (mr_access_flags) {
283283
struct ib_mr *mr;
@@ -1902,7 +1902,7 @@ struct ib_cq *__ib_create_cq(struct ib_device *device,
19021902
atomic_set(&cq->usecnt, 0);
19031903
cq->res.type = RDMA_RESTRACK_CQ;
19041904
rdma_restrack_set_task(&cq->res, caller);
1905-
rdma_restrack_add(&cq->res);
1905+
rdma_restrack_kadd(&cq->res);
19061906
}
19071907

19081908
return cq;
@@ -1984,7 +1984,7 @@ struct ib_mr *ib_alloc_mr(struct ib_pd *pd,
19841984
atomic_inc(&pd->usecnt);
19851985
mr->need_inval = false;
19861986
mr->res.type = RDMA_RESTRACK_MR;
1987-
rdma_restrack_add(&mr->res);
1987+
rdma_restrack_kadd(&mr->res);
19881988
}
19891989

19901990
return mr;

include/rdma/restrack.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ struct rdma_restrack_entry {
116116
* @type: various objects in restrack database
117117
*/
118118
enum rdma_restrack_type type;
119+
/**
120+
* @user: user resource
121+
*/
122+
bool user;
119123
};
120124

121125
/**
@@ -140,11 +144,8 @@ int rdma_restrack_count(struct rdma_restrack_root *res,
140144
enum rdma_restrack_type type,
141145
struct pid_namespace *ns);
142146

143-
/**
144-
* rdma_restrack_add() - add object to the reource tracking database
145-
* @res: resource entry
146-
*/
147-
void rdma_restrack_add(struct rdma_restrack_entry *res);
147+
void rdma_restrack_kadd(struct rdma_restrack_entry *res);
148+
void rdma_restrack_uadd(struct rdma_restrack_entry *res);
148149

149150
/**
150151
* rdma_restrack_del() - delete object from the reource tracking database
@@ -159,7 +160,7 @@ void rdma_restrack_del(struct rdma_restrack_entry *res);
159160
*/
160161
static inline bool rdma_is_kernel_res(struct rdma_restrack_entry *res)
161162
{
162-
return !res->task;
163+
return !res->user;
163164
}
164165

165166
/**

0 commit comments

Comments
 (0)