rdma_core.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  1. /*
  2. * Copyright (c) 2016, Mellanox Technologies inc. All rights reserved.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. */
  32. #include <linux/file.h>
  33. #include <linux/anon_inodes.h>
  34. #include <rdma/ib_verbs.h>
  35. #include <rdma/uverbs_types.h>
  36. #include <linux/rcupdate.h>
  37. #include "uverbs.h"
  38. #include "core_priv.h"
  39. #include "rdma_core.h"
  40. void uverbs_uobject_get(struct ib_uobject *uobject)
  41. {
  42. kref_get(&uobject->ref);
  43. }
  44. static void uverbs_uobject_free(struct kref *ref)
  45. {
  46. struct ib_uobject *uobj =
  47. container_of(ref, struct ib_uobject, ref);
  48. if (uobj->type->type_class->needs_kfree_rcu)
  49. kfree_rcu(uobj, rcu);
  50. else
  51. kfree(uobj);
  52. }
  53. void uverbs_uobject_put(struct ib_uobject *uobject)
  54. {
  55. kref_put(&uobject->ref, uverbs_uobject_free);
  56. }
  57. static int uverbs_try_lock_object(struct ib_uobject *uobj, bool exclusive)
  58. {
  59. /*
  60. * When a shared access is required, we use a positive counter. Each
  61. * shared access request checks that the value != -1 and increment it.
  62. * Exclusive access is required for operations like write or destroy.
  63. * In exclusive access mode, we check that the counter is zero (nobody
  64. * claimed this object) and we set it to -1. Releasing a shared access
  65. * lock is done simply by decreasing the counter. As for exclusive
  66. * access locks, since only a single one of them is is allowed
  67. * concurrently, setting the counter to zero is enough for releasing
  68. * this lock.
  69. */
  70. if (!exclusive)
  71. return __atomic_add_unless(&uobj->usecnt, 1, -1) == -1 ?
  72. -EBUSY : 0;
  73. /* lock is either WRITE or DESTROY - should be exclusive */
  74. return atomic_cmpxchg(&uobj->usecnt, 0, -1) == 0 ? 0 : -EBUSY;
  75. }
  76. static struct ib_uobject *alloc_uobj(struct ib_ucontext *context,
  77. const struct uverbs_obj_type *type)
  78. {
  79. struct ib_uobject *uobj = kzalloc(type->obj_size, GFP_KERNEL);
  80. if (!uobj)
  81. return ERR_PTR(-ENOMEM);
  82. /*
  83. * user_handle should be filled by the handler,
  84. * The object is added to the list in the commit stage.
  85. */
  86. uobj->context = context;
  87. uobj->type = type;
  88. atomic_set(&uobj->usecnt, 0);
  89. kref_init(&uobj->ref);
  90. return uobj;
  91. }
  92. static int idr_add_uobj(struct ib_uobject *uobj)
  93. {
  94. int ret;
  95. idr_preload(GFP_KERNEL);
  96. spin_lock(&uobj->context->ufile->idr_lock);
  97. /*
  98. * We start with allocating an idr pointing to NULL. This represents an
  99. * object which isn't initialized yet. We'll replace it later on with
  100. * the real object once we commit.
  101. */
  102. ret = idr_alloc(&uobj->context->ufile->idr, NULL, 0,
  103. min_t(unsigned long, U32_MAX - 1, INT_MAX), GFP_NOWAIT);
  104. if (ret >= 0)
  105. uobj->id = ret;
  106. spin_unlock(&uobj->context->ufile->idr_lock);
  107. idr_preload_end();
  108. return ret < 0 ? ret : 0;
  109. }
  110. /*
  111. * It only removes it from the uobjects list, uverbs_uobject_put() is still
  112. * required.
  113. */
  114. static void uverbs_idr_remove_uobj(struct ib_uobject *uobj)
  115. {
  116. spin_lock(&uobj->context->ufile->idr_lock);
  117. idr_remove(&uobj->context->ufile->idr, uobj->id);
  118. spin_unlock(&uobj->context->ufile->idr_lock);
  119. }
  120. /* Returns the ib_uobject or an error. The caller should check for IS_ERR. */
  121. static struct ib_uobject *lookup_get_idr_uobject(const struct uverbs_obj_type *type,
  122. struct ib_ucontext *ucontext,
  123. int id, bool exclusive)
  124. {
  125. struct ib_uobject *uobj;
  126. rcu_read_lock();
  127. /* object won't be released as we're protected in rcu */
  128. uobj = idr_find(&ucontext->ufile->idr, id);
  129. if (!uobj) {
  130. uobj = ERR_PTR(-ENOENT);
  131. goto free;
  132. }
  133. uverbs_uobject_get(uobj);
  134. free:
  135. rcu_read_unlock();
  136. return uobj;
  137. }
  138. static struct ib_uobject *lookup_get_fd_uobject(const struct uverbs_obj_type *type,
  139. struct ib_ucontext *ucontext,
  140. int id, bool exclusive)
  141. {
  142. struct file *f;
  143. struct ib_uobject *uobject;
  144. const struct uverbs_obj_fd_type *fd_type =
  145. container_of(type, struct uverbs_obj_fd_type, type);
  146. if (exclusive)
  147. return ERR_PTR(-EOPNOTSUPP);
  148. f = fget(id);
  149. if (!f)
  150. return ERR_PTR(-EBADF);
  151. uobject = f->private_data;
  152. /*
  153. * fget(id) ensures we are not currently running uverbs_close_fd,
  154. * and the caller is expected to ensure that uverbs_close_fd is never
  155. * done while a call top lookup is possible.
  156. */
  157. if (f->f_op != fd_type->fops) {
  158. fput(f);
  159. return ERR_PTR(-EBADF);
  160. }
  161. uverbs_uobject_get(uobject);
  162. return uobject;
  163. }
  164. struct ib_uobject *rdma_lookup_get_uobject(const struct uverbs_obj_type *type,
  165. struct ib_ucontext *ucontext,
  166. int id, bool exclusive)
  167. {
  168. struct ib_uobject *uobj;
  169. int ret;
  170. uobj = type->type_class->lookup_get(type, ucontext, id, exclusive);
  171. if (IS_ERR(uobj))
  172. return uobj;
  173. if (uobj->type != type) {
  174. ret = -EINVAL;
  175. goto free;
  176. }
  177. ret = uverbs_try_lock_object(uobj, exclusive);
  178. if (ret) {
  179. WARN(ucontext->cleanup_reason,
  180. "ib_uverbs: Trying to lookup_get while cleanup context\n");
  181. goto free;
  182. }
  183. return uobj;
  184. free:
  185. uobj->type->type_class->lookup_put(uobj, exclusive);
  186. uverbs_uobject_put(uobj);
  187. return ERR_PTR(ret);
  188. }
  189. static struct ib_uobject *alloc_begin_idr_uobject(const struct uverbs_obj_type *type,
  190. struct ib_ucontext *ucontext)
  191. {
  192. int ret;
  193. struct ib_uobject *uobj;
  194. uobj = alloc_uobj(ucontext, type);
  195. if (IS_ERR(uobj))
  196. return uobj;
  197. ret = idr_add_uobj(uobj);
  198. if (ret)
  199. goto uobj_put;
  200. ret = ib_rdmacg_try_charge(&uobj->cg_obj, ucontext->device,
  201. RDMACG_RESOURCE_HCA_OBJECT);
  202. if (ret)
  203. goto idr_remove;
  204. return uobj;
  205. idr_remove:
  206. uverbs_idr_remove_uobj(uobj);
  207. uobj_put:
  208. uverbs_uobject_put(uobj);
  209. return ERR_PTR(ret);
  210. }
  211. static struct ib_uobject *alloc_begin_fd_uobject(const struct uverbs_obj_type *type,
  212. struct ib_ucontext *ucontext)
  213. {
  214. const struct uverbs_obj_fd_type *fd_type =
  215. container_of(type, struct uverbs_obj_fd_type, type);
  216. int new_fd;
  217. struct ib_uobject *uobj;
  218. struct ib_uobject_file *uobj_file;
  219. struct file *filp;
  220. new_fd = get_unused_fd_flags(O_CLOEXEC);
  221. if (new_fd < 0)
  222. return ERR_PTR(new_fd);
  223. uobj = alloc_uobj(ucontext, type);
  224. if (IS_ERR(uobj)) {
  225. put_unused_fd(new_fd);
  226. return uobj;
  227. }
  228. uobj_file = container_of(uobj, struct ib_uobject_file, uobj);
  229. filp = anon_inode_getfile(fd_type->name,
  230. fd_type->fops,
  231. uobj_file,
  232. fd_type->flags);
  233. if (IS_ERR(filp)) {
  234. put_unused_fd(new_fd);
  235. uverbs_uobject_put(uobj);
  236. return (void *)filp;
  237. }
  238. uobj_file->uobj.id = new_fd;
  239. uobj_file->uobj.object = filp;
  240. uobj_file->ufile = ucontext->ufile;
  241. INIT_LIST_HEAD(&uobj->list);
  242. kref_get(&uobj_file->ufile->ref);
  243. return uobj;
  244. }
  245. struct ib_uobject *rdma_alloc_begin_uobject(const struct uverbs_obj_type *type,
  246. struct ib_ucontext *ucontext)
  247. {
  248. return type->type_class->alloc_begin(type, ucontext);
  249. }
  250. static void uverbs_uobject_add(struct ib_uobject *uobject)
  251. {
  252. mutex_lock(&uobject->context->uobjects_lock);
  253. list_add(&uobject->list, &uobject->context->uobjects);
  254. mutex_unlock(&uobject->context->uobjects_lock);
  255. }
  256. static int __must_check remove_commit_idr_uobject(struct ib_uobject *uobj,
  257. enum rdma_remove_reason why)
  258. {
  259. const struct uverbs_obj_idr_type *idr_type =
  260. container_of(uobj->type, struct uverbs_obj_idr_type,
  261. type);
  262. int ret = idr_type->destroy_object(uobj, why);
  263. /*
  264. * We can only fail gracefully if the user requested to destroy the
  265. * object. In the rest of the cases, just remove whatever you can.
  266. */
  267. if (why == RDMA_REMOVE_DESTROY && ret)
  268. return ret;
  269. ib_rdmacg_uncharge(&uobj->cg_obj, uobj->context->device,
  270. RDMACG_RESOURCE_HCA_OBJECT);
  271. uverbs_idr_remove_uobj(uobj);
  272. return ret;
  273. }
  274. static void alloc_abort_fd_uobject(struct ib_uobject *uobj)
  275. {
  276. struct ib_uobject_file *uobj_file =
  277. container_of(uobj, struct ib_uobject_file, uobj);
  278. struct file *filp = uobj->object;
  279. int id = uobj_file->uobj.id;
  280. /* Unsuccessful NEW */
  281. fput(filp);
  282. put_unused_fd(id);
  283. }
  284. static int __must_check remove_commit_fd_uobject(struct ib_uobject *uobj,
  285. enum rdma_remove_reason why)
  286. {
  287. const struct uverbs_obj_fd_type *fd_type =
  288. container_of(uobj->type, struct uverbs_obj_fd_type, type);
  289. struct ib_uobject_file *uobj_file =
  290. container_of(uobj, struct ib_uobject_file, uobj);
  291. int ret = fd_type->context_closed(uobj_file, why);
  292. if (why == RDMA_REMOVE_DESTROY && ret)
  293. return ret;
  294. if (why == RDMA_REMOVE_DURING_CLEANUP) {
  295. alloc_abort_fd_uobject(uobj);
  296. return ret;
  297. }
  298. uobj_file->uobj.context = NULL;
  299. return ret;
  300. }
  301. static void lockdep_check(struct ib_uobject *uobj, bool exclusive)
  302. {
  303. #ifdef CONFIG_LOCKDEP
  304. if (exclusive)
  305. WARN_ON(atomic_read(&uobj->usecnt) > 0);
  306. else
  307. WARN_ON(atomic_read(&uobj->usecnt) == -1);
  308. #endif
  309. }
  310. static int __must_check _rdma_remove_commit_uobject(struct ib_uobject *uobj,
  311. enum rdma_remove_reason why)
  312. {
  313. int ret;
  314. struct ib_ucontext *ucontext = uobj->context;
  315. ret = uobj->type->type_class->remove_commit(uobj, why);
  316. if (ret && why == RDMA_REMOVE_DESTROY) {
  317. /* We couldn't remove the object, so just unlock the uobject */
  318. atomic_set(&uobj->usecnt, 0);
  319. uobj->type->type_class->lookup_put(uobj, true);
  320. } else {
  321. mutex_lock(&ucontext->uobjects_lock);
  322. list_del(&uobj->list);
  323. mutex_unlock(&ucontext->uobjects_lock);
  324. /* put the ref we took when we created the object */
  325. uverbs_uobject_put(uobj);
  326. }
  327. return ret;
  328. }
  329. /* This is called only for user requested DESTROY reasons */
  330. int __must_check rdma_remove_commit_uobject(struct ib_uobject *uobj)
  331. {
  332. int ret;
  333. struct ib_ucontext *ucontext = uobj->context;
  334. /* put the ref count we took at lookup_get */
  335. uverbs_uobject_put(uobj);
  336. /* Cleanup is running. Calling this should have been impossible */
  337. if (!down_read_trylock(&ucontext->cleanup_rwsem)) {
  338. WARN(true, "ib_uverbs: Cleanup is running while removing an uobject\n");
  339. return 0;
  340. }
  341. lockdep_check(uobj, true);
  342. ret = _rdma_remove_commit_uobject(uobj, RDMA_REMOVE_DESTROY);
  343. up_read(&ucontext->cleanup_rwsem);
  344. return ret;
  345. }
  346. static void alloc_commit_idr_uobject(struct ib_uobject *uobj)
  347. {
  348. uverbs_uobject_add(uobj);
  349. spin_lock(&uobj->context->ufile->idr_lock);
  350. /*
  351. * We already allocated this IDR with a NULL object, so
  352. * this shouldn't fail.
  353. */
  354. WARN_ON(idr_replace(&uobj->context->ufile->idr,
  355. uobj, uobj->id));
  356. spin_unlock(&uobj->context->ufile->idr_lock);
  357. }
  358. static void alloc_commit_fd_uobject(struct ib_uobject *uobj)
  359. {
  360. struct ib_uobject_file *uobj_file =
  361. container_of(uobj, struct ib_uobject_file, uobj);
  362. uverbs_uobject_add(&uobj_file->uobj);
  363. fd_install(uobj_file->uobj.id, uobj->object);
  364. /* This shouldn't be used anymore. Use the file object instead */
  365. uobj_file->uobj.id = 0;
  366. /* Get another reference as we export this to the fops */
  367. uverbs_uobject_get(&uobj_file->uobj);
  368. }
  369. int rdma_alloc_commit_uobject(struct ib_uobject *uobj)
  370. {
  371. /* Cleanup is running. Calling this should have been impossible */
  372. if (!down_read_trylock(&uobj->context->cleanup_rwsem)) {
  373. int ret;
  374. WARN(true, "ib_uverbs: Cleanup is running while allocating an uobject\n");
  375. ret = uobj->type->type_class->remove_commit(uobj,
  376. RDMA_REMOVE_DURING_CLEANUP);
  377. if (ret)
  378. pr_warn("ib_uverbs: cleanup of idr object %d failed\n",
  379. uobj->id);
  380. return ret;
  381. }
  382. uobj->type->type_class->alloc_commit(uobj);
  383. up_read(&uobj->context->cleanup_rwsem);
  384. return 0;
  385. }
  386. static void alloc_abort_idr_uobject(struct ib_uobject *uobj)
  387. {
  388. uverbs_idr_remove_uobj(uobj);
  389. ib_rdmacg_uncharge(&uobj->cg_obj, uobj->context->device,
  390. RDMACG_RESOURCE_HCA_OBJECT);
  391. uverbs_uobject_put(uobj);
  392. }
  393. void rdma_alloc_abort_uobject(struct ib_uobject *uobj)
  394. {
  395. uobj->type->type_class->alloc_abort(uobj);
  396. }
  397. static void lookup_put_idr_uobject(struct ib_uobject *uobj, bool exclusive)
  398. {
  399. }
  400. static void lookup_put_fd_uobject(struct ib_uobject *uobj, bool exclusive)
  401. {
  402. struct file *filp = uobj->object;
  403. WARN_ON(exclusive);
  404. /* This indirectly calls uverbs_close_fd and free the object */
  405. fput(filp);
  406. }
  407. void rdma_lookup_put_uobject(struct ib_uobject *uobj, bool exclusive)
  408. {
  409. lockdep_check(uobj, exclusive);
  410. uobj->type->type_class->lookup_put(uobj, exclusive);
  411. /*
  412. * In order to unlock an object, either decrease its usecnt for
  413. * read access or zero it in case of exclusive access. See
  414. * uverbs_try_lock_object for locking schema information.
  415. */
  416. if (!exclusive)
  417. atomic_dec(&uobj->usecnt);
  418. else
  419. atomic_set(&uobj->usecnt, 0);
  420. uverbs_uobject_put(uobj);
  421. }
  422. const struct uverbs_obj_type_class uverbs_idr_class = {
  423. .alloc_begin = alloc_begin_idr_uobject,
  424. .lookup_get = lookup_get_idr_uobject,
  425. .alloc_commit = alloc_commit_idr_uobject,
  426. .alloc_abort = alloc_abort_idr_uobject,
  427. .lookup_put = lookup_put_idr_uobject,
  428. .remove_commit = remove_commit_idr_uobject,
  429. /*
  430. * When we destroy an object, we first just lock it for WRITE and
  431. * actually DESTROY it in the finalize stage. So, the problematic
  432. * scenario is when we just started the finalize stage of the
  433. * destruction (nothing was executed yet). Now, the other thread
  434. * fetched the object for READ access, but it didn't lock it yet.
  435. * The DESTROY thread continues and starts destroying the object.
  436. * When the other thread continue - without the RCU, it would
  437. * access freed memory. However, the rcu_read_lock delays the free
  438. * until the rcu_read_lock of the READ operation quits. Since the
  439. * exclusive lock of the object is still taken by the DESTROY flow, the
  440. * READ operation will get -EBUSY and it'll just bail out.
  441. */
  442. .needs_kfree_rcu = true,
  443. };
  444. static void _uverbs_close_fd(struct ib_uobject_file *uobj_file)
  445. {
  446. struct ib_ucontext *ucontext;
  447. struct ib_uverbs_file *ufile = uobj_file->ufile;
  448. int ret;
  449. mutex_lock(&uobj_file->ufile->cleanup_mutex);
  450. /* uobject was either already cleaned up or is cleaned up right now anyway */
  451. if (!uobj_file->uobj.context ||
  452. !down_read_trylock(&uobj_file->uobj.context->cleanup_rwsem))
  453. goto unlock;
  454. ucontext = uobj_file->uobj.context;
  455. ret = _rdma_remove_commit_uobject(&uobj_file->uobj, RDMA_REMOVE_CLOSE);
  456. up_read(&ucontext->cleanup_rwsem);
  457. if (ret)
  458. pr_warn("uverbs: unable to clean up uobject file in uverbs_close_fd.\n");
  459. unlock:
  460. mutex_unlock(&ufile->cleanup_mutex);
  461. }
  462. void uverbs_close_fd(struct file *f)
  463. {
  464. struct ib_uobject_file *uobj_file = f->private_data;
  465. struct kref *uverbs_file_ref = &uobj_file->ufile->ref;
  466. _uverbs_close_fd(uobj_file);
  467. uverbs_uobject_put(&uobj_file->uobj);
  468. kref_put(uverbs_file_ref, ib_uverbs_release_file);
  469. }
  470. void uverbs_cleanup_ucontext(struct ib_ucontext *ucontext, bool device_removed)
  471. {
  472. enum rdma_remove_reason reason = device_removed ?
  473. RDMA_REMOVE_DRIVER_REMOVE : RDMA_REMOVE_CLOSE;
  474. unsigned int cur_order = 0;
  475. ucontext->cleanup_reason = reason;
  476. /*
  477. * Waits for all remove_commit and alloc_commit to finish. Logically, We
  478. * want to hold this forever as the context is going to be destroyed,
  479. * but we'll release it since it causes a "held lock freed" BUG message.
  480. */
  481. down_write(&ucontext->cleanup_rwsem);
  482. while (!list_empty(&ucontext->uobjects)) {
  483. struct ib_uobject *obj, *next_obj;
  484. unsigned int next_order = UINT_MAX;
  485. /*
  486. * This shouldn't run while executing other commands on this
  487. * context. Thus, the only thing we should take care of is
  488. * releasing a FD while traversing this list. The FD could be
  489. * closed and released from the _release fop of this FD.
  490. * In order to mitigate this, we add a lock.
  491. * We take and release the lock per order traversal in order
  492. * to let other threads (which might still use the FDs) chance
  493. * to run.
  494. */
  495. mutex_lock(&ucontext->uobjects_lock);
  496. list_for_each_entry_safe(obj, next_obj, &ucontext->uobjects,
  497. list) {
  498. if (obj->type->destroy_order == cur_order) {
  499. int ret;
  500. /*
  501. * if we hit this WARN_ON, that means we are
  502. * racing with a lookup_get.
  503. */
  504. WARN_ON(uverbs_try_lock_object(obj, true));
  505. ret = obj->type->type_class->remove_commit(obj,
  506. reason);
  507. list_del(&obj->list);
  508. if (ret)
  509. pr_warn("ib_uverbs: failed to remove uobject id %d order %u\n",
  510. obj->id, cur_order);
  511. /* put the ref we took when we created the object */
  512. uverbs_uobject_put(obj);
  513. } else {
  514. next_order = min(next_order,
  515. obj->type->destroy_order);
  516. }
  517. }
  518. mutex_unlock(&ucontext->uobjects_lock);
  519. cur_order = next_order;
  520. }
  521. up_write(&ucontext->cleanup_rwsem);
  522. }
  523. void uverbs_initialize_ucontext(struct ib_ucontext *ucontext)
  524. {
  525. ucontext->cleanup_reason = 0;
  526. mutex_init(&ucontext->uobjects_lock);
  527. INIT_LIST_HEAD(&ucontext->uobjects);
  528. init_rwsem(&ucontext->cleanup_rwsem);
  529. }
  530. const struct uverbs_obj_type_class uverbs_fd_class = {
  531. .alloc_begin = alloc_begin_fd_uobject,
  532. .lookup_get = lookup_get_fd_uobject,
  533. .alloc_commit = alloc_commit_fd_uobject,
  534. .alloc_abort = alloc_abort_fd_uobject,
  535. .lookup_put = lookup_put_fd_uobject,
  536. .remove_commit = remove_commit_fd_uobject,
  537. .needs_kfree_rcu = false,
  538. };