drivers/vhost/vsock.c
Source file repositories/reference/linux-study-clean/drivers/vhost/vsock.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/vhost/vsock.c- Extension
.c- Size
- 26491 bytes
- Lines
- 1021
- Domain
- Driver Families
- Bucket
- drivers/vhost
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/miscdevice.hlinux/atomic.hlinux/module.hlinux/mutex.hlinux/vmalloc.hnet/sock.hlinux/virtio_vsock.hlinux/vhost.hlinux/hashtable.hnet/af_vsock.hvhost.h
Detected Declarations
struct vhost_vsockfunction vhost_transport_get_local_cidfunction hash_for_each_possible_rcufunction vhost_transport_has_remote_cidfunction vhost_transport_do_send_pktfunction packetfunction vhost_transport_send_pkt_workfunction vhost_transport_send_pktfunction vhost_vq_get_backendfunction vhost_transport_cancel_pktfunction vhost_vsock_alloc_skbfunction vhost_vsock_more_repliesfunction vhost_transport_msgzerocopy_allowfunction vhost_transport_stream_allowfunction vhost_transport_seqpacket_allowfunction vhost_vsock_handle_tx_kickfunction vhost_vsock_handle_rx_kickfunction vhost_vsock_startfunction vhost_vsock_stopfunction vhost_vsock_freefunction vhost_vsock_dev_openfunction vhost_vsock_flushfunction vhost_vsock_reset_orphansfunction vhost_vsock_dev_releasefunction vhost_vsock_set_cidfunction vhost_vsock_set_featuresfunction vhost_vsock_dev_ioctlfunction vhost_vsock_chr_read_iterfunction vhost_vsock_chr_write_iterfunction vhost_vsock_chr_pollfunction vhost_vsock_initfunction vhost_vsock_exitmodule init vhost_vsock_init
Annotated Snippet
static const struct file_operations vhost_vsock_fops = {
.owner = THIS_MODULE,
.open = vhost_vsock_dev_open,
.release = vhost_vsock_dev_release,
.llseek = noop_llseek,
.unlocked_ioctl = vhost_vsock_dev_ioctl,
.compat_ioctl = compat_ptr_ioctl,
.read_iter = vhost_vsock_chr_read_iter,
.write_iter = vhost_vsock_chr_write_iter,
.poll = vhost_vsock_chr_poll,
};
static struct miscdevice vhost_vsock_misc = {
.minor = VHOST_VSOCK_MINOR,
.name = "vhost-vsock",
.fops = &vhost_vsock_fops,
};
static int __init vhost_vsock_init(void)
{
int ret;
ret = vsock_core_register(&vhost_transport.transport,
VSOCK_TRANSPORT_F_H2G);
if (ret < 0)
return ret;
ret = misc_register(&vhost_vsock_misc);
if (ret) {
vsock_core_unregister(&vhost_transport.transport);
return ret;
}
return 0;
};
static void __exit vhost_vsock_exit(void)
{
misc_deregister(&vhost_vsock_misc);
vsock_core_unregister(&vhost_transport.transport);
};
module_init(vhost_vsock_init);
module_exit(vhost_vsock_exit);
MODULE_LICENSE("GPL v2");
MODULE_AUTHOR("Asias He");
MODULE_DESCRIPTION("vhost transport for vsock ");
MODULE_ALIAS_MISCDEV(VHOST_VSOCK_MINOR);
MODULE_ALIAS("devname:vhost-vsock");
Annotation
- Immediate include surface: `linux/miscdevice.h`, `linux/atomic.h`, `linux/module.h`, `linux/mutex.h`, `linux/vmalloc.h`, `net/sock.h`, `linux/virtio_vsock.h`, `linux/vhost.h`.
- Detected declarations: `struct vhost_vsock`, `function vhost_transport_get_local_cid`, `function hash_for_each_possible_rcu`, `function vhost_transport_has_remote_cid`, `function vhost_transport_do_send_pkt`, `function packet`, `function vhost_transport_send_pkt_work`, `function vhost_transport_send_pkt`, `function vhost_vq_get_backend`, `function vhost_transport_cancel_pkt`.
- Atlas domain: Driver Families / drivers/vhost.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.