Lines Matching refs:context
44 static void ctx_signal_notify(struct vmci_ctx *context) in ctx_signal_notify() argument
46 *context->notify = true; in ctx_signal_notify()
49 static void ctx_clear_notify(struct vmci_ctx *context) in ctx_clear_notify() argument
51 *context->notify = false; in ctx_clear_notify()
58 static void ctx_clear_notify_call(struct vmci_ctx *context) in ctx_clear_notify_call() argument
60 if (context->pending_datagrams == 0 && in ctx_clear_notify_call()
61 vmci_handle_arr_get_size(context->pending_doorbell_array) == 0) in ctx_clear_notify_call()
62 ctx_clear_notify(context); in ctx_clear_notify_call()
69 void vmci_ctx_check_signal_notify(struct vmci_ctx *context) in vmci_ctx_check_signal_notify() argument
71 spin_lock(&context->lock); in vmci_ctx_check_signal_notify()
72 if (context->pending_datagrams) in vmci_ctx_check_signal_notify()
73 ctx_signal_notify(context); in vmci_ctx_check_signal_notify()
74 spin_unlock(&context->lock); in vmci_ctx_check_signal_notify()
85 struct vmci_ctx *context; in vmci_ctx_create() local
107 context = kzalloc(sizeof(*context), GFP_KERNEL); in vmci_ctx_create()
108 if (!context) { in vmci_ctx_create()
114 kref_init(&context->kref); in vmci_ctx_create()
115 spin_lock_init(&context->lock); in vmci_ctx_create()
116 INIT_LIST_HEAD(&context->list_item); in vmci_ctx_create()
117 INIT_LIST_HEAD(&context->datagram_queue); in vmci_ctx_create()
118 INIT_LIST_HEAD(&context->notifier_list); in vmci_ctx_create()
121 init_waitqueue_head(&context->host_context.wait_queue); in vmci_ctx_create()
123 context->queue_pair_array = in vmci_ctx_create()
125 if (!context->queue_pair_array) { in vmci_ctx_create()
130 context->doorbell_array = in vmci_ctx_create()
132 if (!context->doorbell_array) { in vmci_ctx_create()
137 context->pending_doorbell_array = in vmci_ctx_create()
139 if (!context->pending_doorbell_array) { in vmci_ctx_create()
144 context->user_version = user_version; in vmci_ctx_create()
146 context->priv_flags = priv_flags; in vmci_ctx_create()
149 context->cred = get_cred(cred); in vmci_ctx_create()
151 context->notify = &ctx_dummy_notify; in vmci_ctx_create()
152 context->notify_page = NULL; in vmci_ctx_create()
168 context->cid = cid; in vmci_ctx_create()
170 list_add_tail_rcu(&context->list_item, &ctx_list.head); in vmci_ctx_create()
173 return context; in vmci_ctx_create()
176 vmci_handle_arr_destroy(context->doorbell_array); in vmci_ctx_create()
178 vmci_handle_arr_destroy(context->queue_pair_array); in vmci_ctx_create()
180 kfree(context); in vmci_ctx_create()
188 void vmci_ctx_destroy(struct vmci_ctx *context) in vmci_ctx_destroy() argument
191 list_del_rcu(&context->list_item); in vmci_ctx_destroy()
195 vmci_ctx_put(context); in vmci_ctx_destroy()
262 ev.msg.hdr.dst.context); in ctx_fire_notification()
278 struct vmci_ctx *context; in vmci_ctx_pending_datagrams() local
280 context = vmci_ctx_get(cid); in vmci_ctx_pending_datagrams()
281 if (context == NULL) in vmci_ctx_pending_datagrams()
284 spin_lock(&context->lock); in vmci_ctx_pending_datagrams()
286 *pending = context->pending_datagrams; in vmci_ctx_pending_datagrams()
287 spin_unlock(&context->lock); in vmci_ctx_pending_datagrams()
288 vmci_ctx_put(context); in vmci_ctx_pending_datagrams()
299 struct vmci_ctx *context; in vmci_ctx_enqueue_datagram() local
310 context = vmci_ctx_get(cid); in vmci_ctx_enqueue_datagram()
311 if (!context) { in vmci_ctx_enqueue_datagram()
320 vmci_ctx_put(context); in vmci_ctx_enqueue_datagram()
328 spin_lock(&context->lock); in vmci_ctx_enqueue_datagram()
339 if (context->datagram_queue_size + vmci_dg_size >= in vmci_ctx_enqueue_datagram()
345 context->datagram_queue_size + vmci_dg_size >= in vmci_ctx_enqueue_datagram()
347 spin_unlock(&context->lock); in vmci_ctx_enqueue_datagram()
348 vmci_ctx_put(context); in vmci_ctx_enqueue_datagram()
354 list_add(&dq_entry->list_item, &context->datagram_queue); in vmci_ctx_enqueue_datagram()
355 context->pending_datagrams++; in vmci_ctx_enqueue_datagram()
356 context->datagram_queue_size += vmci_dg_size; in vmci_ctx_enqueue_datagram()
357 ctx_signal_notify(context); in vmci_ctx_enqueue_datagram()
358 wake_up(&context->host_context.wait_queue); in vmci_ctx_enqueue_datagram()
359 spin_unlock(&context->lock); in vmci_ctx_enqueue_datagram()
360 vmci_ctx_put(context); in vmci_ctx_enqueue_datagram()
372 struct vmci_ctx *context; in vmci_ctx_exists() local
377 list_for_each_entry_rcu(context, &ctx_list.head, list_item) { in vmci_ctx_exists()
378 if (context->cid == cid) { in vmci_ctx_exists()
393 struct vmci_ctx *c, *context = NULL; in vmci_ctx_get() local
409 context = c; in vmci_ctx_get()
410 kref_get(&context->kref); in vmci_ctx_get()
416 return context; in vmci_ctx_get()
426 struct vmci_ctx *context = container_of(kref, struct vmci_ctx, kref); in ctx_free_ctx() local
435 ctx_fire_notification(context->cid, context->priv_flags); in ctx_free_ctx()
442 temp_handle = vmci_handle_arr_get_entry(context->queue_pair_array, 0); in ctx_free_ctx()
445 context) < VMCI_SUCCESS) { in ctx_free_ctx()
452 vmci_handle_arr_remove_entry(context->queue_pair_array, in ctx_free_ctx()
456 vmci_handle_arr_get_entry(context->queue_pair_array, 0); in ctx_free_ctx()
464 &context->datagram_queue, list_item) { in ctx_free_ctx()
472 &context->notifier_list, node) { in ctx_free_ctx()
477 vmci_handle_arr_destroy(context->queue_pair_array); in ctx_free_ctx()
478 vmci_handle_arr_destroy(context->doorbell_array); in ctx_free_ctx()
479 vmci_handle_arr_destroy(context->pending_doorbell_array); in ctx_free_ctx()
480 vmci_ctx_unset_notify(context); in ctx_free_ctx()
481 if (context->cred) in ctx_free_ctx()
482 put_cred(context->cred); in ctx_free_ctx()
483 kfree(context); in ctx_free_ctx()
495 void vmci_ctx_put(struct vmci_ctx *context) in vmci_ctx_put() argument
497 kref_put(&context->kref, ctx_free_ctx); in vmci_ctx_put()
508 int vmci_ctx_dequeue_datagram(struct vmci_ctx *context, in vmci_ctx_dequeue_datagram() argument
517 spin_lock(&context->lock); in vmci_ctx_dequeue_datagram()
518 if (context->pending_datagrams == 0) { in vmci_ctx_dequeue_datagram()
519 ctx_clear_notify_call(context); in vmci_ctx_dequeue_datagram()
520 spin_unlock(&context->lock); in vmci_ctx_dequeue_datagram()
525 list_item = context->datagram_queue.next; in vmci_ctx_dequeue_datagram()
533 spin_unlock(&context->lock); in vmci_ctx_dequeue_datagram()
540 context->pending_datagrams--; in vmci_ctx_dequeue_datagram()
541 context->datagram_queue_size -= dq_entry->dg_size; in vmci_ctx_dequeue_datagram()
542 if (context->pending_datagrams == 0) { in vmci_ctx_dequeue_datagram()
543 ctx_clear_notify_call(context); in vmci_ctx_dequeue_datagram()
551 list_item = context->datagram_queue.next; in vmci_ctx_dequeue_datagram()
562 spin_unlock(&context->lock); in vmci_ctx_dequeue_datagram()
576 void vmci_ctx_unset_notify(struct vmci_ctx *context) in vmci_ctx_unset_notify() argument
580 spin_lock(&context->lock); in vmci_ctx_unset_notify()
582 notify_page = context->notify_page; in vmci_ctx_unset_notify()
583 context->notify = &ctx_dummy_notify; in vmci_ctx_unset_notify()
584 context->notify_page = NULL; in vmci_ctx_unset_notify()
586 spin_unlock(&context->lock); in vmci_ctx_unset_notify()
600 struct vmci_ctx *context; in vmci_ctx_add_notification() local
605 context = vmci_ctx_get(context_id); in vmci_ctx_add_notification()
606 if (!context) in vmci_ctx_add_notification()
616 if (context->priv_flags & VMCI_PRIVILEGE_FLAG_RESTRICTED) { in vmci_ctx_add_notification()
630 spin_lock(&context->lock); in vmci_ctx_add_notification()
632 if (context->n_notifiers < VMCI_MAX_CONTEXTS) { in vmci_ctx_add_notification()
633 list_for_each_entry(n, &context->notifier_list, node) { in vmci_ctx_add_notification()
645 &context->notifier_list); in vmci_ctx_add_notification()
646 context->n_notifiers++; in vmci_ctx_add_notification()
654 spin_unlock(&context->lock); in vmci_ctx_add_notification()
657 vmci_ctx_put(context); in vmci_ctx_add_notification()
667 struct vmci_ctx *context; in vmci_ctx_remove_notification() local
671 context = vmci_ctx_get(context_id); in vmci_ctx_remove_notification()
672 if (!context) in vmci_ctx_remove_notification()
677 spin_lock(&context->lock); in vmci_ctx_remove_notification()
679 &context->notifier_list, node) { in vmci_ctx_remove_notification()
682 context->n_notifiers--; in vmci_ctx_remove_notification()
687 spin_unlock(&context->lock); in vmci_ctx_remove_notification()
692 vmci_ctx_put(context); in vmci_ctx_remove_notification()
697 static int vmci_ctx_get_chkpt_notifiers(struct vmci_ctx *context, in vmci_ctx_get_chkpt_notifiers() argument
705 if (context->n_notifiers == 0) { in vmci_ctx_get_chkpt_notifiers()
711 data_size = context->n_notifiers * sizeof(*notifiers); in vmci_ctx_get_chkpt_notifiers()
721 list_for_each_entry(entry, &context->notifier_list, node) in vmci_ctx_get_chkpt_notifiers()
722 notifiers[i++] = entry->handle.context; in vmci_ctx_get_chkpt_notifiers()
729 static int vmci_ctx_get_chkpt_doorbells(struct vmci_ctx *context, in vmci_ctx_get_chkpt_doorbells() argument
735 n_doorbells = vmci_handle_arr_get_size(context->doorbell_array); in vmci_ctx_get_chkpt_doorbells()
749 context->doorbell_array, i); in vmci_ctx_get_chkpt_doorbells()
769 struct vmci_ctx *context; in vmci_ctx_get_chkpt_state() local
772 context = vmci_ctx_get(context_id); in vmci_ctx_get_chkpt_state()
773 if (!context) in vmci_ctx_get_chkpt_state()
776 spin_lock(&context->lock); in vmci_ctx_get_chkpt_state()
780 result = vmci_ctx_get_chkpt_notifiers(context, buf_size, pbuf); in vmci_ctx_get_chkpt_state()
795 result = vmci_ctx_get_chkpt_doorbells(context, buf_size, pbuf); in vmci_ctx_get_chkpt_state()
804 spin_unlock(&context->lock); in vmci_ctx_get_chkpt_state()
805 vmci_ctx_put(context); in vmci_ctx_get_chkpt_state()
861 struct vmci_ctx *context; in vmci_ctx_rcv_notifications_get() local
864 context = vmci_ctx_get(context_id); in vmci_ctx_rcv_notifications_get()
865 if (context == NULL) in vmci_ctx_rcv_notifications_get()
868 spin_lock(&context->lock); in vmci_ctx_rcv_notifications_get()
870 *db_handle_array = context->pending_doorbell_array; in vmci_ctx_rcv_notifications_get()
871 context->pending_doorbell_array = in vmci_ctx_rcv_notifications_get()
873 if (!context->pending_doorbell_array) { in vmci_ctx_rcv_notifications_get()
874 context->pending_doorbell_array = *db_handle_array; in vmci_ctx_rcv_notifications_get()
880 spin_unlock(&context->lock); in vmci_ctx_rcv_notifications_get()
881 vmci_ctx_put(context); in vmci_ctx_rcv_notifications_get()
897 struct vmci_ctx *context = vmci_ctx_get(context_id); in vmci_ctx_rcv_notifications_release() local
899 spin_lock(&context->lock); in vmci_ctx_rcv_notifications_release()
911 context->pending_doorbell_array); in vmci_ctx_rcv_notifications_release()
919 context->pending_doorbell_array); in vmci_ctx_rcv_notifications_release()
921 vmci_handle_arr_destroy(context->pending_doorbell_array); in vmci_ctx_rcv_notifications_release()
922 context->pending_doorbell_array = db_handle_array; in vmci_ctx_rcv_notifications_release()
925 ctx_clear_notify_call(context); in vmci_ctx_rcv_notifications_release()
927 spin_unlock(&context->lock); in vmci_ctx_rcv_notifications_release()
928 vmci_ctx_put(context); in vmci_ctx_rcv_notifications_release()
943 struct vmci_ctx *context; in vmci_ctx_dbell_create() local
949 context = vmci_ctx_get(context_id); in vmci_ctx_dbell_create()
950 if (context == NULL) in vmci_ctx_dbell_create()
953 spin_lock(&context->lock); in vmci_ctx_dbell_create()
954 if (!vmci_handle_arr_has_entry(context->doorbell_array, handle)) in vmci_ctx_dbell_create()
955 result = vmci_handle_arr_append_entry(&context->doorbell_array, in vmci_ctx_dbell_create()
960 spin_unlock(&context->lock); in vmci_ctx_dbell_create()
961 vmci_ctx_put(context); in vmci_ctx_dbell_create()
972 struct vmci_ctx *context; in vmci_ctx_dbell_destroy() local
978 context = vmci_ctx_get(context_id); in vmci_ctx_dbell_destroy()
979 if (context == NULL) in vmci_ctx_dbell_destroy()
982 spin_lock(&context->lock); in vmci_ctx_dbell_destroy()
984 vmci_handle_arr_remove_entry(context->doorbell_array, handle); in vmci_ctx_dbell_destroy()
985 vmci_handle_arr_remove_entry(context->pending_doorbell_array, handle); in vmci_ctx_dbell_destroy()
986 spin_unlock(&context->lock); in vmci_ctx_dbell_destroy()
988 vmci_ctx_put(context); in vmci_ctx_dbell_destroy()
1000 struct vmci_ctx *context; in vmci_ctx_dbell_destroy_all() local
1006 context = vmci_ctx_get(context_id); in vmci_ctx_dbell_destroy_all()
1007 if (context == NULL) in vmci_ctx_dbell_destroy_all()
1010 spin_lock(&context->lock); in vmci_ctx_dbell_destroy_all()
1012 struct vmci_handle_arr *arr = context->doorbell_array; in vmci_ctx_dbell_destroy_all()
1016 struct vmci_handle_arr *arr = context->pending_doorbell_array; in vmci_ctx_dbell_destroy_all()
1019 spin_unlock(&context->lock); in vmci_ctx_dbell_destroy_all()
1021 vmci_ctx_put(context); in vmci_ctx_dbell_destroy_all()
1047 dst_context = vmci_ctx_get(handle.context); in vmci_ctx_notify_dbell()
1049 pr_devel("Invalid context (ID=0x%x)\n", handle.context); in vmci_ctx_notify_dbell()
1053 if (src_cid != handle.context) { in vmci_ctx_notify_dbell()
1057 VMCI_CONTEXT_IS_VM(handle.context)) { in vmci_ctx_notify_dbell()
1059 src_cid, handle.context); in vmci_ctx_notify_dbell()
1067 handle.context, handle.resource); in vmci_ctx_notify_dbell()
1082 if (handle.context == VMCI_HOST_CONTEXT_ID) { in vmci_ctx_notify_dbell()
1114 bool vmci_ctx_supports_host_qp(struct vmci_ctx *context) in vmci_ctx_supports_host_qp() argument
1116 return context && context->user_version >= VMCI_VERSION_HOSTQP; in vmci_ctx_supports_host_qp()
1123 int vmci_ctx_qp_create(struct vmci_ctx *context, struct vmci_handle handle) in vmci_ctx_qp_create() argument
1127 if (context == NULL || vmci_handle_is_invalid(handle)) in vmci_ctx_qp_create()
1130 if (!vmci_handle_arr_has_entry(context->queue_pair_array, handle)) in vmci_ctx_qp_create()
1132 &context->queue_pair_array, handle); in vmci_ctx_qp_create()
1143 int vmci_ctx_qp_destroy(struct vmci_ctx *context, struct vmci_handle handle) in vmci_ctx_qp_destroy() argument
1147 if (context == NULL || vmci_handle_is_invalid(handle)) in vmci_ctx_qp_destroy()
1150 hndl = vmci_handle_arr_remove_entry(context->queue_pair_array, handle); in vmci_ctx_qp_destroy()
1160 bool vmci_ctx_qp_exists(struct vmci_ctx *context, struct vmci_handle handle) in vmci_ctx_qp_exists() argument
1162 if (context == NULL || vmci_handle_is_invalid(handle)) in vmci_ctx_qp_exists()
1165 return vmci_handle_arr_has_entry(context->queue_pair_array, handle); in vmci_ctx_qp_exists()
1178 struct vmci_ctx *context; in vmci_context_get_priv_flags() local
1180 context = vmci_ctx_get(context_id); in vmci_context_get_priv_flags()
1181 if (!context) in vmci_context_get_priv_flags()
1184 flags = context->priv_flags; in vmci_context_get_priv_flags()
1185 vmci_ctx_put(context); in vmci_context_get_priv_flags()
1204 struct vmci_ctx *context = vmci_ctx_get(context_id); in vmci_is_context_owner() local
1205 if (context) { in vmci_is_context_owner()
1206 if (context->cred) in vmci_is_context_owner()
1207 is_owner = uid_eq(context->cred->uid, uid); in vmci_is_context_owner()
1208 vmci_ctx_put(context); in vmci_is_context_owner()