drivers/misc/vmw_vmci/vmci_datagram.c
Source file repositories/reference/linux-study-clean/drivers/misc/vmw_vmci/vmci_datagram.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/misc/vmw_vmci/vmci_datagram.c- Extension
.c- Size
- 13868 bytes
- Lines
- 497
- 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/module.hlinux/sched.hlinux/slab.hlinux/bug.hvmci_datagram.hvmci_resource.hvmci_context.hvmci_driver.hvmci_event.hvmci_route.h
Detected Declarations
struct datagram_entrystruct delayed_datagram_infofunction dg_create_handlefunction vmci_datagram_get_priv_flagsfunction dg_delayed_dispatchfunction dg_dispatch_as_hostfunction dg_dispatch_as_guestfunction vmci_datagram_dispatchfunction vmci_datagram_invoke_guest_handlerfunction vmci_datagram_create_handle_privfunction vmci_datagram_create_handlefunction vmci_datagram_destroy_handlefunction vmci_datagram_sendexport vmci_datagram_create_handle_privexport vmci_datagram_create_handleexport vmci_datagram_destroy_handleexport vmci_datagram_send
Annotated Snippet
struct datagram_entry {
struct vmci_resource resource;
u32 flags;
bool run_delayed;
vmci_datagram_recv_cb recv_cb;
void *client_data;
u32 priv_flags;
};
struct delayed_datagram_info {
struct datagram_entry *entry;
struct work_struct work;
bool in_dg_host_queue;
/* msg and msg_payload must be together. */
struct vmci_datagram msg;
u8 msg_payload[];
};
/* Number of in-flight host->host datagrams */
static atomic_t delayed_dg_host_queue_size = ATOMIC_INIT(0);
/*
* Create a datagram entry given a handle pointer.
*/
static int dg_create_handle(u32 resource_id,
u32 flags,
u32 priv_flags,
vmci_datagram_recv_cb recv_cb,
void *client_data, struct vmci_handle *out_handle)
{
int result;
u32 context_id;
struct vmci_handle handle;
struct datagram_entry *entry;
if ((flags & VMCI_FLAG_WELLKNOWN_DG_HND) != 0)
return VMCI_ERROR_INVALID_ARGS;
if ((flags & VMCI_FLAG_ANYCID_DG_HND) != 0) {
context_id = VMCI_INVALID_ID;
} else {
context_id = vmci_get_context_id();
if (context_id == VMCI_INVALID_ID)
return VMCI_ERROR_NO_RESOURCES;
}
handle = vmci_make_handle(context_id, resource_id);
entry = kmalloc_obj(*entry);
if (!entry) {
pr_warn("Failed allocating memory for datagram entry\n");
return VMCI_ERROR_NO_MEM;
}
entry->run_delayed = (flags & VMCI_FLAG_DG_DELAYED_CB) ? true : false;
entry->flags = flags;
entry->recv_cb = recv_cb;
entry->client_data = client_data;
entry->priv_flags = priv_flags;
/* Make datagram resource live. */
result = vmci_resource_add(&entry->resource,
VMCI_RESOURCE_TYPE_DATAGRAM,
handle);
if (result != VMCI_SUCCESS) {
pr_warn("Failed to add new resource (handle=0x%x:0x%x), error: %d\n",
handle.context, handle.resource, result);
kfree(entry);
return result;
}
*out_handle = vmci_resource_handle(&entry->resource);
return VMCI_SUCCESS;
}
/*
* Internal utility function with the same purpose as
* vmci_datagram_get_priv_flags that also takes a context_id.
*/
static int vmci_datagram_get_priv_flags(u32 context_id,
struct vmci_handle handle,
u32 *priv_flags)
{
if (context_id == VMCI_INVALID_ID)
return VMCI_ERROR_INVALID_ARGS;
if (context_id == VMCI_HOST_CONTEXT_ID) {
struct datagram_entry *src_entry;
struct vmci_resource *resource;
Annotation
- Immediate include surface: `linux/vmw_vmci_defs.h`, `linux/vmw_vmci_api.h`, `linux/module.h`, `linux/sched.h`, `linux/slab.h`, `linux/bug.h`, `vmci_datagram.h`, `vmci_resource.h`.
- Detected declarations: `struct datagram_entry`, `struct delayed_datagram_info`, `function dg_create_handle`, `function vmci_datagram_get_priv_flags`, `function dg_delayed_dispatch`, `function dg_dispatch_as_host`, `function dg_dispatch_as_guest`, `function vmci_datagram_dispatch`, `function vmci_datagram_invoke_guest_handler`, `function vmci_datagram_create_handle_priv`.
- 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.