2 * Copyright (c) 2005-2006 Intel Corporation. All rights reserved.
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:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
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.
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
33 #include <linux/completion.h>
34 #include <linux/file.h>
35 #include <linux/mutex.h>
36 #include <linux/poll.h>
37 #include <linux/sched.h>
38 #include <linux/idr.h>
40 #include <linux/in6.h>
41 #include <linux/miscdevice.h>
42 #include <linux/slab.h>
43 #include <linux/sysctl.h>
44 #include <linux/module.h>
45 #include <linux/nsproxy.h>
47 #include <linux/nospec.h>
49 #include <rdma/rdma_user_cm.h>
50 #include <rdma/ib_marshall.h>
51 #include <rdma/rdma_cm.h>
52 #include <rdma/rdma_cm_ib.h>
53 #include <rdma/ib_addr.h>
56 MODULE_AUTHOR("Sean Hefty");
57 MODULE_DESCRIPTION("RDMA Userspace Connection Manager Access");
58 MODULE_LICENSE("Dual BSD/GPL");
60 static unsigned int max_backlog = 1024;
62 static struct ctl_table_header *ucma_ctl_table_hdr;
63 static struct ctl_table ucma_ctl_table[] = {
65 .procname = "max_backlog",
67 .maxlen = sizeof max_backlog,
69 .proc_handler = proc_dointvec,
77 struct list_head ctx_list;
78 struct list_head event_list;
79 wait_queue_head_t poll_wait;
80 struct workqueue_struct *close_wq;
85 struct completion comp;
90 struct ucma_file *file;
91 struct rdma_cm_id *cm_id;
94 struct list_head list;
95 struct list_head mc_list;
96 /* mark that device is in process of destroying the internal HW
97 * resources, protected by the global mut
100 /* sync between removal event and id destroy, protected by file mut */
102 struct work_struct close_work;
105 struct ucma_multicast {
106 struct ucma_context *ctx;
112 struct list_head list;
113 struct sockaddr_storage addr;
117 struct ucma_context *ctx;
118 struct ucma_multicast *mc;
119 struct list_head list;
120 struct rdma_cm_id *cm_id;
121 struct rdma_ucm_event_resp resp;
122 struct work_struct close_work;
125 static DEFINE_MUTEX(mut);
126 static DEFINE_IDR(ctx_idr);
127 static DEFINE_IDR(multicast_idr);
129 static const struct file_operations ucma_fops;
131 static inline struct ucma_context *_ucma_find_context(int id,
132 struct ucma_file *file)
134 struct ucma_context *ctx;
136 ctx = idr_find(&ctx_idr, id);
138 ctx = ERR_PTR(-ENOENT);
139 else if (ctx->file != file || !ctx->cm_id)
140 ctx = ERR_PTR(-EINVAL);
144 static struct ucma_context *ucma_get_ctx(struct ucma_file *file, int id)
146 struct ucma_context *ctx;
149 ctx = _ucma_find_context(id, file);
154 atomic_inc(&ctx->ref);
160 static void ucma_put_ctx(struct ucma_context *ctx)
162 if (atomic_dec_and_test(&ctx->ref))
163 complete(&ctx->comp);
166 static void ucma_close_event_id(struct work_struct *work)
168 struct ucma_event *uevent_close = container_of(work, struct ucma_event, close_work);
170 rdma_destroy_id(uevent_close->cm_id);
174 static void ucma_close_id(struct work_struct *work)
176 struct ucma_context *ctx = container_of(work, struct ucma_context, close_work);
178 /* once all inflight tasks are finished, we close all underlying
179 * resources. The context is still alive till its explicit destryoing
183 wait_for_completion(&ctx->comp);
184 /* No new events will be generated after destroying the id. */
185 rdma_destroy_id(ctx->cm_id);
188 static struct ucma_context *ucma_alloc_ctx(struct ucma_file *file)
190 struct ucma_context *ctx;
192 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
196 INIT_WORK(&ctx->close_work, ucma_close_id);
197 atomic_set(&ctx->ref, 1);
198 init_completion(&ctx->comp);
199 INIT_LIST_HEAD(&ctx->mc_list);
203 ctx->id = idr_alloc(&ctx_idr, ctx, 0, 0, GFP_KERNEL);
208 list_add_tail(&ctx->list, &file->ctx_list);
216 static struct ucma_multicast* ucma_alloc_multicast(struct ucma_context *ctx)
218 struct ucma_multicast *mc;
220 mc = kzalloc(sizeof(*mc), GFP_KERNEL);
225 mc->id = idr_alloc(&multicast_idr, NULL, 0, 0, GFP_KERNEL);
231 list_add_tail(&mc->list, &ctx->mc_list);
239 static void ucma_copy_conn_event(struct rdma_ucm_conn_param *dst,
240 struct rdma_conn_param *src)
242 if (src->private_data_len)
243 memcpy(dst->private_data, src->private_data,
244 src->private_data_len);
245 dst->private_data_len = src->private_data_len;
246 dst->responder_resources =src->responder_resources;
247 dst->initiator_depth = src->initiator_depth;
248 dst->flow_control = src->flow_control;
249 dst->retry_count = src->retry_count;
250 dst->rnr_retry_count = src->rnr_retry_count;
252 dst->qp_num = src->qp_num;
255 static void ucma_copy_ud_event(struct rdma_ucm_ud_param *dst,
256 struct rdma_ud_param *src)
258 if (src->private_data_len)
259 memcpy(dst->private_data, src->private_data,
260 src->private_data_len);
261 dst->private_data_len = src->private_data_len;
262 ib_copy_ah_attr_to_user(&dst->ah_attr, &src->ah_attr);
263 dst->qp_num = src->qp_num;
264 dst->qkey = src->qkey;
267 static void ucma_set_event_context(struct ucma_context *ctx,
268 struct rdma_cm_event *event,
269 struct ucma_event *uevent)
272 switch (event->event) {
273 case RDMA_CM_EVENT_MULTICAST_JOIN:
274 case RDMA_CM_EVENT_MULTICAST_ERROR:
275 uevent->mc = (struct ucma_multicast *)
276 event->param.ud.private_data;
277 uevent->resp.uid = uevent->mc->uid;
278 uevent->resp.id = uevent->mc->id;
281 uevent->resp.uid = ctx->uid;
282 uevent->resp.id = ctx->id;
287 /* Called with file->mut locked for the relevant context. */
288 static void ucma_removal_event_handler(struct rdma_cm_id *cm_id)
290 struct ucma_context *ctx = cm_id->context;
291 struct ucma_event *con_req_eve;
297 /* only if context is pointing to cm_id that it owns it and can be
298 * queued to be closed, otherwise that cm_id is an inflight one that
299 * is part of that context event list pending to be detached and
300 * reattached to its new context as part of ucma_get_event,
301 * handled separately below.
303 if (ctx->cm_id == cm_id) {
307 queue_work(ctx->file->close_wq, &ctx->close_work);
311 list_for_each_entry(con_req_eve, &ctx->file->event_list, list) {
312 if (con_req_eve->cm_id == cm_id &&
313 con_req_eve->resp.event == RDMA_CM_EVENT_CONNECT_REQUEST) {
314 list_del(&con_req_eve->list);
315 INIT_WORK(&con_req_eve->close_work, ucma_close_event_id);
316 queue_work(ctx->file->close_wq, &con_req_eve->close_work);
322 pr_err("ucma_removal_event_handler: warning: connect request event wasn't found\n");
325 static int ucma_event_handler(struct rdma_cm_id *cm_id,
326 struct rdma_cm_event *event)
328 struct ucma_event *uevent;
329 struct ucma_context *ctx = cm_id->context;
332 uevent = kzalloc(sizeof(*uevent), GFP_KERNEL);
334 return event->event == RDMA_CM_EVENT_CONNECT_REQUEST;
336 mutex_lock(&ctx->file->mut);
337 uevent->cm_id = cm_id;
338 ucma_set_event_context(ctx, event, uevent);
339 uevent->resp.event = event->event;
340 uevent->resp.status = event->status;
341 if (cm_id->qp_type == IB_QPT_UD)
342 ucma_copy_ud_event(&uevent->resp.param.ud, &event->param.ud);
344 ucma_copy_conn_event(&uevent->resp.param.conn,
347 if (event->event == RDMA_CM_EVENT_CONNECT_REQUEST) {
354 } else if (!ctx->uid || ctx->cm_id != cm_id) {
356 * We ignore events for new connections until userspace has set
357 * their context. This can only happen if an error occurs on a
358 * new connection before the user accepts it. This is okay,
359 * since the accept will just fail later. However, we do need
360 * to release the underlying HW resources in case of a device
363 if (event->event == RDMA_CM_EVENT_DEVICE_REMOVAL)
364 ucma_removal_event_handler(cm_id);
370 list_add_tail(&uevent->list, &ctx->file->event_list);
371 wake_up_interruptible(&ctx->file->poll_wait);
372 if (event->event == RDMA_CM_EVENT_DEVICE_REMOVAL)
373 ucma_removal_event_handler(cm_id);
375 mutex_unlock(&ctx->file->mut);
379 static ssize_t ucma_get_event(struct ucma_file *file, const char __user *inbuf,
380 int in_len, int out_len)
382 struct ucma_context *ctx;
383 struct rdma_ucm_get_event cmd;
384 struct ucma_event *uevent;
387 if (out_len < sizeof uevent->resp)
390 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
393 mutex_lock(&file->mut);
394 while (list_empty(&file->event_list)) {
395 mutex_unlock(&file->mut);
397 if (file->filp->f_flags & O_NONBLOCK)
400 if (wait_event_interruptible(file->poll_wait,
401 !list_empty(&file->event_list)))
404 mutex_lock(&file->mut);
407 uevent = list_entry(file->event_list.next, struct ucma_event, list);
409 if (uevent->resp.event == RDMA_CM_EVENT_CONNECT_REQUEST) {
410 ctx = ucma_alloc_ctx(file);
415 uevent->ctx->backlog++;
416 ctx->cm_id = uevent->cm_id;
417 ctx->cm_id->context = ctx;
418 uevent->resp.id = ctx->id;
421 if (copy_to_user((void __user *)(unsigned long)cmd.response,
422 &uevent->resp, sizeof uevent->resp)) {
427 list_del(&uevent->list);
428 uevent->ctx->events_reported++;
430 uevent->mc->events_reported++;
433 mutex_unlock(&file->mut);
437 static int ucma_get_qp_type(struct rdma_ucm_create_id *cmd, enum ib_qp_type *qp_type)
441 *qp_type = IB_QPT_RC;
445 *qp_type = IB_QPT_UD;
448 *qp_type = cmd->qp_type;
455 static ssize_t ucma_create_id(struct ucma_file *file, const char __user *inbuf,
456 int in_len, int out_len)
458 struct rdma_ucm_create_id cmd;
459 struct rdma_ucm_create_id_resp resp;
460 struct ucma_context *ctx;
461 struct rdma_cm_id *cm_id;
462 enum ib_qp_type qp_type;
465 if (out_len < sizeof(resp))
468 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
471 ret = ucma_get_qp_type(&cmd, &qp_type);
475 mutex_lock(&file->mut);
476 ctx = ucma_alloc_ctx(file);
477 mutex_unlock(&file->mut);
482 cm_id = rdma_create_id(current->nsproxy->net_ns,
483 ucma_event_handler, ctx, cmd.ps, qp_type);
485 ret = PTR_ERR(cm_id);
490 if (copy_to_user((void __user *)(unsigned long)cmd.response,
491 &resp, sizeof(resp))) {
500 rdma_destroy_id(cm_id);
503 idr_remove(&ctx_idr, ctx->id);
505 mutex_lock(&file->mut);
506 list_del(&ctx->list);
507 mutex_unlock(&file->mut);
512 static void ucma_cleanup_multicast(struct ucma_context *ctx)
514 struct ucma_multicast *mc, *tmp;
517 list_for_each_entry_safe(mc, tmp, &ctx->mc_list, list) {
519 idr_remove(&multicast_idr, mc->id);
525 static void ucma_cleanup_mc_events(struct ucma_multicast *mc)
527 struct ucma_event *uevent, *tmp;
529 list_for_each_entry_safe(uevent, tmp, &mc->ctx->file->event_list, list) {
530 if (uevent->mc != mc)
533 list_del(&uevent->list);
539 * ucma_free_ctx is called after the underlying rdma CM-ID is destroyed. At
540 * this point, no new events will be reported from the hardware. However, we
541 * still need to cleanup the UCMA context for this ID. Specifically, there
542 * might be events that have not yet been consumed by the user space software.
543 * These might include pending connect requests which we have not completed
544 * processing. We cannot call rdma_destroy_id while holding the lock of the
545 * context (file->mut), as it might cause a deadlock. We therefore extract all
546 * relevant events from the context pending events list while holding the
547 * mutex. After that we release them as needed.
549 static int ucma_free_ctx(struct ucma_context *ctx)
552 struct ucma_event *uevent, *tmp;
556 ucma_cleanup_multicast(ctx);
558 /* Cleanup events not yet reported to the user. */
559 mutex_lock(&ctx->file->mut);
560 list_for_each_entry_safe(uevent, tmp, &ctx->file->event_list, list) {
561 if (uevent->ctx == ctx)
562 list_move_tail(&uevent->list, &list);
564 list_del(&ctx->list);
565 mutex_unlock(&ctx->file->mut);
567 list_for_each_entry_safe(uevent, tmp, &list, list) {
568 list_del(&uevent->list);
569 if (uevent->resp.event == RDMA_CM_EVENT_CONNECT_REQUEST)
570 rdma_destroy_id(uevent->cm_id);
574 events_reported = ctx->events_reported;
576 return events_reported;
579 static ssize_t ucma_destroy_id(struct ucma_file *file, const char __user *inbuf,
580 int in_len, int out_len)
582 struct rdma_ucm_destroy_id cmd;
583 struct rdma_ucm_destroy_id_resp resp;
584 struct ucma_context *ctx;
587 if (out_len < sizeof(resp))
590 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
594 ctx = _ucma_find_context(cmd.id, file);
596 idr_remove(&ctx_idr, ctx->id);
602 mutex_lock(&ctx->file->mut);
604 mutex_unlock(&ctx->file->mut);
606 flush_workqueue(ctx->file->close_wq);
607 /* At this point it's guaranteed that there is no inflight
613 wait_for_completion(&ctx->comp);
614 rdma_destroy_id(ctx->cm_id);
619 resp.events_reported = ucma_free_ctx(ctx);
620 if (copy_to_user((void __user *)(unsigned long)cmd.response,
621 &resp, sizeof(resp)))
627 static ssize_t ucma_bind_ip(struct ucma_file *file, const char __user *inbuf,
628 int in_len, int out_len)
630 struct rdma_ucm_bind_ip cmd;
631 struct ucma_context *ctx;
634 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
637 if (!rdma_addr_size_in6(&cmd.addr))
640 ctx = ucma_get_ctx(file, cmd.id);
644 ret = rdma_bind_addr(ctx->cm_id, (struct sockaddr *) &cmd.addr);
649 static ssize_t ucma_bind(struct ucma_file *file, const char __user *inbuf,
650 int in_len, int out_len)
652 struct rdma_ucm_bind cmd;
653 struct ucma_context *ctx;
656 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
659 if (cmd.reserved || !cmd.addr_size ||
660 cmd.addr_size != rdma_addr_size_kss(&cmd.addr))
663 ctx = ucma_get_ctx(file, cmd.id);
667 ret = rdma_bind_addr(ctx->cm_id, (struct sockaddr *) &cmd.addr);
672 static ssize_t ucma_resolve_ip(struct ucma_file *file,
673 const char __user *inbuf,
674 int in_len, int out_len)
676 struct rdma_ucm_resolve_ip cmd;
677 struct ucma_context *ctx;
680 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
683 if ((cmd.src_addr.sin6_family && !rdma_addr_size_in6(&cmd.src_addr)) ||
684 !rdma_addr_size_in6(&cmd.dst_addr))
687 ctx = ucma_get_ctx(file, cmd.id);
691 ret = rdma_resolve_addr(ctx->cm_id, (struct sockaddr *) &cmd.src_addr,
692 (struct sockaddr *) &cmd.dst_addr, cmd.timeout_ms);
697 static ssize_t ucma_resolve_addr(struct ucma_file *file,
698 const char __user *inbuf,
699 int in_len, int out_len)
701 struct rdma_ucm_resolve_addr cmd;
702 struct ucma_context *ctx;
705 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
709 (cmd.src_size && (cmd.src_size != rdma_addr_size_kss(&cmd.src_addr))) ||
710 !cmd.dst_size || (cmd.dst_size != rdma_addr_size_kss(&cmd.dst_addr)))
713 ctx = ucma_get_ctx(file, cmd.id);
717 ret = rdma_resolve_addr(ctx->cm_id, (struct sockaddr *) &cmd.src_addr,
718 (struct sockaddr *) &cmd.dst_addr, cmd.timeout_ms);
723 static ssize_t ucma_resolve_route(struct ucma_file *file,
724 const char __user *inbuf,
725 int in_len, int out_len)
727 struct rdma_ucm_resolve_route cmd;
728 struct ucma_context *ctx;
731 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
734 ctx = ucma_get_ctx(file, cmd.id);
738 ret = rdma_resolve_route(ctx->cm_id, cmd.timeout_ms);
743 static void ucma_copy_ib_route(struct rdma_ucm_query_route_resp *resp,
744 struct rdma_route *route)
746 struct rdma_dev_addr *dev_addr;
748 resp->num_paths = route->num_paths;
749 switch (route->num_paths) {
751 dev_addr = &route->addr.dev_addr;
752 rdma_addr_get_dgid(dev_addr,
753 (union ib_gid *) &resp->ib_route[0].dgid);
754 rdma_addr_get_sgid(dev_addr,
755 (union ib_gid *) &resp->ib_route[0].sgid);
756 resp->ib_route[0].pkey = cpu_to_be16(ib_addr_get_pkey(dev_addr));
759 ib_copy_path_rec_to_user(&resp->ib_route[1],
760 &route->path_rec[1]);
763 ib_copy_path_rec_to_user(&resp->ib_route[0],
764 &route->path_rec[0]);
771 static void ucma_copy_iboe_route(struct rdma_ucm_query_route_resp *resp,
772 struct rdma_route *route)
775 resp->num_paths = route->num_paths;
776 switch (route->num_paths) {
778 rdma_ip2gid((struct sockaddr *)&route->addr.dst_addr,
779 (union ib_gid *)&resp->ib_route[0].dgid);
780 rdma_ip2gid((struct sockaddr *)&route->addr.src_addr,
781 (union ib_gid *)&resp->ib_route[0].sgid);
782 resp->ib_route[0].pkey = cpu_to_be16(0xffff);
785 ib_copy_path_rec_to_user(&resp->ib_route[1],
786 &route->path_rec[1]);
789 ib_copy_path_rec_to_user(&resp->ib_route[0],
790 &route->path_rec[0]);
797 static void ucma_copy_iw_route(struct rdma_ucm_query_route_resp *resp,
798 struct rdma_route *route)
800 struct rdma_dev_addr *dev_addr;
802 dev_addr = &route->addr.dev_addr;
803 rdma_addr_get_dgid(dev_addr, (union ib_gid *) &resp->ib_route[0].dgid);
804 rdma_addr_get_sgid(dev_addr, (union ib_gid *) &resp->ib_route[0].sgid);
807 static ssize_t ucma_query_route(struct ucma_file *file,
808 const char __user *inbuf,
809 int in_len, int out_len)
811 struct rdma_ucm_query cmd;
812 struct rdma_ucm_query_route_resp resp;
813 struct ucma_context *ctx;
814 struct sockaddr *addr;
817 if (out_len < sizeof(resp))
820 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
823 ctx = ucma_get_ctx(file, cmd.id);
827 memset(&resp, 0, sizeof resp);
828 addr = (struct sockaddr *) &ctx->cm_id->route.addr.src_addr;
829 memcpy(&resp.src_addr, addr, addr->sa_family == AF_INET ?
830 sizeof(struct sockaddr_in) :
831 sizeof(struct sockaddr_in6));
832 addr = (struct sockaddr *) &ctx->cm_id->route.addr.dst_addr;
833 memcpy(&resp.dst_addr, addr, addr->sa_family == AF_INET ?
834 sizeof(struct sockaddr_in) :
835 sizeof(struct sockaddr_in6));
836 if (!ctx->cm_id->device)
839 resp.node_guid = (__force __u64) ctx->cm_id->device->node_guid;
840 resp.port_num = ctx->cm_id->port_num;
842 if (rdma_cap_ib_sa(ctx->cm_id->device, ctx->cm_id->port_num))
843 ucma_copy_ib_route(&resp, &ctx->cm_id->route);
844 else if (rdma_protocol_roce(ctx->cm_id->device, ctx->cm_id->port_num))
845 ucma_copy_iboe_route(&resp, &ctx->cm_id->route);
846 else if (rdma_protocol_iwarp(ctx->cm_id->device, ctx->cm_id->port_num))
847 ucma_copy_iw_route(&resp, &ctx->cm_id->route);
850 if (copy_to_user((void __user *)(unsigned long)cmd.response,
851 &resp, sizeof(resp)))
858 static void ucma_query_device_addr(struct rdma_cm_id *cm_id,
859 struct rdma_ucm_query_addr_resp *resp)
864 resp->node_guid = (__force __u64) cm_id->device->node_guid;
865 resp->port_num = cm_id->port_num;
866 resp->pkey = (__force __u16) cpu_to_be16(
867 ib_addr_get_pkey(&cm_id->route.addr.dev_addr));
870 static ssize_t ucma_query_addr(struct ucma_context *ctx,
871 void __user *response, int out_len)
873 struct rdma_ucm_query_addr_resp resp;
874 struct sockaddr *addr;
877 if (out_len < sizeof(resp))
880 memset(&resp, 0, sizeof resp);
882 addr = (struct sockaddr *) &ctx->cm_id->route.addr.src_addr;
883 resp.src_size = rdma_addr_size(addr);
884 memcpy(&resp.src_addr, addr, resp.src_size);
886 addr = (struct sockaddr *) &ctx->cm_id->route.addr.dst_addr;
887 resp.dst_size = rdma_addr_size(addr);
888 memcpy(&resp.dst_addr, addr, resp.dst_size);
890 ucma_query_device_addr(ctx->cm_id, &resp);
892 if (copy_to_user(response, &resp, sizeof(resp)))
898 static ssize_t ucma_query_path(struct ucma_context *ctx,
899 void __user *response, int out_len)
901 struct rdma_ucm_query_path_resp *resp;
904 if (out_len < sizeof(*resp))
907 resp = kzalloc(out_len, GFP_KERNEL);
911 resp->num_paths = ctx->cm_id->route.num_paths;
912 for (i = 0, out_len -= sizeof(*resp);
913 i < resp->num_paths && out_len > sizeof(struct ib_path_rec_data);
914 i++, out_len -= sizeof(struct ib_path_rec_data)) {
916 resp->path_data[i].flags = IB_PATH_GMP | IB_PATH_PRIMARY |
917 IB_PATH_BIDIRECTIONAL;
918 ib_sa_pack_path(&ctx->cm_id->route.path_rec[i],
919 &resp->path_data[i].path_rec);
922 if (copy_to_user(response, resp,
923 sizeof(*resp) + (i * sizeof(struct ib_path_rec_data))))
930 static ssize_t ucma_query_gid(struct ucma_context *ctx,
931 void __user *response, int out_len)
933 struct rdma_ucm_query_addr_resp resp;
934 struct sockaddr_ib *addr;
937 if (out_len < sizeof(resp))
940 memset(&resp, 0, sizeof resp);
942 ucma_query_device_addr(ctx->cm_id, &resp);
944 addr = (struct sockaddr_ib *) &resp.src_addr;
945 resp.src_size = sizeof(*addr);
946 if (ctx->cm_id->route.addr.src_addr.ss_family == AF_IB) {
947 memcpy(addr, &ctx->cm_id->route.addr.src_addr, resp.src_size);
949 addr->sib_family = AF_IB;
950 addr->sib_pkey = (__force __be16) resp.pkey;
951 rdma_addr_get_sgid(&ctx->cm_id->route.addr.dev_addr,
952 (union ib_gid *) &addr->sib_addr);
953 addr->sib_sid = rdma_get_service_id(ctx->cm_id, (struct sockaddr *)
954 &ctx->cm_id->route.addr.src_addr);
957 addr = (struct sockaddr_ib *) &resp.dst_addr;
958 resp.dst_size = sizeof(*addr);
959 if (ctx->cm_id->route.addr.dst_addr.ss_family == AF_IB) {
960 memcpy(addr, &ctx->cm_id->route.addr.dst_addr, resp.dst_size);
962 addr->sib_family = AF_IB;
963 addr->sib_pkey = (__force __be16) resp.pkey;
964 rdma_addr_get_dgid(&ctx->cm_id->route.addr.dev_addr,
965 (union ib_gid *) &addr->sib_addr);
966 addr->sib_sid = rdma_get_service_id(ctx->cm_id, (struct sockaddr *)
967 &ctx->cm_id->route.addr.dst_addr);
970 if (copy_to_user(response, &resp, sizeof(resp)))
976 static ssize_t ucma_query(struct ucma_file *file,
977 const char __user *inbuf,
978 int in_len, int out_len)
980 struct rdma_ucm_query cmd;
981 struct ucma_context *ctx;
982 void __user *response;
985 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
988 response = (void __user *)(unsigned long) cmd.response;
989 ctx = ucma_get_ctx(file, cmd.id);
993 switch (cmd.option) {
994 case RDMA_USER_CM_QUERY_ADDR:
995 ret = ucma_query_addr(ctx, response, out_len);
997 case RDMA_USER_CM_QUERY_PATH:
998 ret = ucma_query_path(ctx, response, out_len);
1000 case RDMA_USER_CM_QUERY_GID:
1001 ret = ucma_query_gid(ctx, response, out_len);
1012 static void ucma_copy_conn_param(struct rdma_cm_id *id,
1013 struct rdma_conn_param *dst,
1014 struct rdma_ucm_conn_param *src)
1016 dst->private_data = src->private_data;
1017 dst->private_data_len = src->private_data_len;
1018 dst->responder_resources =src->responder_resources;
1019 dst->initiator_depth = src->initiator_depth;
1020 dst->flow_control = src->flow_control;
1021 dst->retry_count = src->retry_count;
1022 dst->rnr_retry_count = src->rnr_retry_count;
1023 dst->srq = src->srq;
1024 dst->qp_num = src->qp_num;
1025 dst->qkey = (id->route.addr.src_addr.ss_family == AF_IB) ? src->qkey : 0;
1028 static ssize_t ucma_connect(struct ucma_file *file, const char __user *inbuf,
1029 int in_len, int out_len)
1031 struct rdma_ucm_connect cmd;
1032 struct rdma_conn_param conn_param;
1033 struct ucma_context *ctx;
1036 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
1039 if (!cmd.conn_param.valid)
1042 ctx = ucma_get_ctx(file, cmd.id);
1044 return PTR_ERR(ctx);
1046 ucma_copy_conn_param(ctx->cm_id, &conn_param, &cmd.conn_param);
1047 ret = rdma_connect(ctx->cm_id, &conn_param);
1052 static ssize_t ucma_listen(struct ucma_file *file, const char __user *inbuf,
1053 int in_len, int out_len)
1055 struct rdma_ucm_listen cmd;
1056 struct ucma_context *ctx;
1059 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
1062 ctx = ucma_get_ctx(file, cmd.id);
1064 return PTR_ERR(ctx);
1066 ctx->backlog = cmd.backlog > 0 && cmd.backlog < max_backlog ?
1067 cmd.backlog : max_backlog;
1068 ret = rdma_listen(ctx->cm_id, ctx->backlog);
1073 static ssize_t ucma_accept(struct ucma_file *file, const char __user *inbuf,
1074 int in_len, int out_len)
1076 struct rdma_ucm_accept cmd;
1077 struct rdma_conn_param conn_param;
1078 struct ucma_context *ctx;
1081 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
1084 ctx = ucma_get_ctx(file, cmd.id);
1086 return PTR_ERR(ctx);
1088 if (cmd.conn_param.valid) {
1089 ucma_copy_conn_param(ctx->cm_id, &conn_param, &cmd.conn_param);
1090 mutex_lock(&file->mut);
1091 ret = rdma_accept(ctx->cm_id, &conn_param);
1094 mutex_unlock(&file->mut);
1096 ret = rdma_accept(ctx->cm_id, NULL);
1102 static ssize_t ucma_reject(struct ucma_file *file, const char __user *inbuf,
1103 int in_len, int out_len)
1105 struct rdma_ucm_reject cmd;
1106 struct ucma_context *ctx;
1109 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
1112 ctx = ucma_get_ctx(file, cmd.id);
1114 return PTR_ERR(ctx);
1116 ret = rdma_reject(ctx->cm_id, cmd.private_data, cmd.private_data_len);
1121 static ssize_t ucma_disconnect(struct ucma_file *file, const char __user *inbuf,
1122 int in_len, int out_len)
1124 struct rdma_ucm_disconnect cmd;
1125 struct ucma_context *ctx;
1128 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
1131 ctx = ucma_get_ctx(file, cmd.id);
1133 return PTR_ERR(ctx);
1135 ret = rdma_disconnect(ctx->cm_id);
1140 static ssize_t ucma_init_qp_attr(struct ucma_file *file,
1141 const char __user *inbuf,
1142 int in_len, int out_len)
1144 struct rdma_ucm_init_qp_attr cmd;
1145 struct ib_uverbs_qp_attr resp;
1146 struct ucma_context *ctx;
1147 struct ib_qp_attr qp_attr;
1150 if (out_len < sizeof(resp))
1153 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
1156 if (cmd.qp_state > IB_QPS_ERR)
1159 ctx = ucma_get_ctx(file, cmd.id);
1161 return PTR_ERR(ctx);
1163 if (!ctx->cm_id->device) {
1168 resp.qp_attr_mask = 0;
1169 memset(&qp_attr, 0, sizeof qp_attr);
1170 qp_attr.qp_state = cmd.qp_state;
1171 ret = rdma_init_qp_attr(ctx->cm_id, &qp_attr, &resp.qp_attr_mask);
1175 ib_copy_qp_attr_to_user(&resp, &qp_attr);
1176 if (copy_to_user((void __user *)(unsigned long)cmd.response,
1177 &resp, sizeof(resp)))
1185 static int ucma_set_option_id(struct ucma_context *ctx, int optname,
1186 void *optval, size_t optlen)
1191 case RDMA_OPTION_ID_TOS:
1192 if (optlen != sizeof(u8)) {
1196 rdma_set_service_type(ctx->cm_id, *((u8 *) optval));
1198 case RDMA_OPTION_ID_REUSEADDR:
1199 if (optlen != sizeof(int)) {
1203 ret = rdma_set_reuseaddr(ctx->cm_id, *((int *) optval) ? 1 : 0);
1205 case RDMA_OPTION_ID_AFONLY:
1206 if (optlen != sizeof(int)) {
1210 ret = rdma_set_afonly(ctx->cm_id, *((int *) optval) ? 1 : 0);
1219 static int ucma_set_ib_path(struct ucma_context *ctx,
1220 struct ib_path_rec_data *path_data, size_t optlen)
1222 struct ib_sa_path_rec sa_path;
1223 struct rdma_cm_event event;
1226 if (optlen % sizeof(*path_data))
1229 for (; optlen; optlen -= sizeof(*path_data), path_data++) {
1230 if (path_data->flags == (IB_PATH_GMP | IB_PATH_PRIMARY |
1231 IB_PATH_BIDIRECTIONAL))
1238 if (!ctx->cm_id->device)
1241 memset(&sa_path, 0, sizeof(sa_path));
1243 ib_sa_unpack_path(path_data->path_rec, &sa_path);
1244 ret = rdma_set_ib_paths(ctx->cm_id, &sa_path, 1);
1248 memset(&event, 0, sizeof event);
1249 event.event = RDMA_CM_EVENT_ROUTE_RESOLVED;
1250 return ucma_event_handler(ctx->cm_id, &event);
1253 static int ucma_set_option_ib(struct ucma_context *ctx, int optname,
1254 void *optval, size_t optlen)
1259 case RDMA_OPTION_IB_PATH:
1260 ret = ucma_set_ib_path(ctx, optval, optlen);
1269 static int ucma_set_option_level(struct ucma_context *ctx, int level,
1270 int optname, void *optval, size_t optlen)
1275 case RDMA_OPTION_ID:
1276 ret = ucma_set_option_id(ctx, optname, optval, optlen);
1278 case RDMA_OPTION_IB:
1279 ret = ucma_set_option_ib(ctx, optname, optval, optlen);
1288 static ssize_t ucma_set_option(struct ucma_file *file, const char __user *inbuf,
1289 int in_len, int out_len)
1291 struct rdma_ucm_set_option cmd;
1292 struct ucma_context *ctx;
1296 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
1299 if (unlikely(cmd.optlen > KMALLOC_MAX_SIZE))
1302 ctx = ucma_get_ctx(file, cmd.id);
1304 return PTR_ERR(ctx);
1306 optval = memdup_user((void __user *) (unsigned long) cmd.optval,
1308 if (IS_ERR(optval)) {
1309 ret = PTR_ERR(optval);
1313 ret = ucma_set_option_level(ctx, cmd.level, cmd.optname, optval,
1322 static ssize_t ucma_notify(struct ucma_file *file, const char __user *inbuf,
1323 int in_len, int out_len)
1325 struct rdma_ucm_notify cmd;
1326 struct ucma_context *ctx;
1329 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
1332 ctx = ucma_get_ctx(file, cmd.id);
1334 return PTR_ERR(ctx);
1336 if (ctx->cm_id->device)
1337 ret = rdma_notify(ctx->cm_id, (enum ib_event_type)cmd.event);
1343 static ssize_t ucma_process_join(struct ucma_file *file,
1344 struct rdma_ucm_join_mcast *cmd, int out_len)
1346 struct rdma_ucm_create_id_resp resp;
1347 struct ucma_context *ctx;
1348 struct ucma_multicast *mc;
1349 struct sockaddr *addr;
1353 if (out_len < sizeof(resp))
1356 addr = (struct sockaddr *) &cmd->addr;
1357 if (cmd->addr_size != rdma_addr_size(addr))
1360 if (cmd->join_flags == RDMA_MC_JOIN_FLAG_FULLMEMBER)
1361 join_state = BIT(FULLMEMBER_JOIN);
1362 else if (cmd->join_flags == RDMA_MC_JOIN_FLAG_SENDONLY_FULLMEMBER)
1363 join_state = BIT(SENDONLY_FULLMEMBER_JOIN);
1367 ctx = ucma_get_ctx(file, cmd->id);
1369 return PTR_ERR(ctx);
1371 mutex_lock(&file->mut);
1372 mc = ucma_alloc_multicast(ctx);
1377 mc->join_state = join_state;
1379 memcpy(&mc->addr, addr, cmd->addr_size);
1380 ret = rdma_join_multicast(ctx->cm_id, (struct sockaddr *)&mc->addr,
1386 if (copy_to_user((void __user *)(unsigned long) cmd->response,
1387 &resp, sizeof(resp))) {
1393 idr_replace(&multicast_idr, mc, mc->id);
1396 mutex_unlock(&file->mut);
1401 rdma_leave_multicast(ctx->cm_id, (struct sockaddr *) &mc->addr);
1402 ucma_cleanup_mc_events(mc);
1405 idr_remove(&multicast_idr, mc->id);
1407 list_del(&mc->list);
1410 mutex_unlock(&file->mut);
1415 static ssize_t ucma_join_ip_multicast(struct ucma_file *file,
1416 const char __user *inbuf,
1417 int in_len, int out_len)
1419 struct rdma_ucm_join_ip_mcast cmd;
1420 struct rdma_ucm_join_mcast join_cmd;
1422 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
1425 join_cmd.response = cmd.response;
1426 join_cmd.uid = cmd.uid;
1427 join_cmd.id = cmd.id;
1428 join_cmd.addr_size = rdma_addr_size_in6(&cmd.addr);
1429 if (!join_cmd.addr_size)
1432 join_cmd.join_flags = RDMA_MC_JOIN_FLAG_FULLMEMBER;
1433 memcpy(&join_cmd.addr, &cmd.addr, join_cmd.addr_size);
1435 return ucma_process_join(file, &join_cmd, out_len);
1438 static ssize_t ucma_join_multicast(struct ucma_file *file,
1439 const char __user *inbuf,
1440 int in_len, int out_len)
1442 struct rdma_ucm_join_mcast cmd;
1444 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
1447 if (!rdma_addr_size_kss(&cmd.addr))
1450 return ucma_process_join(file, &cmd, out_len);
1453 static ssize_t ucma_leave_multicast(struct ucma_file *file,
1454 const char __user *inbuf,
1455 int in_len, int out_len)
1457 struct rdma_ucm_destroy_id cmd;
1458 struct rdma_ucm_destroy_id_resp resp;
1459 struct ucma_multicast *mc;
1462 if (out_len < sizeof(resp))
1465 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
1469 mc = idr_find(&multicast_idr, cmd.id);
1471 mc = ERR_PTR(-ENOENT);
1472 else if (mc->ctx->file != file)
1473 mc = ERR_PTR(-EINVAL);
1474 else if (!atomic_inc_not_zero(&mc->ctx->ref))
1475 mc = ERR_PTR(-ENXIO);
1477 idr_remove(&multicast_idr, mc->id);
1485 rdma_leave_multicast(mc->ctx->cm_id, (struct sockaddr *) &mc->addr);
1486 mutex_lock(&mc->ctx->file->mut);
1487 ucma_cleanup_mc_events(mc);
1488 list_del(&mc->list);
1489 mutex_unlock(&mc->ctx->file->mut);
1491 ucma_put_ctx(mc->ctx);
1492 resp.events_reported = mc->events_reported;
1495 if (copy_to_user((void __user *)(unsigned long)cmd.response,
1496 &resp, sizeof(resp)))
1502 static void ucma_lock_files(struct ucma_file *file1, struct ucma_file *file2)
1504 /* Acquire mutex's based on pointer comparison to prevent deadlock. */
1505 if (file1 < file2) {
1506 mutex_lock(&file1->mut);
1507 mutex_lock_nested(&file2->mut, SINGLE_DEPTH_NESTING);
1509 mutex_lock(&file2->mut);
1510 mutex_lock_nested(&file1->mut, SINGLE_DEPTH_NESTING);
1514 static void ucma_unlock_files(struct ucma_file *file1, struct ucma_file *file2)
1516 if (file1 < file2) {
1517 mutex_unlock(&file2->mut);
1518 mutex_unlock(&file1->mut);
1520 mutex_unlock(&file1->mut);
1521 mutex_unlock(&file2->mut);
1525 static void ucma_move_events(struct ucma_context *ctx, struct ucma_file *file)
1527 struct ucma_event *uevent, *tmp;
1529 list_for_each_entry_safe(uevent, tmp, &ctx->file->event_list, list)
1530 if (uevent->ctx == ctx)
1531 list_move_tail(&uevent->list, &file->event_list);
1534 static ssize_t ucma_migrate_id(struct ucma_file *new_file,
1535 const char __user *inbuf,
1536 int in_len, int out_len)
1538 struct rdma_ucm_migrate_id cmd;
1539 struct rdma_ucm_migrate_resp resp;
1540 struct ucma_context *ctx;
1542 struct ucma_file *cur_file;
1545 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
1548 /* Get current fd to protect against it being closed */
1552 if (f.file->f_op != &ucma_fops) {
1557 /* Validate current fd and prevent destruction of id. */
1558 ctx = ucma_get_ctx(f.file->private_data, cmd.id);
1564 cur_file = ctx->file;
1565 if (cur_file == new_file) {
1566 resp.events_reported = ctx->events_reported;
1571 * Migrate events between fd's, maintaining order, and avoiding new
1572 * events being added before existing events.
1574 ucma_lock_files(cur_file, new_file);
1577 list_move_tail(&ctx->list, &new_file->ctx_list);
1578 ucma_move_events(ctx, new_file);
1579 ctx->file = new_file;
1580 resp.events_reported = ctx->events_reported;
1583 ucma_unlock_files(cur_file, new_file);
1586 if (copy_to_user((void __user *)(unsigned long)cmd.response,
1587 &resp, sizeof(resp)))
1596 static ssize_t (*ucma_cmd_table[])(struct ucma_file *file,
1597 const char __user *inbuf,
1598 int in_len, int out_len) = {
1599 [RDMA_USER_CM_CMD_CREATE_ID] = ucma_create_id,
1600 [RDMA_USER_CM_CMD_DESTROY_ID] = ucma_destroy_id,
1601 [RDMA_USER_CM_CMD_BIND_IP] = ucma_bind_ip,
1602 [RDMA_USER_CM_CMD_RESOLVE_IP] = ucma_resolve_ip,
1603 [RDMA_USER_CM_CMD_RESOLVE_ROUTE] = ucma_resolve_route,
1604 [RDMA_USER_CM_CMD_QUERY_ROUTE] = ucma_query_route,
1605 [RDMA_USER_CM_CMD_CONNECT] = ucma_connect,
1606 [RDMA_USER_CM_CMD_LISTEN] = ucma_listen,
1607 [RDMA_USER_CM_CMD_ACCEPT] = ucma_accept,
1608 [RDMA_USER_CM_CMD_REJECT] = ucma_reject,
1609 [RDMA_USER_CM_CMD_DISCONNECT] = ucma_disconnect,
1610 [RDMA_USER_CM_CMD_INIT_QP_ATTR] = ucma_init_qp_attr,
1611 [RDMA_USER_CM_CMD_GET_EVENT] = ucma_get_event,
1612 [RDMA_USER_CM_CMD_GET_OPTION] = NULL,
1613 [RDMA_USER_CM_CMD_SET_OPTION] = ucma_set_option,
1614 [RDMA_USER_CM_CMD_NOTIFY] = ucma_notify,
1615 [RDMA_USER_CM_CMD_JOIN_IP_MCAST] = ucma_join_ip_multicast,
1616 [RDMA_USER_CM_CMD_LEAVE_MCAST] = ucma_leave_multicast,
1617 [RDMA_USER_CM_CMD_MIGRATE_ID] = ucma_migrate_id,
1618 [RDMA_USER_CM_CMD_QUERY] = ucma_query,
1619 [RDMA_USER_CM_CMD_BIND] = ucma_bind,
1620 [RDMA_USER_CM_CMD_RESOLVE_ADDR] = ucma_resolve_addr,
1621 [RDMA_USER_CM_CMD_JOIN_MCAST] = ucma_join_multicast
1624 static ssize_t ucma_write(struct file *filp, const char __user *buf,
1625 size_t len, loff_t *pos)
1627 struct ucma_file *file = filp->private_data;
1628 struct rdma_ucm_cmd_hdr hdr;
1631 if (WARN_ON_ONCE(!ib_safe_file_access(filp)))
1634 if (len < sizeof(hdr))
1637 if (copy_from_user(&hdr, buf, sizeof(hdr)))
1640 if (hdr.cmd >= ARRAY_SIZE(ucma_cmd_table))
1642 hdr.cmd = array_index_nospec(hdr.cmd, ARRAY_SIZE(ucma_cmd_table));
1644 if (hdr.in + sizeof(hdr) > len)
1647 if (!ucma_cmd_table[hdr.cmd])
1650 ret = ucma_cmd_table[hdr.cmd](file, buf + sizeof(hdr), hdr.in, hdr.out);
1657 static unsigned int ucma_poll(struct file *filp, struct poll_table_struct *wait)
1659 struct ucma_file *file = filp->private_data;
1660 unsigned int mask = 0;
1662 poll_wait(filp, &file->poll_wait, wait);
1664 if (!list_empty(&file->event_list))
1665 mask = POLLIN | POLLRDNORM;
1671 * ucma_open() does not need the BKL:
1673 * - no global state is referred to;
1674 * - there is no ioctl method to race against;
1675 * - no further module initialization is required for open to work
1676 * after the device is registered.
1678 static int ucma_open(struct inode *inode, struct file *filp)
1680 struct ucma_file *file;
1682 file = kmalloc(sizeof *file, GFP_KERNEL);
1686 file->close_wq = alloc_ordered_workqueue("ucma_close_id",
1688 if (!file->close_wq) {
1693 INIT_LIST_HEAD(&file->event_list);
1694 INIT_LIST_HEAD(&file->ctx_list);
1695 init_waitqueue_head(&file->poll_wait);
1696 mutex_init(&file->mut);
1698 filp->private_data = file;
1701 return nonseekable_open(inode, filp);
1704 static int ucma_close(struct inode *inode, struct file *filp)
1706 struct ucma_file *file = filp->private_data;
1707 struct ucma_context *ctx, *tmp;
1709 mutex_lock(&file->mut);
1710 list_for_each_entry_safe(ctx, tmp, &file->ctx_list, list) {
1711 ctx->destroying = 1;
1712 mutex_unlock(&file->mut);
1715 idr_remove(&ctx_idr, ctx->id);
1718 flush_workqueue(file->close_wq);
1719 /* At that step once ctx was marked as destroying and workqueue
1720 * was flushed we are safe from any inflights handlers that
1721 * might put other closing task.
1724 if (!ctx->closing) {
1727 wait_for_completion(&ctx->comp);
1728 /* rdma_destroy_id ensures that no event handlers are
1729 * inflight for that id before releasing it.
1731 rdma_destroy_id(ctx->cm_id);
1737 mutex_lock(&file->mut);
1739 mutex_unlock(&file->mut);
1740 destroy_workqueue(file->close_wq);
1745 static const struct file_operations ucma_fops = {
1746 .owner = THIS_MODULE,
1748 .release = ucma_close,
1749 .write = ucma_write,
1751 .llseek = no_llseek,
1754 static struct miscdevice ucma_misc = {
1755 .minor = MISC_DYNAMIC_MINOR,
1757 .nodename = "infiniband/rdma_cm",
1762 static ssize_t show_abi_version(struct device *dev,
1763 struct device_attribute *attr,
1766 return sprintf(buf, "%d\n", RDMA_USER_CM_ABI_VERSION);
1768 static DEVICE_ATTR(abi_version, S_IRUGO, show_abi_version, NULL);
1770 static int __init ucma_init(void)
1774 ret = misc_register(&ucma_misc);
1778 ret = device_create_file(ucma_misc.this_device, &dev_attr_abi_version);
1780 pr_err("rdma_ucm: couldn't create abi_version attr\n");
1784 ucma_ctl_table_hdr = register_net_sysctl(&init_net, "net/rdma_ucm", ucma_ctl_table);
1785 if (!ucma_ctl_table_hdr) {
1786 pr_err("rdma_ucm: couldn't register sysctl paths\n");
1792 device_remove_file(ucma_misc.this_device, &dev_attr_abi_version);
1794 misc_deregister(&ucma_misc);
1798 static void __exit ucma_cleanup(void)
1800 unregister_net_sysctl_table(ucma_ctl_table_hdr);
1801 device_remove_file(ucma_misc.this_device, &dev_attr_abi_version);
1802 misc_deregister(&ucma_misc);
1803 idr_destroy(&ctx_idr);
1804 idr_destroy(&multicast_idr);
1807 module_init(ucma_init);
1808 module_exit(ucma_cleanup);