Skip to content

Commit c34a23c

Browse files
Leon Romanovskyjgunthorpe
authored andcommitted
RDMA/restrack: Simplify restrack tracking in kernel flows
Have a single rdma_restrack_add() that adds an entry, there is no reason to split the user/kernel here, the rdma_restrack_set_task() is responsible for this difference. This patch prepares the code to the future requirement of making restrack is mandatory for managing ib objects. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Leon Romanovsky <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 13ef553 commit c34a23c

File tree

8 files changed

+22
-51
lines changed

8 files changed

+22
-51
lines changed

drivers/infiniband/core/cma.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ static void _cma_attach_to_dev(struct rdma_id_private *id_priv,
454454
rdma_node_get_transport(cma_dev->device->node_type);
455455
list_add_tail(&id_priv->list, &cma_dev->id_list);
456456
if (id_priv->res.kern_name)
457-
rdma_restrack_kadd(&id_priv->res);
457+
rdma_restrack_add(&id_priv->res);
458458
else
459459
rdma_restrack_uadd(&id_priv->res);
460460
trace_cm_id_attach(id_priv, cma_dev->device);

drivers/infiniband/core/core_priv.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,10 @@ static inline struct ib_qp *_ib_create_qp(struct ib_device *dev,
363363
if ((qp_type < IB_QPT_MAX && !is_xrc) || qp_type == IB_QPT_DRIVER) {
364364
if (uobj)
365365
rdma_restrack_uadd(&qp->res);
366-
else
367-
rdma_restrack_kadd(&qp->res);
366+
else {
367+
rdma_restrack_set_task(&qp->res, pd->res.kern_name);
368+
rdma_restrack_add(&qp->res);
369+
}
368370
} else
369371
qp->res.valid = false;
370372

drivers/infiniband/core/counters.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ static void rdma_counter_res_add(struct rdma_counter *counter,
252252
{
253253
if (rdma_is_kernel_res(&qp->res)) {
254254
rdma_restrack_set_task(&counter->res, qp->res.kern_name);
255-
rdma_restrack_kadd(&counter->res);
255+
rdma_restrack_add(&counter->res);
256256
} else {
257257
rdma_restrack_attach_task(&counter->res, qp->res.task);
258258
rdma_restrack_uadd(&counter->res);

drivers/infiniband/core/cq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ struct ib_cq *__ib_alloc_cq(struct ib_device *dev, void *private, int nr_cqe,
267267
goto out_destroy_cq;
268268
}
269269

270-
rdma_restrack_kadd(&cq->res);
270+
rdma_restrack_add(&cq->res);
271271
trace_cq_alloc(cq, nr_cqe, comp_vector, poll_ctx);
272272
return cq;
273273

drivers/infiniband/core/restrack.c

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -123,32 +123,6 @@ int rdma_restrack_count(struct ib_device *dev, enum rdma_restrack_type type)
123123
}
124124
EXPORT_SYMBOL(rdma_restrack_count);
125125

126-
static void set_kern_name(struct rdma_restrack_entry *res)
127-
{
128-
struct ib_pd *pd;
129-
130-
switch (res->type) {
131-
case RDMA_RESTRACK_QP:
132-
pd = container_of(res, struct ib_qp, res)->pd;
133-
if (!pd) {
134-
WARN_ONCE(true, "XRC QPs are not supported\n");
135-
/* Survive, despite the programmer's error */
136-
res->kern_name = " ";
137-
}
138-
break;
139-
case RDMA_RESTRACK_MR:
140-
pd = container_of(res, struct ib_mr, res)->pd;
141-
break;
142-
default:
143-
/* Other types set kern_name directly */
144-
pd = NULL;
145-
break;
146-
}
147-
148-
if (pd)
149-
res->kern_name = pd->res.kern_name;
150-
}
151-
152126
static struct ib_device *res_to_dev(struct rdma_restrack_entry *res)
153127
{
154128
switch (res->type) {
@@ -217,7 +191,11 @@ void rdma_restrack_new(struct rdma_restrack_entry *res,
217191
}
218192
EXPORT_SYMBOL(rdma_restrack_new);
219193

220-
static void rdma_restrack_add(struct rdma_restrack_entry *res)
194+
/**
195+
* rdma_restrack_add() - add object to the reource tracking database
196+
* @res: resource entry
197+
*/
198+
void rdma_restrack_add(struct rdma_restrack_entry *res)
221199
{
222200
struct ib_device *dev = res_to_dev(res);
223201
struct rdma_restrack_root *rt;
@@ -249,19 +227,7 @@ static void rdma_restrack_add(struct rdma_restrack_entry *res)
249227
if (!ret)
250228
res->valid = true;
251229
}
252-
253-
/**
254-
* rdma_restrack_kadd() - add kernel object to the reource tracking database
255-
* @res: resource entry
256-
*/
257-
void rdma_restrack_kadd(struct rdma_restrack_entry *res)
258-
{
259-
res->task = NULL;
260-
set_kern_name(res);
261-
res->user = false;
262-
rdma_restrack_add(res);
263-
}
264-
EXPORT_SYMBOL(rdma_restrack_kadd);
230+
EXPORT_SYMBOL(rdma_restrack_add);
265231

266232
/**
267233
* rdma_restrack_uadd() - add user object to the reource tracking database

drivers/infiniband/core/restrack.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ struct rdma_restrack_root {
2525

2626
int rdma_restrack_init(struct ib_device *dev);
2727
void rdma_restrack_clean(struct ib_device *dev);
28+
void rdma_restrack_add(struct rdma_restrack_entry *res);
2829
void rdma_restrack_del(struct rdma_restrack_entry *res);
2930
void rdma_restrack_new(struct rdma_restrack_entry *res,
3031
enum rdma_restrack_type type);

drivers/infiniband/core/verbs.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ struct ib_pd *__ib_alloc_pd(struct ib_device *device, unsigned int flags,
281281
kfree(pd);
282282
return ERR_PTR(ret);
283283
}
284-
rdma_restrack_kadd(&pd->res);
284+
rdma_restrack_add(&pd->res);
285285

286286
if (device->attrs.device_cap_flags & IB_DEVICE_LOCAL_DMA_LKEY)
287287
pd->local_dma_lkey = device->local_dma_lkey;
@@ -2008,7 +2008,7 @@ struct ib_cq *__ib_create_cq(struct ib_device *device,
20082008
return ERR_PTR(ret);
20092009
}
20102010

2011-
rdma_restrack_kadd(&cq->res);
2011+
rdma_restrack_add(&cq->res);
20122012
return cq;
20132013
}
20142014
EXPORT_SYMBOL(__ib_create_cq);
@@ -2081,7 +2081,8 @@ struct ib_mr *ib_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
20812081
atomic_inc(&pd->usecnt);
20822082

20832083
rdma_restrack_new(&mr->res, RDMA_RESTRACK_MR);
2084-
rdma_restrack_kadd(&mr->res);
2084+
rdma_restrack_set_task(&mr->res, pd->res.kern_name);
2085+
rdma_restrack_add(&mr->res);
20852086

20862087
return mr;
20872088
}
@@ -2164,7 +2165,8 @@ struct ib_mr *ib_alloc_mr(struct ib_pd *pd, enum ib_mr_type mr_type,
21642165
mr->sig_attrs = NULL;
21652166

21662167
rdma_restrack_new(&mr->res, RDMA_RESTRACK_MR);
2167-
rdma_restrack_kadd(&mr->res);
2168+
rdma_restrack_set_task(&mr->res, pd->res.kern_name);
2169+
rdma_restrack_add(&mr->res);
21682170
out:
21692171
trace_mr_alloc(pd, mr_type, max_num_sg, mr);
21702172
return mr;
@@ -2224,7 +2226,8 @@ struct ib_mr *ib_alloc_mr_integrity(struct ib_pd *pd,
22242226
mr->sig_attrs = sig_attrs;
22252227

22262228
rdma_restrack_new(&mr->res, RDMA_RESTRACK_MR);
2227-
rdma_restrack_kadd(&mr->res);
2229+
rdma_restrack_set_task(&mr->res, pd->res.kern_name);
2230+
rdma_restrack_add(&mr->res);
22282231
out:
22292232
trace_mr_integ_alloc(pd, max_num_data_sg, max_num_meta_sg, mr);
22302233
return mr;

include/rdma/restrack.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ struct rdma_restrack_entry {
107107
int rdma_restrack_count(struct ib_device *dev,
108108
enum rdma_restrack_type type);
109109

110-
void rdma_restrack_kadd(struct rdma_restrack_entry *res);
111110
void rdma_restrack_uadd(struct rdma_restrack_entry *res);
112111

113112
/**

0 commit comments

Comments
 (0)