Lines Matching refs:res
28 dev->res = kcalloc(RDMA_RESTRACK_MAX, sizeof(*rt), GFP_KERNEL); in rdma_restrack_init()
29 if (!dev->res) in rdma_restrack_init()
32 rt = dev->res; in rdma_restrack_init()
61 struct rdma_restrack_root *rt = dev->res; in rdma_restrack_clean()
69 struct xarray *xa = &dev->res[i].xa; in rdma_restrack_clean()
113 struct rdma_restrack_root *rt = &dev->res[type]; in rdma_restrack_count()
129 static void set_kern_name(struct rdma_restrack_entry *res) in set_kern_name() argument
133 switch (res->type) { in set_kern_name()
135 pd = container_of(res, struct ib_qp, res)->pd; in set_kern_name()
139 res->kern_name = " "; in set_kern_name()
143 pd = container_of(res, struct ib_mr, res)->pd; in set_kern_name()
152 res->kern_name = pd->res.kern_name; in set_kern_name()
155 static struct ib_device *res_to_dev(struct rdma_restrack_entry *res) in res_to_dev() argument
157 switch (res->type) { in res_to_dev()
159 return container_of(res, struct ib_pd, res)->device; in res_to_dev()
161 return container_of(res, struct ib_cq, res)->device; in res_to_dev()
163 return container_of(res, struct ib_qp, res)->device; in res_to_dev()
165 return container_of(res, struct rdma_id_private, in res_to_dev()
166 res)->id.device; in res_to_dev()
168 return container_of(res, struct ib_mr, res)->device; in res_to_dev()
170 return container_of(res, struct ib_ucontext, res)->device; in res_to_dev()
172 return container_of(res, struct rdma_counter, res)->device; in res_to_dev()
174 WARN_ONCE(true, "Wrong resource tracking type %u\n", res->type); in res_to_dev()
179 void rdma_restrack_set_task(struct rdma_restrack_entry *res, in rdma_restrack_set_task() argument
183 res->kern_name = caller; in rdma_restrack_set_task()
187 if (res->task) in rdma_restrack_set_task()
188 put_task_struct(res->task); in rdma_restrack_set_task()
190 res->task = current; in rdma_restrack_set_task()
199 void rdma_restrack_attach_task(struct rdma_restrack_entry *res, in rdma_restrack_attach_task() argument
202 if (res->task) in rdma_restrack_attach_task()
203 put_task_struct(res->task); in rdma_restrack_attach_task()
205 res->task = task; in rdma_restrack_attach_task()
208 static void rdma_restrack_add(struct rdma_restrack_entry *res) in rdma_restrack_add() argument
210 struct ib_device *dev = res_to_dev(res); in rdma_restrack_add()
217 rt = &dev->res[res->type]; in rdma_restrack_add()
219 kref_init(&res->kref); in rdma_restrack_add()
220 init_completion(&res->comp); in rdma_restrack_add()
221 if (res->type == RDMA_RESTRACK_QP) { in rdma_restrack_add()
223 struct ib_qp *qp = container_of(res, struct ib_qp, res); in rdma_restrack_add()
225 ret = xa_insert(&rt->xa, qp->qp_num, res, GFP_KERNEL); in rdma_restrack_add()
226 res->id = ret ? 0 : qp->qp_num; in rdma_restrack_add()
227 } else if (res->type == RDMA_RESTRACK_COUNTER) { in rdma_restrack_add()
231 counter = container_of(res, struct rdma_counter, res); in rdma_restrack_add()
232 ret = xa_insert(&rt->xa, counter->id, res, GFP_KERNEL); in rdma_restrack_add()
233 res->id = ret ? 0 : counter->id; in rdma_restrack_add()
235 ret = xa_alloc_cyclic(&rt->xa, &res->id, res, xa_limit_32b, in rdma_restrack_add()
240 res->valid = true; in rdma_restrack_add()
247 void rdma_restrack_kadd(struct rdma_restrack_entry *res) in rdma_restrack_kadd() argument
249 res->task = NULL; in rdma_restrack_kadd()
250 set_kern_name(res); in rdma_restrack_kadd()
251 res->user = false; in rdma_restrack_kadd()
252 rdma_restrack_add(res); in rdma_restrack_kadd()
260 void rdma_restrack_uadd(struct rdma_restrack_entry *res) in rdma_restrack_uadd() argument
262 if ((res->type != RDMA_RESTRACK_CM_ID) && in rdma_restrack_uadd()
263 (res->type != RDMA_RESTRACK_COUNTER)) in rdma_restrack_uadd()
264 res->task = NULL; in rdma_restrack_uadd()
266 if (!res->task) in rdma_restrack_uadd()
267 rdma_restrack_set_task(res, NULL); in rdma_restrack_uadd()
268 res->kern_name = NULL; in rdma_restrack_uadd()
270 res->user = true; in rdma_restrack_uadd()
271 rdma_restrack_add(res); in rdma_restrack_uadd()
275 int __must_check rdma_restrack_get(struct rdma_restrack_entry *res) in rdma_restrack_get() argument
277 return kref_get_unless_zero(&res->kref); in rdma_restrack_get()
293 struct rdma_restrack_root *rt = &dev->res[type]; in rdma_restrack_get_byid()
294 struct rdma_restrack_entry *res; in rdma_restrack_get_byid() local
297 res = xa_load(&rt->xa, id); in rdma_restrack_get_byid()
298 if (!res || !rdma_restrack_get(res)) in rdma_restrack_get_byid()
299 res = ERR_PTR(-ENOENT); in rdma_restrack_get_byid()
302 return res; in rdma_restrack_get_byid()
308 struct rdma_restrack_entry *res; in restrack_release() local
310 res = container_of(kref, struct rdma_restrack_entry, kref); in restrack_release()
311 complete(&res->comp); in restrack_release()
314 int rdma_restrack_put(struct rdma_restrack_entry *res) in rdma_restrack_put() argument
316 return kref_put(&res->kref, restrack_release); in rdma_restrack_put()
320 void rdma_restrack_del(struct rdma_restrack_entry *res) in rdma_restrack_del() argument
326 if (!res->valid) in rdma_restrack_del()
329 dev = res_to_dev(res); in rdma_restrack_del()
333 rt = &dev->res[res->type]; in rdma_restrack_del()
335 old = xa_erase(&rt->xa, res->id); in rdma_restrack_del()
336 WARN_ON(old != res); in rdma_restrack_del()
337 res->valid = false; in rdma_restrack_del()
339 rdma_restrack_put(res); in rdma_restrack_del()
340 wait_for_completion(&res->comp); in rdma_restrack_del()
343 if (res->task) { in rdma_restrack_del()
344 put_task_struct(res->task); in rdma_restrack_del()
345 res->task = NULL; in rdma_restrack_del()
350 bool rdma_is_visible_in_pid_ns(struct rdma_restrack_entry *res) in rdma_is_visible_in_pid_ns() argument
358 if (rdma_is_kernel_res(res)) in rdma_is_visible_in_pid_ns()
362 return task_pid_vnr(res->task); in rdma_is_visible_in_pid_ns()