drivers/misc/vmw_vmci/vmci_context.c
Source file repositories/reference/linux-study-clean/drivers/misc/vmw_vmci/vmci_context.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/misc/vmw_vmci/vmci_context.c- Extension
.c- Size
- 30130 bytes
- Lines
- 1163
- Domain
- Driver Families
- Bucket
- drivers/misc
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/vmw_vmci_defs.hlinux/vmw_vmci_api.hlinux/highmem.hlinux/kernel.hlinux/module.hlinux/sched.hlinux/cred.hlinux/slab.hvmci_queue_pair.hvmci_datagram.hvmci_doorbell.hvmci_context.hvmci_driver.hvmci_event.h
Detected Declarations
function ctx_signal_notifyfunction ctx_clear_notifyfunction ctx_clear_notify_callfunction vmci_ctx_check_signal_notifyfunction vmci_ctx_destroyfunction ctx_fire_notificationfunction list_for_each_entry_rcufunction vmci_ctx_enqueue_datagramfunction vmci_make_handlefunction vmci_ctx_existsfunction list_for_each_entry_rcufunction ctx_free_ctxfunction list_for_each_entry_safefunction itfunction vmci_ctx_dequeue_datagramfunction vmci_setup_notifyfunction vmci_ctx_add_notificationfunction vmci_ctx_remove_notificationfunction vmci_ctx_get_chkpt_notifiersfunction vmci_ctx_get_chkpt_doorbellsfunction vmci_ctx_get_chkpt_statefunction vmci_ctx_set_chkpt_statefunction vmci_ctx_rcv_notifications_getfunction vmci_ctx_rcv_notifications_releasefunction vmci_ctx_dbell_createfunction vmci_ctx_dbell_destroyfunction vmci_ctx_notify_dbellfunction vmci_ctx_supports_host_qpfunction vmci_ctx_qp_createfunction vmci_ctx_qp_destroyfunction vmci_ctx_qp_existsfunction vmci_context_get_priv_flagsfunction vmci_is_context_ownerexport vmci_context_get_priv_flagsexport vmci_is_context_owner
Annotated Snippet
list_for_each_entry_rcu(node, &sub_ctx->notifier_list, node) {
if (!vmci_handle_is_equal(node->handle, context_handle))
continue;
vmci_handle_arr_append_entry(&subscriber_array,
vmci_make_handle(sub_ctx->cid,
VMCI_EVENT_HANDLER));
}
}
rcu_read_unlock();
/* Fire event to all subscribers. */
array_size = vmci_handle_arr_get_size(subscriber_array);
for (i = 0; i < array_size; i++) {
int result;
struct vmci_event_ctx ev;
ev.msg.hdr.dst = vmci_handle_arr_get_entry(subscriber_array, i);
ev.msg.hdr.src = vmci_make_handle(VMCI_HYPERVISOR_CONTEXT_ID,
VMCI_CONTEXT_RESOURCE_ID);
ev.msg.hdr.payload_size = sizeof(ev) - sizeof(ev.msg.hdr);
memset((char*)&ev + sizeof(ev.msg.hdr), 0,
ev.msg.hdr.payload_size);
ev.msg.event_data.event = VMCI_EVENT_CTX_REMOVED;
ev.payload.context_id = context_id;
result = vmci_datagram_dispatch(VMCI_HYPERVISOR_CONTEXT_ID,
&ev.msg.hdr, false);
if (result < VMCI_SUCCESS) {
pr_devel("Failed to enqueue event datagram (type=%d) for context (ID=0x%x)\n",
ev.msg.event_data.event,
ev.msg.hdr.dst.context);
/* We continue to enqueue on next subscriber. */
}
}
vmci_handle_arr_destroy(subscriber_array);
return VMCI_SUCCESS;
}
/*
* Queues a VMCI datagram for the appropriate target VM context.
*/
int vmci_ctx_enqueue_datagram(u32 cid, struct vmci_datagram *dg)
{
struct vmci_datagram_queue_entry *dq_entry;
struct vmci_ctx *context;
struct vmci_handle dg_src;
size_t vmci_dg_size;
vmci_dg_size = VMCI_DG_SIZE(dg);
if (vmci_dg_size > VMCI_MAX_DG_SIZE) {
pr_devel("Datagram too large (bytes=%zu)\n", vmci_dg_size);
return VMCI_ERROR_INVALID_ARGS;
}
/* Get the target VM's VMCI context. */
context = vmci_ctx_get(cid);
if (!context) {
pr_devel("Invalid context (ID=0x%x)\n", cid);
return VMCI_ERROR_INVALID_ARGS;
}
/* Allocate guest call entry and add it to the target VM's queue. */
dq_entry = kmalloc_obj(*dq_entry);
if (dq_entry == NULL) {
pr_warn("Failed to allocate memory for datagram\n");
vmci_ctx_put(context);
return VMCI_ERROR_NO_MEM;
}
dq_entry->dg = dg;
dq_entry->dg_size = vmci_dg_size;
dg_src = dg->src;
INIT_LIST_HEAD(&dq_entry->list_item);
spin_lock(&context->lock);
/*
* We put a higher limit on datagrams from the hypervisor. If
* the pending datagram is not from hypervisor, then we check
* if enqueueing it would exceed the
* VMCI_MAX_DATAGRAM_QUEUE_SIZE limit on the destination. If
* the pending datagram is from hypervisor, we allow it to be
* queued at the destination side provided we don't reach the
* VMCI_MAX_DATAGRAM_AND_EVENT_QUEUE_SIZE limit.
*/
if (context->datagram_queue_size + vmci_dg_size >=
VMCI_MAX_DATAGRAM_QUEUE_SIZE &&
(!vmci_handle_is_equal(dg_src,
vmci_make_handle
Annotation
- Immediate include surface: `linux/vmw_vmci_defs.h`, `linux/vmw_vmci_api.h`, `linux/highmem.h`, `linux/kernel.h`, `linux/module.h`, `linux/sched.h`, `linux/cred.h`, `linux/slab.h`.
- Detected declarations: `function ctx_signal_notify`, `function ctx_clear_notify`, `function ctx_clear_notify_call`, `function vmci_ctx_check_signal_notify`, `function vmci_ctx_destroy`, `function ctx_fire_notification`, `function list_for_each_entry_rcu`, `function vmci_ctx_enqueue_datagram`, `function vmci_make_handle`, `function vmci_ctx_exists`.
- Atlas domain: Driver Families / drivers/misc.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.